View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
International Reference Ionosphere (IRI) Model

4.5 | 12 ratings Rate this file 37 Downloads (last 30 days) File Size: 28 KB File ID: #34863 Version: 1.14
image thumbnail

International Reference Ionosphere (IRI) Model


Drew Compston (view profile)


31 Jan 2012 (Updated )

Get the International Reference Ionosphere (IRI) output parameters.

| Watch this File

File Information

Computes the International Reference Ionosphere (IRI), which is an internationally recognized model for various ionospheric properties. I would call it more of a hack than a true IRI implementation as it works by querying an online interface using the curl command on an operating system terminal. Because of this, it requires an internet connection and is pretty slow, but if high speed is not an important issue for you, this can be an easy way to get IRI data into MATLAB. There are two functions that call different IRI versions. Function iri2007 calls the 2007 version found at, and function iri2012 calls the more recent 2012 version whose online interface is at
An example script for how to use the functions is given as iritest.m. This is also the script that generated the attached screenshot. Using a parfor loop on my dual core computer, both the iri2007 and the iri2012 functions took about 5 minutes to run. (For comparison, the IGRF (commented out in the script) takes just over 1 second to run.) You can select which of the two provided functions to test with the function handle fun2test on line 13, and when using a parfor loop (set by the boolean useparfor on line 14), the function's progress can be displayed by utilizing the function parfor_progress on the File Exchange (File ID: 32101).
As stated, the query is made using the command curl in an operating system terminal. This program is built-in to Unix (and Mac I believe) but not Windows. Windows users can download cURL from You'll have to download the appropriate executable for your operating system, and I recommend putting it in the same directory as the provided functions.

There is an odd quirk for the iri2007 program: Sweeps in longitude are only possible for the default altitude (100 km). If you input a vector of longitudes and the altitude is not 100 km, the function will make as many single calls to the online interface as longitudes input rather than utilize the profile sweep functionality (since that does not work). Previously, there were some different quirks in the iri2012 interface, but those have been fixed, and I currently know of no issues with the interface itself. Let me know if you have trouble with the iri2012 version.


This file inspired Msis E 90.

Required Products MATLAB
MATLAB release MATLAB 7.5 (R2007b)
MATLAB Search Path
Other requirements curl.exe (can be downloaded at if not included in your operating system).
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (32)
18 Feb 2017 D

D (view profile)

The IRI model website is encrypted now (it is now https and not http). Please update the following address at line number 795 from

'" > "'


'" > "'

Comment only
13 Feb 2017 Drew Compston

Drew Compston (view profile)

Saeed: your error is likely caused by the IG12 input (9th input) not being a scalar. That input should be a scalar between -50 and 400 (which the help text in the beginning specifies).

Moraes: Sorry I missed your question. This should be possible, though I don't have the time to work out the details. It's a matter of figuring out where the geomagnetic poles are from the IGRF and then applying a coordinate transform. This page and the references therein might be helpful for this problem:

Comment only
12 Feb 2017 Saeed Bello

Thank you for this code. Kindly help me fix this error after running this command:
out = iri2012(time, latitude, longitude, height, utc, coord, ...
curldir, bottom)
The error is:
??? Operands to the || and && operators must be convertible to logical scalar

Error in ==> iri2012 at 576
if isempty(IG12) || (IG12 >= -50 && IG12 <= 400)

Thank you

17 Nov 2016 Alison Moraes

Dear Drew,
Is there a way to compute the geomagnetic coordinate having the geodetic coordinate as input?

11 Oct 2016 Drew Compston

Drew Compston (view profile)

Auroral: You need an active internet connection for curl to work. Is the computer you are using connected to the internet? Sounds like maybe not.

Comment only
11 Oct 2016 Auroral

11 Oct 2016 Auroral

downloaded curl.exe iritest program still came out the 'curl error';
besides , when running my own program using iri2007/2012, always inform error that----' Failed to connect to port 80: Timed out' somebody help me ?

Comment only
23 Jul 2016 Elliot Findley

Has anyone tried using this in octave?

24 Apr 2016 rui zhou


07 Apr 2016 Drew Compston

