External Supermongo links:  (top)

SM-Table of Contents
SM-Table of Contents  (good for searching)
The Joy of Supermongo
SM manual in .ps format
SM manual entry from Unix
SM macros by Krawchuk

To set up Supermongo  (top)

This assumes that Supermongo has already been installed on your system, but not yet set up.
In your home directory, create a file called ".sm" with similar contents:   my  .sm  file
Create a directory where you will store the macros and other related files.  In these examples, my files are stored in my /bin directory.  This is also where your history file will be saved, if so defined in the .sm file.

Creating Files of macros:   (top)

When creating a macro file, type the name of the macro starting in the first column of the file.  Directly after this, type the number of arguments (this can be left blank if there are none).  The commands of the macro will then be listed in subsequent lines, but not in the first column.
Many macros can be placed in one file, with each new macro name starting in the first column, followed by each macro's commands.
See the SM manual page on this or any of my macros listed below.

Auto-Loading Macros into SM (using the .tcshrc file):   (top)

The command to start supermongo at the prompt is: sm.  To exit supermongo, just type quit.  Another way to start Supermongo is by aliasing it to another command such as:

alias mysm     'sm -m ~/bin/start.sm'
(This would be typed into a .tcshrc file, for example)
(If you are not familiar with aliasing, you can also type "sm -m ~/bin/start.sm" at the prompt)

This alias automatically loads and runs the macro titled "start" in the file ~/bin/start.sm
example:             
start    # startup macro
device x11
prompt sm:
expand 1.00001
MACRO READ "/home/bin/start.sm"
MACRO READ "/home/bin/other_macro_file.sm"
Now you have a macro that loads automatically!  You can then use this macro to read in other macro files  so that all of your macros will load at startup as well.
(See my start.sm file below for an example.)
(make sure to read in the start.sm file here as well if you have more than one macro in this file; this only loads the start macro in start.sm) 
This is convenient when you are editing your macros while running SM: you can reload all of your macros by typing 'start' at the prompt.  Thus you do not have to restart SM or type MACRO READ many times just to test a new macro!!

My Macros:    (top)

/bin/start.sm                         
#This macro just loads all of my other macros as well as defining a basic macros.
/bin/macros.sm                    
#This macro is where all of my graphing commands are located.
/bin/paper.sm                        
#This macro is similar to the previous one, but has a few modifications.

Random notes that have come in useful:   (top)

Naming files with variable titles:

When naming files to be used in Supermongo (as in when reading in multiple files with a DO loop), do not name them "$!(variable1[0])_$!(variable2[0]).dat" as Supermongo will see the  _ as an extension of the first variable's name.  However, "file_$!(variable1[0]).dat_$!(variable2[0])" works fine.
OR:  (I just found out)
You can use an underscore after a variable if you put in some extra double quotes after the variable and before the underscore:
       define x 10
       $x""_red.txt    becomes:   10_red.txt

Printing:

To print a graph to a file or to a printer: you must first change the device to the desired location, execute all commands for that graph, and then change the device back to the standard output (dev x11) to close the printer/file connection.  To see all devices, type "list device" at prompt.
Output to a .ps file (8x8)                          dev postscript "file.ps"
Output to a .ps landscape                        dev postland "file.ps"
Output to a .ps portrait                           dev postport "file.ps"
Output to a .eps                                       dev postencap "file.eps"
Output to a .eps landscape                      dev postlandfile "file.eps"
Output to a .eps portrait                         dev postportfile "file.eps"
To a printer,landscape                            dev postland name_of_printer

Variable expansion:

