65 static int Isin_error(
const error_t *,
const char * );
74 fprintf(
stderr,
" error (isinusinv.c/%s) : %s\n", routine, text );
82 static error_t ISIN_BADALLOC = { -3,
"memory allocation" };
83 static error_t ISIN_BADPARAM = { -4,
"invalid parameter" };
84 static error_t ISIN_BADHANDLE = { -5,
"invalid handle" };
85 static error_t ISIN_BADKEY = { -6,
"invalid key" };
148 error(
"isinusinvinit",
"bad return from Isin_inv_free" );
156 error(
"isinusinvinit",
"bad parameter; sphere radius invalid" );
160 if ( lon_cen_mer < -TWO_PI || lon_cen_mer >
TWO_PI )
162 error(
"isinusinvinit",
163 "bad parameter; longitude of central meridian invalid" );
169 error(
"isinusinvinit",
"bad parameter; nzone out of range" );
176 error(
"isinusinvinit",
"bad parameter; nzone not near an integer value");
180 if ( ( nzone % 2 ) != 0 )
182 error(
"isinusinvinit",
"bad parameter; nzone not multiple of two" );
186 if ( djustify < -EPS_CNVT || djustify > ( 2.0 +
EPS_CNVT ) )
188 error(
"isinusinvinit",
"bad parameter; ijustify out of range" );
195 error(
"isinusinvinit",
196 "bad parameter; ijustify not near an integer value" );
201 isin =
Isin_inv_init( sphere, lon_cen_mer, false_east, false_north,
205 error(
"isinusinvinit",
"bad return from Isin_inv_init" );
274 double log2_dcol_min;
282 Isin_error( &ISIN_BADPARAM,
"Isin_inv_init" );
286 if ( lon_cen_mer < -TWO_PI || lon_cen_mer >
TWO_PI )
288 Isin_error( &ISIN_BADPARAM,
"Isin_inv_init" );
291 if ( lon_cen_mer <
PI )
293 if ( lon_cen_mer >=
PI )
298 Isin_error( &ISIN_BADPARAM,
"Isin_inv_init" );
301 if ( ( nrow % 2 ) != 0 )
303 Isin_error( &ISIN_BADPARAM,
"Isin_inv_init" );
307 if ( ijustify < 0 || ijustify > 2 )
309 Isin_error( &ISIN_BADPARAM,
"Isin_inv_init" );
317 Isin_error( &ISIN_BADALLOC,
"Isin_inv_init" );
323 this->false_east = false_east;
324 this->false_north = false_north;
325 this->sphere = sphere;
326 this->sphere_inv = 1.0 / sphere;
327 this->ang_size_inv = ( (
double ) nrow ) /
PI;
329 this->nrow_half = nrow / 2;
330 this->lon_cen_mer = lon_cen_mer;
331 this->ref_lon = lon_cen_mer -
PI;
332 if ( this->ref_lon < -
PI )
334 this->ijustify = ijustify;
338 if ( this->row ==
NULL )
341 Isin_error( &ISIN_BADALLOC,
"Isin_inv_init" );
349 for ( irow = 0; irow < this->nrow_half; irow++, row++ )
352 clat =
HALF_PI * ( 1.0 - ( (
double ) irow + 0.5 ) / this->nrow_half );
356 row->
ncol = (long)((2.0 * cos(clat) * nrow) + 0.5);
360 row->
ncol = (long)((cos(clat) * nrow) + 0.5);
369 if ( row->
ncol < 3 || ( irow == 0 && row->
ncol != 3 ) )
370 printf(
" irow = %d ncol = %d\n", irow, row->
ncol );
374 if ( row->
ncol < 6 || ( irow == 0 && row->
ncol != 6 ) )
375 printf(
" irow = %d ncol = %d\n", irow, row->
ncol );
388 dcol =
fabs( ( 2.0 * cos( clat ) * nrow ) + 0.5 - row->
ncol );
390 dcol = 2.0 *
fabs((cos(clat) * nrow) + 0.5 - (row->
ncol/2));
391 dcol = dcol / row->
ncol;
392 if ( dcol < dcol_min )
397 dcol =
fabs((2.0 * cos(clat) * nrow) + 0.5 - (row->
ncol + 1));
398 dcol = dcol / ( row->
ncol + 1 );
402 dcol = 2.0 *
fabs((cos(clat) * nrow) + 0.5 - ((row->
ncol/2) + 1));
403 dcol = dcol / ( row->
ncol + 2 );
405 if ( dcol < dcol_min )
422 ncol_cen = this->row[this->nrow_half - 1].
ncol;
427 log2_dcol_min = log( dcol_min ) / log( 2.0 );
428 printf(
" dcol_min = %g log2_dcol_min = %g\n", dcol_min, log2_dcol_min );
432 if ( ncol_cen != nrow * 2 )
433 printf(
" ncol_cen = %d nrow = %d\n", ncol_cen, nrow );
438 this->col_dist = (
TWO_PI * sphere ) / ncol_cen;
439 this->col_dist_inv = ncol_cen / (
TWO_PI * sphere );
484 error(
"isinusinv",
"bad return from Isin_inv" );
539 return Isin_error( &ISIN_BADHANDLE,
"Isin_inv" );
541 return Isin_error( &ISIN_BADKEY,
"Isin_inv" );
544 *
lat = (
y - this->false_north ) * this->sphere_inv;
545 if ( *lat < -HALF_PI || *lat >
HALF_PI )
552 row = (
HALF_PI - *
lat ) * this->ang_size_inv;
554 if ( irow >= this->nrow_half )
555 irow = ( this->nrow - 1 ) - irow;
560 col = (
x - this->false_east ) * this->col_dist_inv;
563 flon = ( col + this->row[irow].icol_cen ) * this->row[irow].ncol_inv;
564 if ( flon < 0.0 || flon > 1.0 )
571 *
lon = this->ref_lon + ( flon *
TWO_PI );
606 return Isin_error( &ISIN_BADHANDLE,
"Isin_inv_free" );
608 return Isin_error( &ISIN_BADKEY,
"Isin_inv_free" );
641 static int Isin_error
648 fprintf(
stderr,
" error (isinusinv.c/%s) : (%i) %s\n", routine,
err->num,