22 #include <HdfEosDef.h> 24 #define MAX_FILENAME 5000 25 #define MAX_FIELDNAME 1000 26 #define MAX_LENGTH 1000 28 #define NUMBER_CAMERA 9 29 #define OUTPUT_GRIDNAME "L1B2Reproject" 42 #define ARGR_TYPE_INIT {NULL, NULL, NULL, -1} 54 int main(
int argc,
char *argv[] ) {
58 char *band_name[
NUMBER_BAND] = {
"Blue",
"Green",
"Red",
"NIR"};
99 char *dimlist_ul_lr =
"YDim,XDim";
102 char *dimlist_ur_ll =
"XDim,YDim";
112 int32 tile_dims[2] = {64,64};
114 intn comp_parm[1] = {5};
115 float32 fill_float32 = -9999.0;
130 printf(
"\n\nCheck that projection/map info filename is correct: %s\n",argr.
proj_map_file);
145 printf(
"\n\nCheck that input filename is correct: %s\n",argr.
terrain_file);
158 printf(
"\n\nCheck that GRP_TERRAIN filename is correct: %s\n",argr.
terrain_file);
162 camera = attrbuf.
data.
i32[0][0] - 1;
183 dimlist = dimlist_ul_lr;
185 dimlist = dimlist_ur_ll;
191 upleft[0] = target_map_info.
min_x;
192 upleft[1] = target_map_info.
max_y;
193 lowright[0] = target_map_info.
max_x;
194 lowright[1] = target_map_info.
min_y;
196 size_x = (int)floor((target_map_info.
max_x - target_map_info.
min_x) /
198 size_y = (int)floor((target_map_info.
max_y - target_map_info.
min_y) /
202 camera_name[camera]);
218 if (hstatus ==
FAIL) {
223 if (hstatus ==
FAIL) {
230 if (hstatus ==
FAIL) {
251 if (argr.
band < 0 || iband == argr.
band) {
253 printf(
"Processing band %d (%s)...\n",iband, band_name[iband]);
263 region, &toa_brf_data, &toa_brf_map_info);
274 snprintf(fieldname,
MAX_FIELDNAME,
"%s RDQI",band_name[iband]);
277 region, &toa_rad_rdqi, &toa_rad_rdqi_map_info);
294 for (iline = 0; iline < toa_brf_data.
nline; iline++) {
295 for (isample = 0; isample < toa_brf_data.
nsample; isample++) {
296 if (toa_rad_rdqi.
data.
u8[iline][isample] < 2) {
297 toa_brf_mask.
data.
u8[iline][isample] = 1;
299 toa_brf_mask.
data.
u8[iline][isample] = 0;
328 &resampled_toa_brf_data,
329 &resampled_toa_brf_mask);
354 camera_name[camera], band_name[iband]);
357 if (hstatus ==
FAIL) {
362 if (hstatus ==
FAIL) {
367 tile_dims, comp_code, comp_parm);
368 if (hstatus ==
FAIL) {
372 hstatus =
GDwritefield(gid, fieldname, NULL, NULL, edge,
373 resampled_toa_brf_data.
dataptr);
374 if (hstatus ==
FAIL) {
403 if (hstatus ==
FAIL) {
409 if (hstatus ==
FAIL) {
414 printf(
"Wrote output to %s\n",outputfile);
415 printf(
"Completed normally.\n");
436 printf(
"Failed: status code = %d\n",status_code);
443 "\nUsage: %s [--help] [--band=<band number>] \n" 444 " <projection/map info file> <GRP_TERRAIN file>\n" 445 " <output basename>\n",
450 "Perform reproject L1B2 terrain data to given map projection.\n" 452 "Result is written to an HDF-EOS file in the following fields:\n" 453 " TOA_BRF_<cam>_<band> Input TOA BRF from GRP_TERRAIN file (reprojected).\n" 455 "All output fields have identical map projection and size.\n" 460 "COMMAND-LINE OPTIONS\n" 463 " Returns this usage info.\n" 465 "--band=<band number>\n" 466 " Specifies the band to process. Bands are identified by integer values as\n" 467 " follows: 0 = blue 1 = green 2 = red 3 = nir\n" 472 "COMMAND-LINE ARGUMENTS\n" 474 "<projection/map info file>\n" 475 " Text file specifying map projection for the output. Parameters are\n" 476 " specified as name = value pairs. Parameter names are as follows:\n" 478 " proj_code is the GCTP projection code.\n" 479 " utm_zone is the UTM zone number for UTM projections only.\n" 480 " sphere_code is GCTP spheroid code.\n" 481 " proj_param(n) is the nth GCTP projection parameter. (1 <= n <= 15)\n" 482 " min_corner_x is the minimum X coordinate at the edge of the map.\n" 483 " min_corner_y is the minimum Y coordinate at the edge of the map.\n" 484 " resolution_x is the size of a pixel along the X-axis.\n" 485 " resolution_y is the size of a pixel along the Y-axis.\n" 486 " number_pixel_x is the size of the map in pixels, along the X-axis.\n" 487 " number_pixel_y is the size of the map in pixels, along the Y-axis.\n" 488 " origin_code defines the corner of the map at which pixel 0,0 is located.\n" 489 " pix_reg_code defines whether a pixel value is related to the corner or\n" 490 " center of the corresponding area of that pixel on the map. If the\n" 491 " corner is used, then it is always the corner corresponding to the\n" 492 " corner of the origin.\n" 494 " Possible values for origin_code are:\n" 495 " UL - Upper Left (min X, max Y); Line=Y, Sample=X\n" 496 " UR - Upper Right (max X, max Y); Line=X, Sample=Y\n" 497 " LL - Lower Left (min X, min Y); Line=X, Sample=Y\n" 498 " LR - Lower Right (max X, min Y); Line=Y, Sample=X\n" 500 " Possible values for pix_reg_code are:\n" 504 " Unrecognized parameter names are ignored.\n" 505 " Lines starting with a '#' character are ignored.\n" 506 " Anything after the name = value pair on a line is ignored.\n" 508 " Example projection/map info file:\n" 509 " # Albers equal-area conic projection parameters\n" 510 " proj_code = 3 # Albers equal-area conic\n" 511 " sphere_code = 8 # GRS80\n" 512 " proj_param(3) = 29030000.0 # Latitude of the first standard parallel\n" 513 " proj_param(4) = 45030000.0 # Latitude of the second standard parallel\n" 514 " proj_param(5) = -96000000.0 # Longitude of the central meridian\n" 515 " proj_param(6) = 23000000.0 # Latitude of the projection origin\n" 516 " # Map information\n" 517 " min_corner_x = 1930612.449614\n" 518 " min_corner_y = 2493633.488881\n" 519 " resolution_x = 250.0\n" 520 " resolution_y = 250.0\n" 521 " number_pixel_x = 1311\n" 522 " number_pixel_y = 2078\n" 523 " origin_code = UL\n" 524 " pix_reg_code = CENTER\n" 528 " MISR Terrain-projected Radiance Product (GRP_TERRAIN).\n" 530 "<output basename>\n" 531 " Basename for output file.\n" 535 " MtkL1B2Reproject --band=2 proj_map_info.txt \\\n" 536 " MISR_AM1_GRP_TERRAIN_GM_P011_O013824_DF_F03_0024.b52-56.hdf \\\n" 537 " BRF_O013824_maine\n" 539 " MtkL1B2Reproject \\\n" 540 " proj_map_info.txt \\\n" 541 " MISR_AM1_GRP_TERRAIN_GM_P011_O013824_DF_F03_0024.b52-56.hdf \\\n" 542 " BRF_O013824_maine\n" 556 static struct option longopts[] = {
557 {
"band", required_argument, 0,
'b' },
558 {
"help", no_argument, 0,
'h' },
562 while ((ch = getopt_long(argc, argv,
"b:h", longopts, NULL)) != -1) {
569 argr->
band = (int)atol(optarg);
intn GDdefpixreg(int32, int32)
MTKt_status MtkGCTPProjInfoRead(const char *Filename, MTKt_GCTPProjInfo *Proj_info)
Initialize a MTKt_GCTPProjInfo structure using data from an external file.
MTKt_PixRegCode pix_reg_code
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
int32 GDattach(int32, char *)
MTKt_status MtkSetRegionByGenericMapInfo(const MTKt_GenericMapInfo *Map_info, const MTKt_GCTPProjInfo *Proj_info, int Path, MTKt_Region *Region)
Create an MtkRegion structure that contains the given map.
MTKt_OriginCode origin_code
int process_args(int argc, char *argv[], argr_type *argr)
#define MTKT_MAPINFO_INIT
GCTP projection information.
MTKt_status MtkTransformCoordinates(MTKt_MapInfo mapinfo, MTKt_DataBuffer latbuf, MTKt_DataBuffer lonbuf, MTKt_DataBuffer *linebuf, MTKt_DataBuffer *samplebuf)
Transforms latitude/longitude coordinates into line/sample coordinates for a given mapinfo...
#define MTK_ERR_CODE_JUMP(code)
intn GDdeforigin(int32, int32)
2-dimensional Data Buffer
int main(int argc, char *argv[])
#define MTKT_DATABUFFER_INIT
int32 GDcreate(int32, char *, int32, int32, float64 [], float64 [])
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_status MtkGCTPCreateLatLon(const MTKt_GenericMapInfo *Map_info, const MTKt_GCTPProjInfo *Proj_info, MTKt_DataBuffer *Latitude, MTKt_DataBuffer *Longitude)
Create an array of latitude and longitude values corresponding to each pixel in the given map...
MTKt_status MtkFileAttrGet(const char *filename, const char *attrname, MTKt_DataBuffer *attrbuf)
Get a file attribute.
MTKt_status MtkResampleCubicConvolution(const MTKt_DataBuffer *Source, const MTKt_DataBuffer *Source_mask, const MTKt_DataBuffer *Line, const MTKt_DataBuffer *Sample, float A, MTKt_DataBuffer *Resampled, MTKt_DataBuffer *Resampled_mask)
Resample source data at the given coordinates using interpolation by cubic convolution.
intn GDdefproj(int32, int32, int32, int32, float64 [])
MTKt_status MtkReadData(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads any grid/field from any MISR product file and performs unpacking or unscaling. It also reads any MISR conventional product file.
intn GDsettilecomp(int32, char *, int32, int32 *, int32, intn *)
#define MTK_ERR_MSG_JUMP(msg)
intn GDsetfillvalue(int32, char *, VOIDP)
MTKt_status MtkGenericMapInfoRead(const char *Filename, MTKt_GenericMapInfo *Map_info)
Initialize a MTKt_GenericMapInfo structure using data from an external file.
intn GDdeffield(int32, char *, char *, int32, int32)
intn GDwritefield(int32, char *, int32 [], int32 [], int32 [], VOIDP)
#define HDFE_COMP_DEFLATE
#define MTKT_GENERICMAPINFO_INIT
int32 GDopen(char *, intn)
#define MTKT_GCTPPROJINFO_INIT
MTKt_status MtkFileToPath(const char *filename, int *path)
Read path number from file.