ICGEMFormatReader use from Matlab

I am having trouble creating the gravity field I want from a .gfc file using Orekit via Matlab. I’m sure that I just don’t fully understand how the GravityFieldFactory.addPotentialCoefficientsReader function works.
First I went to this website: ICGEM International Center for Global Gravity Field Models
I downloaded AIUB-GRL350A and placed it in my Matlab workspace.
Below is the code I am using:
org.orekit.forces.gravity.potential.GravityFieldFactory.addPotentialCoefficientsReader(org.orekit.forces.gravity.potential.ICGEMFormatReader(‘AIUB-GRL350A.gfc’, true));
gravityField = org.orekit.forces.gravity.potential.GravityFieldFactory.getNormalizedProvider(degree, order);

I am receiving the following error:
“org.orekit.errors.OrekitException: no gravity field data loaded”

Any help to get me started would be welcome. I think I just don’t fully understand what a .gfc file does or how to run GravityFieldFactory properly.
Thank you,

Hi @erinf,

How did you setup your orekit-data directory ?
The gravity file must be in that directory for Orekit to find it.

There are some other options too:

  • First get the DataProvidersManager of the default data context:
    DataProvidersManager manager = DataContext.getDefault().getDataProvidersManager();
  • Add a custom directory to the DataProvidersManager:
    manager.addProvider(new DirectoryCrawler(myCustomDir));
  • Add a custom file:
    manager.addProvider(new FileListCrawler(myCustomFile));

Here myCustomDir and myCustomFile are Java File objects so I’m not sure how this translates to Python.

Hope this helps,

It worked!
Apparently all I had to do was to put the .gfc file into the orekit-data.zip file, under the Potential folder.
Thanks very much for your help.

Nice @erinf !
And you’re welcome.

Beware that Orekit will read the orekit-data directory or zip file automatically and will take the first gravity file that matches its “potential coefficients readers”.

This time it’s not a problem since you cleared the readers and explicitly gave Orekit the name of the file to read.
But later, if you use the default reader and want to orbit around Earth, beware that it doesn’t take the Moon gravity file instead of the Earth’s one !

Thank you for the note - I will be sure to clear readers and use the right file each time.