Next: , Previous: print statement, Up: ncap2 netCDF Arithmetic Processor


4.1.10 Missing values ncap2

Missing values operate slightly differently in ncap2 Consider the expression where op is any of the following operators (excluding '=')

     Arithmetic operators ( * / % + - ^ )
     Binary Operators     ( >, >= <, <= ==, !=,==,||,&&, >>,<< )
     Assign Operators     ( +=,-=,/=, *= )
     
     var1 'op' var2
     

if var1 has a missing value then this is the value used in the operation else the missing value for var2 is used. if during the element by element operation an element from either operand is equal to the missing value then the missing value is carried through. In this way missing values 'percolate' through an expression.
Missing values associated with Output variables are stored in memory and are written to disk after the script finishes. During script execution its possible (and legal) for the missing value of a variable to take on several different values.

     Consider the variable:
     int rec_var_int_mss_val_int(time); =-999,2,3,4,5,6,7,8,-999,-999;
     rec_var_int_mss_val_int:_FillValue = -999;
     
     n2=rec_var_int_mss_val_int + rec_var_int_mss_val_int.reverse($time);
     
     n2=-999,-999,11,11,11,11,11,11,999,-999;

The following methods are used to edit the missing value associated with a variable. They only work on variables in Output.

set_miss(expr)
Takes one argument the missing value. Sets or overwrites the existing missing value. The argument given is converted if necessary to the variable type
change_miss(expr)
Changes the missing value elements of the variable to the new missing value (nb an expensive function).
get_miss()
Returns the missing value of a variable. If the variable exists in Input and Output then the missing value of the variable in Output is returned. If the variable has no missing value then an error is returned.
delete_miss()
Deletes the missing value associated with a variable.
     
     th=three_dmn_var_dbl;
     th.change_miss(-1e10d);
     /* set values less than 0 or greater than 50 to missing value */
     where( th <0.0 || th > 50.0)
       th=th.get_miss();
     
     
     Another example
     
     new[$time,$lat,$lon]=1.0;
     new.set_miss(-997.0);
     
     /* extract only elements divisible by 3 */
     where ( three_dmn_var_dbl%3 == 0 )
          new=three_dmn_var_dbl;
     elsewhere
          new=new.get_miss();