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