Change name authored by Julien LEBLOND's avatar Julien LEBLOND
# How to generate a CZML file ?
## Prerequisities
- [Java](https://www.java.com/fr/) 8 or more
* A directory and a path of the inputs if there are some.
* A directory and a path of the output.
In order to generate a CZML file, we will first describe the intern architecture of a CZML file :
## CZML Structure
A CZML file is a subset of [JSON files](https://en.wikipedia.org/wiki/JSON). Hence, a CZML file contains only one array of a JSON file. Objects inside the CZML are nammed **[packet]()**, all the objects we will use are in fact packets.
### The [Header](Header)
The header describes the entire scene and the time the simulation will lasts. It is absolutly mandatory that the header is the first object created while writing in the CZML file.
### Objects that can be added :
#### [Satellite](Satellite)
The satellite object will create a satellite and its path. The path will be computed with a propagation for the duration of the scene. (**A propagator can create the header in order to setup the propagation parameters before**).
#### [Ground Station](CZMLGroundStation)
The ground station object will create and display a ground station at the surface of the earth.
#### [Visibility Cone](VisibilityCone)
The visibility cone is an object that can be build in order to create a [Line Of Visibility](LineOfVisibility) of to display what the station sees. It can be created only with a station then it will not be bounded to a specific satellite. Or it can be created with a satellite and the visiblity cone will have the height of the satellite.
#### [Line Of Visibility](LineOfVisibility)
The line of visibility is a line that will be displayed only when a satellite is visible in the local sky of a ground station.
#### [Constellation](Constellation)
The constellation object creates several [Satellites](Satellite) at the same time in order to build a constellation with the number of satellites given and orbital planes given.
## Functions to use
After each object is created, the function `.generateCZML()` is callable to write the object into the CZML file. When the last object is written, the function `.endFile()` will need to be called in order to finish the CZML file (Be careful to use `endFile()` only on the last object of the file).
Here is an example of what a classic OreCZML call can look like :
```java
// String intput and for Output
final String root = System.getProperty("user.dir").replace("\\", "/");
final String outputPath = root + "/" + "Output";
final String outputName = "Output_CZML.txt";
final String output = outputPath + "/" + outputName;
final String oemFile = "intputOem.kvn";
final String inputOemFile = root + "/" + oemFile;
// Setup of the time scale and the frame
final Frame EME2000 = FramesFactory.getEME2000();
final TimeScale UTC = TimeScalesFactory.getUTC();
// Setup of the start and end date
final AbsoluteDate startDate = new AbsoluteDate(2022, 1, 17, 12, 0, 0.0, UTC);
final AbsoluteDate finalDate = new AbsoluteDate(2022, 1, 17, 13, 0, 0.0, UTC);
// Input : An LEO orbit of 550 km of altitude, with an inclination of 60°, a perigee argument of 90° and a //right ascension of the ascending node of 90°
final KeplerianOrbit initialOrbit = new KeplerianOrbit(6928000, 0, FastMath.toRadians(60), 0, FastMath.toRadians(90), FastMath.toRadians(90), PositionAngleType.MEAN, EME2000, startDate, Constants.WGS84_EARTH_MU);
// Topocentric frame of Toulouse
// Setup ITRF
final IERSConventions IERS = IERSConventions.IERS_2010;
final Frame ITRF = FramesFactory.getITRF(IERS, true);
// Definition of the earth
final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, ITRF);
// Position of Toulouse
final GeodeticPoint toulouseFrame = new GeodeticPoint(FastMath.toRadians(43.6047), FastMath.toRadians(1.4442), 10);
final TopocentricFrame topocentricToulouse = new TopocentricFrame(earth, toulouseFrame, "Toulouse Frame");
// Header
// Clock
Clock clock = new Clock(inputOemFile);
Header header = new Header("document", "Header Principal", clock);
// Satellite
Satellite satellite = new Satellite(inputOemFile, header);
// Ground Station
CZMLGroundStation toulouse = new CZMLGroundStation(topocentricToulouse, header);
// Line of visibility
LineOfVisibility lineOfVisu = new LineOfVisibility(topocentricToulouse, satellite, header);
// Writing into the CZML
header.generateCZML();
satellite.generateCZML();
toulouse.generateCZML();
lineOfVisu.generateCZML();
lineofVisu.endFile()
// Writing into the file
final CZMLFile CZMLfile = new CZMLFile(outputPath, output);
CZMLfile.write(header);
CZMLfile.write(satellite);
CZMLfile.write(toulouse);
CZMLfile.write(lineOfVisu);
```