OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
read_pixel_anc_file.cpp
Go to the documentation of this file.
1 /*
2  * read a per pixel ancillary data file.
3  */
4 
5 #include <netcdf>
6 #include "read_pixel_anc_file.h"
7 
8 #include <vector>
9 
10 using namespace std;
11 using namespace netCDF;
12 using namespace netCDF::exceptions;
13 
14 // global variables
15 static bool firstRun = true;
16 NcFile *ncFile = nullptr;
22 NcVar ozoneVar;
25 //NcVar NO2Var;
26 
27 extern "C" void read_pixel_anc_file(char* filename, l1str *l1rec) {
28 
29  if(firstRun) {
30  firstRun = false;
31 
32  try {
33  printf("Loading Pixel Ancillary Data from %s\n", filename);
34  ncFile = new NcFile(filename, NcFile::read);
35  string title;
36  ncFile->getAtt("title").getValues(title);
37  if(title != "Pixel Ancillary Data") {
38  printf("-E- %s:%d - %s is not a per Pixel Ancillary Data file.\n",
39  __FILE__, __LINE__, filename);
40  exit(EXIT_FAILURE);
41  }
42 
43  if(ncFile->getDim("number_of_lines").getSize() != (size_t)l1rec->l1file->nscan) {
44  printf("-E- %s:%d - number_of_lines in %s, must be equal to number of line in the L1 file.\n",
45  __FILE__, __LINE__, filename);
46  exit(EXIT_FAILURE);
47  }
48  if(ncFile->getDim("pixels_per_line").getSize() != (size_t)l1rec->l1file->npix) {
49  printf("-E- %s:%d - pixels_per_line in %s, must be equal to number of pixels in the L1 file.\n",
50  __FILE__, __LINE__, filename);
51  exit(EXIT_FAILURE);
52  }
53 
54  windSpeedVar = ncFile->getVar("wind_speed");
55  windDirectionVar = ncFile->getVar("wind_direction");
56  windMeridionalVar = ncFile->getVar("wind_meridional");
57  windZonalVar = ncFile->getVar("wind_zonal");
58  surfacePressureVar = ncFile->getVar("surface_pressure");
59  ozoneVar = ncFile->getVar("ozone");
60  waterVaporVar = ncFile->getVar("water_vapor");
61  relativeHumidityVar = ncFile->getVar("relative_humidity");
62  //NO2Var = ncFile->getVar("NO2");
63 
64  } catch (NcException& e) {
65  printf("-E- %s:%d - Problem initializing pixel_anc_file %s\n", __FILE__, __LINE__, filename);
66  printf(" %s\n", e.what());
67  exit(EXIT_FAILURE);
68  }
69 
70  } // firstRun
71 
72 
73  try {
74  vector<size_t> start;
75  vector<size_t> count;
76  start.push_back(l1rec->iscan);
77  start.push_back(l1rec->l1file->spix);
78  count.push_back(1);
79  count.push_back(l1rec->npix);
80 
81  if(!windSpeedVar.isNull()) {
82  windSpeedVar.getVar(start, count, l1rec->ws);
83  }
84  if(!windDirectionVar.isNull()) {
85  windDirectionVar.getVar(start, count, l1rec->wd);
86  }
87  if(!windMeridionalVar.isNull()) {
88  windMeridionalVar.getVar(start, count, l1rec->mw);
89  }
90  if(!windZonalVar.isNull()) {
91  windZonalVar.getVar(start, count, l1rec->zw);
92  }
93  if(!surfacePressureVar.isNull()) {
94  surfacePressureVar.getVar(start, count, l1rec->pr);
95  }
96  if(!ozoneVar.isNull()) {
97  ozoneVar.getVar(start, count, l1rec->oz);
98  }
99  if(!waterVaporVar.isNull()) {
100  waterVaporVar.getVar(start, count, l1rec->wv);
101  }
102  if(!relativeHumidityVar.isNull()) {
103  relativeHumidityVar.getVar(start, count, l1rec->rh);
104  }
105 // if(!NO2Var.isNull()) {
106 // NO2Var.getVar(start, count, l1rec->no2_strat);
107 // }
108 
109  } catch (NcException& e) {
110  printf("-E- %s:%d - Problem reading pixel_anc_file %s\n", __FILE__, __LINE__, filename);
111  printf(" %s\n", e.what());
112  exit(EXIT_FAILURE);
113  }
114 
115 }
116 
NcVar relativeHumidityVar
read l1rec
NcVar windZonalVar
NcVar windMeridionalVar
NcVar surfacePressureVar
NcVar windDirectionVar
NcFile * ncFile
NcVar waterVaporVar
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
NcVar windSpeedVar
void read_pixel_anc_file(char *filename, l1str *l1rec)
NcVar ozoneVar
int count
Definition: decode_rs.h:79