ncap2 array function with floating point increment?

Help
2014-02-12
2014-02-12
  • Christine Smit
    Christine Smit
    2014-02-12

    I was expecting

    lon=array(-180,2.5,$lon);

    in an ncap2 script to produce values (-180.0, -177.5, -175.0, ...). Instead, I got (-180.0, -178.0, -176.0, ...). So it looks like the increment needs to be an integer. Is this correct? I've looked in the documentation and I don't see anything indicating the increment must be an integer. Maybe I looked in the wrong place?

     
  • Charlie Zender
    Charlie Zender
    2014-02-12

    Hello Christine,
    ncap2 is using integers because it cues the variable type based on the
    type of the first value in the array() arguments. Change to this:

    lon=array(-180.0,2.5,$lon);

    and ncap2 will produce the desired array.

    Yes, the documentation should make this more clear.

    cz

     
  • Christine Smit
    Christine Smit
    2014-02-12

    Ah! I see. Thanks!

    My script was actually:

    defdim("lon",144);
    lon[lon]=0.0f;
    lon=array(-180,2.5,$lon);

    So I thought that the "lon[lon]=0.0f;" would set the variable type. Are you saying that I was changing the type with the "lon=array(-180,2.5,$lon);" command? When I look in the output file, it looks as though lon is still a float.

     
    Last edit: Christine Smit 2014-02-12
  • Charlie Zender
    Charlie Zender
    2014-02-12

    close. the RHS type is determined by the RHS arguments.
    the LHS type, if not already know, is also determined by RHS arguments.
    otherwise the LHS type remains the same. so you were casting integers
    to floats which then appear to have integer values.
    cz

     
  • Christine Smit
    Christine Smit
    2014-02-12

    Oh. You know what. I think I understand.

    array=(-180,2.5,$lon)

    produces an integer array. This is then cast to a floating point array and assigned to lon. Yes? The type of lon does not factor into how the array is constructed.


    Whoops, our posts must have crossed paths...

    Thank you!

     
    Last edit: Christine Smit 2014-02-12
  • Charlie Zender
    Charlie Zender
    2014-02-12

    yes!