58 const int BYTES_PER_DOUBLE =
sizeof( double );
59 const int BYTES_PER_FLOAT =
sizeof( float );
60 const int BYTES_PER_INT =
sizeof( int );
62 const int BYTES_IN_HEADER =
63 ( 3 * BYTES_PER_INT + 2 * BYTES_PER_DOUBLE );
65 const int NOM_AOI_COLS1 = 100;
66 const int NOM_AOI_ROWS1 = 100;
67 const int NOM_AOI_COLS2_5 = 50;
68 const int NOM_AOI_ROWS2_5 = 50;
70 const double PI = 3.14159265358979323;
72 const double PIDIV2 = PI / 2.0;
73 const double TWOPI = 2.0 *
PI;
75 const double DEG_PER_RAD = 180.0 /
PI;
76 const double RAD_PER_DEG = PI / 180.0;
78 const double MTR_PER_NM = 1852.0;
82 const double SEMI_MAJOR_AXIS = 6378137.0;
83 const double FLATTENING = 1.0 / 298.257223563;
133 "Error: Egm2008AoiGrid: constructor failed." );
144 const std::string &gridFname )
189 "Error: Egm2008AoiGrid: constructor failed." );
243 kount = _nAoiRows * _nAoiCols;
245 _heightGrid =
new float[ kount ];
247 for ( i = 0; i < kount; i++ )
258 "Error: Egm2008AoiGrid: copy contructor failed");
301 if (
this == & oldGrid )
return ( *
this );
337 for ( i = 0; i < kount; i++ )
349 "Error: Egm2008AoiGrid: assignment operator failed");
424 const int TWENTY = 20;
446 double latSupport[ TWENTY ];
447 double lonSupport[ TWENTY ];
448 double moments [ TWENTY ];
456 if (( latitude < -PIDIV2 ) || ( latitude > PIDIV2 ))
return( 1 );
458 while ( longitude < 0.0 ) longitude += TWOPI;
459 while ( longitude > TWOPI ) longitude -= TWOPI;
463 for (i = 0; i < TWENTY; i++)
465 latSupport[ i ] = lonSupport[ i ] = moments[ i ] = 0.0;
473 ( latitude + PIDIV2 ) /
_dLat;
476 ( longitude - 0.0 ) /
_dLon;
481 oddSize = ( wSize != (( wSize / 2 ) * 2 ));
484 i0 = int( latIndex + 0.5 );
485 j0 = int( lonIndex + 0.5 );
487 iMin = i0 - ( wSize / 2 );
488 jMin = j0 - ( wSize / 2 );
491 i0 = int( latIndex );
492 j0 = int( lonIndex );
494 iMin = i0 - ( wSize / 2 ) + 1;
495 jMin = j0 - ( wSize / 2 ) + 1;
498 iMax = iMin + wSize - 1;
499 jMax = jMin + wSize - 1;
512 if ( status != 0 )
return( 1 );
516 if ( status != 0 )
return( 1 );
529 if ( status != 0 )
return( 1 );
541 lonIndex - double( jMin );
546 for ( i = 0; i < wSize; i++ )
555 for ( j = 0; j < wSize; j++ )
559 kIndex = jIndex + offset;
570 this->
initSpline( wSize, lonSupport, moments );
572 if ( status != 0 )
return( 1 );
575 this->
spline( wSize, temp, lonSupport, moments );
583 latIndex - double( iMin );
589 this->
initSpline( wSize, latSupport, moments );
591 if ( status != 0 )
return( 1 );
594 this->
spline( wSize, temp, latSupport, moments );
601 catch ( ... ) {
return( 1 ); }
675 if (( latitude < -PIDIV2 ) || ( latitude > PIDIV2 ))
return( 1 );
677 while ( longitude < 0.0 ) longitude += TWOPI;
678 while ( longitude > TWOPI ) longitude -= TWOPI;
685 ( latitude, longitude, i1, j1 );
687 if ( status != 0 )
return( 1 );
741 a3 = n1 + n3 - n2 - n4;
755 x = ( longitude - lon1 ) /
_dLon;
756 y = ( latitude - lat1 ) /
_dLat;
760 gHeight = a0 + a1 * x + a2 * y + a3 * x * y;
764 catch ( ... ) {
return( 1 ); }
810 const double THRESHOLD = 0.05;
832 i0, j0, latitude, longitude );
834 if ( status != 0 )
return( 1 );
836 cLat = cos( latitude );
837 sLat = sin( latitude );
842 eSquared = FLATTENING * ( 2.0 - FLATTENING );
844 temp = 1.0 - eSquared * sLat * sLat;
846 nRadius = SEMI_MAJOR_AXIS / sqrt( temp );
850 ewDelta0 = SEMI_MAJOR_AXIS *
_dLon;
852 ewDelta = nRadius * _dLon * cLat;
854 ratio = ewDelta / ewDelta0;
856 if ( ratio < THRESHOLD ) ratio = THRESHOLD;
902 catch ( ... ) {
return( 1 ); }
950 std::ifstream::binary | std::ifstream::in );
952 if ( fin.fail() )
return( 1 );
973 for ( i = startRow; i >= endRow; i-- )
983 if ( fin.fail() ) { fin.close();
return( 1 ); }
1003 catch ( ... ) {
return( 1 ); }
1045 std::ifstream::binary | std::ifstream::in );
1047 if ( fin.fail() ) {
return( 1 ); }
1051 fin.read((
char*) &
_nGridPad, BYTES_PER_INT );
1053 if ( fin.fail() ) { fin.close();
return( 1 ); }
1055 fin.read((
char*) &
_nOrigRows, BYTES_PER_INT );
1057 if ( fin.fail() ) { fin.close();
return( 1 ); }
1059 fin.read((
char*) &
_nOrigCols, BYTES_PER_INT );
1061 if ( fin.fail() ) { fin.close();
return( 1 ); }
1063 fin.read((
char*) &
_dLat, BYTES_PER_DOUBLE );
1065 if ( fin.fail() ) { fin.close();
return( 1 ); }
1067 fin.read((
char*) &
_dLon, BYTES_PER_DOUBLE );
1069 if ( fin.fail() ) { fin.close();
return( 1 ); }
1083 _dLat *= RAD_PER_DEG;
1084 _dLon *= RAD_PER_DEG;
1091 ewDelta =
_dLon * SEMI_MAJOR_AXIS;
1093 _nomAoiCols = 1 + int( 150.0 * MTR_PER_NM / ewDelta );
1107 catch ( ... ) {
return( 1 ); }