Modular input files¶
This tutorial describes how to use the MATLAB Interface to generate multiple JSON files that are then combined into a single JSON object by the json_interface
application. The code for this example can be found at:
tudatBundle/matlabInterface/Examples/InputOutput/ModularInputFiles/generateInput.m
The first part of the script sets up the Simulation
object. This is done in a similar way as explained for previous examples.
Once that all the settings have been defined, instead of calling simulatinon.run()
, we export parts of the Simulation
object to different JSON files. Before that, we change the current working directory in MATLAB to the directory in which the root JSON file (main.json
) will be generated, so that relatives paths in the MATLAB script and in the input files coincide:
if exist('input','dir') ~= 7
mkdir('input');
end
originalWorkingDirectory = cd;
cd('input');
We also store the original working directory to set it back once that the file generation is done, and create the directory if it does not exist.
We want to export different parts of the settings to separated files. For instance, we export the body settings to a file bodies.json
inside the input
directory:
simulation.bodies = json.modular(simulation.bodies,'bodies.json');
The json.modular
function exports the object specified as first argument to a file specified by the second argument, and returns the string $(bodies.json)
in this case, which is assigned to simulation.bodies
. In this way, the simulation object does not store the bodies anymore, but a reference to the file containing that information, by means of the special string $()
.
We can do the same for other settings:
simulation.propagators = {json.modular(propagator,'translationalPropagator.json')};
simulation.integrator = json.modular(integrator,'rk4.json');
simulation.export = json.modular(simulation.export,'export.json');
Finally, we export the main JSON file:
json.export(simulation,'main.json');
which looks like this:
{
"initialEpoch": 4.77171E+8,
"finalEpoch": 4.7760480000001341E+8,
"globalFrameOrigin": "SSB",
"globalFrameOrientation": "J2000",
"spice": {
"useStandardKernels": true
},
"bodies": "$(bodies.json)",
"propagators": [
"$(translationalPropagator.json)"
],
"integrator": "$(rk4.json)",
"export": "$(export.json)",
"options": {
"printInterval": 86400,
"fullSettingsFile": "@path(fullSettings.json)"
}
}
After running json_interface main.json
, the directory tree looks like this:
ModularInputFiles
|
| input
| |
| | bodies.json
| | export.json
| | fullSettings.json
| | main.json
| | rk4.json
| | translationalPropagator.json
|
| output
| |
| | epochs.txt
| | states.txt
|
| generateInput.m
| processOutput.m
The script processOutput.m
can be used to generate a plot using the output files.