📄 input.c
字号:
/* Check other dimensions */
for (ir = 0; ir < rank; ir++)
{
if (this->extra_dim[ir] >= this->sds.dim[ir].nval)
{
for (ir1 = 0; ir1 < ir; ir1++) free(this->sds.dim[ir1].name);
SDendaccess(this->sds.id);
SDend(this->sds_file_id);
free(this->sds.name);
free(this->file_name);
free(this);
strcpy (errstr, "OpenInput: invalid dimension");
return (Input_t *)NULL;
}
}
/* Calculate number of scans, and for swath space, check for
an integral 完整的 number of scans */
this->scan_size.l = NDET_1KM_MODIS; /* #define NDET_1KM_MODIS (10) */
this->scan_size.l *= this->ires; /* Number of input scans */
this->scan_size.s = this->size.s;
this->nscan = (this->size.l - 1) / this->scan_size.l + 1;
if ((this->nscan * this->scan_size.l) != this->size.l)
{
for (ir1 = 0; ir1 < ir; ir1++) free(this->sds.dim[ir1].name);
SDendaccess(this->sds.id);
SDend(this->sds_file_id);
free(this->sds.name);
free(this->file_name);
free(this);
strcpy (errstr, "OpenInput: not an integral number of scans");
return (Input_t *)NULL;
}
/* Allocate input buffer */
switch (this->sds.type)
{
case DFNT_CHAR8:
this->data_type_size = sizeof(char8);
this->buf.val_char8 = (char8 *)calloc(this->size.s,
this->data_type_size);
if (this->buf.val_char8 == (char8 *)NULL)
error_string = "allocating input i/o buffer";
break;
case DFNT_UINT8:
this->data_type_size = sizeof(uint8);
this->buf.val_uint8 = (uint8 *)calloc(this->size.s,
this->data_type_size);
if (this->buf.val_uint8 == (uint8 *)NULL)
error_string = "allocating input i/o buffer";
break;
case DFNT_INT8:
this->data_type_size = sizeof(int8);
this->buf.val_int8 = (int8 *)calloc(this->size.s,
this->data_type_size);
if (this->buf.val_int8 == (int8 *)NULL)
error_string = "allocating input i/o buffer";
break;
case DFNT_INT16:
this->data_type_size = sizeof(int16);
this->buf.val_int16 = (int16 *)calloc(this->size.s,
this->data_type_size);
if (this->buf.val_int16 == (int16 *)NULL)
error_string = "allocating input i/o buffer";
break;
case DFNT_UINT16:
this->data_type_size = sizeof(uint16);
this->buf.val_uint16 = (uint16 *)calloc(this->size.s,
this->data_type_size);
if (this->buf.val_uint16 == (uint16 *)NULL)
error_string = "allocating input i/o buffer";
break;
default:
error_string = "unsupported data type";
}
if (error_string != (char *)NULL)
{
for (ir = 0; ir < this->sds.rank; ir++)
free(this->sds.dim[ir].name);
SDendaccess(this->sds.id);
SDend(this->sds_file_id);
free(this->sds.name);
free(this->file_name);
free(this);
sprintf (errstr, "OpenInput: %s", error_string);
return (Input_t *)NULL;
}
return this;
}
#define MIN_LS_DIM_SIZE (250)
bool FindInputDim(int rank, int *param_dim, Myhdf_dim_t *sds_dim,
int *extra_dim, Img_coord_int_t *dim, char *errstr)
/*
!C******************************************************************************
!Description: 'FindInputDim' distinguishes between the line/sample and other
dimensions from the user parameters and the size of the
dimensions.
!Input Parameters:
rank rank of the input SDS
param_dim dimension flags from the user parameters; the line and
sample dimensions are
indicated by a -1 and -2 in this array, respectively;个别地
the index in the other dimensions are indicated by a value
of zero or greater
file_dim actual SDS dimensions
!Output Parameters:
param_dim updated dimensions
extra_dim extra SDS dimensions; other than line and sample
dim SDS line and sample dimension locations
errstr error string
(returns) status:
'true' = okay
'false' = error return
!Team Unique Header:
! Design Notes:
1. An error status is returned when:
a. the dimensions from the user parameters are not valid
b. there are either too many large (not line/sample) or small
(line/sample) dimensions.
2. Error messages are returned as part of the function call. This
allows the calling routine (OpenInput) to print those error
messages or ignore them.
!END****************************************************************************
*/
{
int ir, ils, iextra;
int temp_dim[MYHDF_MAX_RANK]; /* #define MYHDF_MAX_RANK (4) */
/* Set up the default values to be returned */
for (ir = 0; ir < rank; ir++
/* Check to make sure the line/sample dimensions from the user parameters
are the first two dimesions */
if (param_dim[0] >= 0 ||
param_dim[1] >= 0 ||
(param_dim[0] * param_dim[1]) != 2)
{
strcpy (errstr, "FindInputDim: invalid line/sample dimensions");
return false;
}
/* Check to make sure that the remaining dimensions from the user parameters
are valid */
for (ir = 2; ir < rank; ir++)
{
if (param_dim[ir] < 0)
{
strcpy (errstr, "FindInputDim: invalid remaining dimesions");
return false;
}
}
/* Figure out which are the line/sample dimensions and which are the
extra dimensions. The line and sample dimensions are expected to be
greater than MIN_LS_DIM_SIZE. If too many dimensions are "line/sample"
dimensions, then it is an error. If not enough dimensions are
available for "line/sample" dimensions, then it is also an error. */
ils = 0;
iextra = 2;
for (ir = 0; ir < rank; ir++)
{
if (sds_dim[ir].nval > MIN_LS_DIM_SIZE) /* #define MIN_LS_DIM_SIZE (250) */
{
if (ils > 1)
{
sprintf (errstr, "FindInputDim: too many large dimensions. Only "
"the line and sample dimensions can be larger than %d.",
MIN_LS_DIM_SIZE);
return false;
}
temp_dim[ir] = param_dim[ils];
extra_dim[ir] = 0;
if (temp_dim[ir] == -1) dim->l = ir;
else dim->s = ir;
ils++;
} else
{
if (iextra >= MYHDF_MAX_RANK)
{
sprintf (errstr, "FindInputDim: too many small dimensions. The "
"line and sample dimensions need to be larger than %d.",
MIN_LS_DIM_SIZE);
return false;
}
temp_dim[ir] = param_dim[iextra];
extra_dim[ir] = param_dim[iextra];
iextra++;
}
}
/* Update the user parameters */
for (ir = 0; ir < rank; ir++)
param_dim[ir] = temp_dim[ir];
return true;
}
bool CloseInput(Input_t *this)
/*
!C******************************************************************************
!Description: 'CloseInput' ends SDS access and closes the input file.
!Input Parameters:
this 'input' data structure; the following fields are input:
open, sds.id, sds_file_id
!Output Parameters:
this 'input' data structure; the following fields are modified:
open
(returns) status:
'true' = okay
'false' = error return
!Team Unique Header:
! Design Notes:
1. An error status is returned when:
a. the file is not open for access
b. an error occurs when closing access to the SDS.
2. Error messages are handled with the 'RETURN_ERROR' macro.
3. 'OpenInput' must be called before this routine is called.
4. 'FreeInput' should be called to deallocate memory used by the
'input' data structure.
!END****************************************************************************
*/
{
if (!this->open)
RETURN_ERROR("file not open", "CloseInput", false);
if (SDendaccess(this->sds.id) == HDF_ERROR)
RETURN_ERROR("ending sds access", "CloseInput", false);
SDend(this->sds_file_id);
this->open = false;
return true;
}
bool FreeInput(Input_t *this)
/*
!C******************************************************************************
!Description: 'FreeInput' frees the 'input' data structure memory.
!Input Parameters:
this 'input' data structure; the following fields are input:
sds.rank, sds.dim[*].name, sds.name, file_name
!Output Parameters:
(returns) status:
'true' = okay (always returned)
!Team Unique Header:
! Design Notes:
1. 'OpenInput' and 'CloseInput' must be called before this routine is called.
2. An error status is never returned.
!END****************************************************************************
*/
{
int ir;
if (this != (Input_t *)NULL)
{
for (ir = 0; ir < this->sds.rank; ir++)
{
if (this->sds.dim[ir].name != (char *)NULL)
free(this->sds.dim[ir].name);
}
if (this->sds.name != (char *)NULL) free(this->sds.name);
if (this->file_name != (char *)NULL) free(this->file_name);
free(this);
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -