📄 param.c
字号:
routine.
2. An error status is returned when:
a. duplicating strings is not successful
b. errors occur when opening the input HDF file
c. memory allocation is not successful
3. Error messages are handled with the 'RETURN_ERROR' macro.
!END*****************************************************************************/
{
int i, j;
int32 sd_fid, sds_id; /* file id and sds id */
int32 nsds; /* number of SDSs in the file */
int32 nattr; /* number of attributes for the SDS */
int32 data_type; /* data type of the SDS */
char sds_name[MAX_NC_NAME]; /* SDS name */
int32 rank; /* rank of the SDS */
int32 dims[MYHDF_MAX_RANK]; /* dimensions of the SDS */
/* Open file for SD read access */
sd_fid = SDstart(this->input_file_name, DFACC_RDONLY);
if (sd_fid == HDF_ERROR)
RETURN_ERROR("opening input file", "ReadSDS", 0);
/* Get the list of swaths */
SDfileinfo(sd_fid, &nsds, &nattr);
#ifdef DEBUG
printf("Number of SDSs: %i\n", (int) nsds);
#endif
/* Loop through the SDSs to get SDS names and info */
for (i = 0; i < nsds; i++)
{
/* grab the SDS */
sds_id = SDselect(sd_fid, i);
if (sds_id == HDF_ERROR)
RETURN_ERROR("selecting input SDS", "ReadSDS", 0);
/* get information for the current SDS */
if (SDgetinfo(sds_id, sds_name, &rank, dims, &data_type, &nattr) ==
HDF_ERROR)
RETURN_ERROR("getting SDS information", "ReadSDS", 0);
/* process the swath SDSs */
strcpy(this->input_sds_name_list[i], sds_name);
#ifdef DEBUG
printf("\nSDgetinfo: sds %i, %s, rank = %i, dims =", i,
sds_name, (int) rank);
for (j = 0; j < rank; j++)
printf(" %i", (int) dims[j]);
printf("\n");
#endif
/* if the rank is 2 then there is only one band to process, otherwise
the first dimension value contains the number of bands in the SDS */
if (rank == 1)
this->input_sds_nbands[i] = 0;
else if (rank == 2)
this->input_sds_nbands[i] = 1;
else
{
/* 3D product. Use the smallest dim value for the bands. */
this->input_sds_nbands[i] = (int)dims[0];
for (j = 0; j < rank; j++)
{
/* find the smallest dimension */
if ((int)dims[j] < this->input_sds_nbands[i])
this->input_sds_nbands[i] = (int)dims[j];
/* if the smallest dimension is larger than MAX_VAR_DIMS then set
it to MAX_VAR_DIMS. Most likely it won't be processed anyhow. */
if (this->input_sds_nbands[i] > MAX_VAR_DIMS)
this->input_sds_nbands[i] = MAX_VAR_DIMS;
}
}
if (rank > MYHDF_MAX_RANK) {
SDendaccess(sds_id);
RETURN_ERROR("sds rank too large", "ReadSDS", false);
}
/* process all the bands in this SDS */
for (j = 0; j < this->input_sds_nbands[i]; j++)
this->input_sds_bands[i][j] = 1;
/* close the SDS */
SDendaccess(sds_id);
}
/* Close the HDF-EOS file */
SDend(sd_fid);
return (int)nsds;
}
bool SDSInfo(Param_t *this)
/*
!C******************************************************************************
!Description: 'SDSInfo' accesses the specified SDSs in the input file and
grabs the band information for each SDS.
!Input Parameters:
this 'input' data structure; the following fields are input:
input_file_name, input_sds_name_list, input_sds_nbands
!Output Parameters:
this 'input' data structure; the following fields are modified:
input_sds_nbands, input_sds_bands
(returns) status:
'true' = okay
'false' = error return
!Team Unique Header:
! Design Notes:
1. The file is open for HDF access but closed before returning from the
routine.
2. An error status is returned when:
a. duplicating strings is not successful
b. errors occur when opening the input HDF file
c. memory allocation is not successful
3. Error messages are handled with the 'RETURN_ERROR' macro.
!END*****************************************************************************/
{
int i, j;
int32 sd_fid, sds_id; /* file id and sds id */
int32 sds_index; /* index of the current SDS */
int32 nattr; /* number of attributes for the SDS */
int32 data_type; /* data type of the SDS */
char sds_name[MAX_NC_NAME]; /* SDS name */
int32 rank; /* rank of the SDS */
int32 dims[MYHDF_MAX_RANK]; /* dimensions of the SDS */
char errmsg[256]; /* error message */
char tmpsds[MAX_STR_LEN]; /* temp copy of the SDS name in case we need
to remove the '_'s from the SDS name */
int curr_char; /* current character in the SDS name */
/* Open file for SD read access */
sd_fid = SDstart(this->input_file_name, DFACC_RDONLY);
if (sd_fid == HDF_ERROR)
RETURN_ERROR("opening input file", "SDSInfo", false);
/* loop through the SDSs */
for (i = 0; i < this->num_input_sds; i++)
{
/* try to find the index for the current SDS name */
sds_index = SDnametoindex(sd_fid, this->input_sds_name_list[i]);
if (sds_index == HDF_ERROR) {
/* if running the GUI, SDS names with blank spaces have '_'s placed
for the blank spaces. replace the '_'s with blank spaces and then
try to find the SDS. */
strcpy(tmpsds, this->input_sds_name_list[i]);
for (curr_char = 0; curr_char < (int) strlen (tmpsds) - 1; curr_char++)
{
/* if this character is an underscore then replace with a blank */
if (tmpsds[curr_char] == '_')
tmpsds[curr_char] = ' ';
}
/* try to find the index for the new SDS name */
sds_index = SDnametoindex(sd_fid, tmpsds);
if (sds_index == HDF_ERROR) {
sprintf(errmsg, "couldn't get sds index for %s or %s",
this->input_sds_name_list[i], tmpsds);
RETURN_ERROR(errmsg, "SDSInfo", false);
}
/* copy the correct SDS name into the SDS name list */
strcpy(this->input_sds_name_list[i], tmpsds);
}
/* get the current SDS */
sds_id = SDselect(sd_fid, sds_index);
if (sds_id == HDF_ERROR)
RETURN_ERROR("getting sds id", "SDSInfo", false);
/* get the current SDS information */
if (SDgetinfo(sds_id, sds_name, &rank, dims, &data_type, &nattr) ==
HDF_ERROR) {
SDendaccess(sds_id);
RETURN_ERROR("getting sds information", "SDSInfo", false);
}
if (rank > MYHDF_MAX_RANK) {
SDendaccess(sds_id);
RETURN_ERROR("sds rank too large", "SDSInfo", false);
}
/* if the user specified bands to be processed for the current
SDS, then fill in the number of bands in the SDS */
if (this->input_sds_nbands[i] != 0)
{
/* if the rank is 2 then there is only one band to process, otherwise
the first dimension value contains the number of bands in the SDS */
if (rank == 2)
this->input_sds_nbands[i] = 1;
else
this->input_sds_nbands[i] = (int)dims[0];
}
/* otherwise process all the bands in the SDS by default */
else
{
/* if the rank is 2 then there is only one band to process, otherwise
the first dimension value contains the number of bands in the SDS */
if (rank == 2)
this->input_sds_nbands[i] = 1;
else
this->input_sds_nbands[i] = (int)dims[0];
/* Process all the bands in this SDS */
for (j = 0; j < this->input_sds_nbands[i]; j++)
this->input_sds_bands[i][j] = 1;
}
/* close the SDS */
SDendaccess(sds_id);
}
/* close the HDF-EOS file */
SDend(sd_fid);
return true;
}
/******************************************************************************
MODULE: PrintParam
PURPOSE: Print the user processing parameters
RETURN VALUE:
Type = none
Value Description
----- -----------
HISTORY:
Version Date Programmer Code Reason
------- ----- --------------- ---- -------------------------------------
12/03 Gail Schmidt Original Development
NOTES:
******************************************************************************/
void PrintParam
(
Param_t *param /* I: Parameter information */
)
{
/* Strings to match the Kernel_type_t in kernel.h */
static char *ResamplingTypeStrings[] =
{
"NN", "BI", "CC"
};
/* Strings to match the Output_file_format_t in param.h */
static char *FileTypeStrings[] =
{
"HDF", "GEOTIFF", "RAW_BINARY", "HDF and GEOTIFF"
};
int i, j;
int count;
char msgstr[1024],
tempstr[1024],
msg[1024];
sprintf(msg, "\nGeneral processing info\n");
Infomsg(msg);
sprintf(msg, "-----------------------\n");
Infomsg(msg);
sprintf(msg, "input_filename: %s\n", param->input_file_name);
Infomsg(msg);
sprintf(msg, "geoloc_filename: %s\n", param->geoloc_file_name);
Infomsg(msg);
sprintf(msg, "output_filename: %s\n", param->output_file_name);
Infomsg(msg);
sprintf(msg, "output_filetype: %s\n",
FileTypeStrings[(int)param->output_file_format]);
Infomsg(msg);
sprintf(msg, "output_projection_type: %s\n",
Proj_type[param->output_space_def.proj_num].name);
Infomsg(msg);
if (param->output_space_def.proj_num == PROJ_UTM)
{
sprintf(msg, "output_zone_code: %d\n",
param->output_space_def.zone);
Infomsg(msg);
}
if (param->output_space_def.sphere < 0 ||
param->output_space_def.sphere >= PROJ_NSPHERE)
{
sprintf(msg, "output_ellipsoid: None\n");
Infomsg(msg);
}
else
{
sprintf(msg, "output_ellipsoid: %s\n",
Proj_sphere[param->output_space_def.sphere].name);
Infomsg(msg);
}
/* If this is an ellipse-based projection, then the output datum might be
WGS84 */
switch (param->output_space_def.proj_num)
{
case PROJ_ALBERS:
case PROJ_EQRECT:
case PROJ_GEO:
case PROJ_MERCAT:
case PROJ_TM:
case PROJ_UTM:
case PROJ_LAMCC:
case PROJ_PS:
/* If WGS84 ellipsoid, then we can tag the WGS84 datum,
otherwise no datum can be specified. */
if (param->output_space_def.sphere == 8 /* WGS84 */ ||
(param->output_space_def.orig_proj_param[0] == 6378137.0 &&
param->output_space_def.orig_proj_param[1] == 6356752.31414))
{
sprintf(msg, "output_datum: WGS84\n");
Infomsg(msg);
}
else
{
sprintf(msg, "output_datum: No Datum\n");
Infomsg(msg);
}
break;
default:
sprintf(msg, "output_datum: No Datum\n");
Infomsg(msg);
break;
}
sprintf(msg, "resampling_type: %s\n",
ResamplingTypeStrings[param->kernel_type]);
Infomsg(msg);
strcpy(msgstr, "output projection parameters: ");
for (i = 0; i < 15; i++)
{
sprintf(tempstr, "%.2f ", param->output_space_def.orig_proj_param[i]);
strcat(msgstr, tempstr);
}
Infomsg(msgstr);
sprintf(msg,
"\n\n SDS name #bands in SDS #bands "
"to process\n");
Infomsg(msg);
for (i = 0; i < param->num_input_sds; i++)
{
/* Determine how many bands in this SDS are to be processed */
if (param->input_sds_nbands[i] == 1)
{ /* SDS only has one band */
count = 1;
}
else
{ /* SDS has multiple bands */
count = 0;
for (j = 0; j < param->input_sds_nbands[i]; j++)
{
if (param->input_sds_bands[i][j] == 1)
count++;
}
}
sprintf(msg, "%3i) %-32s %6i %15i\n", i+1,
param->input_sds_name_list[i], param->input_sds_nbands[i], count);
Infomsg(msg);
}
Infomsg("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -