Extracting and saving data from different .cdf files

7 views (last 30 days)
I have a set of .cdf files inside which I have several variables which are common to each .cdf file. Each variable in different .cdf file has different amount of data. Rather than opening each .cdf file separately and extracting data for the variable of interest, I am looking a way to do it faster (probably using a loop) and save the results in a .mat file. Could you help me with that? Here is an example of how those .cdf file names look like and size of the variable I am interest at. Note that the file name contains the year, month, date (eg year 2010, month 10, day 15 for th 1st file). We can extract the data in first file as follows.
x1 = ncread('test.a1.20101015.000000.cdf', 'x');
test.a1.20101015.000000 size(x)= 86200x1
test.a1.20101016.000000 size(x)= 84000x1
test.a1.20101101.000000 size(x)= 85500x1
test.a1.20101102.000000 size(x)= 84890x1
Thanks a lot.
  2 Comments
Walter Roberson
Walter Roberson on 18 Aug 2017
cdfread() is limited to the older original CDF format. ncread() can be used for those files and also for NETCDF files. cdfread() only supports 7-bit ASCII for attributes and comments.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 Aug 2017
netcdf files are structured binary files that you cannot simply fseek() into and pull out data. You will not be able to avoid using ncread or cdfread once for each file.
However, if you use a particular portion of the data multiple times, it might be worth reading the data from the files and storing them either as .mat or as binary files for performance reasons.

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by