NASA Logo
Ocean Color Science Software

ocssw V2022
global_attrs.cpp
Go to the documentation of this file.
1 #include "global_attrs.h"
2 #include <ctime>
3 #include <netcdf>
4 #include "rapidjson/document.h"
5 #include "rapidjson/filereadstream.h"
6 #include <cstdio>
7 #include <iostream>
8 #include <libgen.h>
9 
10 using namespace std;
11 using namespace netCDF;
12 using namespace netCDF::exceptions;
13 using namespace rapidjson;
14 
15 string call_sequence(int argc, char* argv[]) {
16 
17  // get processing timestamp, to the second
18  time_t tnow = time(nullptr);
19  char prodtime[80];
20  strftime(prodtime, 80, "%Y-%m-%dT%XZ", gmtime(&tnow));
21 
22  // append calling sequence
23  string callseq = prodtime;
24  callseq.append(":");
25  for (int i=0; i<argc; i++) {
26  callseq.append(" ");
27  callseq.append(basename(argv[i]));
28  }
29  return callseq;
30 }
31 
32 string get_history(NcFile *ncfile) {
33  string history;
34  NcGroupAtt att = ncfile->getAtt("history");
35  if (!att.isNull()) att.getValues(history);
36  if (history.length() > 0) { history.append("; "); }
37  return history;
38 }
39 
41  string history,
42  string doi,
43  string pversion) {
44 
45  // read standard global attributes from JSON file
46  char *dataRoot;
47  if ((dataRoot = getenv("OCDATAROOT")) == NULL) {
48  printf("-E- OCDATAROOT environment variable is not defined.\n");
49  exit(EXIT_FAILURE);
50  }
51  string filename = (string) dataRoot + "/common/global_metadata.json";
52  char readBuffer[65536];
53  Document document;
54 
55  try {
56  FILE* fp = fopen((char*) filename.c_str(), "r");
57  if (fp == nullptr) {
58  cerr << "Error: reading " << filename << endl;
59  exit(EXIT_FAILURE);
60  }
61  FileReadStream is(fp, readBuffer, sizeof(readBuffer));
62  fclose(fp);
63  document.ParseStream(is);
64  }
65  catch (std::exception const & e) {
66  cerr << "Exception: " << e.what() << endl;
67  exit(EXIT_FAILURE);
68  }
69 
70  // set standard global attributes
71  for (Value::ConstMemberIterator itr = document.MemberBegin(); itr != document.MemberEnd(); ++itr)
72  outfile->putAtt(itr->name.GetString(), itr->value.GetString()); // fix for non-string attrs
73 
74  // set pversion info
75  if (!pversion.empty()) {
76  outfile->putAtt("processing_version", pversion);
77  }
78  // set doi info
79  if (!doi.empty()) {
80  outfile->putAtt("identifier_product_doi_authority", "https://dx.doi.org");
81  outfile->putAtt("identifier_product_doi", doi);
82  }
83  // set processing history
84  if (!history.empty()) {
85  outfile->putAtt("history", history);
86  }
87 
88  // set date_created
89  outfile->putAtt("date_created", unix2isodate(now(), 'G'));
90 
91 }
92 
94  string history,
95  string doi,
96  string pversion) {
97 
98  // open file for append
99  NcFile *outfile = new NcFile(filename, NcFile::write);
100 
101  // set attributes
102  set_global_attrs(outfile, history, doi, pversion);
103 
104  // close file
105  outfile->close();
106  delete(outfile);
107 }
#define NULL
Definition: decode_rs.h:63
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start thereby resolving MODur00108 Changed header guard macro names to avoid reserved name resolving MODur00104 Maneuver list file for Terra satellite was updated to include data from Jecue DuChateu Maneuver list files for both Terra and Aqua were updated to include two maneuvers from recent IOT weekly reports The limits for Z component of angular momentum was and to set the fourth GEO scan quality flag for a scan depending upon whether or not it occurred during one of them Added _FillValue attributes to many and changed the fill value for the sector start times from resolving MODur00072 Writes boundingcoordinate metadata to L1A archived metadata For PERCENT *ECS change to treat rather resolving GSFcd01518 Added a LogReport Changed to create the Average Temperatures vdata even if the number of scans is
Definition: HISTORY.txt:301
@ string
string get_history(NcFile *ncfile)
string call_sequence(int argc, char *argv[])
void set_global_attrs(NcFile *outfile, string history, string doi, string pversion)
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
string history
Definition: ncattredit.py:30
#define basename(s)
Definition: l0chunk_modis.c:29
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248
u5 which has been done in the LOCALGRANULEID metadata should have an extension NRT It is requested to identify the NRT production Changes from v6 which may affect scientific the sector rotation may actually occur during one of the scans earlier than the one where it is first reported As a the b1 values are about the LOCALGRANULEID metadata should have an extension NRT It is requested to identify the NRT to fill pixels affected by dead subframes with a special value Output the metadata of noisy and dead subframe Dead Subframe EV and Detector Quality Flag2 Removed the function call of Fill_Dead_Detector_SI to stop interpolating SI values for dead but also for all downstream products for science test only Changes from v5 which will affect scientific to conform to MODIS requirements Removed the Mixed option from the ScanType in the code because the L1A Scan Type is never Mixed Changed for ANSI C compliance and comments to better document the fact that when the HDF_EOS metadata is stricly the and products are off by and in the track respectively Corrected some misspelling of RCS swir_oob_sending_detector to the Reflective LUTs to enable the SWIR OOB correction detector so that if any of the sending detectors becomes noisy or non near by good detectors from the same sending band can be specified as the substitute in the new look up table Code change for adding an additional dimension of mirror side to the Band_21_b1 LUT to separate the coefficient of the two mirror sides for just like other thermal emissive so that the L1B code can calibrate Band scan to scan with mirror side dependency which leads better calibration result Changes which do not affect scientific when the EV data are not provided in this Crosstalk Correction will not be performed to the Band calibration data Changes which do not affect scientific and BB_500m in L1A Logic was added to turn off the or to spatial aggregation processes and the EV_250m_Aggr1km_RefSB and EV_500m_Aggr1km_RefSB fields were set to fill values when SDSs EV_250m and EV_500m are absent in L1A file Logic was added to skip the processing and turn off the output of the L1B QKM and HKM EV data when EV_250m and EV_500m are absent from L1A In this the new process avoids accessing and reading the and L1A EV skips and writing to the L1B and EV omits reading and subsampling SDSs from geolocation file and writing them to the L1B and omits writing metadata to L1B and EV and skips closing the L1A and L1B EV and SDSs Logic was added to turn off the L1B OBC output when the high resolution OBC SDSs are absent from L1A This is accomplished by skipping the openning the writing of metadata and the closing of the L1B OBC hdf which is Bit in the scan by scan bit QA has been changed Until now
Definition: HISTORY.txt:361
char * unix2isodate(double dtime, char zone)
Definition: unix2isodate.c:10
int i
Definition: decode_rs.h:71