International Geomagnetic Reference Field (IGRF) Model
The International Geomagnetic Reference Field (IGRF) is an internationally agreed upon mathematical model of the Earth's magnetic field. This program is a conversion of the FORTRAN subroutines that make the calculation into MATLAB. It does not use a compiled FORTRAN mex file, which probably makes it slower but at the advantage of being easier to use (as no compilation is necessary). In fact, my motivation in writing the program was to provide an IGRF implementation in MATLAB with minimal "fuss." Another motivation was a vectorized IGRF function, which this function is (with a separate routine adapted directly from the FORTRAN code that is faster for scalars implemented as well).
The following files are provided:
-igrf.m: Computes Earth's magnetic field at a point(s).
-igrfline.m: Gives the coordinates along a magnetic field line starting at a given point.
-getigrfcoefs.m: Extracts coefficients from the .dat files provided on the IGRF website and saves them to a .mat file.
-igrfcoefs.mat: IGRF coefficients of the 12th IGRF generation (most recent as of 2015).
-loadigrfcoefs.m: Loads the proper IGRF coefficients at a given time (making the necessary interpolation).
-*grf*.dat: 12th generation IGRF coefficient data files.
-plotbline: Plots a magnetic field line.
-plotbearth: Plots a number of magnetic field lines.
-geod2ecef: Converts geodetic coordinates to ECEF coordinates.
-ecef2geod: Converts ECEF coordinates to geodetic.
The only prerequisite to running either the function IGRF or the function IGRFLINE is to put the file igrfcoefs.mat in the MATLAB search path. The program is designed to be scalable with time: As new IGRF generations are released, simply replace the old .dat files with their newer versions in a subfolder called 'datfiles' within the same directory that the function getigrfcoefs.m is located and run getigrfcoefs, and then replace the file it generates (igrfcoefs.mat) with the old .mat file. Updates happen every five years, with the last update occurring in 2015. New .dat files will hopefully continue to be uploaded to the following website (though it appears the files haven't been updated since 2007):
https://ccmc.gsfc.nasa.gov/pub/modelweb/geomagnetic/igrf/fortran_code/
Finally, I have included two example scripts showing how the function IGRFLINE works: plotbline.m and plotbearth.m. These scripts both utilize the Mapping Toolbox to plot globes upon which magnetic field lines are plotted, but if the user does not have that package, a crude globe with just latitude and longitude lines is shown.
I've made some cursory comparisons with the online IGRF calculator at http://ccmc.gsfc.nasa.gov/modelweb/models/igrf_vitmo.php and found this function to be accurate to within 1 nT. I'm not sure why there is a discrepancy between the two, but my guess is round-off error.
Cite As
Drew Compston (2024). International Geomagnetic Reference Field (IGRF) Model (https://www.mathworks.com/matlabcentral/fileexchange/34388-international-geomagnetic-reference-field-igrf-model), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
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.14.0.0 | Changed years variable name to prevent error in newer MATLAB versions, as pointed out in a 8 Sep 2017 comment by David Koronczay.
|
||
1.13.0.0 | Added igrf1925 coefficients and made loadigrfcoefs.m more robust to different than 5 year gaps between coefficient files. |
||
1.12.0.0 | Updated description text to reflect my most recent update: The newest 2015 coefficients are now included. |
||
1.11.0.0 | . |
||
1.10.0.0 | Includes 2015 coefficients (12th generation IGRF). |
||
1.9.0.0 | Removed 'years' variable from loadigrfcoefs.mat. |
||
1.8.0.0 | Apparently, the earlier bug pointed out by Michael on 25 Jan 2012 resurfaced. Presumably the fix I had implemented before got undone, so this update includes that fix again. |
||
1.7.0.0 | Adjusted initial comment block in IGRF with correct definition of inclination using atan2 (rather than atan). |
||
1.6.0.0 | Added capability to plot globe without mapping toolbox and minor bug fix. |
||
1.5.0.0 | Provided my own ECEF to geodetic conversion routine. |
||
1.4.0.0 | Fixed bug described in Michael's comment. For those interested, it resulted from mistakenly calculating dP using only the last latitude input rather than the vector. |
||
1.3.0.0 | Fixed the issues detailed in Christie Harper's comment (including some additional ones relating to the differences between MATLAB's built-in ecef2lla and the free file exchange ecef2lla) and made some minor changes to speed up the functions slightly. |
||
1.0.0.0 |