International Geomagnetic Reference Field (IGRF) Model (Scripts) Publisher's description
from Drew Compston
The International Geomagnetic Reference Field (IGRF)
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 11th IGRF generation (most recent as of 2010).
-loadigrfcoefs.m: Loads the proper IGRF coefficients at a given time (making the necessary interpolation).
-*grf*.dat: 11th generation IGRF coefficient data files.
-plotbline: Plots a magnetic field line.
-plotbearth: Plots a number of magnetic field lines.
The only prerequisite to running either the function IGRF 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 2010. New .dat files will hopefully continue to be uploaded to the following ftp:
In writing this function, I discovered that MATLAB provides an IGRF function in the Aerospace Toolbox, so the function IGRF will not add anything new to users with that package. However, the Aerospace Toolbox does not provide a function with the same capability as IGRFLINE as far as I know.
Having said that, IGRFLINE utilizes the function ECEF2LLA in the Aerospace Toolbox. Not all is lost for users without that package, though, as a free implementation of the Aerospace Toolbox's ECEF2LLA function can be found on the MATLAB file exchange at:
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.
System Requirements:MATLAB 7.5 (R2007b)
Program Release Status: New Release
Program Install Support: Install and Uninstall