Drew Compston (view profile)

The output of the iri2012 program is an Nx44 array, where N is the number of input locations/times. To get the 13th output of the IRI, simply select the 13th column of the output array. For example:
>> TEC = out(:, 13);
So in iritest, you could replace all the instances of out(:, 1) with out(:, 13) to plot TEC rather than electron density. There are four instances on lines 42, 54, 73, and 80.

Comment only
06 Apr 2016 Sri Ekawati

the iritest program compute and shows the Electron Density (Ne) only... As we know that output of IRI2012 have 44 output. How to get value of TEC (for example, output no. 13).... could anyone help me please

Comment only
05 Apr 2016 Sri Ekawati

@Muresan Aronia : First, I have same problem with you. But when I download the curl.exe and placed the matlab program at the same directory.. the program is successfull.... FYI, I use Windows..

Comment only
29 Apr 2015 Drew Compston

Drew Compston (view profile)

It's hard for me to troubleshoot problems you might be having with curl, especially with as little information as has been given in some of these comments. There is a link in the description to the curl executable program I use in this MATLAB code. I will point out: Someone I work with had trouble getting this to work on her Mac. It had something to do with the curl file provided by MATLAB in her version. I think we fixed it by removing the curl file from the MATLAB install files. But that's all I remember now.

Comment only
29 Apr 2015 Muresan Aronia

Hi everyone.I'm trying to simulate the IRI model but I get the same error with the Curl command.I read above that somebody says to download the curl command but I couldn't find something like this.Could anyone help me?

29 Apr 2015 Muresan Aronia

Hi everyone.I'm trying to simulate the IRI model but I get the same error with the Curl command.I read above that somebody says to download the curl command but I couldn't find something like this.Could anyone help me?

Comment only
02 Oct 2014 Cory

Cory (view profile)

For anyone with the Curl error, you have to download the command (for Windows for sure, not sure about other OS) and set the directory or have it in the same directory. See the description.

01 Oct 2014 Cory

Cory (view profile)

Good stuff! Small error: if I want to look at December 31st in a non-leap year in a sweep (e.g. 12/31/1990), the code computes the sweep stop as 365 + (sweepstep)/10, e.g. 365.1. The IRI 2012 interface rejects this.

I've removed the step/10 bit as a stopgap, but good to correct in later versions.

Comment only
25 Sep 2014 Md. Golam Mostafa

23 Apr 2014 alberto akel

I tested the iritest,but shows error as below:
Error using iri (line 603)
Curl command did not work. It returned status:127

Comment only
22 Apr 2014 Chao-Yen

I trid the iritest, but it shows some error as below : Error using iri (line 603)
Curl command did not work. It
returned status:1,
would you please fixed it or tell me what's wrong. Thanks

03 Apr 2014 Drew Compston

Drew Compston (view profile)

Guanyi, The IRI 2007 model online interface I have been using for this function does not allow for inputting the 10.7 indices (just Rz12 and IG12). But it looks like they have an updated model (IRI 2012) that does incorporate that. I'll provide an updated version soon that utilizes the new model.

Comment only
03 Apr 2014 Guanyi

Guanyi (view profile)

I tried the iritest. Many thanks for such a powerful programs. However, when I tried to input F10.7 in the program, I found that it is in the output. Can I use the observed 10.7 index as an input? How should I modified the program? Thanks!

04 Apr 2013 Derek

Derek (view profile)

Drew, thank you! That fixed my problems! Thanks again for this awesome code!

Comment only
01 Apr 2013 Drew Compston

Drew Compston (view profile)

Derek, there were some problems in some of the time sweeps (unrelated to number of points) which I just fixed and uploaded. Longitude sweeps can also be tricky: First of all, they only work for altitude = 100, and something like [-2 -1 0 1 2] will not work because the negative numbers wrap around to near 360, resulting in a big gap. Please feel free to post any other specific examples where maybe it should calculate a linear sweep but doesn't.

Comment only
27 Mar 2013 Derek

Derek (view profile)

Actually, I retract my statement saying "I believe this is because sweepstop = min([sweep(end) + sweepstep/10, sweepmax]); should be sweepstop = [sweep(end) + sweepstep/10, sweepmax];"

