| 22 | | |
| 23 | | where (expression) is some math expression. The math expression may consist of the standard math operators (+,-,*,/) as well as any already-defined variables and the functions log(), ln(), sqrt(), exp(), ten() (10x), sin(), cos(), etc. Other special operators are the carret (^) for exponetiation (eg, 2^3 is 8) and the @ symbol as a binary arc-tangent (eg, 1@3 is 18.43 degrees). In addition, the operator << returns the minimum of the two surrounding values, and >> returns the maximum. Variables can be numeric or character strings. If the shell does not understand the syntax of the line as a math expression, it is assumed to be a string. local variables |
| 24 | | |
| 25 | | If there is a pair of curly brackets {} anywhere on a command line, whatever is inside is assumed to be a math expression and evaluated before the line is executed. This later feature allows functions of variables to be passed as arguments to Opihi functions. (see also the discussion below about temporary vectors and images). For example: |
| 26 | | |
| | 23 | }}} |
| | 24 | where (expression) is some math expression. The math expression may consist of the standard math operators `(+,-,*,/)` as well as any already-defined variables and the functions `log(), ln(), sqrt(), exp(), ten() (10x), sin(), cos(),` etc. Other special operators are the carret (`^`) for exponetiation (eg, `2^3` is 8) and the `@` symbol as a binary arc-tangent (eg, `1@3` is 18.43 degrees). In addition, the operator `<<` returns the minimum of the two surrounding values, and `>>` returns the maximum. Variables can be numeric or character strings. If the shell does not understand the syntax of the line as a math expression, it is assumed to be a string. local variables |
| | 25 | |
| | 26 | If there is a pair of curly brackets `{}` anywhere on a command line, whatever is inside is assumed to be a math expression and evaluated before the line is executed. This later feature allows functions of variables to be passed as arguments to Opihi functions. (see also the discussion below about temporary vectors and images). For example: |
| | 27 | |
| | 28 | {{{ |
| 28 | | |
| 29 | | would give the response 7.07107 if $fred had the value of 10.0. There are math functions cos, sin, and tan, which operate on radian expressions, and also dcos, dsin, dtan, which operate on degree expressions. There are also the equivalent inverse functions: eg., asin and dasin return radians and degrees, respectively. The help section on Math defines all of the available math functions. |
| | 30 | }}} |
| | 31 | would give the response 7.07107 if `$fred` had the value of 10.0. There are math functions `cos, sin,` and `tan`, which operate on radian expressions, and also `dcos, dsin, dtan,` which operate on degree expressions. There are also the equivalent inverse functions: eg., `asin` and `dasin` return radians and degrees, respectively. The help section on Math defines all of the available math functions. |
| 129 | | |
| 130 | | |
| 131 | | There are several options for programming in the opihi shell. First, a file which contains a series of commands can be executed with input (filename). When an opihi-based program is started, it loads a file from the user's home directory, with a name of the form ~/.programrc. This resource file may contain any commands, and allows a user to customize his or her environment. |
| 132 | | |
| 133 | | It is also possible to define macros which will behave much like regular commands. A macro is defined by typing macro name or macro create name followed by the commands. Arguments to the macro are assigned to the variables $1 .. $N and the number of arguments is given by $0. Macros may be defined in input files. The following is a sample macro: |
| 134 | | |
| | 140 | }}} |
| | 141 | |
| | 142 | There are several options for programming in the opihi shell. First, a file which contains a series of commands can be executed with input (filename). When an opihi-based program (e.g. dvo) is started, it loads a file from the user's home directory, with a name of the form `~/.programrc` (e.g. `~/.dvorc`). This resource file may contain any commands, and allows a user to customize his or her environment. |
| | 143 | |
| | 144 | It is also possible to define macros which will behave much like regular commands. A macro is defined by typing macro name or macro create name followed by the commands. Arguments to the macro are assigned to the variables `$1 .. $N` and the number of arguments is given by $0. Macros may be defined in input files. The following is a sample macro: |
| | 145 | |
| | 146 | {{{ |
| 143 | | |
| 144 | | == Flow Control == |
| 145 | | |
| 146 | | Opihi has several types of flow-control features. These include for-loops, while-loops, if-else blocks. These blocks are defined by the corresponding command (for, while, if) and are terminated with by a line with the single word end. |
| 147 | | |
| 148 | | === For loops === |
| 149 | | |
| 150 | | The for-loop syntax is simplistic. The for command specifies the loop variable, the starting value, the ending value, and optionally the delta for each loop. The implicit loop test is always to check if the loop variable is still less than the end value (or greater than if the delta value is negative). The definitions of this loop syntax and the value of the list length ($list:n) and the vector length (vector[]) make for natural loops over all elements of a list or vector. Below are a few examples: |
| 151 | | |
| | 155 | }}} |
| | 156 | === Flow Control === |
| | 157 | |
| | 158 | Opihi has several types of flow-control features. These include for-loops, while-loops, if-else blocks. These blocks are defined by the corresponding command (`for, while, if`) and are terminated with by a line with the single word `end`. |
| | 159 | |
| | 160 | ==== For loops === |
| | 161 | |
| | 162 | The for-loop syntax is simplistic. The for command specifies the loop variable, the starting value, the ending value, and optionally the delta for each loop. The implicit loop test is always to check if the loop variable is still less than the end value (or greater than if the delta value is negative). The definitions of this loop syntax and the value of the list length (`$list:n`) and the vector length (`vector[]`) make for natural loops over all elements of a list or vector. Below are a few examples: |
| | 163 | |
| | 164 | {{{ |
| 212 | | |
| 213 | | |
| 214 | | Most of these commands should be clear from the simple descriptions above, or from the online help. The command ?? prints the system variables. The help command will provide help on a single command or, without any arguments, will list all available help files (this includes general help not associated with a specific command). |
| 215 | | |
| 216 | | == String Manipulation and other data commands == |
| 217 | | |
| | 225 | }}} |
| | 226 | Most of these commands should be clear from the simple descriptions above, or from the online help. The command `??` prints the system variables. The help command will provide help on a single command or, without any arguments, will list all available help files (this includes general help not associated with a specific command). |
| | 227 | |
| | 228 | === String Manipulation and other data commands === |
| | 229 | |
| | 230 | {{{ |
| 226 | | |
| 227 | | |
| 228 | | These commands provide a few tools to manipulate data in opihi variables. The #local/# command specifies that the given variable is local to its macro. The #output/# command changes the default output destination for functions which print results to the screen. This function does not zero the file length; new output is appended to the file. The command #scan/# reads specific lines from a file, an optionally places them in an opihi variable (EOF is returned at the end of a file). The group of commands #getchr/#, #strlen/#, and #substr/# provide the ability to manipulate the elements of a string. Finally, #sprintf/# and #fprintf/# perform formatted output to a variable and to the screen, respectively. |
| 229 | | |
| 230 | | == Graphing and the Kapa Display == |
| 231 | | |
| | 239 | }}} |
| | 240 | These commands provide a few tools to manipulate data in opihi variables. The `local/` command specifies that the given variable is local to its macro. The `output/` command changes the default output destination for functions which print results to the screen. This function does not zero the file length; new output is appended to the file. The command `scan/` reads specific lines from a file, an optionally places them in an opihi variable (EOF is returned at the end of a file). The group of commands `getchr/`, `strlen/`, and `substr/` provide the ability to manipulate the elements of a string. Finally, `sprintf/` and `fprintf/` perform formatted output to a variable and to the screen, respectively. |
| | 241 | |
| | 242 | == Math, Graphing and the Kapa Display == |
| | 243 | |
| | 244 | {{{ |
| 259 | | |
| 260 | | |
| 261 | | The above will create a histogram of y in Ny and the index in dx. Plotting this with plot dx Ny will show the histogram. |
| 262 | | |
| 263 | | Vector math is performed with a command of the form set new = (expression). The expression is some math function employing vectors and scalars. A complete listing of the math operators available in set can be found in the help for set. |
| 264 | | |
| 265 | | Once vectors are defined, they may be plotted. A pair of vectors can be plotted against each other if they have the same number of entries. The plotting is performed on the graphics window, Kapa. There are actually several graphics windows available to status, any of which may be used to plot at any time. Some of the more complex operations default to either graphics window 0 or 1, depending on the context. Except for those functions with a pre-defined window, all plotting functions apply to the current graphics window unless an option -n N is given to specify a different window. The plotting style is determined by the command style which can set the line width, the line type (solid, dashed, dotted, etc), the point type (box, cross, etc), the point size, the color, and whether a pair of vectors is plotted as a sequence of points, a set of connected lines, or a histogram. Some functions which make plots use their own styles, as discussed below. The function limits lets the user set the range of the plot axes, or check the current setting. The command plot will plot a pair of vectors on the current graphics window using the current plotting style for that window. The command zplot will plot a pair of vectors with the point size scaled by a third vector, with maximum and minimum point sizes representing specified values. The cursor command goes the other way: this command puts the Kapa window in cursor mode and waits for input from Kapa. The user can then type any alphanumeric key on the graphics windows and will be told both the pointer location (in the graphics coordinates) and will have the coordinates stored in status variables. For example, by typing ``1'' in the sky display window, the RA and DEC of the pointer are stored in the variables $R1 and $D1. This command can be used to let the user define locations or regions of interest on the Kapa window. (Future addition: button, which does the same with the mouse buttons). |
| 266 | | |
| | 274 | }}} |
| | 275 | The above will create a histogram of y in Ny and the index in dx. Plotting this with `plot dx Ny` will show the histogram. |
| | 276 | |
| | 277 | Vector math is performed with a command of the form `set new = (expression)`. The expression is some math function employing vectors and scalars. A complete listing of the math operators available in set can be found in the help for set. |
| | 278 | |
| | 279 | === Plotting === |
| | 280 | |
| | 281 | Once vectors are defined, they may be plotted. A pair of vectors can be plotted against each other if they have the same number of entries. The plotting is performed on the graphics window, Kapa. There are actually several graphics windows available to status, any of which may be used to plot at any time. Some of the more complex operations default to either graphics window 0 or 1, depending on the context. Except for those functions with a pre-defined window, all plotting functions apply to the current graphics window unless an option `-n N` is given to specify a different window. |
| | 282 | |
| | 283 | The plotting style is determined by the command style which can set the line width, the line type (solid, dashed, dotted, etc), the point type (box, cross, etc), the point size, the color, and whether a pair of vectors is plotted as a sequence of points, a set of connected lines, or a histogram. Some functions which make plots use their own styles, as discussed below. The function limits lets the user set the range of the plot axes, or check the current setting. |
| | 284 | * The command `plot` will plot a pair of vectors on the current graphics window using the current plotting style for that window. |
| | 285 | * The command `zplot` will plot a pair of vectors with the point size scaled by a third vector, with maximum and minimum point sizes representing specified values. |
| | 286 | * The `cursor` command goes the other way: this command puts the Kapa window in cursor mode and waits for input from Kapa. The user can then type any alphanumeric key on the graphics windows and will be told both the pointer location (in the graphics coordinates) and will have the coordinates stored in status variables. For example, by typing `1` in the sky display window, the RA and DEC of the pointer are stored in the variables `$R1` and `$D1`. This command can be used to let the user define locations or regions of interest on the Kapa window. (Future addition: button, which does the same with the mouse buttons). |
| | 287 | |
| | 288 | {{{ |
| 280 | | == 2D Data and the Image Displays == |
| 281 | | |
| 282 | | Opihi has many commands to manipulate 2-D data (images). Images can be loaded from FITS files and mathematical operations applied to them. Various other operations, such as rebinning, shifting, rotating, and so forth are also available. Images can be displayed using the Kii image window. In an 8-bit visual, the image window has a dynamic colormap to allow the user to change the relationship between pixel value and the displayed color. There are three colormaps which can be selected by pressing the middle three buttons on the bottom row. The PS button produces a PostScript file from the image. The user can change the magnification and the position of the image with the mouse (left - recenter at cursor; middle - zoom out; right - zoom in). There are four color overlays which the user can draw objects of different shapes (circles, boxes, lines) or draw a contour. The four buttons labeled R, G, B, Y turn on or off the display of the red, green, blue, and yellow overlays. |
| 283 | | Image Manipulation Functions |
| 284 | | |
| | 302 | === 2D Data and the Image Displays === |
| | 303 | |
| | 304 | Opihi has many commands to manipulate 2-D data (images). Images can be loaded from FITS files and mathematical operations applied to them. Various other operations, such as rebinning, shifting, rotating, and so forth are also available. Images can be displayed using the Kii image window. In an 8-bit visual, the image window has a dynamic colormap to allow the user to change the relationship between pixel value and the displayed color. |
| | 305 | * There are three colormaps which can be selected by pressing the middle three buttons on the bottom row. The PS button produces a PostScript file from the image. |
| | 306 | * The user can change the magnification and the position of the image with the mouse (left - recenter at cursor; middle - zoom out; right - zoom in). |
| | 307 | * There are four color overlays which the user can draw objects of different shapes (circles, boxes, lines) or draw a contour. The four buttons labeled R, G, B, Y turn on or off the display of the red, green, blue, and yellow overlays. |
| | 308 | |
| | 309 | === Image Manipulation Functions === |
| | 310 | |
| | 311 | {{{ |