20 SC_10hz_records_val = 0;
32 int32_t spixl, int32_t epixl, int32_t iopt_extract) {
35 status = nc_create( l1_filename, NC_NETCDF4, &
ncid);
38 ifstream viirs_l1a_data_structure;
40 string dataStructureFile;
43 dataStructureFile.assign(
"$OCDATAROOT/viirs/j1/VIIRS_Level-1A_Data_Structure_J1.cdl");
44 else if ( this->
platform ==
"JPSS-2")
45 dataStructureFile.assign(
"$OCDATAROOT/viirs/j2/VIIRS_Level-1A_Data_Structure_J2.cdl");
47 dataStructureFile.assign(
"$OCDATAROOT/viirs/npp/VIIRS_Level-1A_Data_Structure.cdl");
50 viirs_l1a_data_structure.open( dataStructureFile.c_str(), ifstream::in);
51 if ( viirs_l1a_data_structure.fail() ==
true) {
52 cout <<
"\"" << dataStructureFile.c_str() <<
"\" not found" << endl;
58 getline( viirs_l1a_data_structure,
line);
59 size_t pos =
line.find(
"dimensions:");
65 int32_t numScans = escan - sscan + 1;
67 getline( viirs_l1a_data_structure,
line);
69 if (
pos == string::npos)
break;
72 istringstream iss(
line.substr(
pos+2, string::npos));
77 iss >> skipws >>
line;
82 if (
line.compare(
"number_of_scans") == 0 && numScans > 0) {
87 if ((
line.compare(
"SC_records") == 0 ||
88 line.compare(
"SC_1hz_records") == 0)
90 dimSize = (int32_t) (numScans*1.78 + 0.5) + 20;
92 SC_records_val = dimSize;
95 if (
line.compare(
"SC_10hz_records") == 0 && numScans > 0) {
98 SC_10hz_records_val = dimSize;
107 if ( spixl != 0 || epixl != 3199) {
108 if (
line.compare(
"Mband_pixels") == 0) {
109 dimSize = epixl - spixl + 1;
110 }
else if (
line.compare(
"Iband_pixels") == 0) {
111 dimSize = 2*(epixl - spixl + 1);
112 }
else if (
line.compare(
"Mband_samples") == 0) {
115 }
else if ( spixl > 639 && spixl <= 1007) {
116 dimSize = 640 + 2*(spixl - 640);
117 }
else if ( spixl > 1007 && spixl <= 2191) {
118 dimSize = 1376 + 3*(spixl - 1008);
119 }
else if ( spixl > 2191 && spixl <= 2559) {
120 dimSize = 4928 + 2*(spixl - 2192);
121 }
else if ( spixl > 2559) {
122 dimSize = 5664 + (spixl - 2560);
128 }
else if ( epixl > 639 && epixl <= 1007) {
129 epixl0 = 641 + 2*(epixl - 640);
130 }
else if ( epixl > 1007 && epixl <= 2191) {
131 epixl0 = 1378 + 3*(epixl - 1008);
132 }
else if ( epixl > 2191 && epixl <= 2559) {
133 epixl0 = 4929 + 2*(epixl - 2192);
134 }
else if ( epixl > 2559) {
135 epixl0 = 5664 + (epixl - 2560);
137 dimSize = epixl0 - dimSize + 1;
141 status = nc_def_dim(
ncid,
line.c_str(), dimSize, &dimid[ndims++]);
147 getline( viirs_l1a_data_structure,
line);
148 size_t pos =
line.find(
"// global attributes");
149 if (
pos == 0)
break;
153 getline( viirs_l1a_data_structure,
line);
155 if (
pos == string::npos)
break;
160 attValue.assign(
line.substr(
pos+4));
161 size_t posQuote = attValue.find(
"\"");
162 attValue.assign(attValue.substr(0, posQuote));
164 istringstream iss(
line.substr(
pos+2));
167 iss >> skipws >>
line;
170 if (
line.compare(
"//") == 0)
continue;
173 attName.assign(
line.substr(1).c_str());
176 if (attName.compare(
"orbit_number") == 0)
continue;
177 if (attName.compare(
"history") == 0)
continue;
178 if (attName.compare(
"format_version") == 0)
continue;
179 if (attName.compare(
"instrument_number") == 0)
continue;
180 if (attName.compare(
"pixel_offset") == 0)
continue;
181 if (attName.compare(
"number_of_filled_scans") == 0)
continue;
185 status = nc_put_att_text(
ncid, NC_GLOBAL, attName.c_str(),
186 strlen(attValue.c_str()), attValue.c_str());
194 getline( viirs_l1a_data_structure,
line);
198 if (
line.substr(0,1).compare(
"}") == 0) {
199 viirs_l1a_data_structure.close();
204 size_t pos =
line.find(
"group:");
210 istringstream iss(
line.substr(6, string::npos));
211 iss >> skipws >>
line;
220 int varDims[NC_MAX_DIMS];
221 size_t dimSize[NC_MAX_DIMS];
222 char dimName[NC_MAX_NAME+1];
228 string flag_meanings;
231 double fill_value=0.0;
236 getline( viirs_l1a_data_structure,
line);
238 getline( viirs_l1a_data_structure,
line);
240 if (
line.length() == 0)
continue;
241 if (
line.substr(0,1).compare(
"\r") == 0)
continue;
242 if (
line.substr(0,1).compare(
"\n") == 0)
continue;
244 size_t found =
line.find(
"DNB");
245 if (found != string::npos && iopt_extract == 1) {
252 if (
pos == string::npos) {
257 sname.c_str(), lname.c_str(),
259 (
void *) &fill_value,
260 flag_values.c_str(), flag_meanings.c_str(),
263 flag_values.assign(
"");
264 flag_meanings.assign(
"");
272 if (
line.substr(0,10).compare(
"} // group") == 0)
break;
276 istringstream iss(
line);
277 iss >> skipws >> varType;
280 if ( varType.compare(
"char") == 0) ntype = NC_CHAR;
281 else if ( varType.compare(
"byte") == 0) ntype = NC_BYTE;
282 else if ( varType.compare(
"short") == 0) ntype = NC_SHORT;
283 else if ( varType.compare(
"int") == 0) ntype = NC_INT;
284 else if ( varType.compare(
"long") == 0) ntype = NC_INT;
285 else if ( varType.compare(
"float") == 0) ntype = NC_FLOAT;
286 else if ( varType.compare(
"real") == 0) ntype = NC_FLOAT;
287 else if ( varType.compare(
"double") == 0) ntype = NC_DOUBLE;
288 else if ( varType.compare(
"ubyte") == 0) ntype = NC_UBYTE;
289 else if ( varType.compare(
"ushort") == 0) ntype = NC_USHORT;
290 else if ( varType.compare(
"uint") == 0) ntype = NC_UINT;
291 else if ( varType.compare(
"int64") == 0) ntype = NC_INT64;
292 else if ( varType.compare(
"uint64") == 0) ntype = NC_UINT64;
296 size_t posSname =
line.substr(0,
pos).rfind(
" ");
297 sname.assign(
line.substr(posSname+1,
pos-posSname-1));
303 for (
int i=0;
i<numDims;
i++) {
304 nc_inq_dim(
ncid, varDims[
i], dimName, &dimSize[
i]);
311 size_t posEql =
line.find(
"=");
312 size_t pos1qte =
line.find(
"\"");
313 size_t pos2qte =
line.substr(pos1qte+1, string::npos).find(
"\"");
319 if (
attrName.compare(
"long_name") == 0) {
320 lname.assign(
line.substr(pos1qte+1, pos2qte));
325 else if (
attrName.compare(
"units") == 0) {
326 units.assign(
line.substr(pos1qte+1, pos2qte));
331 else if (
attrName.compare(
"_FillValue") == 0) {
333 iss.str(
line.substr(posEql+1, string::npos));
339 else if (
attrName.compare(
"flag_values") == 0) {
340 flag_values.assign(
line.substr(pos1qte+1, pos2qte));
344 else if (
attrName.compare(
"flag_meanings") == 0) {
345 flag_meanings.assign(
line.substr(pos1qte+1, pos2qte));
349 else if (
attrName.compare(
"valid_min") == 0) {
351 iss.str(
line.substr(posEql+1, string::npos));
357 else if (
attrName.compare(
"valid_max") == 0) {
359 iss.str(
line.substr(posEql+1, string::npos));
375 this ->
createl1( l1_filename, (int32_t) 0, numScans-1,
376 (int32_t) 0, (int32_t) 3199, (int32_t) 0);
383 size_t dimSize, curPos=0;
384 char dimName[NC_MAX_NAME+1];
389 size_t pos = dimString.find(
",", curPos);
390 if (
pos == string::npos)
391 pos = dimString.find(
")");
394 istringstream iss(dimString.substr(curPos,
pos-curPos));
395 iss >> skipws >> varDimName;
397 for (
int i=0;
i<ndims;
i++) {
398 int status = nc_inq_dim(
ncid, dimid[
i], dimName, &dimSize);
400 printf(
"-E - failed to retrieve dim: %s\n",dimName);
402 if ( varDimName.compare(dimName) == 0) {
403 varDims[(*numDims)++] = dimid[
i];
407 if ( dimString.substr(
pos, 1).compare(
")") == 0)
break;
417 uint16_t (*mbands)[16][6304],
418 uint16_t (*ibands)[32][6400],
419 uint16_t (*dnb)[16][4064],
422 uint8_t (*dqfl)[16]) {
425 int status = nc_inq_grp_ncid(
ncid,
"earth_view_data", &groupid);
428 size_t start[3]={(size_t)isc, 0, 0};
429 size_t count[3]={1, 0, 0};
432 for (
int i=0;
i<=15;
i++) {
434 if (
i < 5 or
i == 6 or
i == 12)
count[2] = 6304;
438 for (
int j=0;
j<16;
j++) {
439 if ( mqfl[
i][
j] >= 64) {
447 varstr <<
"EV_M" << setfill(
'0') << setw(2) <<
i+1;
450 status = nc_inq_varid( groupid, varstr.str().c_str(), &varid);
454 for (
int j=0;
j<16;
j++) {
458 (
const short int*) &mbands[
i][
j][0]);
467 for (
int i=0;
i<=4;
i++) {
472 for (
int j=0;
j<32;
j++) {
473 if ( iqfl[
i][
j] >= 64) {
482 varstr <<
"EV_I" << setfill(
'0') << setw(2) <<
i+1;
486 status = nc_inq_varid( groupid, varstr.str().c_str(), &varid);
493 (
const short int*) &ibands[
i][0][0]);
498 for (
int j=0;
j<16;
j++) {
502 (
const short int*) &ibands[
i][
j][0]);
514 else if (
platform.compare(
"JPSS-1") == 0)
516 else if (
platform.compare(
"JPSS-2") == 0)
519 for (
int i=0;
i<nDNB;
i++) {
525 for (
int j=0;
j<16;
j++) {
526 if ( dqfl[
i][
j] >= 64) {
535 string dnb_tag[5]={
"HGS",
"MGS",
"LGS",
"HGA",
"HGB"};
536 varstr <<
"EV_DNB_" << dnb_tag[
i];
540 status = nc_inq_varid( groupid, varstr.str().c_str(), &varid);
547 (
const short int*) &dnb[
i][0][0]);
552 for (
int j=0;
j<16;
j++) {
556 (
const short int*) &dnb[
i][
j][0]);
569 uint8_t (*hrmets)[146*26],
570 uint8_t (*calmets)[134],
571 uint8_t *
mode,
int iret,
572 const char* l1a_name,
573 char* VIIRS_packet_file) {
575 cout <<
"Writing scan-level metadata" << endl;
577 static char initial_L0_time[32] =
"9999";
578 static char final_L0_time[32] =
"0000";
579 static int32_t total_isc = 0;
580 static int total_iret = 0;
586 strcpy( buf, (
char *) l1a_name);
588 char *last_dot = strrchr( buf,
'.');
590 last_dot = buf + strlen(buf);
593 strcpy( last_dot,
".txt");
598 fout <<
"basename=" <<
basename(buf) << endl;
601 int status = nc_inq_grp_ncid(
ncid,
"scan_line_attributes", &groupid);
605 double *scs =
new double[isc];
606 double *sce =
new double[isc];
607 int16_t *scsd =
new int16_t[isc];
608 int32_t *scsm =
new int32_t[isc];
609 int16_t *scsu =
new int16_t[isc];
610 int16_t *sced =
new int16_t[isc];
611 int32_t *scem =
new int32_t[isc];
612 int16_t *sceu =
new int16_t[isc];
617 for (
int i=0;
i<isc;
i++) {
621 double stime, ptime, etime;
640 double dsec = (
double) stime;
644 fout <<
"start_time=" << datebuf << endl;
645 if ( strcmp( datebuf, initial_L0_time) < 0)
646 strcpy( initial_L0_time, datebuf);
652 double dsec = (
double) stime;
656 fout <<
"stop_time=" << datebuf << endl;
657 if ( strcmp( datebuf, final_L0_time) > 0)
658 strcpy( final_L0_time, datebuf);
661 memcpy( &ui16, (uint16_t *) &
p1[
i][6], 2);
664 memcpy( &ui32, (uint32_t *) &
p1[
i][8], 4);
667 memcpy( &ui16, (uint16_t *) &
p1[
i][12], 2);
670 memcpy( &ui16, (uint16_t *) &
p1[
i][38], 2);
673 memcpy( &ui32, (uint32_t *) &
p1[
i][40], 4);
676 memcpy( &ui16, (uint16_t *) &
p1[
i][44], 2);
681 size_t start[3]={0, 0, 0};
683 count[0] = (size_t) isc;
688 status = nc_inq_varid( groupid,
"scan_start_time", &varid);
694 status = nc_inq_varid( groupid,
"scan_end_time", &varid);
702 status = nc_inq_varid( groupid,
"scan_start_CCSDS_day", &varid);
708 status = nc_inq_varid( groupid,
"scan_start_CCSDS_msec", &varid);
713 status = nc_inq_varid( groupid,
"scan_start_CCSDS_usec", &varid);
721 status = nc_inq_varid( groupid,
"scan_end_CCSDS_day", &varid);
727 status = nc_inq_varid( groupid,
"scan_end_CCSDS_msec", &varid);
732 status = nc_inq_varid( groupid,
"scan_end_CCSDS_usec", &varid);
739 uint8_t *ham =
new uint8_t[isc];
740 for (
int i=0;
i<isc;
i++) ham[
i] = (
p1[
i][32] & 128) / 128;
744 uint32_t *scnum =
new uint32_t[isc];
745 for (
int i=0;
i<isc;
i++) {
746 memcpy( &ui32, (uint32_t *) &
p1[
i][34], 4);
750 status = nc_inq_varid( groupid,
"HAM_side", &varid);
755 status = nc_inq_varid( groupid,
"VIIRS_scan_number", &varid);
760 status = nc_inq_varid( groupid,
"sensor_mode", &varid);
766 status = nc_inq_varid( groupid,
"HR_metadata", &varid);
769 (uint8_t *) &hrmets[0][0]);
773 status = nc_inq_varid( groupid,
"cal_metadata", &varid);
776 (uint8_t *) &calmets[0][0]);
781 status = nc_inq_grp_ncid(
ncid,
"onboard_calibration_data", &groupid);
784 uint8_t *dnb_seq = (uint8_t *) calloc( isc,
sizeof(uint8_t));
785 for (
int i=0;
i<isc;
i++) {
786 dnb_seq[
i] = (calmets[
i][0] % 4)*16 + calmets[
i][1]/16;
789 status = nc_inq_varid( groupid,
"DNB_sequence", &varid);
792 (uint8_t *) dnb_seq);
809 fout <<
"number_of_records=" << isc << endl;
810 fout <<
"quality_flag=" << iret << endl;
813 strcpy( buf, (
char *) VIIRS_packet_file);
814 last_dot = strrchr( buf,
'.');
816 last_dot = buf + strlen(buf);
819 strcpy( last_dot,
".txt");
823 strcat( buf,
".PDS");
824 fout <<
"basename=" <<
basename(buf) << endl;
825 fout <<
"start_time=" << initial_L0_time << endl;
826 fout <<
"stop_time=" << final_L0_time << endl;
827 fout <<
"number_of_records=" << total_isc << endl;
828 fout <<
"quality_flag=" << total_iret << endl;
837 cout <<
"Writing engineering data" << endl;
840 int status = nc_inq_grp_ncid(
ncid,
"engineering_data", &groupid);
843 string engdataName[] = {
"engineering_status",
849 "analog_temperature",
853 int engdataOffset[] = {52, 60, 188, 316, 444, 3516, 3644, 3772, 9188};
858 size_t start[2]={0, 0};
859 size_t count[2]={1, 0};
862 bool *empty =
new bool[isc];
863 for (
int j=0;
j<isc;
j++) {
864 uint8_t non_zero = 0;
865 for (
int i=0;
i<9318;
i++) {
866 if ( engdata[
j][
i] != 0) {
877 for (
int i=0;
i<9;
i++) {
879 status = nc_inq_varid( groupid, engdataName[
i].c_str(), &varid);
885 status = nc_inq_dimlen( groupid, dimids[1], &
count[1]);
888 for (
int j=0;
j<isc;
j++) {
891 (uint8_t *) &engdata[
j][engdataOffset[
i]]);
896 uint16_t encoder_data[1290];
899 string encoderName[] = {
"tel_encoder",
"HAM_encoder"};
900 int encoderOffset[] = {4028, 4028+2580};
902 for (
int i=0;
i<2;
i++) {
903 status = nc_inq_varid( groupid, encoderName[
i].c_str(), &varid);
906 for (
int j=0;
j<isc;
j++) {
909 for (
size_t k=0;
k<
count[1];
k++) {
911 engdata[
j][encoderOffset[
i]+2*
k]*256 +
912 engdata[
j][encoderOffset[
i]+2*
k+1];
915 if ( empty[
j]) encoder_data[
k] = USHRT_MAX;
919 (uint16_t *) encoder_data);
924 int16_t *i16_buffer = (int16_t *) calloc( isc,
sizeof(int16_t));
926 string start_deltaName[] = {
"tel_start_enc",
928 "scan_encoder_delta"};
930 int start_deltaOffset[] = {9188, 9188+2, 60+11};
933 size_t isc_size_t = isc;
935 for (
int i=0;
i<3;
i++) {
936 status = nc_inq_varid( groupid, start_deltaName[
i].c_str(), &varid);
939 for (
int j=0;
j<isc;
j++) {
941 engdata[
j][start_deltaOffset[
i]]*256 +
942 engdata[
j][start_deltaOffset[
i]+1];
947 if (i16_buffer[
j] >= 8192) i16_buffer[
j] -= 16384;
951 if ( strcmp( start_deltaName[
i].c_str(),
"scan_encoder_delta") == 0)
952 i16_buffer[
j] = -32768;
954 i16_buffer[
j] = -999;
957 status = nc_put_vara( groupid, varid, &zero, &isc_size_t,
958 (int16_t *) i16_buffer);
966 uint8_t *ui8_buffer = (uint8_t *) calloc( isc,
sizeof(uint8_t));
968 string seName[] = {
"se_a_teleHAM_scansyn",
969 "se_b_teleHAM_scansyn",
973 "se_a_tele_pos_known",
974 "se_b_tele_pos_known",
976 "se_b_mtrs_stopped"};
978 int seOffset[] = {52+1, 52+1, 60+9, 60+9, 60+8, 60+9, 60+9, 60+9, 60+9};
980 uint8_t andFac[] = {2, 1, 128, 8, 16, 16, 1, 32, 2};
982 for (
int i=0;
i<9;
i++) {
983 status = nc_inq_varid( groupid, seName[
i].c_str(), &varid);
986 for (
int j=0;
j<isc;
j++) {
987 ui8_buffer[
j] = (engdata[
j][seOffset[
i]] & andFac[
i]) / andFac[
i];
990 if ( empty[
j]) ui8_buffer[
j] = 255;
993 status = nc_put_vara( groupid, varid, &zero, &isc_size_t,
994 (uint8_t *) ui8_buffer);
1006 int16_t (*sd_m)[48*16],
1007 int16_t (*sv_m)[48*16],
1008 int16_t (*bb_m)[48*16],
1009 int16_t (*sd_i)[96*32],
1010 int16_t (*sv_i)[96*32],
1011 int16_t (*bb_i)[96*32],
1012 int16_t (*sd_d)[64*16],
1013 int16_t (*sv_d)[64*16],
1014 int16_t (*bb_d)[64*16]) {
1016 cout <<
"Writing calibration data" << endl;
1019 int status = nc_inq_grp_ncid(
ncid,
"onboard_calibration_data", &groupid);
1027 status = nc_inq_varid( groupid,
"SD_M", &varid);
1029 status = nc_put_var( groupid, varid, (int16_t *) sd_m);
1033 status = nc_inq_varid( groupid,
"SV_M", &varid);
1035 status = nc_put_var( groupid, varid, (int16_t *) sv_m);
1039 status = nc_inq_varid( groupid,
"BB_M", &varid);
1041 status = nc_put_var( groupid, varid, (int16_t *) bb_m);
1048 status = nc_inq_varid( groupid,
"SD_I", &varid);
1050 status = nc_put_var( groupid, varid, (int16_t *) sd_i);
1054 status = nc_inq_varid( groupid,
"SV_I", &varid);
1056 status = nc_put_var( groupid, varid, (int16_t *) sv_i);
1060 status = nc_inq_varid( groupid,
"BB_I", &varid);
1062 status = nc_put_var( groupid, varid, (int16_t *) bb_i);
1069 status = nc_inq_varid( groupid,
"SD_DNB", &varid);
1071 status = nc_put_var( groupid, varid, (int16_t *) sd_d);
1075 status = nc_inq_varid( groupid,
"SV_DNB", &varid);
1077 status = nc_put_var( groupid, varid, (int16_t *) sv_d);
1081 status = nc_inq_varid( groupid,
"BB_DNB", &varid);
1083 status = nc_put_var( groupid, varid, (int16_t *) bb_d);
1091 int32_t ltime, int32_t
mtime,
1092 int32_t iyrsc, int32_t idysc, int32_t nscd,
1093 double *otime,
float (*orb)[6],
1094 double *atime,
float (*quat)[4],
1095 char *sdir,
char *edir) {
1098 int status = nc_inq_grp_ncid(
ncid,
"navigation_data", &groupid);
1102 size_t start[2]={0, 0};
1103 size_t count[2]={1, 0};
1107 int16_t iyr16 = (int16_t) iyear;
1108 int16_t idy16 = (int16_t) iday;
1109 int16_t iyrsc16 = (int16_t) iyrsc;
1110 int16_t idysc16 = (int16_t) idysc;
1111 int32_t jdg =
jday( iyr16, 1, idy16);
1112 int32_t jds =
jday( iyrsc16, 1, idysc16);
1114 uint8_t *
k =
new uint8_t[nscd];
1116 int32_t first=-1, last=-1;
1117 for (
int i=0;
i<nscd;
i++) {
1118 double otm = otime[
i] + (jds - jdg)*86400;
1120 if ( otm > (ltime-10) && otm < (
mtime+10)) {
1123 if ( first == -1) first =
i;
1129 cout << nk <<
" orbit vectors in time range" << endl;
1133 cout <<
"Writing orbit data" << endl;
1134 status = nc_inq_varid( groupid,
"orb_time", &varid);
1138 for (
int i=0;
i<nscd;
i++) {
1142 tai =
yds2tai93( iyrsc16, idysc16, otime[
i]);
1146 if (
status != NC_NOERR) {
1158 status = nc_inq_varid( groupid,
"orb_pos", &varid);
1162 for (
int i=0;
i<nscd;
i++) {
1174 status = nc_inq_varid( groupid,
"orb_vel", &varid);
1178 for (
int i=0;
i<nscd;
i++) {
1193 if ( orb[first][5] > 0.0) {
1194 strcpy( sdir,
"Ascending");
1196 strcpy( sdir,
"Descending");
1201 if ( orb[last][5] > 0.0) {
1202 strcpy( edir,
"Ascending");
1204 strcpy( edir,
"Descending");
1210 for (
int i=0;
i<nscd;
i++) {
1211 double atm = atime[
i] + (jds - jdg)*86400;
1212 if ( atm > (ltime-10) && atm < (
mtime+10)) {
1219 cout << nk <<
" attitude quaternions in time range" << endl;
1223 cout <<
"Writing attitude data" << endl;
1224 status = nc_inq_varid( groupid,
"att_time", &varid);
1228 for (
int i=0;
i<nscd;
i++) {
1232 tai =
yds2tai93( iyrsc16, idysc16, atime[
i]);
1236 if (
status != NC_NOERR) {
1247 status = nc_inq_varid( groupid,
"att_quat", &varid);
1251 for (
int i=0;
i<nscd;
i++) {
1271 int32_t ltime, int32_t
mtime,
1272 int32_t iyrad, int32_t idyad,
1273 int32_t nadc, int32_t nbus, int32_t ngps,
1274 double *adctime, uint8_t *admandone,
1276 double *bustime, uint8_t *adstate,
1277 uint8_t *adsolution,
1281 uint8_t *gpspkts[]) {
1284 int status = nc_inq_grp_ncid(
ncid,
"navigation_data", &groupid);
1288 size_t start[2]={0, 0};
1289 size_t count[2]={1, 0};
1293 int16_t iyr16 = (int16_t) iyear;
1294 int16_t idy16 = (int16_t) iday;
1295 int16_t iyrad16 = (int16_t) iyrad;
1296 int16_t idyad16 = (int16_t) idyad;
1297 int32_t jdg =
jday( iyr16, 1, idy16);
1298 int32_t jds =
jday( iyrad16, 1, idyad16);
1301 k =
new uint8_t[nadc];
1305 for (
int i=0;
i<nadc;
i++) {
1306 double atm = adctime[
i] + (jds - jdg)*86400;
1308 if ( atm > (ltime-10) && atm < (
mtime+10)) {
1309 if ( (atm - prevtime) < 0.01) {
1310 cout <<
"Removing short adc period record: "
1311 <<
i <<
" " << fixed << setprecision(4)
1312 << atm <<
" " << prevtime << endl;
1319 if ( first == -1) first =
i;
1321 if ( this->platform ==
"JPSS-2") {
1322 if ( nk > SC_10hz_records_val) {
1323 nk = SC_10hz_records_val;
1327 if ( nk > SC_records_val) {
1328 nk = SC_records_val;
1338 cout << nk <<
" adc records in time range" << endl;
1340 uint32_t SC_rec_val;
1343 cout <<
"Writing adc data" << endl;
1344 if ( this->platform ==
"JPSS-2") {
1345 status = nc_inq_varid( groupid,
"ADCS_10Hz_time", &varid);
1346 SC_rec_val = SC_10hz_records_val;
1348 status = nc_inq_varid( groupid,
"adcs_time", &varid);
1349 SC_rec_val = SC_records_val;
1354 for (
int i=0;
i<nadc;
i++) {
1355 if (
k[
i] == 1 && cnt < SC_rec_val) {
1358 tai =
yds2tai93( iyrad16, idyad16, adctime[
i]);
1362 if (
status != NC_NOERR) {
1374 status = nc_inq_varid( groupid,
"admandone", &varid);
1378 for (
int i=0;
i<nadc;
i++) {
1379 if (
k[
i] == 1 && cnt < SC_rec_val) {
1389 status = nc_inq_varid( groupid,
"adfftid", &varid);
1393 for (
int i=0;
i<nadc;
i++) {
1394 if (
k[
i] == 1 && cnt < SC_rec_val) {
1405 if ( this->platform ==
"JPSS-2")
1406 status = nc_inq_varid( groupid,
"ADCS_10Hz_tlm", &varid);
1408 status = nc_inq_varid( groupid,
"ADCS_tlm", &varid);
1412 for (
int i=0;
i<nadc;
i++) {
1413 if (
k[
i] == 1 && cnt < SC_rec_val) {
1416 status = nc_put_vara( groupid, varid,
start,
count, &adcpkts[
i][14]);
1427 k =
new uint8_t[nbus];
1431 for (
int i=0;
i<nbus;
i++) {
1432 double btm = bustime[
i] + (jds - jdg)*86400;
1434 if ( btm > (ltime-10) && btm < (
mtime+10)) {
1435 if ( (btm - prevtime) < 0.01) {
1436 cout <<
"Removing short bus period record: "
1437 <<
i <<
" " << fixed << setprecision(4)
1438 << btm <<
" " << prevtime << endl;
1445 if ( first == -1) first =
i;
1447 if ( nk > SC_records_val) {
1448 nk = SC_records_val;
1457 cout << nk <<
" bus records in time range" << endl;
1460 cout <<
"Writing bus data" << endl;
1461 if ( this->platform ==
"JPSS-2")
1462 status = nc_inq_varid( groupid,
"ADCS_1Hz_time", &varid);
1464 status = nc_inq_varid( groupid,
"bus_time", &varid);
1468 for (
int i=0;
i<nbus;
i++) {
1469 if (
k[
i] == 1 && cnt < SC_records_val) {
1472 tai =
yds2tai93( iyrad16, idyad16, bustime[
i]);
1476 if (
status != NC_NOERR) {
1488 status = nc_inq_varid( groupid,
"adstate", &varid);
1492 for (
int i=0;
i<nbus;
i++) {
1493 if (
k[
i] == 1 && cnt < SC_records_val) {
1504 status = nc_inq_varid( groupid,
"adsolution", &varid);
1508 for (
int i=0;
i<nbus;
i++) {
1509 if (
k[
i] == 1 && cnt < SC_records_val) {
1520 if ( this->platform ==
"JPSS-2")
1521 status = nc_inq_varid( groupid,
"ADCS_1Hz_tlm", &varid);
1523 status = nc_inq_varid( groupid,
"bus_critical_tlm", &varid);
1527 for (
int i=0;
i<nbus;
i++) {
1528 if (
k[
i] == 1 && cnt < SC_records_val) {
1531 status = nc_put_vara( groupid, varid,
start,
count, &buspkts[
i][14]);
1542 if ( this->platform ==
"JPSS-2") {
1544 k =
new uint8_t[ngps];
1548 for (
int i=0;
i<ngps;
i++) {
1549 double gtm = gpstime[
i] + (jds - jdg)*86400;
1551 if ( gtm > (ltime-10) && gtm < (
mtime+10)) {
1552 if ( (gtm - prevtime) < 0.01) {
1553 cout <<
"Removing short gps period record: "
1554 <<
i <<
" " << fixed << setprecision(4)
1555 << gtm <<
" " << prevtime << endl;
1562 if ( first == -1) first =
i;
1564 if ( nk > SC_records_val) {
1565 nk = SC_records_val;
1574 cout << nk <<
" gps records in time range" << endl;
1577 cout <<
"Writing gps data" << endl;
1578 status = nc_inq_varid( groupid,
"GPS_time", &varid);
1582 for (
int i=0;
i<ngps;
i++) {
1583 if (
k[
i] == 1 && cnt < SC_records_val) {
1586 tai =
yds2tai93( iyrad16, idyad16, gpstime[
i]);
1590 if (
status != NC_NOERR) {
1599 status = nc_inq_varid( groupid,
"GPS_tlm", &varid);
1603 for (
int i=0;
i<ngps;
i++) {
1604 if (
k[
i] == 1 && cnt < SC_records_val) {
1607 status = nc_put_vara( groupid, varid,
start,
count, &gpspkts[
i][14]);
1620 int32_t ltime, int32_t
mtime,
1622 const char* l1a_name,
1623 char *sdir,
char *edir,
1625 int32_t isc, uint8_t *
mode,
1626 int argc,
char *argv[],
1634 stringstream timestr, datestr;
1636 status = nc_put_att_int(
ncid, NC_GLOBAL,
"orbit_number", NC_INT,
1642 for (
int i=1;
i<argc;
i++) {
1644 strcat( buf, argv[
i]);
1646 status = nc_put_att_text(
ncid, NC_GLOBAL,
"history", strlen(buf), buf);
1650 uint8_t fmtver =
p1[28];
1651 uint8_t insnum =
p1[29];
1653 status = nc_put_att_uchar(
ncid, NC_GLOBAL,
"format_version", NC_BYTE,
1657 status = nc_put_att_uchar(
ncid, NC_GLOBAL,
"instrument_number", NC_BYTE,
1665 double dsec = (
double) ltime;
1669 status = nc_put_att_text(
ncid, NC_GLOBAL,
"time_coverage_start",
1677 if ( dsec >= 86400) {
1697 status = nc_put_att_text(
ncid, NC_GLOBAL,
"time_coverage_end",
1702 status = nc_put_att_text(
ncid, NC_GLOBAL,
"date_created", strlen(buf), buf);
1706 status = nc_put_att_text(
ncid, NC_GLOBAL,
"startDirection", strlen(buf), buf);
1710 status = nc_put_att_text(
ncid, NC_GLOBAL,
"endDirection", strlen(buf), buf);
1715 int32_t nday=0, nngt=0;
1716 for (
int i=0;
i<isc;
i++) {
1717 if (
mode[
i] == 4) nday++;
1718 if (
mode[
i] == 5) nngt++;
1720 if ( nday == isc)
strcpy( buf,
"Day");
1721 else if ( nngt == isc)
strcpy( buf,
"Night");
1722 else if ( (nday + nngt) == isc)
strcpy( buf,
"Mixed");
1723 else strcpy( buf,
"Other");
1724 status = nc_put_att_text(
ncid, NC_GLOBAL,
"day_night_flag", strlen(buf), buf);
1729 status = nc_put_att_int(
ncid, NC_GLOBAL,
"number_of_filled_scans",
1734 if(doi && (strlen(doi) > 0)) {
1735 status = nc_put_att_text(
ncid, NC_GLOBAL,
"identifier_product_doi_authority",
1736 strlen(
"http://dx.doi.org"),
"http://dx.doi.org");
1739 status = nc_put_att_text(
ncid, NC_GLOBAL,
"identifier_product_doi",
1753 status = nc_open(l1_filename, NC_NOWRITE, &this->
ncid);
1760 status = nc_inq_attlen(
ncid, NC_GLOBAL,
"platform", &t_len);
1764 platform = (
char *) malloc(t_len + 1);
1774 for (
int i = 0;
i < ndims;
i++) {
1776 nc_inq_dimname(
ncid,
i, dimname);
1777 if (strcmp(dimname,
"SC_records") == 0) {
1779 nc_inq_dimlen(
ncid,
i, &dimlen);
1780 SC_records_val = dimlen;
1789 int32_t sscan, int32_t escan,
1790 int32_t spixl, int32_t epixl) {
1794 ifstream viirs_l1a_data_structure;
1796 string dataStructureFile;
1798 if ( this->platform ==
"JPSS-1")
1799 dataStructureFile.assign(
"$OCDATAROOT/viirs/j1/VIIRS_Level-1A_Data_Structure_J1.cdl");
1801 dataStructureFile.assign(
"$OCDATAROOT/viirs/npp/VIIRS_Level-1A_Data_Structure.cdl");
1804 viirs_l1a_data_structure.open( dataStructureFile.c_str(), ifstream::in);
1805 if ( viirs_l1a_data_structure.fail() ==
true) {
1806 cout <<
"\"" << dataStructureFile.c_str() <<
"\" not found" << endl;
1810 size_t start[4],
count[4], ofile_start[4]={0,0,0,0};
1816 getline( viirs_l1a_data_structure,
line);
1817 size_t pos =
line.find(
"dimensions:");
1818 if (
pos == 0)
break;
1822 getline( viirs_l1a_data_structure,
line);
1823 size_t pos =
line.find(
" = ");
1824 if (
pos == string::npos)
break;
1831 getline( viirs_l1a_data_structure,
line);
1835 if (
line.substr(0,1).compare(
"}") == 0) {
1836 viirs_l1a_data_structure.close();
1841 size_t pos =
line.find(
"group:");
1847 int varDims[NC_MAX_DIMS];
1848 size_t dimSize[NC_MAX_DIMS];
1849 char dimName[NC_MAX_NAME+1];
1852 char *buffer =
NULL;
1855 getline( viirs_l1a_data_structure,
line);
1857 getline( viirs_l1a_data_structure,
line);
1859 if (
line.length() == 0)
continue;
1860 if (
line.substr(0,1).compare(
"\r") == 0)
continue;
1861 if (
line.substr(0,1).compare(
"\n") == 0)
continue;
1863 size_t found =
line.find(
"DNB");
1864 if (found != string::npos) {
1871 if (
pos == string::npos) {
1876 status = nc_get_vara(
gid[ngrps], varid,
1880 if ( sname.compare(
"scan_start_time") == 0) {
1884 cout << scan_end_time << endl;
1888 status = nc_inq_varid( l1_ofile->
gid[ngrps],
1889 sname.c_str(), &ofile_varid);
1892 status = nc_put_vara( l1_ofile->
gid[ngrps], ofile_varid,
1893 ofile_start,
count, (
void *) buffer);
1900 if (
line.substr(0,10).compare(
"} // group") == 0)
break;
1904 size_t posSname =
line.substr(0,
pos).rfind(
" ");
1905 sname.assign(
line.substr(posSname+1,
pos-posSname-1));
1906 cout <<
"Extracting: " << sname.c_str() << endl;
1913 for (
int i=0;
i<numDims;
i++) {
1914 nc_inq_dim(
ncid, varDims[
i], dimName, &dimSize[
i]);
1915 if ( strcmp(dimName,
"number_of_scans") == 0) {
1917 count[
i] = escan - sscan + 1;
1918 }
else if ( strcmp(dimName,
"SC_records") == 0) {
1919 if ( strcmp(sname.c_str(),
"att_time") == 0) {
1920 double *
time =
new double[dimSize[
i]];
1921 status = nc_inq_varid(
gid[ngrps], sname.c_str(), &varid);
1931 for (uint32_t
j=0;
j<dimSize[
i];
j++) {
1933 time[
j] < scan_end_time+10) {
1940 printf(
"-E- %s %d: could not find starting record for att_time.\n",
1941 __FILE__, __LINE__);
1945 if (
count[
i] == l1_ofile->SC_records_val+1)
1946 count[
i] = l1_ofile->SC_records_val;
1948 if (
count[
i] > l1_ofile->SC_records_val) {
1949 cout <<
"Insufficient allocation for extracted SC_records dimension" << endl;
1951 "Allocated: " << l1_ofile->SC_records_val <<
1952 " Required: " <<
count[
i] << endl;
1954 cout <<
"Changing 'Required' to 'Allocated'" << endl;
1955 count[
i] = l1_ofile->SC_records_val;
1959 }
else if ( strcmp(dimName,
"Mband_pixels") == 0) {
1962 count[
i] = epixl - spixl + 1;
1963 }
else if ( strcmp(dimName,
"Iband_pixels") == 0) {
1966 count[
i] = 2*(epixl - spixl + 1);
1967 }
else if ( strcmp(dimName,
"Mband_samples") == 0) {
1983 }
else if ( spixl > 639 && spixl <= 1007) {
1984 start[
i] = 640 + 2*(spixl - 640);
1985 }
else if ( spixl > 1007 && spixl <= 2191) {
1986 start[
i] = 1376 + 3*(spixl - 1008);
1987 }
else if ( spixl > 2191 && spixl <= 2559) {
1988 start[
i] = 4928 + 2*(spixl - 2192);
1989 }
else if ( spixl > 2559) {
1990 start[
i] = 5664 + (spixl - 2560);
1993 if ( epixl <= 639) {
1995 }
else if ( epixl > 639 && epixl <= 1007) {
1996 count[
i] = 641 + 2*(epixl - 640);
1997 }
else if ( epixl > 1007 && epixl <= 2191) {
1998 count[
i] = 1378 + 3*(epixl - 1008);
1999 }
else if ( epixl > 2191 && epixl <= 2559) {
2000 count[
i] = 4929 + 2*(epixl - 2192);
2001 }
else if ( epixl > 2559) {
2002 count[
i] = 5664 + (epixl - 2560);
2014 status = nc_inq_varid(
gid[ngrps], sname.c_str(), &varid);
2025 buffer = (
char *) calloc( bufcnt, typesz);
2036 size_t attlen, typesz;
2038 char name[NC_MAX_NAME], databuf[1024];
2045 << (spixl+1) <<
" " << (epixl+1) <<
" "
2046 << (sscan+1) <<
" " << (escan+1) <<
" "
2049 for (
int i=0;
i<ngatts;
i++) {
2055 if ( strcmp(
name,
"product_name") == 0) {
2057 attlen = strlen(databuf);
2060 if ( strcmp(
name,
"history") == 0) {
2062 attlen = strlen(databuf);
2065 if ( strcmp(
name,
"time_coverage_start") == 0) {
2067 uint32_t int_scan_start_time =
2069 double sec = (
double) (int_scan_start_time % 86400);
2072 sscanf ( databuf,
"%hu-%hu-%hu%*s", &
iyr, &
imn, &
idy);
2079 if ( strcmp(
name,
"time_coverage_end") == 0) {
2081 uint32_t int_scan_end_time =
2082 (uint32_t) (scan_end_time - nleap + 0.5);
2083 double sec = (
double) (int_scan_end_time % 86400);
2086 sscanf ( databuf,
"%hu-%hu-%hu%*s", &
iyr, &
imn, &
idy);
2093 if ( strcmp(
name,
"date_created") == 0) {
2097 if ( strcmp(
name,
"number_of_filled_scans") == 0) {
2098 int32_t filled_scans = escan - sscan + 1;
2099 memcpy( databuf, &filled_scans,
sizeof(int32_t));
2102 status = nc_put_att( l1_ofile->
ncid, NC_GLOBAL,
2106 printf(
"-E - nc_put_att failed for ncid: %i\n",
ncid);
2111 if (spixl != 0 || epixl != 3199) {
2114 status = nc_put_att_int( l1_ofile->
ncid, NC_GLOBAL,
"extract_pixel_start",
2117 status = nc_put_att_int( l1_ofile->
ncid, NC_GLOBAL,
"extract_pixel_stop",
2132 printf(
"-E - nc_close failed for ncid: %i\n",
ncid);
2140 const char *flag_values,
const char *flag_meanings,
2141 double low,
double high,
int nt,
2142 int rank,
int *dimids) {
2147 size_t chunksize[3];
2150 status = nc_def_var(ncid, sname, nt,
rank, dimids, &varid);
2151 if(
status != NC_NOERR) {
2152 printf(
"-E- %s %d: %s for %s\n",
2153 __FILE__, __LINE__, nc_strerror(
status), sname);
2158 double fill_value_dbl;
2159 memcpy( &fill_value_dbl, fill_value,
sizeof(
double));
2168 if ( low != fill_value_dbl) {
2169 if ( nt == NC_BYTE) {
2170 i8 = fill_value_dbl;
2171 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i8);
2172 }
else if ( nt == NC_UBYTE) {
2173 ui8 = fill_value_dbl;
2174 status = nc_def_var_fill( ncid, varid, 0, (
void *) &ui8);
2175 }
else if ( nt == NC_SHORT) {
2176 i16 = fill_value_dbl;
2177 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i16);
2178 }
else if ( nt == NC_INT) {
2179 i32 = fill_value_dbl;
2180 status = nc_def_var_fill( ncid, varid, 0, (
void *) &i32);
2181 }
else if ( nt == NC_FLOAT) {
2182 f32 = fill_value_dbl;
2183 status = nc_def_var_fill( ncid, varid, 0, (
void *) &
f32);
2185 status = nc_def_var_fill( ncid, varid, 0, (
void *) &fill_value_dbl);
2192 if (
rank == 3 && (strncmp(sname,
"EV_", 3) == 0)) {
2193 status = nc_inq_dimlen(ncid, dimids[2], &dimlength);
2196 chunksize[2] = dimlength/10;
2203 status = nc_def_var_chunking(ncid, varid, NC_CHUNKED, chunksize);
2204 if (
status != NC_NOERR) {
2205 printf(
"-E- %s %d: %s for %s\n", __FILE__, __LINE__,
2206 nc_strerror(
status), sname);
2212 status = nc_def_var_deflate(ncid, varid, NC_SHUFFLE, 1, 5);
2213 if (
status != NC_NOERR) {
2214 printf(
"-E- %s %d: %s for %s\n", __FILE__, __LINE__,
2215 nc_strerror(
status), sname);
2222 status = nc_put_att_text(ncid, varid,
"long_name", strlen(lname), lname);
2223 if(
status != NC_NOERR) {
2224 printf(
"-E- %s %d: %s for %s\n",
2225 __FILE__, __LINE__, nc_strerror(
status),
"long_name");
2231 if ( strcmp( flag_values,
"") != 0) {
2236 fv.assign( flag_values);
2237 size_t pos = fv.find(
"=", curPos);
2238 fv = fv.substr(
pos+1);
2240 size_t semicln = fv.find(
";");
2245 while(
pos != semicln) {
2246 pos = fv.find(
",", curPos);
2247 if (
pos == string::npos)
2251 istringstream iss(fv.substr(curPos,
pos-curPos));
2252 iss >> skipws >> flag_value;
2253 vec[n++] = atoi( flag_value.c_str());
2257 status = nc_put_att_schar(ncid, varid,
"flag_values", NC_BYTE, n, vec);
2258 if(
status != NC_NOERR) {
2259 printf(
"-E- %s %d: %s for %s\n",
2260 __FILE__, __LINE__, nc_strerror(
status),
"flag_values");
2266 if ( strcmp( flag_meanings,
"") != 0) {
2267 status = nc_put_att_text(ncid, varid,
"flag_meanings",
2268 strlen(flag_meanings), flag_meanings);
2269 if(
status != NC_NOERR) {
2270 printf(
"-E- %s %d: %s for %s\n",
2271 __FILE__, __LINE__, nc_strerror(
status),
"flag_meanings");
2282 vr[0] = (uint8_t)low;
2283 vr[1] = (uint8_t)high;
2284 status = nc_put_att_uchar(ncid, varid,
"valid_min",NC_BYTE,1,&vr[0]);
2285 if(
status != NC_NOERR) {
2286 printf(
"-E- %s %d: %s for %s\n",
2287 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2290 status = nc_put_att_uchar(ncid, varid,
"valid_max",NC_BYTE,1,&vr[1]);
2291 if(
status != NC_NOERR) {
2292 printf(
"-E- %s %d: %s for %s\n",
2293 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2301 vr[0] = (uint8_t)low;
2302 vr[1] = (uint8_t)high;
2303 status = nc_put_att_uchar(ncid, varid,
"valid_min",NC_UBYTE,1,&vr[0]);
2304 if(
status != NC_NOERR) {
2305 printf(
"-E- %s %d: %s for %s\n",
2306 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2309 status = nc_put_att_uchar(ncid, varid,
"valid_max",NC_UBYTE,1,&vr[1]);
2310 if(
status != NC_NOERR) {
2311 printf(
"-E- %s %d: %s for %s\n",
2312 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2320 vr[0] = (int16_t)low;
2321 vr[1] = (int16_t)high;
2322 status = nc_put_att_short(ncid, varid,
"valid_min",NC_SHORT,1,&vr[0]);
2323 if(
status != NC_NOERR) {
2324 printf(
"-E- %s %d: %s for %s\n",
2325 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2328 status = nc_put_att_short(ncid, varid,
"valid_max",NC_SHORT,1,&vr[1]);
2329 if(
status != NC_NOERR) {
2330 printf(
"-E- %s %d: %s for %s\n",
2331 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2339 vr[0] = (uint16_t)low;
2340 vr[1] = (uint16_t)high;
2341 status = nc_put_att_ushort(ncid, varid,
"valid_min",NC_USHORT,1,&vr[0]);
2342 if(
status != NC_NOERR) {
2343 printf(
"-E- %s %d: %s for %s\n",
2344 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2347 status = nc_put_att_ushort(ncid, varid,
"valid_max",NC_USHORT,1,&vr[1]);
2348 if(
status != NC_NOERR) {
2349 printf(
"-E- %s %d: %s for %s\n",
2350 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2358 vr[0] = (int32_t)low;
2359 vr[1] = (int32_t)high;
2360 status = nc_put_att_int(ncid, varid,
"valid_min",NC_INT,1,&vr[0]);
2361 if(
status != NC_NOERR) {
2362 printf(
"-E- %s %d: %s for %s\n",
2363 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2366 status = nc_put_att_int(ncid, varid,
"valid_max",NC_INT,1,&vr[1]);
2367 if(
status != NC_NOERR) {
2368 printf(
"-E- %s %d: %s for %s\n",
2369 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2378 vr[1] = (
float)high;
2379 status = nc_put_att_float(ncid, varid,
"valid_min",NC_FLOAT,1,&vr[0]);
2380 if(
status != NC_NOERR) {
2381 printf(
"-E- %s %d: %s for %s\n",
2382 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2385 status = nc_put_att_float(ncid, varid,
"valid_max",NC_FLOAT,1,&vr[1]);
2386 if(
status != NC_NOERR) {
2387 printf(
"-E- %s %d: %s for %s\n",
2388 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2398 status = nc_put_att_double(ncid, varid,
"valid_min",NC_DOUBLE,1,&vr[0]);
2399 if(
status != NC_NOERR) {
2400 printf(
"-E- %s %d: %s for %s\n",
2401 __FILE__, __LINE__, nc_strerror(
status),
"valid_min");
2404 status = nc_put_att_double(ncid, varid,
"valid_max",NC_DOUBLE,1,&vr[1]);
2405 if(
status != NC_NOERR) {
2406 printf(
"-E- %s %d: %s for %s\n",
2407 __FILE__, __LINE__, nc_strerror(
status),
"valid_max");
2413 fprintf(
stderr,
"-E- %s line %d: ",__FILE__,__LINE__);
2414 fprintf(
stderr,
"Got unsupported number type (%d) ",nt);
2415 fprintf(
stderr,
"while trying to create NCDF variable, \"%s\", ",sname);
2423 if(
status != NC_NOERR) {
2424 printf(
"-E- %s %d: %s for %s\n",
2425 __FILE__, __LINE__, nc_strerror(
status),
"units");
2432 status = nc_put_att_text(ncid, varid,
"standard_name",
2434 if(
status != NC_NOERR) {
2435 printf(
"-E- %s %d: %s for %s\n",
2436 __FILE__, __LINE__, nc_strerror(
status),
"standard_name");
2454 int32_t jdleap[17] = {2444787, 2445152, 2445517, 2446248,
2455 2447162, 2447893, 2448258, 2448805,
2456 2449170, 2449535, 2450084, 2450631,
2457 2451180, 2453737, 2454833, 2456110,
2461 for (
int i=0;
i<17;
i++) {
2462 if (
jday >= jdleap[
i]) cnt++;