Code covered by the BSD License  

Highlights from
read_netcdf

5.0

5.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 2.79 KB File ID: #28556

read_netcdf

by Samuel Lazerson

 

25 Aug 2010 (Updated 05 Jul 2011)

Reads a netCDF file and returns the contents as elements of a structure.

| Watch this File

File Information
Description

This function uses the MATLAB netCDF routines to read the contents of a netCDF file into a structure. It currently extracts the global attributes, dimensions, variables and variable attributes from the file. The variable attributes use the naming scheme 'varname_attname.'

READ_NETCDF(filename,'flipdim') Flips the dimensions of 2D arrays.

READ_NETCDF(filename,'strip') Strips non-alphanumeric characters from element names so they will be compatible with MATLAB structure element naming conventions.

MATLAB release MATLAB 7.11 (2010b)
Other requirements This code uses Java calls to read the files.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
30 Aug 2010 Samuel Lazerson

I just noticed issues regarding some netCDF files. I believe the issue is the MATLAB routines which I use to actually read the netCDF file. More specifically trying to read large arrays of type double. I've had better luck just using the Java calls so next week I'll post up a v1.5 of this function which uses the Java calls rather than the MATLAB (C routines). Please post up any issues you run into.

30 Aug 2010 Samuel Lazerson

A new version has been uploaded (v0.95) which uses Java to process the netCDF file. This seems to resolve any data inconsistency. If you experience any issues reading a netCDF file using this routine I encourage you to contact me and provide an example netCDF file so I can address whatever issue exists.

30 Aug 2010 Samuel Lazerson

Users should check the format of arrays read by this routine. It appears that the resulting MATLAB arrays may be stored in reverse order from which they were stored. This is most likely due to the use of the copyToNDJavaArray call.

15 Feb 2011 zelalem engida

Dr. Samuel, this is simply a wonderful routine. I am also astonished by your immediate responses to help users who may have issues while using it.
Best wishes!!
  

Please login to add a comment or rating.
Updates
30 Aug 2010

Updated to v0.95. Now uses java to read netCDF files. I've found this is more portable than the MATLAB netCDF calls.

03 Sep 2010

The function can now be called with the 'flipdim' option causing the array indices to be permuted in reverse order.

03 Sep 2010

Fixed issue reading 1D arrays and some scalar variables.

07 Oct 2010

Added the 'strip' and 'flipdim' options.

28 Jan 2011

Increased code's ability to handle strings.

15 Feb 2011

Fixed an issue where non-string attributes would cause the code to fail to read the file. Thanks to Zelalem Engida for bringing this to my attention.

05 Jul 2011

All '+' converted to 'p' in names. All '-' converted to 'n' in names. Thanks to Thomas Leslie Leith for bringing this to my attention.

Tag Activity for this File
Tag Applied By Date/Time
data import Samuel Lazerson 26 Aug 2010 13:39:34
netcdf Samuel Lazerson 26 Aug 2010 13:39:34
data exploration Samuel Lazerson 26 Aug 2010 13:39:34
data exploration zhang zhong 16 Nov 2011 03:02:06
data import zhang zhong 16 Nov 2011 03:02:18
netcdf zhang zhong 16 Nov 2011 03:02:24
image process zhang zhong 16 Nov 2011 03:02:38

Contact us at files@mathworks.com