9 static char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
10 static PGSt_SMF_status errcode;
19 "(does not meet file specs or is corrupted)";
21 "The file may be incomplete or corrupted.";
22 static char *corruptoutputfile =
"Operationally, this should never occur.\n"
23 "The file or file pointer may have become corrupted.";
24 static char *nowriteoutputfile =
"May be out of disk space or file became corrupted.";
31 PGSt_SMF_status assign_data_type(
char *, int32 *);
92 attr_index = SDfindattr(s_id, attr_name);
93 if (attr_index ==
FAIL) {
95 sprintf(errmsgbuf,
"Could not find attribute \"%s\" in the file.",
97 L1BErrorMsg(
"read_attribute", errcode, errmsgbuf,
"SDfindattr", 0,
102 res = SDattrinfo(s_id, attr_index, attr_name_buf, &data_type, &
count);
105 sprintf(errmsgbuf,
"Could not get attribute information for \"%s\".",
107 L1BErrorMsg(
"read_attribute", errcode, errmsgbuf,
"SDattrinfo", 0,
114 if (data_type != TypeID) {
116 sprintf(errmsgbuf,
"Attribute \"%s\" has data type mismatch.\n"
117 "File data type = %ld, expected type = %ld\n",
118 attr_name, (
long)data_type, (
long)TypeID);
124 res = SDreadattr(s_id, attr_index, buffer);
127 sprintf(errmsgbuf,
"Could not read attribute \"%s\" from file.",
129 L1BErrorMsg(
"read_attribute", errcode, errmsgbuf,
"SDreadattr", 0,
139 if (data_type == DFNT_CHAR8)
143 buffer_ptr[
count] =
'\0';
197 int32
start[2] = {0, 0};
198 int32 edge[2] = {0, 0};
206 sds_index = SDnametoindex (sd_id, sds_name);
207 if (sds_index ==
FAIL) {
209 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
211 L1BErrorMsg(
"read_part_sds_rank2", errcode, errmsgbuf,
"SDnametoindex", 0,
216 sds_id = SDselect (sd_id, sds_index);
217 if (sds_id ==
FAIL) {
219 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
221 L1BErrorMsg(
"read_part_sds_rank2", errcode, errmsgbuf,
"SDselect", 0,
229 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
231 L1BErrorMsg(
"read_part_sds_rank2", errcode, errmsgbuf,
"SDreaddata", 0,
236 if (SDendaccess(sds_id)==
FAIL) {
238 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
240 L1BErrorMsg(
"read_part_sds_rank2", errcode, errmsgbuf,
"SDendaccess", 0,
305 int32
start[3] = {0, 0, 0};
306 int32 edge[3] = {0, 0, 0};
316 sds_index = SDnametoindex (sd_id, sds_name);
317 if (sds_index ==
FAIL) {
319 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
321 L1BErrorMsg(
"read_part_sds_rank3", errcode, errmsgbuf,
"SDnametoindex", 0,
326 sds_id = SDselect (sd_id, sds_index);
327 if (sds_id ==
FAIL) {
329 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
331 L1BErrorMsg(
"read_part_sds_rank3", errcode, errmsgbuf,
"SDselect", 0,
339 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
341 L1BErrorMsg(
"read_part_sds_rank3", errcode, errmsgbuf,
"SDreaddata", 0,
346 if (SDendaccess(sds_id)==
FAIL) {
348 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
350 L1BErrorMsg(
"read_part_sds_rank3", errcode, errmsgbuf,
"SDendaccess", 0,
399 int32
start[1] = {0};
404 sds_index = SDnametoindex (file_id, sds_name);
405 if (sds_index ==
FAIL) {
407 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
409 L1BErrorMsg(
"read_sds_rank1", errcode, errmsgbuf,
"SDnametoindex", 0,
414 sds_id = SDselect (file_id, sds_index);
415 if (sds_id ==
FAIL) {
417 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
419 L1BErrorMsg(
"read_sds_rank1", errcode, errmsgbuf,
"SDselect", 0,
428 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
430 L1BErrorMsg(
"read_sds_rank1", errcode, errmsgbuf,
"SDreaddata", 0,
435 result = SDendaccess (sds_id);
438 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
440 L1BErrorMsg(
"read_sds_rank1", errcode, errmsgbuf,
"SDendaccess", 0,
495 int32
start[2] = {0, 0};
496 int32 edge[2] = {0, 0};
501 sds_index = SDnametoindex (file_id, sds_name);
502 if (sds_index ==
FAIL) {
504 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
506 L1BErrorMsg(
"read_sds_rank2", errcode, errmsgbuf,
"SDnametoindex", 0,
511 sds_id = SDselect (file_id, sds_index);
512 if (sds_id ==
FAIL) {
514 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
516 L1BErrorMsg(
"read_sds_rank2", errcode, errmsgbuf,
"SDselect", 0,
525 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
527 L1BErrorMsg(
"read_sds_rank2", errcode, errmsgbuf,
"SDreaddata", 0,
532 result = SDendaccess(sds_id);
535 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
537 L1BErrorMsg(
"read_sds_rank2", errcode, errmsgbuf,
"SDendaccess", 0,
593 int32
start[3] = {0, 0, 0};
594 int32 edge[3] = {0, 0, 0};
600 sds_index = SDnametoindex (file_id, sds_name);
601 if (sds_index ==
FAIL) {
603 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
605 L1BErrorMsg(
"read_sds_rank3", errcode, errmsgbuf,
"SDnametoindex", 0,
610 sds_id = SDselect (file_id, sds_index);
611 if (sds_id ==
FAIL) {
613 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
615 L1BErrorMsg(
"read_sds_rank3", errcode, errmsgbuf,
"SDselect", 0,
624 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
626 L1BErrorMsg(
"read_sds_rank3", errcode, errmsgbuf,
"SDreaddata", 0,
631 result = SDendaccess(sds_id);
634 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
636 L1BErrorMsg(
"read_sds_rank3", errcode, errmsgbuf,
"SDendaccess", 0,
694 int32
start[4] = {0, 0, 0, 0};
695 int32 edge[4] = {0, 0, 0, 0};
702 sds_index = SDnametoindex (file_id, sds_name);
703 if (sds_index ==
FAIL) {
705 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
707 L1BErrorMsg(
"read_sds_rank4", errcode, errmsgbuf,
"SDnametoindex", 0,
712 sds_id = SDselect (file_id, sds_index);
713 if (sds_id ==
FAIL) {
715 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
717 L1BErrorMsg(
"read_sds_rank4", errcode, errmsgbuf,
"SDselect", 0,
726 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
728 L1BErrorMsg(
"read_sds_rank4", errcode, errmsgbuf,
"SDreaddata", 0,
733 result = SDendaccess(sds_id);
736 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
738 L1BErrorMsg(
"read_sds_rank4", errcode, errmsgbuf,
"SDendaccess", 0,
789 intn hdf_return =
FAIL;
795 vd_ref = VSfind(v_id, vname);
799 sprintf(errmsgbuf,
"Could not find Vdata \"%s\" in the file.",
801 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSfind", 0,
806 vd_id = VSattach(v_id, vd_ref,
"r");
809 sprintf(errmsgbuf,
"Could not attach to Vdata \"%s\".",
811 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSattach", 0,
816 hdf_return = VSinquire(vd_id, &n_records, &interlace,
NULL,
NULL,
NULL);
817 if (hdf_return ==
FAIL) {
819 sprintf(errmsgbuf,
"Could not get information about Vdata \"%s\".",
821 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSinquire", 0,
827 records = n_records - start_record;
829 if (n_records < records + start_record ) {
831 sprintf(errmsgbuf,
"Vdata \"%s\" contains too few records based on input arguments.",
838 hdf_return = VSseek (vd_id, start_record);
839 if (hdf_return ==
FAIL) {
841 sprintf(errmsgbuf,
"For Vdata \"%s\", could not set current record to desired start_record.",
843 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSseek", 0,
848 hdf_return = VSsetfields (vd_id, fname);
849 if (hdf_return ==
FAIL) {
851 sprintf(errmsgbuf,
"For Vdata \"%s\", could not set field to \"%s\".",
853 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSsetfields", 0,
858 hdf_return = VSread (vd_id, buffer, records, interlace);
859 if (hdf_return ==
FAIL) {
861 sprintf(errmsgbuf,
"Could not read data from Vdata \"%s\".",
863 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSread", 0,
868 hdf_return = VSdetach(vd_id);
869 if (hdf_return ==
FAIL) {
871 sprintf(errmsgbuf,
"Could not detach from Vdata \"%s\".",
873 L1BErrorMsg(
"read_vdata", errcode, errmsgbuf,
"VSdetach", 0,
882 PGSt_SMF_status assign_data_type(
char *data_type, int32 *number_type)
916 if (!data_type || !number_type) {
918 L1BErrorMsg(
"assign_data_type", errcode,
"NULL input pointer(s)",
922 else if (strcmp(data_type,
"int8") == 0) *number_type = DFNT_INT8;
923 else if (strcmp(data_type,
"uint8") == 0) *number_type = DFNT_UINT8;
924 else if (strcmp(data_type,
"int16") == 0) *number_type =
DFNT_INT16;
925 else if (strcmp(data_type,
"uint16") == 0) *number_type = DFNT_UINT16;
926 else if (strcmp(data_type,
"int32") == 0) *number_type =
DFNT_INT32;
927 else if (strcmp(data_type,
"uint32") == 0) *number_type = DFNT_UINT32;
928 else if (strcmp(data_type,
"float32") == 0) *number_type =
DFNT_FLOAT32;
929 else if (strcmp(data_type,
"float64") == 0) *number_type = DFNT_FLOAT64;
930 else if (strcmp(data_type,
"char") == 0) *number_type = DFNT_CHAR;
934 "data_type \"%s\" does not match any allowed type in function.",
937 "Coding error.",
False);
940 return(returnStatus);
991 int32
start[1] = {0};
993 int32 dim_size[1] = {0};
999 returnStatus = assign_data_type(datatype, &number_type);
1001 L1BErrorMsg(
"write_sds_rank1", returnStatus,
NULL,
"assign_data_type", 0,
1003 return returnStatus;
1006 sds_id = SDcreate(file_id, sds_name, number_type,
rank, dim_size);
1007 if (sds_id ==
FAIL) {
1009 sprintf(errmsgbuf,
"Could not create SDS \"%s\" in the file.",
1011 L1BErrorMsg(
"write_sds_rank1", errcode, errmsgbuf,
"SDcreate", 0,
1012 corruptoutputfile,
False);
1016 dim_id = SDgetdimid(sds_id, 0);
1017 if (dim_id ==
FAIL) {
1019 sprintf(errmsgbuf,
"Could not retrieve dimension id for SDS \"%s\".",
1021 L1BErrorMsg(
"write_sds_rank1", errcode, errmsgbuf,
"SDgetdimid", 0,
1022 corruptoutputfile,
False);
1023 SDendaccess(sds_id);
1027 result = SDsetdimname (dim_id, dim_name);
1030 sprintf(errmsgbuf,
"Could not set dimension name for SDS \"%s\".",
1032 L1BErrorMsg(
"write_sds_rank1", errcode, errmsgbuf,
"SDsetdimname", 0,
1033 corruptoutputfile,
False);
1034 SDendaccess(sds_id);
1041 sprintf(errmsgbuf,
"Could not write data to SDS \"%s\".",
1043 L1BErrorMsg(
"write_sds_rank1", errcode, errmsgbuf,
"SDwritedata", 0,
1044 nowriteoutputfile,
False);
1045 SDendaccess(sds_id);
1049 result = SDendaccess(sds_id);
1052 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1054 L1BErrorMsg(
"write_sds_rank1", errcode, errmsgbuf,
"SDendaccess", 0,
1055 corruptoutputfile,
False);
1112 int32 dim_id[2] = {0, 0};
1113 int32
start[2] = {0, 0};
1123 dim_name[0] = dim_name1;
1124 dim_name[1] = dim_name2;
1126 returnStatus = assign_data_type(datatype, &number_type);
1128 L1BErrorMsg(
"write_sds_rank2", returnStatus,
NULL,
"assign_data_type", 0,
1130 return returnStatus;
1133 sds_id = SDcreate(file_id, sds_name, number_type,
rank, dim_size);
1134 if (sds_id ==
FAIL) {
1136 sprintf(errmsgbuf,
"Could not create SDS \"%s\" in the file.",
1138 L1BErrorMsg(
"write_sds_rank2", errcode, errmsgbuf,
"SDcreate", 0,
1139 corruptoutputfile,
False);
1145 dim_id[
i] = SDgetdimid(sds_id,
i);
1146 if (dim_id[
i] ==
FAIL) {
1148 sprintf(errmsgbuf,
"Could not retrieve dimension #%d id for SDS \"%s\".",
1150 L1BErrorMsg(
"write_sds_rank2", errcode, errmsgbuf,
"SDgetdimid", 0,
1151 corruptoutputfile,
False);
1152 SDendaccess(sds_id);
1156 result = SDsetdimname (dim_id[
i], dim_name[
i]);
1159 sprintf(errmsgbuf,
"Could not set dimension #%d name for SDS \"%s\".",
1161 L1BErrorMsg(
"write_sds_rank2", errcode, errmsgbuf,
"SDsetdimname", 0,
1162 corruptoutputfile,
False);
1163 SDendaccess(sds_id);
1171 sprintf(errmsgbuf,
"Could not write data to SDS \"%s\".",
1173 L1BErrorMsg(
"write_sds_rank2", errcode, errmsgbuf,
"SDwritedata", 0,
1174 nowriteoutputfile,
False);
1175 SDendaccess(sds_id);
1179 result = SDendaccess(sds_id);
1182 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1184 L1BErrorMsg(
"write_sds_rank2", errcode, errmsgbuf,
"SDendaccess", 0,
1185 corruptoutputfile,
False);
1246 int32 dim_id[3] = {0, 0, 0};
1247 int32
start[3] = {0, 0, 0};
1259 dim_name[0] = dim_name1;
1260 dim_name[1] = dim_name2;
1261 dim_name[2] = dim_name3;
1263 returnStatus = assign_data_type(datatype, &number_type);
1265 L1BErrorMsg(
"write_sds_rank3", returnStatus,
NULL,
"assign_data_type", 0,
1267 return returnStatus;
1270 sds_id = SDcreate(file_id, sds_name, number_type,
rank, dim_size);
1271 if (sds_id ==
FAIL) {
1273 sprintf(errmsgbuf,
"Could not create SDS \"%s\" in the file.",
1275 L1BErrorMsg(
"write_sds_rank3", errcode, errmsgbuf,
"SDcreate", 0,
1276 corruptoutputfile,
False);
1282 dim_id[
i] = SDgetdimid(sds_id,
i);
1283 if (dim_id[
i] ==
FAIL) {
1285 sprintf(errmsgbuf,
"Could not retrieve dimension #%d id for SDS \"%s\".",
1287 L1BErrorMsg(
"write_sds_rank3", errcode, errmsgbuf,
"SDgetdimid", 0,
1288 corruptoutputfile,
False);
1289 SDendaccess(sds_id);
1293 result = SDsetdimname (dim_id[
i], dim_name[
i]);
1296 sprintf(errmsgbuf,
"Could not set dimension #%d name for SDS \"%s\".",
1298 L1BErrorMsg(
"write_sds_rank3", errcode, errmsgbuf,
"SDsetdimname", 0,
1299 corruptoutputfile,
False);
1300 SDendaccess(sds_id);
1308 sprintf(errmsgbuf,
"Could not write data to SDS \"%s\".",
1310 L1BErrorMsg(
"write_sds_rank3", errcode, errmsgbuf,
"SDwritedata", 0,
1311 nowriteoutputfile,
False);
1312 SDendaccess(sds_id);
1316 result = SDendaccess(sds_id);
1319 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1321 L1BErrorMsg(
"write_sds_rank3", errcode, errmsgbuf,
"SDendaccess", 0,
1322 corruptoutputfile,
False);
1391 int32 dim_id[4] = {0, 0, 0, 0};
1392 int32
start[4] = {0, 0, 0, 0};
1406 dim_name[0] = dim_name1;
1407 dim_name[1] = dim_name2;
1408 dim_name[2] = dim_name3;
1409 dim_name[3] = dim_name4;
1411 returnStatus = assign_data_type(datatype, &number_type);
1413 L1BErrorMsg(
"write_sds_rank4", returnStatus,
NULL,
"assign_data_type", 0,
1415 return returnStatus;
1418 sds_id = SDcreate(file_id, sds_name, number_type,
rank, dim_size);
1419 if (sds_id ==
FAIL) {
1421 sprintf(errmsgbuf,
"Could not create SDS \"%s\" in the file.",
1423 L1BErrorMsg(
"write_sds_rank4", errcode, errmsgbuf,
"SDcreate", 0,
1424 corruptoutputfile,
False);
1430 dim_id[
i] = SDgetdimid(sds_id,
i);
1431 if (dim_id[
i] ==
FAIL) {
1433 sprintf(errmsgbuf,
"Could not retrieve dimension #%d id for SDS \"%s\".",
1435 L1BErrorMsg(
"write_sds_rank4", errcode, errmsgbuf,
"SDgetdimid", 0,
1436 corruptoutputfile,
False);
1437 SDendaccess(sds_id);
1441 result = SDsetdimname (dim_id[
i], dim_name[
i]);
1444 sprintf(errmsgbuf,
"Could not set dimension #%d name for SDS \"%s\".",
1446 L1BErrorMsg(
"write_sds_rank4", errcode, errmsgbuf,
"SDsetdimname", 0,
1447 corruptoutputfile,
False);
1448 SDendaccess(sds_id);
1456 sprintf(errmsgbuf,
"Could not write data to SDS \"%s\".",
1458 L1BErrorMsg(
"write_sds_rank4", errcode, errmsgbuf,
"SDwritedata", 0,
1459 nowriteoutputfile,
False);
1460 SDendaccess(sds_id);
1464 result = SDendaccess(sds_id);
1467 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1469 L1BErrorMsg(
"write_sds_rank4", errcode, errmsgbuf,
"SDendaccess", 0,
1470 corruptoutputfile,
False);
1530 int32 sds_index = 0;
1539 int32 f_data_type = 0;
1549 sprintf(errmsgbuf,
"One or more input arguments are invalid.");
1551 "This is a code defect.",
False);
1559 sds_index = SDnametoindex (sd_id, sds_name);
1560 if (sds_index ==
FAIL) {
1562 sprintf(errmsgbuf,
"Could not find SDS \"%s\" in the file.",
1564 L1BErrorMsg(
"read_sds_rankn", errcode, errmsgbuf,
"SDnametoindex", 0,
1573 sds_id = SDselect (sd_id, sds_index);
1574 if (sds_id ==
FAIL) {
1576 sprintf(errmsgbuf,
"Could not open access to SDS \"%s\".",
1578 L1BErrorMsg(
"read_sds_rankn", errcode, errmsgbuf,
"SDselect", 0,
1587 result = SDgetinfo (sds_id, f_sds_name, &f_rank, f_dim_sizes,
1588 &f_data_type, &f_nattrs);
1591 sprintf(errmsgbuf,
"Could not retrieve info for SDS \"%s\".",
1593 L1BErrorMsg(
"read_sds_rankn", errcode, errmsgbuf,
"SDgetinfo", 0,
1597 if (data_type != f_data_type) {
1599 sprintf(errmsgbuf,
"SDS \"%s\" has data type mismatch.\n"
1600 "File data type = %ld, expected type = %ld\n",
1601 sds_name, (
long)f_data_type, (
long)data_type);
1606 if (
rank != f_rank) {
1608 sprintf(errmsgbuf,
"SDS \"%s\" has matrix rank mismatch.\n"
1609 "File data rank = %ld, expected rank = %ld\n",
1610 sds_name, (
long)f_rank, (
long)
rank);
1622 SDendaccess(sds_id);
1624 sprintf(errmsgbuf,
"Could not read data from SDS \"%s\".",
1626 L1BErrorMsg(
"read_sds_rankn", errcode, errmsgbuf,
"SDreaddata", 0,
1635 result = SDendaccess(sds_id);
1638 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1640 L1BErrorMsg(
"read_sds_rankn", errcode, errmsgbuf,
"SDendaccess", 0,
1703 char *location =
"write_sds_rankn";
1708 sprintf(errmsgbuf,
"Could not create SDS \"%s\". Rank (%ld) exceeds max (%d)",
1711 "Code bug.",
False);
1718 sds_id = SDcreate(file_id, sds_name, data_type,
rank, edge);
1719 if (sds_id ==
FAIL) {
1721 sprintf(errmsgbuf,
"Could not create SDS \"%s\" in the file.",
1723 L1BErrorMsg(location, errcode, errmsgbuf,
"SDcreate", 0,
1724 corruptoutputfile,
False);
1730 dim_id[
i] = SDgetdimid(sds_id,
i);
1731 if (dim_id[
i] ==
FAIL) {
1733 sprintf(errmsgbuf,
"Could not retrieve dimension #%d id for SDS \"%s\".",
1735 L1BErrorMsg(location, errcode, errmsgbuf,
"SDgetdimid", 0,
1736 corruptoutputfile,
False);
1737 SDendaccess(sds_id);
1741 result = SDsetdimname (dim_id[
i], dim_name[
i]);
1744 sprintf(errmsgbuf,
"Could not set dimension #%d name for SDS \"%s\".",
1746 L1BErrorMsg(location, errcode, errmsgbuf,
"SDsetdimname", 0,
1747 corruptoutputfile,
False);
1748 SDendaccess(sds_id);
1756 sprintf(errmsgbuf,
"Could not write data to SDS \"%s\".",
1758 L1BErrorMsg(location, errcode, errmsgbuf,
"SDwritedata", 0,
1759 nowriteoutputfile,
False);
1760 SDendaccess(sds_id);
1764 result = SDendaccess(sds_id);
1767 sprintf(errmsgbuf,
"Could not end access to SDS \"%s\".",
1769 L1BErrorMsg(location, errcode, errmsgbuf,
"SDendaccess", 0,
1770 corruptoutputfile,
False);
1856 char *unknown_data_name =
"(unknown)";
1857 double del, absd, absdfv;
1875 #define ASSIGN_INT_VALUE(aptr, a, alb, aub, type_of_data) \
1877 if (i < (int32) alb || i > (int32) aub) { \
1878 errcode = MODIS_F_NOK; \
1879 sprintf(errmsgbuf, \
1880 "Checking valid range of \"%s\", the value \"%s\" is not\n" \
1881 "a valid number for the precision of the data type.", \
1883 L1BErrorMsg("Check_Valid_Range", errcode, errmsgbuf, NULL, 0, \
1884 "Code defect.", False); \
1889 switch (type_of_data) \
1890 { case DFNT_INT8: a = (int8) i; break; \
1891 case DFNT_UINT8: a = (uint8) i; break; \
1892 case DFNT_INT16: a = (int16) i; break; \
1893 case DFNT_UINT16: a = (uint16) i; break; \
1894 case DFNT_INT32: a = (int32) i; break; \
1895 case DFNT_UINT32: a = (uint32) i; \
1907 #define CHECK_IVALS_ON_LB \
1908 for (i = 0; i < count; i++) { \
1909 if (data[i] < lb && data[i] != fillvalue) { \
1910 errcode = MODIS_F_OUT_OF_RANGE; \
1911 sprintf(errmsgbuf, \
1912 "One or more values of \"%s\" is less than the lower bound.\n" \
1913 "value[%ld] = %ld\nlower bnd = %s\n", \
1914 data_name, i, (long) data[i], a_lb); \
1915 L1BErrorMsg("Check_Valid_Range", errcode, errmsgbuf, NULL, 0, \
1916 invalidinputfile, False); \
1929 #define CHECK_FVALS_ON_LB \
1930 for (i = 0; i < count; i++) { \
1931 absd = fabs((double) data[i]); absdfv = fabs((double)fillvalue); \
1932 del = fabs((double) (data[i] - fillvalue)); \
1933 if (absd > 0) del /= absd; else if(absdfv > 0) del /= absdfv; \
1934 if (data[i] < lb && del > 1.e-05) { \
1935 errcode = MODIS_F_OUT_OF_RANGE; \
1936 sprintf(errmsgbuf, \
1937 "One or more values of \"%s\" is less than the lower bound.\n" \
1938 "value[%ld] = %f\nlower bnd = %s\n", \
1939 data_name, i, (double) data[i], a_lb); \
1940 L1BErrorMsg("Check_Valid_Range", errcode, errmsgbuf, NULL, 0, \
1941 invalidinputfile, False); \
1954 #define CHECK_IVALS_ON_UB \
1955 for (i = 0; i < count; i++) { \
1956 if (data[i] > ub && data[i] != fillvalue) { \
1957 errcode = MODIS_F_OUT_OF_RANGE; \
1958 sprintf(errmsgbuf, \
1959 "One or more values of \"%s\" is greater than the upper bound.\n" \
1960 "value[%ld] = %ld\nupper bnd = %s\n", \
1961 data_name, i, (long) data[i], a_ub); \
1962 L1BErrorMsg("Check_Valid_Range", errcode, errmsgbuf, NULL, 0, \
1963 invalidinputfile, False); \
1976 #define CHECK_FVALS_ON_UB \
1977 for (i = 0; i < count; i++) { \
1978 absd = fabs((double) data[i]); absdfv = fabs((double)fillvalue); \
1979 del = fabs((double) (data[i] - fillvalue)); \
1980 if (absd > 0) del /= absd; else if(absdfv > 0) del /= absdfv; \
1981 if (data[i] > ub && del > 1.e-05) { \
1982 errcode = MODIS_F_OUT_OF_RANGE; \
1983 sprintf(errmsgbuf, \
1984 "One or more values of \"%s\" is greater than the upper bound.\n" \
1985 "value[%ld] = %f\nupper bnd = %s\n", \
1986 data_name, i, (double) data[i], a_ub); \
1987 L1BErrorMsg("Check_Valid_Range", errcode, errmsgbuf, NULL, 0, \
1988 invalidinputfile, False); \
1997 if (
count <= 0 || !buffer) {
1999 sprintf(errmsgbuf,
"Input arguments are invalid. \"count\" is zero "
2000 "or \"buffer\" is NULL.");
2002 "Code defect (check that data buffer pointer is assigned).",
2013 if (!data_name) data_name = unknown_data_name;
2026 fvptr = a_fillvalue;
2034 if (data_type == DFNT_INT8) {
2035 int8 *
data = (int8 *) buffer;
2041 else if (data_type == DFNT_UINT8) {
2042 uint8 *
data = (uint8 *) buffer;
2043 uint8 lb, fillvalue;
2050 int16 lb, fillvalue;
2055 else if (data_type == DFNT_UINT16) {
2056 uint16 *
data = (uint16 *) buffer;
2057 uint16 lb, fillvalue;
2063 int32 *
data = (int32 *) buffer;
2064 int32 lb, fillvalue;
2065 lb = (int32) atol(a_lb);
2066 fillvalue = (int32) atol(fvptr);
2069 else if (data_type == DFNT_UINT32) {
2070 uint32 *
data = (uint32 *) buffer;
2071 uint32 lb, fillvalue;
2077 float32 *
data = (float32 *) buffer;
2078 float32 lb, fillvalue;
2079 lb = (float32) atof(a_lb);
2080 fillvalue = (float32) atof(fvptr);
2083 else if (data_type == DFNT_FLOAT64) {
2084 float64 *
data = (float64 *) buffer;
2085 float64 lb, fillvalue;
2087 fillvalue = atof(fvptr);
2106 fvptr = a_fillvalue;
2114 if (data_type == DFNT_INT8) {
2115 int8 *
data = (int8 *) buffer;
2121 else if (data_type == DFNT_UINT8) {
2122 uint8 *
data = (uint8 *) buffer;
2123 uint8 ub, fillvalue;
2130 int16 ub, fillvalue;
2135 else if (data_type == DFNT_UINT16) {
2136 uint16 *
data = (uint16 *) buffer;
2137 uint16 ub, fillvalue;
2143 int32 *
data = (int32 *) buffer;
2144 int32 ub, fillvalue;
2145 ub = (int32) atol(a_ub);
2146 fillvalue = (int32) atol(fvptr);
2149 else if (data_type == DFNT_UINT32) {
2150 uint32 *
data = (uint32 *) buffer;
2151 uint32 ub, fillvalue;
2157 float32 *
data = (float32 *) buffer;
2158 float32 ub, fillvalue;
2159 ub = (float32) atof(a_ub);
2160 fillvalue = (float32) atof(fvptr);
2163 else if (data_type == DFNT_FLOAT64) {
2164 float64 *
data = (float64 *) buffer;
2165 float64 ub, fillvalue;
2167 fillvalue = atof(fvptr);