Calling molly commands

It is worth reading this document in full if you have never used molly before.

Prompted input:

The simplest way to start with molly is just to type a command name and let it prompt you for all the parameters. A '?' when responding to numerical parameters will type the allowable range for a parameter. The prompts are only one line long at most and so may be opaque on occasion. If so, look at the help on the command in question. Entering something outside the allowed range should get you out of the command (-1 for a slot is always a good one).

Command line input:

Fairly soon you will get irritated at responding to prompts especially if you are only changing one or two of several. Once you have got to a point in a command where you are not going to change any more parameters, type a backslash "\" (a la FIGARO) and default values will be taken for the rest. Even better, once you start to remember the parameters for a command, you can put them all on the same line as the command, so that e.g. "plot 1 10" will plot spectra in slots 1 through 10. Again a backslash on the command line means take the default value of a parameter and for all following unspecified parameters. Therefore if "plot \ 8" followed "plot 2 10", it would use 2 as the first argument, while "plot \" after this will take 2 and 8. If you are unsure about one of many parameters, you can put a question mark "?" to force prompting. Therefore "plot \ ?" will prompt for the second parameter even though the default flag is set. Finally, a crude level of arithematic is supported for integer, real or double precision arguments, so that you can write e.g. 10++11 meaning 21 (--,**,// also possible). This is most useful for user defined commands and command files (see below). The doubling is to guard against confusion in an expression like 1.E-4++1.E-3

Shortening commands:

Command names can be shortened to their shortest non-ambiguous version. Thus "pl \" is the same as "plot \" if there are no other commands beginning with "pl". Commands are not case-sensitive.

Command line editing

molly supports command line recall and editing. This capability derives from the use of Thewalt's getline C routines. They allow you to recall old commands (any number) and edit them, with cursor keys and emacs-style commands. Thus:
  • ^A/^E = move to start/end of a line.
  • ESC-F/ESC-B = move forward/back one word.
  • ^K = delete to end of line.
  • ^R/^S = reverse/forward search for string in history list
  • ^O = toggle overwrite/insert mode.
  • This capability substantially reduces the need for some options such as user defined commands (see below) and may save you a visit to the doctor for RSI.

    Specifying the spectra that you want:

    Normally operations on blocks of slots are carried out. e.g. 1 through 10 as above and you should for efficiency always try to arrange the spectra in this manner. However, you may want to plot slots 1,2,5, and 6 though. You can do this by specifying "plot 0 0", and you will then be prompted to specify the spectra you want. "plot \" will remember the same spectra as will most commands, but a few commands use the same subroutine (e.g. spline and polynomial fitting) in which case the spectra used by one will equally affect the other. If in doubt, specify the spectra fully for each command. This is most likely to be of importance in batch jobs.

    Concatenation:

    Commands can be concatenated on one line using semicolons. e.g.
       plot 1 10; write file 1 10 n 
    will plot slots 1 to 10 and then write them to a disc file (the "n" means a new file). Execution of concatenated commands stops if any individual command fails.

    User defined commands:

    Concatenation is probably most useful when it comes to commands which you can define yourself with one-line definitions. e.g.
     psum == add $01 $01 $02 $02 1000; plot 1000 1000 \
    
    defines a command with one argument called "psum" which adds two spectra stores the result in slot 1000 (assuming it exists) and then plots it. When you type "psum 10 21" the string 10 will be substituted for $01 and 21 will be substituted for $02. The substitute strings run from $01 to $99.

    If you don't put the arguments on the line you will be prompted for them. However, you will be prompted for each one which negates the advantage of multiple substitutions.

    User defined commands can save alot of typing and time. For example say you have to load, say, the 11th and 12th spectra from a series of files called long_name_A_More, long_name_B_More, etc. Writing it out in full each time is a bore. However defining the command:

     ld == load long_name_$01_More A 2 11
    
    you now need only type "ld A", "ld B" etc. (Note the use of A in the load command to add spectra after the highest numbered slot.)

    The arithematic facility allows you to do things like plot 2 spectra from a given start e.g. p2 == plot $01 $01++1.

    Command files:

    Files of commands can be run by typing "@ Par1 Par2 etc". The parameters are substituted for strings of the form $01 to $99 as for user defined commands. e.g. a file called 'hard' consists of:
      dev postscript_l 
      plot $01 $02 \ 
      close 
      !lpr pgplot.ps 
      dev last 
    
    This changes the device to a postscript printer, plots a range of spectra $01 to $02, closes the plot, submits a shell command (see below) to print it to the default plot device (should be a postscript printer of course) and then switches back to the device being used before the postscript printer. This would be invoked as e.g. "@hard 10 12" to plot spectra 10 to 12. A '#' as the first character is a comment flag inside a command file.

    Shell commands (UNIX only):

    Commands can be issued to the shell by entering
      !command 
    e.g. "!ls" to list the working directory. The routine forks a child process which dies once the command is completed. Therefore a command like "cd" will not effect a permanent change of directory (but may be useful as part of a more complex command). If you an expert, shell commands can do useful things such as rearrange an ascii file dumped by molly with awk.

    Restrictions:

    The options above are varied, but they are subject to some restrictions on what can be called from what. Here is a summary of what options can call what. ---> means "can call or invoke"; File1 and 2 refer to top level and second level command files. Similarly with concatenated(1) etc.
      Terminal input ---> File1, user definition, concatenated(1), shell, molly 
                          and user defined commands.  
      File1          ---> File2, user definition, concatenated(1), shell, molly 
                          and user defined commands.
      File2          ---> user definition, concatenated(1), shell, molly and user
                          defined commands.
      Concatenated(1)---> shell, user defined and molly commands. 
      User defined   ---> concatenated(2), shell and molly commands.
      Concatenated(2)---> shell and molly commands 
    
    Note restrictions which this implies such as : (a) user defined commands cannot call other user defined commands or command files, (b) concatenated commands cannot call command files, (c) only 2 levels of command file are allowed.

    Perl and molly

    For more complex operations you may want to think about using Perl to run molly. The main advantage here is that you gain the huge power of Perl to sort through tables, apply regular expression matching etc. Most of all you can easily write loops for molly which you might want for example if you were processing very large numbers of spectra indeed. I hope to keep a few sample programs of general interest available from these documents.
    Tom Marsh, Warwick.