NCAP2 / WHERE / missing_value

Help
SNINCR
2013-01-11
2013-10-17
  • SNINCR

    SNINCR - 2013-01-11

    I was trying to use the WHERE command in a NCAP2 script, and it appears that a command within a WHERE statement will not change parts of the array marked as missing.  For example executing:

    ncap2 -S testscript zzz1.nc zzz2.nc
    

    where testscript contains:

    defdim("test_dim",3);
    test_array=array(-1.0,1.0,$test_dim);
    test_mask=array(0,1,$test_dim);
    test_output=test_array;
    test_output.set_miss(-99.0);
    test_output=get_miss(test_output);
    print(test_output@_FillValue);
    test_mask=(test_array>0);
    where(test_mask){
     test_output=5.0;
    }
    print(test_array);
    print(test_mask);
    print(test_output);
    

    yields:

    test_output@_FillValue, size = 1 NC_DOUBLE, value = -99
    test_array[0]=-1
    test_array[1]=0
    test_array[2]=1
    test_mask[0]=0
    test_mask[1]=0
    test_mask[2]=1
    test_output[0]=-99
    test_output[1]=-99
    test_output[2]=-99
    

    I would have expected that the last line of the output would have been:

    test_output[2]=5.0
    

    Does anyone know if this is the expected behavior?  I would have thought that when an array on the left hand side of an equation has an entry marked as missing, that would not preclude its value from being changed.  Perhaps I'm doing something wrong here, or not quite understanding something?

    I'm using ncap2 version 4.1.0 linked to netCDF library version 4.2.

     
  • SNINCR

    SNINCR - 2013-01-11

    Thanks!  Somehow I missed the line in the documentation for WHERE that "LHS variable elements set to missing value are not re-assigned". 

    In contrast to the test case I posted, for my actual work I am using a series a WHERE statements to set the values of an array.  After the series of WHERE statements are complete, some elements of the array may not have been set, so I had been setting the whole array to missing before the WHERE statements, in the hope that any elements of the array untouched by any of the WHERE statements would then be marked as missing.  Since WHERE will not touch any missing values this does not work since the entire array remains missing values regardless of any WHERE statements.

    The alternative I'm now using is to wait to inform NCAP2 what the missing value for this variable is until after the WHERE statements.   That way WHERE can affect any array elements, but the elements unaffected by any WHERE statement will still be marked as the missing value (NCAP2 just won't know it is the missing value until after the WHERE statement).  I thought I'd post this in case it was helpful to someone in the future coming across a similar situation.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks