NASA Logo
Ocean Color Science Software

ocssw V2022
get_retrieval_uncertainty.f90
Go to the documentation of this file.
2 
3  implicit none
4  private
5 
6  logical :: print_info
7 
8  real :: new_water_radii(25), new_ice_radii(25)
9 
11 
12  contains
13 
14 subroutine init_half_radii
15 
16  use libraryarrays
17 
18 
19  integer :: i, n
20 
22  new_water_radii(1) = water_radii(1)
23  do i=2, n
24  new_water_radii(i) = water_radii(i) - (water_radii(i) - water_radii(i-1)) / 2.0
25  end do
26  new_water_radii(n+1) = water_radii(n)
27 
28  n = number_iceradii
29  new_ice_radii(1) = ice_radii(1)
30  do i=2, n
31  new_ice_radii(i) = ice_radii(i) - (ice_radii(i)-ice_radii(i-1)) / 2.0
32  end do
33  new_ice_radii(n+1) = ice_radii(n)
34 
35 
36 end subroutine init_half_radii
37 
38 
39 
40 
41 subroutine getuncertainties (thickness, &
42  re, &
43  water_path, &
44  phase, &
45  R1R2wavelengthIdx, &
46  meas_error, &
47  surface_albedo, &
48  transmittance_w1, &
49  transmittance_w2, &
50  delta_transmittance_w1, &
51  delta_transmittance_w2, &
52  transmittance_stddev_w1, &
53  transmittance_stddev_w2, &
54  emission_pw, &
55  emission_Tc, &
56  sigma_R37_pw, &
57  uTau,uRe,uWaterPath, xpoint, ypoint)
58 !-----------------------------------------------------------------------
59 ! !f90
60 !
61 ! !Description:
62 ! This subroutine computes the final uncertainties in thickness, re and water vapor
63 !
64 ! !Input Parameters:
65 ! NONE
66 !
67 ! !Output Parameters:
68 ! NONE
69 !
70 ! !Revision History:
71 ! 2004/06/01 bwind: Brad Wind
72 ! Revision 1.0 Initial Revision
73 !
74 ! !Team-Unique Header:
75 ! Developed by the Cloud Retrieval Group, NASA GSFC, Greenbelt, Maryland, USA.
76 !
77 ! !References and Credits:
78 ! Written by:
79 ! Bradley P. Wind
80 ! L3 GSI
81 ! Code 913, NASA/GSFC
82 ! Greenbelt, MD 20771
83 ! bwind@climate.gsfc.nasa.gov
84 !
85 ! Mark Gray
86 ! L3-GSI
87 ! Climate and Radiation Branch, Code 913
88 ! NASA/GSFC
89 ! Greenbelt MD 20771
90 ! gray@climate.gsfc.nasa.gov
91 !
92 ! !Design Notes:
93 ! NONE
94 !
95 ! !END
96 !
97 !-----------------------------------------------------------------------
98 
99 !
100 ! S. Platnick, 2-23-05:
101 !
102 ! Wrote variance calculations in terms of matrix formulation
103 ! Added covariance(tau,re) to water path uncertainty
104 !
105 
106  use generalauxtype
109  use ch_xfr, only: c2_sensor_id, oci_id, ocis_id
110 #if NOSWIR
113 #else
115 #endif
117 
118  implicit none
119 
120  integer, intent(in) :: xpoint, ypoint
121  real, intent(in) :: thickness, re, water_path, &
122  surface_albedo(2), &
123  transmittance_w1,transmittance_w2, &
124  delta_transmittance_w1,delta_transmittance_w2, &
125  transmittance_stddev_w1, transmittance_stddev_w2, meas_error(2), &
126  emission_pw(:), emission_tc(:), sigma_r37_pw(:)
127 
128 
129  integer, intent(in) :: r1r2wavelengthidx(2)
130  character(10), intent(in) :: phase
131  real, intent(out) :: utau, ure,uwaterpath
132 
133  real :: meancloudtopreflw1, meancloudtopreflw2
134  real :: partialderivtauwrtr1atconstr2, partialderivtauwrtr2atconstr1
135  real :: partialderivrewrtr2atconstr1 , partialderivrewrtr1atconstr2
136  real :: meandeltar1trans, meandeltar2trans
137  real :: deltarcloudtopmean(2), density, sdev_refl(2)
138 
139  real :: correlation_trans, correlation_wp
140  real :: emis_pw_val, emis_tc_val, sigma_r37_val
141 
142 ! declare matrices
143  real, dimension(2,2) :: s, s_transpose, retrieval_covariance, dummy, &
144  refl_cov_total, refl_cov_sfc_albedo, &
145  refl_cov_trans, refl_cov_trans_pw, refl_cov_trans_table, &
146  refl_cov_calibration, refl_cov_cm_sdev, refl_cov_ws, &
147  refl_cov_emission_pw, refl_cov_emission_tc, refl_cov_trans_o3
148 
149  integer :: band37_index
150 
151 #ifdef AIRBORNE
152  band37_index = band_0370 + 3
153 #else
154 
155 #ifdef AHI_INST
156  band37_index = band_0370
157 #else
158  band37_index = band_0370 - 1
159 #endif
160 
161 #endif
162 
163 
164  print_info = .false.
165 
166 ! -----------------------------------------------------------------------
167 ! Calculate change in cloud top reflectance due to sfc albedo uncertainty
168 ! -----------------------------------------------------------------------
169  sdev_refl = 0.
170 
171  if (cox_munk) then
172 
173 
174  call getctrefl_windspeeddiff(re, thickness, phase, &
175  r1r2wavelengthidx, &
176  deltarcloudtopmean, meancloudtopreflw1, meancloudtopreflw2)
177  else
178 
179  call getctref_albedodiff(re, thickness, phase, &
180  r1r2wavelengthidx, &
181  surface_albedo, &
182  deltarcloudtopmean, meancloudtopreflw1, meancloudtopreflw2)
183 
184  endif
185 
186  call get_refl_windvector(re, thickness, phase, r1r2wavelengthidx, sdev_refl)
187 
188 ! -----------------------------------------------------------------------
189 ! Calculate sensitivity derivatives and generate the sensitivity matrix S
190 ! -----------------------------------------------------------------------
191 
192 
193  call sensitivitypartialderivatives( r1r2wavelengthidx, &
194  re, thickness, phase, &
195  surface_albedo, &
196  partialderivtauwrtr1atconstr2, &
197  partialderivtauwrtr2atconstr1, &
198  partialderivrewrtr1atconstr2, &
199  partialderivrewrtr2atconstr1 )
200 
201 
202  s(1,1) = partialderivtauwrtr1atconstr2
203  s(1,2) = partialderivtauwrtr2atconstr1
204  s(2,1) = partialderivrewrtr1atconstr2
205  s(2,2) = partialderivrewrtr2atconstr1
206 
207  s_transpose = transpose(s)
208 
209 
210 ! ----------------------------------------------------------------------
211 ! Calculate the uncertainties attributable to each source of uncertainty
212 ! ----------------------------------------------------------------------
213 
214 ! (1) Reflectance covariance matrix due to Surface albedo uncertainty
215 
216  refl_cov_cm_sdev(1,1) = sdev_refl(1)**2
217 #if NOSWIR
218  refl_cov_cm_sdev(2,2) = 0.0
219 #else
220  refl_cov_cm_sdev(2,2) = sdev_refl(2)**2
221 #endif
222  refl_cov_cm_sdev(1,2) = 0.
223  refl_cov_cm_sdev(2,1) = refl_cov_cm_sdev(1,2)
224 
225  if (cox_munk) then
226 ! wind speed uncertainty
227  refl_cov_ws(1,1) = deltarcloudtopmean(1)**2
228 #if NOSWIR
229  refl_cov_ws(2,2) = 0.0
230 
231 #else
232  refl_cov_ws(2,2) = deltarcloudtopmean(2)**2
233 #endif
234  refl_cov_ws(1,2) = 0.
235  refl_cov_ws(2,1) = refl_cov_ws(1,2)
236 ! wind vector uncertainty
237 
238  refl_cov_sfc_albedo = refl_cov_ws + refl_cov_cm_sdev
239 
240  else
241  refl_cov_sfc_albedo(1,1) = deltarcloudtopmean(1)**2
242 #if NOSWIR
243  refl_cov_sfc_albedo(2,2) = 0.0
244 #else
245  refl_cov_sfc_albedo(2,2) = deltarcloudtopmean(2)**2
246 #endif
247  refl_cov_sfc_albedo(1,2) = 0.
248  refl_cov_sfc_albedo(2,1) = refl_cov_sfc_albedo(1,2)
249 
250  refl_cov_sfc_albedo = refl_cov_sfc_albedo + refl_cov_cm_sdev
251  endif
252 
253 ! (2) Reflectance covariance matrix due to atmospheric transmittance uncertainty
254 
255 ! 2a. Calculate covariance matrix due to percipitable water (PW) first:
256 
257 ! deltaR due to PW uncertainty only:
258  meandeltar1trans = meancloudtopreflw1 * abs(delta_transmittance_w1)/transmittance_w1
259 #if NOSWIR
260  meandeltar2trans = 0.0
261 #else
262  meandeltar2trans = meancloudtopreflw2 * abs(delta_transmittance_w2)/transmittance_w2
263 #endif
264 
265  correlation_trans = 1.0
266  refl_cov_trans_pw(1,1) = meandeltar1trans**2
267  refl_cov_trans_pw(2,2) = meandeltar2trans**2
268 
269  if( ( c2_sensor_id /= oci_id ) .AND. ( c2_sensor_id /= ocis_id ) )then
270  if (r1r2wavelengthidx(2) == band37_index) then
271 
272  ! the sigma_r37_val is already squared.
273 
274  call get_emission_values(re, sigma_r37_pw, phase, sigma_r37_val)
275  refl_cov_trans_pw(1,2) = abs(meandeltar1trans * sqrt(sigma_r37_val + &
276  refl_cov_trans_pw(2,2) ))*correlation_trans
277  refl_cov_trans_pw(2,1) = refl_cov_trans_pw(1,2)
278 
279  refl_cov_trans_pw(2,2) = refl_cov_trans_pw(2,2) + sigma_r37_val
280  else
281  refl_cov_trans_pw(1,2) = abs(meandeltar1trans*meandeltar2trans)* &
282  correlation_trans
283  refl_cov_trans_pw(2,1) = refl_cov_trans_pw(1,2)
284 
285  endif
286  endif
287 
288 
289 ! 2b. Calculate covariance matrix due to table uncertainty next:
290 
291 ! deltaR due to table uncertainty only:
292  meandeltar1trans = meancloudtopreflw1 * transmittance_stddev_w1/transmittance_w1
293 #if NOSWIR
294  meandeltar2trans = 0.0
295 #else
296  meandeltar2trans = meancloudtopreflw2 * transmittance_stddev_w2/transmittance_w2
297 #endif
298 
299  refl_cov_trans_table(1,1) = meandeltar1trans**2
300 #if NOSWIR
301  refl_cov_trans_table(2,2) = 0.0
302 #else
303  refl_cov_trans_table(2,2) = meandeltar2trans**2
304 #endif
305  refl_cov_trans_table(1,2) = 0.
306  refl_cov_trans_table(2,1) = refl_cov_trans_table(1,2)
307 
308 ! 2c. uncertainty due to ozone
309 
310  refl_cov_trans_o3 = 0.
311  if (r1r2wavelengthidx(1) == band_0065 .and. mean_delta_ozone /= fillvalue_real &
312  .and. ozone_transmittance /= fillvalue_real ) then
313  refl_cov_trans_o3(1,1) = (meancloudtopreflw1 * abs(mean_delta_ozone)/ozone_transmittance)**2
314  endif
315 
316 
317 ! 2d. Combined covariance matrix:
318 
319  refl_cov_trans = refl_cov_trans_pw + refl_cov_trans_table + refl_cov_trans_o3
320 
321 ! (3) Reflectance covariance matrix due to calibration uncertainty
322 
323  refl_cov_calibration(1,1) = (meas_error(1) * meancloudtopreflw1)**2
324 #if NOSWIR
325  refl_cov_calibration(2,2) = 0.0
326 #else
327  refl_cov_calibration(2,2) = (meas_error(2) * meancloudtopreflw2)**2
328 #endif
329 ! delta F0 = 0.42 taken from difference between Fontenla and Thekaekara (band averaged Aqua and Terra)
330 
331  if( ( c2_sensor_id /= oci_id ) .and. ( c2_sensor_id /= ocis_id ) )then
332  if (r1r2wavelengthidx(2) == band37_index) then
333  refl_cov_calibration(2,2) = refl_cov_calibration(2,2) + &
334  (( 0.42 * meancloudtopreflw2 ) / solar_constant_37)**2
335  endif
336  endif
337 
338  refl_cov_calibration(1,2) = 0.
339  refl_cov_calibration(2,1) = refl_cov_calibration(1,2)
340 
341 ! Total tau & re covariance matrix
342 
343  refl_cov_total = refl_cov_sfc_albedo + refl_cov_trans + refl_cov_calibration
344 
345 ! ------------------------------------------------------------------------------
346 ! Calculate retrieval covariance matrix = S * retrieval_covariance * S_transpose
347 ! ------------------------------------------------------------------------------
348 
349  dummy = matmul(refl_cov_total, s_transpose)
350  retrieval_covariance = matmul(s, dummy)
351 #if NOSWIR
352  ! Use the standard deviation of all possible CER values (calculated from the LUT CER grid),
353  ! uniformly distributed (i.e., each is equally possible). It is important to have a somewhat
354  ! reasonable CER uncertainty for calculating the water path uncertainty.
355  if ( ( phase == 'water') .and. ( c2_sensor_id /= oci_id ) .and &
356  ( c2_sensor_id /= ocis_id ) ) then
357  retrieval_covariance(1,1) = retrieval_covariance(1,1) + &
358  (optical_thickness_37_final(xpoint,ypoint))**2 ! Add uncertainty due to unknown CER
359  retrieval_covariance(2,2) = 64.0 ! stddev ~8.0, assuming 14µm CER
360  else
361  retrieval_covariance(1,1) = retrieval_covariance(1,1) + &
362  (optical_thickness_1621_final(xpoint,ypoint))**2 ! Add uncertainty due to unknown CER
363  retrieval_covariance(2,2) = 289.0 ! stddev ~17.0, assuming 30µm CER
364  end if
365 #endif
366 
367 
368 ! ---------------------
369 ! Tau, re uncertainties
370 ! ---------------------
371 
372  utau = sqrt( retrieval_covariance(1,1) )
373  ure = sqrt( retrieval_covariance(2,2) )
374 
375 
376 ! ----------------------
377 ! Water path uncertainty
378 ! ----------------------
379 
380 
381  if ((100.*utau/thickness) >= 200. .OR. (100.*ure/re) >= 200. ) then
382  uwaterpath = 200.
383 
384 
385  else
386 
387  if (phase == 'water') then
388  density = liquid_water_density
389  else
390  density = ice_water_density
391  endif
392 
393  uwaterpath = (re**2)*(utau**2) + (thickness**2)*(ure**2) + (utau**2)*(ure**2) + &
394  2*retrieval_covariance(1,2)*utau*ure + retrieval_covariance(1,2)**2
395  if (uwaterpath < 0.) then
396  uwaterpath = 200.
397  else
398  uwaterpath= sqrt( density**2 * uwaterpath )
399  end if
400  endif
401 
402 
403 ! ----------------------
404 ! Relative uncertainties
405 ! ----------------------
406 
407  utau = 100.*utau/thickness
408  ure = 100.*ure/re
409  uwaterpath = 100.*uwaterpath/water_path
410 
411 ! ------------------------------------------------------
412 ! Limit answer to a maximum of 200% relative uncertainty
413 ! ------------------------------------------------------
414 
415 ! sep: Was told by mag that max value should be 200 (or 255)
416 ! because of the scaling value used in the filespec
417 
418  if (utau > 200. ) utau = 200.
419  if (ure > 200. ) ure = 200.
420  if (uwaterpath > 200.) uwaterpath = 200.
421 
422 
423 
424 end subroutine getuncertainties
425 
426 subroutine get_emission_values(re, sigma37, phase, sigma37_val)
427 
430 
431  implicit none
432 
433  character*(*), intent(in) :: phase
434  real, intent(in) :: sigma37(:), re
435  real, intent(inout) :: sigma37_val
436 
437  integer :: i, n, ilow, ihigh
438 
439  ilow = 0 ! WDR-UIV
440  ihigh = 0 ! WDR-UIV
441 
442  ilow = 0 ! WDR-UIV
443  ihigh = 0 ! WDR-UIV
444 
445  if (phase == 'water') then
446  call bisectionsearch(water_radii, re, ilow, ihigh)
447  sigma37_val = linearinterpolation( (/water_radii(ilow), water_radii(ihigh) /), &
448  (/ sigma37(ilow), sigma37(ihigh) /), re)
449  else
450  call bisectionsearch(ice_radii, re, ilow, ihigh)
451  sigma37_val = linearinterpolation( (/ice_radii(ilow), ice_radii(ihigh) /), &
452  (/ sigma37(ilow), sigma37(ihigh) /), re)
453  endif
454 
455 
456 end subroutine get_emission_values
457 
458 
459 
460 subroutine getctrefl_windspeeddiff(&
461  radius, &
462  optical_thickness, &
463  phase, &
464  wave_index, &
465  reflectancediff, meancloudtopreflw1, meancloudtopreflw2)
466 
467 
468  use generalauxtype
470  use libraryarrays
474  implicit none
475 
476  real, intent(in) :: radius
477  integer, intent(in) :: wave_index(2)
478  real, intent(in) :: optical_thickness
479  character(10),intent(in) :: phase
480  real, intent(out) :: reflectancediff(2), meancloudtopreflw1, meancloudtopreflw2
481 
482  integer :: radii_size , radius_upperbound, radius_lowerbound, radius_index, i,j, vectorsize
483  real :: reflectance_lower(2), reflectance_middle(2), reflectance_upper(2)
484  real, dimension(:), allocatable :: opticalthick_vector !(6)
485 
486  real, dimension(:,:,:), allocatable :: temp_refl
487  integer :: status
488 
489  integer :: dummy
490 
491  integer :: TOTAL_POINTS
492 
493  integer :: start_time, end_time, cmax, crate
494 
495 
496 
497  total_points = size(library_taus) + 1
498 
499 
500  allocate(opticalthick_vector(total_points))
501 
502 
503  reflectance_upper = 0.
504  reflectance_lower = 0.
505  reflectance_middle = 0.
506 
507 
508  if (phase == 'water') then
510  water_radii,radius, &
511  i)
512 
513  else
515  ice_radii,radius, &
516  i)
517  endif
518 
519 
520  opticalthick_vector(1) = 0.
521  opticalthick_vector(2:total_points) = library_taus(1:(total_points-1))
522 
523 
524  if (phase == 'water') then
525 
526 
527  do j =1, 2
528  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
529  optical_thickness, &
530  int_reflectance_water(:,wave_index(j),i), &
531  reflectance_middle(j))
532  end do
533 
534 
535  allocate(temp_refl(total_points, number_wavelengths, number_waterradii))
536 
539  temp_refl(:,:,:) )
540 
541 
542 
543 
544  do j =1, 2
545  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
546  optical_thickness, &
547  temp_refl(:,wave_index(j),i), &
548  reflectance_upper(j))
549  end do
550 
553  temp_refl(:,:,:) )
554 
555 
556  do j =1, 2
557  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
558  optical_thickness, &
559  temp_refl(:,wave_index(j),i), &
560  reflectance_lower(j))
561  end do
562 
563 
564  deallocate(temp_refl)
565 
566  do j=1, 2
567 
568  reflectancediff(j) = (abs(reflectance_lower(j) - reflectance_middle(j)) + &
569  abs(reflectance_upper(j) - reflectance_middle(j)))/2.
570  if(j .eq. 1) then
571  meancloudtopreflw1 = reflectance_middle(j)
572  else
573  meancloudtopreflw2 = reflectance_middle(j)
574  endif
575 
576 
577  end do
578 
579  else
580 
581  do j =1, 2
582  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
583  optical_thickness, &
584  int_reflectance_ice(:,wave_index(j),i), &
585  reflectance_middle(j))
586  end do
587 
588 
589  allocate(temp_refl(total_points, number_wavelengths, number_iceradii))
590 
593  temp_refl(:,:,:) )
594 
595 
596  do j =1, 2
597  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
598  optical_thickness, &
599  temp_refl(:,wave_index(j),i), &
600  reflectance_upper(j))
601  end do
602 
605  temp_refl(:,:,:) )
606 
607 
608  do j =1, 2
609  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
610  optical_thickness, &
611  temp_refl(:,wave_index(j),i), &
612  reflectance_lower(j))
613  end do
614 
615 
616  deallocate(temp_refl)
617 
618  do j=1, 2
619 
620  reflectancediff(j) = (abs(reflectance_lower(j) - reflectance_middle(j)) + &
621  abs(reflectance_upper(j) - reflectance_middle(j)))/2.
622  if(j .eq. 1) then
623  meancloudtopreflw1 = reflectance_middle(j)
624  else
625  meancloudtopreflw2 = reflectance_middle(j)
626  endif
627 
628 
629  end do
630 
631 
632  endif
633 
634 
635  deallocate(opticalthick_vector)
636 
637 
638 
639 end subroutine getctrefl_windspeeddiff
640 
641 subroutine get_refl_windvector(radius, optical_thickness, phase, wave_index, sdev_refl)
642 
643 
644  use generalauxtype
646  use libraryarrays
649  implicit none
650 
651  real, intent(in) :: radius
652  integer, intent(in) :: wave_index(2)
653  real, intent(in) :: optical_thickness
654  character(10),intent(in) :: phase
655  real, intent(out) :: sdev_refl(2)
656 
657  integer :: radii_size , radius_upperbound, radius_lowerbound, radius_index, i,j, vectorsize
658  real, dimension(:), allocatable :: opticalthick_vector !(6)
659 
660  integer :: status
661 
662  integer :: dummy
663 
664  integer :: TOTAL_POINTS
665 
666  total_points = size(library_taus) + 1
667 
668  allocate(opticalthick_vector(total_points))
669 
670 
671 
672  if (phase == 'water') then
674  water_radii,radius, &
675  i)
676 
677  else
679  ice_radii,radius, &
680  i)
681  endif
682 
683 
684  opticalthick_vector(1) = 0.
685  opticalthick_vector(2:total_points) = library_taus(1:(total_points-1))
686 
687 
688  if (phase == 'water') then
689 
690  do j =1, 2
691  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
692  optical_thickness, &
693  int_reflectance_water_sdev(:,wave_index(j),i), &
694  sdev_refl(j))
695  end do
696 
697  else
698 
699  do j =1, 2
700  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
701  optical_thickness, &
702  int_reflectance_ice_sdev(:,wave_index(j),i), &
703  sdev_refl(j))
704  end do
705 
706  endif
707 
708 
709  deallocate(opticalthick_vector)
710 
711 end subroutine get_refl_windvector
712 
713 
714 
715 subroutine getctref_albedodiff(&
716  radius, &
717  optical_thickness, &
718  phase, &
719  wave_index, &
720  surface_albedo, &
721  reflectancediff, meancloudtopreflw1, meancloudtopreflw2)
724  use libraryarrays
727  implicit none
728 
729  real, intent(in) :: radius
730  integer, intent(in) :: wave_index(2)
731  real, intent(in) :: optical_thickness, surface_albedo(2)
732  character(10),intent(in) :: phase
733  real, intent(out) :: reflectancediff(2), meancloudtopreflw1, meancloudtopreflw2
734 
735  integer :: radii_size , radius_upperbound, radius_lowerbound, radius_index, i,j, vectorsize
736  real :: reflectance_lower, reflectance_middle, reflectance_upper
737  real, dimension(:), allocatable :: opticalthick_vector !(6)
738  integer :: dummy
739 
740  integer :: TOTAL_POINTS
741 
742  total_points = size(library_taus) + 1
743 
744 
745  allocate(opticalthick_vector(total_points))
746 
747 
748  reflectance_upper = 0.
749  reflectance_lower = 0.
750  reflectance_middle = 0.
751 
752 
753  if (phase == 'water') then
755  water_radii,radius, &
756  i)
757 
758  else
760  ice_radii,radius, &
761  i)
762 
763  endif
764 
765 
766  opticalthick_vector(1) = 0.
767  opticalthick_vector(2:total_points) = library_taus(1:(total_points-1))
768 
769  if (phase == 'water') then
770  do j = 1,2
771 
772 
773  call nonasymptotic_albedovar(opticalthick_vector, &
774  optical_thickness, &
775  spherical_albedo_water(:,wave_index(j),i),&
776  int_reflectance_water(:,wave_index(j),i), &
777  int_fluxdownwater_sensor(:,wave_index(j),i), &
778  int_fluxdownwater_solar(:,wave_index(j),i), &
779  surface_albedo(j), &
780  reflectance_lower, &
781  reflectance_middle, &
782  reflectance_upper)
783 
784 
785  reflectancediff(j) = (abs(reflectance_lower - reflectance_middle) + &
786  abs(reflectance_upper - reflectance_middle))/2.
787  if(j .eq. 1) then
788  meancloudtopreflw1 = reflectance_middle
789  else
790  meancloudtopreflw2 = reflectance_middle
791  endif
792  enddo
793  else
794  do j = 1,2
795 
796  call nonasymptotic_albedovar(opticalthick_vector, &
797  optical_thickness, &
798  spherical_albedo_ice(:,wave_index(j),i),&
799  int_reflectance_ice(:,wave_index(j),i), &
800  int_fluxdownice_sensor(:,wave_index(j),i), &
801  int_fluxdownice_solar(:,wave_index(j),i), &
802  surface_albedo(j), &
803  reflectance_lower, &
804  reflectance_middle, &
805  reflectance_upper)
806 
807  reflectancediff(j) = (abs(reflectance_lower - reflectance_middle) + &
808  abs(reflectance_upper - reflectance_middle))/2.
809  if(j .eq. 1) then
810  meancloudtopreflw1 = reflectance_middle
811  else
812  meancloudtopreflw2 = reflectance_middle
813  endif
814  enddo
815  endif
816 
817 
818  deallocate(opticalthick_vector)
819 
820 end subroutine getctref_albedodiff
821 
822 
823 subroutine getclosestradius(numberradii, radiidata, radius, index)
824 
825  integer, intent(in):: numberradii
826  real, intent(in) :: radiidata(numberradii), radius
827  integer, intent(out):: index
828  integer :: index1(1)
829 
830  index1 = minloc(abs(radiidata-radius))
831  index=index1(1)
832 
833 end subroutine getclosestradius
834 
835 
836 
837 subroutine nonasymptotic_calcu_cox_munk(tau_vector,tc, rf, rf_calculated)
838  use generalauxtype
841 
842  implicit none
843 
844  real, intent(in) :: tau_vector(:),tc
845  real, intent(in) :: rf(:)
846  real, intent(out) :: rf_calculated
847 
848 
849  integer :: lowbound, highbound, taubounds(2)
850  real :: iftau(2), refvals(2)
851 
852  lowbound = 0 ! WDR-UIV
853  highbound = 0 ! WDR-UIV
854 
855  call bisectionsearch(tau_vector, tc, lowbound, highbound)
856  taubounds(1) = lowbound
857  taubounds(2) = highbound
858  iftau(1) = tau_vector(taubounds(1))
859  iftau(2) = tau_vector(taubounds(2))
860 
861  refvals(1) = rf(lowbound)
862  refvals(2) = rf(highbound)
863 
864  rf_calculated = linearinterpolation(iftau,refvals,tc)
865 
866 end subroutine nonasymptotic_calcu_cox_munk
867 
868 
869 
870 subroutine nonasymptotic_calcu(tau_vector,tc, &
871  sfr, rf, ft1,ft0, &
872  albedo,rf_calculated)
877 
878  implicit none
879 
880  real, intent(in) :: tau_vector(:),tc,albedo
881  real, intent(in) :: rf(:), ft0(:), ft1(:), sfr(:)
882  real, intent(out) :: rf_calculated
883 
884  real, dimension(:), allocatable :: reflectance_vector
885 
886  integer :: lowbound, highbound, taubounds(2)
887  real :: iftau(2), refvals(2)
888 
889  integer :: TOTAL_POINTS
890 
891  lowbound = 0 ! WDR-UIV
892  highbound = 0 ! WDR-UIV
893 
894  total_points = size(tau_vector)
895 
896  allocate(reflectance_vector(total_points))
897 
898  reflectance_vector(1) = albedo
899 
900  reflectance_vector(2:total_points) = rf(1:(total_points-1)) + &
901  ft1(1:(total_points-1)) * ft0(1:(total_points-1)) * albedo /( 1. - albedo*sfr(1:(total_points-1)))
902 
903 
904  call bisectionsearch(tau_vector, tc, lowbound, highbound)
905  taubounds(1) = lowbound
906  taubounds(2) = highbound
907  iftau(1) = tau_vector(taubounds(1))
908  iftau(2) = tau_vector(taubounds(2))
909 
910  refvals(1) = reflectance_vector(lowbound)
911  refvals(2) = reflectance_vector(highbound)
912 
913  rf_calculated = linearinterpolation(iftau,refvals,tc)
914 
915  deallocate(reflectance_vector)
916 
917 end subroutine nonasymptotic_calcu
918 
919 subroutine nonasymptotic_albedovar(tau_vector,tc, &
920  sfr, rf, ft1,ft0, &
921  albedo,rf_lower, rf_middle, rf_upper)
924  implicit none
925 
926  real, intent(in) :: tau_vector(:),tc,albedo
927  real, intent(in) :: rf(:), ft0(:), ft1(:), sfr(:)
928  real, intent(out) :: rf_middle, rf_lower, rf_upper
929  real :: albedoUpper
930 
931 
932  call nonasymptotic_calcu(tau_vector,tc, &
933  sfr, rf, ft1,ft0, &
934  albedo,rf_middle)
935 
936  call nonasymptotic_calcu(tau_vector,tc, &
937  sfr, rf, ft1,ft0, &
938  (albedo * (1.0 - albedo_error)),rf_lower)
939 
940  albedoupper = albedo * (1.0 + albedo_error)
941  if(albedoupper .gt. 0.99) albedoupper = 0.99
942  call nonasymptotic_calcu(tau_vector,tc, &
943  sfr, rf, ft1,ft0, &
944  albedoupper,rf_upper)
945 
946 end subroutine nonasymptotic_albedovar
947 
948 
949  subroutine sensitivitypartialderivatives( &
950  R1R2wavelengthIdx,&
951  re, tau, &
952  phase, surface_albedo, &
953  partialDerivTauWrtR1AtConstR2,&
954  partialDerivTauWrtR2AtConstR1,&
955  partialDerivReWrtR1AtConstR2, &
956  partialDerivReWrtR2AtConstR1)
957 !-----------------------------------------------------------------------
958 ! !f90
959 !
960 ! !Description:
961 ! This subroutine computes the partial derivatives of tau and re with
962 ! respect to reflectance in one band as the other one is held constant
963 !
964 !
965 ! !Input Parameters:
966 !
967 ! !Output Parameters:
968 ! NONE
969 !
970 ! !Revision History:
971 ! 2004/05/28 bwind: Brad Wind
972 ! Revision 1.0 Initial Revision
973 !
974 ! !Team-Unique Header:
975 ! Developed by the Cloud Retrieval Group, NASA GSFC, Greenbelt, Maryland, USA.
976 !
977 ! !References and Credits:
978 ! Written by:
979 ! Bradley P. Wind
980 ! L3 GSI
981 ! Code 913, NASA/GSFC
982 ! Greenbelt, MD 20771
983 ! bwind@climate.gsfc.nasa.gov
984 !
985 ! Mark Gray
986 ! L3-GSI
987 ! Climate and Radiation Branch, Code 913
988 ! NASA/GSFC
989 ! Greenbelt MD 20771
990 ! gray@climate.gsfc.nasa.gov
991 !
992 ! !Design Notes:
993 ! NONE
994 !
995 ! !END
996 !
997 !-----------------------------------------------------------------------
998  use generalauxtype
1000  use libraryarrays
1001  implicit none
1002 
1003  integer, intent(in) :: R1R2wavelengthIdx(2)
1004  real, intent(in) :: re, tau
1005  real, intent(in) :: surface_albedo(2)
1006  character(10), intent(in):: phase
1007  real, intent(out) :: partialDerivTauWrtR1AtConstR2, &
1008  partialDerivTauWrtR2AtConstR1, &
1009  partialDerivReWrtR1AtConstR2, &
1010  partialDerivReWrtR2AtConstR1
1011 
1012  real :: partialDerivR1wrtTauAtConstRe, &
1013  partialDerivR2wrtTauAtConstRe, &
1014  partialDerivR1wrtReAtConstTau, &
1015  partialDerivR2wrtReAtConstTau
1016 
1017  integer :: i
1018  integer :: wrtParam
1019 
1020  real :: partialDerivativesTau, partialDerivativesRe
1021  real :: upperLimit, lowerLimit,abscissaintervalstartingpoint
1022  real :: halfAbscissaInterval
1023  real, parameter :: halfAbscissaIntervalTau = 1., halfabscissaintervalre = 1.
1024  real, parameter :: tauUpperLimit = 200.
1025  real, parameter :: tauLowerLimit = 0.
1026 
1027  integer, parameter :: tauParamPosition = 4
1028  integer, parameter :: reParamPosition = 5
1029  real :: small_number
1030 
1031 ! for tau, determine abscissa interval taking into account the
1032 ! extrema and potentially rough transition point(s)
1033 
1034  halfabscissainterval = halfabscissaintervaltau
1035  abscissaintervalstartingpoint = tau
1036  wrtparam = tauparamposition
1037 
1038 
1039 #if NOSWIR
1040 
1041  upperlimit=tauupperlimit
1042  lowerlimit=taulowerlimit
1043 
1044  i = 1
1045  call reflpartialderivative( &
1046  upperlimit, lowerlimit, &
1047  halfabscissainterval, &
1048  abscissaintervalstartingpoint, &
1049  re, tau,phase, &
1050  surface_albedo(i), &
1051  wrtparam, &
1052  r1r2wavelengthidx(i), &
1053  partialderivativestau)
1054 
1055  small_number = epsilon(partialderivativestau)
1056 
1057  if(abs(partialderivativestau) .lt. small_number) partialderivativestau = &
1058  small_number
1059 
1060  partialderivtauwrtr1atconstr2 = 1. / partialderivativestau
1061  partialderivtauwrtr2atconstr1 = 0.0
1062  partialderivrewrtr1atconstr2 = 0.0
1063  partialderivrewrtr2atconstr1 = 0.0
1064 
1065 #else
1066 
1067 ! loop over wavelengths
1068  do i =1, 2
1069 
1070  upperlimit=tauupperlimit
1071  lowerlimit=taulowerlimit
1072 
1073 ! Compute derivative for dR1/dT )re, and dR2/dT )re
1074  call reflpartialderivative( &
1075  upperlimit, lowerlimit, &
1076  halfabscissainterval, &
1077  abscissaintervalstartingpoint, &
1078  re, tau,phase, &
1079  surface_albedo(i), &
1080  wrtparam, &
1081  r1r2wavelengthidx(i), &
1082  partialderivativestau)
1083  if (i .eq. 1) then
1084 ! dR1/dT | re
1085  partialderivr1wrttauatconstre = partialderivativestau
1086  else
1087 ! dR2/dT | re
1088  partialderivr2wrttauatconstre = partialderivativestau
1089  endif
1090  end do
1091 
1092 ! for re, determine abscissa interval taking into account the extrema
1093  halfabscissainterval = halfabscissaintervalre
1094  abscissaintervalstartingpoint = re
1095 
1096 
1097 
1098 ! for re must determine which phase
1099  if(phase == 'water') then
1100  upperlimit = water_radii(number_waterradii)
1101  lowerlimit = water_radii(1)
1102  else
1103  upperlimit = ice_radii(number_iceradii)
1104  lowerlimit = ice_radii(1)
1105  endif
1106 
1107 ! Compute derivative for dR1/dre )T, and dR2/dre)T
1108  wrtparam = reparamposition
1109 
1110  do i = 1, 2
1111  call reflpartialderivative( &
1112  upperlimit, lowerlimit, &
1113  halfabscissainterval, &
1114  abscissaintervalstartingpoint, &
1115  re, tau,phase, &
1116  surface_albedo(i), &
1117  wrtparam, &
1118  r1r2wavelengthidx(i), &
1119  partialderivativesre)
1120 
1121  if (i == 1 ) then
1122 ! dR1 / dre | T
1123  partialderivr1wrtreatconsttau = partialderivativesre
1124  else
1125 ! dR2 / dre | T
1126  partialderivr2wrtreatconsttau = partialderivativesre
1127  endif
1128 
1129  enddo
1130 
1131 
1132 ! head-off divide by 0
1133  small_number = epsilon(partialderivr1wrttauatconstre)
1134 
1135  if(abs(partialderivr1wrttauatconstre) .lt. small_number) partialderivr1wrttauatconstre = &
1136  small_number
1137  if(abs(partialderivr2wrttauatconstre) .lt. small_number) partialderivr2wrttauatconstre = &
1138  small_number
1139  if(abs(partialderivr1wrtreatconsttau) .lt. small_number) partialderivr1wrtreatconsttau = &
1140  small_number
1141  if(abs(partialderivr2wrtreatconsttau) .lt. small_number) partialderivr2wrtreatconsttau = &
1142  small_number
1143 
1144 ! Compute the derivatives
1145  partialderivtauwrtr1atconstr2 = 1. / &
1146  (partialderivr1wrttauatconstre - &
1147  partialderivr1wrtreatconsttau * &
1148  (partialderivr2wrttauatconstre/partialderivr2wrtreatconsttau) )
1149 
1150  partialderivtauwrtr2atconstr1 = 1. / &
1151  (partialderivr2wrttauatconstre - &
1152  partialderivr2wrtreatconsttau * &
1153  (partialderivr1wrttauatconstre/partialderivr1wrtreatconsttau) )
1154 
1155  partialderivrewrtr1atconstr2 = 1. / &
1156  (partialderivr1wrtreatconsttau - &
1157  partialderivr1wrttauatconstre * &
1158  (partialderivr2wrtreatconsttau/partialderivr2wrttauatconstre) )
1159 
1160  partialderivrewrtr2atconstr1 = 1. / &
1161  (partialderivr2wrtreatconsttau - &
1162  partialderivr2wrttauatconstre * &
1163  (partialderivr1wrtreatconsttau/partialderivr1wrttauatconstre) )
1164 
1165 #endif
1166 
1167 if(debugprn) then
1168 print*, 'partialDerivTauWrtR1AtConstR2 = ', partialderivtauwrtr1atconstr2
1169 print*, 'partialDerivTauWrtR2AtConstR1 = ', partialderivtauwrtr2atconstr1
1170 print*, 'partialDerivReWrtR1AtConstR2 = ', partialderivrewrtr1atconstr2
1171 print*, 'partialDerivReWrtR2AtConstR1 = ', partialderivrewrtr2atconstr1
1172 endif
1173 
1174 end subroutine sensitivitypartialderivatives
1175  subroutine reflpartialderivative(upperLimit, lowerLimit, &
1176  halfAbscissaInterval, abscissaIntervalStartingPoint, &
1177  re, tau, phase, &
1178  surface_albedo, &
1179  wrtParam, wavelengthIdx, &
1180  partialDerivative)
1181 !-----------------------------------------------------------------------
1182 ! !f90
1183 !
1184 ! !Description:
1185 ! This subroutine computes a partial derivative of tau or re using the
1186 ! central difference method. Special cases such as crossing to asymptotic regime
1187 ! and being at libraries' ends are handled also.
1188 !
1189 ! !Input Parameters:
1190 ! wrtParam -- integer -- flag controlling whether or not to compute the derivatives
1191 !
1192 ! !Output Parameters:
1193 ! partialDerivatives -- real*4, dimension(:) -- array of partial derivatives
1194 !
1195 ! !Revision History:
1196 ! 2004/05/28 bwind: Brad Wind
1197 ! Revision 1.0 Initial Revision
1198 !
1199 ! !Team-Unique Header:
1200 ! Developed by the Cloud Retrieval Group, NASA GSFC, Greenbelt, Maryland, USA.
1201 !
1202 ! !References and Credits:
1203 ! Written by:
1204 ! Bradley P. Wind
1205 ! L3 GSI
1206 ! Code 913, NASA/GSFC
1207 ! Greenbelt, MD 20771
1208 ! bwind@climate.gsfc.nasa.gov
1209 !
1210 ! Mark Gray
1211 ! L3-GSI
1212 ! Climate and Radiation Branch, Code 913
1213 ! NASA/GSFC
1214 ! Greenbelt MD 20771
1215 ! gray@climate.gsfc.nasa.gov
1216 !
1217 ! !Design Notes:
1218 ! NONE
1219 !
1220 ! !END
1221 !
1222 !-----------------------------------------------------------------------
1223  use generalauxtype
1224  use science_parameters
1225  implicit none
1226 
1227  integer, intent(in) :: wrtParam, wavelengthIdx
1228  real, intent(in) :: re, tau
1229  real, intent(in) :: surface_albedo
1230  real, intent(in) :: upperLimit, lowerLimit
1231  character(10),intent(in) :: phase
1232  real, intent(out) :: partialDerivative
1233 
1234  real :: Rb, Ra
1235  real :: tmpTau, tmpRe
1236 
1237  real :: halfAbscissaInterval, abscissaIntervalStartingPoint
1238  real :: abscissaIntervalLower, abscissaIntervalUpper
1239  integer, parameter :: tauParamPosition = 4
1240  integer, parameter :: reParamPosition = 5
1241 
1242  integer :: idxJ
1243  call abscissainterval(upperlimit, lowerlimit, &
1244  halfabscissainterval, abscissaintervalstartingpoint, &
1245  abscissaintervallower, abscissaintervalupper)
1246 
1247 
1248 
1249 
1250  rb = 0.
1251  ra = 0.
1252 
1253 ! get reflectances
1254  select case (wrtparam)
1255  case(tauparamposition)
1256 ! in tau case
1257 ! ...abscissaIntervalUpper/Lower are upper and lower optical thicknesses
1258  call getctref_constradius( &
1259  abscissaintervalupper, &
1260  abscissaintervallower, &
1261  re, phase, &
1262  surface_albedo, &
1263  wavelengthidx, rb, ra)
1264  partialderivative = (rb - ra)
1265  partialderivative = partialderivative / (abscissaintervalupper - abscissaintervallower)
1266 
1267  case(reparamposition)
1268 ! in re case
1269 ! ...abscissaIntervalUpper/Lower are upper and lower effective radii
1270 
1271  call getctref_consttau( &
1272  abscissaintervalupper, &
1273  abscissaintervallower, &
1274  re, tau, phase, &
1275  surface_albedo, &
1276  wavelengthidx, partialderivative)
1277 
1278 
1279  case default
1280  end select
1281 
1282 
1283  ! perform the division
1284 
1285  end subroutine reflpartialderivative
1286 
1287 
1288 subroutine abscissainterval(upperLimit, lowerLimit, &
1289  halfAbscissaInterval, abscissaIntervalStartingPoint, &
1290  abscissaIntervalLower, abscissaIntervalUpper)
1292 !-----------------------------------------------------------------------
1293 ! !f90
1294 !
1295 ! !Description:
1296 ! This subroutine figures out the interval for use in the
1297 ! central difference method. Special cases such as crossing to asymptotic regime
1298 ! and being at libraries' ends are handled also.
1299 !
1300 ! !Input Parameters:
1301 ! NONE
1302 !
1303 ! !Output Parameters:
1304 ! NONE
1305 !
1306 ! !Revision History:
1307 ! 2004/05/28 bwind: Brad Wind
1308 ! Revision 1.0 Initial Revision
1309 !
1310 ! !Team-Unique Header:
1311 ! Developed by the Cloud Retrieval Group, NASA GSFC, Greenbelt, Maryland, USA.
1312 !
1313 ! !References and Credits:
1314 ! Written by:
1315 ! Bradley P. Wind
1316 ! L3 GSI
1317 ! Code 913, NASA/GSFC
1318 ! Greenbelt, MD 20771
1319 ! bwind@climate.gsfc.nasa.gov
1320 !
1321 ! Mark Gray
1322 ! L3-GSI
1323 ! Climate and Radiation Branch, Code 913
1324 ! NASA/GSFC
1325 ! Greenbelt MD 20771
1326 ! gray@climate.gsfc.nasa.gov
1327 !
1328 ! !Design Notes:
1329 ! NONE
1330 !
1331 ! !END
1332 !
1333 !-----------------------------------------------------------------------\
1334  use science_parameters
1335 
1336  implicit none
1337 
1338  real, intent(in) :: upperLimit, lowerLimit, &
1339  halfAbscissaInterval, abscissaIntervalStartingPoint
1340  real, intent(out) :: abscissaIntervalLower, abscissaIntervalUpper
1341 
1342  ! Reminder: halfAbscissaIntervalTau = 1., halfAbscissaIntervalRe = 1.
1343 
1344  if((abscissaintervalstartingpoint+halfabscissainterval) > upperlimit) then
1345  abscissaintervalupper = abscissaintervalstartingpoint
1346  else
1347  abscissaintervalupper = (abscissaintervalstartingpoint+halfabscissainterval)
1348  end if
1349 
1350  if((abscissaintervalstartingpoint-halfabscissainterval) < lowerlimit) then
1351  abscissaintervallower = abscissaintervalstartingpoint
1352  else
1353  abscissaintervallower = (abscissaintervalstartingpoint-halfabscissainterval)
1354  end if
1355 
1356 end subroutine abscissainterval
1357 subroutine getctref_constradius( &
1358  optical_thickness_upper, &
1359  optical_thickness_lower, &
1360  radius, &
1361  phase, &
1362  surface_albedo, &
1363  wave_index, &
1364  reflectance_upper, &
1365  reflectance_lower)
1368  use libraryarrays
1370  use mod06_run_settings
1371  use science_parameters
1372  implicit none
1373 
1374  real, intent(in) :: optical_thickness_upper, optical_thickness_lower
1375  integer, intent(in) :: wave_index
1376  real, intent(in) :: radius, surface_albedo
1377  character(10),intent(in) :: phase
1378  real, intent(out) :: reflectance_upper, reflectance_lower
1379 
1380  integer :: radii_size , radius_upperbound, radius_lowerbound, radius_index, i,j, points
1381  real, dimension(:), allocatable :: opticalthick_vector!(6)
1382  real :: reflectance_vector_upper(3), reflectance_vector_lower(3), yy2(3)
1383 
1384  integer :: TOTAL_POINTS
1385 
1386  total_points = size(library_taus) + 1
1387 
1388 
1389  allocate(opticalthick_vector(total_points))
1390 
1391 
1392  opticalthick_vector(1) = 0.
1393  opticalthick_vector(2:total_points) = library_taus(1:(total_points-1))
1394 
1395 
1396  if (phase == 'water') then
1398  water_radii,radius, &
1399  i)
1400 
1401  if (cox_munk) then
1402 
1403  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1404  optical_thickness_lower, &
1405  int_reflectance_water(:,wave_index,i), &
1406  reflectance_lower)
1407 
1408  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1409  optical_thickness_upper, &
1410  int_reflectance_water(:,wave_index,i), &
1411  reflectance_upper)
1412 
1413 
1414  else
1415  call nonasymptotic_calcu(opticalthick_vector, optical_thickness_lower, &
1416  spherical_albedo_water(:,wave_index,i), int_reflectance_water(:,wave_index,i), &
1417  int_fluxdownwater_sensor(:,wave_index,i), int_fluxdownwater_solar(:,wave_index,i), &
1418  surface_albedo, reflectance_lower)
1419  call nonasymptotic_calcu(opticalthick_vector, optical_thickness_upper, &
1420  spherical_albedo_water(:,wave_index,i), int_reflectance_water(:,wave_index,i), &
1421  int_fluxdownwater_sensor(:,wave_index,i), int_fluxdownwater_solar(:,wave_index,i), &
1422  surface_albedo, reflectance_upper)
1423  endif
1424 
1425  else
1427  ice_radii,radius, &
1428  i)
1429 
1430  if (cox_munk) then
1431 
1432  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1433  optical_thickness_lower, &
1434  int_reflectance_ice(:,wave_index,i), &
1435  reflectance_lower)
1436 
1437  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1438  optical_thickness_upper, &
1439  int_reflectance_ice(:,wave_index,i), &
1440  reflectance_upper)
1441 
1442  else
1443  call nonasymptotic_calcu(opticalthick_vector, optical_thickness_lower, &
1444  spherical_albedo_ice(:,wave_index,i), int_reflectance_ice(:,wave_index,i), &
1445  int_fluxdownice_sensor(:,wave_index,i), int_fluxdownice_solar(:,wave_index,i), &
1446  surface_albedo, reflectance_lower)
1447  call nonasymptotic_calcu(opticalthick_vector, optical_thickness_upper, &
1448  spherical_albedo_ice(:,wave_index,i), int_reflectance_ice(:,wave_index,i), &
1449  int_fluxdownice_sensor(:,wave_index,i), int_fluxdownice_solar(:,wave_index,i), &
1450  surface_albedo, reflectance_upper)
1451  endif
1452  endif
1453 
1454 
1455  deallocate(opticalthick_vector)
1456 
1457 end subroutine getctref_constradius
1458 subroutine getctref_consttau(&
1459  radius_upper, &
1460  radius_lower, &
1461  radius, optical_thickness, &
1462  phase, &
1463  surface_albedo, &
1464  wave_index, &
1465  partial_derivative)
1468  use libraryarrays
1470  use mod06_run_settings
1471  use science_parameters
1472  implicit none
1473 
1474  real, intent(inout) :: radius_upper, radius_lower
1475  integer, intent(in) :: wave_index
1476  real, intent(in) :: optical_thickness, radius, surface_albedo
1477  character(10),intent(in) :: phase
1478  real, intent(out) :: partial_derivative
1479 
1480  real :: reflectance_upper, reflectance_lower
1481 
1482  integer :: radii_size , radius_upperbound, radius_lowerbound, radius_index, i,j, vectorsize
1483  real, dimension(:), allocatable :: opticalthick_vector, opticalthick_vector2!(6)
1484  real,dimension(20):: reflectance_vector
1485 
1486  integer :: dummy, il, jl, iu, ju, k
1487  real :: my_radius, myrefl(90), myres(90), myx(3), myy(3), half_rad(2)
1488  integer :: TOTAL_POINTS
1489  real :: mymid1, mymid2, reflectance_middle, delre
1490  real :: new_derivatives(25)
1491  integer :: istart, jstart
1492 
1493  total_points = size(library_taus) + 1
1494 
1495 
1496  allocate(opticalthick_vector(total_points), opticalthick_vector2(total_points))
1497 
1498 
1499  opticalthick_vector(1) = 0.
1500  opticalthick_vector(2:total_points) = library_taus(1:(total_points-1))
1501  opticalthick_vector2 = opticalthick_vector
1502  if (phase == 'water') then
1503 
1504  call getradiibounds(number_waterradii, water_radii, radius, j, i)
1505 
1506 ! radius_lower = water_radii(i)
1507 ! radius_upper = water_radii(j)
1508 ! call nonasymptotic_calcu(opticalthick_vector, optical_thickness, &
1509 ! spherical_albedo_water(:,wave_index,i), int_reflectance_water(:,wave_index,i), &
1510 ! int_fluxdownwater_sensor(:,wave_index,i), int_fluxdownwater_solar(:,wave_index,i), &
1511 ! surface_albedo, reflectance_lower)
1512 
1513 ! call nonasymptotic_calcu(opticalthick_vector2, optical_thickness, &
1514 ! spherical_albedo_water(:,wave_index,j), int_reflectance_water(:,wave_index,j), &
1515 ! int_fluxdownwater_sensor(:,wave_index,j), int_fluxdownwater_solar(:,wave_index,j), &
1516 ! surface_albedo, reflectance_upper)
1517 
1518  new_derivatives = 0.
1519 
1520  i = i-1
1521  j = j+1
1522  if (i<1) i = 1
1524 
1525  if (cox_munk) then
1526 
1527  do il = i, j-1
1528  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1529  optical_thickness, &
1530  int_reflectance_water(:,wave_index,il), &
1531  reflectance_lower)
1532 
1533  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1534  optical_thickness, &
1535  int_reflectance_water(:,wave_index,il+1), &
1536  reflectance_upper)
1537 
1538  new_derivatives(il+1) = (reflectance_upper - reflectance_lower) / &
1539  (water_radii(il+1) - water_radii(il))
1540  end do
1541 
1542  else
1543 
1544  do il = i, j-1
1545  call nonasymptotic_calcu(opticalthick_vector, optical_thickness, &
1546  spherical_albedo_water(:,wave_index,il), int_reflectance_water(:,wave_index,il), &
1547  int_fluxdownwater_sensor(:,wave_index,il), int_fluxdownwater_solar(:,wave_index,il), &
1548  surface_albedo, reflectance_lower)
1549 
1550  call nonasymptotic_calcu(opticalthick_vector2, optical_thickness, &
1551  spherical_albedo_water(:,wave_index,il+1), int_reflectance_water(:,wave_index,il+1), &
1552  int_fluxdownwater_sensor(:,wave_index,il+1), int_fluxdownwater_solar(:,wave_index,il+1), &
1553  surface_albedo, reflectance_upper)
1554 
1555  new_derivatives(il+1) = (reflectance_upper - reflectance_lower) / &
1556  (water_radii(il+1) - water_radii(il))
1557 
1558  end do
1559  endif
1560 
1561 
1562  new_derivatives(1) = new_derivatives(2)
1563  new_derivatives(number_waterradii+1) = new_derivatives(number_waterradii)
1564 
1565  call getradiibounds(number_waterradii+1, new_water_radii, radius, iu, il)
1566 
1567  partial_derivative = linearinterpolation( (/ new_water_radii(il), new_water_radii(iu) /), &
1568  (/ new_derivatives(il), new_derivatives(iu) /), &
1569  radius)
1570 
1571 
1572  else
1573 
1574  call getradiibounds(number_iceradii, ice_radii, radius, j, i)
1575 
1576 
1577  new_derivatives = 0.
1578 
1579  i = i-1
1580  j = j+1
1581  if (i <1) i = 1
1582  if (j>number_iceradii) j = number_iceradii
1583 
1584  if (cox_munk) then
1585  do il = i, j-1
1586  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1587  optical_thickness, &
1588  int_reflectance_ice(:,wave_index,il), &
1589  reflectance_lower)
1590 
1591  call nonasymptotic_calcu_cox_munk(opticalthick_vector, &
1592  optical_thickness, &
1593  int_reflectance_ice(:,wave_index,il+1), &
1594  reflectance_upper)
1595 
1596  new_derivatives(il+1) = (reflectance_upper - reflectance_lower) / &
1597  (ice_radii(il+1) - ice_radii(il))
1598 
1599  end do
1600 
1601  else
1602  do il = i, j-1
1603  call nonasymptotic_calcu(opticalthick_vector, optical_thickness, &
1604  spherical_albedo_ice(:,wave_index,il), int_reflectance_ice(:,wave_index,il), &
1605  int_fluxdownice_sensor(:,wave_index,il), int_fluxdownice_solar(:,wave_index,il), &
1606  surface_albedo, reflectance_lower)
1607 
1608  call nonasymptotic_calcu(opticalthick_vector, optical_thickness , &
1609  spherical_albedo_ice(:,wave_index,il+1), int_reflectance_ice(:,wave_index,il+1), &
1610  int_fluxdownice_sensor(:,wave_index,il+1), int_fluxdownice_solar(:,wave_index,il+1), &
1611  surface_albedo, reflectance_upper)
1612 
1613  new_derivatives(il+1) = (reflectance_upper - reflectance_lower) / &
1614  (ice_radii(il+1) - ice_radii(il))
1615 
1616  end do
1617  endif
1618 
1619  new_derivatives(1) = new_derivatives(2)
1620  new_derivatives(number_iceradii+1) = new_derivatives(number_iceradii)
1621 
1622 
1623  call getradiibounds(number_iceradii+1, new_ice_radii, radius, iu, il)
1624 
1625  partial_derivative = linearinterpolation( (/ new_ice_radii(il), new_ice_radii(iu) /), &
1626  (/ new_derivatives(il), new_derivatives(iu) /), &
1627  radius)
1628 
1629  endif
1630 
1631 
1632  deallocate(opticalthick_vector, opticalthick_vector2)
1633 
1634 
1635 end subroutine getctref_consttau
1636 
1637 subroutine getradiibounds(radiisize, radiidata, radius, upperbound, lowerbound)
1639  implicit none
1640 
1641  integer, intent(in) :: radiisize
1642  real, intent(in) :: radiidata(:), radius
1643  integer, intent(out) :: upperbound, lowerbound
1644 
1645  integer :: i
1646 
1647  upperbound = -1
1648  lowerbound = -1
1649  do i = 1, radiisize - 1
1650  if (radius >= radiidata(i).and. radius <= radiidata(i+1)) then
1651  upperbound = i+1
1652  lowerbound = i
1653  exit
1654  endif
1655  enddo
1656 
1657 
1658 end subroutine getradiibounds
1659 
1660 end module get_retrieval_uncertainty
Definition: ch_xfr.f90:1
integer number_wavelengths
real ozone_transmittance
subroutine nonasymptotic_calcu(tau_vector, tc, sfr, rf, ft1, ft0, albedo, rf_calculated)
integer ocis_id
Definition: ch_xfr.f90:51
subroutine getctrefl_windspeeddiff(radius, optical_thickness, phase, wave_index, reflectancediff, meancloudtopreflw1, meancloudtopreflw2)
real(single), dimension(:,:), allocatable optical_thickness_37_final
Definition: core_arrays.f90:41
subroutine nonasymptotic_albedovar(tau_vector, tc, sfr, rf, ft1, ft0, albedo, rf_lower, rf_middle, rf_upper)
real function, public linearinterpolation(X, Y, XX)
real(single), dimension(:,:,:), allocatable int_reflectance_ice
real(single), dimension(:,:,:), allocatable int_fluxdownwater_solar
integer, parameter band_0370
subroutine getctref_constradius(optical_thickness_upper, optical_thickness_lower, radius, phase, surface_albedo, wave_index, reflectance_upper, reflectance_lower)
subroutine getctref_consttau(radius_upper, radius_lower, radius, optical_thickness, phase, surface_albedo, wave_index, partial_derivative)
subroutine reflpartialderivative(upperLimit, lowerLimit, halfAbscissaInterval, abscissaIntervalStartingPoint, re, tau, phase, surface_albedo, wrtParam, wavelengthIdx, partialDerivative)
real(single), dimension(:), allocatable water_radii
real(single), dimension(:), allocatable library_taus
real(single), dimension(:,:,:), allocatable int_reflectance_ice_sdev
real(single), dimension(:,:,:), allocatable int_reflectance_water_sdev
real, parameter ice_water_density
real(single), dimension(:,:,:), allocatable spherical_albedo_water
subroutine, public getuncertainties(thickness, re, water_path, phase, R1R2wavelengthIdx, meas_error, surface_albedo, transmittance_w1, transmittance_w2, delta_transmittance_w1, delta_transmittance_w2, transmittance_stddev_w1, transmittance_stddev_w2, emission_pw, emission_Tc, sigma_R37_pw, uTau, uRe, uWaterPath, xpoint, ypoint)
subroutine, public interpolate_wind_speed(wspeed, data_in, data_out)
real mean_delta_ozone
real(single), dimension(:,:,:), allocatable int_fluxdownice_solar
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
real(single), dimension(:,:,:), allocatable spherical_albedo_ice
subroutine, public getradiibounds(radiisize, radiidata, radius, upperbound, lowerbound)
real, parameter albedo_error
===========================================================================V5.0.48(Terra) 03/20/2015 Changes shown below are differences from MOD_PR02 V5.0.46(Terra)============================================================================Changes noted for V6.1.20(Terra) below were also instituted for this version.============================================================================V6.1.20(Terra) 03/12/2015 Changes shown below are differences from MOD_PR02 V6.1.18(Terra)============================================================================Changes from v6.1.18 which may affect scientific output:A situation can occur in which a scan which contains sector rotated data has a telemetry value indicating the completeness of the sector rotation. This issue is caused by the timing of the instrument command to perform the sector rotation and the recording of the telemetry point that reports the status of sector rotation. In this case a scan is considered valid by L1B and pass through the calibration - reporting extremely high radiances. Operationally the TEB calibration uses a 40 scan average coefficient, so the 20 scans(one mirror side) after the sector rotation are contaminated with anomalously high radiance values. A similar timing issue appeared before the sector rotation was fixed in V6.1.2. Our analysis indicates the ‘SET_FR_ENC_DELTA’ telemetry correlates well with the sector rotation encoder position. The use of this telemetry point to determine scans that are sector rotated should fix the anomaly occured before and after the sector rotation(usually due to the lunar roll maneuver). The fix related to the sector rotation in V6.1.2 is removed in this version.============================================================================V6.1.18(Terra) 10/01/2014 Changes shown below are differences from MOD_PR02 V6.1.16(Terra)============================================================================Added doi attributes to NRT(Near-Real-Time) product.============================================================================V6.1.16(Terra) 01/27/2014 Changes shown below are differences from MOD_PR02 V6.1.14(Terra)============================================================================Migrate to SDP Toolkit 5.2.17============================================================================V6.1.14(Terra) 06/26/2012 Changes shown below are differences from MOD_PR02 V6.1.12(Terra)============================================================================Added the doi metadata to L1B product============================================================================V6.1.12(Terra) 04/25/2011 Changes shown below are differences from MOD_PR02 V6.1.8(Terra)============================================================================1. The algorithm to calculate uncertainties for reflective solar bands(RSB) is updated. The current uncertainty in L1B code includes 9 terms from prelaunch analysis. The new algorithm regroups them with the new added contributions into 5 terms:u1:the common term(AOI and time independent) and
Definition: HISTORY.txt:126
subroutine abscissainterval(upperLimit, lowerLimit, halfAbscissaInterval, abscissaIntervalStartingPoint, abscissaIntervalLower, abscissaIntervalUpper)
real(single), dimension(:), allocatable ice_radii
subroutine get_emission_values(re, sigma37, phase, sigma37_val)
real, parameter wind_speed_error
integer c2_sensor_id
Definition: ch_xfr.f90:50
subroutine getclosestradius(numberradii, radiidata, radius, index)
real(single), dimension(:,:,:), allocatable int_reflectance_water
integer, parameter band_0065
integer number_waterradii
real(single), dimension(:,:), allocatable optical_thickness_1621_final
Definition: core_arrays.f90:42
#define re
Definition: l1_czcs.c:695
subroutine phase
Definition: phase.f:2
real(single), dimension(:,:,:), allocatable int_fluxdownwater_sensor
subroutine getctref_albedodiff(radius, optical_thickness, phase, wave_index, surface_albedo, reflectancediff, meancloudtopreflw1, meancloudtopreflw2)
integer number_iceradii
real, parameter liquid_water_density
integer oci_id
Definition: ch_xfr.f90:52
subroutine, public bisectionsearch(xx, x, jlo, jhi)
real(single), dimension(:,:,:), allocatable int_fluxdownice_sensor
subroutine get_refl_windvector(radius, optical_thickness, phase, wave_index, sdev_refl)
real(single), dimension(:,:,:,:), allocatable int_reflectance_water_wspeed
void radius(double A)
Definition: proj_report.c:132
#define abs(a)
Definition: misc.h:90
real(single), dimension(:,:,:,:), allocatable int_reflectance_ice_wspeed
subroutine sensitivitypartialderivatives(R1R2wavelengthIdx, re, tau, phase, surface_albedo, partialDerivTauWrtR1AtConstR2, partialDerivTauWrtR2AtConstR1, partialDerivReWrtR1AtConstR2, partialDerivReWrtR2AtConstR1)
void transpose(float *in[], float *out[])
Definition: get_zenaz.c:97