This HTML automatically generated with rman for NEMO
Table of Contents

Name

nemoinp, natof, natoi, atox - decode and parse string into reals, integers, logicals, sexagesimal

Synopsis


int nemoinpd (expr,doutv,nout)
int nemoinpf (expr,foutv,nout)
int nemoinpr (expr,routv,nout)
int nemoinpi (expr,ioutv,nout)
int nemoinpl (expr,loutv,nout)
int nemoinpb (expr,boutv,nout)
int nemoinpx (expr,doutv,nout)
int nemorinpi (string var, int    *xvar,  int n, int    defvar, bool repeated)
int nemorinpd (string var, double *xvar,  int n, double defvar, bool repeated)
int nemorinpf (string var, float  *xvar,  int n, float  defvar, bool repeated)
int nemorinpl (string var, long   *xvar,  int n, long   defvar, bool repeated)
int nemorinpb (string var, int    *xvar,  int n, bool   defvar, bool repeated)
double natof(expr)
int  natoi(expr)
double atox(expr)
char *expr;
double doutv[];
float  foutv[];
real   routv[];
int    ioutv[];
long   loutv[];
bool   boutv[];
int    nout;

Description

nemoinp*(3NEMO) parses the input character string Xexpr into a list of basic C-data structure items, pointed to by Xoutv. The input string must be comma, space or colon separated (TABs are considered dangerous). A colon is used as an implied do-loop, where the first number is the starting value, the second the ending value, and an optional increment (which defaults to 1). Hence the format is s:e[:i]. A repeat facility is also built in by using the double colon, and has the format v::n, the number v is repeated n times. nout is the declared length of Xoutv. In case of success nemoinpX returns the actual number of items returned in Xoutv, otherwise it returns a negative error code (see herinp(3NEMO) . A 0 return code means nothing was present in the expr string, in which case preset defaults must be assumed.

For convenience, NEMO parsing versions of the standard C library atof(3) and atoi(3) are provided as natof() and natoi(), but they do not provide any error checking (most importantly if the string contains non-number parts, except for the string "NaN" or "nan" in natof() where it will return the appropriate IEEE nan value).

atox provides the Babylonian sexagesimal (D:M:S) conversion to D+M/60+S/3600 conversion, but without any error checking. The user is still responsible for units, e.g. it does not know how to distinguish between H:M:S and D:M:S.

An expression can have basic mathematical functions, such as addition, most transcendental functions and even some mathematical and physical constants. See also herinp(3NEMO) .

The only exception to herinp(3NEMO) parsing is nemoinpx, which parses a string in d:m:s.s format, returning the number(s) in fractional degrees. For h:m:s conversion, the user is responsible for the extra factor of 15 between d:m:s and h:m:s.

The nemorinpX routines were added to allow for filling exactly n values with defval (repeated=FALSE) or with the last used value (repeated=TRUE)

Operators

The following operators are known:
+    addition
-    subtraction
*    multiplication
/    division
**    power

Constants

The following constants are implemented (in SI units, where applicable)
pi    3.14159....            
c    speed of light (SI)
h    Planck (SI)            
k    Boltzmann (SI)
g    gravitation (SI)       
s    Stefan-Boltzman (SI)
m    mass of sun (SI)       
p    parsec (SI)
undef    errorval
Note: the Hubble constant is not included.

Functions

The following mathematical functions are implemented:
abs(x)        absolute value of x   
sqrt(x)        square root of x
sin(x)        sine of x             
asin(x)        inverse sine of x
cos(x)        cosine of x           
acos(x)        inverse cosine of x
tan(x)        tangent of x          
atan(x)        inverse tan of x
exp(x)       exponential of x      
sinh(x)        hyperbolic sine of x
ln(x)         natural log of x      
cosh(x)        hyperbolic cosine of x
log(x)        log (bas 10) of x     
tanh(x)        hyperbolic tangent of x
rad(x)        convert x to radians  
deg(x)         convert x to degrees
erf(x)       error function of x   
erfc(x)        1-error function
max(x,y)      maximum of x and y    
min(x,y)       minimum of x and y
sinc(x)      sin(x)/x              
atan2(x,y)    inverse tan (mod 2pi); x = sin, y = cos
sign(x)       sign of x (-1,0,1)    
mod(x,y)       gives remainder of x/y
int(x)        truncates to integer  
nint(x)        nearest integer
ranu(x,y)     generates uniform noise between x and y
rang(x,y)     generates gaussian noise with mean x and dispersion y
ranp(x)       generates poisson noise with mean x
ifeq(x,y,a,b)      returns a if x equal y, else b
ifne(x,y,a,b)      returns a if x not equal y, else b
ifgt(x,y,a,b)      returns a if x greater y, else b
ifge(x,y,a,b)      returns a if x greater or equal y, else b
iflt(x,y,a,b)      returns a if x less y, else b
ifle(x,y,a,b)      returns a if x less or equal y, else b
range(x,a,b)    return 1 if x inbetween (included border) and b, else 0

Error Return Code


0       no error
-11       bad call
-12       unknown function
-13       syntax error
-14       illegal character
-15       wrong repeat argument (maximum is 32767)
-16       wrong number of arguments
-17       arithmetic error
-18       not enough internal memory
-19       conversion error
-20       unequal list length
-21       empty list
-22       nested lists
-23       output buffer overflow
-24       floating overflow/underflow in conversion

Bugs

The number e-floating number 0 (0.00000E+00) cannot be processed, nemoinp complains about floating underflow. Begeman is looking into this (dec 88)

Limitations

Each subexpression can contain at most 32767 items, e.g. "1::40000" will not parse but "1::20000,1::20000" will correctly parse to 40000 1’s.

Loops, repeats and lists cannot be nested!!

Examples


1 2 3/3  sin(pi)          yields           1.0 2.0 1.0 0.0
log(10)::4                yields           1.0 1.0 1.0 1.0
log(10):log(100):2/4      yields           1.0 1.5 2.0
10**[0 1 2 3]             yields           1.0 10.0 100.0 1000.0

See Also

herinp(3NEMO) , fie(3NEMO) , nemofie(3NEMO) , getrange(3NEMO)

Author

Peter

Teuben

History


18-May-88    Implemented in NEMO by calling GIPSY’s herinp    PJT
xx-feb-89    nemoinp made archaic - must now call nemoinpX    PJT
20-jun-89    doc updated    PJT
4-mar-94    added nemoinpf/r    PJT
31-may-01    added natof/natoi    PJT
4-mar-03    1.9 added nemoinpx()    PJT
28-jan-04    recognize nan’s in natof    PJT
jan-2005    added nemorinpX    PJT
dec-2021    added atox, fix sign bug    PJT
3-apr-2023    added range()    PJT


Table of Contents