Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active February 22, 2026 18:07
Show Gist options
  • Select an option

  • Save scivision/4cecadd143458c0e5c844c67c57ac89b to your computer and use it in GitHub Desktop.

Select an option

Save scivision/4cecadd143458c0e5c844c67c57ac89b to your computer and use it in GitHub Desktop.
Examples of using E-CHAIM model

E-CHAIM altitude profile example

E-CHAIM ionospheric model is available for C, IDL, and Matlab. We will describe the Matlab version only here.

This example is for E-CHAIM Matlab release 4.3.2. Free registration is required to download the E-CHAIM Zip archive. Extract this archive from Matlab:

unzip('Release_Matlab_CDB-4.3.2.zip')

cd('Release_Matlab_CDB-4.3.2/')

The “ECHAIM.p” file is a function ECHAIM() accessed from Matlab. Unlike the “.m” script files one is used to, “.p” files are encrypted to keep source code private, but can be run just like “.m” files.

Let’s run a Matlab E-CHAIM self-test that will automatically compile the MEX code. The MEX compiled libraries will be under

Release_Matlab_CDB-4.3.2/nrlmsise/matlab_nrlmsise.mex*
Release_Matlab_CDB-4.3.2/aacgm/mex_aacgm.mex*

Where "mex*" is the file extension given by the Matlab command "mexext". If you get an error message about compilers not being setup, there should be a link in the Matlab error on how to setup the MEX compilers. To share ".mex*" compiled libraries between computers - for example if your computer doesn't have C compilers compatible with Matlab available, the computers must both have the same operating system (e.g. macOS, Windows, Linux) and the same CPU architecture as seen by Matlab command computer('arch'). The Matlab release (e.g. R2026a) should also be the same, but sometimes MEX libraries compiled with an older Matlab version may work with a newer Matlab release--manually copy over the .mex* files to the appropriate directories on the other computer. From Matlab:

ECHAIM(‘test’)

If you get error

Unrecognized function or variable 'matlab_nrlmsise'

ECHAIM('create_nrlmsise')

Then, generate an electron density altitude profile by running this example script "altitude_profile.m"

>> Y

Y =

  struct with fields:

            NmF2: 5.410904881893724e+11
            hmF2: 2.447915856537269e+02
            hmF1: 1.750454670458398e+02
             HF1: 1.868798962096763
            HBot: 39.312566734418397
            HTop: 36.788016405991129
              HE: 11.069314546679436
            dens: [941×1 double]
             NmE: 7.352674400770149e+09
            NmF1: 7.021969909180861e+10
             Lon: 69.500000000000000
             Lat: 55
             Alt: [60 61 62 63 64 65 66 67 68 69 70 71 … ] (1×941 double)
            MLon: 1.430599130098475e+02
            MLat: 52.020061248035766
             MLT: 16.116123313057603
           Dates: 23-Jan-2013 11:24:50
             Err: [1×1 struct]
            foEs: 3.013522515707382
            hmEs: 1.026634910209048e+02
    Es_Occurence: 0.119584693714115
          dbDate: 10-Sep-2025 12:00:11
         version: "4.3.2"
dates_use = datetime(2013, 1, 23, 11, 24, 50);
lat_use = 55;
lon_use = 69.5;
alts_use = 60:1:1000;
Y = ECHAIM (lat_use, lon_use, dates_use, alts_use);
plot(Y.dens, Y.Alt)
set(gca, XScale='log', Xlim=[1e9,1e12])
title(sprintf("%s [%0.2f %0.2f]", string(dates_use), lat_use, lon_use))
ylabel('Altitude [km]')
xlabel('Electron Number Density [e^- / m^3]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment