Table of Contents


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


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)
double natof(expr)
int  natoi(expr)
char *expr;
double doutv[];
float  foutv[];
real   routv[];
int    ioutv[];
long   loutv[];
bool   boutv[];
int    nout;


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).

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 following operators are known:
+    addition
-    subtraction
*    multiplication
/    division
**    power


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.


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

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


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


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!!


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)


Peter Teuben

Update 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

Table of Contents