1

I have a single NetCDF file with some identically sized variables in it. I am trying to save all data into different NetCDF files based on dimensions. For example, each variable in a NetCDF file has data in one dimension called "row" with a size of 1000 datapoints. How can I create three different NetCDF files, splitting the data into the first 300 points, then 400 and the last with the final 300 points?

The data type, variables, variable full name, and units are as below respectively:

float latitude(row=1000), long_name = "Latitude", units = "degrees_north";
float longitude(row=1000), long_name = "Longitude", units = "degrees_east";
float ve(row=1000), long_name = "Eastward velocity", units = "m/s";
float vn(row=1000), long_name = "Northward velocity", :units = "m/s";
double time(row=1000), long_name = "Time", units = "seconds since 1970-01-01T00:00:00Z";
char ID(row=1000, ID_strlen=8), long_name = "Global Drifter Program Buoy ID";
int WMO(row=1000), long_name = "World Meteorological Organization buoy identification number";
etc...

The row numbers are the same across all variables. Also note that there are different types of data such as "double", "char","float", and "int". Row values like 300, 400, and 300 should appear in the output NetCDF files, and the column values should match those in the primary files for the corresponding variables. Other dimensions and parameters shouldn't change. Is it possible to do it using Python or CDO?

11
  • 1
    As you've tagged the question fortran, do you know how to write a Fortran program which reads a NetCDF variable? How to write a Fortran program which creates a NetCDF file? How to refer to parts of a Fortran array? How to write a Fortran program which writes a variable to a NetCDF file? If you can do all of those, you can do your whole task; if there's one of those you can't do, ask for specific details on that. (If you can do none, then this question is likely too broad for useful answers.) Commented Aug 10, 2022 at 13:26
  • you need to specify what the dimension is... if the 1000 dimension is time then this is easy to do in cdo or nco in one line Commented Aug 10, 2022 at 14:30
  • This question needs more clarity. You have tagged cdo, but CDO does not deal with dimensions in the abstract, instead it works with space and time . As suggested above revise the question to state what the dimension is Commented Aug 10, 2022 at 18:36
  • HI @francescalus. thank you for your valuable comment. I am not familiar with writing data into nc file using Fortran so, I have updated the question and asked with specific detail. Commented Aug 11, 2022 at 12:49
  • 1
    @AdrianTompkins I think you are correct. In that case there is probably no CDO solution. NCO is likely the way to go. Commented Aug 11, 2022 at 14:37

1 Answer 1

3

You can use nco to split data according to a index according to this answer:

ncks -d row,1,300 in.nc -O row1_300.nc
ncks -d row,301,700 in.nc -O row301_700.nc

etc...

ps: careful with ncks selection, if you use float values it splits using the dimension entry, not the index. If the row entry is simply counting 1,2,3,4 etc then this doesn't matter as the index and value are identical.

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

1 Comment

This is what I was expecting and it is very helpful. You have added extra words "https" in the referred link. Please edit it. Thank you.

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.