00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include "geodesy.h"
00040 #include "constants.h"
00041
00042
00043 int main( int argc, char* argv[] )
00044 {
00045 const int min_nr_args = 3;
00046 int ellipse=0;
00047 int fn_choice=0;
00048 GEODESY_enumReferenceEllipse referenceEllipse = GEODESY_REFERENCE_ELLIPSE_WGS84;
00049 BOOL result = FALSE;
00050
00051 if( argc < min_nr_args )
00052 {
00053 printf("\nUSAGE\n");
00054 printf("geodesy <ellipse> <function> <additional arguments for function ... >\n");
00055 printf("\nellipse:\n");
00056 printf("0, WGS84\n");
00057 printf("1, Airy 1830\n");
00058 printf("2, Modified Airy\n");
00059 printf("3, Australian National\n");
00060 printf("4, Bessel 1841\n");
00061 printf("5, Clarke 1866\n");
00062 printf("6, Clarke 1880\n");
00063 printf("7, Everest(India 1830)\n");
00064 printf("8, Everest(Brunei & E.Malaysia)\n");
00065 printf("9, Everest(W.Malaysia & Singapore)\n");
00066 printf("10, Geodetic Reference System 1980\n");
00067 printf("11, Helmert 1906\n");
00068 printf("12, Hough 1960\n");
00069 printf("13, International 1924\n");
00070 printf("14, South American 1969\n");
00071 printf("15, World Geodetic System 1972\n");
00072
00073 printf("\nfunction and additional arguments:\n");
00074 printf("0, GEODESY_GetReferenceEllipseParameters\n");
00075 printf(" requires no additions arguments\n");
00076 printf("1, GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates\n");
00077 printf(" latitude[deg], longitude[deg], height[m]\n");
00078 printf("2, GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates\n");
00079 printf(" userX[m], userY[m], userZ[m]\n");
00080 printf("3, GEODESY_ComputeNorthingEastingVertical\n");
00081 printf(" ref_lat[deg], ref_lon[deg] ref_hgt[m], lat[deg], lon[deg], hgt[m]\n");
00082 printf("4 ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame\n" );
00083 printf(" fromX[m], fromY[m], fromZ[m], toX[m], toY[m], toZ[m]\n" );
00084 printf("5, GEODESY_ComputePositionDifference\n");
00085 printf(" ref_lat[deg], ref_lon[deg] ref_hgt[m], lat[deg], lon[deg], hgt[m]\n");
00086
00087 return 0;
00088 }
00089
00090 ellipse = atoi(argv[1]);
00091 if( ellipse > 15 )
00092 {
00093 printf("Invalid ellipse argument\n");
00094 return -1;
00095 }
00096 referenceEllipse = (GEODESY_enumReferenceEllipse)ellipse;
00097
00098 fn_choice = atoi(argv[2]);
00099 if( fn_choice < 0 || fn_choice > 5 )
00100 {
00101 printf("Invalid function argument\n");
00102 return -1;
00103 }
00104
00105
00106
00107 switch(fn_choice)
00108 {
00109 case 0: if( argc != 3 ){ printf("Invalid function arguments\n"); return -1; } break;
00110 case 1: if( argc != 6 ){ printf("Invalid function arguments\n"); return -1; } break;
00111 case 2: if( argc != 6 ){ printf("Invalid function arguments\n"); return -1; } break;
00112 case 3: if( argc != 9 ){ printf("Invalid function arguments\n"); return -1; } break;
00113 case 4: if( argc != 9 ){ printf("Invalid function arguments\n"); return -1; } break;
00114 case 5: if( argc != 6 ){ printf("Invalid function arguments\n"); return -1; } break;
00115 default: break;
00116 }
00117
00118 switch(fn_choice)
00119 {
00120 case 0:
00121 {
00122 double a;
00123 double b;
00124 double f_inv;
00125 double e2;
00126
00127 result = GEODESY_GetReferenceEllipseParameters( referenceEllipse,
00128 &a,
00129 &b,
00130 &f_inv,
00131 &e2
00132 );
00133 if( result == FALSE )
00134 {
00135 printf("GEODESY_GetReferenceEllipseParameters returned FALSE\n");
00136 return -1;
00137 }
00138
00139 printf( "GEODESY_GetReferenceEllipseParameters\n" );
00140 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00141 printf( "a [m] = %20.3f\n", a );
00142 printf( "b [m] = %20.9f\n", b );
00143 printf( "f_inv [] = %20.11f\n", f_inv );
00144 printf( "e2 [] = %.15f\n\n", e2 );
00145 break;
00146 }
00147 case 1:
00148 {
00149 double latitude;
00150 double longitude;
00151 double height;
00152 double x;
00153 double y;
00154 double z;
00155
00156 latitude = atof( argv[3] )*DEG2RAD;
00157 longitude = atof( argv[4] )*DEG2RAD;
00158 height = atof( argv[5] );
00159
00160 result = GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates(
00161 referenceEllipse,
00162 latitude,
00163 longitude,
00164 height,
00165 &x,
00166 &y,
00167 &z
00168 );
00169 if( result == FALSE )
00170 {
00171 printf("GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates returned FALSE\n");
00172 return -1;
00173 }
00174 printf( "GEODESY_ConvertGeodeticCurvilinearToEarthFixedCartesianCoordinates\n" );
00175 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00176 printf( "latitude [deg] = %.12lf\n", latitude*RAD2DEG );
00177 printf( "longitude [deg] = %.12lf\n", longitude*RAD2DEG );
00178 printf( "height [m] = %.4lf\n", height );
00179 printf( "x [m] = %.4lf\n", x );
00180 printf( "y [m] = %.4lf\n", y );
00181 printf( "z [m] = %.4lf\n\n", z );
00182 break;
00183 }
00184 case 2:
00185 {
00186 double latitude;
00187 double longitude;
00188 double height;
00189 double x;
00190 double y;
00191 double z;
00192
00193 x = atof( argv[3] );
00194 y = atof( argv[4] );
00195 z = atof( argv[5] );
00196
00197 result = GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates(
00198 referenceEllipse,
00199 x,
00200 y,
00201 z,
00202 &latitude,
00203 &longitude,
00204 &height
00205 );
00206 if( result == FALSE )
00207 {
00208 printf("GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates returned FALSE\n");
00209 return -1;
00210 }
00211
00212 printf( "GEODESY_ConvertEarthFixedCartesianToGeodeticCurvilinearCoordinates\n" );
00213 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00214 printf( "latitude [deg] = %.12lf\n", latitude*RAD2DEG );
00215 printf( "longitude [deg] = %.12lf\n", longitude*RAD2DEG );
00216 printf( "height [m] = %.4lf\n", height );
00217 printf( "x [m] = %.4lf\n", x );
00218 printf( "y [m] = %.4lf\n", y );
00219 printf( "z [m] = %.4lf\n\n", z );
00220 break;
00221 }
00222 case 3:
00223 {
00224 double referenceLatitude;
00225 double referenceLongitude;
00226 double referenceHeight;
00227 double latitude;
00228 double longitude;
00229 double height;
00230 double northing;
00231 double easting;
00232 double vertical;
00233
00234 referenceLatitude = atof(argv[3])*DEG2RAD;
00235 referenceLongitude= atof(argv[4])*DEG2RAD;
00236 referenceHeight = atof(argv[5]);
00237
00238 latitude = atof(argv[6])*DEG2RAD;
00239 longitude= atof(argv[7])*DEG2RAD;
00240 height = atof(argv[8]);
00241
00242 result = GEODESY_ComputeNorthingEastingVertical(
00243 referenceEllipse,
00244 referenceLatitude,
00245 referenceLongitude,
00246 referenceHeight,
00247 latitude,
00248 longitude,
00249 height,
00250 &northing,
00251 &easting,
00252 &vertical
00253 );
00254 if( result == FALSE )
00255 {
00256 printf("GEODESY_ComputeNorthingEastingVertical returned FALSE\n");
00257 return -1;
00258 }
00259
00260 printf( "GEODESY_ComputeNorthingEastingVertical\n" );
00261 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00262 printf( "reference_latitude [deg] = %.12lf\n", referenceLatitude*RAD2DEG );
00263 printf( "reference_longitude [deg] = %.12lf\n", referenceLongitude*RAD2DEG );
00264 printf( "reference_height [m] = %.4lf\n", referenceHeight );
00265 printf( "latitude [deg] = %.12lf\n", latitude*RAD2DEG );
00266 printf( "longitude [deg] = %.12lf\n", longitude*RAD2DEG );
00267 printf( "height [m] = %.4lf\n", height );
00268 printf( "northing [m] = %.4lf\n", northing );
00269 printf( "easting [m] = %.4lf\n", easting );
00270 printf( "vertical [m] = %.4lf\n\n", vertical );
00271 break;
00272 }
00273 case 4:
00274 {
00275 double elevation=0;
00276 double azimuth=0;
00277 double fromX = atof( argv[3] );
00278 double fromY = atof( argv[4] );
00279 double fromZ = atof( argv[5] );
00280 double toX = atof( argv[6] );
00281 double toY = atof( argv[7] );
00282 double toZ = atof( argv[8] );
00283
00284 result = GEODESY_ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame(
00285 referenceEllipse,
00286 fromX,
00287 fromY,
00288 fromZ,
00289 toX,
00290 toY,
00291 toZ,
00292 &elevation,
00293 &azimuth
00294 );
00295 if( result == FALSE )
00296 {
00297 printf("GEODESY_ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame returned FALSE\n");
00298 return -1;
00299 }
00300 printf( "GEODESY_ComputeAzimuthAndElevationAnglesBetweenToPointsInTheEarthFixedFrame\n" );
00301 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00302 printf( "fromX [m] = %.4lf\n", fromX );
00303 printf( "fromY [m] = %.4lf\n", fromY );
00304 printf( "fromZ [m] = %.4lf\n", fromZ );
00305 printf( "toX [m] = %.4lf\n", toX );
00306 printf( "toY [m] = %.4lf\n", toY );
00307 printf( "toZ [m] = %.4lf\n", toZ );
00308 printf( "azimuth [deg] = %.12lf\n", azimuth*RAD2DEG );
00309 printf( "elevation [deg] = %.12lf\n", elevation*RAD2DEG );
00310
00311 break;
00312 }
00313 case 5:
00314 {
00315 double referenceLatitude;
00316 double referenceLongitude;
00317 double referenceHeight;
00318 double latitude;
00319 double longitude;
00320 double height;
00321 double northing;
00322 double easting;
00323 double vertical;
00324
00325 referenceLatitude = atof(argv[3])*DEG2RAD;
00326 referenceLongitude= atof(argv[4])*DEG2RAD;
00327 referenceHeight = atof(argv[5]);
00328
00329 latitude = atof(argv[6])*DEG2RAD;
00330 longitude= atof(argv[7])*DEG2RAD;
00331 height = atof(argv[8]);
00332
00333 result = GEODESY_ComputeNorthingEastingVertical(
00334 referenceEllipse,
00335 referenceLatitude,
00336 referenceLongitude,
00337 referenceHeight,
00338 latitude,
00339 longitude,
00340 height,
00341 &northing,
00342 &easting,
00343 &vertical
00344 );
00345 if( result == FALSE )
00346 {
00347 printf("GEODESY_ComputeNorthingEastingVertical returned FALSE\n");
00348 return -1;
00349 }
00350
00351 printf( "GEODESY_ComputePositionDifference\n" );
00352 printf( "ellipse = %s\n", GEODESY_REFERENCE_ELLIPSE_STRING_DESCRIPTION[ellipse] );
00353 printf( "reference_latitude [deg] = %.12lf\n", referenceLatitude*RAD2DEG );
00354 printf( "reference_longitude [deg] = %.12lf\n", referenceLongitude*RAD2DEG );
00355 printf( "reference_height [m] = %.4lf\n", referenceHeight );
00356 printf( "latitude [deg] = %.12lf\n", latitude*RAD2DEG );
00357 printf( "longitude [deg] = %.12lf\n", longitude*RAD2DEG );
00358 printf( "height [m] = %.4lf\n", height );
00359 printf( "northing [m] = %.4lf\n", northing );
00360 printf( "easting [m] = %.4lf\n", easting );
00361 printf( "vertical [m] = %.4lf\n\n", vertical );
00362 break;
00363 }
00364 default:
00365 {
00366 break;
00367 }
00368 }
00369
00370 return 0;
00371 }