int safssi_stdat(fmgeopos gpos, fmprojspec myproj, osihdf *safssi, safssi_data *ssi) { char *where="safssi_stdat"; int dx, dy, i, j, k, l, m; int nodata = 0; fmtime timeid; fmindex xyp, tgin; fmucspos tgxy; fmgeopos tgll; fmucsref rim; /* * Convert from image header to useable data structures, first * satellite id. */ sprintf((*ssi).source,"%s", safssi->h.source); /* * The UCS info is converted */ rim.Ax = safssi->h.Ax; rim.Ay = safssi->h.Ay; rim.Bx = safssi->h.Bx; rim.By = safssi->h.By; rim.iw = safssi->h.iw; rim.ih = safssi->h.ih; /* printf(" lat: %.2f lon: %.2f\n",gpos.lat,gpos.lon); printf(" Bx: %.2f By: %.2f Ax: %.2f Ay: %.2f\n", rim.Bx,rim.By,rim.Ax,rim.Ay); */ (*ssi).nav.Ax = rim.Ax; (*ssi).nav.Ay = rim.Ay; /* * Set UNIX time for product */ timeid.fm_min = safssi->h.minute; timeid.fm_hour = safssi->h.hour; timeid.fm_mday = safssi->h.day; timeid.fm_mon = safssi->h.month; timeid.fm_year = safssi->h.year; (*ssi).vtime = tofmsec1970(timeid);; /* * Get UCS position of the requested geographical position within the * image. */ tgxy = fmgeo2ucs(gpos, myproj); tgin = fmucs2ind(rim,tgxy); if (tgin.col < 0 || tgin.row < 0) { fmerrmsg(where, "This is out of image..."); fprintf(stdout," lat: %.2f lon: %.2f\n",tgll.lat,tgll.lon); fprintf(stdout," northings: %d eastings: %d\n",tgxy.northings,tgxy.eastings); fprintf(stdout," myproj: %d\n", myproj); return(FM_SYNTAX_ERR); } (*ssi).nav.Bx = (float) tgxy.eastings; (*ssi).nav.By = (float) tgxy.northings; /* * Check bounding box size, these parameters are set by the init * function... */ if ((*ssi).nav.iw%2 == 0 || (*ssi).nav.ih%2 == 0) { fmerrmsg("avhrr_stdat","area required must be odd\n"); return(FM_SYNTAX_ERR); } /* * Collect the actual data, l is used for pixel count within the * actual image, and k within the storage tile. */ dx = (int) floorf((float) (*ssi).nav.iw/2.); dy = (int) floorf((float) (*ssi).nav.ih/2.); k = 0; for (i=(tgin.row-dy); i<=(tgin.row+dy); i++) { for (j=(tgin.col-dx); j<=(tgin.col+dx); j++) { /* * Check if within image coverage... */ if (i < 0 || j < 0 || i >= rim.ih || j >= rim.iw) continue; /* * Navigation is performed in 2D while data is stored in 1D... */ l = fmivec(j,i,rim.iw); /* * Collect data... */ (*ssi).data[k] = ((float *) safssi->d[0].data)[l]; (*ssi).qflg[k] = ((unsigned short *) safssi->d[1].data)[l]; /* * Check number of unprocessed pixels */ if ((*ssi).data[k] < -100.) nodata++; k++; } } /* * If all pixels are unprocessed this is likely to be out of coverage, * return code to indicate this... */ if (nodata == k) { fmlogmsg(where,"This request contains all unprocessed pixels."); return(FM_OTHER_ERR); } return(FM_OK); }
int return_product_area(fmgeopos gpos, PRODhead header, float *data, s_data *a) { char *where="return_product_area"; int dx, dy, i, j, k; long l, maxsize; int nodata = 1; fmucsref uref; fmucspos upos; fmindex xyp; uref.Bx = header.Bx; uref.By = header.By; uref.Ax = header.Ax; uref.Ay = header.Ay; uref.iw = header.iw; uref.ih = header.ih; maxsize = header.iw*header.ih; upos = fmgeo2ucs(gpos, MI); xyp = fmucs2ind(uref, upos); /* printf("%.2f %.2f\n", gpos.lat, gpos.lon); printf("%.2f %.2f %.2f %.2f\n", uref.Bx, uref.By, uref.Ax, uref.Ay); printf("%4d %4d\n", uref.iw, uref.ih); printf("%.2f %.2f\n", upos.eastings, upos.northings); */ if ((*a).iw == 1 && (*a).ih == 1) { *((*a).data) = data[fmivec(xyp.col,xyp.row,header.iw)]; return(FM_OK); } if ((*a).iw%2 == 0 || (*a).ih%2 == 0) { fmerrmsg(where, "The area specified must contain an odd number of pixels."); return(FM_IO_ERR); } dx = (int) floorf((float) (*a).iw/2.); dy = (int) floorf((float) (*a).ih/2.); /* printf("dy: %4d dx: %4d\n", dy, dx); */ k = 0; for (i=(xyp.row-dy); i<=(xyp.row+dy); i++) { for (j=(xyp.col-dx); j<=(xyp.col+dx); j++) { l = (int) fmivec(j,i,header.iw); if (l >= maxsize) { fmerrmsg(where, "Image size (%d) exceeded when subsetting image (%d)", maxsize, l); return(FM_IO_ERR); } /* printf("%4d %4d %3d %3d %.2f\n", k, l, i, j, data[l]); */ if ((int) (floorf (data[l]*100.)) != OUTOFIMAGE && (int) (floorf (data[l]*100.)) != MISVAL) { nodata = 0; } (*a).data[k] = data[l]; k++; } } if (nodata) { fmerrmsg(where,"No data were found."); return(FM_IO_ERR); } return(FM_OK); }
int safcm_stdat(fmgeopos gpos, fmprojspec myproj, CTy_t *ctype, safcm_data *cm) { char *where = "safcm_stdat"; char what[FMSTRING256]; int dx, dy, i, j, k, l, m, in, jn; int nodata = 1; int notprocessed = 0; /* struct clb c; */ fmucspos tgxy; fmindex tgin; fmgeopos tgll; fmucsref rim; if (FMCOL_NO_CLOUDTYPE_VALUES != SM_NUMBER_OF_CLOUDTYPE_VALUES) { sprintf(what,"The number of cloud types seem to have changed %d->%d",FMCOL_NO_CLOUDTYPE_VALUES,SM_NUMBER_OF_CLOUDTYPE_VALUES); fmerrmsg(where, what); return(FM_IO_ERR); } /* * Convert from image header to useable data structures, first * satellite id. */ sprintf((*cm).source,"%s", ctype->satellite_id); /* * The UCS info is converted, remember that SAFNWC use meter unit * while DNMI use kilometer... */ rim.Ax = M2KM(fabs(ctype->reg->area_extent[2]-ctype->reg->area_extent[0])/ (double) ctype->reg->xsize); rim.Ay = M2KM(fabs(ctype->reg->area_extent[3]-ctype->reg->area_extent[1])/ (double) ctype->reg->ysize); rim.Bx = M2KM(ctype->reg->area_extent[0]); rim.By = M2KM(ctype->reg->area_extent[3]); rim.iw = ctype->reg->xsize; rim.ih = ctype->reg->ysize; (*cm).nav.Ax = (float) rim.Ax; (*cm).nav.Ay = (float) rim.Ay; /* * Set UNIX time for product */ (*cm).vtime = ctype->sec_1970; /* * Get UCS position of the requested geographical position within the * image. */ tgll.lat = (double) gpos.lat; tgll.lon = (double) gpos.lon; tgxy = fmgeo2ucs(tgll, myproj) ; tgin = fmucs2ind(rim, tgxy); if (tgin.col < 0 || tgin.row < 0) return(FM_SYNTAX_ERR); (*cm).nav.Bx = (float) tgxy.eastings; (*cm).nav.By = (float) tgxy.northings; /* * Check bounding box size, these parameters are set by the init * function... */ if ((*cm).nav.iw%2 == 0 || (*cm).nav.ih%2 == 0) { fmerrmsg("avhrr_stdat","area required must be odd\n"); return(FM_SYNTAX_ERR); } /* * Transfer decoding information for cloudmask/type to storage tile * structure... */ for (i=0; i<FMCOL_NO_CLOUDTYPE_VALUES; i++) { /* printf(" Lengde: %d\n", strlen(ctype->cloudtype_lut[i])); */ if (ctype->cloudtype_lut[i]) { /* strncpy((*cm).description[i], ctype->cloudtype_lut[i],MAX_LENGTH_STRING); */ strncpy((*cm).description[i], ctype->cloudtype_lut[i],50); } else { sprintf((*cm).description[i],"NA"); } } /* * Collect the actual data, l is used for pixel count within the * actual image, and k within the storage tile. */ dx = (int) floorf((float) (*cm).nav.iw/2.); dy = (int) floorf((float) (*cm).nav.ih/2.); k = 0; for (i=(tgin.row-dy); i<=(tgin.row+dy); i++) { for (j=(tgin.col-dx); j<=(tgin.col+dx); j++) { /* * Check if within image coverage... */ if (i < 0 || j < 0 || i >= rim.ih || j >= rim.iw) continue; /* * Navigation is performed in 2D while data is stored in 1D... */ l = fmivec(j,i,rim.iw); /* * Collect data... */ (*cm).data[k] = (unsigned char) ctype->cloudtype[l]; /* * Check number of unprocessed pixels */ if (ctype->cloudtype[l] == 0) notprocessed++; k++; } } /* * If all pixels are unprocessed this is likely to be out of coverage, * return code to indicate this... */ if (notprocessed == k) { fmlogmsg(where,"This request contains all unprocessed pixels."); return(FM_OTHER_ERR); } return(FM_OK); }