PerturbationsWriter.java

  1. /* Copyright 2002-2024 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. package org.orekit.files.ccsds.ndm.odm.ocm;

  18. import java.io.IOException;
  19. import java.util.ArrayList;
  20. import java.util.List;

  21. import org.orekit.files.ccsds.definitions.BodyFacade;
  22. import org.orekit.files.ccsds.definitions.TimeConverter;
  23. import org.orekit.files.ccsds.definitions.Units;
  24. import org.orekit.files.ccsds.section.AbstractWriter;
  25. import org.orekit.files.ccsds.utils.generation.Generator;
  26. import org.orekit.utils.units.Unit;

  27. /** Writer for perturbations parameters data.
  28.  * @author Luc Maisonobe
  29.  * @since 11.0
  30.  */
  31. class PerturbationsWriter extends AbstractWriter {

  32.     /** Perturbation parameters block. */
  33.     private final Perturbations perturbations;

  34.     /** Converter for dates. */
  35.     private final TimeConverter timeConverter;

  36.     /** Create a writer.
  37.      * @param perturbations perturbations parameters to write
  38.      * @param timeConverter converter for dates
  39.      */
  40.     PerturbationsWriter(final Perturbations perturbations, final TimeConverter timeConverter) {
  41.         super(OcmDataSubStructureKey.pert.name(), OcmDataSubStructureKey.PERT.name());
  42.         this.perturbations = perturbations;
  43.         this.timeConverter = timeConverter;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     protected void writeContent(final Generator generator) throws IOException {

  48.         // perturbations parameters block
  49.         generator.writeComments(perturbations.getComments());

  50.         // atmosphere
  51.         generator.writeEntry(PerturbationsKey.ATMOSPHERIC_MODEL.name(), perturbations.getAtmosphericModel(), null, false);

  52.         // gravity
  53.         if (perturbations.getGravityModel() != null) {
  54.             final String model =
  55.                             new StringBuilder().
  56.                             append(perturbations.getGravityModel()).
  57.                             append(": ").
  58.                             append(perturbations.getGravityDegree()).
  59.                             append("D ").
  60.                             append(perturbations.getGravityOrder()).
  61.                             append('O').
  62.                             toString();
  63.             generator.writeEntry(PerturbationsKey.GRAVITY_MODEL.name(), model, null, false);
  64.         }
  65.         generator.writeEntry(PerturbationsKey.EQUATORIAL_RADIUS.name(),    perturbations.getEquatorialRadius(), Unit.KILOMETRE, false);
  66.         generator.writeEntry(PerturbationsKey.GM.name(),                   perturbations.getGm(), Units.KM3_PER_S2,             false);
  67.         if (perturbations.getNBodyPerturbations() != null && !perturbations.getNBodyPerturbations().isEmpty()) {
  68.             final List<String> names = new ArrayList<>();
  69.             for (BodyFacade bf : perturbations.getNBodyPerturbations()) {
  70.                 names.add(bf.getName());
  71.             }
  72.             generator.writeEntry(PerturbationsKey.N_BODY_PERTURBATIONS.name(), names, false);
  73.         }
  74.         generator.writeEntry(PerturbationsKey.CENTRAL_BODY_ROTATION.name(), perturbations.getCentralBodyRotation(), Units.DEG_PER_S,       false);
  75.         generator.writeEntry(PerturbationsKey.OBLATE_FLATTENING.name(),     perturbations.getOblateFlattening(), Unit.ONE,                 false);
  76.         generator.writeEntry(PerturbationsKey.OCEAN_TIDES_MODEL.name(),     perturbations.getOceanTidesModel(),                      null, false);
  77.         generator.writeEntry(PerturbationsKey.SOLID_TIDES_MODEL.name(),     perturbations.getSolidTidesModel(),                      null, false);
  78.         generator.writeEntry(PerturbationsKey.REDUCTION_THEORY.name(),      perturbations.getReductionTheory(),                      null, false);

  79.         // radiation
  80.         generator.writeEntry(PerturbationsKey.ALBEDO_MODEL.name(),      perturbations.getAlbedoModel(),    null, false);
  81.         generator.writeEntry(PerturbationsKey.ALBEDO_GRID_SIZE.name(),  perturbations.getAlbedoGridSize(),       false);
  82.         generator.writeEntry(PerturbationsKey.SHADOW_MODEL.name(),      perturbations.getShadowModel(),          false);
  83.         if (perturbations.getShadowBodies() != null && !perturbations.getShadowBodies().isEmpty()) {
  84.             final List<String> names = new ArrayList<>();
  85.             for (BodyFacade bf : perturbations.getShadowBodies()) {
  86.                 names.add(bf.getName());
  87.             }
  88.             generator.writeEntry(PerturbationsKey.SHADOW_BODIES.name(), names, false);
  89.         }
  90.         generator.writeEntry(PerturbationsKey.SRP_MODEL.name(),          perturbations.getSrpModel(), null, false);

  91.         // data source
  92.         generator.writeEntry(PerturbationsKey.SW_DATA_SOURCE.name(),    perturbations.getSpaceWeatherSource(),                    null, false);
  93.         generator.writeEntry(PerturbationsKey.SW_DATA_EPOCH.name(),     timeConverter, perturbations.getSpaceWeatherEpoch(),      true, false);
  94.         generator.writeEntry(PerturbationsKey.SW_INTERP_METHOD.name(),  perturbations.getInterpMethodSW(),                        null, false);
  95.         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_KP.name(),   perturbations.getFixedGeomagneticKp(), Units.NANO_TESLA,        false);
  96.         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_AP.name(),   perturbations.getFixedGeomagneticAp(), Units.NANO_TESLA,        false);
  97.         generator.writeEntry(PerturbationsKey.FIXED_GEOMAG_DST.name(),  perturbations.getFixedGeomagneticDst(), Units.NANO_TESLA,       false);
  98.         generator.writeEntry(PerturbationsKey.FIXED_F10P7.name(),       perturbations.getFixedF10P7(), Unit.SOLAR_FLUX_UNIT,            false);
  99.         generator.writeEntry(PerturbationsKey.FIXED_F10P7_MEAN.name(),  perturbations.getFixedF10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
  100.         generator.writeEntry(PerturbationsKey.FIXED_M10P7.name(),       perturbations.getFixedM10P7(), Unit.SOLAR_FLUX_UNIT,            false);
  101.         generator.writeEntry(PerturbationsKey.FIXED_M10P7_MEAN.name(),  perturbations.getFixedM10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
  102.         generator.writeEntry(PerturbationsKey.FIXED_S10P7.name(),       perturbations.getFixedS10P7(), Unit.SOLAR_FLUX_UNIT,            false);
  103.         generator.writeEntry(PerturbationsKey.FIXED_S10P7_MEAN.name(),  perturbations.getFixedS10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);
  104.         generator.writeEntry(PerturbationsKey.FIXED_Y10P7.name(),       perturbations.getFixedY10P7(), Unit.SOLAR_FLUX_UNIT,            false);
  105.         generator.writeEntry(PerturbationsKey.FIXED_Y10P7_MEAN.name(),  perturbations.getFixedY10P7Mean(), Unit.SOLAR_FLUX_UNIT,        false);

  106.     }

  107. }