next up previous contents index
Next: Debugging of Procedures and Up: Monitor and Command Language Previous: Context Levels

   
Running a Program within MIDAS

To execute a user-written MIDAS application program  (coded in FORTRAN or C), employ the command RUN. The command RUN MYPROG or RUN myprog will execute myprog.exe in a subprocess like any other MIDAS command.
It is better practice to embed the command RUN MYPROG in a MIDAS command procedure. Typical tasks of this procedure would be to provide default values for all parameters , to check the validity of parameter values, and to store the parameters into the keywords your program will use.   
Let us assume you have written your special filter program and stored the executable module as bestfilt.exe on disk. Program bestfilt just needs the names of the input and output image which are obtained inside the program from the keywords IN_A and OUT_A .   
The following MIDAS procedure:

!+
! MIDAS procedure bestfilt.prg
!+
CROSSREF INPUT RESULT
DEFINE/PARAMETER P1 ? IMA "Enter input frame: "
DEFINE/PARAMETER P2 ? IMA "Enter output frame: "
DEFINE/MAXPAR 2
! max. 2 parameters expected
!
WRITE/KEYWORD IN_A
$\{$P1$\}$
WRITE/KEYWORD OUT_A
$\{$P2$\}$
RUN BESTFILT
! .exe is the default type
will check, that the two parameters are valid MIDAS file names and prompt for input if any parameter is not given. Together with the MIDAS command
CREATE/COMMAND BESTFILT/IMAGE @@ bestfilt
your application will then be integrated smoothly into MIDAS.
Now, you can apply your own filtering algorithm to the image lobo.bdf by typing e.g.
BESTFILT/IMAGE res=perrito in=lobo.   
As with data files you can specify a search path for executables via the command
SET/MIDAS_SYSTEM EPATH=directory which is then used by the RUN command. Furthermore, if your module is written in C you can pass parameters to the executable in the usual way (argc, arv stuff) via, e.g.
RUN BESTFILT par1 par2 ...

If you want to execute Midas commands from a shell script you can do so as shown in the following example, where we use the procedure myproc.prg and Bourne shell script myscript to obtain the median value of an image.

!
! MIDAS procedure myproc.prg
! to return the median of an image in an ASCII file
! execute via `@@ myproc image_name'
!
define/param p1 ? ima "Enter name of image:"
!
statistics/image
$\{$p1$\}$
!
! save median of statistics command (was stored in keyword OUTPUTR(8))
!
define/local value/r/1/1
$\{$outputr(8)$\}$
define/local fc/i/1/2 0,0
!
! create new ASCII file (named `info.asci') and store median in there
!
open/file info.asci write fc
write/file
$\{$fc(1)$\}$ median = $\{$value$\}$
close/file
$\{$fc(1)$\}$
!
bye
! terminate Midas


#! /bin/sh
# Bourne shell script `myscript' - execute via: $ myscript parameter
#
# delete last file we got
rm -f info.asci
#
# start up Midas in another xterm window
# and let it execute the procedure `myproc.prg'
# shell parameter $1 will be passed as parameter P1 to Midas
#
xterm -e inmidas -j "@@ myproc $1" 33 -p
#
# the info we want is now in file: info.asci
#
more info.asci

There is also the possibility to run any Midas command (procedure) directly from the Unix command line via the drs command. To have it available you must do once

$ source /midas/version/system/unix/drs_config
or

$ sh /midas/version/system/unix/drs_config.sh
  
then, assuming you have a FITS file fors1data.fits in your directory, you type

$drs read/descr fors1data.fits "eso.*"
to get all the ESO hierarchical FITS keywords of the image fors1data.fits.
Note, that the descriptor pattern `eso.*' has to be enclosed in double quotes to avoid expansion of this term by the shell.
With

$ drs -h
you get a short help about the command.

Note
The drs command is currently only implemented for Unix (Linux) systems, furthermore, it cannot be applied to Midas commands which use a graphics or display window. Also, Midas keyword manipulations don't make much sense, since the keyword data base is NOT saved...



 
next up previous contents index
Next: Debugging of Procedures and Up: Monitor and Command Language Previous: Context Levels
Petra Nass
1999-06-09