next up previous contents index
Next: Interrupting Procedures Up: MIDAS Command Language Previous: Conditional Statements, Branching

  
Special Functions

Special functions may be used with the command COMPUTE/KEYWORD. The currently supported functions are listed in the following tables (on the next pages). Note, that arg1, arg2 may either be the name of a keyword, the contents of which are used, or a constant. Character constants have to be enclosed in double quotes to distinguish them from a keyword name. On-line help for these functions is available via HELP COMPUTE/KEYWORD.


 
Table 3.2: Special Functions available for operations on keywords
Command Description
M$ABS( arg1) returns the absolute value of integer/real/double arg1 as integer/real/double
M$EXIST( arg1) returns 1 or 0, if file arg1 exists or not
M$EXISTD( arg1, arg2) returns 1 or 0, if descriptor arg2 of frame arg1 exists or not
M$EXISTK( arg1) returns 1 or 0, if keyword arg1 exists or not
M$EXISTC( arg1, arg2) returns the number of the column specified in arg2 of the table arg1; returns -2 or -1, if table arg1 or column arg2 doesn't exist
M$FILTYP( arg1, arg2) returns a type_no for file in arg1, if the file name does not include a file type, the type definition in arg2 is appended to the file name
M$INDEX( arg1, arg2) returns index of string arg2 in string arg1 as integer value (same as function INDEX of FORTRAN 77, i.e. first position is 1 (not 0))
M$INDEXB( arg1, arg2) same as M$INDEX but search is done backwards, starting at the end of the string
M$LEN( arg1) returns length of string arg1 until the first blank or end of string, e.g. for argument "abcd" result=4 and for "abc de" result=3
M$STRLEN( arg1) returns `true' string length of arg1 e.g. for argument "abcd" result=4 for "abc de" result=6; if the string contains only blanks, 0 will be returned
M$NINT( arg1) returns nearest integer of real/double arg1
M$SYMBOL( arg1) returns the translation of Unix environment variable arg1 (or DCL symbol in VMS) as a character string
M$LOWER( arg1) returns character string arg1 in lower case
M$UPPER( arg1) returns character string arg1 in upper case
M$TSTNO( arg1) returns 1 or 0, if string arg1 is a number or not
M$TIME() returns current date and time as string of 30 characters (as given by the host system)
M$TIME(1) returns current date and time as string in the form
  yyyy-mm-dd
M$SECS() returns the current time as no. of seconds elapsed since 1st Jan. 1970 (as an integer)
M$AGL( arg1) returns contents of AGL definition file agldevices.dat related to arg1 as an ASCII string
M$LN(arg1) returns natural logarithm of real/double arg1
M$LOG(arg1) returns base-10 logarithm of real/double arg1
M$EXP(arg1) returns exponential of real/double arg1 (base e)
 


 
Table 3.3: Special Functions available for operations on keywords - cont.
Command Description
M$SIN(arg1) returns sine of real/double angle arg1 (angle in degrees)
M$COS(arg1) returns cosine of real/double angle arg1 (angle in degrees)
M$TAN(arg1) returns tangent of real/double angle arg1 (angle in degrees)
M$ASIN(arg1) returns arcsine of real/double arg1 in degrees
M$ACOS(arg1) returns arccosine of real/double arg1 in degrees
M$ATAN(arg1) returns arctangent of real/double arg1 in degrees
M$SQRT(arg1) returns square root of real/double arg1
M$VALUE(imag[x,y,z]) returns a pixel of image imag as real value
M$VALUE(imag,dscr) returns an element of descr dscr of frame imag according to the descriptor type
M$VALUE(tbl,col,row) returns a single element of table tbl in column col and row row according to the column type
 

  
  
  
  
Note, that the M$VALUE function is different from all other functions:
Firstly it has a variable no. of arguments and secondly, because its operands are not keyword names (or constants) but the real names of images and tables.
  
As an example we want to to display the header of a FITS file stored on disk (without converting the data), the FITS file name may be entered with or without the file extension .mt; if not given we append the type inside the procedure:
!+
! Example 16, MIDAS procedure exa16.prg
!+
DEFINE/PARAM P1 ? ? "Enter FITS file name:"
!
DEFINE/LOCAL INA/C/1/80 " " all
! that fills all elements of INA with blanks
DEFINE/LOCAL K/I/1/2 0,0
!
K = M$INDEX(P1,".mt")
! test, if type of FITS file entered
IF K .LT. 2 THEN
WRITE/KEYW INA
$\{$P1$\}$.mt ! if not, append type
ELSE
WRITE/KEYW INA
$\{$P1$\}$! if yes, no need to append type
ENDIF
INTAPE/FITS 1 midd
$\{$ina$\}$ fnn | $more
!
but if we want to save the no. of axes of the FITS file
!
we do not use the keyword name INA but it's contents
K = M$VALUE(
$\{$ina$\}$,naxis)
WRITE/OUT we have
$\{$K$\}$ axes
The MIDAS commands @@ exa16 test as well as @@ exa16 test.mt will both display the header of the FITS file test.mt. Note, that this procedure will display the header in a user friendly way, i.e. one screen at a time (and only work for Unix).
One of the MIDAS verification procedures, verify3.prg shows the usage of all currently available functions. Enter @ vericopy to copy this procedure into your current directory (also the usage of verify3 will be shown then).


next up previous contents index
Next: Interrupting Procedures Up: MIDAS Command Language Previous: Conditional Statements, Branching
http://www.eso.org/midas/midas-support.html
1999-06-09