6 #include <gsl/gsl_blas.h>
7 #include <gsl/gsl_linalg.h>
8 #include <gsl/gsl_matrix_double.h>
9 #include <boost/algorithm/string/trim.hpp>
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 #include <boost/numeric/ublas/matrix.hpp>
23 #define ERROR_EXIT(dim) {if(dim==0){printf("--Error--: the dimension %s is zero. Exiting. See line %d in file %s",#dim,__LINE__, __FILE__);exit(EXIT_FAILURE);} }
52 vector<vector<double>>& posj,
vector<vector<double>>& velj,
double l1aEpoch) {
54 ifstream inStream(ephfile, ios::in);
55 if (!inStream.is_open()) {
56 cerr <<
"-E- Unable to open definitive ephemeris file\n";
63 vector<double> posVec(3);
64 vector<double> velVec(3);
66 vector<string> tokens;
67 vector<double> secondsVec(1921);
70 while (inStream.peek() != EOF) {
71 getline(inStream, ephStr,
'\n');
73 istringstream lineStream(ephStr);
77 while (lineStream >>
token) {
78 tokens.push_back(
token);
81 if(tokens.size() != 7 || tokens[0].find(
"T") == string::npos) {
87 if(oldTime == theTime)
92 posVec.push_back(stod(tokens[1]));
93 posVec.push_back(stod(tokens[2]));
94 posVec.push_back(stod(tokens[3]));
97 velVec.push_back(stod(tokens[4]));
98 velVec.push_back(stod(tokens[5]));
99 velVec.push_back(stod(tokens[6]));
101 posj.push_back(posVec);
102 velj.push_back(velVec);
103 otime.push_back(theTime - l1aEpoch);
110 if (otime.size() == 0) {
111 cerr <<
"-E- No records found in definitive ephemeris file\n";
119 string l1b_filename,
string dem_file,
bool radiance,
120 string doi,
const string ephFile,
string pversion) {
125 NcFile *l1afile =
new NcFile( l1a_filename, NcFile::read);
129 ncGrps[0] = l1afile->getGroup(
"scan_line_attributes");
130 ncGrps[1] = l1afile->getGroup(
"spatial_spectral_modes");
131 ncGrps[2] = l1afile->getGroup(
"engineering_data");
132 ncGrps[3] = l1afile->getGroup(
"navigation_data");
133 ncGrps[4] = l1afile->getGroup(
"onboard_calibration_data");
134 ncGrps[5] = l1afile->getGroup(
"science_data");
145 att = l1afile->getAtt(
"time_coverage_start");
146 att.getValues(tstart);
148 att = l1afile->getAtt(
"time_coverage_end");
151 size_t pos = tstart.find(
"T");
152 if(
pos == string::npos) {
153 cout <<
"-E- L1A file time_coverage_start, bad format\n";
156 string granule_date = tstart.substr(0,
pos);
159 vector<vector<double>> ephPosVec;
161 vector<vector<double>> ephVelVec;
162 vector<double> ephOTime;
164 if (!ephFile.empty()) {
170 unix2ymds(l1a_start, &yr, &mo, &dy, &secs);
171 double l1a_epoch =
ymds2unix(yr, mo, dy, 0.0);
173 read_def_eph(ephFile, ephOTime, ephPosVec, ephVelVec, l1a_epoch);
176 if((l1a_start < (ephOTime.front() + l1a_epoch)) ||
177 (l1a_end > (ephOTime.back() + l1a_epoch))) {
178 cerr <<
"-E- Definitive ephemeris file does not cover L1A file time" << endl;
184 NcDim nscan_dim = l1afile->getDim(
"number_of_scans");
185 uint32_t
nscan = nscan_dim.getSize();
189 uint32_t nswband = l1afile->getDim(
"SWIR_bands").getSize();
191 NcDim mcescan_dim = l1afile->getDim(
"number_of_mce_scans");
192 uint32_t nmcescan = mcescan_dim.getSize();
194 double *sstime =
new double[
nscan];
195 var = ncGrps[0].getVar(
"scan_start_time");
199 var = ncGrps[0].getVar(
"spin_ID");
202 uint8_t *hside =
new uint8_t[
nscan];
203 var = ncGrps[0].getVar(
"HAM_side");
209 sstime[sdim] = sstime[
i];
210 hside[sdim] = hside[
i];
216 short *sfl =
new short[sdim]();
219 NcDim natt_dim = l1afile->getDim(
"att_records");
220 uint32_t n_att_rec = natt_dim.getSize();
223 double *att_time =
new double[n_att_rec];
224 var = ncGrps[3].getVar(
"att_time");
225 var.getVar( att_time);
227 NcDim nquat_dim = l1afile->getDim(
"quaternion_elements");
228 uint32_t n_quat_elems = nquat_dim.getSize();
231 float **att_quat =
new float *[n_att_rec];
232 att_quat[0] =
new float[n_quat_elems*n_att_rec];
233 for (
size_t i=1;
i<n_att_rec;
i++)
234 att_quat[
i] = att_quat[
i-1] + n_quat_elems;
236 var = ncGrps[3].getVar(
"att_quat");
237 var.getVar( &att_quat[0][0]);
239 NcDim norb_dim = l1afile->getDim(
"orb_records");
240 uint32_t n_orb_rec = norb_dim.getSize();
243 vector<double> orb_time(n_orb_rec);
244 if (ephFile.empty()) {
245 var = ncGrps[3].getVar(
"orb_time");
246 var.getVar( orb_time.data());
249 float **orb_pos =
new float *[n_orb_rec];
250 orb_pos[0] =
new float[3*n_orb_rec];
251 for (
size_t i=1;
i<n_orb_rec;
i++) orb_pos[
i] = orb_pos[
i-1] + 3;
252 var = ncGrps[3].getVar(
"orb_pos");
253 var.getVar( &orb_pos[0][0]);
255 float **orb_vel =
new float *[n_orb_rec];
256 orb_vel[0] =
new float[3*n_orb_rec];
257 for (
size_t i=1;
i<n_orb_rec;
i++) orb_vel[
i] = orb_vel[
i-1] + 3;
258 var = ncGrps[3].getVar(
"orb_vel");
259 var.getVar( &orb_vel[0][0]);
261 NcDim ntilt_dim = l1afile->getDim(
"tilt_samples");
262 uint32_t n_tilts = ntilt_dim.getSize();
265 float *tiltin =
new float[n_tilts];
266 var = ncGrps[3].getVar(
"tilt");
269 double *ttime =
new double[n_tilts];
270 var = ncGrps[3].getVar(
"tilt_time");
278 NcFile *geoLUTfile =
new NcFile( geo_lut_filename, NcFile::read);
281 NcGroup gidTime, gidCT, gidRTA_HAM, gidPlanarity;
283 gidTime = geoLUTfile->getGroup(
"time_params");
284 var = gidTime.getVar(
"master_clock");
286 var = gidTime.getVar(
"MCE_clock");
289 gidCT = geoLUTfile->getGroup(
"coord_trans");
290 var = gidCT.getVar(
"sc_to_tilt");
292 var = gidCT.getVar(
"tilt_axis");
294 var = gidCT.getVar(
"tilt_angles");
296 var = gidCT.getVar(
"tilt_home");
298 var = gidCT.getVar(
"tilt_to_oci_mech");
300 var = gidCT.getVar(
"oci_mech_to_oci_opt");
303 gidRTA_HAM = geoLUTfile->getGroup(
"RTA_HAM_params");
304 var = gidRTA_HAM.getVar(
"RTA_axis");
306 var = gidRTA_HAM.getVar(
"HAM_axis");
308 var = gidRTA_HAM.getVar(
"HAM_AT_angles");
310 var = gidRTA_HAM.getVar(
"HAM_CT_angles");
312 var = gidRTA_HAM.getVar(
"RTA_enc_scale");
314 var = gidRTA_HAM.getVar(
"HAM_enc_scale");
316 var = gidRTA_HAM.getVar(
"RTA_nadir");
319 gidPlanarity = geoLUTfile->getGroup(
"planarity");
320 var = gidPlanarity.getVar(
"along_scan_planarity");
322 var = gidPlanarity.getVar(
"along_track_planarity");
329 double revpsec, secpline;
331 int32_t *mspin =
new int32_t[nmcescan];
332 int32_t *ot_10us =
new int32_t[nmcescan];
333 uint8_t *enc_count =
new uint8_t[nmcescan];
336 NcDim nenc_dim = l1afile->getDim(
"encoder_samples");
337 uint32_t nenc = nenc_dim.getSize();
339 float **hamenc =
new float *[nmcescan];
340 hamenc[0] =
new float[nenc*nmcescan];
341 for (
size_t i=1;
i<nmcescan;
i++) hamenc[
i] = hamenc[
i-1] + nenc;
343 float **rtaenc =
new float *[nmcescan];
344 rtaenc[0] =
new float[nenc*nmcescan];
345 for (
size_t i=1;
i<nmcescan;
i++) rtaenc[
i] = rtaenc[
i-1] + nenc;
348 read_mce_tlm( l1afile, geoLUT, ncGrps[2], nmcescan, nenc, ppr_off, revpsec,
349 secpline, board_id, mspin, ot_10us, enc_count, hamenc, rtaenc,
361 if (!ephFile.empty()) {
363 size_t ephOTimeLBIndex = -1;
364 size_t ephOTimeUBIndex = -1;
366 for (
size_t i = 0;
i < ephOTime.size();
i++) {
367 double value = ephOTime[
i];
369 if (
value <= sstime[0]) {
379 double omega_e = 7.29211585494e-5;
380 size_t num_eph_recs = ephOTimeUBIndex - ephOTimeLBIndex + 1;
382 n_orb_rec = num_eph_recs;
389 orb_time.resize(n_orb_rec);
391 for (
size_t idxRec = 0; idxRec < num_eph_recs; idxRec++) {
392 size_t ephIndex = idxRec + ephOTimeLBIndex;
393 orb_time[idxRec] = ephOTime[ephIndex];
397 for (
size_t idxLine = 0; idxLine < 3; idxLine++) {
398 for (
size_t idxValue = 0; idxValue < 3; idxValue++) {
399 posr[idxRec][idxLine] += ecmat[idxLine][idxValue] * ephPosVec[ephIndex][idxValue];
400 velr[idxRec][idxLine] += ecmat[idxLine][idxValue] * ephVelVec[ephIndex][idxValue];
404 velr[idxRec][0] = velr[idxRec][0] + posr[idxRec][1] * omega_e;
405 velr[idxRec][1] = velr[idxRec][1] - posr[idxRec][0] * omega_e;
411 for (
size_t i = 0;
i < n_orb_rec;
i++) {
414 for (
size_t j = 0;
j < 3;
j++) {
415 posr[
i][
j] = orb_pos[
i][
j] / 1000;
416 velr[
i][
j] = orb_vel[
i][
j] / 1000;
423 for (
size_t i = 0;
i < n_att_rec;
i++) {
424 double ecq[4], qt2[4];
429 memcpy(qt1, &att_quat[
i][0], 3 *
sizeof(
float));
430 qt1[3] = att_quat[
i][3];
432 qprod(ecq, qt1, qt2);
433 for (
size_t j = 0;
j < 4;
j++) quatr[
i][
j] = qt2[
j];
439 NcDim spatzn_dim = l1afile->getDim(
"spatial_zones");
440 uint32_t spatzn = spatzn_dim.getSize();
442 int16_t *
dtype =
new int16_t[spatzn];
443 var = ncGrps[1].getVar(
"spatial_zone_data_type");
446 int16_t *
lines =
new int16_t[spatzn];
447 var = ncGrps[1].getVar(
"spatial_zone_lines");
450 int16_t *iagg =
new int16_t[spatzn];
451 var = ncGrps[1].getVar(
"spatial_aggregation");
454 float clines[32400], slines[4050];
455 uint16_t pcdim, psdim;
456 double ev_toff, deltc[32400], delts[4050];
459 clines, slines, deltc, delts, dark, iret);
461 cout <<
"No Earth view in file: " << l1a_filename << endl;
466 double *evtime =
new double[sdim];
467 for (
size_t i = 0;
i < sdim;
i++)
468 if (sstime[
i] == -32767) evtime[
i] = sstime[
i];
470 evtime[
i] = sstime[
i] + ev_toff;
476 orb_interp(n_orb_rec, sdim, orb_time.data(), posr, velr, evtime, posi, veli);
479 q_interp(n_att_rec, sdim, att_time, quatr, evtime, quati);
481 float *
tilt =
new float[sdim];
483 for (
size_t i = 0;
i < sdim;
i++)
485 for (
size_t i = 0;
i < sdim;
i++) {
496 float *
xlon =
new float[sdim * pcdim]();
497 float *
xlat =
new float[sdim * pcdim]();
498 short *
solz =
new short[sdim * pcdim]();
499 short *
sola =
new short[sdim * pcdim]();
500 short *
senz =
new short[sdim * pcdim]();
501 short *
sena =
new short[sdim * pcdim]();
503 uint8_t *qfl =
new uint8_t[sdim * pcdim]();
505 short *height =
new short[sdim * pcdim]();
508 for (
size_t i = 0;
i < sdim * pcdim;
i++) {
519 float **pview =
new float *[pcdim];
520 pview[0] =
new float[3*pcdim];
521 for (
size_t i=1;
i<pcdim;
i++) pview[
i] = pview[
i-1] + 3;
526 double *rs =
new double[sdim];
527 l_sun(sdim,
iyr, iday, evtime, sunr, rs);
528 double distcorr = pow(rs[sdim/2],2);
531 gsl_matrix *sc2tiltp = gsl_matrix_alloc(3, 3);
532 gsl_matrix *sc2ocim = gsl_matrix_alloc(3, 3);
533 gsl_matrix *sc_to_oci = gsl_matrix_alloc(3, 3);
534 gsl_matrix *smat = gsl_matrix_alloc(3, 3);
536 double *thetap =
new double[pcdim]();
541 float lonwest = +180;
542 float loneast = -180;
543 float latsouth = +90;
544 float latnorth = -90;
545 for (
size_t iscn = 0; iscn < sdim; iscn++) {
547 if (sstime[iscn] != -999.0) {
566 A = gsl_matrix_view_array( (
double *) geoLUT.
sc_to_tilt, 3, 3);
567 B = gsl_matrix_view_array( (
double *) tiltm, 3, 3);
568 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0,
569 &
A.matrix, &
B.matrix, 0.0, sc2tiltp);
570 ptr_C = gsl_matrix_ptr(sc2tiltp, 0, 0);
574 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0,
575 sc2tiltp, &
B.matrix, 0.0, sc2ocim);
576 ptr_C = gsl_matrix_ptr(sc2ocim, 0, 0);
580 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0,
581 sc2ocim, &
B.matrix, 0.0, sc_to_oci);
582 ptr_C = gsl_matrix_ptr(sc_to_oci, 0, 0);
587 qtom(quati[iscn], qmat);
590 B = gsl_matrix_view_array(&qmat[0][0], 3, 3);
591 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0,
592 sc_to_oci, &
B.matrix, 0.0, smat);
595 mat2rpy(posi[iscn], veli[iscn], qmat, rpy[iscn]);
598 ptr_C = gsl_matrix_ptr(smat, 0, 0);
600 scan_ell(posi[iscn], (
double(*)[3])ptr_C, coef);
605 ev_toff,
spin[iscn], hside[iscn], clines, deltc,
606 revpsec, ppr_off, board_id, nmcescan, mspin, enc_count,
607 &hamenc[0], &rtaenc[0], pview, thetap, iret);
612 size_t ip = iscn * pcdim;
613 oci_geonav(dem_file.c_str(), posi[iscn], veli[iscn], (
double(*)[3])ptr_C,
614 coef, sunr[iscn], pview, pcdim, delts, &
xlat[ip], &
xlon[ip],
616 lonwest, loneast, latsouth, latnorth);
621 gsl_matrix_free(smat);
622 gsl_matrix_free(sc2tiltp);
623 gsl_matrix_free(sc2ocim);
624 gsl_matrix_free(sc_to_oci);
630 NcDim ntaps_dim = l1afile->getDim(
"number_of_taps");
631 uint32_t ntaps = ntaps_dim.getSize();
633 int16_t *bagg =
new int16_t[ntaps];
634 var = ncGrps[1].getVar(
"blue_spectral_mode");
637 int16_t *ragg =
new int16_t[ntaps];
638 var = ncGrps[1].getVar(
"red_spectral_mode");
641 size_t *ia =
new size_t[ntaps];
650 outfile.createFile(l1b_filename.c_str(),
652 "$OCDATAROOT/oci/OCI_GEO_Level-1B_Data_Structure.cdl",
653 sdim, &geo_ncid, geo_gid, bbb, rbb,
654 pcdim, psdim, nswband, geoLUT.
rta_nadir, radiance);
683 count.push_back(sdim);
687 var =
outfile.ncGrps[1].getVar(
"time");
689 var.putAtt(
"units",
"seconds since " + granule_date);
691 var =
outfile.ncGrps[1].getVar(
"HAM_side");
694 var =
outfile.ncGrps[1].getVar(
"scan_quality_flags");
697 var =
outfile.ncGrps[3].getVar(
"tilt_angle");
702 var =
outfile.ncGrps[3].getVar(
"att_quat");
708 var =
outfile.ncGrps[3].getVar(
"att_ang");
711 var =
outfile.ncGrps[3].getVar(
"orb_pos");
714 var =
outfile.ncGrps[3].getVar(
"orb_vel");
717 var =
outfile.ncGrps[3].getVar(
"sun_ref");
721 count.push_back(pcdim);
723 var =
outfile.ncGrps[2].getVar(
"latitude");
726 var =
outfile.ncGrps[2].getVar(
"longitude");
729 var =
outfile.ncGrps[2].getVar(
"quality_flag");
732 var =
outfile.ncGrps[2].getVar(
"sensor_azimuth");
735 var =
outfile.ncGrps[2].getVar(
"sensor_zenith");
738 var =
outfile.ncGrps[2].getVar(
"solar_azimuth");
741 var =
outfile.ncGrps[2].getVar(
"solar_zenith");
747 var =
outfile.ncGrps[2].getVar(
"height");
753 outfile.geofile->putAtt(
"earth_sun_distance_correction",
754 NC_DOUBLE, 1, &distcorr);
756 outfile.geofile->putAtt(
"cdm_data_type",
"swath");
758 outfile.geofile->putAtt(
"geospatial_lat_min", NC_FLOAT, 1, &latsouth);
759 outfile.geofile->putAtt(
"geospatial_lat_max", NC_FLOAT, 1, &latnorth);
760 outfile.geofile->putAtt(
"geospatial_lon_min", NC_FLOAT, 1, &lonwest);
761 outfile.geofile->putAtt(
"geospatial_lon_max", NC_FLOAT, 1, &loneast);
763 outfile.geofile->putAtt(
"geospatial_bounds_crs",
"EPSG:4326");
790 delete[]pview[0];
delete[](pview);
793 delete [] hamenc[0];
delete [] hamenc;
794 delete [] rtaenc[0];
delete [] rtaenc;
802 delete []att_quat[0];
delete [](att_quat);
803 delete []orb_vel[0];
delete [](orb_vel);
804 delete []orb_pos[0];
delete[](orb_pos);
807 delete [](enc_count);
836 double xnut[3][3], ut1utc;
841 double day =
idy + (sec + ut1utc) / 86400;
842 double gha, gham[3][3];
845 gham[0][0] = cos(gha /
RADEG);
846 gham[1][1] = cos(gha /
RADEG);
848 gham[0][1] = sin(gha /
RADEG);
849 gham[1][0] = -sin(gha /
RADEG);
857 gsl_matrix_view
A = gsl_matrix_view_array(&gham[0][0], 3, 3);
858 gsl_matrix_view
B = gsl_matrix_view_array(&xnut[0][0], 3, 3);
859 gsl_matrix *
C = gsl_matrix_alloc(3, 3);
861 gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, &
A.matrix, &
B.matrix, 0.0,
C);
863 gsl_matrix_view D = gsl_matrix_view_array(&j2mod[0][0], 3, 3);
864 gsl_matrix *E = gsl_matrix_alloc(3, 3);
865 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0,
C, &D.matrix, 0.0, E);
866 double *ptr_E = gsl_matrix_ptr(E, 0, 0);
868 memcpy(ecmat, ptr_E, 9 *
sizeof(
double));
891 double t =
jday(iyear, 1, iday) - (
double)2451545.5 + sec / 86400;
894 double zeta0 =
t * (2306.2181 + 0.302 *
t + 0.018 *
t *
t) /
RADEG / 3600;
895 double thetap =
t * (2004.3109 - 0.4266 *
t - 0.04160 *
t *
t) /
RADEG / 3600;
896 double xip =
t * (2306.2181 + 1.095 *
t + 0.018 *
t *
t) /
RADEG / 3600;
898 j2mod[0][0] = -sin(zeta0) * sin(xip) + cos(zeta0) * cos(xip) * cos(thetap);
899 j2mod[0][1] = -cos(zeta0) * sin(xip) - sin(zeta0) * cos(xip) * cos(thetap);
900 j2mod[0][2] = -cos(xip) * sin(thetap);
901 j2mod[1][0] = sin(zeta0) * cos(xip) + cos(zeta0) * sin(xip) * cos(thetap);
902 j2mod[1][1] = cos(zeta0) * cos(xip) - sin(zeta0) * sin(xip) * cos(thetap);
903 j2mod[1][2] = -sin(xip) * sin(thetap);
904 j2mod[2][0] = cos(zeta0) * sin(thetap);
905 j2mod[2][1] = -sin(zeta0) * sin(thetap);
906 j2mod[2][2] = cos(thetap);
915 double t =
jday(iyear, 1, iday) - (
double)2451545.5;
917 double xls, gs, xlm,
omega;
950 xls = (
double)280.46592 + ((
double)0.9856473516) *
t;
951 xls = fmod(xls, (
double)360);
954 gs = (
double)357.52772 + ((
double)0.9856002831) *
t;
955 gs = fmod(gs, (
double)360);
958 xlm = (
double)218.31643 + ((
double)13.17639648) *
t;
959 xlm = fmod(xlm, (
double)360);
969 double &
dpsi,
double &
eps,
double &epsm) {
982 1.3187 * sin(2. * xls /
RADEG) + 0.1426 * sin(gs /
RADEG) -
983 0.2274 * sin(2. * xlm /
RADEG);
986 epsm = (
double)23.439291 - ((
double)3.560e-7) *
t;
989 double deps = 9.2025 * cos(
omega /
RADEG) + 0.5736 * cos(2. * xls /
RADEG);
992 eps = epsm + deps / 3600;
1000 int16_t iyear =
iyr;
1003 static int32_t ijd[25000];
1004 static double ut1[25000];
1005 string utcpole =
"$OCVARROOT/modis/utcpole.dat";
1006 static bool first =
true;
1013 ifstream utcpfile(
utcpole.c_str());
1014 if (utcpfile.is_open()) {
1015 getline(utcpfile,
line);
1016 getline(utcpfile,
line);
1017 while (getline(utcpfile,
line)) {
1019 istr.str(
line.substr(0, 5));
1022 istr.str(
line.substr(44, 9));
1030 cout <<
utcpole.c_str() <<
" not found" << endl;
1036 int mjd =
jday(iyear, 1, iday) - 2400000;
1037 while (ijd[
k] > 0) {
1038 if (mjd == ijd[
k]) {
1059 double fday =
day - iday;
1061 double t =
jd - (
double)2451545.5 + fday;
1064 double gmst = (
double)100.4606184 + (
double)0.9856473663 *
t +
1068 double xls, gs, xlm,
omega;
1075 gha = fmod(gha, (
double)360);
1080 int mtoq(
double rm[3][3],
double q[4]) {
1087 double cphi = (rm[0][0] + rm[1][1] + rm[2][2] - 1) / 2;
1091 double ssphi = (pow(rm[0][1] - rm[1][0], 2) +
1092 pow(rm[2][0] - rm[0][2], 2) +
1093 pow(rm[1][2] - rm[2][1], 2)) /
1095 phi = asin(sqrt(ssphi));
1096 if (
cphi < 0) phi =
PI - phi;
1100 e[0] = (rm[2][1] - rm[1][2]) / (sin(phi) * 2);
1101 e[1] = (rm[0][2] - rm[2][0]) / (sin(phi) * 2);
1102 e[2] = (rm[1][0] - rm[0][1]) / (sin(phi) * 2);
1103 double norm = sqrt(e[0] * e[0] + e[1] * e[1] + e[2] * e[2]);
1109 q[0] = e[0] * sin(phi / 2);
1110 q[1] = e[1] * sin(phi / 2);
1111 q[2] = e[2] * sin(phi / 2);
1112 q[3] = cos(phi / 2);
1117 int qprod(
double q1[4],
float q2[4],
double q3[4]) {
1120 q3[0] = q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1] + q1[3] * q2[0];
1121 q3[1] = -q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0] + q1[3] * q2[1];
1122 q3[2] = q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3] + q1[3] * q2[2];
1123 q3[3] = -q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2] + q1[3] * q2[3];
1128 int qprod(
float q1[4],
float q2[4],
float q3[4]) {
1131 q3[0] = q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1] + q1[3] * q2[0];
1132 q3[1] = -q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0] + q1[3] * q2[1];
1133 q3[2] = q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3] + q1[3] * q2[2];
1134 q3[3] = -q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2] + q1[3] * q2[3];
1170 double a0[3], a1[3], a2[3], a3[3];
1173 for (
int i=0;
i<3;
i++) {
1193 double startOrbTime = torb[0];
1194 double endOrbTime = torb[n_orb_rec-1];
1195 const double NAV_FILL = -9999999.0;
1198 for (
size_t i = 0;
i < sdim;
i++) {
1201 if (
time[
i] < startOrbTime ||
time[
i] > endOrbTime) {
1211 for (
size_t j = ind;
j < n_orb_rec;
j++) {
1219 double dt = torb[ind + 1] - torb[ind];
1220 for (
size_t j = 0;
j < 3;
j++) {
1222 a1[
j] =
v[ind][
j] * dt;
1224 a2[
j] = 3 *
p[ind + 1][
j] - 3 *
p[ind][
j] - 2 *
v[ind][
j] * dt -
1226 a3[
j] = 2 *
p[ind][
j] - 2 *
p[ind + 1][
j] +
v[ind][
j] * dt +
1229 a2[
j] = (
v[ind + 1][
j] -
v[ind][
j]) / 2;
1237 double x = (
time[
i] - torb[ind]) / dt;
1240 for (
size_t j = 0;
j < 3;
j++) {
1241 posi[
i][
j] = a0[
j] + a1[
j] *
x + a2[
j] * x2 + a3[
j] * x3;
1242 veli[
i][
j] = (a1[
j] + 2 * a2[
j] *
x + 3 * a3[
j] * x2) / dt;
1256 double startAttTime = tq[0];
1257 double endAttTime = tq[n_att_rec-1];
1258 const double NAV_FILL = -32767.0;
1260 for (
size_t i = 0;
i < sdim;
i++) {
1263 if (
time[
i] < startAttTime ||
time[
i] > endAttTime) {
1264 for (
int element=0; element<4; element++) {
1265 qi[
i][element] = NAV_FILL;
1272 for (
size_t j = ind;
j < n_att_rec;
j++) {
1280 double dt = tq[ind + 1] - tq[ind];
1282 qin[0] = -
q[ind][0];
1283 qin[1] = -
q[ind][1];
1284 qin[2] = -
q[ind][2];
1288 qprod(qin,
q[ind + 1], qr);
1289 memcpy(e, qr, 3 *
sizeof(
double));
1290 double sto2 = sqrt(e[0] * e[0] + e[1] * e[1] + e[2] * e[2]);
1291 for (
size_t j = 0;
j < 3;
j++) e[
j] /= sto2;
1294 double x = (
time[
i] - tq[ind]) / dt;
1295 float qri[4], qp[4];
1296 for (
size_t j = 0;
j < 3;
j++) qri[
j] = e[
j] * sto2 *
x;
1299 memcpy(qi[
i], qp, 4 *
sizeof(
float));
1306 int tilt_interp(
size_t n_tilts,
size_t sdim,
double *ttilt,
float *tiltin,
1309 double startTiltTime = ttilt[0];
1310 double endTiltTime = ttilt[n_tilts-1];
1311 const double NAV_FILL = -32767.0;
1314 for (
size_t i = 0;
i < sdim;
i++) {
1316 if (
time[
i] < startTiltTime ||
time[
i] > endTiltTime) {
1322 for (
size_t j = ind;
j < n_tilts;
j++) {
1329 double x = (
time[
i] - ttilt[ind])/(ttilt[ind+1] - ttilt[ind]);
1330 tilt[
i] = (1-
x)*tiltin[ind] +
x*tiltin[ind+1];
1337 int l_sun(
size_t sdim, int32_t
iyr, int32_t iday,
double *sec,
1346 for (
size_t i = 0;
i < sdim;
i++) {
1347 double day = iday + sec[
i] / 86400;
1350 double ghar = gha /
RADEG;
1353 float temp0 = sunr[
i][0] * cos(ghar) + sunr[
i][1] * sin(ghar);
1354 float temp1 = sunr[
i][1] * cos(ghar) - sunr[
i][0] * sin(ghar);
1371 float xk = 0.0056932;
1375 int16_t iyear =
iyr;
1378 for (
size_t i = 0;
i < sdim;
i++) {
1380 jday(iyear, 1, iday) - (
double)2451545.0 + (sec[
i] - 43200) / 86400;
1382 double xls, gs, xlm,
omega;
1392 double g2 = 50.40828 + 1.60213022 *
t;
1393 g2 = fmod(g2, (
double)360);
1396 double g4 = 19.38816 + 0.52402078 *
t;
1397 g4 = fmod(g4, (
double)360);
1400 double g5 = 20.35116 + 0.08309121 *
t;
1401 g5 = fmod(g5, (
double)360);
1405 = 1.00014 - 0.01671 * cos(gs /
RADEG) - 0.00014 * cos(2. * gs /
RADEG);
1408 double dls = (6893. - 4.6543463e-4 *
t) * sin(gs /
RADEG) +
1409 72. * sin(2. * gs /
RADEG) - 7. * cos((gs - g5) /
RADEG) +
1410 6. * sin((xlm - xls) /
RADEG) +
1411 5. * sin((4. * gs - 8. * g4 + 3. * g5) /
RADEG) -
1412 5. * cos((2. * gs - 2. * g2) /
RADEG) -
1413 4. * sin((gs - g2) /
RADEG) +
1414 4. * cos((4. * gs - 8. * g4 + 3. * g5) /
RADEG) +
1415 3. * sin((2. * gs - 2. * g2) /
RADEG) - 3. * sin(g5 /
RADEG) -
1416 3. * sin((2. * gs - 2. * g5) /
RADEG);
1418 double xlsg = xls + dls / 3600;
1422 double xlsa = xlsg +
dpsi - xk / rs[
i];
1425 sun[
i][0] = cos(xlsa /
RADEG);
1436 rm[0][0] =
q[0] *
q[0] -
q[1] *
q[1] -
q[2] *
q[2] +
q[3] *
q[3];
1437 rm[0][1] = 2 * (
q[0] *
q[1] +
q[2] *
q[3]);
1438 rm[0][2] = 2 * (
q[0] *
q[2] -
q[1] *
q[3]);
1439 rm[1][0] = 2 * (
q[0] *
q[1] -
q[2] *
q[3]);
1440 rm[1][1] = -
q[0] *
q[0] +
q[1] *
q[1] -
q[2] *
q[2] +
q[3] *
q[3];
1441 rm[1][2] = 2 * (
q[1] *
q[2] +
q[0] *
q[3]);
1442 rm[2][0] = 2 * (
q[0] *
q[2] +
q[1] *
q[3]);
1443 rm[2][1] = 2 * (
q[1] *
q[2] -
q[0] *
q[3]);
1444 rm[2][2] = -
q[0] *
q[0] -
q[1] *
q[1] +
q[2] *
q[2] +
q[3] *
q[3];
1449 int scan_ell(
float p[3],
double sm[3][3],
double coef[10]) {
1464 double re = 6378.137;
1465 double f = 1 / 298.257;
1466 double omf2 = (1 -
f) * (1 -
f);
1472 coef[0] = 1 + (
rd - 1) * sm[0][2] * sm[0][2];
1473 coef[1] = 1 + (
rd - 1) * sm[1][2] * sm[1][2];
1474 coef[2] = 1 + (
rd - 1) * sm[2][2] * sm[2][2];
1475 coef[3] = (
rd - 1) * sm[0][2] * sm[1][2] * 2;
1476 coef[4] = (
rd - 1) * sm[0][2] * sm[2][2] * 2;
1477 coef[5] = (
rd - 1) * sm[1][2] * sm[2][2] * 2;
1478 coef[6] = (sm[0][0] *
p[0] + sm[0][1] *
p[1] + sm[0][2] *
p[2] *
rd) * 2;
1479 coef[7] = (sm[1][0] *
p[0] + sm[1][1] *
p[1] + sm[1][2] *
p[2] *
rd) * 2;
1480 coef[8] = (sm[2][0] *
p[0] + sm[2][1] *
p[1] + sm[2][2] *
p[2] *
rd) * 2;
1481 coef[9] =
p[0] *
p[0] +
p[1] *
p[1] +
p[2] *
p[2] *
rd -
re *
re;
1487 double smat[3][3],
double coef[10],
float sunr[3],
1488 float **pview,
size_t npix,
double *delt,
float *
xlat,
1490 short *
senz,
short *
sena,
short *height,
1491 float& lonwest,
float& loneast,
float& latsouth,
float& latnorth)
1550 float f = 1 / 298.257;
1551 float omf2 = (1 -
f) * (1 -
f);
1552 gsl_vector *
C = gsl_vector_alloc(3);
1554 for (
size_t i = 0;
i <
npix;
i++) {
1558 coef[0] * pview[
i][0] * pview[
i][0] +
1559 coef[1] * pview[
i][1] * pview[
i][1] +
1560 coef[2] * pview[
i][2] * pview[
i][2] +
1561 coef[3] * pview[
i][0] * pview[
i][1] +
1562 coef[4] * pview[
i][0] * pview[
i][2] +
1563 coef[5] * pview[
i][1] * pview[
i][2];
1566 coef[6] * pview[
i][0] + coef[7] * pview[
i][1] + coef[8] * pview[
i][2];
1570 double r =
p *
p - 4 *
q * o;
1584 double d = (-
p - sqrt(
r)) / (2 * o);
1586 for (
size_t j = 0;
j < 3;
j++) x1[
j] = d * pview[
i][
j];
1589 float re = 6378.137;
1593 double rg =
re*(1.-
f)/sqrt(1.-(2.-
f)*
f*clatg*clatg);
1597 v[0] = vel[0] *
rg /
pm;
1598 v[1] = vel[1] *
rg /
pm;
1599 v[2] = vel[2] *
rg /
pm;
1602 gsl_matrix_view
A = gsl_matrix_view_array((
double *)smat, 3, 3);
1603 gsl_vector_view
B = gsl_vector_view_array(x1, 3);
1605 gsl_blas_dgemv(CblasTrans, 1.0, &
A.matrix, &
B.vector, 0.0,
C);
1607 float rh[3], geovec[3];
1608 double *ptr_C = gsl_vector_ptr(
C, 0);
1609 for (
size_t j = 0;
j < 3;
j++) {
1611 geovec[
j] =
pos[
j] + rh[
j] +
v[
j]*delt[
i];
1615 float uxy = geovec[0] * geovec[0] + geovec[1] * geovec[1];
1616 float temp = sqrt(geovec[2] * geovec[2] +
omf2 *
omf2 * uxy);
1619 up[0] =
omf2 * geovec[0] / temp;
1620 up[1] =
omf2 * geovec[1] / temp;
1621 up[2] = geovec[2] / temp;
1622 float upxy = sqrt(up[0] * up[0] + up[1] * up[1]);
1625 ea[0] = -up[1] / upxy;
1626 ea[1] = up[0] / upxy;
1631 no[0] = -up[2] * ea[1];
1632 no[1] = up[2] * ea[0];
1633 no[2] = up[0] * ea[1] - up[1] * ea[0];
1636 float xlat_ =
RADEG * asin(up[2]);
1637 float xlon_ =
RADEG * atan2(up[1], up[0]);
1646 rl[0] = -ea[0] * rh[0] - ea[1] * rh[1] - ea[2] * rh[2];
1647 rl[1] = -no[0] * rh[0] - no[1] * rh[1] - no[2] * rh[2];
1648 rl[2] = -up[0] * rh[0] - up[1] * rh[1] - up[2] * rh[2];
1650 sl[0] = sunr[0] * ea[0] + sunr[1] * ea[1] + sunr[2] * ea[2];
1651 sl[1] = sunr[0] * no[0] + sunr[1] * no[1] + sunr[2] * no[2];
1652 sl[2] = sunr[0] * up[0] + sunr[1] * up[1] + sunr[2] * up[2];
1656 atan2(sqrt(sl[0] * sl[0] + sl[1] * sl[1]), sl[2]));
1659 if (
solz[
i] > 0.01)
sola[
i] = (short)(100 *
RADEG * atan2(sl[0], sl[1]));
1663 atan2(sqrt(rl[0] * rl[0] + rl[1] * rl[1]), rl[2]));
1666 if (
senz[
i] > 0.01)
sena[
i] = (short)(100 *
RADEG * atan2(rl[0], rl[1]));
1669 float tmp_sena =
sena[
i] / 100.0;
1670 float tmp_senz =
senz[
i] / 100.0;
1671 float tmp_height = 0;
1673 &tmp_senz, &tmp_sena, &tmp_height);
1690 sena[
i] = (short)(tmp_sena * 100.0);
1691 senz[
i] = (short)(tmp_senz * 100.0);
1692 height[
i] = (short)tmp_height;
1701 int mat2rpy(
float pos[3],
float vel[3],
double smat[3][3],
float rpy[3]) {
1718 double f = 1 / (
double)298.257;
1719 double omegae = 7.29211585494e-5;
1720 double omf2 = (1 -
f) * (1 -
f);
1724 for (
size_t j = 0;
j < 3;
j++) {
1728 v[0] -=
p[1] * omegae;
1729 v[1] +=
p[0] * omegae;
1732 double pm = sqrt(
p[0] *
p[0] +
p[1] *
p[1] +
p[2] *
p[2]);
1733 double omf2p = (
omf2 * rem +
pm - rem) /
pm;
1734 double pxy =
p[0] *
p[0] +
p[1] *
p[1];
1735 double temp = sqrt(
p[2] *
p[2] + omf2p * omf2p * pxy);
1738 z[0] = -omf2p *
p[0] / temp;
1739 z[1] = -omf2p *
p[1] / temp;
1740 z[2] = -
p[2] / temp;
1744 on[0] =
v[1] * z[2] -
v[2] * z[1];
1745 on[1] =
v[2] * z[0] -
v[0] * z[2];
1746 on[2] =
v[0] * z[1] -
v[1] * z[0];
1748 double onm = sqrt(
on[0] *
on[0] +
on[1] *
on[1] +
on[2] *
on[2]);
1751 for (
size_t j = 0;
j < 3;
j++)
y[
j] = -
on[
j] / onm;
1755 x[0] =
y[1] * z[2] -
y[2] * z[1];
1756 x[1] =
y[2] * z[0] -
y[0] * z[2];
1757 x[2] =
y[0] * z[1] -
y[1] * z[0];
1761 memcpy(&om[0][0], &
x, 3 *
sizeof(
double));
1762 memcpy(&om[1][0], &
y, 3 *
sizeof(
double));
1763 memcpy(&om[2][0], &z, 3 *
sizeof(
double));
1767 gsl_matrix_view rm_mat = gsl_matrix_view_array(&rm[0][0], 3, 3);
1771 gsl_permutation *perm = gsl_permutation_alloc(3);
1774 gsl_matrix_view
B = gsl_matrix_view_array(&om[0][0], 3, 3);
1775 gsl_linalg_LU_decomp(&
B.matrix, perm, &
s);
1779 gsl_matrix_view inv_mat = gsl_matrix_view_array(&inv[0][0], 3, 3);
1781 gsl_linalg_LU_invert(&
B.matrix, perm, &inv_mat.matrix);
1783 gsl_matrix_view
A = gsl_matrix_view_array(&smat[0][0], 3, 3);
1785 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, &
A.matrix, &inv_mat.matrix,
1786 0.0, &rm_mat.matrix);
1788 gsl_permutation_free(perm);
1791 rpy[0] =
RADEG * atan(-rm[2][1] / rm[2][2]);
1792 double cosp = sqrt(rm[2][1] * rm[2][1] + rm[2][2] * rm[2][2]);
1793 if (rm[2][2] < 0) cosp *= -1;
1794 rpy[1] =
RADEG * atan2(rm[2][0], cosp);
1795 rpy[2] =
RADEG * atan(-rm[1][0] / rm[0][0]);
1805 size_t sdim,
int *ncid,
int *gid,
1806 uint32_t bbb, uint32_t rbb,
1807 int16_t pcdim, int16_t psdim,
size_t nswband, int32_t *rta_nadir,
1813 catch ( NcException& e) {
1815 cerr <<
"Failure creating OCI GEO file: " <<
filename << endl;
1819 ifstream output_data_structure;
1821 string dataStructureFile;
1823 dataStructureFile.assign( cdlfile);
1826 output_data_structure.open( dataStructureFile.c_str(), ifstream::in);
1827 if ( output_data_structure.fail() ==
true) {
1828 cout <<
"\"" << dataStructureFile.c_str() <<
"\" not found" << endl;
1834 getline( output_data_structure,
line);
1835 size_t pos =
line.find(
"dimensions:");
1836 if (
pos == 0)
break;
1843 getline( output_data_structure,
line);
1845 if (
line.substr(0,2) ==
"//")
continue;
1847 size_t pos =
line.find(
" = ");
1848 if (
pos == string::npos)
break;
1851 istringstream iss(
line.substr(
pos+2, string::npos));
1856 iss >> skipws >>
line;
1858 if (
line.compare(
"number_of_scans") == 0) {
1862 if (
line.compare(
"blue_bands") == 0) {
1866 if (
line.compare(
"red_bands") == 0) {
1870 if (
line.compare(
"ccd_pixels") == 0) {
1874 if (
line.compare(
"SWIR_pixels") == 0) {
1878 if (
line.compare(
"SWIR_bands") == 0) {
1882 ncDims[ndims++] =
geofile->addDim(
line, dimSize);
1884 catch ( NcException& e) {
1886 cerr <<
"Failure creating dimension: " <<
line.c_str() << endl;
1894 getline( output_data_structure,
line);
1896 size_t pos =
line.find(
"// global attributes");
1897 if (
pos == 0)
break;
1901 getline( output_data_structure,
line);
1902 size_t pos =
line.find(
" = ");
1903 if (
pos == string::npos)
break;
1905 string attValue =
line.substr(
pos+3);
1908 attValue.erase(attValue.length()-2);
1909 size_t begQuote = attValue.find(
'"');
1910 size_t endQuote = attValue.find_last_of(
'"');
1911 if (begQuote == string::npos)
continue;
1912 attValue = attValue.substr(begQuote+1, endQuote-begQuote-1);
1914 istringstream iss(
line.substr(
pos+2));
1917 iss >> skipws >>
line;
1920 if (
line.compare(
"//") == 0)
continue;
1923 attName.assign(
line.substr(1).c_str());
1926 geofile->putAtt(attName, attValue);
1928 catch ( NcException& e) {
1930 cerr <<
"Failure creating attribute: " + attName << endl;
1936 geofile->putAtt(
"rta_nadir", NC_LONG, 2, rta_nadir);
1941 getline( output_data_structure,
line);
1945 if (
line.substr(0,1).compare(
"}") == 0) {
1946 output_data_structure.close();
1951 size_t pos =
line.find(
"group:");
1957 istringstream iss(
line.substr(6, string::npos));
1958 iss >> skipws >>
line;
1973 string flag_meanings;
1978 double fill_value=0.0;
1981 vector<NcDim> varVec;
1987 getline( output_data_structure,
line);
1989 getline( output_data_structure,
line);
1992 if (
line.substr(0,2) ==
"//")
continue;
1993 if (
line.length() == 0)
continue;
1994 if (
line.substr(0,1).compare(
"\r") == 0)
continue;
1995 if (
line.substr(0,1).compare(
"\n") == 0)
continue;
1998 if (
line.find(
"rhot_") != std::string::npos)
continue;
2000 if (
line.find(
"Lt_") != std::string::npos)
continue;
2006 if (
pos == string::npos) {
2010 createField( ncGrps[ngrps-1], sname.c_str(), lname.c_str(),
2013 (
void *) &fill_value,
2014 flag_masks.c_str(), flag_meanings.c_str(),
2017 ntype, varVec, coordinates);
2020 flag_meanings.clear();
2024 coordinates.clear();
2033 if (
line.substr(0,10).compare(
"} // group") == 0)
break;
2037 istringstream iss(
line);
2038 iss >> skipws >> varType;
2041 if ( varType.compare(
"char") == 0) ntype = NC_CHAR;
2042 else if ( varType.compare(
"byte") == 0) ntype = NC_BYTE;
2043 else if ( varType.compare(
"short") == 0) ntype = NC_SHORT;
2044 else if ( varType.compare(
"int") == 0) ntype = NC_INT;
2045 else if ( varType.compare(
"long") == 0) ntype = NC_INT;
2046 else if ( varType.compare(
"float") == 0) ntype = NC_FLOAT;
2047 else if ( varType.compare(
"real") == 0) ntype = NC_FLOAT;
2048 else if ( varType.compare(
"double") == 0) ntype = NC_DOUBLE;
2049 else if ( varType.compare(
"ubyte") == 0) ntype = NC_UBYTE;
2050 else if ( varType.compare(
"ushort") == 0) ntype = NC_USHORT;
2051 else if ( varType.compare(
"uint") == 0) ntype = NC_UINT;
2052 else if ( varType.compare(
"ulong") == 0) ntype = NC_UINT;
2053 else if ( varType.compare(
"int64") == 0) ntype = NC_INT64;
2054 else if ( varType.compare(
"uint64") == 0) ntype = NC_UINT64;
2058 size_t posSname =
line.substr(0,
pos).rfind(
" ");
2059 sname.assign(
line.substr(posSname+1,
pos-posSname-1));
2062 this->
parseDims( line.substr(
pos+1, string::npos), varVec);
2063 numDims = varVec.size();
2067 size_t posEql =
line.find(
"=");
2068 size_t pos1qte =
line.find(
"\"");
2069 size_t pos2qte =
line.substr(pos1qte+1, string::npos).find(
"\"");
2074 if (
attrName.compare(
"long_name") == 0) {
2075 lname.assign(
line.substr(pos1qte+1, pos2qte));
2079 else if (
attrName.compare(
"units") == 0) {
2080 units.assign(
line.substr(pos1qte+1, pos2qte));
2084 else if (
attrName.compare(
"description") == 0) {
2089 else if (
attrName.compare(
"_FillValue") == 0) {
2091 iss.str(
line.substr(posEql+1, string::npos));
2096 else if (
attrName.compare(
"flag_masks") == 0) {
2097 flag_masks.assign(
line.substr(pos1qte+1, pos2qte));
2099 else if (
attrName.compare(
"flag_masks") == 0) {
2100 flag_masks.assign(
line.substr(pos1qte+1, pos2qte));
2104 else if (
attrName.compare(
"flag_meanings") == 0) {
2105 flag_meanings.assign(
line.substr(pos1qte+1, pos2qte));
2109 else if (
attrName.compare(
"valid_min") == 0) {
2111 iss.str(
line.substr(posEql+1, string::npos));
2116 else if (
attrName.compare(
"valid_max") == 0) {
2118 iss.str(
line.substr(posEql+1, string::npos));
2123 else if (
attrName.compare(
"scale_factor") == 0) {
2125 iss.str(
line.substr(posEql+1, string::npos));
2130 else if (
attrName.compare(
"add_offset") == 0) {
2132 iss.str(
line.substr(posEql+1, string::npos));
2137 else if (
attrName.compare(
"coordinates") == 0) {
2138 coordinates.assign(
line.substr(pos1qte+1, pos2qte));
2157 size_t pos = dimString.find(
",", curPos);
2158 if (
pos == string::npos)
2159 pos = dimString.find(
")");
2162 istringstream iss(dimString.substr(curPos,
pos-curPos));
2163 iss >> skipws >> varDimName;
2165 for (
int i=0;
i<ndims;
i++) {
2168 dimName = ncDims[
i].getName();
2170 catch ( NcException& e) {
2172 cerr <<
"Failure accessing dimension: " + dimName << endl;
2176 if ( varDimName.compare(dimName) == 0) {
2177 varDims.push_back(ncDims[
i]);
2181 if ( dimString.substr(
pos, 1).compare(
")") == 0)
break;
2194 catch ( NcException& e) {
2195 cout << e.what() << endl;
2196 cerr <<
"Failure closing: " + fileName << endl;