OB.DAAC Logo
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 ! integer, parameter :: band_0065 = 1, &
292 ! band_0086 = 2, &
293 ! band_0124 = 3, &
294 ! band_0163 = 4, &
295 ! band_0213 = 5, &
296 ! band_0935 = 6, &
297 ! band_0370 = 7, &
298 ! 1 2 3 4 5 6 7 8
299 ! ! 470, 550, 650, 0.86, 0.94, 1.2, 1.6, 2.1
300 ! have_band = (/.true., .true., .true., .true., .true., .true., .true., .true./)
301 
302 ! the only thing that channels 3 and 4 have absorption from is ozone
303 ! used for discriminating very uniform stratocumulus from aerosol when CSR=2 for the GMAO FFNET code
304 
305  if (have_band(1)) then
306  o3_trans_470 = exp(-1.0 * column_ozone(xpoint, ypoint)* o3_coef_470 * angle)
307  if (meas_out(band_0047) /= fillvalue_real)&
308  meas_out(band_0047) = meas_out(band_0047) / o3_trans_470
309  endif
310  if (have_band(2)) then
311  o3_trans_550 = exp(-1.0 * column_ozone(xpoint, ypoint)* o3_coef_550 * angle)
312  if (meas_out(band_0055) /= fillvalue_real)&
313  meas_out(band_0055) = meas_out(band_0055) / o3_trans_550
314  endif
315 
316  if (have_band(3)) then
317  if (meas_out(band_0065) /= fillvalue_real) &
318  meas_out(band_0065) = meas_out(band_0065)/ &
319  (ozone_transmittance*twoway_correction(band_0065)) ! .68
323  endif
324 
325  if (have_band(4)) then
326  if (meas_out(band_0086) /= fillvalue_real) &
327  meas_out(band_0086) = meas_out(band_0086)/&
328  twoway_correction(band_0086) ! .86
329  endif
330  ! WDR orig, out: if (have_band(5)) then
331  if (c2_cmp_there(band_0935) == 1 ) then
332  if (meas_out(band_0935) /= fillvalue_real) &
333  meas_out(band_0935) = meas_out(band_0935)/&
334  twoway_correction(band_0935) ! .94
335  endif
336  if (have_band(6)) then
337  if (meas_out(band_0124) /= fillvalue_real) &
338  meas_out(band_0124) = meas_out(band_0124)/&
339  twoway_correction(band_0124) ! 1.2
340  endif
341  if (have_band(7)) then
342  if (meas_out(band_0163) /= fillvalue_real) &
343  meas_out(band_0163) = meas_out(band_0163)/&
344  twoway_correction(band_0163) ! 1.6
345  endif
346  if (have_band(8)) then
347  if (meas_out(band_0213) /= fillvalue_real) &
348  meas_out(band_0213) = meas_out(band_0213)/&
349  twoway_correction(band_0213) ! 2.1
350  endif
351 
352 
353  thermal_correction_twoway(1:2) = 1.
354  thermal_correction_oneway(1:2) = 1.
355 
356 
357 
358 
359 ! 3.7 transmittance corrections cannot be applied until we have seperated the visible/thermal contribution to
360 ! the total radiance
361  if (do_37) then
362 ! subtract the emission due to atmosphere above cloud from measured radiance
363 #ifndef SIM_NORAD
364  meas_out(band_0370) = meas_out(band_0370) - emission37
365 #endif
366 
367  if (have_fascode) then
368  transmittance_twoway(band_0370) = trans2way37
369  else
370 #if !VIIRS_INST && !AHI_INST
372  trans2way37 = twoway_correction(band_0370)
373  trans1way37 = oneway_correction(1)
374  trans1way37_low = oneway_correction_lower(1)
375  trans1way37_high = oneway_correction_upper(1)
376  trans2way37_low = twoway_correction_lower(band_0370)
377  trans2way37_high = twoway_correction_upper(band_0370)
378 #endif
379  endif
380  else
381  trans2way37 = 1.
382  trans1way37 = 1.
383  trans1way37_low = 1.
384  trans1way37_high = 1.
385  trans2way37_low = 1.
386  trans2way37_high = 1.
387  endif
388 
389  thermal_correction_twoway(1) = trans2way37 ! 2 way correction for 3.7um, to be used later
390  thermal_correction_oneway(1) = trans1way37 ! 1 way correction for 3.7um, to be user later
391 
392  thermal_correction_oneway_low(1) = trans1way37_low
393  thermal_correction_oneway_high(1) = trans1way37_high
394  thermal_correction_twoway_low(1) = trans2way37_low
395  thermal_correction_twoway_high(1) = trans2way37_high
396 
397 
398 end subroutine atmospheric_correction
399 
400 SUBROUTINE gettransmittancedata(KDIM_1WAY, &
401  KDIM_2WAY, &
402  BigTauTable, &
403  BigSdevTable,&
404  p, &
405  tpw, &
406  miu0, &
407  miu1, &
408  tau1way, &
409  tau2way, &
410  sdev1way, &
411  sdev2way, &
412  errorLevel)
413 !................................................................................
414 !
415 !................................................................................
416 ! !F90
417 !
418 ! !DESCRIPTION:
419 ! given pressure, integrated precipitable water amount, miu0 and miu1, this
420 ! program returns:
421 ! (1) one way transmittance for 3.7 and 11 um bands.
422 ! (2) two way transmittance for 0.67, 0.86, 1.2, 1.6, 2.1 and 3.7 um bands.
423 !
424 !
425 ! !INPUT PARAMETERS:
426 !
427 ! KDIM_1WAY = delcared band-dimension for 1-way tau array; >= 2
428 ! KDIM_2WAY = declared band-dimension for 2-way tau array; >= 6
429 !
430 ! p(XDIM, YDIM) = pressure height in mb.
431 ! tpw(XDIM, YDIM) = precipitable water (g/cm2) from level p to TOA.
432 ! miu0(XDIM, YDIM) = cosine of solar zenith angle.
433 ! miu1(XDIM, YDIM) = cosine of viewing zenith at level p.
434 !
435 !
436 ! !OUTPUT PARAMETERS:
437 !
438 ! tau1way(XDIM, YDIM, 2) = contains 1-way spectral transmittance information.
439 ! tau2way(XDIM, YDIM, 6) = contains 2-way spectral transmittance information.
440 ! sdev1way(XDIM, YDIM, 2) = contains 1-way standard deviations.
441 ! sdev2way(XDIM, YDIM, 6) = contains 2-way standard deviations.
442 !
443 ! *** Note ***: Fill value for tau1way and tau2way is -1.
444 !
445 ! errorLevel = return error status
446 ! 0 : none.
447 ! 1 : second nearest neighbour maybe used (warning).
448 ! 2 : cannot find required files (fatal)
449 !
450 !
451 !
452 !
453 ! !REQUIRED EXTERNAL PROGRAMS:
454 ! netcdf.f90 and ModisAuxType.f90
455 !................................................................................
456 ! !Revision History:
457 !
458 !
459 ! Revision 2.5 2004/06/30 MAG
460 ! fixed confusion between transmittance table and standard deviation table
461 !
462 ! Revision 2.5 2004/05/06 wind
463 ! added standard deviation processing in order to facilitate uncertainty calculations
464 ! Revision 2.0 2002/10/25 wind,mag
465 ! add bilinear smoothing to fields
466 !
467 ! Revision 1.5 2001/05/01 18:50:08 jyli
468 ! read entire transmittance table once to speed up process.
469 !
470 ! Revision 1.4 2001/04/18 21:56:35 jyli
471 ! return both 1-way (for longwave) and 2-way (for shortwave) tau.
472 !
473 ! Revision 1.3 2001/04/06 19:11:57 jyli
474 ! first delivery version which includs MODIS run environment stuff.
475 !
476 ! Revision 1.1 2001/04/06 18:46:11 jyli
477 ! Initial revision
478 !
479 !................................................................................
480 ! !Team-unique Header:
481 ! Cloud Retrieval Group, NASA/GSFC
482 !
483 ! !PROGRAMMER:
484 !
485 ! Mark Gray (L3 Com)
486 ! Climate and Radiation Branch
487 ! NASA Goddard Space Flight Center
488 ! Greenbelt, Maryland 20771, U.S.A.
489 !
490 ! Gala Wind (L3 Com)
491 ! Climate and Radiation Branch
492 ! NASA Goddard Space Flight Center
493 ! Greenbelt, Maryland 20771, U.S.A.
494 !
495 ! Jason Li (Emergent-IT)
496 ! Climate and Radiation Branch
497 ! NASA Goddard Space Flight Center
498 ! Greenbelt, Maryland 20771, U.S.A.
499 !*******************************************************************************
500 ! !END
504 
505 IMPLICIT NONE
506 
507 
508 !... i/o variable delcarations:
509 
510 INTEGER, intent(in) :: KDIM_1WAY, KDIM_2WAY
511 REAL , intent(in) :: p, tpw, miu0, miu1
512 REAL, intent(out),DIMENSION(KDIM_1WAY) :: tau1way, sdev1way
513 REAL, intent(out),DIMENSION(KDIM_2WAY) :: tau2way, sdev2way
514 INTEGER, intent(out) :: errorLevel
515 REAL, intent(in), DIMENSION(:,:,:,:) :: bigTauTable, bigSdevTable
516 
517 
518 INTEGER :: i, pIndex, miu1Index, miu2Index, pwIndex, set_fill
519 INTEGER, DIMENSION(4) :: start, counts, mindex
520 
521 INTEGER :: NumberOfPixels_1km, NumberOfLines_1km
522 
523 REAL :: miu, tauValue
524 real :: tau11, tau12, tau21, tau22, tau_mid1, tau_mid2
525 real :: sdev11, sdev12, sdev21, sdev22, sdev_mid1, sdev_mid2
526 Integer :: first_pwIndex, first_miuindex, second_pwIndex, second_miuindex
527 real, dimension(numberofshortwavelengths) :: temp_trans, temp_sdev
528 !................................................................................
529 
530 
531 ! initialize values
532 temp_trans = -999.
533 temp_sdev = -999.
534 
535 
536 errorlevel = 0
537 
538  miu = (miu0*miu1)/(miu0+miu1)
539 
540 !
541 !... find array indicies along p, pw and miu dimension:
542 !
543  pindex = nint( (p - heightscale(1)) / 100.0 ) + 1
544  set_fill = 0
545  if (p< 0. .and. tpw < 0.) set_fill = 1
546 
547  if(pindex < 1) then
548  pindex = 1
549  errorlevel = 1
550  elseif(pindex > numberofpressureheights) then
551  pindex = numberofpressureheights
552  errorlevel = 1
553  endif
554 
555  miu1index = nint( (miu1 - miuscale(1)) / 0.05 ) + 1
556  if (miu1index < 1) then
557  miu1index = 1
558  errorlevel = 1
559  elseif(miu1index > numberofmiu) then
560  miu1index = numberofmiu
561  errorlevel = 1
562  endif
563 
564  miu2index = nint( (miu - miuscale(1)) / 0.05 ) + 1
565  if (miu2index < 1) then
566  miu2index = 1
567  errorlevel = 1
568  elseif(miu2index > numberofmiu) then
569  miu2index = numberofmiu
570  errorlevel = 1
571  endif
572 
573 
574 ! changed by G. Wind 5.6.04 to match the new bins in transmittance table
575  if(tpw < 0.0) then
576  pwindex = 1
577  errorlevel = 1
578  elseif(tpw < 0.2) then
579  pwindex = nint( (tpw- pwscale(1)) / 0.02 ) + 1
580  else
581  pwindex = nint( (tpw - pwscale(11)) / 0.20 ) + 11
582  if(pwindex > numberofprecipitablewater) then
583  pwindex = numberofprecipitablewater
584  errorlevel = 1
585  endif
586  endif
587 
588  !...
589  !... 1-way case (for longwave 3.7 and 11 micron bands):
590  !...
591 
592  mindex(1) = pindex
593  mindex(2) = pwindex
594  mindex(3) = miu1index
595  mindex(4) = 1
596 
597  tauvalue = bigtautable(mindex(1),mindex(2),mindex(3),mindex(4))
598 
599 ! we need to step back until we find a value that is non-fill, the second neighbor will not be
600 ! enough in many cases
601 
602  if (tauvalue < 0.0) then ! do I need 2nd nearest neighbour?
603 ! errorLevel = 1
604 ! mindex(2) = pwIndex - 1
605 
606  do i=mindex(2), 1, -1
607  tauvalue = bigtautable(mindex(1),i,mindex(3),mindex(4))
608  if (tauvalue >= 0.) exit
609  end do
610 
611 ! now we have a good value of trans, non-fill, so we set the index accordingly
612  mindex(2) = i
613 
614  endif
615 
616 ! grab the 4 points for bilinear interpolation: pw1,u1 pw2,u1 pw1,u2, pw2,u2
617 
618  if (pwscale(mindex(2)) >= tpw ) then
619  second_pwindex = mindex(2)
620  if (mindex(2) == 1) then
621  first_pwindex = mindex(2)
622  else
623  first_pwindex = mindex(2) - 1
624  if (bigtautable(mindex(1), first_pwindex, mindex(3), mindex(4)) < 0.) &
625  first_pwindex = mindex(2)
626  endif
627 
628  else
629  first_pwindex = mindex(2)
630  if (mindex(2) == numberofprecipitablewater) then
631  second_pwindex = mindex(2)
632  else
633  second_pwindex = mindex(2) + 1
634  if (bigtautable(mindex(1),second_pwindex,mindex(3),mindex(4)) < 0.0) &
635  second_pwindex = mindex(2)
636  endif
637  endif
638 
639  if (miuscale(miu1index) >= miu1 ) then
640  first_miuindex = miu1index -1
641  second_miuindex = miu1index
642  else
643  first_miuindex = miu1index
644  second_miuindex = miu1index + 1
645  endif
646 
647  do i = 1, numberoflongwavelengths
648  mindex(4) = bandindexmaplw(i)
649 
650  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
651  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
652 
653  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
654  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
655 
656  sdev11 = bigsdevtable(pindex, first_pwindex, first_miuindex, mindex(4))
657  sdev12 = bigsdevtable(pindex, first_pwindex, second_miuindex, mindex(4))
658 
659  sdev21 = bigsdevtable(pindex, second_pwindex, first_miuindex, mindex(4))
660  sdev22 = bigsdevtable(pindex, second_pwindex, second_miuindex, mindex(4))
661 
662 
663 ! first we interpolate along the PW lines
664  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
665  (/tau11, tau21 /), &
666  tpw)
667  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
668  (/tau12, tau22 /), &
669  tpw)
670 
671  sdev_mid1 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
672  (/sdev11, sdev21/), &
673  tpw)
674  sdev_mid2 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
675  (/sdev12, sdev22/), &
676  tpw)
677 
678 
679 ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
680 ! (bilinear interpolation)
681  tau1way(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
682  (/tau_mid1, tau_mid2/), &
683  miu1)
684  sdev1way(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
685  (/sdev_mid1, sdev_mid2/), &
686  miu1)
687  if (set_fill == 1 )then
688  tau1way(i) = -999.
689  sdev1way(i) = -999.
690  endif
691  enddo
692 
693  !
694  !... 2-way case (for shortwave channels upto 3.7 micron band):
695  !
696 
697  mindex(2) = pwindex
698  mindex(3) = miu2index
699  mindex(4) = 1
700 
701 ! the pw_index values had already been determined and they don't change with changing miu,
702 ! so pray tell why should we recompute them. This code had been deleted. G.Wind 2.2.05
703 
704  if (miuscale(miu2index) >= miu ) then
705  first_miuindex = miu2index -1
706  second_miuindex = miu2index
707  else
708  first_miuindex = miu2index
709  second_miuindex = miu2index + 1
710  endif
711 
712  do i = 1, numberofshortwavelengths
713  mindex(4) = bandindexmapsw(i)
714 
715  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
716  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
717 
718  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
719  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
720 
721  sdev11 = bigsdevtable(pindex, first_pwindex, first_miuindex, mindex(4))
722  sdev12 = bigsdevtable(pindex, first_pwindex, second_miuindex, mindex(4))
723 
724  sdev21 = bigsdevtable(pindex, second_pwindex, first_miuindex, mindex(4))
725  sdev22 = bigsdevtable(pindex, second_pwindex, second_miuindex, mindex(4))
726 
727 ! first we interpolate along the PW lines
728  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
729  (/tau11, tau21 /), &
730  tpw)
731  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
732  (/tau12, tau22 /), &
733  tpw)
734 ! then we repeat for the standard deviations
735  sdev_mid1 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
736  (/sdev11, sdev21/), &
737  tpw)
738  sdev_mid2 =linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex)/), &
739  (/sdev12, sdev22/), &
740  tpw)
741 ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
742 ! nothing but rather standard bilinear interpolation
743 ! and that is our answer.
744  temp_trans(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
745  (/tau_mid1, tau_mid2/), &
746  miu)
747 
748 ! and these are the final standard deviations
749  temp_sdev(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
750  (/sdev_mid1, sdev_mid2/), &
751  miu )
752  if (set_fill == 1 )then
753  temp_trans(i) = -999.
754  temp_sdev(i) = -999.
755  endif
756 
757  end do
758 
759 
760 ! remap the bands, so they can be indexed by the main instrument band index
761  call remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)
762 
763 
764 9999 RETURN
765 
766 END SUBROUTINE gettransmittancedata
767 SUBROUTINE gettransmittance_simple( &
768  BigTauTable, &
769  p, &
770  tpw, &
771  miu0, &
772  miu1, &
773  tau2way, &
774  errorLevel)
775 !................................................................................
776 !
777 !................................................................................
778 ! !F90
779 !
780 ! !DESCRIPTION:
781 ! given pressure, integrated precipitable water amount, miu0 and miu1, this
782 ! program returns:
783 ! (1) one way transmittance for 3.7 and 11 um bands.
784 ! (2) two way transmittance for 0.67, 0.86, 1.2, 1.6, 2.1 and 3.7 um bands.
785 !
786 !
787 ! !INPUT PARAMETERS:
788 !
789 ! KDIM_2WAY(xdim, ydim, n) = declared band-dimension for 2-way tau array; >= n bands
790 !
791 ! p(XDIM, YDIM) = pressure height in mb.
792 ! tpw(XDIM, YDIM) = precipitable water (g/cm2) from level p to TOA.
793 ! miu0(XDIM, YDIM) = cosine of solar zenith angle.
794 ! miu1(XDIM, YDIM) = cosine of viewing zenith at level p.
795 !
796 !
797 ! !OUTPUT PARAMETERS:
798 !
799 ! tau2way(XDIM, YDIM, n) = contains 2-way spectral transmittance information.
800 !
801 ! *** Note ***: Fill value for tau1way and tau2way is -1.
802 !
803 ! errorLevel = return error status
804 ! 0 : none.
805 ! 1 : second nearest neighbour maybe used (warning).
806 ! 2 : cannot find required files (fatal)
807 !
808 !................................................................................
809 ! !Revision History:
810 !................................................................................
811 ! !Team-unique Header:
812 ! Cloud Retrieval Group, NASA/GSFC
813 !
814 ! !PROGRAMMER:
815 !
816 ! Mark Gray (L3 Com)
817 ! Climate and Radiation Branch
818 ! NASA Goddard Space Flight Center
819 ! Greenbelt, Maryland 20771, U.S.A.
820 !
821 ! Gala Wind (L3 Com)
822 ! Climate and Radiation Branch
823 ! NASA Goddard Space Flight Center
824 ! Greenbelt, Maryland 20771, U.S.A.
825 !
826 ! Jason Li (Emergent-IT)
827 ! Climate and Radiation Branch
828 ! NASA Goddard Space Flight Center
829 ! Greenbelt, Maryland 20771, U.S.A.
830 !*******************************************************************************
831 ! !END
832 
836 
837 IMPLICIT NONE
838 
839 
840 
841 !... i/o variable delcarations:
842 
843 REAL , intent(in) :: p, tpw, miu0, miu1
844 REAL, intent(out),DIMENSION(:) :: tau2way
845 INTEGER, intent(out) :: errorLevel
846 REAL, intent(in), DIMENSION(:,:,:,:) :: bigTauTable
847 
848 
849 
850 INTEGER :: i, pIndex, miu1Index, miu2Index, pwIndex, set_fill
851 INTEGER, DIMENSION(4) :: start, counts, mindex
852 
853 INTEGER :: NumberOfPixels_1km, NumberOfLines_1km
854 
855 REAL :: miu, tauValue
856 real :: tau11, tau12, tau21, tau22, tau_mid1, tau_mid2
857 real :: sdev11, sdev12, sdev21, sdev22, sdev_mid1, sdev_mid2
858 Integer :: first_pwIndex, first_miuindex, second_pwIndex, second_miuindex
859 real, dimension(numberofshortwavelengths) :: temp_trans, temp_sdev, sdev2way
860 !................................................................................
861 
862 
863 ! initialize values
864 temp_trans = -999.
865 
866 
867 
868 errorlevel = 0
869 
870  miu = (miu0*miu1)/(miu0+miu1)
871 
872 !
873 !... find array indicies along p, pw and miu dimension:
874 !
875  pindex = nint( (p - heightscale(1)) / 100.0 ) + 1
876  set_fill = 0
877  if (p< 0. .and. tpw < 0.) set_fill = 1
878 
879  if(pindex < 1) then
880  pindex = 1
881  errorlevel = 1
882  elseif(pindex > numberofpressureheights) then
883  pindex = numberofpressureheights
884  errorlevel = 1
885  endif
886 
887  miu1index = nint( (miu1 - miuscale(1)) / 0.05 ) + 1
888  if (miu1index < 1) then
889  miu1index = 1
890  errorlevel = 1
891  elseif(miu1index > numberofmiu) then
892  miu1index = numberofmiu
893  errorlevel = 1
894  endif
895 
896  miu2index = nint( (miu - miuscale(1)) / 0.05 ) + 1
897  if (miu2index < 1) then
898  miu2index = 1
899  errorlevel = 1
900  elseif(miu2index > numberofmiu) then
901  miu2index = numberofmiu
902  errorlevel = 1
903  endif
904 
905 
906 ! changed by G. Wind 5.6.04 to match the new bins in transmittance table\
907  pwindex = 1
908  if(tpw < 0.0) then
909  errorlevel = 1
910  elseif(tpw < 0.2) then
911  pwindex = nint( (tpw- pwscale(1)) / 0.02 ) + 1
912  else
913  pwindex = nint( (tpw - pwscale(11)) / 0.20 ) + 11
914  if(pwindex > numberofprecipitablewater) then
915  pwindex = numberofprecipitablewater
916  errorlevel = 1
917  endif
918  endif
919 
920  !
921  !... 2-way case (for shortwave channels upto 3.7 micron band):
922  !
923 
924  mindex(1) = pindex
925  mindex(2) = pwindex
926  mindex(3) = miu2index
927  mindex(4) = 1
928 
929  if (pwindex < 1) print*, "HERE" , mindex, tpw, p
930 
931  tauvalue = bigtautable(mindex(1),mindex(2),mindex(3),mindex(4))
932 
933 ! we need to step back until we find a value that is non-fill, the second neighbor will not be
934 ! enough in many cases
935 
936  if (tauvalue < 0.0) then ! do I need 2nd nearest neighbour?
937 ! errorLevel = 1
938 ! mindex(2) = pwIndex - 1
939 
940  do i=mindex(2), 1, -1
941  tauvalue = bigtautable(mindex(1),i,mindex(3),mindex(4))
942  if (tauvalue >= 0.) exit
943  end do
944 
945 ! now we have a good value of trans, non-fill, so we set the index accordingly
946  mindex(2) = i
947 
948  endif
949 
950 
951 ! grab the 4 points for bilinear interpolation: pw1,u1 pw2,u1 pw1,u2, pw2,u2
952  if (pwscale(mindex(2)) >= tpw ) then
953  second_pwindex = mindex(2)
954  if (mindex(2) == 1) then
955  first_pwindex = mindex(2)
956  else
957  first_pwindex = mindex(2) - 1
958  if (bigtautable(mindex(1), first_pwindex, mindex(3), mindex(4)) < 0.) &
959  first_pwindex = mindex(2)
960  endif
961 
962  else
963  first_pwindex = mindex(2)
964  if (mindex(2) == numberofprecipitablewater) then
965  second_pwindex = mindex(2)
966  else
967  second_pwindex = mindex(2) + 1
968  if (bigtautable(mindex(1),second_pwindex,mindex(3),mindex(4)) < 0.0) &
969  second_pwindex = mindex(2)
970  endif
971  endif
972 
973 
974  if (miuscale(miu2index) >= miu ) then
975  first_miuindex = miu2index -1
976  second_miuindex = miu2index
977  else
978  first_miuindex = miu2index
979  second_miuindex = miu2index + 1
980  endif
981 
982  do i = 1, numberofshortwavelengths
983  mindex(4) = bandindexmapsw(i)
984 
985  tau11 = bigtautable(pindex, first_pwindex, first_miuindex, mindex(4))
986  tau12 = bigtautable(pindex, first_pwindex, second_miuindex, mindex(4))
987 
988  tau21 = bigtautable(pindex, second_pwindex, first_miuindex, mindex(4))
989  tau22 = bigtautable(pindex, second_pwindex, second_miuindex, mindex(4))
990 
991 ! first we interpolate along the PW lines
992  tau_mid1 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
993  (/tau11, tau21 /), &
994  tpw)
995  tau_mid2 = linearinterpolation( (/pwscale(first_pwindex), pwscale(second_pwindex) /), &
996  (/tau12, tau22 /), &
997  tpw)
998 
999 ! now we interpolate along the MIU line through tau_mid1 and tau_mid2
1000 ! nothing but rather standard bilinear interpolation
1001 ! and that is our answer.
1002  temp_trans(i) = linearinterpolation( (/miuscale(first_miuindex), miuscale(second_miuindex)/), &
1003  (/tau_mid1, tau_mid2/), &
1004  miu)
1005 
1006  if (set_fill == 1 )then
1007  temp_trans(i) = -999.
1008  endif
1009 
1010  end do
1011 
1012 
1013 ! remap the bands, so they can be indexed by the main instrument band index
1014  temp_sdev(1) = -10000. ! we don't do standard deviation in this subroutine
1015  call remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)
1016 
1017 
1018 9999 RETURN
1019 
1020 END SUBROUTINE gettransmittance_simple
1021 
1022 
1023 
1024 
Definition: ch_xfr.f90:1
real, dimension(nchan, model_levels), public rtm_trans_atm_clr
Definition: rtm_support.f90:47
integer, parameter band_0124
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
logical, dimension(8) have_band
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_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
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
integer, parameter numberofshortwavelengths
real(single), dimension(:,:), allocatable abovecloud_watervapor
integer, dimension(numberofshortwavelengths) bandindexmapsw
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:41
subroutine gettransmittance_simple(BigTauTable, p, tpw, miu0, miu1, tau2way, errorLevel)
subroutine remap_bands(tau2way, temp_trans, sdev2way, temp_sdev)