By far the best way to add your own routine is to copy an existing routine with related argument structure. e.g. if your command will take some spectra and output a modified set, then you could use one of the rebinning commands as a template. If you do this, most of it will be so obvious that you won't need to look for further help. If you do see below.
At the moment the support subroutines standardly used by molly are poorly documented. I hope to remedy this in the future. In the meantime please ask me any questions that you may have. I would prefer to keep to a single set of such subroutines rather than have calls to different subroutines which essentially perform the same operation.
CALL HEDPLT(SPLIT, NSPLIT, MXSPLIT, DEVICE, COUNTS, & ERRORS, FLUX, MXBUFF, MXSPEC, MAXPX, NPIX, ARC, NARC, & MXARC, NMCHAR, NMDOUB, NMINTR, NMREAL, HDCHAR, HDDOUB, & HDINTR, HDREAL, NCHAR, NDOUB, NINTR, NREAL, MXCHAR, & MXDOUB, MXINTR, MXREAL, NMSCHAR, VSCHAR, NMSDOUB, VSDOUB, & NMSINTR, VSINTR, NMSREAL, VSREAL, NSCHAR, NSDOUB, NSINTR, & NSREAL, MXSCHAR, MXSDOUB, MXSINTR, MXSREAL, ..... etc)This looks fairly horrific, largely because I have tried to avoid using common blocks as much as possible in molly to avoid hard-to-track-down bugs. This has paid off in that I can normally find bugs in molly very quickly and do not have to worry about nasty interactions between subroutines.
I have also avoided the declaration of arrays as NCHAR(*) or NCHAR(1) which avoids having to specify the size of the array. This means that as well as the number of useful array items, the maximum number possible has to be passed. This does enable checks to be made against writing off the end of the array.
Looked at bit by bit, the above call is straightforward:
INTEGER NSPLIT, MXSPLIT CHARACTER*(*) SPLIT(MXSPLIT)SPLIT contains the command arguments (NSPLIT of them, NSPLIT may = 0). These were generated by molly command parser, control.f. Thus a clall "hedplt 1 2" would have 1 and 2 as the NSPLIT=2 arguments. It is up to the programmer as to what to do with these, but see below for standard routines to handle these inputs.
CHARACTER*(*) DEVICEthe name of the plot device/file for commands which need to know it. Look at a command which plots to see how the device should be opened.
REAL COUNTS(MXBUFF), ERRORS(MXBUFF), FLUX(MXBUFF)or
REAL COUNTS(MAXPX,MXBUFF/MAXPX), ..The latter method allows you to treat the data arrays as 2D arrays and makes it much easier to specify the correct slot. The arrays are declared in the main molly program as 1D arrays, but FORTRAN does not care about whether it is declared differently inside a subroutine.
INTEGER MXBUFF, MXSPEC, MAXPXthe size of the data arrays, the maximum number of header arrays and the maximum number of pixels/spec. Note that the maximum number of spectra possible is the lesser of MXSPEC and the number of slots i.e. MIN(MXBUFF/MAXPX, MXSPEC). MXBUFF and MXSPEC are fixed by parameter declaration inside molly.f; MAXPX can be altered at run time.
INTEGER NPIX(MXSPEC)array containing number of pixels/spectrum. NPIX(SLOT) = 0 indicates that SLOT is empty.
DOUBLE PRECISION ARC(MXARC,MXSPEC) INTEGER NARC(MXSPEC)ARC contains the arc poly coefficients for each spectrum and NARC the number of coefficients for each spectrum. If NARC(SLOT) = 0 then the slot has no wavelength scale. MXARC is fixed by a parameter declaration inside molly.f.
CHARACTER*(*) NMCHAR(MXCHAR,MXSPEC) CHARACTER*(*) NMDOUB(MXCHAR,MXSPEC) CHARACTER*(*) NMINTR(MXCHAR,MXSPEC) CHARACTER*(*) NMREAL(MXCHAR,MXSPEC)These arrays contain the names of the header items for each spectrum. There are separate arrays for character, double precision, integer and real header items. The number of characters/item is specified in 'molly/molly.dims'.
CHARACTER*(*) HDCHAR(MXCHAR,MXSPEC) DOUBLE PRECISION HDDOUB(MXCHAR,MXSPEC) INTEGER HDINTR(MXCHAR,MXSPEC) REAL HDREAL(MXCHAR,MXSPEC)Arrays containing the values of the header items.
INTEGER NCHAR(MXSPEC), NDOUB(MXSPEC), NINTR(MXSPEC), NREAL(MXSPEC)Arrays containg the numbers of header items of each type for each spectrum. *
INTEGER MXCHAR, MXDOUB, MXINTR, MXREALIntegers containing the maximum numbers of header items of each type/spectrum. These are fixed by parameter declarations in molly.f
CHARACTER*(*) NMSCHAR(MXSCHAR) CHARACTER*(*) NMSDOUB(MXSCHAR) CHARACTER*(*) NMSINTR(MXSCHAR) CHARACTER*(*) NMSREAL(MXSCHAR) CHARACTER*(*) VSCHAR(MXSCHAR) DOUBLE PRECISION VSDOUB(2,MXSCHAR) INTEGER VSINTR(2,MXSCHAR) REAL VSREAL(2,MXSCHAR)Names and values or ranges of the search parameters. You may not want to apply selection in your routine, but if you do, you must pass these arrays.
INTEGER NSCHAR, NSDOUB, NSINTR, NSREALThese are the number of search parameters of each type (they can all be zero of course).
INTEGER MXSCHAR, MXSDOUB, MXSINTR, MXSREALThese are the maximum number of search parameters of each type and are declared as parameters in molly.f.
At this stage you can do anything you like inside the subroutine. However if you want your command to be standard molly, there are some other rules to follow:
MAXSPEC = MIN(MXBUFF/MAXPX, MXSPEC) ! Set maximum number of slots DEFAULT = .FALSE. ! Initialise for command input IFAIL = 0 ! If IFAIL.NE.0, INTR_IN etc return immediately NCOM = 0 ! Counter for command arguments. * * Get range/list of slots to plot. Each of the numeric input routines * includes an upper and lower limit for the parameter. * CALL INTR_IN('First slot for header plot', SPLIT, NSPLIT, &MXSPLIT, NCOM, DEFAULT, SLOT1, 0, MAXSPEC, IFAIL) IF(IFAIL.NE.0) GOTO 999 SLOT2 = MAX(SLOT1, SLOT2) CALL INTR_IN('Last slot for header plot', SPLIT, NSPLIT, &MXSPLIT, NCOM, DEFAULT, SLOT2, SLOT1, MAXSPEC, IFAIL) IF(IFAIL.NE.0) GOTO 999 IF(SLOT1.EQ.0 .AND. SLOT2.NE.0) THEN WRITE(*,*) 'Only 0,0 to get list option' GOTO 999 ELSE IF(SLOT1.EQ.0 .AND. SLOT2.EQ.0) THEN IF(DEFAULT .AND. NLIST.GT.0) THEN CALL SETSLOT(LIST, NLIST, MXLIST, SLOTS, NSLOTS, MXSLOTS) ELSE WRITE(*,*) 'Enter list of spectra for header plot' CALL GETLIS(LIST, NLIST, MXLIST, MAXSPEC, SLOTS, & NSLOTS, MXSLOTS) END IF IF(NSLOTS.EQ.0) GOTO 999 ELSE CALL SETLIS(SLOT1, SLOT2, LIST, NLIST, MXLIST, SLOTS, & NSLOTS, MXSLOTS) END IF * * Get name of header item for X axis. Character input does not have * any range of possible inputs. * CALL CHAR_IN('X axis header item', SPLIT, NSPLIT, &MXSPLIT, NCOM, DEFAULT, XNAME, IFAIL)Note the way 0 0 for the slot range passes onto GETLIS for getting a list of slots. LIST(2,MXLIST) here is an INTEGER array that should be declared inside the subroutine. Common storage is not used here so that subroutines remember the slot lists they were called with.
*command * * this is the help on command "command" bla bla * *commandTry to keep the same style as other molly commands, and if you think your command is of general use, let me know about it.
There is a small possibility that will have to increase the parameter MXCOM by 1 to allow space for it in the command buffers (you will be told this on startup).