Project

General

Profile

cdo setdate multiple files, would like to read from file name and setdate

Added by Imeshi Weerasinghe almost 10 years ago

Hello All,

I have a large number of files for daily climatic data in netcdf format. I have noticed while trying to mergetime on all records that I do not have a date within each netcdf file. Therefore when I mergetime I get one file with only one record. I need to set the date for each file so that when I merge I get a record for each date.

I would like to know if there is a way to read the first 8 characters of a file name and use this to set the date. For example, one file with name 19610101.rain.nc should setdate 1961-01-01 within the record. I have over 100000 files so I would need to do multiple files at the same time. Trying to setdate each file would take over 200 days if I worked 8 straight hours a day!

Can anyone please help me?

I apologise if I am not clear, this is my first posting. But I would be happy to answer any questions if you have any.

Thank you so much for your help in advance.

Imeshi


Replies (3)

RE: cdo setdate multiple files, would like to read from file name and setdate - Added by Jaison-Thomas Ambadan almost 10 years ago

I'm not sure if I undestood your question correctly. If you would like to fix the time axis of your merged file, use settaxis operator

cdo -settaxis,1961-01-01,00:00:00,1day ifile.nc ofile.nc

If there is no record/time dimension in your input files, use NCO operators ncks to add a record dimension. Please have a look at the examples 8/9 in the following link http://jisao.washington.edu/data/nco/#example8

RE: cdo setdate multiple files, would like to read from file name and setdate - Added by Uwe Schulzweida almost 10 years ago

If you have alphanumeric sorted filenames you can simple use the CDO operator cat to concatenate all files. Here is an example for the year 1961:

rm rain.nc
cdo cat 1961*.rain.nc rain.nc
cdo settaxis,1961-01-01,00:00:00,1day  rain.nc rain.1961.nc
You can do it in one command line with single quotes around the cat input files:
cdo settaxis,1961-01-01,00:00:00,1day -cat '1961*.rain.nc' rain.1961.nc

RE: cdo setdate multiple files, would like to read from file name and setdate - Added by Sanita Dhaubanjar about 7 years ago

Hi,
I just tried to combine multiple files with alphanumeric sorted filenames using the example above and I can do it using the example with multiple commands. But when I try to use the one line command, i get the following error:

$ cdo settaxis,2016-12-01,00:00:00,1day -cat '3B42_Daily.2016*.nc4' cdo_TRMMDec2016.nc4
cdo settaxis: Started child process "cat 3B42_Daily.2016*.nc4 (pipe1.1)".
cdo(2) cat: 3%Segmentation fault: 11

I am using the latest version of CDO on Mac OSX Mavericks. Any suggestions is greatly appreciated!

    (1-3/3)