2
# .COPYRIGHT: Copyright (c) 1988-2010 European Southern Observatory,
6
# .LANGUAGE Bourne-shell script
7
# .ENVIRONMENT Unix Systems. Executable under any SHELL.
8
# .USAGE inmidas [ unit ] [-h midashome] [-r midvers] [-d display]
9
# [-m mid_work] [-p/-np] [-noh ] [-j midas-comman-line]
10
# unit: MIDAS unit (00, 01, ..., 99, xa, ..., zz)
11
# (default: 00 if NOPARALLE mode)
12
# display: X server for display and graphical windows.
13
# midashome: Home directory for MIDAS. (default: MIDASHOME0)
14
# midvers: Version of MIDAS. (default: MIDVERS0)
15
# mid_work: MIDAS startup directory (default: $HOME/mid_work)
16
# -p/-nop: Set MIDOPTIONS to PARALLEL/NOPARALLE
17
# (default: NOPARALLEL)
18
# -noh: No welcome header.
19
# -drs: reuse keyfile from drs commands
20
# -j: Execute next argument as a MIDAS command.
21
# -clean Clean up $MID_WORK dir. before starting the
24
# .COMMENTS Script to start MIDAS. It uses the following environment:
25
# MIDASHOME, MIDVERS and MIDOPTION.
26
# variables if they exist, otherwise takes defaults.
27
# It checks arguments if any and exec to
28
# $MIDASHOME/$MIDVERS/monit/prepa.exe
30
# .REMARKS MIDASHOME0 & MIDVERS0 are set to defaults values by option
31
# "8- MIDAS setup" in the MIDAS "config" script.
33
# .VERSION 1.1 910221: CG. Implementation
34
# .VERSION 2.1 930706: CG. Simplified and passing arguments.
35
# .VERSION 2.2 010831: KB. remove all Midas related files in $MID_WORK
38
#**************************************************************************
40
#**************************************************************************
43
# Modify the default values of MIDASHOME0 and MIDVERS0
44
# according to your site.
46
# Environment variables MIDASHOME and MIDVERS overwrite these defaults.
48
# Done automaticaly by option "8- setup MIDAS" in the "config" script.
51
MIDASHOME0=/home/esomidas
55
# END of Configure Here
56
#**************************************************************************
60
MIDASDRS=''; export MIDASDRS
62
# Check command "echo"
66
if [ "`echo -n`" = "-n" ] ; then
72
# Strip "/dev/", strip "pty/" (HP), "pts/" (IBM), and "tty" (all)
76
tt=`tty | sed -e 's/^.*dev\///' -e 's/pty\///' -e 's/pts\///' -e 's/tty//'`
81
#**************************************************************************
91
echo "Usage: inmidas [unit] [-h midashome] [-r midvers] [-d display] [-p/-P/-nop]"
92
echo " [-m mid_work] [-noh] [-j \"midas-command-line\"] [-drs] [-help]"
95
echo " Home directory for MIDAS. Sets variable MIDASHOME to midashome"
97
echo " Release of MIDAS. Sets variable MIDVERS to midvers and it must exist as "
98
echo " a subdirectory under MIDASHOME."
100
echo " This option specifies the X server to contact."
102
echo " -p and -P options set variable MIDOPTION to PARALLEL. -nop option"
103
echo " sets MIDOPTION to NOPARALLEL."
104
echo " With -nop (NOPARALLEL) all working files from previous MIDAS sessions"
105
echo " located in the directory MID_WORK are deleted. Only one MIDAS session can"
106
echo " run at a time. With -p and -P (PARALLEL) no working files are removed"
107
echo " from MID_WORK and several sessions can run simultaneously."
108
echo " With -P and -nop options and if not unit is given the system will select"
109
echo " automatically one free unit for you (in [01, ..., 99])."
110
echo " With -p option and no unit, the user will be requested to enter one."
112
echo " Unit to be associated to the MIDAS session. Valid values for this option"
113
echo " are in the range (00 to 99) for X environments, or (xa to zz) for ASCII"
114
echo " terminals other than X (no graphics). If no unit is provided the "
115
echo " system will select one for you except with -p option."
117
echo " This option sets the MID_WORK variable that specifies the MIDAS working"
118
echo " directory. By default MID_WORK is set to ~/midwork and it will be created"
119
echo " if it does not exist."
121
echo " Starts a MIDAS session without clearing the terminal and without any"
122
echo " welcome message. This option is meant for background purposes."
123
echo "-j \"midas_command_line\""
124
echo " Execute \"midas_command_line\" as the first command typed in the MIDAS"
125
echo " monitor. This option sets also -noh option."
127
echo " Starts a MIDAS session which reuses an existing FORGRdrs.KEY in the "
128
echo " current directory, by default this keyfile is recreated each time."
130
echo " Clean up $MID_WORK dir. before starting the MIDAS session."
132
echo " Display this help page."
134
-clean) clean_flag=1; shift ;;
135
-h) MIDASHOME=$2; export MIDASHOME; shift; shift ;;
136
-r) MIDVERS=$2; export MIDVERS; shift; shift ;;
137
-d) DISPLAY=$2; export DISPLAY; shift; shift ;;
138
-m) MID_WORK=$2; export MID_WORK; shift; shift ;;
139
-P) SELECT_UNIT=AUTO; MIDOPTION=PARALLEL; export SELECT_UNIT MIDOPTION; shift ;;
140
-p) MIDOPTION=PARALLEL; export MIDOPTION; shift ;;
141
-nop) MIDOPTION=NOPARALLEL; export MIDOPTION; shift ;;
142
-noh) MIDASHD=noheader; export MIDASHD; shift ;;
143
-drs) MIDASDRS=yes; export MIDASDRS; shift ;;
144
-j) MIDASJOB=$2; export MIDASJOB; shift; shift ;;
146
-*) echo "Usage: inmidas [unit] [-h midashome] [-r midvers] [-d display] [-p/-P/-nop]"
147
echo " [-m mid_work] [-noh] [-j \"midas-command-line\"] [-help]" >&2
150
*) DAZUNIT=$1; export DAZUNIT; shift ;;
155
# If MIDASHOME or MIDVERS variable not defined then set to default
157
if [ -z "$MIDASHOME" ]; then
158
MIDASHOME="$MIDASHOME0"; export MIDASHOME
160
if [ -z "$MIDVERS" ]; then
161
MIDVERS="$MIDVERS0"; export MIDVERS
165
# Check access to Midas directory
167
if [ ! -d $MIDASHOME/$MIDVERS ]; then
168
echo "$MIDASHOME/${MIDVERS}: no such directory."
169
echo "Call your MIDAS operator. EXIT."
173
# echo clean_flag = $clean_flag
175
if [ $clean_flag = 1 ]; then
176
if [ ! -d $MID_WORK ]; then
177
echo No directory $MID_WORK found...
183
echo using shell script $MIDASHOME/$MIDVERS/system/unix/clean_midwork
184
echo to clean up $MID_WORK
185
$MIDASHOME/$MIDVERS/system/unix/clean_midwork
189
# if necessary create MIDAS work directory
191
if [ -z "$MID_WORK" ]; then
192
MID_WORK=$HOME/midwork/ ; export MID_WORK
196
# if last char. of MID_WORK != '/' append a '/'
198
if [ `expr $MID_WORK : '.*\(.\)'` != '/' ]; then
199
MID_WORK=$MID_WORK/ ; export MID_WORK
202
if [ ! -d $MID_WORK ]; then
203
mkdir `expr $MID_WORK : '\(.*\).'` #use MID_WORK except last char.
205
echo Could not create directory `expr $MID_WORK : '\(.*\).'`
211
# get all the variables (logical names)
213
if [ -f $MIDASHOME/$MIDVERS/monit/midlogs.sh ]; then
214
. $MIDASHOME/$MIDVERS/monit/midlogs.sh
216
echo "$MIDASHOME/$MIDVERS/monit/midlogs.sh - no such file."
217
echo "Call your MIDAS operator. EXIT."
222
# Set default DAZUNIT to first unit free (~/midwork/RUNNING<unit>)
224
if [ -z "$DAZUNIT" -a \( -z "$MIDOPTION" -o "$MIDOPTION" = "NOPARALLEL" -o "$SELECT_UNIT" = "AUTO" \) ]
227
lockfile -1 -r 10 $MID_WORK/running.lock # 2> /dev/null
228
if [ $? != 0 ] ; then
232
DAZUNIT=`(ls $MID_WORK/RUNNING?? 2>/dev/null) | awk ' \
234
tmp = index($1,"RUNNING"); \
235
unit[substr($1,tmp+7,2)+0] = 1 \
242
if (i < 10) printf "0%d\n",i; \
243
else printf "%d\n",i ; \
250
printf "inmidas - Error: Too many MIDAS sessions already running.\n"; \
258
if [ $? -ne 0 ]; then
265
# If AUTOPARALLEL, DAZUNIT is now selected, and MIDOPTION is set to PARALLEL
267
if [ "$MIDOPTION" = "AUTOPARALLEL" ]; then
272
# logical assignements to devices.
274
if [ -f $MID_WORK/devices.sh ] ; then
275
. $MID_WORK/devices.sh
277
. $MIDASHOME/$MIDVERS/monit/devices.sh
281
# test, if DAZUNIT defined
285
if [ -z "$DAZUNIT" ]; then
286
$echo "Enter Midas unit (00, 01, ..., 99, xa, ..., zz) " $SV_NONL
288
if [ -z "$DAZUNIT" ]; then
295
# here for X Workstations
297
WORK_STATION=DAZ$DAZUNIT
306
DAZUNIT=`echo $DAZUNIT | tr "[a-z]" "[A-Z]" ` # convert to upper case
308
# no graphics capabilities
310
WORK_STATION=DAZ$DAZUNIT
314
echo "invalid Midas unit: $DAZUNIT"
325
export DAZUNIT WORK_STATION I_TYPE AGL3DEV
328
# Check if there is a running session already for DAZUNIT.
330
if [ -f "$MID_WORK/RUNNING$DAZUNIT" ]; then
331
echo "Unit $DAZUNIT is locked by another MIDAS session."
332
echo "To unlock just continue."
333
$echo "Do you want to continue [yn]? (n): " $SV_NONL
335
if [ -z "$answ" ]; then
338
if [ "$answ" != "y" -a "$answ" != "Y" ]; then
341
rm -f $MID_WORK/RUNNING$DAZUNIT
345
# Check PARALLEL option in MIDOPTION.
347
if [ -z "$MIDOPTION" ]; then
348
MIDOPTION=NOPARALLEL; export MIDOPTION
352
if [ "$MIDOPTION" != "PARALLEL" -a "$MIDOPTION" != "parallel" ] ; then
353
# echo Deleting old MIDAS files ...
354
# Ensure at least one file is deleted.
357
if (ls * 2>/dev/null | grep -s RUNNING)
359
echo "WARNING: Other MIDAS sessions might be running."
360
echo "Exit and use option <-p> for PARALLEL mode."
361
echo "If you continue all previous MIDAS sessions will be removed."
362
$echo "Do you want to continue [yn]? (n): " $SV_NONL
364
if [ -z "$answ" ]; then
367
if [ "$answ" != "y" -a "$answ" != "Y" ]; then
371
rm -f middum* midtemp* midjob*.prg midlis*.prg midtab*.prg \
372
IDISERV* idiserv* idisave*.dat .inmidas* CODE*.SAV sxw*.dat \
373
getXdepth* midas_xw* MIDAS*.PID RUNNING* xhelp*
376
# delete all &a,&b, ... files
377
rm -f middum* midtemp* >/dev/null 2>&1
381
# Catch any possible interrupt and remove the lock file
383
trap "rm -f $MID_WORK/RUNNING$DAZUNIT; exit 1" 1 2 3 15
384
touch $MID_WORK/RUNNING$DAZUNIT
386
rm -f $MID_WORK/running.lock
389
# Prepare $MID_WORK/.inmidas for next gomidas command
391
rm -f $MID_WORK/.inmidas $MID_WORK/.inmidas.$tt >/dev/null 2>&1
392
echo "# Date: " `date` > $MID_WORK/.inmidas
393
echo "MIDASHOME=$MIDASHOME; export MIDASHOME" >> $MID_WORK/.inmidas
394
echo "MIDVERS=$MIDVERS; export MIDVERS" >> $MID_WORK/.inmidas
395
echo "MIDOPTION=$MIDOPTION; export MIDOPTION" >> $MID_WORK/.inmidas
396
echo "DAZUNIT=$DAZUNIT; export DAZUNIT" >> $MID_WORK/.inmidas
397
echo "WORK_STATION=$WORK_STATION; export WORK_STATION" >> $MID_WORK/.inmidas
398
echo "I_TYPE=$I_TYPE; export I_TYPE" >> $MID_WORK/.inmidas
399
if [ -n "$AGL3DEV" ]; then
400
echo "AGL3DEV=$AGL3DEV; export AGL3DEV" >> $MID_WORK/.inmidas
402
if [ -n "$graph_term" ]; then
403
echo "graph_term=$graph_term; export graph_term" >> $MID_WORK/.inmidas
407
# Copy .inmidas to inmidas.<tt> that will be used by gomidas afterwards.
409
cp $MID_WORK/.inmidas $MID_WORK/.inmidas.$tt
412
# Set PATH for shared libraries
417
if [ -z "$LD_LIBRARY_PATH" ] ; then
418
LD_LIBRARY_PATH=$MIDASHOME/$MIDVERS/lib
420
LD_LIBRARY_PATH=$MIDASHOME/$MIDVERS/lib:$LD_LIBRARY_PATH
422
export LD_LIBRARY_PATH
425
if [ -z "$SHLIB_PATH" ] ; then
426
SHLIB_PATH=$MIDASHOME/$MIDVERS/lib
428
SHLIB_PATH=$MIDASHOME/$MIDVERS/lib:$SHLIB_PATH
439
$MID_MONIT/midasgo.exe
441
echo "...Midas session aborted..."
442
rm -f $MID_WORK/RUNNING$DAZUNIT
447
# Ignore CTRL-C before runnning prepa.exe
455
echo "...Midas session aborted..."
456
rm -f $MID_WORK/RUNNING$DAZUNIT
463
rm -f $MID_WORK/RUNNING$DAZUNIT