1   /* Contributed in the public domain.
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.spice.binary.daf.generic;
18  
19  import org.orekit.errors.OrekitException;
20  import org.orekit.errors.OrekitMessages;
21  
22  /**
23   * Represents the first, global file record of a {@link DAF} file, containing
24   * generic metadata.
25   *
26   * @author Rafael Ayala
27   * @since 14.0
28   */
29  public class DAFFileRecord {
30  
31      /**
32       * String indicating the type of data stored in the DAF file. This should be of the format "DAF/XXXX",
33       * i.e., "DAF/" followed by 4 or less characters. For example, for SPK files, it should be "DAF/SPK"
34       */
35      private final String fileType;
36  
37      /**
38       * Number of doubles stored in each array summary.
39       */
40      private final int numDoublesSummary;
41  
42      /**
43       * Number of integers stored in each array summary.
44       */
45      private final int numIntsSummary;
46  
47      /**
48       * Number of characters used to store each array name.
49       */
50      private final int numCharsName;
51  
52      /**
53       * Size of a single array summary in doubles.
54       */
55      private final int singleSummarySizeDoubles;
56  
57      /**
58       * Internal name of the DAF file.
59       */
60      private final String description;
61  
62      /**
63       * Record number of the first summary record in the file.
64       */
65      private final int firstSummaryRecNum;
66  
67      /**
68       * Record number of the last summary record in the file.
69       */
70      private final int lastSummaryRecNum;
71  
72      /**
73       * Byte address of the first free byte in the file.
74       */
75      private final long firstFreeAddress;
76  
77      /**
78       * Endianness of the file. This should be either "LTL-IEEE" or "BIG-IEEE".
79       */
80      private final String endianString;
81  
82      /**
83       * Integrity-check string. This should match "FTPSTR:\r:\n:\r\n:\r:\u0081:\u0010\u00ce:ENDFTP".
84       */
85      private final String ftpString;
86  
87      /**
88       * Constructor initializing all metadata fields.
89       *
90       * @param fileType string of the format DAF/XXXX, i.e., "DAF/" followed by 4
91       * or less characters
92       * @param numDoublesSummary number of doubles in each array summary
93       * @param numIntsSummary number of integers in each array summary
94       * @param numCharsName number of characters used to store each array name
95       * @param singleSummarySizeDoubles size of a single array summary in doubles
96       * @param description internal name or description of the DAF file
97       * @param firstSummaryRecNum index of the first summary record in the DAF
98       * file
99       * @param lastSummaryRecNum index of the last summary record in the DAF file
100      * @param firstFreeAddress the first free byte address in the DAF file
101      * @param endianString the file endianness string (either "LTL-IEEE" or
102      * "BIG-IEEE")
103      * @param ftpString integrity-check string (should match
104      * "FTPSTR:\r:\n:\r\n:\r:\u0081:\u0010\u00ce:ENDFTP";)
105      */
106     public DAFFileRecord(final String fileType,
107             final int numDoublesSummary,
108             final int numIntsSummary,
109             final int numCharsName,
110             final int singleSummarySizeDoubles,
111             final String description,
112             final int firstSummaryRecNum,
113             final int lastSummaryRecNum,
114             final long firstFreeAddress,
115             final String endianString,
116             final String ftpString) {
117         // Check FTP string integrity
118         if (!DAFConstants.FTPSTR.equals(ftpString)) {
119             throw new OrekitException(OrekitMessages.INVALID_DAF_FTPSTR, description);
120         }
121         this.fileType = fileType;
122         this.numDoublesSummary = numDoublesSummary;
123         this.numIntsSummary = numIntsSummary;
124         this.numCharsName = numCharsName;
125         this.singleSummarySizeDoubles = singleSummarySizeDoubles;
126         this.description = description;
127         this.firstSummaryRecNum = firstSummaryRecNum;
128         this.lastSummaryRecNum = lastSummaryRecNum;
129         this.firstFreeAddress = firstFreeAddress;
130         this.endianString = endianString;
131         this.ftpString = ftpString;
132     }
133 
134     /**
135      * Get the file type string.
136      *
137      * @return the file type string
138      */
139     public String getFileType() {
140         return fileType;
141     }
142 
143     /**
144      * Get the number of doubles stored in each array summary.
145      *
146      * @return the number of doubles stored in each array summary
147      */
148     public int getNumDoublesSummary() {
149         return numDoublesSummary;
150     }
151 
152     /**
153      * Get the number of integers stored in each array summary.
154      *
155      * @return the number of integers stored in each array summary
156      */
157     public int getNumIntsSummary() {
158         return numIntsSummary;
159     }
160 
161     /**
162      * Get the number of characters used to store each array name.
163      *
164      * @return the number of characters used to store each array name
165      */
166     public int getNumCharsName() {
167         return numCharsName;
168     }
169 
170     /**
171      * Get the size of a single array summary in doubles.
172      *
173      * @return the size of a single array summary in doubles
174      */
175     public int getSingleSummarySizeDoubles() {
176         return singleSummarySizeDoubles;
177     }
178 
179     /**
180      * Get the internal name of the DAF file.
181      *
182      * @return the internal name of the DAF file
183      */
184     public String getDescription() {
185         return description;
186     }
187 
188     /**
189      * Get the record number of the first summary record in the DAF file.
190      *
191      * @return the record number of the first summary record in the DAF file
192      */
193     public int getFirstSummaryRecNum() {
194         return firstSummaryRecNum;
195     }
196 
197     /**
198      * Get the record number of the last summary record in the DAF file.
199      *
200      * @return the record number of the last summary record in the DAF file
201      */
202     public int getLastSummaryRecNum() {
203         return lastSummaryRecNum;
204     }
205 
206     /**
207      * Get the first free byte address in the DAF file.
208      *
209      * @return the first free byte address in the DAF file
210      */
211     public long getFirstFreeAddress() {
212         return firstFreeAddress;
213     }
214 
215     /**
216      * Get the endianness string of the file.
217      *
218      * @return the endianness string of the file
219      */
220     public String getEndianString() {
221         return endianString;
222     }
223 
224     /**
225      * Get the integrity-check (FTP) string.
226      *
227      * @return the integrity-check (FTP) string
228      */
229     public String getFtpString() {
230         return ftpString;
231     }
232 }