2

I have a netcdf file structured as bellow:

File AA_14.nc (NC_FORMAT_CLASSIC):

 8 variables (excluding dimension variables):
    short year[time]   
        units: -
    short doy[time]   
        units: days since 2008-01-01
        long_name: day of year
    short hour_min[time]   
        units: -
    float seconds[time]   
        units: -
    float Ux[time]   
        units: m s^-1
        long_name: horizontal w in x-coordinate
    float Uy[time]   
        units: m s^-1
        long_name: horizontal w in y-coordinate
    float Uz[time]   
        units: m s^-1
        long_name: horizontal w in z-coordinate
    float CO2[time]   
        units: mg m^-3
        long_name: 

 1 dimensions:
    time  Size:3241707   *** is unlimited ***

2 global attributes:
    title: data
    history: 20Hz data (50ms) 

In the variable "doy" I have 3 days of the year 100, 101, and 102 I would like to extract all the variables for the day of the year 101. I have tried to do it using the ncks from nco but I did not manage.

Which would be the right way to do it? Thanks.

Marin
  • 21
  • 3

1 Answers1

3

Assuming that time is monotonic in your file and XXX is the first index where doy is 101 and YYY is the last index of doy is 101 then something like this will hyperslab all the doy=101 values:

ncks -d time,XXX,YYY in.nc out.nc

XXX and YYY can be found by just paging through the text output from, e.g.,

ncks -v doy -C --trd in.nc | more

The manual explains the meaning of all the options.

Charlie Zender
  • 5,929
  • 14
  • 19
  • The first part was obvious to me as well and I got it running by selecting a random beginning and ending index. I was not entirely sure how to find the precise beginning and ending of my DOY indexing but now everything is clear. Thank you very much! – Marin Feb 26 '19 at 09:57
  • There is however an issue I cannot explain. Considering that xxx and yyy the index when one individual day starts and when it ends the line I am using is as you have mentioned ncks -d time xxx yyy in.nc -h out.nc I have added -h to remove the history of the operation. If I extract the data from my initial ncdf file for the DOY 100 for instance is different with the data from the output created for the same day after the splitting. Should I add another argument, or what could be the cause? Thank you. – Marin Mar 21 '19 at 09:14
  • The problem you are experiencing is unclear to me, so I don't know how to help you. – Charlie Zender Mar 22 '19 at 12:35