evaluates CHARACTER strings containing FORTRAN-like expressions and
returns numeric and string values.
The primary routine JUCALC acts like a powerful desk-top
calculator. It supports named variables and has several arrays of
55555 elements each. Many standard FORTRAN functions are available,
plus access to user-written functions is permitted via the
user-supplied routine JUOWN1().
Using this interface it is easy to make free-format and
order-independent input interfaces where values can be expressions
and variable names instead of simple formatted numbers.
The programmer (generally) uses just the JUCALC routine or several
convenience routines (INUM0, RNUM0, SNUM0, STRGAR2, JUCALCX) that
simplify making the most common type of calls to JUCALC.
The library is written in FORTRAN.
The calculator library is composed of the following routines:
is the main calculator interface. All other routines are internal
routines that the user does not (generally) call directly or routines
that simplify making the most common forms of calls to JUCALC.
- JUPARS crack out the parenthesis and pass each subexpression to JFUNS or JUARGS
- JUFUNS processes function call strings of form "fun(a1,a2,a3,...pi)"
- STUFFTOK stores a string being returned by a function into the string dictionary
- JUARGS separates a list of expressions that do not contain parenthesis and passes them to JUCALS
- JUCALS resolve a single expression into a value and restring it
- JUPOWS process power expressions "a**b" in expressions from JUCALS
- JUFACS process multiplies and divides in expressions from JUCALS
- JUATOR return a REAL value from a numeric string
- JURTOA return a numeric string from a REAL value
- JUSQES removes spaces and tokenizes strings before the calculator starts to crack the input expression.
- JUBOUS find where a new variable name should be stored or where an old name and it's associated value can be found
- JUADDR Add a new variable name and it's value to the dictionary.
- JUADDS add a new string variable and it's value to the string dictionary
- JUATOA given a string variable name return it's value
- JUFIND given a function name find the line JUFUNS() should go to
- STUFF directly store a value into calculator variable name table. This routine can be directly called when need warrants.
- STUFFA directly store a string into calculator variable name table This routine can be directly called when need warrants.
- BLOCKDATA JUINIT
The BLOCKDATA defines the commons used to hold the X,Y,$X
$Y, ... arrays and the dictionaries of variable names and
string names and their associated values.
returns the results of evaluating an expression but in addition
it displays error messages and other information. It calls
JUCALC to evaluate the expression.
returns an array of numeric values from a list of expressions
by separating the expressions and calling jucalcx.
returns an integer value from an expression by calling jucalcx.
is a function that
returns a REAL value from an expression by calling jucalcx.
is a function that
returns a CHARACTER value from an expression by calling jucalcx.
A summary of the syntax rules for the expressions follows:
- The hierarchy of
operations is the same as that of FORTRAN except that adjacent
exponents are done from left to right, not right to
left [i.e. in FORTRAN 3**2**4=3**(2**4), in JUCALC
3**2**4=(3**2)**4]; and +- strings are resolved to a single sign
(that is, 3+ -4 is acceptable instead of 3+(-4)).
- The JUCALC routine provides almost all the ANSI mathematical
functions available in FORTRAN, as well as access to common
extensions and user-written routines.
- Embedded blanks are ignored during the processing of a calculation.
- All numeric values are treated as FORTRAN type REAL variables.
- Input lines should not normally be over 80 characters long, although
255 is now supported.
- There are three ways to store results to be used in future calculations:
Each of the types will be discussed separately.
- Variable names
- The current-value
- The x and y arrays
- VARIABLE NAMES
Names must be 1 to 20 characters long, and are
case-sensitive. Up to 2345 names are permitted. Numeric variable names
should be composed of the letters a-z and underscores and numbers.
String variables are similar but start with a dollar sign($).
Names must not end in a "digit-E" combination. For example:
Variables may be defined by equating them to an expression. To define
or redefine a variable called FRED, simply enter:
The last value assigned to a variable will be used to evaluate the
expression on the left of the equals sign when this expression
redefines the variable. For example:
To allow FORTRAN-type E-format numeric entry and yet not cause the
calculator routine to do an excessive amount of checking, a variable
name ending in the letter E must not have a digit (012345789) in front
of that ending E. Attempting to define such a variable name will
produce an error. This limitation prevents the calculator from
becoming confused by whether 12E+3 is a variable called 12E plus 3
or the exponential number 12E3=12000.
- CURRENT VALUE
The variable name '?' is automatically set by the program to contain
the last calculated value. This current-value register may be used
like any variable or number. It is 0 at program initialization.
- THE X AND Y ARRAYS
Two arrays called X and Y are available that can contain up to 55555
values each. The arrays are originally initialized to all zeros.
To set values in the arrays, use the xstore (or ystore) command. The
format of the commands is
where start=array address to start storing at
and ex(i) are expressions.
The current value is assigned the last value stored.
In addition there are similar string arrays and functions that can
hold up to 50 255-character strings:
For example, to store into the locations 10,11,and 12 the values
1/10,2/10, and 3/10, the following could be entered:
- $nstore(), $xstore(), $ystore()
- $n() ,$x() ,$y()
xstore( 10 , 1/10 , 2/20 , 3/10 )
*-------Start storing evaluated expressions sequentially,
beginning at x(10).
- REFERENCING AN ARRAY VALUE
The values stored into the arrays may be referenced by subscript. For
- x and y array values cannot be used on the left of equal signs.
x(10)=5 # IS ILLEGAL
- The current value is set to the value of the last expression
by the xstore and ystore commands
- AVAILABLE FUNCTIONS
- ANSI FORTRAN INTRINSIC MATH FUNCTIONS
The majority of intrinisic Fortran numeric functions are available.
At a minimum the following are available:
| abs || acos || aint || anint || asin
| atan || atan2 || cos || cosh || dim
| exp || frac || hypot || int || log
| log10 || max || min || mod || nint
| real || sign || sin || sinh || sqrt
| tan || tanh || || ||
|| asinh || acosh || atanh || ||
A full description of the ANSI FORTRAN Functions is available in
The ANSI FORTRAN function supplement
- r2d(arg) - converts from radians to degrees
- d2r(arg) - converts from degrees to radians
- f2c() - convert Fahrenheit to Celsius
- c2f() - convert Celsius to Fahrenheit
- ge(val1,val2) - return TRUE if VAL1 is greater than or equal to VAL2, else return FALSE
- gt(val1,val2) - return TRUE if VAL1 is greater than to VAL2, else return FALSE
- eq(val1,val2) - return TRUE if VAL1 is equal to VAL2, else return FALSE
- le(val1,val2) - return TRUE if VAL1 is less than or equal to VAL2, else return FALSE
- lt(val1,val2) - return TRUE if VAL1 is less than VAL2, else return FALSE
- ne(val1,val2) - return TRUE if VAL1 is not equal to VAL2, else return FALSE
- if(expression,val1,val2) - If expression is TRUE, return VAL1 else return VAL2
means return a if b is greater than or equal to c else return d.
lexical logical functions
- lge($str1,$str2) - return TRUE if $STR1 is lexically greater than or equal to $STR2, else return FALSE
- lgt($str1,$str2) - return TRUE if $STR1 is lexically greater than to $STR2, else return FALSE
- leq($str1,$strN) - return TRUE if $STR1 is lexically equal to any of the other strings, else return FALSE
- lle($str1,$str2) - return TRUE if $STR1 is lexically less than or equal to $STR2, else return FALSE
- llt($str1,$str2) - return TRUE if $STR1 is lexically less than $STR2, else return FALSE
- lne($str1,$strN) - return TRUE if $STR1 is not equal to all following strings.
- $if(expression,$str1,$str2) - If expression is TRUE, return $STR1 else return $STR2
- ownmode() - ownmode(1) enables calls to user-supplied functions via JUOWN1() and C() routines.
- c(val1) - user-supplied
- ceiling(val1) - ceiling()(or ceil()) returns the least integral value greater than or equal to VAL1.
- floor(val1) - floor() returns the greatest integral value less than or equal to VAL1.
- in(val1,val2,val3) - returns TRUE if VAL1 is between VAL2 and VAL3 else returns FALSE
- round(val1,val2) - round VAL1 to VAL2 significant digits. Warning: this function is not ready yet.
- same(x1,x2,idigits) - test if X1 and X2 are the same out to IDIGITS digits. 0=TRUE.
- $change($str1,"c/old/new") - substring substitution
- $char(v1,v2,....) - return characters indicated by numeric ADE (ASCII decimal equivalent) values passed.
- delimx(istore,$str1,$delimiters) - parse string into tokens in array $x()
- $f(fortran_format,value) - create string from value using specified Fortran FORMAT statement
- ichar($char) - return the ADE (ASCII Decimal Equivalent) value of a letter
- index($str1,$str2) - return column number where $str2 begins in $str1 or zero(0).
- $l($str1) - convert string to lowercase
- len($str1) - return the length of the string
- $matchw($expression,$string) - simple wild-card match of a string
- $modif($str1,$directive) - modify a string
- $(ex,ex,ex,...) or $str(ex,ex,ex,...) - generate a string from a series of
strings and numbers. The expressions may be numeric or string.
- str(ex,ex,ex,...) - same as $str() but convert resulting string to a number IF the string is a simple numeric value
- $substr(string,i,j) - return a string that is columns i thru j of the input string (first
character is called column 1).
- $u($str1) - convert string to uppercase
- ye() - return year
- mo() - return month
- da() - return day of month
- ho() - return hour (0 -23)
- mi() - return minute
- se() - return second
- dw() - days since Sunday (0 - 6)
- ju() - days since January 1st (0 - 365)
- $dw([0-7]) - day of week as a string
- $mo([1-12]) - month as a string
- rand([itype]) - return random number from 0.0 to 1.0
- srand(number[,itype]) - set seed for rand(). Seeds should be whole numbers
If ITYPE is present different algorithms are used. The system routines vary from
platform to platform. The preferred algorithm is the "Numerical Recipes" algorithm.
The ITYPE must agree between the SRAND() call and the RAND() call. A call to SRAND()
should precede use of RAND().
- The system C routine rand()
- The Fortran intrinsic RANDOM_NUMBER()
- The algorithm purchased from Numerical Recipes
This routine (RAN_MOD()), is a modified version of routine RAN1() from the book
"Numerical Recipes in FORTRAN" (Cambridge University Press),
Copyright (C) 1986, 1992 by Numerical Recipes Software. Used by
permission. Use of this routine other than as an integral part of
BELOCA-related programs requires an additional license from Numerical Recipes
Software. Further distribution in any form is prohibited.
RAN_MOD() is a "MINIMUM" random number generator of Park and Miller
with Bays-Durham shuffle and added safeguards. It returns uniform random
deviates between 0.0 and 1.0 (exclusive of the endpoint values).
Do not alter the seed between successive deviates in a sequence.
- MISCELLANEOUS COMMANDS
- Displaying variable values: dump
The current value and all defined variable names are displayed via
the dump command.
- Listing Available Functions: funcs
A display of all available functions can be obtained when
executing JUCALC by entering the command 'funcs'. No descriptions
- REVISION RECORD
Changes regarding variable names ending in letter E. Previously
variable names could not safely end in the letter E. The previous
version of the calculator would be confused by whether 12E+3 is a
variable called 12E plus 3 or the exponential number 12E3=12000).If
all occurrences of the variable name are placed in brackets, this
limitation could be ignored; but typographical errors would be harder
to diagnose. With this understanding, the following was acceptable:
This restriction no longer applies
Placed calculator on UNICOS (Already on VMS,NOS,NOS/VE,COS,and several