general/mini/
calc.pro
Procedure: calc Purpose: This routine takes a string as input and interprets the string as a mini-language. This language can manipulate normal idl variables and tplot variables. The idl variables that can be modified are non-system variables in the scope in which the procedure is called. Inputs: s : A string that will be interpreted as the mini language Keywords: error: If an error occurs during processing this keyword will return a struct that contains information about the error. If error is set at time of input this routine will set it to undefined, before it interprets 's' to prevent internal errors. Note that setting this keyword will supress automatic printing of errors unless the verbose keyword is set. function_list: return an array of strings that lists of the names/syntax of available functions in the mini_language. Return without processing 's' if an argument in the returned name is in brackets it is optional for example: min(x[,dim]) operator_list: return an array of strings that lists of the names of available operators in the mini_language. Return without processing 's' verbose: set this keyword if you want the routine to print errors to screen when you are using the error keyword. quiet: set this keyword to supress printing of errors to the screen at all times. gui_data_obj: If 'calc' is being used inside the gui, then the loaded_data object will be passed in through this keyword. NOTE: end users should not even set this argument. replay: if 'calc' is being used from the GUI, this keyword is set when the GUI is replaying a document. Users shouldn't set this keyword manually overwrite_selections: tracking the user's selections to overwrite tplot variables that already exist. Users shouldn't set this keyword manually statusbar: the status bar object will be passed through this keyword. Users shouldn't set this keyword manually historywin: the history window object will be passed through this keyword. Users shouldn't set this keyword manually gui_id: the top level GUI widget ID -- for prompting the user for overwrites in the GUI. Users shouldn't set this keyword manually interpolate: Set this to the name of the tplot variable that you'd like to interpolate data to. If you set this keyword to 1(ex /interpolate), but don't name a specific variable, it will interpolate to the left-most variable in each binary operation. This second way of using this keyword should be used carefully in complicated expressions, as it may not be obvious which interpolation operations are being performed nan: Deprecated. Use /nan keyword to functions cumulative_total: Deprecated. Use /cumulative keyword to total function. Outputs: none, but it will modify various variables in your environment Examples: calc,'a = 5' calc,'"pos_re" = "tha_state_pos"/6374' calc,'a += 7',/v ;abbreviated verbose keyword calc,'"tvar" = "tvar" + var' calc,'"tvar" = ln("tvar")' calc,'"tvar" = total("tvar"+3,2)' calc,'"tvar" = -a + 5.43e-7 ^ ("thb_fgs_dsl_x" / total("thb_fgs_dsl_x")) calc,operator_list=o,function_list=f calc,'"th?_state_pos_re" = "th?_state_pos"/6374.4' ;globbing Notes: 1. The language generally uses a fairly straightforward computational syntax. The main difference from idl is that quoted strings are treated as tplot variables in this language 2. A full specification of language syntax in backus-naur form can be found in the file bnf_formal.txt, the programmatic specification of this syntax can be found in productions.pro 3. The language is parsed using an slr parser. The tables required to do this parsing are generated and stored ahead of time in the file grammar.sav and parse_tables.sav 4. The routines that describe the evaluation rules for the language can be found in the file mini_routines.pro 5. If you want to modify the way the language works you'll probably need to modify productions.pro, regenerate the slr parse tables using save_calc_tables and modify/add routines to mini_routines.pro 6. Arrays must have the same dimensions to be combines, and tplot variables must also have the same times. 7. Procedures: min,max,mean,median,count,total all take a second argument that allow you to select the dimension over which the operation is performed 8. Calc supports globbing in tplot variable operands, but for it to work, the output variable also needs to be a tplot variable with the same number of glob characters. Correct: calc,'"th?_state_pos_re" = "th?_state_pos"/6374.4' Incorrect: calc,'tha_state_pos_re = "th?_state_pos"/6374.4' Incorrect: calc,'"th?_state_pos_re" = "th?_state_*"/6374.4' See Also: All routines in the ssl_general/mini directory The techniques used for this interpreter are based on two books: 1. Compilers:Principles,Techniques,and Tools by Aho,Sethi,& Ullman 1986 (esp. Ch3(for lexical analysis) & Ch4(for SLR parser design)) 2. Structure & Interpretation of Computer Programs by Abelson & Sussman 1996 (esp. Ch4(evaluators & meta-circular evaluator)) If you want to understand/modify this program it may help to use these books as a reference. Also see: thm_crib_calc.pro for examples of usage ToDo: 1. Implement 0 argument functions 2. Implement keywords for functions 3. Implement procedures 4. Implement control statements $LastChangedBy: aaflores $ $LastChangedDate: 2014-05-06 10:41:49 -0700 (Tue, 06 May 2014) $ $LastChangedRevision: 15055 $ $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/trunk/general/mini/calc.pro $
Routines
top source calc
calc, s, error=error, function_list=function_list, operator_list=operator_list, verbose=verbose, gui_data_obj=gui_data_obj, interpolate=interpolate, quiet=quiet, replay=replay, overwrite_selections=overwrite_selections, overwrite_count=overwrite_count, statusbar=statusbar, historywin=historywin, gui_id=gui_id, calc_prompt_obj=calc_prompt_obj, nan=nan, cumulative_total=cumulative_total, _extra=_extra
Parameters
- s
Keywords
- error
- function_list
- operator_list
- verbose
- gui_data_obj
- interpolate
- quiet
- replay
- overwrite_selections
- overwrite_count
- statusbar
- historywin
- gui_id
- calc_prompt_obj
- nan
- cumulative_total
- _extra
File attributes
Modification date: | Mon May 12 22:33:57 2014 |
Lines: | 133 |