1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.orekit.files.ccsds.ndm.odm.ocm;
19  
20  import java.io.IOException;
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.orekit.files.ccsds.definitions.BodyFacade;
25  import org.orekit.files.ccsds.definitions.TimeConverter;
26  import org.orekit.files.ccsds.definitions.Units;
27  import org.orekit.files.ccsds.section.AbstractWriter;
28  import org.orekit.files.ccsds.utils.generation.Generator;
29  import org.orekit.utils.units.Unit;
30  
31  /** Writer for perturbations parameters data.
32   * @author Luc Maisonobe
33   * @since 11.0
34   */
35  class PerturbationsWriter extends AbstractWriter {
36  
37      /** Perturbation parameters block. */
38      private final Perturbations perturbations;
39  
40      /** Converter for dates. */
41      private final TimeConverter timeConverter;
42  
43      /** Create a writer.
44       * @param perturbations perturbations parameters to write
45       * @param timeConverter converter for dates
46       */
47      PerturbationsWriter(final Perturbations perturbations, final TimeConverter timeConverter) {
48          super(OcmDataSubStructureKey.pert.name(), OcmDataSubStructureKey.PERT.name());
49          this.perturbations = perturbations;
50          this.timeConverter = timeConverter;
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      protected void writeContent(final Generator generator) throws IOException {
56  
57          // perturbations parameters block
58          generator.writeComments(perturbations.getComments());
59  
60          // atmosphere
61          generator.writeEntry(PerturbationsKey.ATMOSPHERIC_MODEL.name(), perturbations.getAtmosphericModel(), null, false);
62  
63          // gravity
64          if (perturbations.getGravityModel() != null) {
65              final String model =
66                              new StringBuilder().
67                              append(perturbations.getGravityModel()).
68                              append(": ").
69                              append(perturbations.getGravityDegree()).
70                              append("D ").
71                              append(perturbations.getGravityOrder()).
72                              append('O').
73                              toString();
74              generator.writeEntry(PerturbationsKey.GRAVITY_MODEL.name(), model, null, false);
75          }
76          generator.writeEntry(PerturbationsKey.EQUATORIAL_RADIUS.name(),    perturbations.getEquatorialRadius(), Unit.KILOMETRE, false);
77          generator.writeEntry(PerturbationsKey.GM.name(),                   perturbations.getGm(), Units.KM3_PER_S2,             false);
78          if (perturbations.getNBodyPerturbations() != null && !perturbations.getNBodyPerturbations().isEmpty()) {
79              final List<String> names = new ArrayList<>();
80              for (BodyFacade bf : perturbations.getNBodyPerturbations()) {
81                  names.add(bf.getName());
82              }
83              generator.writeEntry(PerturbationsKey.N_BODY_PERTURBATIONS.name(), names, false);
84          }
85          generator.writeEntry(PerturbationsKey.CENTRAL_BODY_ROTATION.name(), perturbations.getCentralBodyRotation(), Units.DEG_PER_S,       false);
86          generator.writeEntry(PerturbationsKey.OBLATE_FLATTENING.name(),     perturbations.getOblateFlattening(), Unit.ONE,                 false);
87          generator.writeEntry(PerturbationsKey.OCEAN_TIDES_MODEL.name(),     perturbations.getOceanTidesModel(),                      null, false);
88          generator.writeEntry(PerturbationsKey.SOLID_TIDES_MODEL.name(),     perturbations.getSolidTidesModel(),                      null, false);
89          generator.writeEntry(PerturbationsKey.REDUCTION_THEORY.name(),      perturbations.getReductionTheory(),                      null, false);
90  
91          // radiation
92          generator.writeEntry(PerturbationsKey.ALBEDO_MODEL.name(),      perturbations.getAlbedoModel(),    null, false);
93          generator.writeEntry(PerturbationsKey.ALBEDO_GRID_SIZE.name(),  perturbations.getAlbedoGridSize(),       false);
94          generator.writeEntry(PerturbationsKey.SHADOW_MODEL.name(),      perturbations.getShadowModel(),          false);
95          if (perturbations.getShadowBodies() != null && !perturbations.getShadowBodies().isEmpty()) {
96              final List<String> names = new ArrayList<>();
97              for (BodyFacade bf : perturbations.getShadowBodies()) {
98                  names.add(bf.getName());
99              }
100             generator.writeEntry(PerturbationsKey.SHADOW_BODIES.name(), names, false);
101         }
102         generator.writeEntry(PerturbationsKey.SRP_MODEL.name(),          perturbations.getSrpModel(), null, false);
103 
104         // data source
105         generator.writeEntry(PerturbationsKey.SW_DATA_SOURCE.name(),    perturbations.getSpaceWeatherSource(),                    null, false);
106         generator.writeEntry(PerturbationsKey.SW_DATA_EPOCH.name(),     timeConverter, perturbations.getSpaceWeatherEpoch(),      true, false);
107         generator.writeEntry(PerturbationsKey.SW_INTERP_METHOD.name(),  perturbations.getInterpMethodSW(),                        null, false);
108         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_KP.name(),   perturbations.getFixedGeomagneticKp(), Units.NANO_TESLA,        false);
109         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_AP.name(),   perturbations.getFixedGeomagneticAp(), Units.NANO_TESLA,        false);
110         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_DST.name(),  perturbations.getFixedGeomagneticDst(), Units.NANO_TESLA,       false);
111         generator.writeEntry(PerturbationsKey.FIXED_F10P7.name(),       perturbations.getFixedF10P7(), Unit.SOLAR_FLUX_UNIT,            false);
112         generator.writeEntry(PerturbationsKey.FIXED_F10P7_MEAN.name(),  perturbations.getFixedF10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
113         generator.writeEntry(PerturbationsKey.FIXED_M10P7.name(),       perturbations.getFixedM10P7(), Unit.SOLAR_FLUX_UNIT,            false);
114         generator.writeEntry(PerturbationsKey.FIXED_M10P7_MEAN.name(),  perturbations.getFixedM10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
115         generator.writeEntry(PerturbationsKey.FIXED_S10P7.name(),       perturbations.getFixedS10P7(), Unit.SOLAR_FLUX_UNIT,            false);
116         generator.writeEntry(PerturbationsKey.FIXED_S10P7_MEAN.name(),  perturbations.getFixedS10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
117         generator.writeEntry(PerturbationsKey.FIXED_Y10P7.name(),       perturbations.getFixedY10P7(), Unit.SOLAR_FLUX_UNIT,            false);
118         generator.writeEntry(PerturbationsKey.FIXED_Y10P7_MEAN.name(),  perturbations.getFixedY10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
119 
120     }
121 
122 }