NASA Logo
Ocean Color Science Software

ocssw V2022
copyvaratts.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include <iostream>
4 #include <netcdf>
5 
6 using namespace std;
7 using namespace netCDF;
8 using namespace netCDF::exceptions;
9 
10 int copyVarAtts( NcVar *varin, NcVar *varout, string override[],
11  string overridetype[]) {
12 
13  char buffer[1000];
14 
15  // Copy field attributes
16  map <string, NcVarAtt> attributes;
17  NcVarAtt vattr;
18  attributes = varin->getAtts();
19 
20  int k=0;
21  for (map<string, NcVarAtt>:: iterator it=attributes.begin();
22  it!=attributes.end(); ++it) {
23 
24  vattr = (*it).second;
25  NcType type = vattr.getType();
26  size_t attlen = vattr.getAttLength();
27 
28  // cout << (*it).first << " " << attlen << " "
29  // << type.getSize() << endl;
30  //if (override != NULL) cout << override[k].c_str() << endl;
31 
32  string attrname = (*it).first;;
33 
34  if (override == NULL || override[k].compare("=") == 0) {
35  vattr.getValues((void *) buffer);
36  } else if (override[k].compare("") == 0) {
37  k++;
38  continue;
39  } else {
40  //cout << override[k].c_str() << " " << overridetype[k].c_str() << endl;
41  if ( overridetype[k] == "B") {
42  int8_t temp = (uint8_t) stoi(override[k].c_str());
43  memcpy( buffer, &temp, 1);
44  } else if ( overridetype[k] == "F") {
45  float temp = stof(override[k].c_str());
46  memcpy( buffer, &temp, 4);
47  } else {
48  memcpy( buffer, override[k].c_str(), override[k].length());
49  }
50  }
51 
52  if (attrname.compare("_FillValue") == 0) {
53  varout->setFill(true, (void *) buffer);
54  } else {
55  if (override == NULL || override[k].compare("=") == 0)
56  varout->putAtt( attrname, type, attlen, buffer);
57  else if ( overridetype[k] == "F")
58  varout->putAtt( attrname, NC_FLOAT, attlen, buffer);
59  else
60  varout->putAtt( attrname, type, override[k].length(), buffer);
61  }
62 
63  k++;
64  }
65 
66  return 0;
67 }
68 
69 int copyVarAtts( NcVar *varin, NcVar *varout) {
70 
71  copyVarAtts( varin, varout, NULL, NULL);
72 
73  return 0;
74 }
75 
int copyVarAtts(NcVar *varin, NcVar *varout, string override[], string overridetype[])
Definition: copyvaratts.cpp:10
#define NULL
Definition: decode_rs.h:63
int k
Definition: decode_rs.h:73
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file attributes
Definition: HISTORY.txt:65