Help save net neutrality! Learn more.
Close

teleconnections and ncap printing

Help
e ddc
2013-01-07
2013-10-17
  • e ddc

    e ddc - 2013-01-07

    Hello

    Happy new year 2013 for you all!

    I have a netcdf file with temperature fields, T(time,lat,lon), and would like to have  lat x lon netcdf files each one with a single timeseries (one for location).

    I need to do this for different grids, so I cannot assume that lat,lon values are known. If lat,lon were always the same and known, it would be easy to write a shell script using ncks to extract those locations. However, as the lat,lon values depend on the filed to be read, they need to be read in some way from the netcdf file itself and passed to a shell variable to be then used in the script. I have tried "ncks -H" and "ncap2 print" to read lat and lon variables to a shell variable but without success. For instance, I tried
    lon=`ncap -s 'print(lon,"%3.2f,")' $file` and got "Segmentation fault"
    also tried
    ncks -H -v lon $file   and got
    lon=0
    lon=2.5
    lon=5

    but I want just the values 0, 2.5, 5 … and not the "lon=" chain.
    Perhaps I will eventually use this piped with "cut" but would prefer a more elegant solution.

    Any ideas how to achieve this?

    Context:
    I am trying to compute teleconnections, that is, correlations between T in one location and the T in the other points of the field for every location in the field.
    Perhaps there is a completely different way to compute teleconnections or point correaltions that avoids extracting locations. Please let me know if you know about such an algorithm.

    Thanks a lot in advance for your time and insight on this.

    Regards,

    e.

     
  • Charlie Zender

    Charlie Zender - 2013-01-09

    you want to use ncap2 not ncap.
    the distinction between the two is in the manual.
    always use ncap2 if possible.
    this works:
    lon=`ncap2 -s 'print(lon,"%3.2f,")' $file`

    as does this:
    ncks -H -s '%3.2f, ' -v lon $file

    see http://nco.sf.net/nco.html#xmp_ncks

     

Log in to post a comment.