$! forces variable expansion within ""  (file names are specified in "", thus in order to use a variable in the file's name, reference the variable as $!(var1[0]), not $(var1[0]).  $!! expands variables anywhere.

Difference between SET and DEFINE for variables:

Supermongo treats variables (defined with SET, not DEFINE) and vectors the same.  Thus a variable is a 1 by 1 dimensional vector and is referenced by $(var1[0]).  (The DEFINE command can be used to define numeric variables, however, in my experience I have found this method to be less reliable than using the SET command.)

Latex in Supermongo

Latex comes in handy for professional looking labels.  There are a few examples in my macros, but a comprehensive (also known as more than you ever needed) list of latex symbols can be found here. Make sure to enable the Tex_strings variable in your .sm file.

Quadratic LSQ Fitting

For those of you trying to find a quadratic least squares fit, in Supermongo: I have looked all over the web for one and could not find a macro to do this.  Eventually, I ended up writing this macro to do the job.  It includes a little macro to test/illustrate fitting a parabola named test.  Feel free to use this, but please leave the 'credits' attached.

Comparing String values

I was having some problems doing logic on string variables, but I found the following to work quite well.  The single quotes are the important things here.
define name word3
FOREACH v (word1 word2){
     if ('$name'=='$v'){
           define axis .003
      } }



BASIC SUPERMONGO COMMANDS     (top)

help COMMAND
Use this to get help on commands from the SM prompt!

#i am a comment
The all important comment indicator.

echo Hello world!
Prints "Hello world!" to the terminal.

define VAR 1.235
Defines a string variable with a value or expression, referenced with $VAR.

set VAR=-5.2
Defines a numeric variable (1 by 1 array) to the value of -5.2.  Reference the variable by $(VAR[0]).

set VEC=VEC*2
Defines each element of vector VEC to be twice the value of each element of VEC.

set VEC[21]=-5.26*pi
Defines only one element of a vector.

erase
Clears the x11 graph window.

quit
Exit Supermongo.

delete  VEC
Deletes a vector/variable stored in Supermongo.

set VEC=VEC**2
Exponential notation.

set VEC=lg (VEC)
set VAR=lg($(VAR[0])
Takes the logarithm (base 10) of entire vector/variable.


set dimen(VEC)=10
Define the dimension of a vector to be 10.  DIMEN(VEC) can also be used as a variable with a value of 10 (in this case).  This works well as the upper bound for DO loops:  DO i=0, dimen(VEC)-1,1.


BASIC GRAPHING     (top)

expand 1.001
Expands all of the fonts to 1.001 their original size.  Any value except 1 will stop SM from using the machine font.

window 3 2 1 1
Defines a 3 by 2 array of windows, currently specifying the bottom-left (x=1 y=1) window.
 x=1 y=2   |   x=2 y=2   |   x=3 y=2
--------------|---------------|---------------
 x=1 y=1   |   x=2 y=1   |   x=3 y=1

location 3500 15500 18500 31000
Sets the X and Y location for drawing a graph, can be used instead of WINDOW for greater control.
For a simple shortcut: see my macro where I define a 4 plot or 6 plot window layouts.

xlabel log [r/r_{200}]
Label the X axis.   Latex works well here.
Are you having trouble moving the axis closer or further from the numeric labels?  Me too.  I wrote a macro titled xlabel2 to allow more flexibility, however, your label will need to be enclosed in "". This would be called as: xlabel2 50 -10 "xlabel".

ylabel log [10^y]
Label the Y axis.  Latex works well here.
To get more flexibility with positioning, see my macro ylabel2.  However, your label will need to be enclosed in "". This would be called as: ylabel2 50 -10 "ylabel".

toplabel FILE: $(VAR[0])   
Label the top of the page.  Again, use Latex if you wish.

relocate -4 -1.15        
relocate (14500 14500)
Relocates the cursor to the specified graph coordinates or SM coordinates.  This gives more control than xlabel or ylabel, and can place labels anywhere on the SM plot.

move 5 15 This example uses the SM defined limits to place a label at 5% of the x axis and 15% of the y axis.  This places a label in a graph, and keeps it there, even while the limits are changing.  This is one of my macros, you will have to define the macro as well.

label \beta_{fit}  = $(VAR[0])
Places a label at the place specified by RELOCATE.

limits -4.5 2.0 -2 4      
limits XVEC YVEC
Sets the limits of the graph in a definite interval or an interval determined by the bounds of the x and y vectors.

box
Draws the box and axis.  For more details, follow the link.

ptype 1 1
Defines the type of point to use when using POINTS.  1 1 is the default for points, 4 1 defines crosses.

points XVEC (YVEC+2*0)
Plots the points in the vectors XVEC and YVEC.

ltype 0
Defines the line type for connecting points, drawing lines.  0:solid, 1:dot, 2:dash, etc.

lweight 1
Defines the weight of the line, 1 is default.  A higher value defines a stronger line.

ctype magenta
Defines the color of the line, points, and text.  Default colors are: black, white, blue, green, red, yellow, magenta, and cyan.  Also, define your own color with the add_ctype command (see below).

con XVEC (YVEC+2*0)
Connects the points in vectors XVEC and (YVEC+2*0) with the aforementioned line color, style, and weight.

lsq xin yin xin yout rms
Do a Least Squares Fit to vectors xin and yin.  This will create a new vector, yout with the LSQ fit, and a RMS variable.


DO AND IF LOOPS     (top)

do z=5093,5142, 1{ 
     COMMANDS    }
DO loop syntax:  to reference the value of z in the loop, use $z  (unlike set-defined variable references $(var[0])

if ( (iii[$j]>r)&&(i[$j]<r) ){
     COMMANDS }
IF loop syntax.


INPUT/ OUTPUT     (top)

dev postfile "/home/file.ps"
Changes the device to a postscript file.  Other types of postscript outputs are listed a ways down in this link.

dev PRINTERNAME
Changes the device to a specific printer.

data "/home/file.dat"
Specify a file to read.

read {VEC1 5 VEC2 6 VEC3 7}
Read columns 5, 6, and 7 from "/home/file.dat" into vectors named VEC1, VEC2, VEC3.
To read in a specific format (even strings), place a ."specifier" right after the column number to be read in.  Example:  read {vec1 1 vec2 2.s vec3 3.g vec4 4.i}.  Here column 1 is read as default, 2 as string values, 3 as floating point, and 4 as integers.
dev x11
Change the output device to the default x11 graph window.

write "/home/$!num/fits_avg.dat" $num $(facto[0]) $(beta[0])
Writes a line to the specified file.  Use WRITE + to append.  Use this in a DO loop to write specific lines.  If you write to the same file multiple times (without opening a different file in between calls), your file should be automatically appended.  Thus, to make sure that a file is replaced, open a different file right before:
   write "delete_me.txt"             #opens a different file, causing the replacement
#of out1.txt upon next write command.
   write "out1.txt"                      #starts the file out1.txt from scratch!!
   write + "out1.txt"                   #appends out1.txt.


MACROS      (top)

macro read "/home/.smstuff/start.sm"
Load and read a macro from a file.

macro1 1 $z $(var[0])
Execute "macro1" with 3 input parameters: 1 specific value, 1 DEFINEd variable, and one SET-defined variable.

define VAR $1
If your macro has arguments (values or vectors passed to it when it was called), you can use this command in your macro to reference the first argument $1 and rename it to VAR. To reference VAR in the macro, use $VAR.  This can be a numeric variable.
Also, vectors and variable do not have to be directly passed to a macro. Once it is defined, all macros can see/reference it. Though, be careful when the macros become complicated; make sure you know which macro set/altered that variable last.


MISCELLANEOUS     (top)

set facto=sprintf ('%5.2f',facto)
Formats a variable or vector using C format strings.

bell
Causes the computer to beep, does not work on all systems.

list set
List all of the defined vectors (and variables defined with SET).

cursor
Saves the position of the cursor, but works well to pause your macro until you click on the x11 graph window.

add_ctype darkgreen 5 155 5
Create a new color, here dark green, by specifying 3 numbers from 0 to 256 (list of colors).
Also, I automatically define extra colors every time I start SM in this macro.