27 float bilin(
float *,
float *, int32 *,
int16 *, int32 *);
37 static float tilat, tilon, tslon, tslat, tansnz, sinsna, cossna;
38 static float x0, y0,
x,
y, dx, dy, dd, dist, distn, ddist;
39 static float coslat, hgt1, hgt2, los1, los2;
41 static int16 i, irow, icol, itile;
46 static int firstCall = 1;
47 static int32 idims[3] = {1, 220, 220};
48 static int32 istart[3] = {0, 0, 0};
49 static int32 itilem = -999;
50 static float step = .5f;
51 static float tszmin = .01f;
52 static float snzmax = 56.f;
53 static float remm = 6371000.f;
68 tslat = 180.f / (
dem.nrows - 1);
71 distn = remm * tslat / (
dem.itsize *
RADEG);
78 irow = (*
xlat - 0.0001f + 90.f) / tslat + .5
f;
79 icol = (*
xlon - 0.0001f + 180.f) / 360.
f *
dem.ncols[irow];
80 itile =
dem.nstart[irow] + icol;
102 dist = *height * tansnz * remm / (remm + *height);
108 if (itile != itilem) {
111 istart[0] =
dem.irecno[itile];
114 if (SDreaddata(tileid, istart,
NULL, idims, tile) != 0) {
115 printf(
"Error reading tile %d record %d\n",
116 itile,
dem.irecno[itile]);
121 tslon = 360.f /
dem.ncols[irow];
124 tilat = (irow - .5f) * tslat - 90.
f;
125 tilon = icol * tslon - 180.f;
131 npts =
dem.ihmax[itile] * tansnz / ddist + 2;
135 x0 = (*
xlon - tilon) / tslon *
dem.itsize +
dem.ioff + .5f;
136 y0 = (*
xlat - tilat) / tslat *
dem.itsize +
dem.ioff + .5f;
143 if (*height == 0.
f &&
iflag == 2) {
151 dx = dx * tslat / (coslat * tslon);
156 if (tansnz < tszmin) {
157 dist = *height * tansnz;
169 los1 = dist * (dist * tansnz / 2.f + remm)
170 / (remm * tansnz - dist);
173 while (los1 > hgt1) {
184 printf(
"Warning: %d %d outside tile range\n", (
int)
x, (
int)
y);
186 los1 = dist * (dist * tansnz / 2.f + remm)
187 / (remm * tansnz - dist);
191 dd = (hgt1 - los1) / (hgt1 - los1 + los2 - hgt2);
201 if (*
senz <= snzmax) {
202 printf(
"Bilinear interpolation error %d %d %d\n",
203 (
int)
x, (
int)
y, (
int)
dem.isize);
216 *
xlon += dist * sinsna *
RADEG / (remm * coslat);
224 if (*
xlon < -180.
f) {
233 #define tile_ref(a_1,a_2) tile[(a_2)*tile_dim1 + a_1]
237 int tile_dim1, tile_offset;
246 tile_offset = 1 + tile_dim1;
247 tile -= (int32) tile_offset;
254 if ((ix > 0) && (ix < *
isize) && (iy > 0) && (iy < *
isize)) {
259 ret_val = (1 - dx) * (1 - dy) *
tile_ref(ix, iy)
260 + dx * (1 - dy) *
tile_ref(ix + 1, iy)
261 + (1 - dx) * dy *
tile_ref(ix, iy + 1)
262 + dx * dy *
tile_ref(ix + 1, iy + 1);
277 static int32 istart = 0;
278 static int32 istr = 1;
282 static int32 at_id, sd_id, idims, fileid;
288 fileid = SDstart(demfile, DFACC_RDONLY);
290 printf(
"Error opening DEM file: %s\n", demfile);
297 at_id = SDfindattr(fileid,
"Number of rows");
299 printf(
"Error getting index for Number of rows\n");
302 status = SDreadattr(fileid, at_id, &
dem.nrows);
304 printf(
"Error getting value for Number of rows\n");
308 at_id = SDfindattr(fileid,
"Equator tiles");
310 printf(
"Error getting index for Equator tiles\n");
313 status = SDreadattr(fileid, at_id, &
dem.neq);
315 printf(
"Error getting value for Equator tiles\n");
319 at_id = SDfindattr(fileid,
"Array size");
321 printf(
"Error getting index for Array size\n");
324 status = SDreadattr(fileid, at_id, &
dem.isize);
326 printf(
"Error getting value for Array size\n");
330 at_id = SDfindattr(fileid,
"Tile size");
332 printf(
"Error getting index for Tile size\n");
335 status = SDreadattr(fileid, at_id, &
dem.itsize);
337 printf(
"Error getting value for Tile size\n");
341 at_id = SDfindattr(fileid,
"Array tile offset");
343 printf(
"Error getting index for Array tile offset\n");
346 status = SDreadattr(fileid, at_id, &
dem.ioff);
348 printf(
"Error getting value for Array tile offset\n");
352 at_id = SDfindattr(fileid,
"Number of tiles");
354 printf(
"Error getting index for Number of tiles\n");
357 status = SDreadattr(fileid, at_id, &
dem.ntiles);
359 printf(
"Error getting value for Number of tiles\n");
363 at_id = SDfindattr(fileid,
"Number of filled tiles");
365 printf(
"Error getting index for Number of filled tiles\n");
368 status = SDreadattr(fileid, at_id, &
dem.nftiles);
370 printf(
"Error getting value for Number of filled tiles\n");
378 ind = SDnametoindex(fileid,
"Row_number_of_tiles");
380 printf(
"Error getting index for Row_number_of_tiles\n");
383 sd_id = SDselect(fileid, ind);
385 printf(
"Error selecting Row_number_of_tiles\n");
388 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.ncols);
390 printf(
"Error reading Row_number_of_tiles\n");
393 status = SDendaccess(sd_id);
395 ind = SDnametoindex(fileid,
"Row_start_tile");
397 printf(
"Error getting index for Row_start_tile\n");
400 sd_id = SDselect(fileid, ind);
402 printf(
"Error selecting Row_start_tile\n");
405 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.nstart);
407 printf(
"Error reading Row_start_tile\n");
410 status = SDendaccess(sd_id);
414 ind = SDnametoindex(fileid,
"DEM_tile_record");
416 printf(
"Error getting index for DEM_tile_record\n");
419 sd_id = SDselect(fileid, ind);
421 printf(
"Error selecting DEM_tile_record\n");
424 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.irecno);
426 printf(
"Error reading DEM_tile_record\n");
429 status = SDendaccess(sd_id);
431 ind = SDnametoindex(fileid,
"DEM_tile_flag");
433 printf(
"Error getting index for DEM_tile_flag\n");
436 sd_id = SDselect(fileid, ind);
438 printf(
"Error selecting DEM_tile_flag\n");
441 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.iflag);
443 printf(
"Error reading DEM_tile_flag\n");
446 status = SDendaccess(sd_id);
448 ind = SDnametoindex(fileid,
"Tile_minimum_height");
450 printf(
"Error getting index for Tile_minimum_height\n");
453 sd_id = SDselect(fileid, ind);
455 printf(
"Error selecting Tile_minimum_height\n");
458 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.ihmin);
460 printf(
"Error reading Tile_minimum_height\n");
463 status = SDendaccess(sd_id);
465 ind = SDnametoindex(fileid,
"Tile_maximum_height");
467 printf(
"Error getting index for Tile_maximum_height\n");
470 sd_id = SDselect(fileid, ind);
472 printf(
"Error selecting Tile_maximum_height\n");
475 status = SDreaddata(sd_id, &istart, &istr, &idims,
dem.ihmax);
477 printf(
"Error reading Tile_maximum_height\n");
480 status = SDendaccess(sd_id);
483 ind = SDnametoindex(fileid,
"DEM_tile_data");
485 printf(
"Error getting index for DEM_tile_data\n");
488 tileid[0] = SDselect(fileid, ind);
489 if (tileid[0] == -1) {
490 printf(
"Error selecting DEM_tile_flag\n");
502 static float tilat, tilon, tslon, tslat;
505 static int16 irow, icol, itile;
510 static int firstCall = 1;
511 static int32 idims[3] = {1, 220, 220};
512 static int32 istart[3] = {0, 0, 0};
513 static int32 itilem = -999;
528 tslat = 180.f / (
dem.nrows - 1);
532 irow = (*
xlat - 0.0001f + 90.f) / tslat + .5
f;
533 icol = (*
xlon - 0.0001f + 180.f) / 360.
f *
dem.ncols[irow];
534 itile =
dem.nstart[irow] + icol;
553 if (itile != itilem) {
556 istart[0] =
dem.irecno[itile];
559 if (SDreaddata(tileid, istart,
NULL, idims, tile) != 0) {
560 printf(
"Error reading tile %d record %d\n",
561 itile,
dem.irecno[itile]);
566 tslon = 360.f /
dem.ncols[irow];
569 tilat = (irow - .5f) * tslat - 90.
f;
570 tilon = icol * tslon - 180.f;
575 x0 = (*
xlon - tilon) / tslon *
dem.itsize +
dem.ioff + .5f;
576 y0 = (*
xlat - tilat) / tslat *
dem.itsize +
dem.ioff + .5f;