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 "L2ASCloudMask" 38 char *output_basename;
42 #define ARGR_TYPE_INIT {NULL, NULL, NULL, -1} 54 int main(
int argc,
char *argv[] ) {
90 char *dimlist_ul_lr =
"YDim,XDim";
93 char *dimlist_ur_ll =
"XDim,YDim";
103 int32 tile_dims[2] = {64,64};
105 intn comp_parm[1] = {5};
106 int32 fill_int32 = 0;
121 printf(
"\n\nCheck that projection/map info filename is correct: %s\n",argr.
proj_map_file);
136 printf(
"\n\nCheck that input filename is correct: %s\n",argr.
aerosol_file);
158 dimlist = dimlist_ul_lr;
160 dimlist = dimlist_ur_ll;
166 upleft[0] = target_map_info.
min_x;
167 upleft[1] = target_map_info.
max_y;
168 lowright[0] = target_map_info.
max_x;
169 lowright[1] = target_map_info.
min_y;
171 size_x = (int)floor((target_map_info.
max_x - target_map_info.
min_x) /
173 size_y = (int)floor((target_map_info.
max_y - target_map_info.
min_y) /
192 if (hstatus ==
FAIL) {
197 if (hstatus ==
FAIL) {
204 if (hstatus ==
FAIL) {
251 printf(
"Reading RetrAppMask, camera %d, band %d...\n",icamera,iband);
253 snprintf(fieldname,
MAX_FIELDNAME,
"RetrAppMask[%d][%d]",iband,icamera);
256 region, &retr_app_mask, &retr_app_mask_map_info);
265 for (iline = 0; iline < retr_app_mask.
nline; iline++) {
266 for (isample = 0; isample < retr_app_mask.
nsample; isample++) {
267 if (retr_app_mask.
data.
u8[iline][isample] == 7) {
268 cloud_mask.
data.
i32[iline][isample] = 1;
270 cloud_mask.
data.
i32[iline][isample] = 0;
304 &resampled_cloud_mask);
328 if (hstatus ==
FAIL) {
333 if (hstatus ==
FAIL) {
338 tile_dims, comp_code, comp_parm);
339 if (hstatus ==
FAIL) {
343 hstatus =
GDwritefield(gid, fieldname, NULL, NULL, edge,
345 if (hstatus ==
FAIL) {
367 if (hstatus ==
FAIL) {
373 if (hstatus ==
FAIL) {
378 printf(
"Wrote output to %s\n",outputfile);
379 printf(
"Completed normally.\n");
398 printf(
"Failed: status code = %d\n",status_code);
405 "\nUsage: %s [--help] [--band=<band number>] \n" 406 " <projection/map info file> <GRP_TERRAIN file>\n" 407 " <output basename>\n",
412 "Perform reproject L1B2 terrain data to given map projection.\n" 414 "Result is written to an HDF-EOS file in the following fields:\n" 417 "All output fields have identical map projection and size.\n" 422 "COMMAND-LINE OPTIONS\n" 425 " Returns this usage info.\n" 427 "--band=<band number>\n" 428 " Specifies the band to process. Bands are identified by integer values as\n" 429 " follows: 0 = blue 1 = green 2 = red 3 = nir\n" 434 "COMMAND-LINE ARGUMENTS\n" 436 "<projection/map info file>\n" 437 " Text file specifying map projection for the output. Parameters are\n" 438 " specified as name = value pairs. Parameter names are as follows:\n" 440 " proj_code is the GCTP projection code.\n" 441 " utm_zone is the UTM zone number for UTM projections only.\n" 442 " sphere_code is GCTP spheroid code.\n" 443 " proj_param(n) is the nth GCTP projection parameter. (1 <= n <= 15)\n" 444 " min_corner_x is the minimum X coordinate at the edge of the map.\n" 445 " min_corner_y is the minimum Y coordinate at the edge of the map.\n" 446 " resolution_x is the size of a pixel along the X-axis.\n" 447 " resolution_y is the size of a pixel along the Y-axis.\n" 448 " number_pixel_x is the size of the map in pixels, along the X-axis.\n" 449 " number_pixel_y is the size of the map in pixels, along the Y-axis.\n" 450 " origin_code defines the corner of the map at which pixel 0,0 is located.\n" 451 " pix_reg_code defines whether a pixel value is related to the corner or\n" 452 " center of the corresponding area of that pixel on the map. If the\n" 453 " corner is used, then it is always the corner corresponding to the\n" 454 " corner of the origin.\n" 456 " Possible values for origin_code are:\n" 457 " UL - Upper Left (min X, max Y); Line=Y, Sample=X\n" 458 " UR - Upper Right (max X, max Y); Line=X, Sample=Y\n" 459 " LL - Lower Left (min X, min Y); Line=X, Sample=Y\n" 460 " LR - Lower Right (max X, min Y); Line=Y, Sample=X\n" 462 " Possible values for pix_reg_code are:\n" 466 " Unrecognized parameter names are ignored.\n" 467 " Lines starting with a '#' character are ignored.\n" 468 " Anything after the name = value pair on a line is ignored.\n" 470 " Example projection/map info file:\n" 471 " # Albers equal-area conic projection parameters\n" 472 " proj_code = 3 # Albers equal-area conic\n" 473 " sphere_code = 8 # GRS80\n" 474 " proj_param(3) = 29030000.0 # Latitude of the first standard parallel\n" 475 " proj_param(4) = 45030000.0 # Latitude of the second standard parallel\n" 476 " proj_param(5) = -96000000.0 # Longitude of the central meridian\n" 477 " proj_param(6) = 23000000.0 # Latitude of the projection origin\n" 478 " # Map information\n" 479 " min_corner_x = 1930612.449614\n" 480 " min_corner_y = 2493633.488881\n" 481 " resolution_x = 250.0\n" 482 " resolution_y = 250.0\n" 483 " number_pixel_x = 1311\n" 484 " number_pixel_y = 2078\n" 485 " origin_code = UL\n" 486 " pix_reg_code = CENTER\n" 490 " MISR Terrain-projected Radiance Product (GRP_TERRAIN).\n" 492 "<output basename>\n" 493 " Basename for output file.\n" 497 " MtkL1B2Reproject proj_map_info.txt \\\n" 498 " MISR_AM1_AS_AEROSOL_P143_O031948_F12_0022.hdf \\\n" 499 " cloud_mask_o31948\n" 513 static struct option longopts[] = {
514 {
"band", required_argument, 0,
'b' },
515 {
"help", no_argument, 0,
'h' },
519 while ((ch = getopt_long(argc, argv,
"b:h", longopts, NULL)) != -1) {
526 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
#define MTKT_MAPINFO_INIT
int process_args(int argc, char *argv[], argr_type *argr)
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
#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...
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)
int main(int argc, char *argv[])
#define HDFE_COMP_DEFLATE
MTKt_status MtkSnapToGrid(int path, int resolution, MTKt_Region region, MTKt_MapInfo *mapinfo)
Snap a region to a MISR grid based on path number and resolution.
MTKt_status MtkResampleNearestNeighbor(MTKt_DataBuffer srcbuf, MTKt_DataBuffer linebuf, MTKt_DataBuffer samplebuf, MTKt_DataBuffer *resampbuf)
Perform nearest neighbor resampling.
#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.