NASA Logo
Ocean Color Science Software

ocssw V2022
atmospheric_correction.f90
Go to the documentation of this file.
2 
4 
5 implicit none
6 
7 private
8 
10 
11 !... scale in p, tpw and miu dimension:
12 
13 INTEGER, PARAMETER :: NumberOfPressureHeights = 10
14 REAL, DIMENSION(NumberOfPressureHeights), PARAMETER :: &
15 heightScale = (/ 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000. /)
16 
17 
18 ! changed by G. Wind 5.6.04 to match the new axis of transmittance table
19 INTEGER, PARAMETER :: NumberOfPrecipitableWater = 53
20 REAL, DIMENSION(NumberOfPrecipitableWater), PARAMETER :: &
21  pwScale = (/ 0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, &
22  0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6,1.8, &
23  2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, &
24  4.2, 4.4, 4.6, 4.8, 5.0, 5.2, 5.4, 5.6, 5.8, 6.0, 6.2, &
25  6.4, 6.6, 6.8, 7.0, 7.2, 7.4, 7.6, 7.8, 8.0, 8.2, 8.4, &
26  8.6 /)
27 
28 INTEGER, PARAMETER :: NumberOfMiu = 20
29 REAL, DIMENSION(NumberOfMiu), PARAMETER :: &
30 miuScale = (/ 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, &
31  0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, &
32  0.95, 1.00 /)
33 
34 
35 contains
36 
37 #if AMS_INST | ASTER_INST | AVIRIS_INST | RSP_INST | EPIC_INST | SSFR_INST
38 subroutine fascode_vals(xpoint, ypoint, P, model, emission, trans2way, trans1way, trans2way_mean, &
39  trans2way_low, trans2way_high, trans1way_low, trans1way_high)
41 
42  real, intent(in) :: P
43  type(ancillary_type), intent(in) :: model
44  real, intent(inout) :: emission, trans2way, trans1way
45  real, intent(inout) :: trans2way_mean, trans1way_low, trans1way_high, trans2way_low, trans2way_high
46  integer, intent(in) :: xpoint, ypoint
47 
48 end subroutine fascode_vals
49 
50 #else
51 subroutine fascode_vals(xpoint, ypoint, P, model, emission, trans2way, trans1way, trans2way_mean, &
52  trans2way_low, trans2way_high, trans1way_low, trans1way_high)
53 
60 
61  real, intent(in) :: P
62  type(ancillary_type), intent(in) :: model
63  real, intent(inout) :: emission, trans2way, trans1way
64  real, intent(inout) :: trans2way_mean, trans1way_low, trans1way_high, trans2way_low, trans2way_high
65  integer, intent(in) :: xpoint, ypoint
66 
67  integer :: i, n, ilow, ihi, istart, iend
68 
69  real :: elow, ehi, t2low, t2hi, t1low, t1hi
70 
71  istart = model%trop_level
72  iend = model%surface_level
73 
74  do i=istart, iend
75  if (p <= model%pressure_profile(i)) exit
76  end do
77 
78  if (i > iend) i = iend
79 
80  emission = rtm_rad_atm_clr(2, i)
81  trans2way = rtm_trans_2way(2,i) ! 2 way correction for 3.7um, to be used later
82  trans1way = rtm_trans_atm_clr(2,i) ! 1 way correction for 3.7um, to be user later
83 
84  if (cloud_height_method(xpoint, ypoint) == 6) then
85  trans2way_mean = rtm_trans_2way_mean(i) ! 2 way correction for 3.7um, to be used later
86 
87  trans2way_low = rtm_trans_2way_low(2,i)
88  trans2way_high = rtm_trans_2way_high(2,i)
89 
90  trans1way_low = rtm_trans_atm_clr_low(2,i)
91  trans1way_high = rtm_trans_atm_clr_high(2,i)
92 
93  else
94 
95  do ilow=istart, iend
96  if ((p-delta_pc) <= model%pressure_profile(ilow)) exit
97  end do
98  do ihi=istart, iend
99  if ((p+delta_pc) <= model%pressure_profile(ihi)) exit
100  end do
101 
102  t2low = rtm_trans_2way(2,ilow) ! 2 way correction for 3.7um, to be used later
103  t1low = rtm_trans_atm_clr(2,ilow) ! 1 way correction for 3.7um, to be user later
104 
105  t2hi = rtm_trans_2way(2,ihi) ! 2 way correction for 3.7um, to be used later
106  t1hi = rtm_trans_atm_clr(2,ihi) ! 1 way correction for 3.7um, to be user later
107 
108  trans2way_mean = ( abs(t2low - trans2way) + abs(t2hi - trans2way) ) / 2.0
109 
110  trans2way_low = t2low
111  trans2way_high = t2hi
112 
113  trans1way_low = t1low
114  trans1way_high = t1hi
115 
116 
117  endif
118 
119 
120 
121 end subroutine fascode_vals
122 #endif
123 
124 subroutine atmospheric_correction(xpoint,ypoint, iteration, meas_out, model, debug,status)
125 
126  use generalauxtype
128  use core_arrays
129  use libraryarrays
135  use ch_xfr, only: c2_cmp_there
136  implicit none
137 
138  logical, intent(in) :: debug
139  integer, intent(in) :: xpoint,ypoint, iteration
140  integer, intent(out) :: status
141  real, dimension(:), intent(inout) :: meas_out
142  type(ancillary_type), intent(in) :: model
143 
144  real :: oneway_correction(2), twoway_correction(trans_nband), &
145  oneway_standarddev(2),twoway_standarddev(trans_nband), &
146  twoway_correction_lower(trans_nband), twoway_correction_upper(trans_nband)
147  real :: cos_solarzenith, cos_viewingangle
148  integer :: errorlevel
149  integer, parameter :: oneway_correction_index = 2, twoway_correction_index =trans_nband
150  real :: angle
151  real :: emission37, trans2way37, trans1way37
152  real :: trans2way37_mean, trans2way37_low, trans2way37_high, trans1way37_low, trans1way37_high
153  real :: o3_trans_low, o3_trans_high, o3_trans_550, o3_trans_470
154 
155  real :: sdev_2way(trans_nband), sdev_1way(2), oneway_correction_lower(2), oneway_correction_upper(2)
156 
157  status = 0
158 
159  call setup_atm_corr
160 
161 
162  cos_solarzenith = cos(d2r*solar_zenith_angle(xpoint,ypoint))
163 
164  cos_viewingangle = cos(d2r*sensor_zenith_angle(xpoint,ypoint))
165 
166  angle = 1./cos_solarzenith + 1./cos_viewingangle
167 
168 ! currently the transmittance table breaks the MODIS band ordering by
169 ! choosing index the wavelength without regard to the SDS ordering implicit
170 ! in the data
171 ! bottom line; in the transmittance data .94 site between .86 and 1.2
172 ! in the measurements .94 sits betweem 2.1 and 3.7 (because .94 is in the 1km dataset)
173 
174  if ( cloud_top_pressure(xpoint,ypoint) >= 0. .and. &
175  cloud_top_temperature(xpoint, ypoint) >= 0. ) then
176 
177  call gettransmittancedata(oneway_correction_index, &
178  twoway_correction_index, &
181  cloud_top_pressure(xpoint,ypoint), &
182  abovecloud_watervapor(xpoint,ypoint), &
183  cos_solarzenith, &
184  cos_viewingangle, &
185  oneway_correction, &
186  twoway_correction, &
187  oneway_standarddev, &
188  twoway_standarddev, &
189  errorlevel)
190  if (have_fascode) then
193  cloud_top_pressure(xpoint,ypoint), &
194  abovecloud_watervapor(xpoint,ypoint)*(1. - watervapor_error), &
195  cos_solarzenith, &
196  cos_viewingangle, &
197  twoway_correction_lower, &
198  errorlevel)
201  cloud_top_pressure(xpoint,ypoint), &
202  abovecloud_watervapor(xpoint,ypoint)*(1. + watervapor_error), &
203  cos_solarzenith, &
204  cos_viewingangle, &
205  twoway_correction_upper, &
206  errorlevel)
207  else
208  call gettransmittancedata(oneway_correction_index, &
209  twoway_correction_index, &
212  cloud_top_pressure(xpoint,ypoint), &
213  abovecloud_watervapor(xpoint,ypoint)*(1. - watervapor_error), &
214  cos_solarzenith, &
215  cos_viewingangle, &
216  oneway_correction_lower, &
217  twoway_correction_lower, &
218  sdev_1way, &
219  sdev_2way, &
220  errorlevel)
221  call gettransmittancedata(oneway_correction_index, &
222  twoway_correction_index, &
225  cloud_top_pressure(xpoint,ypoint), &
226  abovecloud_watervapor(xpoint,ypoint)*(1. + watervapor_error), &
227  cos_solarzenith, &
228  cos_viewingangle, &
229  oneway_correction_upper, &
230  twoway_correction_upper, &
231  sdev_1way, &
232  sdev_2way, &
233  errorlevel)
234  endif
235 
236 
237 ! the values will never be fill, because there has been a change in the gettransmittance routines
238 ! used above. G.Wind 2.2.05
239 
240 
241 ! we need to re-order the mean
242 
243  meandelta_trans(1:trans_nband) = ( abs(twoway_correction_lower - twoway_correction) + &
244  abs(twoway_correction_upper - twoway_correction) ) /2.
245  transmittance_twoway(1:trans_nband) = twoway_correction
246  transmittance_stddev(1:trans_nband) = twoway_standarddev
247 
248 ! we are not using the table, so transmittance for 3.7um is from FASCODE and there is no standard deviation as it's not
249 ! statistical.
250  if (do_37) then
251  if (have_fascode) then
252  call fascode_vals(xpoint, ypoint, cloud_top_pressure(xpoint, ypoint), model, emission37, trans2way37, trans1way37, &
253  trans2way37_mean, trans2way37_low, trans2way37_high, trans1way37_low, trans1way37_high )
254 
255  meandelta_trans(band_0370) = trans2way37_mean
257  else
258  emission37 = 0.
259  endif
260 
261  endif
262 
263  else
264 
265 ! these values are set to have a benign effect on subsequent computations
266 ! status is set an an early return performed. It is expected that subsequest
267 ! retrieval computation on this scene will be terminated
268  oneway_correction = 1.
269  twoway_correction = 1.
270 
271  transmittance_twoway(:) = 1.
272  transmittance_stddev(:) = 0.
273  meandelta_trans(:) = 0.
274 
275  status = 1
276 
277  emission37 = 0.
278  trans2way37 = 1.
279  trans1way37 = 1.
280  trans2way37_mean = 1.
281 
282  return
283  endif
284 ! Beer's law for ozone transmittance from M.D. King
285  ozone_transmittance = exp(-1.0 * column_ozone(xpoint, ypoint)* ozone_absorp_coeff * angle)
286 
287  o3_trans_low = exp(-1.0 * 0.8*column_ozone(xpoint, ypoint)* ozone_absorp_coeff * angle)
288  o3_trans_high = exp(-1.0 * 1.2*column_ozone(xpoint, ypoint)* ozone_absorp_coeff * angle)
289  mean_delta_ozone = (abs(o3_trans_low - ozone_transmittance) + abs(o3_trans_high - ozone_transmittance))/2.0
290 
291 ! the only thing that channels 3 and 4 have absorption from is ozone
292 ! used for discriminating very uniform stratocumulus from aerosol when CSR=2 for the GMAO FFNET code
293 
294  if (have_band(1)) then
295  o3_trans_470 = exp(-1.0 * column_ozone(xpoint, ypoint)* o3_coef_470 * angle)
296  if (meas_out(band_0047) /= fillvalue_real)&
297  meas_out(band_0047) = meas_out(band_0047) / o3_trans_470
298  endif
299  if (have_band(2)) then
300  o3_trans_550 = exp(-1.0 * column_ozone(xpoint, ypoint)* o3_coef_550 * angle)
301  if (meas_out(band_0055) /= fillvalue_real)&
302  meas_out(band_0055) = meas_out(band_0055) / o3_trans_550
303  endif
304 
305  if (have_band(3)) then
306  if (meas_out(band_0065) /= fillvalue_real) &
307  meas_out(band_0065) = meas_out(band_0065)/ &
308  (ozone_transmittance*twoway_correction(band_0065)) ! .68
312  endif
313 
314  if (have_band(4)) then
315  if (meas_out(band_0086) /= fillvalue_real) &
316  meas_out(band_0086) = meas_out(band_0086)/&
317  twoway_correction(band_0086) ! .86
318  endif
319  ! WDR orig, out: if (have_band(5)) then
320  if (c2_cmp_there(band_0935) == 1 ) then
321  if (meas_out(band_0935) /= fillvalue_real) &
322  meas_out(band_0935) = meas_out(band_0935)/&
323  twoway_correction(band_0935) ! .94
324  endif
325  if (have_band(6)) then
326  if (meas_out(band_0124) /= fillvalue_real) &
327  meas_out(band_0124) = meas_out(band_0124)/&
328  twoway_correction(band_0124) ! 1.2
329  endif
330  if (have_band(7)) then
331  if (meas_out(band_0163) /= fillvalue_real) &
332  meas_out(band_0163) = meas_out(band_0163)/&
333  twoway_correction(band_0163) ! 1.6
334  endif
335  if (have_band(8)) then
336  if (meas_out(band_0213) /= fillvalue_real) &
337  meas_out(band_0213) = meas_out(band_0213)/&
338  twoway_correction(band_0213) ! 2.1
339  endif
340 
341  if (have_band(9)) then
342  if (meas_out(band_0226) /= fillvalue_real) &
343  meas_out(band_0226) = meas_out(band_0226)/&
344  twoway_correction(band_0226) ! 2.2
345  endif
346 
347 
348  thermal_correction_twoway(1:2) = 1.
349  thermal_correction_oneway(1:2) = 1.
350 
351 ! 3.7 transmittance corrections cannot be applied until we have seperated the visible/thermal contribution to
352 ! the total radiance
353  if (do_37) then
354 ! subtract the emission due to atmosphere above cloud from measured radiance
355 #ifndef SIM_NORAD
356  meas_out(band_0370) = meas_out(band_0370) - emission37
357 #endif
358 
359  if (have_fascode) then
360  transmittance_twoway(band_0370) = trans2way37
361  else
362 #if !VIIRS_INST && !AHI_INST
364  trans2way37 = twoway_correction(band_0370)
365  trans1way37 = oneway_correction(1)
366  trans1way37_low = oneway_correction_lower(1)
367  trans1way37_high = oneway_correction_upper(1)
368  trans2way37_low = twoway_correction_lower(band_0370)
369  trans2way37_high = twoway_correction_upper(band_0370)
370 #endif
371  endif
372  else
373  trans2way37 = 1.
374  trans1way37 = 1.
375  trans1way37_low = 1.
376  trans1way37_high = 1.
377  trans2way37_low = 1.
378  trans2way37_high = 1.
379  endif
380 
381  thermal_correction_twoway(1) = trans2way37 ! 2 way correction for 3.7um, to be used later
382  thermal_correction_oneway(1) = trans1way37 ! 1 way correction for 3.7um, to be user later
383 
384  thermal_correction_oneway_low(1) = trans1way37_low
385  thermal_correction_oneway_high(1) = trans1way37_high
386  thermal_correction_twoway_low(1) = trans2way37_low
387  thermal_correction_twoway_high(1) = trans2way37_high
388 
389 
390 end subroutine atmospheric_correction
391 
392 SUBROUTINE gettransmittancedata(KDIM_1WAY, &
393  KDIM_2WAY, &
394  BigTauTable, &
395  BigSdevTable,&
396  p, &
397  tpw, &
398  miu0, &
399  miu1, &
400  tau1way, &
401  tau2way, &
402  sdev1way, &
403  sdev2way, &
404  errorLevel)
405 !................................................................................
406 !
407 !................................................................................
408 ! !F90
409 !
410 ! !DESCRIPTION:
411 ! given pressure, integrated precipitable water amount, miu0 and miu1, this
412 ! program returns:
413 ! (1) one way transmittance for 3.7 and 11 um bands.
414 ! (2) two way transmittance for 0.67, 0.86, 1.2, 1.6, 2.1 and 3.7 um bands.
415 !
416 !
417 ! !INPUT PARAMETERS:
418 !
419 ! KDIM_1WAY = delcared band-dimension for 1-way tau array; >= 2
420 ! KDIM_2WAY = declared band-dimension for 2-way tau array; >= 6
421 !
422 ! p(XDIM, YDIM) = pressure height in mb.
423 ! tpw(XDIM, YDIM) = precipitable water (g/cm2) from level p to TOA.
424 ! miu0(XDIM, YDIM) = cosine of solar zenith angle.
425 ! miu1(XDIM, YDIM) = cosine of viewing zenith at level p.
426 !
427 !
428 ! !OUTPUT PARAMETERS:
429 !
430 ! tau1way(XDIM, YDIM, 2) = contains 1-way spectral transmittance information.
431 ! tau2way(XDIM, YDIM, 6) = contains 2-way spectral transmittance information.
432 ! sdev1way(XDIM, YDIM, 2) = contains 1-way standard deviations.
433 ! sdev2way(XDIM, YDIM, 6) = contains 2-way standard deviations.
434 !
435 ! *** Note ***: Fill value for tau1way and tau2way is -1.
436 !
437 ! errorLevel = return error status
438 ! 0 : none.
439 ! 1 : second nearest neighbour maybe used (warning).
440 ! 2 : cannot find required files (fatal)
441 !
442 !
443 !
444 !
445 ! !REQUIRED EXTERNAL PROGRAMS:
446 ! netcdf.f90 and ModisAuxType.f90
447 !................................................................................
448 ! !Revision History:
449 !
450 !
451 ! Revision 2.5 2004/06/30 MAG
452 ! fixed confusion between transmittance table and standard deviation table
453 !
454 ! Revision 2.5 2004/05/06 wind
455 ! added standard deviation processing in order to facilitate uncertainty calculations
456 ! Revision 2.0 2002/10/25 wind,mag
457 ! add bilinear smoothing to fields
458 !
459 ! Revision 1.5 2001/05/01 18:50:08 jyli
460 ! read entire transmittance table once to speed up process.
461 !
462 ! Revision 1.4 2001/04/18 21:56:35 jyli
463 ! return both 1-way (for longwave) and 2-way (for shortwave) tau.
464 !
465 ! Revision 1.3 2001/04/06 19:11:57 jyli
466 ! first delivery version which includs MODIS run environment stuff.
467 !
468 ! Revision 1.1 2001/04/06 18:46:11 jyli
469 ! Initial revision
470 !
471 !................................................................................
472 ! !Team-unique Header:
473 ! Cloud Retrieval Group, NASA/GSFC
474 !
475 ! !PROGRAMMER:
476 !
477 ! Mark Gray (L3 Com)
478 ! Climate and Radiation Branch
479 ! NASA Goddard Space Flight Center
480 ! Greenbelt, Maryland 20771, U.S.A.
481 !
482 ! Gala Wind (L3 Com)
483 ! Climate and Radiation Branch
484 ! NASA Goddard Space Flight Center
485 ! Greenbelt, Maryland 20771, U.S.A.
486 !
487 ! Jason Li (Emergent-IT)
488 ! Climate and Radiation Branch
489 ! NASA Goddard Space Flight Center
490 ! Greenbelt, Maryland 20771, U.S.A.
491 !*******************************************************************************
492 ! !END
496 use ch_xfr, only : c2_cmp_there
497 
498 IMPLICIT NONE
499 
500 
501 !... i/o variable delcarations:
502 
503 INTEGER, intent(in) :: KDIM_1WAY, KDIM_2WAY
504 REAL , intent(in) :: p, tpw, miu0, miu1
505 REAL, intent(out),DIMENSION(KDIM_1WAY) :: tau1way, sdev1way
506 REAL, intent(out),DIMENSION(KDIM_2WAY) :: tau2way, sdev2way
507 INTEGER, intent(out) :: errorLevel
508 REAL, intent(in), DIMENSION(:,:,:,:) :: bigTauTable, bigSdevTable
509 
510 
511 INTEGER :: i, pIndex, miu1Index, miu2Index, pwIndex, set_fill
512 INTEGER, DIMENSION(4) :: start, counts, mindex
513 
514 INTEGER :: NumberOfPixels_1km, NumberOfLines_1km
515 
516 REAL :: miu, tauValue
517 real :: tau11, tau12, tau21, tau22, tau_mid1, tau_mid2
518 real :: sdev11, sdev12, sdev21, sdev22, sdev_mid1, sdev_mid2
519 Integer :: first_pwIndex, first_miuindex, second_pwIndex, second_miuindex
520 real, dimension(8) :: temp_trans, temp_sdev
521 !................................................................................
522 
523 
524 ! initialize values
525 temp_trans = -999.
526 temp_sdev = -999.
527 
528 
529 errorlevel = 0
530 
531  miu = (miu0*miu1)/(miu0+miu1)
532 
533 !
534 !... find array indicies along p, pw and miu dimension:
535 !
536  pindex = nint( (p - heightscale(1)) / 100.0 ) + 1
537  set_fill = 0
538  if (p< 0. .and. tpw < 0.) set_fill = 1
539 
540  if(pindex < 1) then
541  pindex = 1
542  errorlevel = 1
543  elseif(pindex > numberofpressureheights) then
544  pindex = numberofpressureheights
545  errorlevel = 1
546  endif
547 
548  miu1index = nint( (miu1 - miuscale(1)) / 0.05 ) + 1
549  if (miu1index < 1) then
550  miu1index = 1
551  errorlevel = 1
552  elseif(miu1index > numberofmiu) then
553  miu1index = numberofmiu
554  errorlevel = 1
555  endif
556 
557  miu2index = nint( (miu - miuscale(1)) / 0.05 ) + 1
558  if (miu2index < 1) then
559  miu2index = 1
560  errorlevel = 1
561  elseif(miu2index > numberofmiu) then
562  miu2index = numberofmiu
563  errorlevel = 1
564  endif
565 
566 
567 ! changed by G. Wind 5.6.04 to match the new bins in transmittance table
568  if(tpw < 0.0) then
569  pwindex = 1
570  errorlevel = 1
571  elseif(tpw < 0.2) then
572  pwindex = nint( (tpw- pwscale(1)) / 0.02 ) + 1
573  else
574  pwindex = nint( (tpw - pwscale(11)) / 0.20 ) + 11
575  if(pwindex > numberofprecipitablewater) then
576  pwindex = numberofprecipitablewater
577  errorlevel = 1
578  endif
579  endif
580 
581  !...
582  !... 1-way case (for longwave 3.7 and 11 micron bands):
583  !...
584 
585  mindex(1) = pindex
586  mindex(2) = pwindex
587  mindex(3) = miu1index
588  mindex(4) = 1
589 
590  tauvalue = bigtautable(mindex(1),mindex(2),mindex(3),mindex(4))
591 
592 ! we need to step back until we find a value that is non-fill, the second neighbor will not be
593 ! enough in many cases
594 
595  if (tauvalue < 0.0) then ! do I need 2nd nearest neighbour?
596 ! errorLevel = 1
597 ! mindex(2) = pwIndex - 1
598 
599  do i=mindex(2), 1, -1
600  tauvalue = bigtautable(mindex(1),i,mindex(3),mindex(4))
601  if (tauvalue >= 0.) exit
602  end do
603 
604 ! now we have a good value of trans, non-fill, so we set the index accordingly
605  mindex(2) = i
606 
607  endif
608 
609 ! grab the 4 points for bilinear interpolation: pw1,u1 pw2,u1 pw1,u2, pw2,u2
610 
611  if (pwscale(mindex(2)) >= tpw ) then
612  second_pwindex = mindex(2)
613  if (mindex(2) == 1) then
614  first_pwindex = mindex(2)
615  else
616  first_pwindex = mindex(2) - 1
617  if (bigtautable(mindex(1), first_pwindex, mindex(3), mindex(4)) < 0.) &
618  first_pwindex = mindex(2)
619  endif
620 
621  else
622  first_pwindex = mindex(2)
623  if (mindex(2) == numberofprecipitablewater) then
624  second_pwindex = mindex(2)
625  else
626  second_pwindex = mindex(2) + 1
627  if (bigtautable(mindex(1),second_pwindex,mindex(3),mindex(4)) < 0.0) &
628  second_pwindex = mindex(2)
629  endif
630  endif
631 
632  if (miuscale(miu1index) >= miu1 ) then
633  first_miuindex = miu1index -1
634  second_miuindex = miu1index
635  else
636  first_miuindex = miu1index
637  second_miuindex = miu1index + 1
638  endif
639 
640  if( c2_cmp_there(band_0370) == 1) then
641  do i = 1, numberoflongwavelengths
642  mindex(4) = bandindexmaplw(i)
643 
644  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
645  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
646 
647  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
648  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
649 
650  sdev11 = bigsdevtable(pindex, first_pwindex, first_miuindex, mindex(4))
651  sdev12 = bigsdevtable(pindex, first_pwindex, second_miuindex, mindex(4))
652 
653  sdev21 = bigsdevtable(pindex, second_pwindex, first_miuindex, mindex(4))
654  sdev22 = bigsdevtable(pindex, second_pwindex, second_miuindex, mindex(4))
655 
656 
657  ! first we interpolate along the PW lines
658  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
659  (/tau11, tau21 /), &
660  tpw)
661  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
662  (/tau12, tau22 /), &
663  tpw)
664 
665  sdev_mid1 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
666  (/sdev11, sdev21/), &
667  tpw)
668  sdev_mid2 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
669  (/sdev12, sdev22/), &
670  tpw)
671 
672 
673  ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
674  ! (bilinear interpolation)
675  tau1way(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
676  (/tau_mid1, tau_mid2/), &
677  miu1)
678  sdev1way(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
679  (/sdev_mid1, sdev_mid2/), &
680  miu1)
681  if (set_fill == 1 )then
682  tau1way(i) = -999.
683  sdev1way(i) = -999.
684  endif
685  enddo
686  endif
687 
688  !
689  !... 2-way case (for shortwave channels upto 3.7 micron band):
690  !
691 
692  mindex(2) = pwindex
693  mindex(3) = miu2index
694  mindex(4) = 1
695 
696 ! the pw_index values had already been determined and they don't change with changing miu,
697 ! so pray tell why should we recompute them. This code had been deleted. G.Wind 2.2.05
698 
699  if (miuscale(miu2index) >= miu ) then
700  first_miuindex = miu2index -1
701  second_miuindex = miu2index
702  else
703  first_miuindex = miu2index
704  second_miuindex = miu2index + 1
705  endif
706 
707  do i = 1, numberofshortwavelengths
708  mindex(4) = bandindexmapsw(i)
709 
710  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
711  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
712 
713  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
714  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
715 
716  sdev11 = bigsdevtable(pindex, first_pwindex, first_miuindex, mindex(4))
717  sdev12 = bigsdevtable(pindex, first_pwindex, second_miuindex, mindex(4))
718 
719  sdev21 = bigsdevtable(pindex, second_pwindex, first_miuindex, mindex(4))
720  sdev22 = bigsdevtable(pindex, second_pwindex, second_miuindex, mindex(4))
721 
722 ! first we interpolate along the PW lines
723  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
724  (/tau11, tau21 /), &
725  tpw)
726  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
727  (/tau12, tau22 /), &
728  tpw)
729 ! then we repeat for the standard deviations
730  sdev_mid1 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
731  (/sdev11, sdev21/), &
732  tpw)
733  sdev_mid2 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
734  (/sdev12, sdev22/), &
735  tpw)
736 ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
737 ! nothing but rather standard bilinear interpolation
738 ! and that is our answer.
739  temp_trans(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
740  (/tau_mid1, tau_mid2/), &
741  miu)
742 
743 ! and these are the final standard deviations
744  temp_sdev(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
745  (/sdev_mid1, sdev_mid2/), &
746  miu )
747  if (set_fill == 1 )then
748  temp_trans(i) = -999.
749  temp_sdev(i) = -999.
750  endif
751 
752  end do
753 
754 
755 ! remap the bands, so they can be indexed by the main instrument band index
756  call remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)
757 
758 
759 9999 RETURN
760 
761 END SUBROUTINE gettransmittancedata
762 SUBROUTINE gettransmittance_simple( &
763  BigTauTable, &
764  p, &
765  tpw, &
766  miu0, &
767  miu1, &
768  tau2way, &
769  errorLevel)
770 !................................................................................
771 !
772 !................................................................................
773 ! !F90
774 !
775 ! !DESCRIPTION:
776 ! given pressure, integrated precipitable water amount, miu0 and miu1, this
777 ! program returns:
778 ! (1) one way transmittance for 3.7 and 11 um bands.
779 ! (2) two way transmittance for 0.67, 0.86, 1.2, 1.6, 2.1 and 3.7 um bands.
780 !
781 !
782 ! !INPUT PARAMETERS:
783 !
784 ! KDIM_2WAY(xdim, ydim, n) = declared band-dimension for 2-way tau array; >= n bands
785 !
786 ! p(XDIM, YDIM) = pressure height in mb.
787 ! tpw(XDIM, YDIM) = precipitable water (g/cm2) from level p to TOA.
788 ! miu0(XDIM, YDIM) = cosine of solar zenith angle.
789 ! miu1(XDIM, YDIM) = cosine of viewing zenith at level p.
790 !
791 !
792 ! !OUTPUT PARAMETERS:
793 !
794 ! tau2way(XDIM, YDIM, n) = contains 2-way spectral transmittance information.
795 !
796 ! *** Note ***: Fill value for tau1way and tau2way is -1.
797 !
798 ! errorLevel = return error status
799 ! 0 : none.
800 ! 1 : second nearest neighbour maybe used (warning).
801 ! 2 : cannot find required files (fatal)
802 !
803 !................................................................................
804 ! !Revision History:
805 !................................................................................
806 ! !Team-unique Header:
807 ! Cloud Retrieval Group, NASA/GSFC
808 !
809 ! !PROGRAMMER:
810 !
811 ! Mark Gray (L3 Com)
812 ! Climate and Radiation Branch
813 ! NASA Goddard Space Flight Center
814 ! Greenbelt, Maryland 20771, U.S.A.
815 !
816 ! Gala Wind (L3 Com)
817 ! Climate and Radiation Branch
818 ! NASA Goddard Space Flight Center
819 ! Greenbelt, Maryland 20771, U.S.A.
820 !
821 ! Jason Li (Emergent-IT)
822 ! Climate and Radiation Branch
823 ! NASA Goddard Space Flight Center
824 ! Greenbelt, Maryland 20771, U.S.A.
825 !*******************************************************************************
826 ! !END
827 
831 
832 IMPLICIT NONE
833 
834 
835 
836 !... i/o variable delcarations:
837 
838 REAL , intent(in) :: p, tpw, miu0, miu1
839 REAL, intent(out),DIMENSION(:) :: tau2way
840 INTEGER, intent(out) :: errorLevel
841 REAL, intent(in), DIMENSION(:,:,:,:) :: bigTauTable
842 
843 
844 
845 INTEGER :: i, pIndex, miu1Index, miu2Index, pwIndex, set_fill
846 INTEGER, DIMENSION(4) :: start, counts, mindex
847 
848 INTEGER :: NumberOfPixels_1km, NumberOfLines_1km
849 
850 REAL :: miu, tauValue
851 real :: tau11, tau12, tau21, tau22, tau_mid1, tau_mid2
852 real :: sdev11, sdev12, sdev21, sdev22, sdev_mid1, sdev_mid2
853 Integer :: first_pwIndex, first_miuindex, second_pwIndex, second_miuindex
854 real, dimension(8) :: temp_trans, temp_sdev, sdev2way
855 !................................................................................
856 
857 
858 ! initialize values
859 temp_trans = -999.
860 
861 
862 
863 errorlevel = 0
864 
865  miu = (miu0*miu1)/(miu0+miu1)
866 
867 !
868 !... find array indicies along p, pw and miu dimension:
869 !
870  pindex = nint( (p - heightscale(1)) / 100.0 ) + 1
871  set_fill = 0
872  if (p< 0. .and. tpw < 0.) set_fill = 1
873 
874  if(pindex < 1) then
875  pindex = 1
876  errorlevel = 1
877  elseif(pindex > numberofpressureheights) then
878  pindex = numberofpressureheights
879  errorlevel = 1
880  endif
881 
882  miu1index = nint( (miu1 - miuscale(1)) / 0.05 ) + 1
883  if (miu1index < 1) then
884  miu1index = 1
885  errorlevel = 1
886  elseif(miu1index > numberofmiu) then
887  miu1index = numberofmiu
888  errorlevel = 1
889  endif
890 
891  miu2index = nint( (miu - miuscale(1)) / 0.05 ) + 1
892  if (miu2index < 1) then
893  miu2index = 1
894  errorlevel = 1
895  elseif(miu2index > numberofmiu) then
896  miu2index = numberofmiu
897  errorlevel = 1
898  endif
899 
900 
901 ! changed by G. Wind 5.6.04 to match the new bins in transmittance table\
902  pwindex = 1
903  if(tpw < 0.0) then
904  errorlevel = 1
905  elseif(tpw < 0.2) then
906  pwindex = nint( (tpw- pwscale(1)) / 0.02 ) + 1
907  else
908  pwindex = nint( (tpw - pwscale(11)) / 0.20 ) + 11
909  if(pwindex > numberofprecipitablewater) then
910  pwindex = numberofprecipitablewater
911  errorlevel = 1
912  endif
913  endif
914 
915  !
916  !... 2-way case (for shortwave channels upto 3.7 micron band):
917  !
918 
919  mindex(1) = pindex
920  mindex(2) = pwindex
921  mindex(3) = miu2index
922  mindex(4) = 1
923 
924  if (pwindex < 1) print*, "HERE" , mindex, tpw, p
925 
926  tauvalue = bigtautable(mindex(1),mindex(2),mindex(3),mindex(4))
927 
928 ! we need to step back until we find a value that is non-fill, the second neighbor will not be
929 ! enough in many cases
930 
931  if (tauvalue < 0.0) then ! do I need 2nd nearest neighbour?
932 ! errorLevel = 1
933 ! mindex(2) = pwIndex - 1
934 
935  do i=mindex(2), 1, -1
936  tauvalue = bigtautable(mindex(1),i,mindex(3),mindex(4))
937  if (tauvalue >= 0.) exit
938  end do
939 
940 ! now we have a good value of trans, non-fill, so we set the index accordingly
941  mindex(2) = i
942 
943  endif
944 
945 
946 ! grab the 4 points for bilinear interpolation: pw1,u1 pw2,u1 pw1,u2, pw2,u2
947  if (pwscale(mindex(2)) >= tpw ) then
948  second_pwindex = mindex(2)
949  if (mindex(2) == 1) then
950  first_pwindex = mindex(2)
951  else
952  first_pwindex = mindex(2) - 1
953  if (bigtautable(mindex(1), first_pwindex, mindex(3), mindex(4)) < 0.) &
954  first_pwindex = mindex(2)
955  endif
956 
957  else
958  first_pwindex = mindex(2)
959  if (mindex(2) == numberofprecipitablewater) then
960  second_pwindex = mindex(2)
961  else
962  second_pwindex = mindex(2) + 1
963  if (bigtautable(mindex(1),second_pwindex,mindex(3),mindex(4)) < 0.0) &
964  second_pwindex = mindex(2)
965  endif
966  endif
967 
968 
969  if (miuscale(miu2index) >= miu ) then
970  first_miuindex = miu2index -1
971  second_miuindex = miu2index
972  else
973  first_miuindex = miu2index
974  second_miuindex = miu2index + 1
975  endif
976 
977  do i = 1, numberofshortwavelengths
978  mindex(4) = bandindexmapsw(i)
979 
980  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
981  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
982 
983  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
984  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
985 
986 ! first we interpolate along the PW lines
987  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
988  (/tau11, tau21 /), &
989  tpw)
990  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
991  (/tau12, tau22 /), &
992  tpw)
993 
994 ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
995 ! nothing but rather standard bilinear interpolation
996 ! and that is our answer.
997  temp_trans(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
998  (/tau_mid1, tau_mid2/), &
999  miu)
1000 
1001  if (set_fill == 1 )then
1002  temp_trans(i) = -999.
1003  endif
1004 
1005  end do
1006 
1007 
1008 ! remap the bands, so they can be indexed by the main instrument band index
1009  temp_sdev(1) = -10000. ! we don't do standard deviation in this subroutine
1010  call remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)
1011 
1012 
1013 9999 RETURN
1014 
1015 END SUBROUTINE gettransmittance_simple
1016 
1017 
1018 
1019 
Definition: ch_xfr.f90:1
real, dimension(nchan, model_levels), public rtm_trans_atm_clr
Definition: rtm_support.f90:47
integer, parameter band_0124
integer, dimension(8) bandindexmapsw
real ozone_transmittance
real, dimension(nchan, model_levels), public rtm_trans_atm_clr_low
Definition: rtm_support.f90:58
real, dimension(set_number_of_bands) thermal_correction_oneway
real, dimension(2) thermal_correction_oneway_high
real, dimension(set_number_of_bands) meandelta_trans
integer, dimension(numberoflongwavelengths) bandindexmaplw
real, dimension(2) thermal_correction_twoway_high
real, parameter ozone_absorp_coeff
real, parameter watervapor_error
real(single), dimension(:,:), allocatable cloud_top_pressure
integer, parameter numberoflongwavelengths
integer, parameter band_0047
real function, public linearinterpolation(X, Y, XX)
integer, parameter trans_nband
real, dimension(set_number_of_bands) transmittance_twoway
integer, parameter band_0370
real, dimension(set_number_of_bands) thermal_correction_twoway
integer, parameter band_0226
integer, parameter band_0086
integer, parameter band_0213
real, dimension(nchan, model_levels), public rtm_trans_atm_clr_high
Definition: rtm_support.f90:63
real, dimension(nchan, model_levels), public rtm_rad_atm_clr
Definition: rtm_support.f90:48
real, parameter delta_pc
real, dimension(:,:), allocatable solar_zenith_angle
Definition: core_arrays.f90:6
real, dimension(nchan, model_levels), public rtm_trans_2way_high
Definition: rtm_support.f90:62
real(single), dimension(:,:), allocatable column_ozone
real mean_delta_ozone
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
real, dimension(nchan, model_levels), public rtm_trans_2way_low
Definition: rtm_support.f90:57
real, parameter o3_coef_470
real, dimension(:,:,:,:), allocatable transmit_stddev_table
real, parameter o3_coef_550
integer, parameter band_0163
real(single), dimension(:,:), allocatable cloud_top_temperature
subroutine, public atmospheric_correction(xpoint, ypoint, iteration, meas_out, model, debug, status)
real, dimension(:,:), allocatable sensor_zenith_angle
integer, parameter model_levels
integer, parameter band_0065
subroutine gettransmittancedata(KDIM_1WAY, KDIM_2WAY, BigTauTable, BigSdevTable, p, tpw, miu0, miu1, tau1way, tau2way, sdev1way, sdev2way, errorLevel)
integer, parameter band_0935
integer, parameter band_0055
real(single), dimension(:,:), allocatable abovecloud_watervapor
real, dimension(nchan, model_levels), public rtm_trans_2way
Definition: rtm_support.f90:46
real, dimension(set_number_of_bands) transmittance_stddev
integer *1, dimension(:,:), allocatable cloud_height_method
real, dimension(2) thermal_correction_oneway_low
real, dimension(2) thermal_correction_twoway_low
real, dimension(model_levels), public rtm_trans_2way_mean
Definition: rtm_support.f90:55
real, dimension(:,:,:,:), allocatable transmit_correction_table
#define abs(a)
Definition: misc.h:90
integer *1, dimension(:), allocatable c2_cmp_there
Definition: ch_xfr.f90:43
subroutine gettransmittance_simple(BigTauTable, p, tpw, miu0, miu1, tau2way, errorLevel)
subroutine remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)
logical, dimension(9) have_band