Go to the documentation of this file.
4 using namespace netCDF;
5 using namespace netCDF::exceptions;
8 uint16_t& pcdim, uint16_t& psdim,
double& ev_toff,
9 float *clines,
float *slines,
double *deltc,
double *delts,
13 int16_t iz=0, line0=0;
15 while (
dtype[iz] == 0) {
19 if (iz == 10)
return 0;
24 int16_t linen = line0;
25 for (
size_t i=iz;
i<9;
i++) {
29 uint16_t np =
lines[
i] / iagg[
i];
30 for (
size_t j=0;
j<np;
j++) {
31 clines[pcdim+
j] = linen +
j*iagg[
i] + 0.5*iagg[
i] - 64;
34 uint16_t ns =
lines[
i] / 8;
35 for (
size_t j=0;
j<ns;
j++) {
36 slines[psdim+
j] = linen +
j*8 + 3.5;
45 for (
size_t i=0;
i<(size_t) pcdim;
i++) deltc[
i] = secpline * clines[
i];
46 ev_toff = 0.5 * (deltc[0] + deltc[pcdim-1]);
47 for (
size_t i=0;
i<(size_t) pcdim;
i++) deltc[
i] -= ev_toff;
49 for (
size_t i=0;
i<(size_t) psdim;
i++)
50 delts[
i] = secpline * slines[
i] - ev_toff;
57 double ev_toff, int32_t
spin,
float *slines,
double *delt,
58 double revpsec, int32_t ppr_off, int32_t *mspin,
59 int32_t *ot_10us, uint8_t *enc_count,
float **hamenc,
60 float **rtaenc,
float **pview,
double *theta, int16_t& iret) {
68 int32_t max_enc_cts = 131072;
70 constexpr
double pi = 3.14159265358979323846;
72 double rad2asec = (180/
pi) * 3600;
75 float pprang = 2 *
pi * (ppr_off - geoLUT.
rta_nadir) / max_enc_cts;
76 if (pprang >
pi) pprang -= 2*
pi;
79 double *toff =
new double[pdim];
80 for (
size_t i=0;
i<pdim;
i++) toff[
i] = delt[
i] + ev_toff;
82 for (
size_t i=0;
i<pdim;
i++)
83 theta[
i] = pprang + 2 *
pi * revpsec * toff[
i];
87 double *thetacor =
new double[pdim];
91 if ( mspin[
i] ==
spin) {
97 cout <<
"No MCE encoder data for spin: " <<
spin << endl;
104 for (
size_t j=0;
j<enc_count[isp];
j++) {
105 double tenc =
j*dtenc;
106 if ( tenc < toff[ip] && (tenc+dtenc) > toff[ip]) {
113 for (
size_t i=0;
i<pdim;
i++) {
114 if ( toff[
i] >= tenc_ke && toff[
i] < tenc_ke+dtenc) {
115 double ft = (toff[
i] - tenc_ke) / dtenc;
116 thetacor[
i] = (1-ft)*rtaenc[isp][ke] + ft*rtaenc[isp][ke+1];
125 for (
size_t i=0;
i<pdim;
i++) {
126 theta[
i] = theta[
i] + thetacor[
i] / rad2asec;
127 pview[
i][1] = sin(theta[
i]);
128 pview[
i][2] = cos(theta[
i]);
138 int createField( NcGroup &ncGrp,
const char *sname,
const char *lname,
140 void *fill_value,
const char *flag_values,
141 const char *flag_meanings,
142 double low,
double high,
int nt, vector<NcDim>& varVec) {
150 ncVar = ncGrp.addVar(sname, nt, varVec);
152 catch ( NcException& e) {
153 cout << e.what() << endl;
154 cerr <<
"Failure creating variable: " << sname << endl;
159 double fill_value_dbl;
160 memcpy( &fill_value_dbl, fill_value,
sizeof(
double));
170 if ( low != fill_value_dbl) {
171 if ( nt == NC_BYTE) {
173 ncVar.setFill(
true, (
void *) &i8);
174 }
else if ( nt == NC_UBYTE) {
175 ui8 = fill_value_dbl;
176 ncVar.setFill(
true, (
void *) &ui8);
177 }
else if ( nt == NC_SHORT) {
178 i16 = fill_value_dbl;
179 ncVar.setFill(
true, (
void *) &i16);
180 }
else if ( nt == NC_USHORT) {
181 ui16 = fill_value_dbl;
182 ncVar.setFill(
true, (
void *) &ui16);
183 }
else if ( nt == NC_INT) {
184 i32 = fill_value_dbl;
185 ncVar.setFill(
true, (
void *) &i32);
186 }
else if ( nt == NC_UINT) {
187 ui32 = fill_value_dbl;
188 ncVar.setFill(
true, (
void *) &ui32);
189 }
else if ( nt == NC_FLOAT) {
190 f32 = fill_value_dbl;
191 ncVar.setFill(
true, (
void *) &
f32);
193 ncVar.setFill(
true, (
void *) &fill_value_dbl);
199 vector<size_t> chunkVec;
200 if ( varVec.size() == 3 && (strncmp(sname,
"EV_", 3) == 0)) {
201 dimlength = varVec[2].getSize();
203 chunkVec.push_back(1);
204 chunkVec.push_back(16);
205 chunkVec.push_back(dimlength/10);
214 ncVar.setChunking(ncVar.nc_CHUNKED, chunkVec);
216 catch ( NcException& e) {
218 cerr <<
"Failure setting chunking: " << sname << endl;
223 ncVar.setCompression(
true,
true, 5);
225 catch ( NcException& e) {
227 cerr <<
"Failure setting compression: " << sname << endl;
235 ncVar.putAtt(
"long_name", lname);
237 catch ( NcException& e) {
239 cerr <<
"Failure creating 'long_name' attribute: " << lname << endl;
243 if ( strcmp( flag_values,
"") != 0) {
248 fv.assign( flag_values);
249 size_t pos = fv.find(
"=", curPos);
250 fv = fv.substr(
pos+1);
252 size_t semicln = fv.find(
";");
257 while(
pos != semicln) {
258 pos = fv.find(
",", curPos);
259 if (
pos == string::npos)
263 istringstream iss(fv.substr(curPos,
pos-curPos));
264 iss >> skipws >> flag_value;
265 vec[n++] = atoi( flag_value.c_str());
270 ncVar.putAtt(
"flag_values", NC_BYTE, n, vec);
272 catch ( NcException& e) {
274 cerr <<
"Failure creating 'flag_values' attribute: " << lname << endl;
280 if ( strcmp( flag_meanings,
"") != 0) {
283 ncVar.putAtt(
"flag_meanings", flag_meanings);
285 catch ( NcException& e) {
287 cerr <<
"Failure creating 'flag_meanings' attribute: "
288 << flag_meanings << endl;
299 vr[0] = (uint8_t)low;
300 vr[1] = (uint8_t)high;
303 ncVar.putAtt(
"valid_min", NC_BYTE, 1, &vr[0]);
305 catch ( NcException& e) {
307 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
312 ncVar.putAtt(
"valid_max", NC_BYTE, 1, &vr[1]);
314 catch ( NcException& e) {
316 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
324 vr[0] = (uint8_t)low;
325 vr[1] = (uint8_t)high;
328 ncVar.putAtt(
"valid_min", NC_UBYTE, 1, &vr[0]);
330 catch ( NcException& e) {
332 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
337 ncVar.putAtt(
"valid_max", NC_UBYTE, 1, &vr[1]);
339 catch ( NcException& e) {
341 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
349 vr[0] = (int16_t)low;
350 vr[1] = (int16_t)high;
353 ncVar.putAtt(
"valid_min", NC_SHORT, 1, &vr[0]);
355 catch ( NcException& e) {
357 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
362 ncVar.putAtt(
"valid_max", NC_SHORT, 1, &vr[1]);
364 catch ( NcException& e) {
366 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
374 vr[0] = (uint16_t)low;
375 vr[1] = (uint16_t)high;
378 ncVar.putAtt(
"valid_min", NC_USHORT, 1, &vr[0]);
380 catch ( NcException& e) {
382 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
387 ncVar.putAtt(
"valid_max", NC_USHORT, 1, &vr[1]);
389 catch ( NcException& e) {
391 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
399 vr[0] = (int32_t)low;
400 vr[1] = (int32_t)high;
403 ncVar.putAtt(
"valid_min", NC_INT, 1, &vr[0]);
405 catch ( NcException& e) {
407 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
412 ncVar.putAtt(
"valid_max", NC_INT, 1, &vr[1]);
414 catch ( NcException& e) {
416 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
425 vr[0] = (uint32_t)low;
426 vr[1] = (uint32_t)high;
429 ncVar.putAtt(
"valid_min", NC_UINT, 1, &vr[0]);
431 catch ( NcException& e) {
433 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
438 ncVar.putAtt(
"valid_max", NC_UINT, 1, &vr[1]);
440 catch ( NcException& e) {
442 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
455 ncVar.putAtt(
"valid_min", NC_FLOAT, 1, &vr[0]);
457 catch ( NcException& e) {
459 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
464 ncVar.putAtt(
"valid_max", NC_FLOAT, 1, &vr[1]);
466 catch ( NcException& e) {
468 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
480 ncVar.putAtt(
"valid_min", NC_DOUBLE, 1, &vr[0]);
482 catch ( NcException& e) {
484 cerr <<
"Failure creating 'valid_min' attribute: " << vr[0] << endl;
489 ncVar.putAtt(
"valid_max", NC_DOUBLE, 1, &vr[1]);
491 catch ( NcException& e) {
493 cerr <<
"Failure creating 'valid_max' attribute: " << vr[1] << endl;
499 fprintf(
stderr,
"-E- %s line %d: ",__FILE__,__LINE__);
500 fprintf(
stderr,
"Got unsupported number type (%d) ",nt);
501 fprintf(
stderr,
"while trying to create NCDF variable, \"%s\", ",sname);
510 ncVar.putAtt(
"units",
units);
512 catch ( NcException& e) {
514 cerr <<
"Failure creating 'units' attribute: " <<
units << endl;
522 ncVar.putAtt(
"standard_name",
units);
524 catch ( NcException& e) {
526 cerr <<
"Failure creating 'standard_name' attribute: "
void spin(double st, double *pos1, double *pos2)
int get_oci_vecs(uint32_t nscan, uint16_t pdim, geo_struct &geoLUT, double ev_toff, int32_t spin, float *slines, double *delt, double revpsec, int32_t ppr_off, int32_t *mspin, int32_t *ot_10us, uint8_t *enc_count, float **hamenc, float **rtaenc, float **pview, double *theta, int16_t &iret)
int get_ev(double secpline, int16_t *dtype, int16_t *lines, int16_t *iagg, uint16_t &pcdim, uint16_t &psdim, double &ev_toff, float *clines, float *slines, double *deltc, double *delts, int16_t &iret)
These two strings are used for the product XML output If product_id is not set then prefix is used If the last char of the name_prefix is _ then it is removed If algorithm_id is not set then name_suffix is used If the first char is _ then it is removed l2prod standard_name[0]
int createField(NcGroup &ncGrp, const char *sname, const char *lname, const char *standard_name, const char *units, void *fill_value, const char *flag_values, const char *flag_meanings, double low, double high, int nt, vector< NcDim > &varVec)