00001 // CLASSIFICATION: UNCLASSIFIED 00002 00003 /****************************************************************************/ 00004 /* RSC IDENTIFIER: Ellipsoid Library 00005 * 00006 * ABSTRACT 00007 * 00008 * The purpose of ELLIPSOID is to provide access to ellipsoid parameters 00009 * for a collection of common ellipsoids. A particular ellipsoid can be 00010 * accessed by using its standard 2-letter code to find its index in the 00011 * ellipsoid table. The index can then be used to retrieve the ellipsoid 00012 * name and parameters. 00013 * 00014 * By sequentially retrieving all of the ellipsoid codes and/or names, a 00015 * menu of the available ellipsoids can be constructed. The index values 00016 * resulting from selections from this menu can then be used to access the 00017 * parameters of the selected ellipsoid. 00018 * 00019 * This component depends on a data file named "ellips.dat", which contains 00020 * the ellipsoid parameter values. A copy of this file must be located in 00021 * the directory specified by the environment variable "MSPCCS_DATA", if 00022 * defined, or else in the current directory, whenever a program containing 00023 * this component is executed. 00024 * 00025 * Additional ellipsoids can be added to this file, either manually or using 00026 * the Create_Ellipsoid function. However, if a large number of ellipsoids 00027 * are added, the ellipsoid table array size in this component will have to 00028 * be increased. 00029 * 00030 * ERROR HANDLING 00031 * 00032 * This component checks parameters for valid values. If an invalid value 00033 * is found, the error code is combined with the current error code using 00034 * the bitwise or. This combining allows multiple error codes to be 00035 * returned. The possible error codes are: 00036 * 00037 * ELLIPSE_NO_ERROR : No errors occured in function 00038 * ELLIPSE_FILE_OPEN_ERROR : Ellipsoid file opening error 00039 * ELLIPSE_INITIALIZE_ERROR : Ellipsoid table can not initialize 00040 * ELLIPSE_TABLE_OVERFLOW_ERROR : Ellipsoid table overflow 00041 * ELLIPSE_NOT_INITIALIZED_ERROR: Ellipsoid table not initialized properly 00042 * ELLIPSE_INVALID_INDEX_ERROR : Index is an invalid value 00043 * ELLIPSE_INVALID_CODE_ERROR : Code was not found in table 00044 * ELLIPSE_A_ERROR : Semi-major axis less than or equal to zero 00045 * ELLIPSE_INV_F_ERROR : Inverse flattening outside of valid range 00046 * (250 to 350) 00047 * ELLIPSE_NOT_USERDEF_ERROR : Ellipsoid is not user defined - cannot be 00048 * deleted 00049 * 00050 * REUSE NOTES 00051 * 00052 * Ellipsoid is intended for reuse by any application that requires Earth 00053 * approximating ellipsoids. 00054 * 00055 * REFERENCES 00056 * 00057 * Further information on Ellipsoid can be found in the Reuse Manual. 00058 * 00059 * Ellipsoid originated from : U.S. Army Topographic Engineering Center (USATEC) 00060 * Geospatial Information Division (GID) 00061 * 7701 Telegraph Road 00062 * Alexandria, VA 22310-3864 00063 * 00064 * LICENSES 00065 * 00066 * None apply to this component. 00067 * 00068 * RESTRICTIONS 00069 * 00070 * Ellipsoid has no restrictions. 00071 * 00072 * ENVIRONMENT 00073 * 00074 * Ellipsoid was tested and certified in the following environments 00075 * 00076 * 1. Solaris 2.5 00077 * 2. Windows 95 00078 * 00079 * MODIFICATIONS 00080 * 00081 * Date Description 00082 * ---- ----------- 00083 * 11-19-95 Original Code 00084 * 17-Jan-97 Moved local constants out of public interface 00085 * Improved efficiency in algorithms (GEOTRANS) 00086 * 24-May-99 Added user-defined ellipsoids (GEOTRANS for JMTK) 00087 * 06-27-06 Moved data file to data directory 00088 * 03-09-07 Original C++ Code 00089 * 00090 */ 00091 00092 00093 /***************************************************************************/ 00094 /* 00095 * INCLUDES 00096 */ 00097 00098 #include "EllipsoidLibrary.h" 00099 #include "EllipsoidLibraryImplementation.h" 00100 00101 /* 00102 * ctype.h - standard C character handling library 00103 * stdio.h - standard C input/output library 00104 * stdlib.h - standard C general utilities library 00105 * string.h - standard C string handling library 00106 * DatumLibrary.h - used to determine if user defined ellipsoid 00107 * is in use by a user defined datum 00108 * EllipsoidLibrary.h - prototype error checking and error codes 00109 * Ellipsoid.h - used to store individual ellipsoid information 00110 * threads.h - used for thread safety 00111 * CoordinateConversionException.h - Exception handler 00112 * ErrorMessages.h - Contains exception messages 00113 */ 00114 00115 00116 using namespace MSP::CCS; 00117 00118 00119 /************************************************************************/ 00120 /* FUNCTIONS 00121 * 00122 */ 00123 00124 EllipsoidLibrary::EllipsoidLibrary( EllipsoidLibraryImplementation* __ellipsoidLibraryImplementation ) 00125 { 00126 /* 00127 * The constructor creates an empty list to store the ellipsoid data from ellips.dat 00128 * which is used to build the ellipsoid table. 00129 */ 00130 00131 _ellipsoidLibraryImplementation = __ellipsoidLibraryImplementation; 00132 } 00133 00134 00135 EllipsoidLibrary::EllipsoidLibrary( const EllipsoidLibrary &el ) 00136 { 00137 _ellipsoidLibraryImplementation = el._ellipsoidLibraryImplementation; 00138 } 00139 00140 00141 EllipsoidLibrary::~EllipsoidLibrary() 00142 { 00143 _ellipsoidLibraryImplementation = 0; 00144 } 00145 00146 00147 EllipsoidLibrary& EllipsoidLibrary::operator=( const EllipsoidLibrary &el ) 00148 { 00149 if ( &el == this ) 00150 return *this; 00151 00152 _ellipsoidLibraryImplementation = el._ellipsoidLibraryImplementation; 00153 00154 return *this; 00155 } 00156 00157 00158 void EllipsoidLibrary::defineEllipsoid( const char* code, const char* name, double semiMajorAxis, double flattening ) 00159 { 00160 /* 00161 * The function defineEllipsoid creates a new ellipsoid with the specified 00162 * Code, name, and axes. If the ellipsoid table has not been initialized, 00163 * the specified code is already in use, or a new version of the ellips.dat 00164 * file cannot be created, an exception is thrown. 00165 * Note that the indexes of all ellipsoids in the ellipsoid 00166 * table may be changed by this function. 00167 * 00168 * code : 2-letter ellipsoid code. (input) 00169 * name : Name of the new ellipsoid (input) 00170 * semiMajorAxis : Semi-major axis, in meters, of new ellipsoid (input) 00171 * flattening : Flattening of new ellipsoid. (input) 00172 * 00173 */ 00174 00175 _ellipsoidLibraryImplementation->defineEllipsoid( code, name, semiMajorAxis, flattening ); 00176 } 00177 00178 00179 void EllipsoidLibrary::removeEllipsoid( const char* code ) 00180 { 00181 /* 00182 * The function removeEllipsoid deletes a user defined ellipsoid with 00183 * the specified Code. If the ellipsoid table has not been created, 00184 * the specified code is in use by a user defined datum, or a new version 00185 * of the ellips.dat file cannot be created, an exception is thrown. 00186 * Note that the indexes of all 00187 * ellipsoids in the ellipsoid table may be changed by this function. 00188 * 00189 * code : 2-letter ellipsoid code. (input) 00190 * 00191 */ 00192 00193 _ellipsoidLibraryImplementation->removeEllipsoid( code ); 00194 } 00195 00196 00197 void EllipsoidLibrary::getEllipsoidCount( long *count ) 00198 { 00199 /* 00200 * The function getEllipsoidCount returns the number of ellipsoids in the 00201 * ellipsoid table. 00202 * 00203 * count : The number of ellipsoids in the ellipsoid table. (output) 00204 * 00205 */ 00206 00207 _ellipsoidLibraryImplementation->ellipsoidCount( count ); 00208 } 00209 00210 00211 void EllipsoidLibrary::getEllipsoidIndex( const char *code, long* index ) 00212 { 00213 /* 00214 * The function getEllipsoidIndex returns the index of the ellipsoid in 00215 * the ellipsoid table with the specified code. If ellipsoid code is not found, 00216 * an exception is thrown. 00217 * 00218 * code : 2-letter ellipsoid code. (input) 00219 * index : Index of the ellipsoid in the ellipsoid table with the 00220 * specified code (output) 00221 * 00222 */ 00223 00224 _ellipsoidLibraryImplementation->ellipsoidIndex( code, index ); 00225 } 00226 00227 00228 void EllipsoidLibrary::getEllipsoidInfo( const long index, char *code, char *name ) 00229 { 00230 /* 00231 * The Function getEllipsoidInfo returns the 2-letter code and name of the 00232 * ellipsoid in the ellipsoid table with the specified index. If index is 00233 * invalid, an exception is thrown. 00234 * 00235 * index : Index of a given ellipsoid in the ellipsoid table (input) 00236 * code : 2-letter ellipsoid code. (output) 00237 * name : Name of the ellipsoid referencd by index (output) 00238 * 00239 */ 00240 00241 _ellipsoidLibraryImplementation->ellipsoidCode( index, code ); 00242 _ellipsoidLibraryImplementation->ellipsoidName( index, name ); 00243 } 00244 00245 00246 void EllipsoidLibrary::getEllipsoidParameters( const long index, double *a, double *f ) 00247 { 00248 /* 00249 * The function getEllipsoidParameters returns the semi-major axis and flattening 00250 * for the ellipsoid with the specified index. If index is invalid, 00251 * an exception is thrown. 00252 * 00253 * index : Index of a given ellipsoid in the ellipsoid table (input) 00254 * a : Semi-major axis, in meters, of ellipsoid (output) 00255 * f : Flattening of ellipsoid. (output) 00256 * 00257 */ 00258 00259 _ellipsoidLibraryImplementation->ellipsoidParameters( index, a, f ); 00260 } 00261 00262 // CLASSIFICATION: UNCLASSIFIED