[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20030926:aggregate different netCDF files
- Subject: Re: 20030926:aggregate different netCDF files
- Date: Tue, 30 Sep 2003 17:04:55 -0600
>To: address@hidden
>From: Susana Mendes <address@hidden>
>Subject: aggregate different netCDF files.
>Organization: Evora Geophysics Centre, Evora University, Portugal
>Keywords: 200309241639.h8OGd1k1023653
Hi Susana,
> I need help!
> Here is the problem: I have 10 netCDF files, one file per pressure level -
> 1000 hPa, 950hPa,......,200 hPa. The dimensions Lat, Long and Time are the
> same in all files: Lon= 110, Lat=104, Time=52.
> In first place I want to extract data to get one file per pressure level and
> per time, like:
> file 1:time =0, lev=1000hPa, Lon=110, lat=104
> file 2 :time=1, lev=1000hPa, Lon=110, Lat=104
> ......
> file52:time=51, lev=1000hPa, Lon=110,Lat=104
So you want to convert the 10 original files (say lev-1000.nc,
lev-950.nc, ..., lev-200.nc) into 520 (= 10*52) smaller files. The
nco operator program ncks will do this. For example, just put the
following 520 commands into a script:
ncks --dimension=Time,0 lev-1000.nc lev-1000-Time-0.nc
ncks --dimension=Time,1 lev-1000.nc lev-1000-Time-1.nc
ncks --dimension=Time,2 lev-1000.nc lev-1000-Time-2.nc
...
ncks --dimension=Time,51 lev-200.nc lev-200-Time-51.nc
But you would probably want to write shell script loops instead. A
/bin/sh script for this would be something like:
#!/bin/sh
for lev in 1000 950 900 800 700 600 500 400 300 200 ; do
for Time in 0 1 2 3 ... 51; do
ncks --dimension=Time,"$Time" lev-"$lev".nc lev-"$lev"-Time-"$Time".nc
ls -l lev-"$lev"-Time-"$Time".nc
done
done
where I have used "..." to avoid typing all the numbers from 4 through 50.
> In second place, I need to aggregate different pressure levels at same time
> with the same dimensions of lat and lon, like:
> file 1: time=0, lev=1000, 950, 900,.....200, Lon=110, Lat=104
> file2: time=1, lev=1000, 950, 900, .....200, Lon=110, Lat=104
> ....
> file52:time=51, lev=1000,....,200, Lon=110, Lat=104
>
> What is the best way to do this?
>
> I tried several NCO commands without any success, because when I use the
> ncdump to the output file(after aggregation), it doesn't recognize the
> different levels.
>
> Is there anyone able to help me?
You can almost do this with the ncecat program, but it creates a
record dimension that you may not want. For example, if you run
ncecat lev-1000-Time-0.nc lev-950-Time-0.nc ... lev-200-Time-0.nc Time-0.nc
(where I've used "..." to save typing), you get a file with the first
time and all 10 levels, but now have a record dimension of 10, where 1
record is used for each level, something like:
float var(record, Time, lev, Lon, Lat) ;
with lev of size 1 and record of size 10, instead of
float var(Time, lev, Lon, Lat) ;
with lev of size 10. To get the latter, you can either write a
program that makes netCDF library calls to get exactly what you want,
or use ncgen/ncdump and a text editor to eliminate the record
dimension. For example, run
ncdump Time-0.nc > Time-0x.cdl
then edit the CDL file Time-0x.cdl to remove the definition and all
occurrences of the "record" dimension and increase the "lev" dimension
from 1 to 10, providing values for the corresponding lev variable and
saving the result in Time-0y.cdl. Now use ncgen to get what you want:
ncgen -b -o Time-0y.nc Time-0y.cdl
and the result you want will be in the file Time-0y.nc. I don't
think there is any easy way to do this with the NCO netCDF operators,
but I'll CC: Charlie Zender on this note, just in case he knows.
> I send this email to you: Sincerely, I don't know if this is the right
> procedure. If it doesn't, please let me know.
Sending questions to address@hidden is correct.
> Many Thanks in advance.
> Susana M. Mendes.
> Evora Geophysics Centre
> Evora University,
> Portugal.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu/staff/russ