1

I am using the following command to dump the content of the variable 'tas' within a netcdf file tas_EUR-44_historical.nc

ncdump -v tas tas_EUR-44_historical.nc

tas is a variable of three dimensions consisting of time, latitude and longitude tas(time, rlat, rlon)

Now I need to dump the first value of time ,0, for rlat ranging from 0 to 5 and rlon ranging from 0 to 5.

Does anyone know how this can be done?

Thanks!

2 Answers 2

2

You can use ncks

ncks -d time,0 -d rlat,0,5 -d rlon,0,5 in.nc out.nc

Sign up to request clarification or add additional context in comments.

2 Comments

Dear Charlie, I am aware of this method. What I explicit want is to use ncdump and then visualize values in the requested region without creating an out.nc file.
I'm not sure what you mean by visualize. Unlike ncdump, ncks will print the hyperslab of values to screen in CDL format (without generating a .nc file) if you give it the --cdl switch: ncks --cdl -d time,0 -d rlat,0,5 -d rlon,0,5 in.nc
1

Strongly depends on what kind of tools you want to use. This is a very trivial task with most programming languages ("Python/R/..."), if you want a command line tool you might want to look at NCO and especially its ncks (NetCDF Kitchen Sink) command.

For example, if I have a NetCDF file (output ncdump -h)

netcdf u.xz {
dimensions:
    xh = 256 ;
    y = 1 ;
    z = 160 ;
    time = UNLIMITED ; // (481 currently)
variables:
    float time(time) ;
        string time:units = "Seconds since start of experiment" ;
    float xh(xh) ;
    float y(y) ;
    float z(z) ;
    float u(time, z, xh, y) ;
}

I can extract for example the first time record using:

ncks -d time,0,0 u.xz.nc test.nc

Or, something closer to your question, select the first time record and slice the spatial dimensions:

ncks -d time,0,0 -d xh,0,5 -d z,0,5 u.xz.nc test.nc

Each time the manipulated NetCDF file is written to a new file. You can leave out the last argument test.nc to dump the output to screen, or simply dump the output of test.nc with ncdump.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.