OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
AfrtProcess.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * NAME: AfrtProcess.cpp
4  *
5  * DESCRIPTION: Object class that interfaces with the Ahmad-Frazier codes.
6  *
7  * Created on: June, 2018
8  * Author: Sam Anderson
9  *
10  * Modified:
11  *
12  *******************************************************************************/
13 
14 
15 #include <AfrtProcess.h>
16 #include <libgen.h>
17 
18 #include <new> // nothrow
19 #include <fstream> // std::ifstream
20 #include <algorithm> // std::sort
21 #include <iostream> // std::cout
22 #include <functional> // std::bind
23 #include <vector>
24 #include <netcdf>
25 #include <sys/time.h>
26 
27 #include <AfrtOptions.h>
28 #include <afrt.h>
29 
30 using namespace std;
31 
32 extern"C" {
33 void af_phs_read_( char* infile, int* nlam, int* nsd,
34  int* ilam1, int* ilam2, int* isd1, int* isd2, int* ifunc, int* jnorm,
35  int* jrgm, int* mfunc, int* irh, int* iset, char* xtitle,
36  double* xww, double* xn1, double* xn2, double* xrg, double* xsig,
37  double* xnpar, double* xdx, double* epar);
38 void af_phs_process_( char* phsdir, int* ilam, int* isd, int* isd1, int* isd2,
39  int* ifunc, int* jnorm, int* jrgm, int* mfunc, int* irh, int* iset,
40  char* xtitle,double* xww, double* refr, double* refi, double* xrg,
41  double* xsig, double* xnpar, double* xdx, double* epar,
42  double* rmin, double* rmax, double* deltar, double* deltax,
43  double* r11, double* r22, double* r33, double* r44, double* reff,
44  double* veff, double* ccnsml, double* bsr, double* salb,
45  double* asf, double* qscat, double* qext, double* angl,
46  double* phfu, double* pol, double* thd, double* t, double* rbar,
47  double* dnzp, double* dnp, double* dvp, double* sumnp, double* wt);
48 void af_ocn_read_( char* infile, int* nww, int* iopt, int* isig, int* isolz,
49  int* nsza, int* nthe, int* nphi, int* nsig, int* ibgn, int* iend,
50  double* dlth, double* dlph, double* xr, double* xi, double* v,
51  double* thcel, double* phcel, double* wav, double* tha, double* sig_hg,
52  double* solz);
53 void af_ocn_process_( char* ocndir, int* alam, int* asig, int* iopt,
54  int* isig, int* isolz, int* nsza, int* ntha, int* nphi, double* dlth,
55  double* dlph, double* xr, double* xi, double* v, double* thcel,
56  double* phcel, double* wav, double* tha, double* sig_hg, double* solz, int* iprob,
57  double* thp, double* phcnd, double* thcnd, double* txx,
58  double* pti, double* xinlpi, double* xi_hgpi, double* xin2pi,
59  double* xin2top);
60 void af_rt1_read_(char* infile, char* phsdir, char* rt1dir, char* ozone_lut,
61  char* atm_lut, char* coeff_lut, int* nsd, int* iair,
62  int* iprin, int* ipsudo, int* ioptn, int* idust, int* iaprof,
63  int* iblyr, int* icld, int* nch, int* nt55, int* nrh, int* kset,
64  int* ilam1, int* ilam2, int* isd1, int* isd2, int* itau1, int* itau2,
65  int* kznum, int* krhum, double* deltau, double* psrfc,
66  double* ht_dust, double* sigma_dust, double* pcldtop, double* pcldbtm,
67  double* taum55, double* xlamb, double* c0, double* c1, double* c2,
68  double* beta, double* rho, double* ppo, double* x101, double* temp101,
69  double* htdd, double* ppodd, double* dxdd, double* znpdd,
70  int* nortau, int* ioznab, int* nrmww,
71  double* qst, double* qtt, double* qst5, double* qtt5);
72 void af_rt1_process_(char* rt1dir, int* ailam, int* aisd, int* airh, int* aitau,
73  int* aiair, int* aiprin, int* aipsudo, int* aioptn, int* aidust,
74  int* aiaprof, int* aiblyr, int* aicld, int* anch, int* ant55, int* ansd,
75  int* anrh, int* akset, int* akznum, int* akrhum, double* adeltau,
76  double* apsrfc, double* aht_dust, double* asigma_dust, double* apcldtop,
77  double* apcldbtm, double* ataum55, double* axlamb, double* ac0,
78  double* ac1, double* ac2, double* abeta, double* arho, double* appo,
79  double* ax101, double* atemp101, double* ahtdd, double* appodd,
80  double* adxdd, double* aznpdd, int* anortau, int* aioznab, int* anrmww,
81  double* aqst, double* aqtt, double* aqst5, double* aqtt5, double* htlvl,
82  double* pplvl, double* fr, double* fn, double* fa, double* ftot,
83  double* dtrr, double* dtmm, double* dtaa, double* dtot, double* trp,
84  double* tmp, double* tap, double* salb, double* turbhl, double* dx,
85  double* x, double* tozn101, double* htdv, double* pdv, double* taur,
86  double* taum, double* taua, double* tau, double* wvlth, double* psrfc,
87  double* rho, double* xozn, double* tautot, double* dtau1, int* nolyr,
88  double* tcar, double* twat, double* tozn, int* ifc, int* nmodl);
89 void af_rt2_input_(char* infile, int* iref, int* itrans, int* iset,
90  int* irh1, int* irh2, int* ilm1, int* ilm2, int* isd1, int* isd2,
91  int* itau1, int* itau2, int* ithe01, int* ithe02, int* iwnd1,
92  int* iwnd2, int* nx, int* nthe0, int* nwl, int* nrh, int* iww,
93  int* krhum, int* iprin, int* ipol, int* npass1, int* npass2,
94  int* icrft, int* iactflx, int* isurf, int* iglint, int* iocn,
95  int* ifoam, int* iwatr, int* iconc, double* dtheta,
96  double* dphi, double* hcrft, double* rx, double* the0in,
97  double* wwl, double* albwat);
98 void af_rt2_read_(char* adir1, char* adir2, char* adir3, char* adir4,
99  char* adir5, int* ailm, int* aisd, int* airh, int* aiwind,
100  int* aitau, int* aiset, int* airef, int* aipol,
101  int* aiww, int* akrhum, double* awwl, double* aalbwat,
102  int* ifunc, int* mfunc, double* refr, double* refi, double* rmin,
103  double* rmax, double* deltar, double* deltax, double* rg,
104  double* sig, double* npar, double* r11, double* r22, double* r33,
105  double* r44, double* reff, double* veff, double* ccn, double* bsr,
106  double* salb, double* asf, double* qscat, double* qext,
107  double* t, double* thd, double* xr, double* xi, double* v,
108  double* thcel, double* phcel, double* txx, double* pti,
109  double* wvlth, double* psrfc, double* rho,
110  double* xozn, double* tautot, double* deltau, double* trp,
111  double* tmp, double* tap, double* tcar, double* twat,
112  double* tozn, double* htlvl, double* pplvl,
113  double* dtrr, double* dtmm, double* dtaa, double* dtot,
114  double* htdv, double* pdv, double* taur,
115  double* taum, double* taua,
116  int* ifc, int* nmodl, int* nolyr, float* bfr);
117 void af_rt2_process_( char* odir, int* ailm, int* aisd, int* airh, int* aitau,
118  int* aiwnd, int* airef, int* aitrans, int* aiset,
119  int* airh1, int* airh2, int* ailm1, int* ailm2, int* aisd1, int* aisd2,
120  int* aitau1, int* aitau2, int* aithe01, int* aithe02, int* aiwnd1,
121  int* aiwnd2, int* anx, int* anthe0, int* anwl, int* anrh, int* ansd, int* aiww,
122  int* akrhum, int* aiprin, int* aipol, int* anpass1, int* anpass2,
123  int* aicrft, int* aiactflx, int* aisurf, int* aiglint, int* aiocn,
124  int* aifoam, int* aiwatr, int* aiconc, double* adtheta,
125  double* adphi, double* ahcrft, double* arx, double* athe0in,
126  double* awwl, double* aalbwat, int* ifunc, int* mfunc,
127  double* arefr, double* arefi, double* armin,
128  double* armax, double* adeltar, double* adeltax, double* arg,
129  double* asig, double* anpar, double* ar11,
130  double* ar22, double* ar33, double* ar44, double* areff, double* aveff,
131  double* accn, double* absr, double* asalb, double* aasf,
132  double* aqscat, double* aqext, double* at, double* athd,
133  double* xr, double* xi, double* v, double* thcel, double* phcel,
134  double* atxx, double* apti, double* awvlth, double* apsrfc,
135  double* arho, double* axozn, double* atautot, double* adeltau,
136  double* atrp, double* atmp, double* atap, double* atcar,
137  double* atwat, double* atozn, double* ahtlvl, double* applvl,
138  double* adtrr, double* adtmm, double* adtaa, double* adtot,
139  double* ahtdv, double* apdv, double* ataur,
140  double* ataum, double* ataua,
141  int* aifc, int* anmodl, int* anolyr, int* apsudo, float* abfr,
142  double* tma, double* tmb, double* tmc, double* tmfd,
143  double* tmfu, double* tms, double* tmg, double* tmh,
144  double* tmp, double* tmq, double* tmt, double* tmpp, double* tmqq,
145  double* tmrr, double* tmss, double* transm, double* tmcfd,
146  double* tmcfu, double* tmf1, double* tmf2,
147  double* xzeroz, double* xzerod, double* tupz, double* tdwnz);
148 };
149 
150 const double pace_wavelengths[NUM_PACE_BANDS] =
151 {365.9298, 375.594, 385.2625, 394.9355, 404.6129, 414.2946, 423.9808, 433.6713,
152  443.3662, 453.0655, 462.7692, 472.4773, 482.1898, 491.9066, 501.6279, 511.3535,
153  521.0836, 530.818, 540.5568, 550.3, 560.0477, 569.7996, 579.556, 589.3168,
154  599.0819, 608.8515, 618.6254, 628.4037, 638.1865, 647.9736, 657.7651, 665.5994,
155  675.4012, 685.1979, 694.9894, 704.7756, 714.5566, 724.3325, 734.1031, 743.8685,
156  753.6287, 763.3837, 773.1335, 782.8781, 792.6174, 802.3516, 812.0805, 821.8043,
157  831.5228, 841.2361, 850.9442, 860.6471, 870.3448, 880.0372, 889.7245, 936.646,
158  1238.75, 1383.0, 1641.53, 2126.795, 2246.658
159 };
160 
161 
162 /**************************************************************************
163  * NAME: AfrtProcess()
164  *
165  * DESCRIPTION: Class Constructor
166  *
167  *************************************************************************/
168 
170 {
171 }
172 
174 {
175  bNC4_ = false;
176 }
177 
179 {
180 }
181 
183 {
184 }
185 
187 {
188 }
189 
191 {
192 }
193 
194 /**************************************************************************
195  * NAME: ~AfrtProcess()
196  *
197  * DESCRIPTION: Class Destructor
198  *
199  *************************************************************************/
200 
202 {
203 }
204 
206 {
207  if (in_ != nullptr) delete in_;
208  if (out_ != nullptr) delete out_;
209 }
210 
212 {
213  if (in_ != nullptr) delete in_;
214  if (out_ != nullptr) delete out_;
215 }
216 
218 {
219  if (in_ != nullptr) delete in_;
220  if (out_ != nullptr) delete out_;
221 }
222 
224 {
225  if (in_ != nullptr) delete in_;
226  if (out_ != nullptr) delete out_;
227 }
228 
230 {
231  if (phs_ != nullptr) delete phs_;
232  if (ocn_ != nullptr) delete ocn_;
233  if (rt1_ != nullptr) delete rt1_;
234 }
235 
236 /**************************************************************************
237  * NAME: initialize()
238  *
239  * DESCRIPTION: Initializes object class; reads input data.
240  *
241  *************************************************************************/
242 
244 {
245  int status = RT_SUCCESS;
246  return status;
247 }
248 
250 {
251  int status = RT_SUCCESS;
252 
253  in_ = new(phs_in);
254  out_ = new(phs_out);
255 
256  status = read_af();
257 
258  return status;
259 }
260 
261 int AfrtProcessPhs::initialize(int l1, int l2, int s1, int s2)
262 {
263  int status = RT_SUCCESS;
264 
265  in_ = new(phs_in);
266  out_ = new(phs_out);
267 
268  string phs_filepath = afrt_get_option(INPUT_PHS);
269  if (phs_filepath.empty()) {
270  cerr << "\nAfrtProcessPhs:: Failure locating input file path.\n" << endl;
271  return RT_FAIL;
272  }
273 
274  size_t dlam = l2 - l1 + 1;
275  size_t dsd = s2 - s1 + 1;
276 
277  out_->ifunc.resize(boost::extents[dsd]);
278  out_->mfunc.resize(boost::extents[dsd]);
279  out_->refr.resize(boost::extents[dlam][dsd][nmd]);
280  out_->refi.resize(boost::extents[dlam][dsd][nmd]);
281  out_->rg.resize(boost::extents[dlam][dsd][nmd]);
282  out_->sig.resize(boost::extents[dlam][dsd][nmd]);
283  out_->npar.resize(boost::extents[dlam][dsd][nmd]);
284  out_->dx.resize(boost::extents[dlam][dsd][nmd]);
285  out_->epar.resize(boost::extents[dlam][dsd][nmd]);
286  out_->rmin.resize(boost::extents[dlam][dsd][nmd]);
287  out_->rmax.resize(boost::extents[dlam][dsd][nmd]);
288  out_->deltar.resize(boost::extents[dlam][dsd][nmd]);
289  out_->deltax.resize(boost::extents[dlam][dsd][nmd]);
290  out_->r11.resize(boost::extents[dlam][dsd]);
291  out_->r22.resize(boost::extents[dlam][dsd]);
292  out_->r33.resize(boost::extents[dlam][dsd]);
293  out_->r44.resize(boost::extents[dlam][dsd]);
294  out_->reff.resize(boost::extents[dlam][dsd]);
295  out_->veff.resize(boost::extents[dlam][dsd]);
296  out_->ccnsml.resize(boost::extents[dlam][dsd]);
297  out_->bsr.resize(boost::extents[dlam][dsd]);
298  out_->salb.resize(boost::extents[dlam][dsd]);
299  out_->asf.resize(boost::extents[dlam][dsd]);
300  out_->qscat.resize(boost::extents[dlam][dsd]);
301  out_->qext.resize(boost::extents[dlam][dsd]);
302  out_->angl.resize(boost::extents[ntf]);
303  out_->phfu.resize(boost::extents[dlam][dsd][ntf]);
304  out_->pol.resize(boost::extents[dlam][dsd][ntf]);
305  out_->wt.resize(boost::extents[dlam][dsd][ntf]);
306  out_->sumnp.resize(boost::extents[dlam][dsd][ntf]);
307  out_->thd.resize(boost::extents[dlam][dsd][ntf]);
308  out_->rbar.resize(boost::extents[dlam][dsd][ntf]);
309  out_->dnzp.resize(boost::extents[dlam][dsd][ntf]);
310  out_->dnp.resize(boost::extents[dlam][dsd][ntf]);
311  out_->dvp.resize(boost::extents[dlam][dsd][ntf]);
312  out_->t.resize(boost::extents[dlam][dsd][nstk][ntf]);
313 
314  size_t rn = phs_filepath.find(".nc");
315  if(rn > 1000) {
316  status = read_af();
317  bNC4_ = false;
318  } else {
319  read_nc4(phs_filepath, l1, l2, s1, s2);
320  bNC4_ = true;
321  }
322 
323  return status;
324 }
325 
327 {
328  int status = RT_SUCCESS;
329 
330  in_ = new(ocn_in);
331  out_ = new(ocn_out);
332 
333 // status = read_af();
334 // in_->infile = afrt_get_option(INPUT_OCN);
335 
336  double* ftemp;
337  int count;
339  if (ftemp != nullptr) {
340  in_->inw = count;
341  for (int i=0; i<count; i++){
342  in_->wav[i] = ftemp[i];
343  }
344  }
346  if (ftemp != nullptr) {
347  in_->insig = count;
348  for (int i=0; i<count; i++){
349  in_->sig_hg[i] = ftemp[i]/100.0;
350  }
351  }
353  if (ftemp != nullptr) {
354  in_->inthe = count;
355  in_->insza = count-1;
356  in_->dlth = ftemp[2] - ftemp[1];
357  for (int i=0; i<count; i++){
358  in_->tha[i] = ftemp[i];
359  in_->solz[i] = ftemp[i];
360  }
361  }
363  if (value > 0.0) {
364  in_->dlph = value;
365  in_->inphi = 180.0/value + 2.0 + 0.01;
366  }
368  in_->xr = value;
370  in_->xi = value;
372  in_->thcel = value;
374  in_->phcel = value;
375 
376  in_->iprob = afrt_get_option_int(INPUT_IPROB);
377 
378  in_->iopt = 0;
379  in_->isig = 1;
380  in_->isolz = 0;
381  in_->v = 0.0;
382 
383  return status;
384 }
385 
387 {
388  int status = RT_SUCCESS;
389 
390  in_ = new(rt1_in);
391  out_ = new(rt1_out);
392 
393 // Must provide the total number of scattering models
394  AfrtProcessPhs* phs = new AfrtProcessPhs();
395  status = phs->initialize(1,1,1,1);
396  in_->nsd = phs->in_->insd;
397  delete phs;
398 
399 // status = read_af();
400 // in_->infile = afrt_get_option(INPUT_RT1);
401 // in_->infile.append(" ");
402  in_->ozone_lut = afrt_get_option(INPUT_OZONE_RT1);
403  in_->ozone_lut.append(" ");
404  in_->atm_lut = afrt_get_option(INPUT_ATM_RT1);
405  in_->atm_lut.append(" ");
406  in_->coeff_lut = afrt_get_option(INPUT_COEFF_RT1);
407  in_->coeff_lut.append(" ");
408  in_->phsdir = afrt_get_option(ODIR_PHS);
409  in_->phsdir.append(" ");
410  in_->rt1dir = afrt_get_option(ODIR_RT1);
411  in_->rt1dir.append(" ");
412 
413  double* ftemp;
414  int count = 0;
416  if (ftemp != nullptr) {
417  in_->inch = count;
418  }
420  if (ftemp != nullptr) {
421  in_->int55 = count;
422  for (int i=0; i<count; i++){
423  in_->taum55[i] = ftemp[i];
424  }
425  }
426  int* itemp;
428  if (itemp != nullptr) {
429  for (int i=0; i<count; i++){
430  in_->iair[i] = itemp[i];
431  }
432  }
433 
435  in_->deltau = value;
437  in_->psrfc = value;
438  in_->ipsudo = afrt_get_option_bool(INPUT_PSUDO) ? 1 : 0;;
439  in_->iair[0] = afrt_get_option_bool(INPUT_RAYLEIGH) ? 1 : 0;
440  in_->iair[1] = afrt_get_option_bool(INPUT_AEROSOLS) ? 1 : 0;
441  in_->iair[2] = afrt_get_option_bool(INPUT_GASES) ? 1 : 0;
442  in_->ikset = 3;
443  in_->iprin = 0;
444  in_->ioptn = 0;
445  in_->idust = 0;
446  in_->iaprof = 1;
447  in_->iblyr = 0;
448  in_->icld = 0;
449  in_->nortau = 0;
450  in_->ioznab = 1;
451  in_->nrmww = 0;
452 
453 // Read ozone values from text file
454  string line, dummy;
456  if(filepath.empty()) {
457  cerr << "AfrtProcessRt1::initialize() Invalid path for ozone LUT file." << endl;
458  return RT_FAIL;
459  }
460  ifstream finz(filepath.c_str());
461  if(!finz) {
462  std::cout << "AfrtProcessRt1::initialize() Error opening ozone LUT file." << endl;
463  return RT_FAIL;
464  }
465  for (int iL=0; iL<koznp; iL++) {
466  getline(finz, line);
467  stringstream ss(line);
468  ss >> in_->ppo[iL];
469  ss >> in_->x101[iL];
470  ss >> in_->temp101[iL];
471  }
472 
473 // Read coefficient values from text file
475  if(filepath.empty()) {
476  cerr << "AfrtProcessRt1::initialize() Invalid path for coefficient LUT file." << endl;
477  return RT_FAIL;
478  }
479  ifstream fina(filepath.c_str());
480  if(!fina) {
481  std::cout << "AfrtProcessRt1::initialize() Error opening coefficient LUT file." << endl;
482  return RT_FAIL;
483  }
484  getline(fina, line);
485  for (int iL=0; iL<in_->inch; iL++) {
486  getline(fina, line);
487  stringstream ss(line);
488  ss >> value;
489  ss >> in_->xlamb[iL];
490  ss >> in_->c0[iL];
491  ss >> in_->c1[iL];
492  ss >> in_->c2[iL];
493  ss >> in_->beta[iL];
494  ss >> in_->rho[iL];
495  }
496 
497 // Read atmosphere values from text file
499  if(filepath.empty()) {
500  cerr << "AfrtProcessRt1::initialize() Invalid path for atmosphere LUT file." << endl;
501  return RT_FAIL;
502  }
503  ifstream finc(filepath.c_str());
504  if(!finc) {
505  std::cout << "AfrtProcessRt1::initialize() Error opening atmosphere LUT file." << endl;
506  return RT_FAIL;
507  }
508  for (int iL=0; iL<knm; iL++) {
509  getline(finc, line);
510  stringstream ss(line);
511  ss >> in_->htdd[iL];
512  ss >> in_->ppodd[iL];
513  ss >> in_->dxdd[iL];
514  ss >> in_->znpdd[iL];
515  }
516 
517  return status;
518 }
519 
521 {
522  int status = RT_SUCCESS;
523 
524  in_ = new(rt2_in);
525  out_ = new(rt2_out);
526 
527 // status = read_af();
528 // in_->infile = afrt_get_option(INPUT_RT2);
529 // in_->infile.append(" ");
530  in_->rt1dir = afrt_get_option(ODIR_RT1);
531  in_->rt1dir.append(" ");
532  in_->phsdir = afrt_get_option(ODIR_PHS);
533  in_->phsdir.append(" ");
534  in_->rt2dir = afrt_get_option(ODIR_RT2);
535  in_->rt2dir.append(" ");
536  in_->ocndir = afrt_get_option(ODIR_OCN);
537  in_->ocndir.append(" ");
538  in_->outdir = afrt_get_option(ODIR_RT2);
539  in_->outdir.append(" ");
540 
541  in_->iref = afrt_get_option_int(INPUT_IREF);
542  in_->itrans = afrt_get_option_bool(INPUT_ITRANS) ? 1 : 0;
543  in_->ipol = afrt_get_option_bool(INPUT_POL) ? 1 : 0;
544  in_->icrft = afrt_get_option_bool(INPUT_CRFT) ? 1 : 0;
545  in_->iactflx = afrt_get_option_bool(INPUT_ACTFLX) ? 1 : 0;
546  in_->isurf = afrt_get_option_bool(INPUT_SURF) ? 1 : 0;
547  in_->iglint = afrt_get_option_bool(INPUT_GLINT) ? 1 : 0;
548  in_->iocn = afrt_get_option_bool(INPUT_IOCN) ? 1 : 0;
549  in_->ifoam = afrt_get_option_bool(INPUT_FOAM) ? 1 : 0;
550  in_->iwatr = afrt_get_option_bool(INPUT_WATR) ? 1 : 0;
551  in_->iconc = 0;
552  in_->iset = 0;
553  in_->iprin = 0;
554  in_->inpass1 = 19;
555  in_->inpass2 = 20;
556  in_->inrh = 8;
557  in_->insd = 80;
558 
559  double* ftemp;
560  int count;
562  if (ftemp != nullptr) {
563  in_->inwl = count;
564  for (int i=0; i<count; i++){
565  in_->wwl[i] = ftemp[i];
566  }
567  }
569  if (ftemp != nullptr) {
570  in_->inrh = count;
571  for (int i=0; i<count; i++){
572  in_->krhum[i] = ftemp[i];
573  }
574  }
576  if (ftemp != nullptr) {
577  for (int i=0; i<count; i++){
578  in_->iww[i] = ftemp[i];
579  }
580  }
582  if (ftemp != nullptr) {
583  in_->inx = count;
584  in_->inthe0 = count-1;
585  in_->dtheta = ftemp[2] - ftemp[1];
586  for (int i=0; i<count; i++){
587  in_->rx[i] = ftemp[i];
588  if ( i+1 < count) {
589  in_->the0in[i] = (ftemp[i+1] + ftemp[i])/2.0;
590  }
591  }
592  }
593  in_->ithe01 = 1;
594  in_->ithe02 = in_->inthe0;
596  if (value > 0.0) {
597  in_->dphi = value;
598  int nph = (360.0/in_->dphi)/2.0 +1;
599  for (int i=0; i<nph; i++) {
600  in_->phi[i] = i*in_->dphi;
601  }
602  }
603 
604  return status;
605 }
606 
608 {
609  int status = RT_SUCCESS;
610 
611 #ifdef WITH_MPI
612  MPI_Init(NULL, NULL); // START MPI
613  MPI_Comm_rank(MPI_COMM_WORLD, &mpi_id); // DETERMINE RANK OF THIS PROCESSOR
614  MPI_Comm_size(MPI_COMM_WORLD, &n_mpi_nodes); // DETERMINE TOTAL NUMBER OF PROCESSORS
615  cout << "mpi_id: " << mpi_id << endl;
616 #endif
617 
618  int* intArray;
619  int count;
620  int l1 = 0;
621  int l2 = 0;
622  int s1 = 0;
623  int s2 = 0;
624  int t1 = 0;
625  int t2 = 0;
626  int w1 = 0;
627  int w2 = 0;
628 
630  if (intArray != 0L) {
631  l1 = intArray[0];
632  l2 = intArray[1];
633  }
635  if (intArray != 0L) {
636  s1 = intArray[0];
637  s2 = intArray[1];
638  }
640  if (intArray != 0L) {
641  t1 = intArray[0];
642  t2 = intArray[1];
643  }
645  if (intArray != 0L) {
646  w1 = intArray[0];
647  w2 = intArray[1];
648  }
649  if (l1<1 || l2<l1 || s1<1 || s2<s1 || t1<1 || t2<t1 || w1<1 || w2<w1) {
650  std::cerr << "Bad command line options!!!" << std::endl;
651  return(status);
652  }
653 
654  phs_ = new AfrtProcessPhs();
655  status = phs_->initialize(l1, l2, s1, s2);
656  if ( status != RT_SUCCESS ) return(status);
657 
658  ocn_ = new AfrtProcessOcn();
659  status = ocn_->initialize();
660  if ( status != RT_SUCCESS ) return(status);
661 
662  rt1_ = new AfrtProcessRt1();
663  status = rt1_->initialize();
664  if ( status != RT_SUCCESS ) return(status);
665 
667  if ( status != RT_SUCCESS ) return(status);
668 
669  out_->outdir = afrt_get_option(ODIR_RT2);
670  out_->outdir.append(" ");
671 
672  if (l1>0 && l2>=l1) {
673  in_->ilm1 = l1;
674  in_->ilm2 = l2;
675  }
676  if (s1>0 && s2>=s1) {
677  in_->isd1 = s1;
678  in_->isd2 = s2;
679  }
680  if (t1>0 && t2>=t1) {
681  in_->itau1 = t1;
682  in_->itau2 = t2;
683  }
684  if (w1>0 && w2>=w1) {
685  in_->iwnd1 = w1;
686  in_->iwnd2 = w2;
687  }
688 
689  //size_t dlam = in_->ilm2 - in_->ilm1 + 1;
690  //size_t dsd = in_->isd2 - in_->isd1 + 1;
691  //size_t dtau = in_->itau2 - in_->itau1 + 1;
692  //size_t dwnd = in_->iwnd2 - in_->iwnd1 + 1;
693  //size_t dnsig = nsig;
694  size_t dnsza = nsza;
695  size_t dnthe = nthe;
696  size_t dnphi = nphi;
697  size_t dnlyr = nlyr;
698 
699  ocn_->out_->thp.resize(boost::extents[dnsza]);
700  ocn_->out_->phcnd.resize(boost::extents[dnphi]);
701  ocn_->out_->thcnd.resize(boost::extents[dnthe]);
702  ocn_->out_->txx.resize(boost::extents[1][1][dnsza][dnthe][dnphi][ntrx]);
703  ocn_->out_->pti.resize(boost::extents[1][1][dnsza][dnthe][dnphi][npti]);
704  ocn_->out_->xinlpi.resize(boost::extents[1][1][dnsza][dnthe][dnphi]);
705  ocn_->out_->xi_hgpi.resize(boost::extents[1][1][dnsza][dnthe][dnphi]);
706  ocn_->out_->xin2pi.resize(boost::extents[1][1][dnsza][dnthe][dnphi]);
707  ocn_->out_->xin2top.resize(boost::extents[1][1][dnsza][dnthe][dnphi]);
708 
709  rt1_->out_->htlvl.resize(boost::extents[1][1][1][nlyr]);
710  rt1_->out_->pplvl.resize(boost::extents[1][1][1][nlyr]);
711  rt1_->out_->fr.resize(boost::extents[1][1][1][nlyr]);
712  rt1_->out_->fn.resize(boost::extents[1][1][1][nlyr]);
713  rt1_->out_->fa.resize(boost::extents[1][1][1][nlyr]);
714  rt1_->out_->ftot.resize(boost::extents[1][1][1][nlyr]);
715  rt1_->out_->dtrr.resize(boost::extents[1][1][1][nlyr]);
716  rt1_->out_->dtmm.resize(boost::extents[1][1][1][nlyr]);
717  rt1_->out_->dtaa.resize(boost::extents[1][1][1][nlyr]);
718  rt1_->out_->dtot.resize(boost::extents[1][1][1][nlyr]);
719  rt1_->out_->salb.resize(boost::extents[1][1][1][nlyr]);
720  rt1_->out_->turbhl.resize(boost::extents[1][1][1][nlyr]);
721  rt1_->out_->trp.resize(boost::extents[1][1][1]);
722  rt1_->out_->tmp.resize(boost::extents[1][1][1]);
723  rt1_->out_->tap.resize(boost::extents[1][1][1]);
724  rt1_->out_->tautot.resize(boost::extents[1][1][1]);
725  rt1_->out_->ppo.resize(boost::extents[1][1][1][nozn]);
726  rt1_->out_->dx.resize(boost::extents[1][1][1][nozn]);
727  rt1_->out_->x.resize(boost::extents[1][1][1][nozn]);
728  rt1_->out_->tozn101.resize(boost::extents[1][1][1][nozn]);
729  rt1_->out_->htdv.resize(boost::extents[1][1][1][nlyr+1]);
730  rt1_->out_->pdv.resize(boost::extents[1][1][1][nlyr+1]);
731  rt1_->out_->taur.resize(boost::extents[1][1][1][nlyr]);
732  rt1_->out_->taum.resize(boost::extents[1][1][1][nlyr]);
733  rt1_->out_->taua.resize(boost::extents[1][1][1][nlyr]);
734  rt1_->out_->tau.resize(boost::extents[1][1][1][nlyr]);
735  rt1_->out_->wvlth.resize(boost::extents[1][1][1]);
736  rt1_->out_->psrfc.resize(boost::extents[1][1][1]);
737  rt1_->out_->rho.resize(boost::extents[1][1][1]);
738  rt1_->out_->xozn.resize(boost::extents[1][1][1]);
739  rt1_->out_->dtau1.resize(boost::extents[1][1][1]);
740  rt1_->out_->tcar.resize(boost::extents[1][1][1]);
741  rt1_->out_->twat.resize(boost::extents[1][1][1]);
742  rt1_->out_->tozn.resize(boost::extents[1][1][1]);
743  rt1_->out_->ifc.resize(boost::extents[1][1][1]);
744  rt1_->out_->nolyr.resize(boost::extents[1][1][1]);
745  rt1_->out_->nmodl.resize(boost::extents[1][1][1]);
746 
747  out_->tma.resize(boost::extents[1][1][1][1][dnsza]);
748  out_->tmb.resize(boost::extents[1][1][1][1][dnsza]);
749  out_->tmc.resize(boost::extents[1][1][1][1][dnsza]);
750  out_->tmfd.resize(boost::extents[1][1][1][1][dnsza]);
751  out_->tmfu.resize(boost::extents[1][1][1][1][dnsza]);
752  out_->tms.resize(boost::extents[1][1][1][1][dnsza]);
753  out_->tmg.resize(boost::extents[1][1][1][1][dnsza]);
754  out_->tmh.resize(boost::extents[1][1][1][1][dnsza]);
755  out_->tmp.resize(boost::extents[1][1][1][1][dnsza]);
756  out_->tmq.resize(boost::extents[1][1][1][1][dnsza]);
757  out_->tmt.resize(boost::extents[1][1][1][1][dnsza]);
758  out_->tmpp.resize(boost::extents[1][1][1][1][dnsza]);
759  out_->tmqq.resize(boost::extents[1][1][1][1][dnsza]);
760  out_->tmrr.resize(boost::extents[1][1][1][1][dnsza]);
761  out_->tmss.resize(boost::extents[1][1][1][1][dnsza]);
762  out_->transm.resize(boost::extents[1][1][1][1][dnsza]);
763  out_->tmcfd.resize(boost::extents[1][1][1][1][dnsza]);
764  out_->tmcfu.resize(boost::extents[1][1][1][1][dnsza]);
765  out_->tmf1.resize(boost::extents[1][1][1][1][dnlyr][dnsza]);
766  out_->tmf2.resize(boost::extents[1][1][1][1][dnlyr]);
767  out_->xzeroz.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
768  out_->xzerod.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
769  out_->tupz.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
770  out_->tdwnz.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
771 // out_->crfttup.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
772 // out_->crftzu.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
773 // out_->crfttdn.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
774 // out_->crftzd.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
775 // out_->surfzu.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
776 // out_->radsky.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
777 // out_->radocn.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
778 // out_->raddir.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi]);
779 
780  string ofilepath = afrt_get_option(OFILE_NC4);
781  string odir = afrt_get_option(ODIR_NC4);
782 
783  if (mpi_id <= 0) {
784  if (!ofilepath.empty()) {
785  ofilepath_ = ofilepath;
786  } else {
787  char buf[256];
788  sprintf( buf, "MD%d-%d_WL%d-%d_TA%d-%d_WD%d-%d",
789  s1,s2,l1,l2,t1,t2,w1,w2 );
790  ofilepath_ = odir + "/RT00_" + string(buf) + ".nc";
791  }
792 
793  status = initialize_nc4(ofilepath_);
794  }
795 
796  return status;
797 }
798 
799 /**************************************************************************
800  * NAME: read_af()
801  *
802  * DESCRIPTION: Read AF legacy input forms
803  *
804  *************************************************************************/
805 
807 {
808  int status = RT_SUCCESS;
809  return status;
810 }
811 
813 {
814  int status = RT_SUCCESS;
815 
816  in_->infile = afrt_get_option(INPUT_PHS);
817  in_->infile.append(" ");
818 
819  af_phs_read_((char*)in_->infile.c_str(),
820  &in_->inw,
821  &in_->insd,
822  &in_->ilam1,
823  &in_->ilam2,
824  &in_->isd1,
825  &in_->isd2,
826  &in_->ifunc[0],
827  &in_->jnorm[0],
828  &in_->jrgm[0],
829  &in_->mfunc[0],
830  &in_->irh[0],
831  &in_->iset[0],
832  &in_->xtitle[0][0],
833  &in_->ww[0][0],
834  &in_->refr[0][0][0],
835  &in_->refi[0][0][0],
836  &in_->rg[0][0][0],
837  &in_->sig[0][0][0],
838  &in_->npar[0][0][0],
839  &in_->dx[0][0][0],
840  &in_->epar[0][0][0]);
841 
842 // std::cout << "Input file = " << in_->infile << std::endl;
843 
844  return status;
845 }
846 
848 {
849  int status = RT_SUCCESS;
850 
851  in_->infile = afrt_get_option(INPUT_OCN);
852  in_->infile.append(" ");
853  in_->iprob = 1;
854  af_ocn_read_((char*)in_->infile.c_str(),
855  &in_->inw,
856  &in_->iopt,
857  &in_->isig,
858  &in_->isolz,
859  &in_->insza,
860  &in_->inthe,
861  &in_->inphi,
862  &in_->insig,
863  &in_->ilam1,
864  &in_->ilam2,
865  &in_->dlth,
866  &in_->dlph,
867  &in_->xr,
868  &in_->xi,
869  &in_->v,
870  &in_->thcel,
871  &in_->phcel,
872  &in_->wav[0],
873  &in_->tha[0],
874  &in_->sig_hg[0],
875  &in_->solz[0]);
876 
877 // std::cout << "Input file = " << in_->infile << std::endl;
878 
879  return status;
880 }
881 
883 {
884  int status = RT_SUCCESS;
885 
886  in_->infile = afrt_get_option(INPUT_RT1);
887  in_->infile.append(" ");
888  in_->ozone_lut = afrt_get_option(INPUT_OZONE_RT1);
889  in_->ozone_lut.append(" ");
890  in_->atm_lut = afrt_get_option(INPUT_ATM_RT1);
891  in_->atm_lut.append(" ");
892  in_->coeff_lut = afrt_get_option(INPUT_COEFF_RT1);
893  in_->coeff_lut.append(" ");
894  in_->phsdir = afrt_get_option(ODIR_PHS);
895  in_->phsdir.append(" ");
896  in_->rt1dir = afrt_get_option(ODIR_RT1);
897  in_->rt1dir.append(" ");
898 
899  af_rt1_read_((char*)in_->infile.c_str(),
900  (char*)in_->phsdir.c_str(),
901  (char*)in_->rt1dir.c_str(),
902  (char*)in_->ozone_lut.c_str(),
903  (char*)in_->atm_lut.c_str(),
904  (char*)in_->coeff_lut.c_str(),
905  &in_->nsd,
906  &in_->iair[0],
907  &in_->iprin,
908  &in_->ipsudo,
909  &in_->ioptn,
910  &in_->idust,
911  &in_->iaprof,
912  &in_->iblyr,
913  &in_->icld,
914  &in_->inch,
915  &in_->int55,
916  &in_->inrh,
917  &in_->ikset,
918  &in_->ilam1,
919  &in_->ilam2,
920  &in_->isd1,
921  &in_->isd2,
922  &in_->itau1,
923  &in_->itau2,
924  &in_->kznum,
925  &in_->krhum[0],
926  &in_->deltau,
927  &in_->psrfc,
928  &in_->ht_dust,
929  &in_->sigma_dust,
930  &in_->pcldtop,
931  &in_->pcldbtm,
932  &in_->taum55[0],
933  &in_->xlamb[0],
934  &in_->c0[0],
935  &in_->c1[0],
936  &in_->c2[0],
937  &in_->beta[0],
938  &in_->rho[0],
939  &in_->ppo[0],
940  &in_->x101[0],
941  &in_->temp101[0],
942  &in_->htdd[0],
943  &in_->ppodd[0],
944  &in_->dxdd[0],
945  &in_->znpdd[0],
946  &in_->nortau,
947  &in_->ioznab,
948  &in_->nrmww,
949  &in_->qst[0][0][0],
950  &in_->qtt[0][0][0],
951  &in_->qst5[0][0][0],
952  &in_->qtt5[0][0][0] );
953 
954 // std::cout << "Input file = " << in_->infile << std::endl;
955 
956  return status;
957 }
958 
960 {
961  int status = RT_SUCCESS;
962  in_->infile = afrt_get_option(INPUT_RT2);
963  in_->infile.append(" ");
964  in_->rt1dir = afrt_get_option(ODIR_RT1);
965  in_->rt1dir.append(" ");
966  in_->phsdir = afrt_get_option(ODIR_PHS);
967  in_->phsdir.append(" ");
968  in_->rt2dir = afrt_get_option(ODIR_RT2);
969  in_->rt2dir.append(" ");
970  in_->ocndir = afrt_get_option(ODIR_OCN);
971  in_->ocndir.append(" ");
972  in_->outdir = afrt_get_option(ODIR_RT2);
973  in_->outdir.append(" ");
974 
975  af_rt2_input_((char*)in_->infile.c_str(),
976  &in_->iref,
977  &in_->itrans,
978  &in_->iset,
979  &in_->irh1,
980  &in_->irh2,
981  &in_->ilm1,
982  &in_->ilm2,
983  &in_->isd1,
984  &in_->isd2,
985  &in_->itau1,
986  &in_->itau2,
987  &in_->ithe01,
988  &in_->ithe02,
989  &in_->iwnd1,
990  &in_->iwnd2,
991  &in_->inx,
992  &in_->inthe0,
993  &in_->inwl,
994  &in_->inrh,
995  &in_->iww[0],
996  &in_->krhum[0],
997  &in_->iprin,
998  &in_->ipol,
999  &in_->inpass1,
1000  &in_->inpass2,
1001  &in_->icrft,
1002  &in_->iactflx,
1003  &in_->isurf,
1004  &in_->iglint,
1005  &in_->iocn,
1006  &in_->ifoam,
1007  &in_->iwatr,
1008  &in_->iconc,
1009  &in_->dtheta,
1010  &in_->dphi,
1011  &in_->hcrft,
1012  &in_->rx[0],
1013  &in_->the0in[0],
1014  &in_->wwl[0],
1015  &in_->albwat[0]);
1016 
1017 // std::cout << "Input file = " << in_->infile << std::endl;
1018 
1019  return status;
1020 }
1021 
1022 /**************************************************************************
1023  * NAME: process()
1024  *
1025  * DESCRIPTION: Execute main algorithm
1026  *
1027  *************************************************************************/
1028 
1030 {
1031  int status = RT_SUCCESS;
1032  return status;
1033 }
1034 
1036 {
1037  int status = RT_SUCCESS;
1038 
1039  out_->outdir = afrt_get_option(ODIR_PHS);
1040  out_->outdir.append(" ");
1041 
1042  size_t dlam = in_->ilam2 - in_->ilam1 + 1;
1043  size_t dsd = in_->isd2 - in_->isd1 + 1;
1044 
1045  out_->ifunc.resize(boost::extents[dsd]);
1046  out_->mfunc.resize(boost::extents[dsd]);
1047  out_->angl.resize(boost::extents[ntf]);
1048  out_->ww.resize(boost::extents[dlam]);
1049  out_->refr.resize(boost::extents[dlam][dsd][nmd]);
1050  out_->refi.resize(boost::extents[dlam][dsd][nmd]);
1051  out_->rg.resize(boost::extents[dlam][dsd][nmd]);
1052  out_->sig.resize(boost::extents[dlam][dsd][nmd]);
1053  out_->npar.resize(boost::extents[dlam][dsd][nmd]);
1054  out_->dx.resize(boost::extents[dlam][dsd][nmd]);
1055  out_->epar.resize(boost::extents[dlam][dsd][nmd]);
1056 
1057  for (int iLm=in_->ilam1; iLm<=in_->ilam2; iLm++) {
1058  int oLm = iLm - in_->ilam1;
1059  out_->ww[oLm] = in_->ww[iLm][0];
1060  for (int iSd=in_->isd1; iSd<=in_->isd2; iSd++) {
1061  int oSd = iSd - in_->isd1;
1062  out_->ifunc[oSd] = in_->ifunc[iSd];
1063  out_->mfunc[oSd] = in_->mfunc[iSd];
1064  for (int iMd=0; iMd<nmd; iMd++) {
1065  out_->refr[oLm][oSd][iMd] = in_->refr[oLm][oSd][iMd];
1066  out_->refi[oLm][oSd][iMd] = in_->refi[oLm][oSd][iMd];
1067  out_->rg[oLm][oSd][iMd] = in_->rg[oLm][oSd][iMd];
1068  out_->sig[oLm][oSd][iMd] = in_->sig[oLm][oSd][iMd];
1069  out_->npar[oLm][oSd][iMd] = in_->npar[oLm][oSd][iMd];
1070  out_->dx[oLm][oSd][iMd] = in_->dx[oLm][oSd][iMd];
1071  out_->epar[oLm][oSd][iMd] = in_->epar[oLm][oSd][iMd];
1072  }
1073  }
1074  }
1075 
1076  out_->rmin.resize(boost::extents[dlam][dsd][nmd]);
1077  out_->rmax.resize(boost::extents[dlam][dsd][nmd]);
1078  out_->deltar.resize(boost::extents[dlam][dsd][nmd]);
1079  out_->deltax.resize(boost::extents[dlam][dsd][nmd]);
1080  out_->r11.resize(boost::extents[dlam][dsd]);
1081  out_->r11.resize(boost::extents[dlam][dsd]);
1082  out_->r11.resize(boost::extents[dlam][dsd]);
1083  out_->r11.resize(boost::extents[dlam][dsd]);
1084  out_->r22.resize(boost::extents[dlam][dsd]);
1085  out_->r33.resize(boost::extents[dlam][dsd]);
1086  out_->r44.resize(boost::extents[dlam][dsd]);
1087  out_->reff.resize(boost::extents[dlam][dsd]);
1088  out_->veff.resize(boost::extents[dlam][dsd]);
1089  out_->ccnsml.resize(boost::extents[dlam][dsd]);
1090  out_->bsr.resize(boost::extents[dlam][dsd]);
1091  out_->salb.resize(boost::extents[dlam][dsd]);
1092  out_->asf.resize(boost::extents[dlam][dsd]);
1093  out_->qscat.resize(boost::extents[dlam][dsd]);
1094  out_->qext.resize(boost::extents[dlam][dsd]);
1095  out_->phfu.resize(boost::extents[dlam][dsd][ntf]);
1096  out_->pol.resize(boost::extents[dlam][dsd][ntf]);
1097  out_->wt.resize(boost::extents[dlam][dsd][ntf]);
1098  out_->rbar.resize(boost::extents[dlam][dsd][ntf]);
1099  out_->dnzp.resize(boost::extents[dlam][dsd][ntf]);
1100  out_->dnp.resize(boost::extents[dlam][dsd][ntf]);
1101  out_->dvp.resize(boost::extents[dlam][dsd][ntf]);
1102  out_->sumnp.resize(boost::extents[dlam][dsd][ntf]);
1103  out_->t.resize(boost::extents[dlam][dsd][nstk][ntf]);
1104  out_->thd.resize(boost::extents[dlam][dsd][ntf]);
1105 
1106  long int tsv = 0;
1107  for (int iLm=in_->ilam1; iLm<=in_->ilam2; iLm++) {
1108  for (int iSd=in_->isd1; iSd<=in_->isd2; iSd++) {
1109 
1110  int oLm = iLm - in_->ilam1;
1111  int oSd = iSd - in_->isd1;
1112 
1113  af_phs_process_( (char*)out_->outdir.c_str(),
1114  &iLm, &iSd,
1115  &in_->isd1,
1116  &in_->isd2,
1117  &in_->ifunc[0],
1118  &in_->jnorm[0],
1119  &in_->jrgm[0],
1120  &in_->mfunc[0],
1121  &in_->irh[0],
1122  &in_->iset[0],
1123  &in_->xtitle[0][0],
1124  &in_->ww[0][0],
1125  &in_->refr[0][0][0],
1126  &in_->refi[0][0][0],
1127  &in_->rg[0][0][0],
1128  &in_->sig[0][0][0],
1129  &in_->npar[0][0][0],
1130  &in_->dx[0][0][0],
1131  &in_->epar[0][0][0],
1132 
1133  &out_->rmin[oLm][oSd][0],
1134  &out_->rmax[oLm][oSd][0],
1135  &out_->deltar[oLm][oSd][0],
1136  &out_->deltax[oLm][oSd][0],
1137  &out_->r11[oLm][oSd],
1138  &out_->r22[oLm][oSd],
1139  &out_->r33[oLm][oSd],
1140  &out_->r44[oLm][oSd],
1141  &out_->reff[oLm][oSd],
1142  &out_->veff[oLm][oSd],
1143  &out_->ccnsml[oLm][oSd],
1144  &out_->bsr[oLm][oSd],
1145  &out_->salb[oLm][oSd],
1146  &out_->asf[oLm][oSd],
1147  &out_->qscat[oLm][oSd],
1148  &out_->qext[oLm][oSd],
1149  &out_->angl[0],
1150  &out_->phfu[oLm][oSd][0],
1151  &out_->pol[oLm][oSd][0],
1152  &out_->t[oLm][oSd][0][0],
1153  &out_->thd[oLm][oSd][0],
1154  &out_->rbar[oLm][oSd][0],
1155  &out_->dnzp[oLm][oSd][0],
1156  &out_->dnp[oLm][oSd][0],
1157  &out_->dvp[oLm][oSd][0],
1158  &out_->sumnp[oLm][oSd][0],
1159  &out_->wt[oLm][oSd][0] );
1160 
1161  struct timeval tp;
1162  gettimeofday(&tp, NULL);
1163  long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
1164  long int tdiff = ms - tsv;
1165  tsv = ms;
1166  cout << "Wavelength index: "<<iLm<<" Model index: "<<iSd<<" : Elapsed time (ms): "<<tdiff<<endl;
1167  }
1168  }
1169  return status;
1170 }
1171 
1173 {
1174  int status = RT_SUCCESS;
1175 
1176  struct timeval tp;
1177  gettimeofday(&tp, NULL);
1178  long int tsv = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
1179 
1180  for (int iLm=in_->ilm1; iLm<=in_->ilm2; iLm++) {
1181  size_t oLm = iLm - in_->ilm1;
1182 
1183  for (int iSd=in_->isd1; iSd<=in_->isd2; iSd++) {
1184 
1185  in_->iset = phs_->in_->iset[iSd-1];
1186 
1187  size_t oSd = iSd - in_->isd1;
1188  int pLm = phs_->in_->ilam1 + iLm -1;
1189  if (!phs_->bNC4_) {
1190  af_phs_process_( (char*)in_->phsdir.c_str(),
1191  &pLm, &iSd,
1192  &phs_->in_->isd1,
1193  &phs_->in_->isd2,
1194  &phs_->in_->ifunc[0],
1195  &phs_->in_->jnorm[0],
1196  &phs_->in_->jrgm[0],
1197  &phs_->in_->mfunc[0],
1198  &phs_->in_->irh[0],
1199  &phs_->in_->iset[0],
1200  &phs_->in_->xtitle[0][0],
1201  &phs_->in_->ww[0][0],
1202  &phs_->in_->refr[0][0][0],
1203  &phs_->in_->refi[0][0][0],
1204  &phs_->in_->rg[0][0][0],
1205  &phs_->in_->sig[0][0][0],
1206  &phs_->in_->npar[0][0][0],
1207  &phs_->in_->dx[0][0][0],
1208  &phs_->in_->epar[0][0][0],
1209 
1210  &phs_->out_->rmin[oLm][oSd][0],
1211  &phs_->out_->rmax[oLm][oSd][0],
1212  &phs_->out_->deltar[oLm][oSd][0],
1213  &phs_->out_->deltax[oLm][oSd][0],
1214  &phs_->out_->r11[oLm][oSd],
1215  &phs_->out_->r22[oLm][oSd],
1216  &phs_->out_->r33[oLm][oSd],
1217  &phs_->out_->r44[oLm][oSd],
1218  &phs_->out_->reff[oLm][oSd],
1219  &phs_->out_->veff[oLm][oSd],
1220  &phs_->out_->ccnsml[oLm][oSd],
1221  &phs_->out_->bsr[oLm][oSd],
1222  &phs_->out_->salb[oLm][oSd],
1223  &phs_->out_->asf[oLm][oSd],
1224  &phs_->out_->qscat[oLm][oSd],
1225  &phs_->out_->qext[oLm][oSd],
1226  &phs_->out_->angl[0],
1227  &phs_->out_->phfu[oLm][oSd][0],
1228  &phs_->out_->pol[oLm][oSd][0],
1229  &phs_->out_->t[oLm][oSd][0][0],
1230  &phs_->out_->thd[oLm][oSd][0],
1231  &phs_->out_->rbar[oLm][oSd][0],
1232  &phs_->out_->dnzp[oLm][oSd][0],
1233  &phs_->out_->dnp[oLm][oSd][0],
1234  &phs_->out_->dvp[oLm][oSd][0],
1235  &phs_->out_->sumnp[oLm][oSd][0],
1236  &phs_->out_->wt[oLm][oSd][0] );
1237  }
1238 
1239  for (int iTau=in_->itau1; iTau<=in_->itau2; iTau++) {
1240  size_t oTau = iTau - in_->itau1;
1241  int tmp = 1;
1242  af_rt1_process_( (char*)in_->rt1dir.c_str(),
1243  &iLm, &iSd, &tmp, &iTau,
1244  &rt1_->in_->iair[0],
1245  &rt1_->in_->iprin,
1246  &rt1_->in_->ipsudo,
1247  &rt1_->in_->ioptn,
1248  &rt1_->in_->idust,
1249  &rt1_->in_->iaprof,
1250  &rt1_->in_->iblyr,
1251  &rt1_->in_->icld,
1252  &rt1_->in_->inch,
1253  &rt1_->in_->int55,
1254  &in_->insd,
1255  &in_->inrh,
1256  &phs_->in_->iset[iSd-1],
1257  &rt1_->in_->kznum,
1258  &phs_->in_->irh[0],
1259  &rt1_->in_->deltau,
1260  &rt1_->in_->psrfc,
1261  &rt1_->in_->ht_dust,
1262  &rt1_->in_->sigma_dust,
1263  &rt1_->in_->pcldtop,
1264  &rt1_->in_->pcldbtm,
1265  &rt1_->in_->taum55[0],
1266  &rt1_->in_->xlamb[0],
1267  &rt1_->in_->c0[0],
1268  &rt1_->in_->c1[0],
1269  &rt1_->in_->c2[0],
1270  &rt1_->in_->beta[0],
1271  &rt1_->in_->rho[0],
1272  &rt1_->in_->ppo[0],
1273  &rt1_->in_->x101[0],
1274  &rt1_->in_->temp101[0],
1275  &rt1_->in_->htdd[0],
1276  &rt1_->in_->ppodd[0],
1277  &rt1_->in_->dxdd[0],
1278  &rt1_->in_->znpdd[0],
1279  &rt1_->in_->nortau,
1280  &rt1_->in_->ioznab,
1281  &rt1_->in_->nrmww,
1282  &phs_->out_->qscat[oLm][oSd],
1283  &phs_->out_->qext[oLm][oSd],
1284  &rt1_->in_->qst5[iLm-1][iSd-1][iTau-1],
1285  &rt1_->in_->qtt5[iLm-1][iSd-1][iTau-1],
1286  // Adjust for quirk in rt1_read
1287  &rt1_->out_->htlvl[0][0][0][1],
1288  &rt1_->out_->pplvl[0][0][0][1],
1289  &rt1_->out_->fr[0][0][0][0],
1290  &rt1_->out_->fn[0][0][0][0],
1291  &rt1_->out_->fa[0][0][0][0],
1292  &rt1_->out_->ftot[0][0][0][0],
1293  &rt1_->out_->dtrr[0][0][0][0],
1294  &rt1_->out_->dtmm[0][0][0][0],
1295  &rt1_->out_->dtaa[0][0][0][0],
1296  &rt1_->out_->dtot[0][0][0][0],
1297  &rt1_->out_->trp[0][0][0],
1298  &rt1_->out_->tmp[0][0][0],
1299  &rt1_->out_->tap[0][0][0],
1300  &rt1_->out_->salb[0][0][0][0],
1301  &rt1_->out_->turbhl[0][0][0][0],
1302  &rt1_->out_->dx[0][0][0][0],
1303  &rt1_->out_->x[0][0][0][0],
1304  &rt1_->out_->tozn101[0][0][0][0],
1305  &rt1_->out_->htdv[0][0][0][0],
1306  &rt1_->out_->pdv[0][0][0][0],
1307  &rt1_->out_->taur[0][0][0][0],
1308  &rt1_->out_->taum[0][0][0][0],
1309  &rt1_->out_->taua[0][0][0][0],
1310  &rt1_->out_->tau[0][0][0][0],
1311  &rt1_->out_->wvlth[0][0][0],
1312  &rt1_->out_->psrfc[0][0][0],
1313  &rt1_->out_->rho[0][0][0],
1314  &rt1_->out_->xozn[0][0][0],
1315  &rt1_->out_->tautot[0][0][0],
1316  &rt1_->out_->dtau1[0][0][0],
1317  &rt1_->out_->nolyr[0][0][0],
1318  &rt1_->out_->tcar[0][0][0],
1319  &rt1_->out_->twat[0][0][0],
1320  &rt1_->out_->tozn[0][0][0],
1321  &rt1_->out_->ifc[0][0][0],
1322  &rt1_->out_->nmodl[0][0][0]);
1323 
1324 // Reduce precision to match ascii files
1325 // double dtot[nlyr];
1326 // for (int i=0; i<nlyr; i++) {
1327 // dtot[i] = (floor(rt1_->out_->dtot[0][0][0][i]*10e6))/10e6;
1328 // }
1329 
1330 // Adjust for quirk in rt1_read
1331  rt1_->out_->htlvl[0][0][0][0] = 84.0;
1332  rt1_->out_->pplvl[0][0][0][0] = 5.3040e-6;
1333  for (int iWnd=in_->iwnd1; iWnd<=in_->iwnd2; iWnd++) {
1334  int oWnd = iWnd - in_->iwnd1;
1335  int sWnd = iWnd;
1336  int tmp_iref = in_->iref;
1337 
1338  if(ocn_->in_->sig_hg[iWnd-1] == 0.0) {
1339  tmp_iref = 1;
1340  } else {
1341 
1342  af_ocn_process_((char*)in_->ocndir.c_str(),
1343  &iLm, &sWnd,
1344  &ocn_->in_->iopt,
1345  &ocn_->in_->isig,
1346  &ocn_->in_->isolz,
1347  &ocn_->in_->insza,
1348  &ocn_->in_->inthe,
1349  &ocn_->in_->inphi,
1350  &ocn_->in_->dlth,
1351  &ocn_->in_->dlph,
1352  &ocn_->in_->xr,
1353  &ocn_->in_->xi,
1354  &ocn_->in_->v,
1355  &ocn_->in_->thcel,
1356  &ocn_->in_->phcel,
1357  &ocn_->in_->wav[0],
1358  &ocn_->in_->tha[0],
1359  &ocn_->in_->sig_hg[0],
1360  &ocn_->in_->solz[0],
1361  &ocn_->in_->iprob,
1362 
1363  &ocn_->out_->thp[0],
1364  &ocn_->out_->phcnd[0],
1365  &ocn_->out_->thcnd[0],
1366  &ocn_->out_->txx[0][0][0][0][0][0],
1367  &ocn_->out_->pti[0][0][0][0][0][0],
1368  &ocn_->out_->xinlpi[0][0][0][0][0],
1369  &ocn_->out_->xi_hgpi[0][0][0][0][0],
1370  &ocn_->out_->xin2pi[0][0][0][0][0],
1371  &ocn_->out_->xin2top[0][0][0][0][0] );
1372  }
1373 
1374  af_rt2_process_((char*)out_->outdir.c_str(),
1375  &iLm, &iSd, &tmp, &iTau, &iWnd,
1376  &tmp_iref,
1377  &in_->itrans,
1378  &phs_->in_->iset[iSd-1],
1379  &in_->irh1,
1380  &in_->irh2,
1381  &in_->ilm1,
1382  &in_->ilm2,
1383  &in_->isd1,
1384  &in_->isd2,
1385  &in_->itau1,
1386  &in_->itau2,
1387  &in_->ithe01,
1388  &in_->ithe02,
1389  &in_->iwnd1,
1390  &in_->iwnd2,
1391  &in_->inx,
1392  &in_->inthe0,
1393  &in_->inwl,
1394  &in_->inrh,
1395  &in_->insd,
1396  &in_->iww[0],
1397  &phs_->in_->irh[0],
1398  &in_->iprin,
1399  &in_->ipol,
1400  &in_->inpass1,
1401  &in_->inpass2,
1402  &in_->icrft,
1403  &in_->iactflx,
1404  &in_->isurf,
1405  &in_->iglint,
1406  &in_->iocn,
1407  &in_->ifoam,
1408  &in_->iwatr,
1409  &in_->iconc,
1410  &in_->dtheta,
1411  &in_->dphi,
1412  &in_->hcrft,
1413  &in_->rx[0],
1414  &in_->the0in[0],
1415  &in_->wwl[0],
1416  &in_->albwat[0],
1417  //phs
1418  &phs_->in_->ifunc[iSd-1],
1419  &phs_->in_->mfunc[iSd-1],
1420  &phs_->in_->refr[pLm-1][iSd-1][0],
1421  &phs_->in_->refi[pLm-1][iSd-1][0],
1422  &phs_->out_->rmin[oLm][oSd][0],
1423  &phs_->out_->rmax[oLm][oSd][0],
1424  &phs_->out_->deltar[oLm][oSd][0],
1425  &phs_->out_->deltax[oLm][oSd][0],
1426  &phs_->in_->rg[pLm-1][iSd-1][0],
1427  &phs_->in_->sig[pLm-1][iSd-1][0],
1428  &phs_->in_->npar[pLm-1][iSd-1][0],
1429  &phs_->out_->r11[oLm][oSd],
1430  &phs_->out_->r22[oLm][oSd],
1431  &phs_->out_->r33[oLm][oSd],
1432  &phs_->out_->r44[oLm][oSd],
1433  &phs_->out_->reff[oLm][oSd],
1434  &phs_->out_->veff[oLm][oSd],
1435  &phs_->out_->ccnsml[oLm][oSd],
1436  &phs_->out_->bsr[oLm][oSd],
1437  &phs_->out_->salb[oLm][oSd],
1438  &phs_->out_->asf[oLm][oSd],
1439  &phs_->out_->qscat[oLm][oSd],
1440  &phs_->out_->qext[oLm][oSd],
1441  &phs_->out_->t[oLm][oSd][0][0],
1442  &phs_->out_->thd[oLm][oSd][0],
1443  //ocn
1444  &ocn_->in_->xr,
1445  &ocn_->in_->xi,
1446  &ocn_->in_->v,
1447  &ocn_->in_->thcel,
1448  &ocn_->in_->phcel,
1449  &ocn_->out_->txx[0][0][0][0][0][0],
1450  &ocn_->out_->pti[0][0][0][0][0][0],
1451  //rt1
1452  &rt1_->out_->wvlth[0][0][0],
1453  &rt1_->out_->psrfc[0][0][0],
1454  &rt1_->out_->rho[0][0][0],
1455  &rt1_->out_->xozn[0][0][0],
1456  &rt1_->out_->tautot[0][0][0],
1457  &rt1_->out_->dtau1[0][0][0],
1458  &rt1_->out_->trp[0][0][0],
1459  &rt1_->out_->tmp[0][0][0],
1460  &rt1_->out_->tap[0][0][0],
1461  &rt1_->out_->tcar[0][0][0],
1462  &rt1_->out_->twat[0][0][0],
1463  &rt1_->out_->tozn[0][0][0],
1464  &rt1_->out_->htlvl[0][0][0][0],
1465  &rt1_->out_->pplvl[0][0][0][0],
1466  &rt1_->out_->dtrr[0][0][0][0],
1467  &rt1_->out_->dtmm[0][0][0][0],
1468  &rt1_->out_->dtaa[0][0][0][0],
1469  &rt1_->out_->dtot[0][0][0][0],
1470  &rt1_->out_->htdv[0][0][0][0],
1471  &rt1_->out_->pdv[0][0][0][0],
1472  &rt1_->out_->taur[0][0][0][0],
1473  &rt1_->out_->taum[0][0][0][0],
1474  &rt1_->out_->taua[0][0][0][0],
1475  &rt1_->out_->ifc[0][0][0],
1476  &rt1_->out_->nmodl[0][0][0],
1477  &rt1_->out_->nolyr[0][0][0],
1478  &rt1_->in_->ipsudo,
1479 
1480  &in_->bfr[iLm-1][iSd-1][iTau-1][iWnd-1][0],
1481  &out_->tma[0][0][0][0][0],
1482  &out_->tmb[0][0][0][0][0],
1483  &out_->tmc[0][0][0][0][0],
1484  &out_->tmfd[0][0][0][0][0],
1485  &out_->tmfu[0][0][0][0][0],
1486  &out_->tms[0][0][0][0][0],
1487  &out_->tmg[0][0][0][0][0],
1488  &out_->tmh[0][0][0][0][0],
1489  &out_->tmp[0][0][0][0][0],
1490  &out_->tmq[0][0][0][0][0],
1491  &out_->tmt[0][0][0][0][0],
1492  &out_->tmpp[0][0][0][0][0],
1493  &out_->tmqq[0][0][0][0][0],
1494  &out_->tmrr[0][0][0][0][0],
1495  &out_->tmss[0][0][0][0][0],
1496  &out_->transm[0][0][0][0][0],
1497  &out_->tmcfd[0][0][0][0][0],
1498  &out_->tmcfu[0][0][0][0][0],
1499  &out_->tmf1[0][0][0][0][0][0],
1500  &out_->tmf2[0][0][0][0][0],
1501  &out_->xzeroz[0][0][0][0][0][0][0][0],
1502  &out_->xzerod[0][0][0][0][0][0][0][0],
1503  &out_->tupz[0][0][0][0][0][0][0][0],
1504  &out_->tdwnz[0][0][0][0][0][0][0][0]);
1505 
1506 // Afrt* af = new Afrt();
1507 // af->rt2(iLm, iSd, iTau, iWnd, in_, out_, rt1_->in_, rt1_->out_,
1508 // ocn_->in_, ocn_->out_, phs_->in_, phs_->out_);
1509 // delete af;
1510 
1511  struct timeval tp;
1512  gettimeofday(&tp, NULL);
1513  long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
1514  long int tdiff = ms - tsv;
1515  tsv = ms;
1516  cout <<iLm<<" : "<<iSd<<" : "<< iTau<<": "<< iWnd<<" Elapsed ms: "<<tdiff<<endl;
1517  cout <<"qscat : "<<phs_->out_->qscat[oLm][oSd]<<" qext : "<< phs_->out_->qext[oLm][oSd]<<endl;
1518  out_->wl = in_->wwl[iLm-1];
1519  out_->wnd = roundf(ocn_->in_->v*100.0)/100.0;
1520  out_->tau = rt1_->in_->taum55[iTau-1];
1521  write_nc4(oLm, oSd, oTau, oWnd);
1522  }
1523  }
1524  }
1525  }
1526 
1527  return status;
1528 }
1529 
1530 
1531 
1533 {
1534  int status = RT_SUCCESS;
1535 
1536 #if WITH_MPI
1537 
1538  struct timeval tp;
1539  gettimeofday(&tp, NULL);
1540  long int tsv = tp.tv_sec * 1000 + tp.tv_usec / 1000; //get current timestamp in milliseconds
1541 
1542  MPI_Status mpi_status;
1543 
1544  int ntasks, nLm, nSd, nTau, nWnd;
1545 
1546  int iLm, iSd, iTau, iWnd;
1547  size_t oLm, oSd, oTau, oWnd;
1548 
1549  nLm = in_->ilm2 - in_->ilm1 + 1;
1550  nSd = iSd=in_->isd2 - in_->isd1 + 1;
1551  nTau = iTau=in_->itau2 - in_->itau1 + 1;
1552  nWnd = iWnd=in_->iwnd2 - in_->iwnd1 + 1;
1553 
1554  ntasks = nLm * nSd * nTau * nWnd;
1555 
1556  int itask;
1557  int task_vec[4];
1558  int prev_iLm = 0;
1559  int prev_iSd = 0;
1560  int prev_iTau = 0;
1561  int prev_iWnd = 0;
1562 
1563  size_t dlam = in_->ilm2 - in_->ilm1 + 1;
1564  size_t dsd = in_->isd2 - in_->isd1 + 1;
1565  size_t dtau = in_->itau2 - in_->itau1 + 1;
1566  size_t dwnd = in_->iwnd2 - in_->iwnd1 + 1;
1567  size_t dnsza = in_->inthe0;
1568  size_t dnthe = in_->inthe0;
1569  size_t dnphi = (360.0/in_->dphi)/2.0 +1;
1570 
1571  double *xzeroz = new double[dnsza*dnthe*dnphi*nstk];
1572  double *xzerod = new double[dnsza*dnthe*dnphi*nstk];
1573 
1574  if (mpi_id == 0) {
1575 
1577  // MASTER SECTION //
1579 
1580  int n_complete;
1581  int itask, iproc, icomplete;
1582 
1583  int *task_status, *busy;
1584  int **task_vec = new int *[ntasks];
1585  task_status = new int [ntasks];
1586  busy = new int [n_mpi_nodes-1];
1587 
1588  // Define task vectors
1589  task_vec[0] = new int[4*ntasks];
1590  for (size_t i=1; i<ntasks; i++) task_vec[i] = task_vec[i-1] + 4;
1591 
1592  int k = 0;
1593  for (int iLm=in_->ilm1; iLm<=in_->ilm2; iLm++) {
1594  for (int iSd=in_->isd1; iSd<=in_->isd2; iSd++) {
1595  for (int iTau=in_->itau1; iTau<=in_->itau2; iTau++) {
1596  for (int iWnd=in_->iwnd1; iWnd<=in_->iwnd2; iWnd++) {
1597  task_vec[k][0] = iLm;
1598  task_vec[k][1] = iSd;
1599  task_vec[k][2] = iTau;
1600  task_vec[k][3] = iWnd;
1601  k++;
1602  }
1603  }
1604  }
1605  }
1606 
1607  for (size_t i=0 ; i<ntasks; i++) task_status[i] = 0;
1608  for (size_t i=0 ; i<=n_mpi_nodes-1; i++) busy[i] = 0;
1609 
1610  n_complete = 0;
1611 
1612  while (n_complete < ntasks) {
1613 
1614  for (iproc=1; iproc<n_mpi_nodes; iproc++) {
1615  if (busy[iproc-1] == 0 && ((iproc-1) % 1 == mpi_id) && n_complete < ntasks) {
1616  for (itask=1; itask<=ntasks; itask++) {
1617  if (task_status[itask-1] == 0) {
1618  printf("%s %d %d %s %d %s %d %d %d %d\n",
1619  "MASTER| Sending to process: ", mpi_id,
1620  iproc, " task: ", itask, " iLm, iSd, iTau, iWnd: ",
1621  task_vec[itask-1][0], task_vec[itask-1][1],
1622  task_vec[itask-1][2], task_vec[itask-1][3]);
1623  MPI_Send(&itask, 1, MPI_INTEGER, iproc, 0, MPI_COMM_WORLD);
1624  MPI_Send(task_vec[itask-1], 4, MPI_INTEGER, iproc, 0,
1625  MPI_COMM_WORLD);
1626  task_status[itask-1] = 1;
1627  busy[iproc-1] = 1;
1628  break;
1629  }
1630  } // task loop
1631  }
1632  } // proc loop
1633 
1634  int ret_task_vec[4];
1635 
1636  MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &mpi_status);
1637 
1638  // icomplete (1-based)
1639  MPI_Recv(&icomplete, 1, MPI_INTEGER, mpi_status.MPI_SOURCE,
1640  MPI_ANY_TAG, MPI_COMM_WORLD, &mpi_status);
1641 
1642  MPI_Recv(ret_task_vec, 4, MPI_INTEGER, mpi_status.MPI_SOURCE,
1643  MPI_ANY_TAG, MPI_COMM_WORLD, &mpi_status);
1644 
1645  MPI_Recv(&out_->wl, 1, MPI_DOUBLE, mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1646  MPI_COMM_WORLD, &mpi_status);
1647 
1648  MPI_Recv(&out_->tau, 1, MPI_DOUBLE, mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1649  MPI_COMM_WORLD, &mpi_status);
1650 
1651  MPI_Recv(&out_->wnd, 1, MPI_DOUBLE, mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1652  MPI_COMM_WORLD, &mpi_status);
1653 
1654  MPI_Recv(&rt1_->out_->tautot[0][0][0], 1, MPI_DOUBLE,
1655  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1656  MPI_COMM_WORLD, &mpi_status);
1657 
1658  MPI_Recv(&rt1_->out_->trp[0][0][0], 1, MPI_DOUBLE,
1659  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1660  MPI_COMM_WORLD, &mpi_status);
1661 
1662  MPI_Recv(&rt1_->out_->tmp[0][0][0], 1, MPI_DOUBLE,
1663  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1664  MPI_COMM_WORLD, &mpi_status);
1665 
1666  MPI_Recv(&rt1_->out_->tap[0][0][0], 1, MPI_DOUBLE,
1667  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1668  MPI_COMM_WORLD, &mpi_status);
1669 
1670  MPI_Recv(&rt1_->out_->twat[0][0][0], 1, MPI_DOUBLE,
1671  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1672  MPI_COMM_WORLD, &mpi_status);
1673 
1674  MPI_Recv(&out_->tmb[0][0][0][0][0], dnsza, MPI_DOUBLE,
1675  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1676  &mpi_status);
1677 
1678  MPI_Recv(&out_->tmc[0][0][0][0][0], dnsza, MPI_DOUBLE,
1679  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1680  &mpi_status);
1681 
1682  MPI_Recv(&out_->tmfd[0][0][0][0][0], dnsza, MPI_DOUBLE,
1683  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1684  &mpi_status);
1685 
1686  MPI_Recv(&out_->tmfu[0][0][0][0][0], dnsza, MPI_DOUBLE,
1687  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1688  &mpi_status);
1689 
1690  MPI_Recv(&out_->tms[0][0][0][0][0], dnsza, MPI_DOUBLE,
1691  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1692  &mpi_status);
1693 
1694  MPI_Recv(&out_->transm[0][0][0][0][0], dnsza, MPI_DOUBLE,
1695  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1696  &mpi_status);
1697 
1698 
1699  MPI_Recv(&out_->tmq[0][0][0][0][0], dnsza, MPI_DOUBLE,
1700  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1701  MPI_COMM_WORLD, &mpi_status);
1702 
1703  MPI_Recv(&out_->tmpp[0][0][0][0][0], dnsza, MPI_DOUBLE,
1704  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1705  MPI_COMM_WORLD, &mpi_status);
1706 
1707  MPI_Recv(&out_->tmqq[0][0][0][0][0], dnsza, MPI_DOUBLE,
1708  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1709  MPI_COMM_WORLD, &mpi_status);
1710 
1711  MPI_Recv(&out_->tmrr[0][0][0][0][0], dnsza, MPI_DOUBLE,
1712  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1713  MPI_COMM_WORLD, &mpi_status);
1714 
1715  MPI_Recv(&out_->tmss[0][0][0][0][0], dnsza, MPI_DOUBLE,
1716  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1717  MPI_COMM_WORLD, &mpi_status);
1718 
1719  MPI_Recv(&out_->tmg[0][0][0][0][0], dnsza, MPI_DOUBLE,
1720  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1721  MPI_COMM_WORLD, &mpi_status);
1722 
1723  MPI_Recv(&out_->tmh[0][0][0][0][0], dnsza, MPI_DOUBLE,
1724  mpi_status.MPI_SOURCE, MPI_ANY_TAG,
1725  MPI_COMM_WORLD, &mpi_status);
1726 
1727 
1728 
1729  MPI_Recv(xzeroz, dnsza*dnthe*dnphi*nstk, MPI_DOUBLE,
1730  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1731  &mpi_status);
1732 
1733 
1734  int cnt=0;
1735  for (size_t i=0; i<dnsza; i++) {
1736  for (size_t j=0; j<dnthe; j++) {
1737  for (size_t k=0; k<dnphi; k++) {
1738  for (size_t s=0; s<nstk; s++) {
1739  out_->xzeroz[0][0][0][0][i][j][k][s] = xzeroz[cnt++];
1740  }
1741  }
1742  }
1743  }
1744 
1745  MPI_Recv(xzerod, dnsza*dnthe*dnphi*nstk, MPI_DOUBLE,
1746  mpi_status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
1747  &mpi_status);
1748 
1749  cnt=0;
1750  for (size_t i=0; i<dnsza; i++) {
1751  for (size_t j=0; j<dnthe; j++) {
1752  for (size_t k=0; k<dnphi; k++) {
1753  for (size_t s=0; s<nstk; s++) {
1754  out_->xzerod[0][0][0][0][i][j][k][s] = xzerod[cnt++];
1755  }
1756  }
1757  }
1758  }
1759 
1760  task_status[icomplete-1] = 2;
1761  n_complete++;
1762  busy[mpi_status.MPI_SOURCE-1] = 0;
1763  printf("%s%d%s%d %s %d ", "MASTER| Received message from process: ",
1764  mpi_status.MPI_SOURCE, " number complete: ", n_complete,
1765  " task: ", icomplete);
1766 
1767  // write nc4
1768  oLm = ret_task_vec[0];
1769  oSd = ret_task_vec[1];
1770  oTau = ret_task_vec[2];
1771  oWnd = ret_task_vec[3];
1772 
1773  printf("write_nc4: %d %d %d %d\n", oLm+1, oSd+1, oTau+1, oWnd+1);
1774  write_nc4(oLm, oSd, oTau, oWnd);
1775  } // while loop
1776 
1777  printf("%s\n", "Sending all complete message");
1778  int zero=0;
1779  for (iproc=1; iproc<n_mpi_nodes; iproc++) {
1780  MPI_Send(&zero, 1, MPI_INTEGER, iproc, 0, MPI_COMM_WORLD);
1781  }
1782 
1783  delete[] task_status;
1784  delete[] busy;
1785  delete[] task_vec[0];
1786  delete[] task_vec;
1787 
1788  } else {
1789 
1790 
1792  // WORKER SECTION //
1794 
1795  MPI_Status mpi_status;
1796 
1797  while (1) {
1798  MPI_Probe(0, MPI_ANY_TAG, MPI_COMM_WORLD, &mpi_status);
1799  MPI_Recv(&itask, 1, MPI_INTEGER, 0, MPI_ANY_TAG, MPI_COMM_WORLD,
1800  &mpi_status);
1801  if (itask == 0) break;
1802  MPI_Recv(task_vec, 4, MPI_INTEGER, 0, MPI_ANY_TAG, MPI_COMM_WORLD,
1803  &mpi_status);
1804 
1805  iLm = task_vec[0];
1806  iSd = task_vec[1];
1807  iTau = task_vec[2];
1808  iWnd = task_vec[3];
1809 
1810  printf("%s %d iLm: %d iSd: %d iTau: %d iWnd: %d\n", "WORKER|",
1811  mpi_id, iLm, iSd, iTau, iWnd);
1812 
1813  size_t oLm = iLm - in_->ilm1;
1814  size_t oSd = iSd - in_->isd1;
1815  int pLm = phs_->in_->ilam1 + iLm -1;
1816  if (!phs_->bNC4_ && (iLm != prev_iLm || iSd != prev_iSd)) {
1817  // std::cout << "before phs" << std::endl;
1818  af_phs_process_( (char*)in_->phsdir.c_str(),
1819  &pLm, &iSd,
1820  &phs_->in_->isd1,
1821  &phs_->in_->isd2,
1822  &phs_->in_->ifunc[0],
1823  &phs_->in_->jnorm[0],
1824  &phs_->in_->jrgm[0],
1825  &phs_->in_->mfunc[0],
1826  &phs_->in_->irh[0],
1827  &phs_->in_->iset[0],
1828  &phs_->in_->xtitle[0][0],
1829  &phs_->in_->ww[0][0],
1830  &phs_->in_->refr[0][0][0],
1831  &phs_->in_->refi[0][0][0],
1832  &phs_->in_->rg[0][0][0],
1833  &phs_->in_->sig[0][0][0],
1834  &phs_->in_->npar[0][0][0],
1835  &phs_->in_->dx[0][0][0],
1836  &phs_->in_->epar[0][0][0],
1837 
1838  &phs_->out_->rmin[oLm][oSd][0],
1839  &phs_->out_->rmax[oLm][oSd][0],
1840  &phs_->out_->deltar[oLm][oSd][0],
1841  &phs_->out_->deltax[oLm][oSd][0],
1842  &phs_->out_->r11[oLm][oSd],
1843  &phs_->out_->r22[oLm][oSd],
1844  &phs_->out_->r33[oLm][oSd],
1845  &phs_->out_->r44[oLm][oSd],
1846  &phs_->out_->reff[oLm][oSd],
1847  &phs_->out_->veff[oLm][oSd],
1848  &phs_->out_->ccnsml[oLm][oSd],
1849  &phs_->out_->bsr[oLm][oSd],
1850  &phs_->out_->salb[oLm][oSd],
1851  &phs_->out_->asf[oLm][oSd],
1852  &phs_->out_->qscat[oLm][oSd],
1853  &phs_->out_->qext[oLm][oSd],
1854  &phs_->out_->angl[0],
1855  &phs_->out_->phfu[oLm][oSd][0],
1856  &phs_->out_->pol[oLm][oSd][0],
1857  &phs_->out_->t[oLm][oSd][0][0],
1858  &phs_->out_->thd[oLm][oSd][0],
1859  &phs_->out_->rbar[oLm][oSd][0],
1860  &phs_->out_->dnzp[oLm][oSd][0],
1861  &phs_->out_->dnp[oLm][oSd][0],
1862  &phs_->out_->dvp[oLm][oSd][0],
1863  &phs_->out_->sumnp[oLm][oSd][0],
1864  &phs_->out_->wt[oLm][oSd][0] );
1865  //std::cout << "after phs" << std::endl;
1866  }
1867 
1868  size_t oTau = iTau - in_->itau1;
1869 
1870  int tmp = 1;
1871  if (iLm != prev_iLm || iSd != prev_iSd || iTau != prev_iTau) {
1872  // std::cout << "before rt1" << std::endl;
1873  af_rt1_process_( (char*)in_->rt1dir.c_str(),
1874  &iLm, &iSd, &tmp, &iTau,
1875  &rt1_->in_->iair[0],
1876  &rt1_->in_->iprin,
1877  &rt1_->in_->ipsudo,
1878  &rt1_->in_->ioptn,
1879  &rt1_->in_->idust,
1880  &rt1_->in_->iaprof,
1881  &rt1_->in_->iblyr,
1882  &rt1_->in_->icld,
1883  &rt1_->in_->inch,
1884  &rt1_->in_->int55,
1885  &in_->insd,
1886  &in_->inrh,
1887  &phs_->in_->iset[iSd-1],
1888  &rt1_->in_->kznum,
1889  &phs_->in_->irh[0],
1890  &rt1_->in_->deltau,
1891  &rt1_->in_->psrfc,
1892  &rt1_->in_->ht_dust,
1893  &rt1_->in_->sigma_dust,
1894  &rt1_->in_->pcldtop,
1895  &rt1_->in_->pcldbtm,
1896  &rt1_->in_->taum55[0],
1897  &rt1_->in_->xlamb[0],
1898  &rt1_->in_->c0[0],
1899  &rt1_->in_->c1[0],
1900  &rt1_->in_->c2[0],
1901  &rt1_->in_->beta[0],
1902  &rt1_->in_->rho[0],
1903  &rt1_->in_->ppo[0],
1904  &rt1_->in_->x101[0],
1905  &rt1_->in_->temp101[0],
1906  &rt1_->in_->htdd[0],
1907  &rt1_->in_->ppodd[0],
1908  &rt1_->in_->dxdd[0],
1909  &rt1_->in_->znpdd[0],
1910  &rt1_->in_->nortau,
1911  &rt1_->in_->ioznab,
1912  &rt1_->in_->nrmww,
1913  &phs_->out_->qscat[oLm][oSd],
1914  &phs_->out_->qext[oLm][oSd],
1915  &rt1_->in_->qst5[iLm-1][iSd-1][iTau-1],
1916  &rt1_->in_->qtt5[iLm-1][iSd-1][iTau-1],
1917  // Adjust for quirk in rt1_read
1918  &rt1_->out_->htlvl[0][0][0][1],
1919  &rt1_->out_->pplvl[0][0][0][1],
1920  &rt1_->out_->fr[0][0][0][0],
1921  &rt1_->out_->fn[0][0][0][0],
1922  &rt1_->out_->fa[0][0][0][0],
1923  &rt1_->out_->ftot[0][0][0][0],
1924  &rt1_->out_->dtrr[0][0][0][0],
1925  &rt1_->out_->dtmm[0][0][0][0],
1926  &rt1_->out_->dtaa[0][0][0][0],
1927  &rt1_->out_->dtot[0][0][0][0],
1928  &rt1_->out_->trp[0][0][0],
1929  &rt1_->out_->tmp[0][0][0],
1930  &rt1_->out_->tap[0][0][0],
1931  &rt1_->out_->salb[0][0][0][0],
1932  &rt1_->out_->turbhl[0][0][0][0],
1933  &rt1_->out_->dx[0][0][0][0],
1934  &rt1_->out_->x[0][0][0][0],
1935  &rt1_->out_->tozn101[0][0][0][0],
1936  &rt1_->out_->htdv[0][0][0][0],
1937  &rt1_->out_->pdv[0][0][0][0],
1938  &rt1_->out_->taur[0][0][0][0],
1939  &rt1_->out_->taum[0][0][0][0],
1940  &rt1_->out_->taua[0][0][0][0],
1941  &rt1_->out_->tau[0][0][0][0],
1942  &rt1_->out_->wvlth[0][0][0],
1943  &rt1_->out_->psrfc[0][0][0],
1944  &rt1_->out_->rho[0][0][0],
1945  &rt1_->out_->xozn[0][0][0],
1946  &rt1_->out_->tautot[0][0][0],
1947  &rt1_->out_->dtau1[0][0][0],
1948  &rt1_->out_->nolyr[0][0][0],
1949  &rt1_->out_->tcar[0][0][0],
1950  &rt1_->out_->twat[0][0][0],
1951  &rt1_->out_->tozn[0][0][0],
1952  &rt1_->out_->ifc[0][0][0],
1953  &rt1_->out_->nmodl[0][0][0]);
1954  // std::cout << "after rt1" << std::endl;
1955  }
1956  // Reduce precision to match ascii files
1957 // double dtot[nlyr];
1958 // for (int i=0; i<nlyr; i++) {
1959 // dtot[i] = (floor(rt1_->out_->dtot[0][0][0][i]*10e6))/10e6;
1960 // }
1961 
1962 // Adjust for quirk in rt1_read
1963  rt1_->out_->htlvl[0][0][0][0] = 84.0;
1964  rt1_->out_->pplvl[0][0][0][0] = 5.3040e-6;
1965 
1966  int oWnd = iWnd - in_->iwnd1;
1967  int sWnd = iWnd;
1968  // std::cout << "before ocn" << std::endl;
1969 
1970  int tmp_iref = in_->iref;
1971 
1972  if(ocn_->in_->sig_hg[iWnd-1] == 0.0) {
1973  tmp_iref = 1;
1974  } else {
1975 
1976  af_ocn_process_((char*)in_->ocndir.c_str(),
1977  &iLm, &sWnd,
1978  &ocn_->in_->iopt,
1979  &ocn_->in_->isig,
1980  &ocn_->in_->isolz,
1981  &ocn_->in_->insza,
1982  &ocn_->in_->inthe,
1983  &ocn_->in_->inphi,
1984  &ocn_->in_->dlth,
1985  &ocn_->in_->dlph,
1986  &ocn_->in_->xr,
1987  &ocn_->in_->xi,
1988  &ocn_->in_->v,
1989  &ocn_->in_->thcel,
1990  &ocn_->in_->phcel,
1991  &ocn_->in_->wav[0],
1992  &ocn_->in_->tha[0],
1993  &ocn_->in_->sig_hg[0],
1994  &ocn_->in_->solz[0],
1995  &ocn_->in_->iprob,
1996 
1997  &ocn_->out_->thp[0],
1998  &ocn_->out_->phcnd[0],
1999  &ocn_->out_->thcnd[0],
2000  &ocn_->out_->txx[0][0][0][0][0][0],
2001  &ocn_->out_->pti[0][0][0][0][0][0],
2002  &ocn_->out_->xinlpi[0][0][0][0][0],
2003  &ocn_->out_->xi_hgpi[0][0][0][0][0],
2004  &ocn_->out_->xin2pi[0][0][0][0][0],
2005  &ocn_->out_->xin2top[0][0][0][0][0] );
2006  }
2007 
2008  in_->iset = phs_->in_->iset[iSd-1];
2009 
2010  af_rt2_process_((char*)out_->outdir.c_str(),
2011  &iLm, &iSd, &tmp, &iTau, &iWnd,
2012  &tmp_iref,
2013  &in_->itrans,
2014  &phs_->in_->iset[iSd-1],
2015  &in_->irh1,
2016  &in_->irh2,
2017  &in_->ilm1,
2018  &in_->ilm2,
2019  &in_->isd1,
2020  &in_->isd2,
2021  &in_->itau1,
2022  &in_->itau2,
2023  &in_->ithe01,
2024  &in_->ithe02,
2025  &in_->iwnd1,
2026  &in_->iwnd2,
2027  &in_->inx,
2028  &in_->inthe0,
2029  &in_->inwl,
2030  &in_->inrh,
2031  &in_->insd,
2032  &in_->iww[0],
2033  &phs_->in_->irh[0],
2034  &in_->iprin,
2035  &in_->ipol,
2036  &in_->inpass1,
2037  &in_->inpass2,
2038  &in_->icrft,
2039  &in_->iactflx,
2040  &in_->isurf,
2041  &in_->iglint,
2042  &in_->iocn,
2043  &in_->ifoam,
2044  &in_->iwatr,
2045  &in_->iconc,
2046  &in_->dtheta,
2047  &in_->dphi,
2048  &in_->hcrft,
2049  &in_->rx[0],
2050  &in_->the0in[0],
2051  &in_->wwl[0],
2052  &in_->albwat[0],
2053  //phs
2054  &phs_->in_->ifunc[iSd-1],
2055  &phs_->in_->mfunc[iSd-1],
2056  &phs_->in_->refr[pLm-1][iSd-1][0],
2057  &phs_->in_->refi[pLm-1][iSd-1][0],
2058  &phs_->out_->rmin[oLm][oSd][0],
2059  &phs_->out_->rmax[oLm][oSd][0],
2060  &phs_->out_->deltar[oLm][oSd][0],
2061  &phs_->out_->deltax[oLm][oSd][0],
2062  &phs_->in_->rg[pLm-1][iSd-1][0],
2063  &phs_->in_->sig[pLm-1][iSd-1][0],
2064  &phs_->in_->npar[pLm-1][iSd-1][0],
2065  &phs_->out_->r11[oLm][oSd],
2066  &phs_->out_->r22[oLm][oSd],
2067  &phs_->out_->r33[oLm][oSd],
2068  &phs_->out_->r44[oLm][oSd],
2069  &phs_->out_->reff[oLm][oSd],
2070  &phs_->out_->veff[oLm][oSd],
2071  &phs_->out_->ccnsml[oLm][oSd],
2072  &phs_->out_->bsr[oLm][oSd],
2073  &phs_->out_->salb[oLm][oSd],
2074  &phs_->out_->asf[oLm][oSd],
2075  &phs_->out_->qscat[oLm][oSd],
2076  &phs_->out_->qext[oLm][oSd],
2077  &phs_->out_->t[oLm][oSd][0][0],
2078  &phs_->out_->thd[oLm][oSd][0],
2079  //ocn
2080  &ocn_->in_->xr,
2081  &ocn_->in_->xi,
2082  &ocn_->in_->v,
2083  &ocn_->in_->thcel,
2084  &ocn_->in_->phcel,
2085  &ocn_->out_->txx[0][0][0][0][0][0],
2086  &ocn_->out_->pti[0][0][0][0][0][0],
2087  //rt1
2088  &rt1_->out_->wvlth[0][0][0],
2089  &rt1_->out_->psrfc[0][0][0],
2090  &rt1_->out_->rho[0][0][0],
2091  &rt1_->out_->xozn[0][0][0],
2092  &rt1_->out_->tautot[0][0][0],
2093  &rt1_->out_->dtau1[0][0][0],
2094  &rt1_->out_->trp[0][0][0],
2095  &rt1_->out_->tmp[0][0][0],
2096  &rt1_->out_->tap[0][0][0],
2097  &rt1_->out_->tcar[0][0][0],
2098  &rt1_->out_->twat[0][0][0],
2099  &rt1_->out_->tozn[0][0][0],
2100  &rt1_->out_->htlvl[0][0][0][0],
2101  &rt1_->out_->pplvl[0][0][0][0],
2102  &rt1_->out_->dtrr[0][0][0][0],
2103  &rt1_->out_->dtmm[0][0][0][0],
2104  &rt1_->out_->dtaa[0][0][0][0],
2105  &rt1_->out_->dtot[0][0][0][0],
2106  &rt1_->out_->htdv[0][0][0][0],
2107  &rt1_->out_->pdv[0][0][0][0],
2108  &rt1_->out_->taur[0][0][0][0],
2109  &rt1_->out_->taum[0][0][0][0],
2110  &rt1_->out_->taua[0][0][0][0],
2111  &rt1_->out_->ifc[0][0][0],
2112  &rt1_->out_->nmodl[0][0][0],
2113  &rt1_->out_->nolyr[0][0][0],
2114  &rt1_->in_->ipsudo,
2115 
2116  &in_->bfr[iLm-1][iSd-1][iTau-1][iWnd-1][0],
2117  &out_->tma[0][0][0][0][0],
2118  &out_->tmb[0][0][0][0][0],
2119  &out_->tmc[0][0][0][0][0],
2120  &out_->tmfd[0][0][0][0][0],
2121  &out_->tmfu[0][0][0][0][0],
2122  &out_->tms[0][0][0][0][0],
2123  &out_->tmg[0][0][0][0][0],
2124  &out_->tmh[0][0][0][0][0],
2125  &out_->tmp[0][0][0][0][0],
2126  &out_->tmq[0][0][0][0][0],
2127  &out_->tmt[0][0][0][0][0],
2128  &out_->tmpp[0][0][0][0][0],
2129  &out_->tmqq[0][0][0][0][0],
2130  &out_->tmrr[0][0][0][0][0],
2131  &out_->tmss[0][0][0][0][0],
2132  &out_->transm[0][0][0][0][0],
2133  &out_->tmcfd[0][0][0][0][0],
2134  &out_->tmcfu[0][0][0][0][0],
2135  &out_->tmf1[0][0][0][0][0][0],
2136  &out_->tmf2[0][0][0][0][0],
2137  &out_->xzeroz[0][0][0][0][0][0][0][0],
2138  &out_->xzerod[0][0][0][0][0][0][0][0],
2139  &out_->tupz[0][0][0][0][0][0][0][0],
2140  &out_->tdwnz[0][0][0][0][0][0][0][0]);
2141  // std::cout << "after ocn" << std::endl;
2142  task_vec[0] = oLm;
2143  task_vec[1] = oSd;
2144  task_vec[2] = oTau;
2145  task_vec[3] = oWnd;
2146 
2147  MPI_Send(&itask, 1, MPI_INTEGER, 0, 0, MPI_COMM_WORLD);
2148  MPI_Send(task_vec, 4, MPI_INTEGER, 0, 0, MPI_COMM_WORLD);
2149 
2150  out_->wl = in_->wwl[iLm-1];
2151  out_->wnd = roundf(ocn_->in_->v*100.0)/100.0;
2152  // out_->wnd = in_->iww[iWnd-1];
2153  out_->tau = rt1_->in_->taum55[iTau-1];
2154 
2155  MPI_Send(&out_->wl, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
2156  MPI_Send(&out_->tau, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
2157  MPI_Send(&out_->wnd, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
2158 
2159  MPI_Send(&rt1_->out_->tautot[0][0][0], 1, MPI_DOUBLE, 0, 0,
2160  MPI_COMM_WORLD);
2161 
2162  MPI_Send(&rt1_->out_->trp[0][0][0], 1, MPI_DOUBLE, 0, 0,
2163  MPI_COMM_WORLD);
2164 
2165  MPI_Send(&rt1_->out_->tmp[0][0][0], 1, MPI_DOUBLE, 0, 0,
2166  MPI_COMM_WORLD);
2167 
2168  MPI_Send(&rt1_->out_->tap[0][0][0], 1, MPI_DOUBLE, 0, 0,
2169  MPI_COMM_WORLD);
2170 
2171  MPI_Send(&rt1_->out_->twat[0][0][0], 1, MPI_DOUBLE, 0, 0,
2172  MPI_COMM_WORLD);
2173 
2174 
2175  MPI_Send(&out_->tmb[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2176  MPI_COMM_WORLD);
2177 
2178  MPI_Send(&out_->tmc[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2179  MPI_COMM_WORLD);
2180 
2181  MPI_Send(&out_->tmfd[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2182  MPI_COMM_WORLD);
2183 
2184  MPI_Send(&out_->tmfu[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2185  MPI_COMM_WORLD);
2186 
2187  MPI_Send(&out_->tms[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2188  MPI_COMM_WORLD);
2189 
2190  MPI_Send(&out_->transm[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2191  MPI_COMM_WORLD);
2192 
2193 
2194  MPI_Send(&out_->tmq[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2195  MPI_COMM_WORLD);
2196 
2197  MPI_Send(&out_->tmpp[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2198  MPI_COMM_WORLD);
2199 
2200  MPI_Send(&out_->tmqq[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2201  MPI_COMM_WORLD);
2202 
2203  MPI_Send(&out_->tmrr[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2204  MPI_COMM_WORLD);
2205 
2206  MPI_Send(&out_->tmss[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2207  MPI_COMM_WORLD);
2208 
2209  MPI_Send(&out_->tmg[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2210  MPI_COMM_WORLD);
2211 
2212  MPI_Send(&out_->tmh[0][0][0][0][0], dnsza, MPI_DOUBLE, 0, 0,
2213  MPI_COMM_WORLD);
2214 
2215 
2216  int cnt=0;
2217  for (size_t i=0; i<dnsza; i++) {
2218  for (size_t j=0; j<dnthe; j++) {
2219  for (size_t k=0; k<dnphi; k++) {
2220  for (size_t s=0; s<nstk; s++) {
2221  xzeroz[cnt++] = out_->xzeroz[0][0][0][0][i][j][k][s];
2222  }
2223  }
2224  }
2225  }
2226 
2227  MPI_Send(xzeroz, dnsza*dnthe*dnphi*nstk, MPI_DOUBLE, 0, 0,
2228  MPI_COMM_WORLD);
2229 
2230  cnt=0;
2231  for (size_t i=0; i<dnsza; i++) {
2232  for (size_t j=0; j<dnthe; j++) {
2233  for (size_t k=0; k<dnphi; k++) {
2234  for (size_t s=0; s<nstk; s++) {
2235  xzerod[cnt++] = out_->xzerod[0][0][0][0][i][j][k][s];
2236  }
2237  }
2238  }
2239  }
2240 
2241  MPI_Send(xzerod, dnsza*dnthe*dnphi*nstk, MPI_DOUBLE, 0, 0,
2242  MPI_COMM_WORLD);
2243 
2244  } // while(1)
2245  }
2246 
2247  delete[] xzeroz;
2248  delete[] xzerod;
2249 
2250  MPI_Barrier(MPI_COMM_WORLD);
2251  MPI_Finalize();
2252 #endif
2253 
2254  return status;
2255 }
2256 
2257 /**************************************************************************
2258  * NAME: open_netcdf()
2259  *
2260  * DESCRIPTION: Create NetCDF4 output file and return pointer
2261  *
2262  *************************************************************************/
2263 
2264 NcFile* AfrtProcess::open_nc4(string output_filepath)
2265 {
2266  //int status = RT_SUCCESS;
2267 
2268  if (output_filepath.empty()) {
2269  cerr << "\nAfrtProcess:: Failure locating output file path.\n" << endl;
2270  return 0L;
2271  }
2272  size_t pos = output_filepath.rfind("/");
2273  prod_name_ = output_filepath.substr(pos+1);
2274 
2275  NcFile* ncout;
2276  try {
2277  ncout = new NcFile( output_filepath, NcFile::newFile );
2278  }
2279  catch( NcException& e) {
2280  e.what();
2281  cerr << "AfrtProcess:: Output file exists: "
2282  << output_filepath << endl;
2283  ncout = (NcFile*) 0L;
2284  }
2285  if (ncout == 0) {
2286  try {
2287  ncout = new NcFile( output_filepath, NcFile::replace );
2288  }
2289  catch( NcException& e) {
2290  e.what();
2291  cerr << "AfrtProcess:: Failure opening output file: "
2292  << output_filepath << endl;
2293  return 0L;;
2294  }
2295  }
2296  write_global_attributes( ncout );
2297 
2298  return ncout;
2299 }
2300 
2301 /**************************************************************************
2302  * NAME: write_nc4()
2303  *
2304  * DESCRIPTION: Write output data to NetCDF4 file
2305  *
2306  *************************************************************************/
2307 
2308 int AfrtProcess::write_nc4(NcFile* ncout)
2309 {
2310  int status = RT_SUCCESS;
2311  return status;
2312 }
2313 
2314 int AfrtProcessPhs::write_nc4(NcFile* ncout)
2315 {
2316  int status = RT_SUCCESS;
2317 
2318  size_t dlam = in_->ilam2 - in_->ilam1 + 1;
2319  size_t dsd = in_->isd2 - in_->isd1 + 1;
2320 
2321  NcDim wave_dim = ncout->addDim( "dim_wavelengths", dlam );
2322  NcDim sd_dim = ncout->addDim( "dim_sd", dsd );
2323  NcDim angle_dim = ncout->addDim( "dim_angle", ntf );
2324  NcDim stokes_dim = ncout->addDim( "dim_stokes", nstk );
2325  NcDim mode_dim = ncout->addDim( "dim_mode", nmd );
2326 
2327 // Convert stattering matrix elements from AF
2328  double_5darray F;
2329  F.resize(boost::extents[dsd][dlam][ntf][nstk][nstk]);
2330 
2331  for (size_t iL=0; iL<dlam; iL++) {
2332  for (size_t iSd=0; iSd<dsd; iSd++) {
2333  for (size_t iA=0; iA<ntf; iA++) {
2334  double F11 = out_->t[iL][iSd][0][iA] + out_->t[iL][iSd][1][iA];
2335  double F12 = out_->t[iL][iSd][0][iA] - out_->t[iL][iSd][1][iA];
2336  F[iSd][iL][iA][0][0] = F11/2.0;
2337  F[iSd][iL][iA][0][1] = F12/2.0;
2338  F[iSd][iL][iA][0][2] = 0;
2339  F[iSd][iL][iA][0][3] = 0;
2340  F[iSd][iL][iA][1][0] = F12/2.0;
2341  F[iSd][iL][iA][1][1] = F11/2.0;
2342  F[iSd][iL][iA][1][2] = 0;
2343  F[iSd][iL][iA][1][3] = 0;
2344  F[iSd][iL][iA][2][0] = 0;
2345  F[iSd][iL][iA][2][1] = 0;
2346  F[iSd][iL][iA][2][2] = out_->t[iL][iSd][2][iA];
2347  F[iSd][iL][iA][2][3] = -out_->t[iL][iSd][3][iA];
2348  F[iSd][iL][iA][3][0] = 0;
2349  F[iSd][iL][iA][3][1] = 0;
2350  F[iSd][iL][iA][3][2] = out_->t[iL][iSd][3][iA];
2351  F[iSd][iL][iA][3][3] = out_->t[iL][iSd][2][iA];
2352  }
2353  }
2354  }
2355 
2356  vector<NcDim> scat_dims;
2357  scat_dims.push_back(sd_dim);
2358  scat_dims.push_back(wave_dim);
2359  vector<NcDim> mode_dims;
2360  mode_dims.push_back(sd_dim);
2361  mode_dims.push_back(wave_dim);
2362  mode_dims.push_back(mode_dim);
2363  vector<NcDim> pol_dims;
2364  pol_dims.push_back(sd_dim);
2365  pol_dims.push_back(wave_dim);
2366  pol_dims.push_back(angle_dim);
2367  vector<NcDim> fmat_dims;
2368  fmat_dims.push_back(sd_dim);
2369  fmat_dims.push_back(wave_dim);
2370  fmat_dims.push_back(angle_dim);
2371  fmat_dims.push_back(stokes_dim);
2372  fmat_dims.push_back(stokes_dim);
2373 
2374  NcVar var = ncout->addVar("IFUNC", ncInt, sd_dim);
2375  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2376  var.putVar( &in_->ifunc[0] );
2377 
2378  var = ncout->addVar("MFUNC", ncInt, sd_dim);
2379  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2380  var.putVar( &in_->mfunc[0] );
2381 
2382  var = ncout->addVar("WAVELENGTHS", ncDouble, wave_dim);
2383  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2384 
2385  var = ncout->addVar("REF_INDEX_REAL", ncDouble, mode_dims);
2386  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2387  var.putVar( &out_->refr[0][0][0] );
2388 
2389  var = ncout->addVar("REF_INDEX_IMAG", ncDouble, mode_dims);
2390  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2391  var.putVar( &out_->refi[0][0][0] );
2392 
2393  var = ncout->addVar("RADIUS_MEAN", ncDouble, mode_dims);
2394  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2395  var.putVar( &out_->rg[0][0][0] );
2396 
2397  var = ncout->addVar("RADIUS_SDEV", ncDouble, mode_dims);
2398  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2399  var.putVar( &out_->sig[0][0][0] );
2400 
2401  var = ncout->addVar("NUMBER_PARTICLES", ncDouble, mode_dims);
2402  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2403  var.putVar( &out_->npar[0][0][0] );
2404 
2405  var = ncout->addVar("DELX", ncDouble, mode_dims);
2406  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2407  var.putVar( &out_->dx[0][0][0] );
2408 
2409  var = ncout->addVar("EPAR", ncDouble, mode_dims);
2410  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2411  var.putVar( &out_->epar[0][0][0] );
2412 
2413  var = ncout->addVar("RMIN", ncDouble, mode_dims);
2414  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2415  var.putVar( &out_->rmin[0][0][0] );
2416 
2417  var = ncout->addVar("RMAX", ncDouble, mode_dims);
2418  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2419  var.putVar( &out_->rmax[0][0][0] );
2420 
2421  var = ncout->addVar("DELTAR", ncDouble, mode_dims);
2422  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2423  var.putVar( &out_->deltar[0][0][0] );
2424 
2425  var = ncout->addVar("DELTAX", ncDouble, mode_dims);
2426  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2427  var.putVar( &out_->deltax[0][0][0] );
2428 
2429  var = ncout->addVar("R11", ncDouble, scat_dims);
2430  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2431  var.putVar( &out_->r11[0][0] );
2432 
2433  var = ncout->addVar("R22", ncDouble, scat_dims);
2434  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2435  var.putVar( &out_->r22[0][0] );
2436 
2437  var = ncout->addVar("R33", ncDouble, scat_dims);
2438  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2439  var.putVar( &out_->r33[0][0] );
2440 
2441  var = ncout->addVar("R44", ncDouble, scat_dims);
2442  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2443  var.putVar( &out_->r44[0][0] );
2444 
2445  var = ncout->addVar("REFF", ncDouble, scat_dims);
2446  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2447  var.putVar( &out_->reff[0][0] );
2448 
2449  var = ncout->addVar("VEFF", ncDouble, scat_dims);
2450  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2451  var.putVar( &out_->veff[0][0] );
2452 
2453  var = ncout->addVar("CCNSML", ncDouble, scat_dims);
2454  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2455  var.putVar( &out_->ccnsml[0][0] );
2456 
2457  var = ncout->addVar("BSR", ncDouble, scat_dims);
2458  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2459  var.putVar( &out_->bsr[0][0] );
2460 
2461  var = ncout->addVar("SALB", ncDouble, scat_dims);
2462  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2463  var.putVar( &out_->salb[0][0] );
2464 
2465  var = ncout->addVar("ASF", ncDouble, scat_dims);
2466  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2467  var.putVar( &out_->asf[0][0] );
2468 
2469  var = ncout->addVar("QSCAT", ncDouble, scat_dims);
2470  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2471  var.putVar( &out_->qscat[0][0] );
2472 
2473  var = ncout->addVar("QEXT", ncDouble, scat_dims);
2474  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2475  var.putVar( &out_->qext[0][0] );
2476 
2477  var = ncout->addVar("ANGLE", ncDouble, angle_dim);
2478  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2479  var.putVar( &out_->angl[0] );
2480 
2481  var = ncout->addVar("PHASE_FUNCTION", ncDouble, pol_dims);
2482  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2483  var.putVar( &out_->phfu[0][0][0]);
2484 
2485  var = ncout->addVar("POLARIZATION", ncDouble, pol_dims);
2486  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2487  var.putVar( &out_->pol[0][0][0]);
2488 
2489  var = ncout->addVar("WT", ncDouble, pol_dims);
2490  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2491  var.putVar( &out_->wt[0][0][0]);
2492 
2493  var = ncout->addVar("RBAR", ncDouble, pol_dims);
2494  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2495  var.putVar( &out_->rbar[0][0][0]);
2496 
2497  var = ncout->addVar("DN_DLOGR", ncDouble, pol_dims);
2498  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2499  var.putVar( &out_->dnzp[0][0][0]);
2500 
2501  var = ncout->addVar("DN_DR", ncDouble, pol_dims);
2502  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2503  var.putVar( &out_->dnp[0][0][0]);
2504 
2505  var = ncout->addVar("DV_DLOGR", ncDouble, pol_dims);
2506  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2507  var.putVar( &out_->dvp[0][0][0]);
2508 
2509  var = ncout->addVar("TOTAL_PARTICLES", ncDouble, pol_dims);
2510  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2511  var.putVar( &out_->sumnp[0][0][0]);
2512 
2513  var = ncout->addVar("F-MATRIX", ncDouble, fmat_dims);
2514  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2515  var.putVar( &F[0][0][0][0][0]);
2516 
2517  return status;
2518 }
2519 
2521 {
2522  int status = RT_SUCCESS;
2523 
2524  if (ofile.empty()) {
2525  cerr << "\nAfrtProcess:: Invalid output file path.\n" << endl;
2526  return 0L;
2527  }
2528  size_t pos = ofile.rfind("/");
2529  prod_name_ = ofile.substr(pos+1);
2530 
2531  NcFile* ncout;
2532  try {
2533  ncout = new NcFile( ofile, NcFile::newFile );
2534  }
2535  catch( NcException& e) {
2536  e.what();
2537  cerr << "AfrtProcess:: Output file exists: "
2538  << ofile << endl;
2539  ncout = (NcFile*) 0L;
2540  }
2541  if (ncout == 0) {
2542  try {
2543  ncout = new NcFile( ofile, NcFile::replace );
2544  }
2545  catch( NcException& e) {
2546  e.what();
2547  cerr << "AfrtProcess:: Failure opening output file: "
2548  << ofile << endl;
2549  return RT_FAIL;;
2550  }
2551  }
2552  write_global_attributes( ncout );
2553 
2554  size_t dlam = in_->ilm2 - in_->ilm1 + 1;
2555  size_t dsd = in_->isd2 - in_->isd1 + 1;
2556  size_t dtau = in_->itau2 - in_->itau1 + 1;
2557  size_t dwnd = in_->iwnd2 - in_->iwnd1 + 1;
2558  size_t dnsza = in_->inthe0;
2559  size_t dnthe = in_->inthe0;
2560  size_t dnphi = (360.0/in_->dphi)/2.0 +1;
2561 
2562  NcDim index_dim = ncout->addDim( "dim_index", 2 );
2563  NcDim wave_dim = ncout->addDim( "dim_wave", dlam );
2564  NcDim sd_dim = ncout->addDim( "dim_size", dsd );
2565  NcDim tau_dim = ncout->addDim( "dim_tau", dtau );
2566  NcDim wnd_dim = ncout->addDim( "dim_wind", dwnd );
2567  NcDim sza_dim = ncout->addDim( "dim_sza", dnsza );
2568  NcDim the_dim = ncout->addDim( "dim_the", dnthe );
2569  NcDim phi_dim = ncout->addDim( "dim_phi", dnphi );
2570  NcDim stokes_dim = ncout->addDim( "dim_stokes", nstk );
2571 
2572  vector<NcDim> scalar_dims;
2573  scalar_dims.push_back(sd_dim);
2574  scalar_dims.push_back(wave_dim);
2575  scalar_dims.push_back(tau_dim);
2576  vector<NcDim> sza_dims;
2577  sza_dims.push_back(sd_dim);
2578  sza_dims.push_back(wave_dim);
2579  sza_dims.push_back(tau_dim);
2580  sza_dims.push_back(wnd_dim);
2581  sza_dims.push_back(sza_dim);
2582  vector<NcDim> phi_dims;
2583  phi_dims.push_back(sd_dim);
2584  phi_dims.push_back(wave_dim);
2585  phi_dims.push_back(tau_dim);
2586  phi_dims.push_back(wnd_dim);
2587  phi_dims.push_back(sza_dim);
2588  phi_dims.push_back(the_dim);
2589  phi_dims.push_back(phi_dim);
2590  phi_dims.push_back(stokes_dim);
2591 
2592  int id[2];
2593  id[0] = in_->ilm1;
2594  id[1] = in_->ilm2;
2595  NcVar var = ncout->addVar("wavelength_index", ncInt, index_dim);
2596  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2597  var.putVar(&id[0]);
2598 
2599  id[0] = in_->isd1;
2600  id[1] = in_->isd2;
2601  var = ncout->addVar("model_index", ncInt, index_dim);
2602  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2603  var.putVar(&id[0]);
2604 
2605  id[0] = in_->itau1;
2606  id[1] = in_->itau2;
2607  var = ncout->addVar("tau_index", ncInt, index_dim);
2608  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2609  var.putVar(&id[0]);
2610 
2611  id[0] = in_->iwnd1;
2612  id[1] = in_->iwnd2;
2613  var = ncout->addVar("wind_index", ncInt, index_dim);
2614  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2615  var.putVar(&id[0]);
2616 
2617  var = ncout->addVar("WAVELENGTH", ncDouble, wave_dim);
2618  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2619 
2620  var = ncout->addVar("TAU_RAYLEIGH", ncDouble, scalar_dims);
2621  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2622 
2623  var = ncout->addVar("TAU_AEROSOL", ncDouble, scalar_dims);
2624  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2625 
2626  // var = ncout->addVar("TAU_ABSORB", ncDouble, scalar_dims);
2627  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2628 
2629  var = ncout->addVar("TAU_TOTAL", ncDouble, scalar_dims);
2630  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2631 
2632  var = ncout->addVar("WIND_SPEED", ncDouble, wnd_dim);
2633  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2634 
2635  var = ncout->addVar("AOT", ncDouble, tau_dim);
2636  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2637 
2638  var = ncout->addVar("SZA", ncDouble, sza_dim);
2639  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2640 
2641  var = ncout->addVar("THETA", ncDouble, the_dim);
2642  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2643 
2644  var = ncout->addVar("PHI", ncDouble, phi_dim);
2645  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2646 
2647  var = ncout->addVar("BOA_DIRECT", ncDouble, sza_dims);
2648  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2649 
2650  // var = ncout->addVar("SBAR", ncDouble, sza_dims);
2651  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2652 
2653  var = ncout->addVar("BOA_DIFFUSE", ncDouble, sza_dims);
2654  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2655 
2656  var = ncout->addVar("TOA_DIFFUSE", ncDouble, sza_dims);
2657  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2658 
2659  var = ncout->addVar("HEM_REFLECTANCE", ncDouble, sza_dims);
2660  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2661 
2662  // var = ncout->addVar("FTW_DIRECT_OCEAN", ncDouble, sza_dims);
2663  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2664  // var.putVar( &out_->tmg[0][0][0][0][0] );
2665 
2666  // var = ncout->addVar("FTW_DIFFUSE_OCEAN", ncDouble, sza_dims);
2667  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2668  // var.putVar( &out_->tmh[0][0][0][0][0] );
2669 
2670  // var = ncout->addVar("FTW_UP_DIFFUSE_OCEAN_BELOW", ncDouble, sza_dims);
2671  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2672  // var.putVar( &out_->tmp[0][0][0][0][0] );
2673 
2674  // var = ncout->addVar("FTW_UP_DIFFUSE_OCEAN_ABOVE", ncDouble, sza_dims);
2675  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2676  // var.putVar( &out_->tmq[0][0][0][0][0] );
2677 
2678  // var = ncout->addVar("HEM_TRANS_REF", ncDouble, sza_dims);
2679  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2680  // var.putVar( &out_->tmpp[0][0][0][0][0] );
2681 
2682  var = ncout->addVar("HEM_REFL_REF", ncDouble, sza_dims);
2683  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2684  var.putVar( &out_->tmqq[0][0][0][0][0] );
2685 
2686  // var = ncout->addVar("HEM_DIRECT_REF", ncDouble, sza_dims);
2687  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2688  // var.putVar( &out_->tmrr[0][0][0][0][0] );
2689 
2690  // var = ncout->addVar("HEM_DIFFUSE_REF", ncDouble, sza_dims);
2691  // var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2692  // var.putVar( &out_->tmss[0][0][0][0][0] );
2693 /*
2694  var = ncout->addVar("TRANSMITTANCE", ncDouble, sza_dims);
2695  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2696 */
2697  var = ncout->addVar("TOA_RADIANCE", ncDouble, phi_dims);
2698  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2699 
2700  var = ncout->addVar("BOA_RADIANCE", ncDouble, phi_dims);
2701  var.setCompression(bShuffleFilter, bDeflateFilter, deflateLevel);
2702 
2703  delete ncout;
2704 
2705  return status;
2706 }
2707 
2708 int AfrtProcessNC4::write_nc4(size_t l1, size_t s1, size_t t1, size_t w1)
2709 {
2710  int status = RT_SUCCESS;
2711 
2712  if (ofilepath_.empty()) {
2713  cerr << "\nAfrtProcess:: Failure locating output file path.\n" << endl;
2714  return 0L;
2715  }
2716 
2717  NcFile* ncout;
2718  try {
2719  ncout = new NcFile( ofilepath_, NcFile::write );
2720  }
2721  catch( NcException& e) {
2722  e.what();
2723  cerr << "AfrtProcess:: Can't open output file: "
2724  << ofilepath_ << endl;
2725  ncout = (NcFile*) 0L;
2726  return RT_FAIL;
2727  }
2728 
2729  //size_t dnwnd = in_->iww[nsig];
2730  size_t dnsza = in_->inthe0;
2731  size_t dnthe = in_->inthe0;
2732  size_t dnphi = (360.0/in_->dphi)/2.0 +1;
2733 
2735  double_1darray the;
2736  double_1darray phi;
2737  double_8darray xzeroz;
2738  double_8darray xzerod;
2739  sza.resize(boost::extents[dnsza]);
2740  the.resize(boost::extents[dnthe]);
2741  phi.resize(boost::extents[dnphi]);
2742  xzeroz.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
2743  xzerod.resize(boost::extents[1][1][1][1][dnsza][dnthe][dnphi][nstk]);
2744  for (size_t i=0; i<dnsza; i++) {
2745  double z = in_->the0in[i];
2746  sza[i] = z;
2747  for (size_t j=0; j<dnthe; j++) {
2748  double t = (in_->rx[j] + in_->rx[j+1])/2.0;
2749  the[j] = t;
2750  for (size_t k=0; k<dnphi; k++) {
2751  double p = in_->phi[k];
2752  phi[k] = p;
2753  for (size_t s=0; s<nstk; s++) {
2754  double x = out_->xzeroz[0][0][0][0][i][j][k][s];
2755  xzeroz[0][0][0][0][i][j][k][s] = x;
2756  x = out_->xzerod[0][0][0][0][i][j][k][s];
2757  xzerod[0][0][0][0][i][j][k][s] = x;
2758  }
2759  }
2760  }
2761  }
2762 
2763  vector<size_t> startw,countw;
2764  startw.push_back((size_t)l1);
2765  countw.push_back((size_t)1);
2766 
2767  NcVar var = ncout->getVar("WAVELENGTH");
2768  var.putVar( startw, countw, &out_->wl );
2769 
2770  startw[0] = t1;
2771  var = ncout->getVar("AOT");
2772  var.putVar( startw, countw, &out_->tau );
2773 
2774  startw[0] = w1;
2775  var = ncout->getVar("WIND_SPEED");
2776  var.putVar( startw, countw, &out_->wnd );
2777 
2778  var = ncout->getVar("SZA");
2779  var.putVar( &sza[0] );
2780 
2781  var = ncout->getVar("THETA");
2782  var.putVar( &the[0] );
2783 
2784  var = ncout->getVar("PHI");
2785  var.putVar( &phi[0] );
2786 
2787  vector<size_t> startp,countp;
2788  startp.push_back((size_t)s1);
2789  startp.push_back((size_t)l1);
2790  startp.push_back((size_t)t1);
2791  startp.push_back((size_t)w1);
2792  countp.push_back((size_t)1);
2793  countp.push_back((size_t)1);
2794  countp.push_back((size_t)1);
2795  countp.push_back((size_t)1);
2796 
2797  var = ncout->getVar("TAU_TOTAL");
2798  var.putVar( startp, countp, &rt1_->out_->tautot[0][0][0] );
2799 
2800  var = ncout->getVar("TAU_RAYLEIGH");
2801  var.putVar( startp, countp, &rt1_->out_->trp[0][0][0] );
2802 
2803  var = ncout->getVar("TAU_AEROSOL");
2804  var.putVar( startp, countp, &rt1_->out_->tmp[0][0][0] );
2805 
2806  // var = ncout->getVar("TAU_ABSORB");
2807  // var.putVar( startp, countp, &rt1_->out_->tap[0][0][0] );
2808 
2809  startp.push_back(0);
2810  countp.push_back(dnsza);
2811 
2812  var = ncout->getVar("BOA_DIRECT");
2813  var.putVar( startp, countp, &out_->tmb[0][0][0][0][0] );
2814 
2815  // var = ncout->getVar("SBAR");
2816  // var.putVar( startp, countp, &out_->tmc[0][0][0][0][0] );
2817 
2818  var = ncout->getVar("BOA_DIFFUSE");
2819  var.putVar( startp, countp, &out_->tmfd[0][0][0][0][0] );
2820 
2821  var = ncout->getVar("TOA_DIFFUSE");
2822  var.putVar( startp, countp, &out_->tmfu[0][0][0][0][0] );
2823 
2824  var = ncout->getVar("HEM_REFLECTANCE");
2825  var.putVar( startp, countp, &out_->tms[0][0][0][0][0] );
2826 
2827  // var = ncout->getVar("FTW_DIRECT_OCEAN");
2828  // var.putVar( startp, countp, &out_->tmg[0][0][0][0][0] );
2829 
2830  // var = ncout->getVar("FTW_DIFFUSE_OCEAN");
2831  // var.putVar( startp, countp, &out_->tmh[0][0][0][0][0] );
2832 
2833  // var = ncout->getVar("FTW_UP_DIFFUSE_OCEAN_BELOW");
2834  // var.putVar( startp, countp, &out_->tmp[0][0][0][0][0] );
2835 
2836  // var = ncout->getVar("FTW_UP_DIFFUSE_OCEAN_ABOVE");
2837  // var.putVar( startp, countp, &out_->tmq[0][0][0][0][0] );
2838 
2839  // var = ncout->getVar("HEM_TRANS_REF");
2840  // var.putVar( startp, countp, &out_->tmpp[0][0][0][0][0] );
2841 
2842  var = ncout->getVar("HEM_REFL_REF");
2843  var.putVar( startp, countp, &out_->tmqq[0][0][0][0][0] );
2844 
2845  // var = ncout->getVar("HEM_DIRECT_REF");
2846  // var.putVar( startp, countp, &out_->tmrr[0][0][0][0][0] );
2847 
2848  // var = ncout->getVar("HEM_DIFFUSE_REF");
2849  // var.putVar( startp, countp, &out_->tmss[0][0][0][0][0] );
2850 
2851 /*
2852  var = ncout->getVar("TRANSMITTANCE");
2853  var.putVar( startp, countp, &out_->transm[0][0][0][0][0] );
2854 */
2855  startp.push_back(0);
2856  startp.push_back(0);
2857  startp.push_back(0);
2858  countp.push_back(dnthe);
2859  countp.push_back(dnphi);
2860  countp.push_back(nstk);
2861 
2862  var = ncout->getVar("TOA_RADIANCE");
2863  var.putVar( startp, countp, &xzeroz[0][0][0][0][0][0][0][0] );
2864 
2865  var = ncout->getVar("BOA_RADIANCE");
2866  var.putVar( startp, countp, &xzerod[0][0][0][0][0][0][0][0] );
2867 
2868  delete ncout;
2869 
2870  return status;
2871 }
2872 
2873 int AfrtProcessPhs::read_nc4(string filepath, int l1, int l2, int s1, int s2)
2874 {
2875  int status = RT_SUCCESS;
2876 
2877  NcFile* nc_input;
2878  try {
2879  nc_input = new NcFile(filepath, NcFile::read );
2880  }
2881  catch( NcException& e) {
2882  e.what();
2883  cerr << "AfrtProcessPhs:: Failure opening netcdf LUT file: "
2884  + filepath << endl;
2885  return RT_FAIL;
2886  }
2887  NcGroup grp = nc_input->getGroup("PHS" );
2888  NcVar var = grp.getVar ( "F-MATRIX" );
2889  //int ndims = var.getDimCount();
2890  NcDim dim_lam = var.getDim(0);
2891  long dl = dim_lam.getSize();
2892  NcDim dim_sd = var.getDim(1);
2893  long ds = dim_sd.getSize();
2894 
2895  if (l2 > dl || s2 > ds) return RT_FAIL;
2896 
2897  in_->inw = dl;
2898  in_->insd = ds;
2899 
2900  size_t l_start = l1 - 1;
2901  size_t s_start = s1 - 1;
2902  size_t l_count = l2 - l1 + 1;
2903  size_t s_count = s2 - s1 + 1;
2904 
2905  vector<size_t> startp,countp;
2906  startp.push_back(s_start);
2907  countp.push_back(s_count);
2908 
2909  var = grp.getVar("IFUNC");
2910  var.getVar(startp,countp, &in_->ifunc[0] );
2911 
2912  var = grp.getVar("MFUNC");
2913  var.getVar(startp,countp, &in_->mfunc[0] );
2914 
2915  startp.clear();
2916  countp.clear();
2917  startp.push_back(s_start);
2918  startp.push_back(l_start);
2919  startp.push_back(0);
2920  countp.push_back(s_count);
2921  countp.push_back(l_count);
2922  countp.push_back(nmd);
2923 
2924  var = grp.getVar("REF_INDEX_REAL");
2925  var.getVar( startp,countp, &out_->refr[0][0][0] );
2926 
2927  var = grp.getVar("REF_INDEX_IMAG");
2928  var.getVar( startp,countp, &out_->refi[0][0][0] );
2929 
2930  var = grp.getVar("RADIUS_MEAN");
2931  var.getVar( startp,countp, &out_->rg[0][0][0] );
2932 
2933  var = grp.getVar("RADIUS_SDEV");
2934  var.getVar( startp,countp, &out_->sig[0][0][0] );
2935 
2936  var = grp.getVar("NUMBER_PARTICLES");
2937  var.getVar( startp,countp, &out_->npar[0][0][0] );
2938 
2939  var = grp.getVar("DELX");
2940  var.getVar( startp,countp, &out_->dx[0][0][0] );
2941 
2942  var = grp.getVar("EPAR");
2943  var.getVar( startp,countp, &out_->epar[0][0][0] );
2944 
2945  var = grp.getVar("RMIN");
2946  var.getVar( startp,countp, &out_->rmin[0][0][0] );
2947 
2948  var = grp.getVar("RMAX");
2949  var.getVar( startp,countp, &out_->rmax[0][0][0] );
2950 
2951  var = grp.getVar("DELTAR");
2952  var.getVar( startp,countp, &out_->deltar[0][0][0] );
2953 
2954  var = grp.getVar("DELTAX");
2955  var.getVar( startp,countp, &out_->deltax[0][0][0] );
2956 
2957  startp.clear();
2958  countp.clear();
2959  startp.push_back(s_start);
2960  startp.push_back(l_start);
2961  countp.push_back(s_count);
2962  countp.push_back(l_count);
2963 
2964  var = grp.getVar("R11");
2965  var.getVar(startp,countp, &out_->r11[0][0] );
2966 
2967  var = grp.getVar("R22");
2968  var.getVar(startp,countp, &out_->r22[0][0] );
2969 
2970  var = grp.getVar("R33");
2971  var.getVar(startp,countp, &out_->r33[0][0] );
2972 
2973  var = grp.getVar("R44");
2974  var.getVar(startp,countp, &out_->r44[0][0] );
2975 
2976  var = grp.getVar("REFF");
2977  var.getVar(startp,countp, &out_->reff[0][0] );
2978 
2979  var = grp.getVar("VEFF");
2980  var.getVar(startp,countp, &out_->veff[0][0] );
2981 
2982  var = grp.getVar("CCNSML");
2983  var.getVar(startp,countp, &out_->ccnsml[0][0] );
2984 
2985  var = grp.getVar("BSR");
2986  var.getVar(startp,countp, &out_->bsr[0][0] );
2987 
2988  var = grp.getVar("SALB");
2989  var.getVar(startp,countp, &out_->salb[0][0] );
2990 
2991  var = grp.getVar("ASF");
2992  var.getVar(startp,countp, &out_->asf[0][0] );
2993 
2994  var = grp.getVar("QSCAT");
2995  var.getVar(startp,countp, &out_->qscat[0][0] );
2996 
2997  var = grp.getVar("QEXT");
2998  var.getVar(startp,countp, &out_->qext[0][0] );
2999 
3000  startp.clear();
3001  countp.clear();
3002  startp.push_back(s_start);
3003  startp.push_back(l_start);
3004  startp.push_back(0);
3005  countp.push_back(s_count);
3006  countp.push_back(l_count);
3007  countp.push_back(ntf);
3008 
3009  var = grp.getVar("PHFU");
3010  var.getVar(startp,countp, &out_->phfu[0][0][0]);
3011 
3012  var = grp.getVar("POLARIZATION");
3013  var.getVar(startp,countp, &out_->pol[0][0][0]);
3014 
3015  var = grp.getVar("WT");
3016  var.getVar(startp,countp, &out_->wt[0][0][0]);
3017 
3018  var = grp.getVar("RBAR");
3019  var.getVar(startp,countp, &out_->rbar[0][0][0]);
3020 
3021  var = grp.getVar("DN_DLOGR");
3022  var.getVar(startp,countp, &out_->dnzp[0][0][0]);
3023 
3024  var = grp.getVar("DN_DR");
3025  var.getVar(startp,countp, &out_->dnp[0][0][0]);
3026 
3027  var = grp.getVar("DV_DLOGR");
3028  var.getVar(startp,countp, &out_->dvp[0][0][0]);
3029 
3030  var = grp.getVar("TOTAL_PARTICLES");
3031  var.getVar(startp,countp, &out_->sumnp[0][0][0]);
3032 
3033  startp.clear();
3034  countp.clear();
3035  startp.push_back(s_start);
3036  startp.push_back(l_start);
3037  startp.push_back(0);
3038  startp.push_back(0);
3039  countp.push_back(s_count);
3040  countp.push_back(l_count);
3041  countp.push_back(nstk);
3042  countp.push_back(nstk);
3043 
3044  double_5darray F;
3045  F.resize(boost::extents[s_count][l_count][ntf][nstk][nstk]);
3046  var = grp.getVar("F-MATRIX");
3047  var.getVar(startp,countp, &F[0][0][0][0][0]);
3048 
3049  for (size_t iL=0; iL<l_count; iL++) {
3050  for (size_t iSd=0; iSd<s_count; iSd++) {
3051  for (int iA=0; iA<ntf; iA++) {
3052  double T1 = F[iSd][iL][iA][0][0] + F[iSd][iL][iA][0][1];
3053  double T2 = F[iSd][iL][iA][0][0] - F[iSd][iL][iA][0][1];
3054  out_->t[iSd][iL][0][iA] = T1/2.0;
3055  out_->t[iSd][iL][1][iA] = T2/2.0;
3056  out_->t[iSd][iL][2][iA] = F[iSd][iL][iA][2][2];
3057  out_->t[iSd][iL][3][iA] = F[iSd][iL][iA][3][2];
3058  }
3059  }
3060  }
3061  F.resize(boost::extents[0][0][0][0][0]);
3062 
3063 // std::cout << "Input file = " << filepath << std::endl;
3064 
3065  return status;
3066 }
3067 
3068 
3069 /**************************************************************************
3070  * write_global_attributes()
3071  *
3072  * Write global attributes to specified netCDF file ID
3073  *
3074  **************************************************************************/
3075 
3077 {
3078 // global attributes
3079  conventions_ = "CF-1.6";
3080  institution_ = "NASA Goddard Space Flight Center, VIIRS L1 Processing Group";
3081  license_ = "https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/";
3082  naming_authority_ = "gov.nasa.gsfc.sci.oceandata";
3083  keywords_vocabulary_ = "NASA Global Change Master Directory (GCMD) Science Keywords";
3084  stdname_vocabulary_ = "NetCDF Climate and Forecast (CF) Metadata Convention";
3085  creator_name_ = "NASA Ocean Biology Processing Group";
3086  creator_email_ = "modis-ops@lists.nasa.gov";
3087  creator_url_ = "https://oceandata.sci.gsfc.nasa.gov";
3088  project_ = "NASA Ocean Biology Processing Project";
3089  publisher_name_ = "OBPG";
3090  publisher_url_ = "https://oceandata.sci.gsfc.nasa.gov";
3091  publisher_email_ = "data@oceancolor.gsfc.nasa.gov";
3092  processing_level_ = "L1B";
3093  cdm_data_type_ = "swath";
3094 
3095  time_t rawtime;
3096  struct tm * timeinfo;
3097  char buffer[80];
3098  time (&rawtime);
3099  timeinfo = localtime(&rawtime);
3100  strftime(buffer, 80, "%Y-%m-%dT%I:%M:%SZ", timeinfo);
3101  date_created_ = (std::string) buffer;
3102  ncout->putAtt( "processing_version", processing_version_);
3103 
3104  ncout->putAtt( "Conventions", conventions_);
3105  ncout->putAtt( "institution", institution_);
3106  ncout->putAtt( "license", license_);
3107  ncout->putAtt( "naming_authority", naming_authority_);
3108  ncout->putAtt( "date_created", date_created_);
3109  ncout->putAtt( "ProductionTime", date_created_);
3110  ncout->putAtt( "keywords_vocabulary", keywords_vocabulary_);
3111  ncout->putAtt( "stdname_vocabulary", stdname_vocabulary_);
3112  ncout->putAtt( "creator_name", creator_name_);
3113  ncout->putAtt( "creator_email", creator_email_);
3114  ncout->putAtt( "creator_url", creator_url_);
3115  ncout->putAtt( "project", project_);
3116  ncout->putAtt( "publisher_name", publisher_name_);
3117  ncout->putAtt( "publisher_url", publisher_url_);
3118  ncout->putAtt( "publisher_email", publisher_email_);
3119  ncout->putAtt( "processing_level", processing_level_);
3120  ncout->putAtt( "cdm_data_type", cdm_data_type_);
3121  ncout->putAtt( "history", history_);
3122  ncout->putAtt( "source", source_files_);
3123  ncout->putAtt( "time_coverage_start", time_coverage_start_);
3124  ncout->putAtt( "time_coverage_end", time_coverage_end_);
3125  ncout->putAtt( "PGE_StartTime", pge_start_time_);
3126  ncout->putAtt( "PGE_EndTime", pge_end_time_);
3127  ncout->putAtt( "StartTime", pge_start_time_);
3128  ncout->putAtt( "EndTime", pge_end_time_);
3129  string pge_name_ = basename((char*)afrt_get_option("PGE_Name").c_str());
3130  if (!pge_name_.empty()) {
3131  ncout->putAtt("PGE_Name",pge_name_);
3132  }
3133  string versionid_ = basename((char*)afrt_get_option("VersionID").c_str());
3134  if (!versionid_.empty()) {
3135  ncout->putAtt("VersionId",versionid_);
3136  }
3137 
3138  ncout->putAtt( "title", title_ );
3139  ncout->putAtt( "platform", platform_);
3140  ncout->putAtt( "instrument", sensor_ );
3141  ncout->putAtt( "product_name", prod_name_ );
3142  ncout->putAtt( "LocalGranuleID", prod_name_);
3143 
3144  return RT_SUCCESS;
3145 }
void af_rt1_read_(char *infile, char *phsdir, char *rt1dir, char *ozone_lut, char *atm_lut, char *coeff_lut, int *nsd, int *iair, int *iprin, int *ipsudo, int *ioptn, int *idust, int *iaprof, int *iblyr, int *icld, int *nch, int *nt55, int *nrh, int *kset, int *ilam1, int *ilam2, int *isd1, int *isd2, int *itau1, int *itau2, int *kznum, int *krhum, double *deltau, double *psrfc, double *ht_dust, double *sigma_dust, double *pcldtop, double *pcldbtm, double *taum55, double *xlamb, double *c0, double *c1, double *c2, double *beta, double *rho, double *ppo, double *x101, double *temp101, double *htdd, double *ppodd, double *dxdd, double *znpdd, int *nortau, int *ioznab, int *nrmww, double *qst, double *qtt, double *qst5, double *qtt5)
virtual int initialize()
int32 value
Definition: Granule.c:1235
data_t t[NROOTS+1]
Definition: decode_rs.h:77
void af_ocn_process_(char *ocndir, int *alam, int *asig, int *iopt, int *isig, int *isolz, int *nsza, int *ntha, int *nphi, double *dlth, double *dlph, double *xr, double *xi, double *v, double *thcel, double *phcel, double *wav, double *tha, double *sig_hg, double *solz, int *iprob, double *thp, double *phcnd, double *thcnd, double *txx, double *pti, double *xinlpi, double *xi_hgpi, double *xin2pi, double *xin2top)
int write_global_attributes(NcFile *nc_output)
const std::string INPUT_ATM_RT1
Definition: AfrtOptions.cpp:39
int j
Definition: decode_rs.h:73
const std::string ODIR_PHS
Definition: AfrtOptions.cpp:41
int status
Definition: l1_czcs_hdf.c:32
const std::string INPUT_ITRANS
Definition: AfrtOptions.cpp:92
#define L(lambda, T)
Definition: PreprocessP.h:185
void af_rt2_process_(char *odir, int *ailm, int *aisd, int *airh, int *aitau, int *aiwnd, int *airef, int *aitrans, int *aiset, int *airh1, int *airh2, int *ailm1, int *ailm2, int *aisd1, int *aisd2, int *aitau1, int *aitau2, int *aithe01, int *aithe02, int *aiwnd1, int *aiwnd2, int *anx, int *anthe0, int *anwl, int *anrh, int *ansd, int *aiww, int *akrhum, int *aiprin, int *aipol, int *anpass1, int *anpass2, int *aicrft, int *aiactflx, int *aisurf, int *aiglint, int *aiocn, int *aifoam, int *aiwatr, int *aiconc, double *adtheta, double *adphi, double *ahcrft, double *arx, double *athe0in, double *awwl, double *aalbwat, int *ifunc, int *mfunc, double *arefr, double *arefi, double *armin, double *armax, double *adeltar, double *adeltax, double *arg, double *asig, double *anpar, double *ar11, double *ar22, double *ar33, double *ar44, double *areff, double *aveff, double *accn, double *absr, double *asalb, double *aasf, double *aqscat, double *aqext, double *at, double *athd, double *xr, double *xi, double *v, double *thcel, double *phcel, double *atxx, double *apti, double *awvlth, double *apsrfc, double *arho, double *axozn, double *atautot, double *adeltau, double *atrp, double *atmp, double *atap, double *atcar, double *atwat, double *atozn, double *ahtlvl, double *applvl, double *adtrr, double *adtmm, double *adtaa, double *adtot, double *ahtdv, double *apdv, double *ataur, double *ataum, double *ataua, int *aifc, int *anmodl, int *anolyr, int *apsudo, float *abfr, double *tma, double *tmb, double *tmc, double *tmfd, double *tmfu, double *tms, double *tmg, double *tmh, double *tmp, double *tmq, double *tmt, double *tmpp, double *tmqq, double *tmrr, double *tmss, double *transm, double *tmcfd, double *tmcfu, double *tmf1, double *tmf2, double *xzeroz, double *xzerod, double *tupz, double *tdwnz)
boost::multi_array< double, 5 > double_5darray
Definition: AfrtConstants.h:23
const std::string INPUT_WAVELENGTHS
Definition: AfrtOptions.cpp:69
double afrt_get_option_double(const std::string &name)
const std::string INPUT_IPROB
const std::string INPUT_SEA_NR
Definition: AfrtOptions.cpp:77
const std::string ODIR_RT1
Definition: AfrtOptions.cpp:43
const std::string INPUT_TAU_INDEX
Definition: AfrtOptions.cpp:55
#define NULL
Definition: decode_rs.h:63
int insd
Definition: AfrtProcess.h:67
subroutine ccn(ifunc, irgm)
Definition: phs.f:940
const std::string OFILE_NC4
Definition: AfrtOptions.cpp:51
subroutine angl
Definition: angl.f:2
const std::string INPUT_RAYLEIGH
Definition: AfrtOptions.cpp:84
const std::string INPUT_ACTFLX
Definition: AfrtOptions.cpp:95
virtual ~AfrtProcess()
int initialize_nc4(string ofile)
const std::string INPUT_DELTA_TAU
Definition: AfrtOptions.cpp:60
NcFile * open_nc4(string ofile)
double * afrt_get_option_doubles(const std::string &name, int &count)
float32 * pos
Definition: l1_czcs_hdf.c:35
const std::string INPUT_AEROSOLS
Definition: AfrtOptions.cpp:85
void af_phs_read_(char *infile, int *nlam, int *nsd, int *ilam1, int *ilam2, int *isd1, int *isd2, int *ifunc, int *jnorm, int *jrgm, int *mfunc, int *irh, int *iset, char *xtitle, double *xww, double *xn1, double *xn2, double *xrg, double *xsig, double *xnpar, double *xdx, double *epar)
float tm[MODELMAX]
const std::string INPUT_OPTDEPTHS
Definition: AfrtOptions.cpp:73
const std::string INPUT_PHI_CELL
Definition: AfrtOptions.cpp:81
boost::multi_array< double, 1 > double_1darray
Definition: AfrtConstants.h:17
const std::string INPUT_RT2
Definition: AfrtOptions.cpp:37
const std::string INPUT_ANGLES
Definition: AfrtOptions.cpp:72
const std::string INPUT_GLINT
Definition: AfrtOptions.cpp:97
@ string
const std::string INPUT_PSUDO
Definition: AfrtOptions.cpp:83
float tp[MODELMAX]
Definition: atrem_corl1.h:173
const std::string ODIR_OCN
Definition: AfrtOptions.cpp:42
void af_phs_process_(char *phsdir, int *ilam, int *isd, int *isd1, int *isd2, int *ifunc, int *jnorm, int *jrgm, int *mfunc, int *irh, int *iset, char *xtitle, double *xww, double *refr, double *refi, double *xrg, double *xsig, double *xnpar, double *xdx, double *epar, double *rmin, double *rmax, double *deltar, double *deltax, double *r11, double *r22, double *r33, double *r44, double *reff, double *veff, double *ccnsml, double *bsr, double *salb, double *asf, double *qscat, double *qext, double *angl, double *phfu, double *pol, double *thd, double *t, double *rbar, double *dnzp, double *dnp, double *dvp, double *sumnp, double *wt)
const double F
const std::string INPUT_SEA_NI
Definition: AfrtOptions.cpp:78
boost::multi_array< double, 8 > double_8darray
Definition: AfrtConstants.h:26
int write_nc4(NcFile *ncout)
const std::string INPUT_GASES
Definition: AfrtOptions.cpp:86
const std::string INPUT_OCN
Definition: AfrtOptions.cpp:35
virtual int write_nc4(NcFile *ncout)
data_t tmp
Definition: decode_rs.h:74
int read_nc4(std::string filepath, int l1, int l2, int s1, int s2)
const std::string INPUT_IOCN
Definition: AfrtOptions.cpp:98
const std::string INPUT_WINDSPEEDS
Definition: AfrtOptions.cpp:71
std::string afrt_get_option(const std::string &name)
const int RT_FAIL
Definition: AfrtConstants.h:35
void af_rt2_input_(char *infile, int *iref, int *itrans, int *iset, int *irh1, int *irh2, int *ilm1, int *ilm2, int *isd1, int *isd2, int *itau1, int *itau2, int *ithe01, int *ithe02, int *iwnd1, int *iwnd2, int *nx, int *nthe0, int *nwl, int *nrh, int *iww, int *krhum, int *iprin, int *ipol, int *npass1, int *npass2, int *icrft, int *iactflx, int *isurf, int *iglint, int *iocn, int *ifoam, int *iwatr, int *iconc, double *dtheta, double *dphi, double *hcrft, double *rx, double *the0in, double *wwl, double *albwat)
const std::string INPUT_SD_INDEX
Definition: AfrtOptions.cpp:54
int afrt_get_option_int(const std::string &name)
const int RT_SUCCESS
Definition: AfrtConstants.h:34
void af_rt2_read_(char *adir1, char *adir2, char *adir3, char *adir4, char *adir5, int *ailm, int *aisd, int *airh, int *aiwind, int *aitau, int *aiset, int *airef, int *aipol, int *aiww, int *akrhum, double *awwl, double *aalbwat, int *ifunc, int *mfunc, double *refr, double *refi, double *rmin, double *rmax, double *deltar, double *deltax, double *rg, double *sig, double *npar, double *r11, double *r22, double *r33, double *r44, double *reff, double *veff, double *ccn, double *bsr, double *salb, double *asf, double *qscat, double *qext, double *t, double *thd, double *xr, double *xi, double *v, double *thcel, double *phcel, double *txx, double *pti, double *wvlth, double *psrfc, double *rho, double *xozn, double *tautot, double *deltau, double *trp, double *tmp, double *tap, double *tcar, double *twat, double *tozn, double *htlvl, double *pplvl, double *dtrr, double *dtmm, double *dtaa, double *dtot, double *htdv, double *pdv, double *taur, double *taum, double *taua, int *ifc, int *nmodl, int *nolyr, float *bfr)
const std::string INPUT_FOAM
Definition: AfrtOptions.cpp:99
const std::string INPUT_SURF
Definition: AfrtOptions.cpp:96
const std::string INPUT_WL_INDEX
Definition: AfrtOptions.cpp:53
const std::string INPUT_RT1
Definition: AfrtOptions.cpp:36
string filepath
Definition: color_dtdb.py:207
#define basename(s)
Definition: l0chunk_modis.c:29
const std::string INPUT_WIND_INDEX
Definition: AfrtOptions.cpp:56
const std::string INPUT_IAIR
Definition: AfrtOptions.cpp:87
const std::string INPUT_CRFT
Definition: AfrtOptions.cpp:94
const std::string INPUT_THETA_CELL
Definition: AfrtOptions.cpp:80
double beta
const std::string INPUT_COEFF_RT1
Definition: AfrtOptions.cpp:40
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
int * afrt_get_option_ints(const std::string &name, int &count)
const std::string INPUT_POL
Definition: AfrtOptions.cpp:93
const std::string INPUT_OZONE_RT1
Definition: AfrtOptions.cpp:38
const bool bDeflateFilter
const std::string INPUT_SURF_PRESSURE
Definition: AfrtOptions.cpp:61
virtual int process()
const std::string INPUT_PHS
Definition: AfrtOptions.cpp:34
void af_ocn_read_(char *infile, int *nww, int *iopt, int *isig, int *isolz, int *nsza, int *nthe, int *nphi, int *nsig, int *ibgn, int *iend, double *dlth, double *dlph, double *xr, double *xi, double *v, double *thcel, double *phcel, double *wav, double *tha, double *sig_hg, double *solz)
data_t s[NROOTS]
Definition: decode_rs.h:75
const std::string ODIR_RT2
Definition: AfrtOptions.cpp:44
virtual int read_af()
bool afrt_get_option_bool(const std::string &name)
phs_in * in_
Definition: AfrtProcess.h:570
void af_rt1_process_(char *rt1dir, int *ailam, int *aisd, int *airh, int *aitau, int *aiair, int *aiprin, int *aipsudo, int *aioptn, int *aidust, int *aiaprof, int *aiblyr, int *aicld, int *anch, int *ant55, int *ansd, int *anrh, int *akset, int *akznum, int *akrhum, double *adeltau, double *apsrfc, double *aht_dust, double *asigma_dust, double *apcldtop, double *apcldbtm, double *ataum55, double *axlamb, double *ac0, double *ac1, double *ac2, double *abeta, double *arho, double *appo, double *ax101, double *atemp101, double *ahtdd, double *appodd, double *adxdd, double *aznpdd, int *anortau, int *aioznab, int *anrmww, double *aqst, double *aqtt, double *aqst5, double *aqtt5, double *htlvl, double *pplvl, double *fr, double *fn, double *fa, double *ftot, double *dtrr, double *dtmm, double *dtaa, double *dtot, double *trp, double *tmp, double *tap, double *salb, double *turbhl, double *dx, double *x, double *tozn101, double *htdv, double *pdv, double *taur, double *taum, double *taua, double *tau, double *wvlth, double *psrfc, double *rho, double *xozn, double *tautot, double *dtau1, int *nolyr, double *tcar, double *twat, double *tozn, int *ifc, int *nmodl)
int write_nc4(size_t l1, size_t s1, size_t t1, size_t w1)
const std::string INPUT_WATR
const bool bShuffleFilter
const std::string INPUT_IREF
Definition: AfrtOptions.cpp:89
const double pace_wavelengths[NUM_PACE_BANDS]
virtual int initialize()
const int deflateLevel
int i
Definition: decode_rs.h:71
const std::string ODIR_NC4
Definition: AfrtOptions.cpp:45
int k
Definition: decode_rs.h:73
const std::string INPUT_HUMIDITIES
Definition: AfrtOptions.cpp:70
const std::string INPUT_DELTA_PHI
Definition: AfrtOptions.cpp:76
float p[MODELMAX]
Definition: atrem_corl1.h:131
int count
Definition: decode_rs.h:79