20 intn
setAttr(uint8
isHDF5, int32 obj_id,
const char *attr_name, int32 data_type,
23 hid_t
dtype = H5T_NATIVE_CHAR;
24 if (data_type == DFNT_CHAR &&
count > 1)
dtype = H5T_STRING;
25 else if (data_type == DFNT_CHAR)
dtype = H5T_NATIVE_CHAR;
26 else if (data_type == DFNT_UINT8)
dtype = H5T_NATIVE_UCHAR;
28 else if (data_type == DFNT_UINT16)
dtype = H5T_NATIVE_USHORT;
30 else if (data_type == DFNT_UINT32)
dtype = H5T_STD_U32LE;
38 if (data_type == DFNT_CHAR)
dtype = NC_CHAR;
39 else if (data_type == DFNT_UINT8)
dtype = NC_UBYTE;
41 else if (data_type == DFNT_UINT16)
dtype = NC_SHORT;
43 else if (data_type == DFNT_UINT32)
dtype = NC_INT;
49 return SDsetattr(obj_id, attr_name, data_type,
count, (VOIDP)
values);
70 unsigned char *map_palette,
149 int32_t
put_smi(
char *l3m_path,
char*l3m_name, uint8 *l3m_data,
160 float32 *l3m_dminmax,
175 int32 fid, sdfid, sdsid;
176 int32
i,
rank = 2, mix, pal_ref;
177 int32
start[2] = {0, 0};
181 char *loc_path, *
str, loc_measure[
MAXVAL];
183 float32 lat_step, lon_step, swlat, swlon;
192 int32 valid_range[2] = {0, 2};
195 h5fid = H5Fcreate(l3m_path, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
197 printf(
"\nError creating file %s \n", l3m_path);
200 grp0 = H5Gopen1(h5fid,
"/");
203 status = nc_create(l3m_path, NC_NETCDF4, &ncid);
205 printf(
"\nError creating file %s \n", l3m_path);
210 sdfid = SDstart(l3m_path, DFACC_CREATE);
211 fid = Hopen(l3m_path, DFACC_RDWR, 0);
213 if (sdfid < 0 || fid < 0) {
214 printf(
"\nError creating file %s \n", l3m_path);
225 if ((loc_path = strrchr(l3m_path,
'/')) !=
NULL)
233 strlen(loc_path) + 1, (VOIDP) loc_path);
239 strlen(meta_l3b->
sensor) + 1, (VOIDP) meta_l3b->
sensor);
242 " Level-3 Standard Mapped Image");
245 strlen(
" Level-3 Standard Mapped Image") + 1,
274 strlen(
input.pversion) + 1, (VOIDP)
input.pversion);
285 strlen(meta_l3b->
ptime) + 1, (VOIDP) meta_l3b->
ptime);
287 if ((
str = strrchr(infiles,
'/')) !=
NULL)
293 strlen(
str) + 1, (VOIDP)
str);
296 strlen(proc_con) + 1, (VOIDP) proc_con);
299 strlen(
input.parms) + 1, (VOIDP)
input.parms);
349 if (lat_range[0] <= lat_range[1]) {
350 printf(
"\nput_smi: Given latitude range is in error \n");
358 lat_step = (lat_range[0] - lat_range[1]) / dim_sizes[0];
361 if (lon_range[1] > lon_range[0])
362 lon_step = (lon_range[1] - lon_range[0]) / dim_sizes[1];
364 lon_step = (360 - lon_range[0] + lon_range[1]) / dim_sizes[1];
367 swlat = (lat_range[1] + lat_step / 2.0);
368 swlon = (lon_range[0] + lon_step / 2.0);
382 (VOIDP)
input.proddesc);
384 for (
i = 0;
i < (int32_t) strlen(measure);
i++)
385 loc_measure[
i] = measure[
i];
386 loc_measure[
i] = (char)
NULL;
394 printf(
"\nput_smi: Error: measure - %s unrecognized\n", measure);
405 (VOIDP)
input.units);
407 if (strcmp(scale_type,
"LOG") == 0) {
422 (VOIDP) & si_used[1]);
428 (VOIDP) & aminmax[0]);
430 (VOIDP) & aminmax[1]);
431 setAttr(
isHDF5, sdfid,
"Suggested Image Scaling Type", DFNT_CHAR, strlen(atype) + 1,
433 setAttr(
isHDF5, sdfid,
"Suggested Image Scaling Applied", DFNT_CHAR, strlen(aopt) + 1,
437 strlen(meta_l3b->
ptime) + 1, (VOIDP) meta_l3b->
ptime);
442 strlen(loc_path) + 1, (VOIDP) loc_path);
448 " Level-3 Standard Mapped Image");
451 strlen(
" Level-3 Standard Mapped Image") + 1,
456 strcpy(buf,
"Ocean Biology Processing Group (NASA/GSFC/OBPG)");
459 if (strcmp(meta_l3b->
mission,
"") != 0)
467 strlen(
input.pversion) + 1, (VOIDP)
input.pversion);
472 strlen(meta_l3b->
ptime) + 1, (VOIDP) meta_l3b->
ptime);
475 strlen(proc_con) + 1, (VOIDP) proc_con);
481 setAttr(
isHDF5, sdfid,
"time_coverage_start", DFNT_CHAR, strlen(attr_buffer) + 1, attr_buffer);
484 setAttr(
isHDF5, sdfid,
"time_coverage_end", DFNT_CHAR, strlen(attr_buffer) + 1, attr_buffer);
492 strcpy(attr_buffer,
"degrees_north");
493 setAttr(
isHDF5, sdfid,
"latitude_units", DFNT_CHAR, strlen(attr_buffer) + 1,
494 (VOIDP) attr_buffer);
496 strcpy(attr_buffer,
"degrees_east");
497 setAttr(
isHDF5, sdfid,
"longitude_units", DFNT_CHAR, strlen(attr_buffer) + 1,
498 (VOIDP) attr_buffer);
502 if (lat_range[0] <= lat_range[1]) {
503 printf(
"\nput_smi: Given latitude range is in error \n");
516 setAttr(
isHDF5, sdfid,
"grid_mapping_name", DFNT_CHAR, 18, (VOIDP)
"latitude_longitude");
518 lat_step = (lat_range[0] - lat_range[1]) / dim_sizes[0];
521 if (lon_range[1] > lon_range[0])
522 lon_step = (lon_range[1] - lon_range[0]) / dim_sizes[1];
524 lon_step = (360 - lon_range[0] + lon_range[1]) / dim_sizes[1];
527 if ((lonarray = (
float *) malloc(dim_sizes[1] *
sizeof (
float))) ==
NULL) {
529 "-E- : Error allocating memory for lon array\n");
532 if ((latarray = (
float *) malloc(dim_sizes[0] *
sizeof (
float))) ==
NULL) {
534 "-E- : Error allocating memory for lat array\n");
537 for (
i = 0;
i < dim_sizes[1];
i++) {
538 lonarray[
i] = lon_range[0] + lon_step *
i + lon_step / 2.0;
540 for (
i = 0;
i < dim_sizes[0];
i++) {
541 latarray[
i] = lat_range[0] - lat_step *
i - lat_step / 2.0;
543 swlat = (lat_range[1] + lat_step / 2.0);
544 swlon = (lon_range[0] + lon_step / 2.0);
548 float geo_resolution;
549 char geospatial_units[8];
550 if (strcmp(
input.resolution,
"LAND") == 0) {
551 geo_resolution = 4.6;
552 strcpy(geospatial_units,
"km");
553 }
else if (strcmp(
input.resolution,
"9km") == 0) {
554 geo_resolution = 9.2;
555 strcpy(geospatial_units,
"km");
556 }
else if (strcmp(
input.resolution,
"18km") == 0) {
557 geo_resolution = 18.5;
558 strcpy(geospatial_units,
"km");
559 }
else if (strcmp(
input.resolution,
"4km") == 0) {
560 geo_resolution = 4.6;
561 strcpy(geospatial_units,
"km");
562 }
else if (strcmp(
input.resolution,
"2km") == 0) {
563 geo_resolution = 2.3;
564 strcpy(geospatial_units,
"km");
565 }
else if (strcmp(
input.resolution,
"1km") == 0) {
566 geo_resolution = 1.2;
567 strcpy(geospatial_units,
"km");
568 }
else if (strcmp(
input.resolution,
"hkm") == 0) {
569 geo_resolution = 575;
570 strcpy(geospatial_units,
"m");
571 }
else if (strcmp(
input.resolution,
"qkm") == 0) {
572 geo_resolution = 288;
573 strcpy(geospatial_units,
"m");
574 }
else if (strcmp(
input.resolution,
"36km") == 0) {
576 strcpy(geospatial_units,
"km");
577 }
else if (strcmp(
input.resolution,
"90km") == 0) {
579 strcpy(geospatial_units,
"km");
580 }
else if (strcmp(
input.resolution,
"1deg") == 0) {
582 strcpy(geospatial_units,
"deg");
583 }
else if (strcmp(
input.resolution,
"hdeg") == 0) {
584 geo_resolution = 0.5;
585 strcpy(geospatial_units,
"deg");
586 }
else if (strcmp(
input.resolution,
"qdeg") == 0) {
587 geo_resolution = 0.25;
588 strcpy(geospatial_units,
"deg");
589 }
else if (strcmp(
input.resolution,
"10deg") == 0) {
591 strcpy(geospatial_units,
"deg");
592 }
else if (strncmp(
input.resolution,
"udeg", 4) == 0) {
593 geo_resolution = (
float) atof(&
input.resolution[5]);
594 strcpy(geospatial_units,
"deg");
595 }
else if (strncmp(
input.resolution,
"ukm", 3) == 0) {
596 geo_resolution = (
float) atof(&
input.resolution[4]);
597 strcpy(geospatial_units,
"km");
600 setAttr(
isHDF5, sdfid,
"geospatial_lon_resolution", DFNT_FLOAT, 1, &geo_resolution);
601 setAttr(
isHDF5, sdfid,
"geospatial_lat_resolution", DFNT_FLOAT, 1, &geo_resolution);
605 strlen(geospatial_units) + 1, geospatial_units);
608 strlen(geospatial_units) + 1, geospatial_units);
610 sprintf(buf,
"%3.2f %s", geo_resolution, geospatial_units);
612 strlen(buf) + 1, buf);
619 for (
i = 0;
i < (int32_t) strlen(measure);
i++)
620 loc_measure[
i] = measure[
i];
621 loc_measure[
i] = (char)
NULL;
629 printf(
"\nput_smi: Error: measure - %s unrecognized\n", measure);
640 (VOIDP) & aminmax[0]);
642 (VOIDP) & aminmax[1]);
643 setAttr(
isHDF5, sdfid,
"suggested_image_scaling_type", DFNT_CHAR, strlen(atype) + 1,
645 setAttr(
isHDF5, sdfid,
"suggested_image_scaling_applied", DFNT_CHAR, strlen(aopt) + 1,
649 strlen(meta_l3b->
ptime) + 1, (VOIDP) meta_l3b->
ptime);
651 setAttr(
isHDF5, sdfid,
"Conventions", DFNT_CHAR, strlen(
"CF-1.6") + 1,
655 strlen(
"NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group") + 1,
656 (VOIDP)
"NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group");
658 char const *standard_name_vocabulary =
659 "NetCDF Climate and Forecast (CF) Metadata Convention";
660 strcpy(buf, standard_name_vocabulary);
662 strlen(buf) + 1, buf);
664 char const *Metadata_Conventions =
"Unidata Dataset Discovery v1.0";
665 strcpy(buf, Metadata_Conventions);
668 char const *naming_authority =
"gov.nasa.gsfc.sci.oceandata";
669 strcpy(buf, naming_authority);
673 if (strcmp(meta_l3b->
pversion,
"Unspecified") != 0) {
683 char const *license =
684 "http://science.nasa.gov/earth-science/earth-science-data/data-information-policy/";
688 strcpy(buf,
"NASA/GSFC/OBPG");
692 strcpy(buf,
"data@oceancolor.gsfc.nasa.gov");
696 strcpy(buf,
"http://oceandata.sci.gsfc.nasa.gov");
706 strcpy(buf,
"http://dx.doi.org");
708 strlen(buf) + 1, buf);
711 strcpy(buf,
"10.5067/NIMBUS-7/CZCS_OC.2014.0");
713 strcpy(buf,
"10.5067/ADEOS/OCTS_OC.2014.0");
715 strcpy(buf,
"10.5067/ORBVIEW-2/SEAWIFS_OC.2014.0");
718 strcpy(buf,
"10.5067/AQUA/MODIS_OC.2014.0");
720 strcpy(buf,
"10.5067/TERRA/MODIS_OC.2014.0");
725 strlen(buf) + 1, buf);
727 char const *keyword_oc =
728 "Oceans > Ocean Chemistry > Chlorophyll; Oceans > Ocean Optics > Ocean Color";
729 char const *keyword_sst =
730 "Oceans > Ocean Temperature > Sea Surface Temperature";
732 char const *keyword_salinity =
733 "SURFACE SALINITY, SALINITY, AQUARIUS, Jet Propulsion Laboratory, NASA, http://aquarius.nasa.gov/, AQUARIUS SAC-D, Aquarius Scatterometer, Aquarius Radiometer";
741 strcpy(buf, keyword_salinity);
745 char const *keywords_vocabulary =
746 "NASA Global Change Master Directory (GCMD) Science Keywords";
747 strcpy(buf, keywords_vocabulary);
749 strlen(buf) + 1, buf);
753 nc_def_grp(sdfid,
"processing_control", &grpid);
763 if ((
str = strrchr(infiles,
'/')) !=
NULL)
768 strlen(
str) + 1, (VOIDP)
str);
775 nc_def_grp(grpid,
"input_parameters", &grpid);
777 char *token = strtok_r(
input.parms,
"|", &end_str);
779 while (token !=
NULL) {
782 char *
name = strtok_r(token,
"=", &end_token);
783 for (uint32_t
i = 0;
i < strlen(
name);
i++) {
784 if (
name[
i] ==
' ') {
789 strcpy(tmp_buf, strtok_r(
NULL,
"|", &end_token));
792 strlen(tmp_buf), (VOIDP) & tmp_buf[1]);
793 token = strtok_r(
NULL,
"|", &end_str);
800 hsize_t dims[2] = {(hsize_t) dim_sizes[0], (hsize_t) dim_sizes[1]};
801 hid_t dataspace = H5Screate_simple(
rank, dims,
NULL);
803 if (strcmp(precision,
"F") == 0) {
804 datatype = H5T_NATIVE_FLOAT;
805 }
else if (strcmp(precision,
"I") == 0) {
806 datatype = H5T_NATIVE_USHORT;
808 datatype = H5T_NATIVE_UCHAR;
813 printf(
"\nput_smi: H5Dcreate call to create %s is unsuccessful",
820 if ((H5Dwrite(
dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
821 (VOIDP) l3m_data)) < 0) {
822 printf(
"\nput_smi: H5Dwrite unsuccessful\n");
826 if (strcmp(scale_type,
"LOG") == 0) {
841 (VOIDP) & si_used[1]);
847 (VOIDP) & si_used[1]);
855 dataspace = H5Screate_simple(2, dims,
NULL);
856 if ((
dataset = H5Dcreate1(grp0,
"palette", H5T_NATIVE_UCHAR, dataspace,
858 printf(
"\nput_smi: H5Dcreate call to create %s is unsuccessful",
863 if ((H5Dwrite(
dataset, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT,
864 (VOIDP) map_palette)) < 0) {
865 printf(
"\nput_smi: H5Dwrite unsuccessful\n");
876 status = nc_def_dim(sdfid,
"lat", dim_sizes[0], &dimids[0]);
879 status = nc_def_dim(sdfid,
"lon", dim_sizes[1], &dimids[1]);
883 if (strcmp(precision,
"F") == 0) {
885 }
else if (strcmp(precision,
"I") == 0) {
886 datatype = NC_USHORT;
897 status = nc_def_var(sdfid, l3m_name, datatype, 2, dimids, &varid);
901 if (
input.deflate > 0) {
903 size_t chunksize[2] = {64, 64};
904 status = nc_def_var_chunking(sdfid, varid, NC_CHUNKED, chunksize);
906 if (
status != NC_NOERR) exit(1);
909 status = nc_def_var_deflate(sdfid, varid, NC_NOSHUFFLE, 1,
912 if (
status != NC_NOERR) exit(1);
915 static productInfo_t *p_info;
921 if (sensorId == -1) {
927 printf(
"%s not found in XML product table\n", l3m_name);
931 status = nc_put_att_text(sdfid, varid,
"long_name",
932 strlen(p_info->description) + 1,
933 p_info->description);
935 status = nc_put_att_text(sdfid, varid,
"units",
936 strlen(p_info->units) + 1,
940 if (p_info->standardName !=
NULL) {
941 status = nc_put_att_text(sdfid, varid,
"standard_name",
942 strlen(p_info->standardName) + 1,
943 p_info->standardName);
946 if (datatype == NC_SHORT) {
947 short fv_i16 = (
int) p_info->fillValue;
948 status = nc_put_att(sdfid, varid,
"_FillValue", NC_SHORT, 1, &fv_i16);
951 valid = p_info->validMin;
952 status = nc_put_att_short(sdfid, varid,
"valid_min", NC_SHORT, 1,
954 valid = p_info->validMax;
955 status = nc_put_att_short(sdfid, varid,
"valid_max", NC_SHORT, 1,
959 }
else if (datatype == NC_INT) {
960 float fv_i = (
int) p_info->fillValue;
961 status = nc_put_att(sdfid, varid,
"_FillValue", NC_INT, 1, &fv_i);
964 valid = p_info->validMin;
965 status = nc_put_att_int(sdfid, varid,
"valid_min", NC_INT, 1,
967 valid = p_info->validMax;
968 status = nc_put_att_int(sdfid, varid,
"valid_max", NC_INT, 1,
972 }
else if (datatype == NC_FLOAT) {
973 float fv_f32 = (
float) p_info->fillValue;
974 status = nc_put_att(sdfid, varid,
"_FillValue", NC_FLOAT, 1, &fv_f32);
977 valid = p_info->validMin;
978 status = nc_put_att_float(sdfid, varid,
"valid_min", NC_FLOAT, 1,
980 valid = p_info->validMax;
981 status = nc_put_att_float(sdfid, varid,
"valid_max", NC_FLOAT, 1,
987 status = nc_put_att_text(sdfid, varid,
"display_scale",
988 strlen(p_info->displayScale) + 1,
989 p_info->displayScale);
991 status = nc_put_att_double(sdfid, varid,
"display_min", NC_DOUBLE, 1,
992 &p_info->displayMin);
993 status = nc_put_att_double(sdfid, varid,
"display_max", NC_DOUBLE, 1,
994 &p_info->displayMax);
996 status = nc_put_att_float(sdfid, varid,
"scale_factor", NC_FLOAT, 1,
998 status = nc_put_att_float(sdfid, varid,
"add_offset", NC_FLOAT, 1,
1001 if (&p_info->reference[0] != 0)
1002 status = nc_put_att_text(sdfid, varid,
"reference",
1003 strlen(p_info->reference) + 1,
1006 if (&p_info->comment[0] != 0)
1007 status = nc_put_att_text(sdfid, varid,
"comment",
1008 strlen(p_info->comment) + 1,
1011 status = nc_put_var(sdfid, varid, l3m_data);
1014 if (qual_byt !=
NULL) {
1016 char l3m_qualname[128];
1017 strcpy(l3m_qualname,
"qual_");
1018 strcat(l3m_qualname, l3m_name);
1019 status = nc_def_var(sdfid, l3m_qualname, NC_BYTE, 2, dimids, &qualid);
1022 status = nc_put_var(sdfid, qualid, qual_byt);
1031 status = nc_def_var(sdfid,
"lat", NC_FLOAT, 1, &dimids[0], &varid);
1034 printf(
"%s not found in XML product table\n", l3m_name);
1037 status = nc_put_att_text(sdfid, varid,
"long_name",
1038 strlen(p_info->description) + 1,
1039 p_info->description);
1041 status = nc_put_att_text(sdfid, varid,
"units",
1042 strlen(p_info->units) + 1,
1046 if (p_info->standardName !=
NULL) {
1047 status = nc_put_att_text(sdfid, varid,
"standard_name",
1048 strlen(p_info->standardName) + 1,
1049 p_info->standardName);
1051 float fv_f32 = (
float) p_info->fillValue;
1052 status = nc_put_att(sdfid, varid,
"_FillValue", NC_FLOAT, 1, &fv_f32);
1054 valid = p_info->validMin;
1055 status = nc_put_att_float(sdfid, varid,
"valid_min", NC_FLOAT, 1,
1057 valid = p_info->validMax;
1058 status = nc_put_att_float(sdfid, varid,
"valid_max", NC_FLOAT, 1,
1060 status = nc_put_var(sdfid, varid, latarray);
1064 status = nc_def_var(sdfid,
"lon", NC_FLOAT, 1, &dimids[1], &varid);
1067 printf(
"%s not found in XML product table\n", l3m_name);
1070 status = nc_put_att_text(sdfid, varid,
"long_name",
1071 strlen(p_info->description) + 1,
1072 p_info->description);
1074 status = nc_put_att_text(sdfid, varid,
"units",
1075 strlen(p_info->units) + 1,
1079 if (p_info->standardName !=
NULL) {
1080 status = nc_put_att_text(sdfid, varid,
"standard_name",
1081 strlen(p_info->standardName) + 1,
1082 p_info->standardName);
1084 fv_f32 = (
float) p_info->fillValue;
1085 status = nc_put_att(sdfid, varid,
"_FillValue", NC_FLOAT, 1, &fv_f32);
1086 valid = p_info->validMin;
1087 status = nc_put_att_float(sdfid, varid,
"valid_min", NC_FLOAT, 1,
1089 valid = p_info->validMax;
1090 status = nc_put_att_float(sdfid, varid,
"valid_max", NC_FLOAT, 1,
1092 status = nc_put_var(sdfid, varid, lonarray);
1099 status = nc_def_dim(sdfid,
"rgb", 3, &dimids[0]);
1102 status = nc_def_dim(sdfid,
"eightbitcolor", 256, &dimids[1]);
1105 status = nc_def_var(sdfid,
"palette", NC_UBYTE, 2, dimids, &varid);
1108 status = nc_put_var(sdfid, varid, map_palette);
1111 status = nc_close(sdfid);
1118 if (strcmp(precision,
"F") == 0) {
1120 printf(
"\nput_smi: SDcreate call to create %s is unsuccessful",
1125 }
else if (strcmp(precision,
"I") == 0) {
1126 if ((sdsid = SDcreate(sdfid,
SDS_NAME, DFNT_UINT16,
rank, dim_sizes)) < 0) {
1127 printf(
"\nput_smi: SDcreate call to create %s is unsuccessful",
1133 if ((sdsid = SDcreate(sdfid,
SDS_NAME, DFNT_UINT8,
rank, dim_sizes)) < 0) {
1134 printf(
"\nput_smi: SDcreate call to create %s is unsuccessful",
1141 if ((SDwritedata(sdsid,
start,
NULL, dim_sizes, (VOIDP) l3m_data)) < 0) {
1142 printf(
"\nput_smi: SDwritedata unsuccessful\n");
1146 if (strcmp(scale_type,
"LOG") == 0) {
1161 (VOIDP) & si_used[1]);
1165 if (qual_byt !=
NULL) {
1166 if ((sdsid = SDcreate(sdfid,
"l3m_qual", DFNT_UINT8,
rank, dim_sizes)) < 0) {
1167 printf(
"\nput_smi: SDcreate call to create %s is unsuccessful",
1172 if ((SDwritedata(sdsid,
start,
NULL, dim_sizes, (VOIDP) qual_byt)) < 0) {
1173 printf(
"\nput_smi: SDwritedata unsuccessful (qual_byt)\n");
1187 if ((DFPaddpal(l3m_path, (VOIDP) map_palette)) < 0) {
1188 fprintf(
stderr,
"put_smi: Error writing map_palette.\n");
1192 if ((pal_ref = DFPlastref()) > 0) {
1193 if ((DFANputlabel(l3m_path, DFTAG_IP8, pal_ref, (
char*)
"palette")) < 0) {
1194 printf(
"\nput_smi: Error writing palette label\n");