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;
19  
20  import java.io.IOException;
21  
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.TimeStampedPVCoordinates;
27  import org.orekit.utils.units.Unit;
28  
29  /** Writer for state vector data.
30   * @author Luc Maisonobe
31   * @since 11.0
32   */
33  public class StateVectorWriter extends AbstractWriter {
34  
35      /** State vector block. */
36      private final StateVector stateVector;
37  
38      /** Converter for dates. */
39      private final TimeConverter timeConverter;
40  
41      /** Create a writer.
42       * @param xmlTag name of the XML tag surrounding the section
43       * @param kvnTag name of the KVN tag surrounding the section (may be null)
44       * @param stateVector state vector to write
45       * @param timeConverter converter for dates
46       */
47      public StateVectorWriter(final String xmlTag, final String kvnTag,
48                               final StateVector stateVector, final TimeConverter timeConverter) {
49          super(xmlTag, kvnTag);
50          this.stateVector   = stateVector;
51          this.timeConverter = timeConverter;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      protected void writeContent(final Generator generator) throws IOException {
57  
58          // state vector block
59          final TimeStampedPVCoordinates pv = stateVector.toTimeStampedPVCoordinates();
60          generator.writeComments(stateVector.getComments());
61          generator.writeEntry(StateVectorKey.EPOCH.name(), timeConverter, pv.getDate(), true, true);
62          generator.writeEntry(StateVectorKey.X.name(),     pv.getPosition().getX(), Unit.KILOMETRE, true);
63          generator.writeEntry(StateVectorKey.Y.name(),     pv.getPosition().getY(), Unit.KILOMETRE, true);
64          generator.writeEntry(StateVectorKey.Z.name(),     pv.getPosition().getZ(), Unit.KILOMETRE, true);
65          generator.writeEntry(StateVectorKey.X_DOT.name(), pv.getVelocity().getX(), Units.KM_PER_S, true);
66          generator.writeEntry(StateVectorKey.Y_DOT.name(), pv.getVelocity().getY(), Units.KM_PER_S, true);
67          generator.writeEntry(StateVectorKey.Z_DOT.name(), pv.getVelocity().getZ(), Units.KM_PER_S, true);
68          // note that OPM format does not use X_DDOT, Y_DDOT, Z_DDOT, they are used only in OEM format
69  
70      }
71  
72  }