Getting dimension size?

  • Hi folks,

    Can the number of time periods within a netCDF file be determined within NCO?  This would be very useful  as follows (in pseudo code): 

    if less than 1200 time elements in file then do X
    else do Y


    • Charlie Zender
      Charlie Zender

      Dimension sizes are currently reported only by the
      output of ncks -m. To use this information in the
      shell, you can grab it using standard text utilities grep and cut, e.g.,

      zender@elnino:~/nco/data$ ncks -C -m -v time
      time: # dim. = 1, NC_DOUBLE, # att. = 0, ID = 8
      time dimension 0: time, size = 10 NC_DOUBLE, dim. ID = 14 (CRD)(REC)
      time memory size is 10*nco_typ_lng(NC_DOUBLE) = 10*8 = 80 bytes
      zender@elnino:~/nco/data$ ncks -C -v time -m | grep "size =" | cut -d' ' -f 7

      Hope this helps,

    • This worked just fine!  Great software, many thanks!

  • Christine Smit
    Christine Smit

    Is this still the case? I can't seem to get size() to work on a dimension in my ncap2 script. Note - this dimension does not have a dimension variable. The 'size()' function obviously works on variables that are dimensions.

  • henry Butowsky
    henry Butowsky

    Hi Christine --
    A slight ambiguity in the grammar:

    for dims use: $time.size
    for vars use: time.size() or three_dmn_var_dbl.size();


    ncap2 -v -O -s 'n2=$time.size;print(n2);'


    • Christine Smit
      Christine Smit

      Great! Thanks. I didn't see that in the documentation.