A MATLAB reader for GRIB1 data has been developed based on wgrib1.c (ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib/wgrib.c), which has been wrapped in a MATLAB mexFunction. Using the reader, you can read GRIB1 data directly in MATLAB. I have tested it with the NLDAS-2 forcing data. It is much faster than all “MATLAB GRIB’ toolboxes/scripts I found from internet. The reader only for GRIB1 data. If you want, you can cook one for GRIB2 similarly.
You are welcome to use/test it. If there is any problem on the MATLAB side, I will be happy to help. The following is a simple instruction:
Compile the code: mex readGRIB1.c within matlab, you get “readGRIB1.mexa64” if you work on a 64-bit linux system.
Make a symbolic link of readGRIB1.mexa64 or copy it to your working directory
You may call readGRIB1 in you matlab code/command line window like the following line:
[data, nx, ny]=readGRIB1('2014102309.nldasforce-b.grb',2);
in which, “2” is the record number of the GRIB variable. What you need to do is just to figure out the record number of your variable in GRIB file.
Have fun!
Cite As
Shugong Wang (2025). Efficient GRIB1 data reader (https://au.mathworks.com/matlabcentral/fileexchange/53705-efficient-grib1-data-reader), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Data Import and Analysis >
- Sciences > Geoscience > Geology >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | email update A memory leak has been fixed. |
