UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
EllipsoidLibrary.cpp
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 
3 /****************************************************************************/
4 /* RSC IDENTIFIER: Ellipsoid Library
5  *
6  * ABSTRACT
7  *
8  * The purpose of ELLIPSOID is to provide access to ellipsoid parameters
9  * for a collection of common ellipsoids. A particular ellipsoid can be
10  * accessed by using its standard 2-letter code to find its index in the
11  * ellipsoid table. The index can then be used to retrieve the ellipsoid
12  * name and parameters.
13  *
14  * By sequentially retrieving all of the ellipsoid codes and/or names, a
15  * menu of the available ellipsoids can be constructed. The index values
16  * resulting from selections from this menu can then be used to access the
17  * parameters of the selected ellipsoid.
18  *
19  * This component depends on a data file named "ellips.dat", which contains
20  * the ellipsoid parameter values. A copy of this file must be located in
21  * the directory specified by the environment variable "MSPCCS_DATA", if
22  * defined, or else in the current directory, whenever a program containing
23  * this component is executed.
24  *
25  * Additional ellipsoids can be added to this file, either manually or using
26  * the Create_Ellipsoid function. However, if a large number of ellipsoids
27  * are added, the ellipsoid table array size in this component will have to
28  * be increased.
29  *
30  * ERROR HANDLING
31  *
32  * This component checks parameters for valid values. If an invalid value
33  * is found, the error code is combined with the current error code using
34  * the bitwise or. This combining allows multiple error codes to be
35  * returned. The possible error codes are:
36  *
37  * ELLIPSE_NO_ERROR : No errors occured in function
38  * ELLIPSE_FILE_OPEN_ERROR : Ellipsoid file opening error
39  * ELLIPSE_INITIALIZE_ERROR : Ellipsoid table can not initialize
40  * ELLIPSE_NOT_INITIALIZED_ERROR: Ellipsoid table not initialized properly
41  * ELLIPSE_INVALID_INDEX_ERROR : Index is an invalid value
42  * ELLIPSE_INVALID_CODE_ERROR : Code was not found in table
43  * ELLIPSE_A_ERROR : Semi-major axis less than or equal to zero
44  * ELLIPSE_INV_F_ERROR : Inverse flattening outside of valid range
45  * (250 to 350)
46  * ELLIPSE_NOT_USERDEF_ERROR : Ellipsoid is not user defined - cannot be
47  * deleted
48  *
49  * REUSE NOTES
50  *
51  * Ellipsoid is intended for reuse by any application that requires Earth
52  * approximating ellipsoids.
53  *
54  * REFERENCES
55  *
56  * Further information on Ellipsoid can be found in the Reuse Manual.
57  *
58  * Ellipsoid originated from : U.S. Army Topographic Engineering Center (USATEC)
59  * Geospatial Information Division (GID)
60  * 7701 Telegraph Road
61  * Alexandria, VA 22310-3864
62  *
63  * LICENSES
64  *
65  * None apply to this component.
66  *
67  * RESTRICTIONS
68  *
69  * Ellipsoid has no restrictions.
70  *
71  * ENVIRONMENT
72  *
73  * Ellipsoid was tested and certified in the following environments
74  *
75  * 1. Solaris 2.5
76  * 2. Windows 95
77  *
78  * MODIFICATIONS
79  *
80  * Date Description
81  * ---- -----------
82  * 11-19-95 Original Code
83  * 17-Jan-97 Moved local constants out of public interface
84  * Improved efficiency in algorithms (GEOTRANS)
85  * 24-May-99 Added user-defined ellipsoids (GEOTRANS for JMTK)
86  * 06-27-06 Moved data file to data directory
87  * 03-09-07 Original C++ Code
88  *
89  */
90 
91 
92 /***************************************************************************/
93 /*
94  * INCLUDES
95  */
96 
97 #include "EllipsoidLibrary.h"
99 
100 /*
101  * ctype.h - standard C character handling library
102  * stdio.h - standard C input/output library
103  * stdlib.h - standard C general utilities library
104  * string.h - standard C string handling library
105  * DatumLibrary.h - used to determine if user defined ellipsoid
106  * is in use by a user defined datum
107  * EllipsoidLibrary.h - prototype error checking and error codes
108  * Ellipsoid.h - used to store individual ellipsoid information
109  * threads.h - used for thread safety
110  * CoordinateConversionException.h - Exception handler
111  * ErrorMessages.h - Contains exception messages
112  */
113 
114 
115 using namespace MSP::CCS;
116 
117 
118 /************************************************************************/
119 /* FUNCTIONS
120  *
121  */
122 
124 {
125 /*
126  * The constructor creates an empty list to store the ellipsoid data from ellips.dat
127  * which is used to build the ellipsoid table.
128  */
129 
130  _ellipsoidLibraryImplementation = __ellipsoidLibraryImplementation;
131 }
132 
133 
135 {
136  _ellipsoidLibraryImplementation = el._ellipsoidLibraryImplementation;
137 }
138 
139 
141 {
142  _ellipsoidLibraryImplementation = 0;
143 }
144 
145 
147 {
148  if ( &el == this )
149  return *this;
150 
151  _ellipsoidLibraryImplementation = el._ellipsoidLibraryImplementation;
152 
153  return *this;
154 }
155 
156 
157 void EllipsoidLibrary::defineEllipsoid( const char* code, const char* name, double semiMajorAxis, double flattening )
158 {
159 /*
160  * The function defineEllipsoid creates a new ellipsoid with the specified
161  * Code, name, and axes. If the ellipsoid table has not been initialized,
162  * the specified code is already in use, or a new version of the ellips.dat
163  * file cannot be created, an exception is thrown.
164  * Note that the indexes of all ellipsoids in the ellipsoid
165  * table may be changed by this function.
166  *
167  * code : 2-letter ellipsoid code. (input)
168  * name : Name of the new ellipsoid (input)
169  * semiMajorAxis : Semi-major axis, in meters, of new ellipsoid (input)
170  * flattening : Flattening of new ellipsoid. (input)
171  *
172  */
173 
174  _ellipsoidLibraryImplementation->defineEllipsoid( code, name, semiMajorAxis, flattening );
175 }
176 
177 
178 void EllipsoidLibrary::removeEllipsoid( const char* code )
179 {
180 /*
181  * The function removeEllipsoid deletes a user defined ellipsoid with
182  * the specified Code. If the ellipsoid table has not been created,
183  * the specified code is in use by a user defined datum, or a new version
184  * of the ellips.dat file cannot be created, an exception is thrown.
185  * Note that the indexes of all
186  * ellipsoids in the ellipsoid table may be changed by this function.
187  *
188  * code : 2-letter ellipsoid code. (input)
189  *
190  */
191 
192  _ellipsoidLibraryImplementation->removeEllipsoid( code );
193 }
194 
195 
197 {
198 /*
199  * The function getEllipsoidCount returns the number of ellipsoids in the
200  * ellipsoid table.
201  *
202  * count : The number of ellipsoids in the ellipsoid table. (output)
203  *
204  */
205 
206  _ellipsoidLibraryImplementation->ellipsoidCount( count );
207 }
208 
209 
210 void EllipsoidLibrary::getEllipsoidIndex( const char *code, long* index )
211 {
212 /*
213  * The function getEllipsoidIndex returns the index of the ellipsoid in
214  * the ellipsoid table with the specified code. If ellipsoid code is not found,
215  * an exception is thrown.
216  *
217  * code : 2-letter ellipsoid code. (input)
218  * index : Index of the ellipsoid in the ellipsoid table with the
219  * specified code (output)
220  *
221  */
222 
223  _ellipsoidLibraryImplementation->ellipsoidIndex( code, index );
224 }
225 
226 
227 void EllipsoidLibrary::getEllipsoidInfo( const long index, char *code, char *name )
228 {
229 /*
230  * The Function getEllipsoidInfo returns the 2-letter code and name of the
231  * ellipsoid in the ellipsoid table with the specified index. If index is
232  * invalid, an exception is thrown.
233  *
234  * index : Index of a given ellipsoid in the ellipsoid table (input)
235  * code : 2-letter ellipsoid code. (output)
236  * name : Name of the ellipsoid referencd by index (output)
237  *
238  */
239 
240  _ellipsoidLibraryImplementation->ellipsoidCode( index, code );
241  _ellipsoidLibraryImplementation->ellipsoidName( index, name );
242 }
243 
244 
245 void EllipsoidLibrary::getEllipsoidParameters( const long index, double *a, double *f )
246 {
247 /*
248  * The function getEllipsoidParameters returns the semi-major axis and flattening
249  * for the ellipsoid with the specified index. If index is invalid,
250  * an exception is thrown.
251  *
252  * index : Index of a given ellipsoid in the ellipsoid table (input)
253  * a : Semi-major axis, in meters, of ellipsoid (output)
254  * f : Flattening of ellipsoid. (output)
255  *
256  */
257 
258  _ellipsoidLibraryImplementation->ellipsoidParameters( index, a, f );
259 }
260 
261 // CLASSIFICATION: UNCLASSIFIED