58 static int Isin_error(
const error_t *,
const char * );
60 static void error(
const char *routine,
const char *text )
63 fprintf(
stderr,
" error (isinusfor.c/%s : %s\n", routine, text );
71 static error_t ISIN_BADALLOC = { -3,
"memory allocation" };
72 static error_t ISIN_BADPARAM = { -4,
"invalid parameter" };
73 static error_t ISIN_BADHANDLE = { -5,
"invalid handle" };
74 static error_t ISIN_BADKEY = { -6,
"invalid key" };
135 error(
"isinusforinit",
"bad return from Isin_for_free" );
143 error(
"isinusforinit",
"bad parameter; sphere radius invalid" );
147 if ( lon_cen_mer < -TWO_PI || lon_cen_mer >
TWO_PI )
149 error(
"isinusforinit",
150 "bad parameter; longitude of central meridian invalid" );
156 error(
"isinusforinit",
"bad parameter; nzone out of range" );
163 error(
"isinusforinit",
"bad parameter; nzone not near an integer value");
167 if ( ( nzone % 2 ) != 0 )
169 error(
"isinusforinit",
"bad parameter; nzone not multiple of two" );
173 if ( djustify < -EPS_CNVT || djustify > ( 2.0 +
EPS_CNVT ) )
175 error(
"isinusforinit",
"bad parameter; ijustify out of range" );
182 error(
"isinusforinit",
183 "bad parameter; ijustify not near an integer value" );
188 isin =
Isin_for_init( sphere, lon_cen_mer, false_east, false_north,
192 error(
"Isin_for_init",
"bad return from Isin_for_init" );
261 double log2_dcol_min;
269 Isin_error( &ISIN_BADPARAM,
"Isin_for_init" );
273 if ( lon_cen_mer < -TWO_PI || lon_cen_mer >
TWO_PI )
275 Isin_error( &ISIN_BADPARAM,
"Isin_for_init" );
278 if ( lon_cen_mer <
PI )
280 if ( lon_cen_mer >=
PI )
285 Isin_error( &ISIN_BADPARAM,
"Isin_for_init" );
288 if ( ( nrow % 2 ) != 0 )
290 Isin_error( &ISIN_BADPARAM,
"Isin_for_init" );
294 if ( ijustify < 0 || ijustify > 2 )
296 Isin_error( &ISIN_BADPARAM,
"Isin_for_init" );
304 Isin_error( &ISIN_BADALLOC,
"Isin_for_init" );
310 this->false_east = false_east;
311 this->false_north = false_north;
312 this->sphere = sphere;
313 this->sphere_inv = 1.0 / sphere;
314 this->ang_size_inv = ( (
double ) nrow ) /
PI;
316 this->nrow_half = nrow / 2;
317 this->lon_cen_mer = lon_cen_mer;
318 this->ref_lon = lon_cen_mer -
PI;
319 if ( this->ref_lon < -
PI )
321 this->ijustify = ijustify;
325 if ( this->row ==
NULL )
328 Isin_error( &ISIN_BADALLOC,
"Isin_for_init" );
336 for ( irow = 0; irow < this->nrow_half; irow++, row++ )
340 clat =
HALF_PI * ( 1.0 - ( (
double ) irow + 0.5 ) / this->nrow_half );
344 row->
ncol = (long)((2.0 * cos(clat) * nrow) + 0.5);
348 row->
ncol = (long)((cos(clat) * nrow) + 0.5);
357 if ( row->
ncol < 3 || ( irow == 0 && row->
ncol != 3 ) )
358 printf(
" irow = %d ncol = %d\n", irow, row->
ncol );
362 if ( row->
ncol < 6 || ( irow == 0 && row->
ncol != 6 ) )
363 printf(
" irow = %d ncol = %d\n", irow, row->
ncol );
376 dcol =
fabs( ( 2.0 * cos( clat ) * nrow ) + 0.5 - row->
ncol );
378 dcol = 2.0 *
fabs((cos(clat) * nrow) + 0.5 - (row->
ncol/2));
379 dcol = dcol / row->
ncol;
380 if ( dcol < dcol_min )
385 dcol =
fabs((2.0 * cos(clat) * nrow) + 0.5 - (row->
ncol + 1));
386 dcol = dcol / ( row->
ncol + 1 );
390 dcol = 2.0 *
fabs((cos(clat) * nrow) + 0.5 - ((row->
ncol/2) + 1));
391 dcol = dcol / ( row->
ncol + 2 );
393 if ( dcol < dcol_min )
410 ncol_cen = this->row[this->nrow_half - 1].
ncol;
415 log2_dcol_min = log( dcol_min ) / log( 2.0 );
416 printf(
" dcol_min = %g log2_dcol_min = %g\n", dcol_min, log2_dcol_min );
420 if ( ncol_cen != nrow * 2 )
421 printf(
" ncol_cen = %d nrow = %d\n", ncol_cen, nrow );
426 this->col_dist = (
TWO_PI * sphere ) / ncol_cen;
427 this->col_dist_inv = ncol_cen / (
TWO_PI * sphere );
472 error(
"isinusfor",
"bad return from Isin_fwd" );
529 return Isin_error( &ISIN_BADHANDLE,
"Isin_fwd" );
531 return Isin_error( &ISIN_BADKEY,
"Isin_fwd" );
532 if ( lon < -TWO_PI || lon >
TWO_PI )
534 if ( lat < -HALF_PI || lat >
HALF_PI )
538 *
y = this->false_north + (
lat * this->sphere );
543 if ( irow >= this->nrow_half )
544 irow = ( this->nrow - 1 ) - irow;
551 flon += ( 1 - ( long ) flon );
553 flon -= ( long ) flon;
556 col = ( this->row[irow].ncol * flon ) - this->row[irow].icol_cen;
559 *
x = this->false_east + ( this->col_dist * col );
590 return Isin_error( &ISIN_BADHANDLE,
"Isin_for_free" );
592 return Isin_error( &ISIN_BADKEY,
"Isin_for_free" );
625 static int Isin_error
632 fprintf(
stderr,
" error (isinusfor.c/%s) : (%i) %s\n", routine,
err->num,