Comment only
27 Mar 2013 Derek

Derek (view profile)

Thank you for submitting this code and updating it. On that note, I believe there is an issue with sweeping linear arrays greater than 500 elements. The program should enter into case {1 2 3 4 5 6 7} however, it instead moves to case 8. If the adjustment is made to force the program into case {1 2 3 4 5 6 7}, sweeping still fails. I believe this is because sweepstop = min([sweep(end) + sweepstep/10, sweepmax]); should be sweepstop = [sweep(end) + sweepstep/10, sweepmax];

Comment only
11 Oct 2012 Brandon

On line 496 in iri.m, there is a conversion from time into hours (in decimal form), and I think there is a mistake. The conversion divides seconds by 360 when I think it should be 3600.

Comment only
22 May 2012 Drew Compston

Drew Compston (view profile)

Krishna, as you pointed out, there was a bug in my geocentric coordinate conversion which might have caused your confusion. Look at it when the new version I just uploaded gets approved. When the input COORD is 'geoc', input LATITUDE is elevation, input LONGITUDE is azimuth, and input ALTITUDE is range.

Comment only
22 May 2012 Krishna Prasad

Hi This is a great piece of code.But I have a small doubt.When the input is geocentric coordinate system we need azimuth,elevation and range to convert it to geodetic coordinates your code converts does this conversion but where does you give elevation,azimuth and range as input.And there is minor bug in the code where you used sph2cart function.Have a look at it.May be I am wrong I am not sure.But this is really awesome stuff it helped me a lot..

Comment only
13 Feb 2012 Allen Kummer

13 Feb 2012 Allen Kummer

13 Feb 2012 Allen Kummer

For robustness, I would suggest updating the definition for endcmd at line 386 with below. As written, if your path has a space in it, curl gets confused, so adding quotes around the path name helps.

Otherwise the file seems to work great!

Also, for your information, at least my mac has curl built in.

endcmd = [Rz12 IG12 tec_hmax ...
'&ne_top=' ne_top ...
'&imap=' fpeak ...
'&ffof2=' storm ...
'&ib0=' bottom ...
'&probab=' f1prob ...
'&dreg=' d_reg ...
'&tset=' Te_top ...
'&icomp=' ioncomp ...
sprintf('&nmf2=%g.', f2peak_N) ...
sprintf('&f2=%g.', f2peak_M) ...
sprintf('&vars=%i', 11:50) ...
'" > "' ...
fullfile(fpath, 'temp.html"')];

Comment only
02 Feb 2012 1.1

Fixed typo in title/description.

13 Feb 2012 1.2

Fixed some more typos in the comments of the files and made the changes suggested in Allen Kummer's comments.

13 Feb 2012 1.3

Fixed a problem where the online interface didn't do a full sweep for fractional steps and added an error check on reading temp.html from the interface.

22 May 2012 1.5

Fixed geocentric coordinate conversion bug.

07 Aug 2012 1.7

Updated initial comment block, added an error check on calling curl, fixed/updated some of the other error checks, and added capability to run example script without Mapping Toolbox.

11 Oct 2012 1.8

Fixed bug pointed out by Brandon (old line 459 actually I believe, not 496) and also fixed an odd issue with the online interface output for longitude sweeps and non-default altitude (first noticed by John H.).

18 Jan 2013 1.9

Fixed problem where online interface would hang without returning anything for some inputs (including in iritest.m).

01 Apr 2013 1.10

Fixed some problems in sweeping day of year/month/etc.

28 Apr 2014 1.11

Added more information on inputs in initial comment block, provided functions to call both IRI-2007 and IRI-2012, added capability to run functions in a parfor loop, changed output from multiple vectors to single matrix.

09 Aug 2014 1.12

Made iri2012 compatible with new online interface having auroral boundary option.

11 Aug 2014 1.13

Fixed error in input argument order in the list in the initial comment block for the iri2012 function.

06 Oct 2014 1.14

Fixed issue with non-leap year day of year sweeps (as pointed out by Cory in comments above).

Contact us