14 integer,
parameter :: SGL = selected_real_kind(p=3)
16 real,
dimension(30) :: lut_raa
17 real,
dimension(46) :: lut_vza
19 real,
dimension(12,46,30,10,8,20) :: nvalx412
20 real,
dimension(12,46,30,10,4,24) :: nvalx470
21 real,
dimension(12,46,30,10,24) :: nvalx650
23 type :: viirs_aerosol_lut
32 real,
dimension(:),
allocatable :: sza
33 real,
dimension(:),
allocatable :: vza
34 real,
dimension(:),
allocatable :: raa
35 real,
dimension(:),
allocatable :: aot
36 real,
dimension(:),
allocatable :: ssa
37 real,
dimension(:),
allocatable :: sfc
39 real,
dimension(:,:,:,:,:,:),
allocatable :: nvalx
40 end type viirs_aerosol_lut
42 type(viirs_aerosol_lut) :: default_lut412, default_lut488, default_lut672
43 type(viirs_aerosol_lut) :: dust_lut412, dust_lut488, dust_lut672
45 common /aottbl/ nvalx412, nvalx(12,46,30,10), &
46 & theta0(12), theta(46), &
47 & phi(30), sfc_ref412(20), tau(10), w0(8), w0_470(4), &
48 & nvalx650, sfc_ref650(24), sfc_ref470(24), &
49 & sfcprs(360,720), nvalx470
56 character(len=255),
intent(in) :: lut_file
57 character(len=255) :: lut_type
60 lut_type =
'LAND_AEROSOL_FINE'
61 status = read_aerosol_lut_file(lut_file, lut_type, default_lut412, default_lut488, default_lut672)
63 print *,
'ERROR: Failed to read in default land aerosol model LUT: ', status
64 print *,
'File: ',
trim(lut_file)
70 lut_type =
'LAND_AEROSOL_DUST'
71 status = read_aerosol_lut_file(lut_file, lut_type, dust_lut412, dust_lut488, dust_lut672)
73 print *,
'ERROR: Failed to read in dust aerosol model LUT: ', status
74 print *,
'File: ',
trim(lut_file)
82 nvalx412 = default_lut412%nvalx(:,:,:,:,:,:)
83 nvalx470 = default_lut488%nvalx(:,:,:,:,:,:)
84 nvalx650 = default_lut672%nvalx(:,:,:,:,1,:)
86 tau = default_lut412%aot
87 theta0 = default_lut412%sza
88 phi = default_lut412%raa
89 theta = default_lut412%vza
90 w0 = default_lut412%ssa
92 w0_470 = default_lut488%ssa
93 sfc_ref412 = default_lut412%sfc
94 sfc_ref470 = default_lut488%sfc
95 sfc_ref650 = default_lut672%sfc
104 integer,
intent(inout) :: status
115 integer function read_aerosol_lut_file(lut_file, type, lut412, lut488, lut672)
result(status)
123 character(len=255),
intent(in) :: lut_file
124 character(len=255),
intent(in) :: type
125 type(viirs_aerosol_lut),
intent(inout) :: lut412
126 type(viirs_aerosol_lut),
intent(inout) :: lut488
127 type(viirs_aerosol_lut),
intent(inout) :: lut672
129 integer :: sd_id, sds_index, sds_id, rank, n_attrs, data_type
130 integer,
dimension(1) :: start1, stride1, edges1, dim_sizes1
131 integer,
dimension(5) :: edges5, start5, stride5, dim_sizes5
132 integer,
dimension(6) :: edges6, start6, stride6, dim_sizes6
133 integer,
dimension(32):: dimids
135 integer :: xtype, ndims
141 character(len=255) :: dset_name
142 character(len=255) :: attr_name
143 character(len=255) :: group_name
144 character(len=255) :: err_msg
146 status = nf90_open(lut_file, nf90_nowrite, nc_id)
147 if (status /= nf90_noerr)
then
148 print *,
"ERROR: Failed to open deepblue lut_nc4 file: ", status
152 group_name =
trim(type)
153 status = nf90_inq_ncid(nc_id, group_name, grp_id)
154 if (status /= nf90_noerr)
then
155 print *,
"ERROR: Failed to get ID of group "//
trim(group_name)//
": ", status
161 dset_name =
'SZA412_Nodes'
162 status = nf90_inq_varid(grp_id, dset_name, dset_id)
163 if (status /= nf90_noerr)
then
164 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
167 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
168 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
169 err_msg = nf90_strerror(status)
170 if (status /= nf90_noerr)
then
171 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
177 allocate(lut412%sza(lut412%nsza), stat=status)
178 if (status /= 0)
then
179 print *,
"ERROR: Unable to allocate SZA412 data array: ", status
185 edges1 = (/lut412%nsza/)
186 status = nf90_get_var(grp_id, dset_id, lut412%sza, start=start1, &
187 stride=stride1, count=edges1)
188 err_msg = nf90_strerror(status)
189 if (status /= nf90_noerr)
then
190 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
194 dset_name =
'VZA412_Nodes'
195 status = nf90_inq_varid(grp_id, dset_name, dset_id)
196 if (status /= nf90_noerr)
then
197 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
200 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
201 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
202 err_msg = nf90_strerror(status)
203 if (status /= nf90_noerr)
then
204 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
210 allocate(lut412%vza(lut412%nvza), stat=status)
211 if (status /= 0)
then
212 print *,
"ERROR: Unable to allocate VZA412 data array: ", status
218 edges1 = (/lut412%nvza/)
219 status = nf90_get_var(grp_id, dset_id, lut412%vza, start=start1, &
220 stride=stride1, count=edges1)
221 err_msg = nf90_strerror(status)
222 if (status /= nf90_noerr)
then
223 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
227 dset_name =
'RAA412_Nodes'
228 status = nf90_inq_varid(grp_id, dset_name, dset_id)
229 if (status /= nf90_noerr)
then
230 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
233 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
234 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
235 err_msg = nf90_strerror(status)
236 if (status /= nf90_noerr)
then
237 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
243 allocate(lut412%raa(lut412%nraa), stat=status)
244 if (status /= 0)
then
245 print *,
"ERROR: Unable to allocate RAA412 data array: ", status
251 edges1 = (/lut412%nraa/)
252 status = nf90_get_var(grp_id, dset_id, lut412%raa, start=start1, &
253 stride=stride1, count=edges1)
254 if (status /= nf90_noerr)
then
255 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
259 dset_name =
'AOT412_Nodes'
260 status = nf90_inq_varid(grp_id, dset_name, dset_id)
261 if (status /= nf90_noerr)
then
262 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
265 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
266 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
267 err_msg = nf90_strerror(status)
268 if (status /= nf90_noerr)
then
269 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
275 allocate(lut412%aot(lut412%naot), stat=status)
276 if (status /= 0)
then
277 print *,
"ERROR: Unable to allocate AOT412 data array: ", status
283 edges1 = (/lut412%naot/)
284 status = nf90_get_var(grp_id, dset_id, lut412%aot, start=start1, &
285 stride=stride1, count=edges1)
286 err_msg = nf90_strerror(status)
287 if (status /= nf90_noerr)
then
288 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
292 dset_name =
'SSA412_Nodes'
293 status = nf90_inq_varid(grp_id, dset_name, dset_id)
294 if (status /= nf90_noerr)
then
295 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
298 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
299 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
300 err_msg = nf90_strerror(status)
301 if (status /= nf90_noerr)
then
302 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
308 allocate(lut412%ssa (lut412%nssa ), stat=status)
309 if (status /= 0)
then
310 print *,
"ERROR: Unable to allocate SSA412 data array: ", status
316 edges1 = (/lut412%nssa /)
317 status = nf90_get_var(grp_id, dset_id, lut412%ssa , start=start1, &
318 stride=stride1, count=edges1)
319 err_msg = nf90_strerror(status)
320 if (status /= nf90_noerr)
then
321 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
325 dset_name =
'SR412_Nodes'
326 status = nf90_inq_varid(grp_id, dset_name, dset_id)
327 if (status /= nf90_noerr)
then
328 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
331 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
332 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
333 err_msg = nf90_strerror(status)
334 if (status /= nf90_noerr)
then
335 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
341 allocate(lut412%sfc (lut412%nsfc ), stat=status)
342 if (status /= 0)
then
343 print *,
"ERROR: Unable to allocate SR412 data array: ", status
349 edges1 = (/lut412%nsfc /)
350 status = nf90_get_var(grp_id, dset_id, lut412%sfc , start=start1, &
351 stride=stride1, count=edges1)
352 err_msg = nf90_strerror(status)
353 if (status /= nf90_noerr)
then
354 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
358 allocate(lut412%nvalx(lut412%nsza,lut412%nvza,lut412%nraa,lut412%naot,lut412%nssa, &
359 & lut412%nsfc), stat=status)
360 if (status /= 0)
then
361 print *,
"ERROR: Unable to allocate nvalx412 data array: ", status
365 dset_name =
'NVALX412'
366 status = nf90_inq_varid(grp_id, dset_name, dset_id)
367 if (status /= nf90_noerr)
then
368 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
371 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
372 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
373 err_msg = nf90_strerror(status)
374 if (status /= nf90_noerr)
then
375 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
380 lut412%nvalx = dimlen
381 if (status /= 0)
then
382 print *,
"ERROR: Unable to allocate SR412 data array: ", status
386 start6 = (/1,1,1,1,1,1/)
387 stride6 = (/1,1,1,1,1,1/)
388 edges6 = shape(lut412%nvalx)
389 status = nf90_get_var(grp_id, dset_id, lut412%nvalx , start=start6, &
390 stride=stride6, count=edges6)
391 err_msg = nf90_strerror(status)
392 if (status /= nf90_noerr)
then
393 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
400 dset_name =
'SZA488_Nodes'
401 status = nf90_inq_varid(grp_id, dset_name, dset_id)
402 if (status /= nf90_noerr)
then
403 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
406 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
407 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
408 err_msg = nf90_strerror(status)
409 if (status /= nf90_noerr)
then
410 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
416 allocate(lut488%sza(lut488%nsza), stat=status)
417 if (status /= 0)
then
418 print *,
"ERROR: Unable to allocate SZA488 data array: ", status
424 edges1 = (/lut488%nsza/)
425 status = nf90_get_var(grp_id, dset_id, lut488%sza, start=start1, &
426 stride=stride1, count=edges1)
427 err_msg = nf90_strerror(status)
428 if (status /= nf90_noerr)
then
429 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
433 dset_name =
'VZA488_Nodes'
434 status = nf90_inq_varid(grp_id, dset_name, dset_id)
435 if (status /= nf90_noerr)
then
436 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
439 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
440 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
441 err_msg = nf90_strerror(status)
442 if (status /= nf90_noerr)
then
443 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
449 allocate(lut488%vza(lut488%nvza), stat=status)
450 if (status /= 0)
then
451 print *,
"ERROR: Unable to allocate VZA488 data array: ", status
457 edges1 = (/lut488%nvza/)
458 status = nf90_get_var(grp_id, dset_id, lut488%vza, start=start1, &
459 stride=stride1, count=edges1)
460 err_msg = nf90_strerror(status)
461 if (status /= nf90_noerr)
then
462 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
466 dset_name =
'RAA488_Nodes'
467 status = nf90_inq_varid(grp_id, dset_name, dset_id)
468 if (status /= nf90_noerr)
then
469 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
472 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
473 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
474 err_msg = nf90_strerror(status)
475 if (status /= nf90_noerr)
then
476 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
482 allocate(lut488%raa(lut488%nraa), stat=status)
483 if (status /= 0)
then
484 print *,
"ERROR: Unable to allocate RAA488 data array: ", status
490 edges1 = (/lut488%nraa/)
491 status = nf90_get_var(grp_id, dset_id, lut488%raa, start=start1, &
492 stride=stride1, count=edges1)
493 err_msg = nf90_strerror(status)
494 if (status /= nf90_noerr)
then
495 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
499 dset_name =
'AOT488_Nodes'
500 status = nf90_inq_varid(grp_id, dset_name, dset_id)
501 if (status /= nf90_noerr)
then
502 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
505 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
506 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
507 err_msg = nf90_strerror(status)
508 if (status /= nf90_noerr)
then
509 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
515 allocate(lut488%aot(lut488%naot), stat=status)
516 if (status /= 0)
then
517 print *,
"ERROR: Unable to allocate AOT488 data array: ", status
523 edges1 = (/lut488%naot/)
524 status = nf90_get_var(grp_id, dset_id, lut488%aot, start=start1, &
525 stride=stride1, count=edges1)
526 err_msg = nf90_strerror(status)
527 if (status /= nf90_noerr)
then
528 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
532 dset_name =
'SSA488_Nodes'
533 status = nf90_inq_varid(grp_id, dset_name, dset_id)
534 if (status /= nf90_noerr)
then
535 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
538 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
539 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
540 err_msg = nf90_strerror(status)
541 if (status /= nf90_noerr)
then
542 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
548 allocate(lut488%ssa(lut488%nssa ), stat=status)
549 if (status /= 0)
then
550 print *,
"ERROR: Unable to allocate SSA488 data array: ", status
556 edges1 = (/lut488%nssa /)
557 status = nf90_get_var(grp_id, dset_id, lut488%ssa , start=start1, &
558 stride=stride1, count=edges1)
559 err_msg = nf90_strerror(status)
560 if (status /= nf90_noerr)
then
561 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
565 dset_name =
'SR488_Nodes'
566 status = nf90_inq_varid(grp_id, dset_name, dset_id)
567 if (status /= nf90_noerr)
then
568 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
571 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
572 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
573 err_msg = nf90_strerror(status)
574 if (status /= nf90_noerr)
then
575 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
581 allocate(lut488%sfc (lut488%nsfc ), stat=status)
582 if (status /= 0)
then
583 print *,
"ERROR: Unable to allocate SR488 data array: ", status
589 edges1 = (/lut488%nsfc /)
590 status = nf90_get_var(grp_id, dset_id, lut488%sfc , start=start1, &
591 stride=stride1, count=edges1)
592 if (status /= nf90_noerr)
then
593 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
597 allocate(lut488%nvalx(lut488%nsza,lut488%nvza,lut488%nraa,lut488%naot, &
598 lut488%nssa, lut488%nsfc), stat=status)
599 if (status /= 0)
then
600 print *,
"ERROR: Unable to allocate nvalx488 data array: ", status
604 dset_name =
'NVALX488'
605 status = nf90_inq_varid(grp_id, dset_name, dset_id)
606 if (status /= nf90_noerr)
then
607 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
610 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
611 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
612 err_msg = nf90_strerror(status)
613 if (status /= nf90_noerr)
then
614 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
619 lut488%nvalx = dimlen
620 if (status /= 0)
then
621 print *,
"ERROR: Unable to allocate SR488 data array: ", status
625 start6 = (/1,1,1,1,1,1/)
626 stride6 = (/1,1,1,1,1,1/)
627 edges6 = shape(lut488%nvalx)
628 status = nf90_get_var(grp_id, dset_id, lut488%nvalx , start=start6, &
629 stride=stride6, count=edges6)
630 err_msg = nf90_strerror(status)
631 if (status /= nf90_noerr)
then
632 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
639 dset_name =
'SZA672_Nodes'
640 status = nf90_inq_varid(grp_id, dset_name, dset_id)
641 if (status /= nf90_noerr)
then
642 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
645 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
646 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
647 err_msg = nf90_strerror(status)
648 if (status /= nf90_noerr)
then
649 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
655 allocate(lut672%sza(lut672%nsza), stat=status)
656 if (status /= 0)
then
657 print *,
"ERROR: Unable to allocate SZA672 data array: ", status
663 edges1 = (/lut672%nsza/)
664 status = nf90_get_var(grp_id, dset_id, lut672%sza, start=start1, &
665 stride=stride1, count=edges1)
666 err_msg = nf90_strerror(status)
667 if (status /= nf90_noerr)
then
668 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
672 dset_name =
'VZA672_Nodes'
673 status = nf90_inq_varid(grp_id, dset_name, dset_id)
674 if (status /= nf90_noerr)
then
675 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
678 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
679 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
680 err_msg = nf90_strerror(status)
681 if (status /= nf90_noerr)
then
682 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
688 allocate(lut672%vza(lut672%nvza), stat=status)
689 if (status /= 0)
then
690 print *,
"ERROR: Unable to allocate VZA672 data array: ", status
696 edges1 = (/lut672%nvza/)
697 status = nf90_get_var(grp_id, dset_id, lut672%vza, start=start1, &
698 stride=stride1, count=edges1)
699 err_msg = nf90_strerror(status)
700 if (status /= nf90_noerr)
then
701 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
705 dset_name =
'RAA672_Nodes'
706 status = nf90_inq_varid(grp_id, dset_name, dset_id)
707 if (status /= nf90_noerr)
then
708 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
711 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
712 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
713 err_msg = nf90_strerror(status)
714 if (status /= nf90_noerr)
then
715 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
721 allocate(lut672%raa(lut672%nraa), stat=status)
722 if (status /= 0)
then
723 print *,
"ERROR: Unable to allocate RAA672 data array: ", status
729 edges1 = (/lut672%nraa/)
730 status = nf90_get_var(grp_id, dset_id, lut672%raa, start=start1, &
731 stride=stride1, count=edges1)
732 err_msg = nf90_strerror(status)
733 if (status /= nf90_noerr)
then
734 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
738 dset_name =
'AOT672_Nodes'
739 status = nf90_inq_varid(grp_id, dset_name, dset_id)
740 if (status /= nf90_noerr)
then
741 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
744 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
745 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
746 err_msg = nf90_strerror(status)
747 if (status /= nf90_noerr)
then
748 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
754 allocate(lut672%aot(lut672%naot), stat=status)
755 if (status /= 0)
then
756 print *,
"ERROR: Unable to allocate AOT672 data array: ", status
762 edges1 = (/lut672%naot/)
763 status = nf90_get_var(grp_id, dset_id, lut672%aot, start=start1, &
764 stride=stride1, count=edges1)
765 err_msg = nf90_strerror(status)
766 if (status /= nf90_noerr)
then
767 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
771 dset_name =
'SSA672_Nodes'
772 status = nf90_inq_varid(grp_id, dset_name, dset_id)
773 if (status /= nf90_noerr)
then
774 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
777 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
778 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
779 err_msg = nf90_strerror(status)
780 if (status /= nf90_noerr)
then
781 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
787 allocate(lut672%ssa(lut672%nssa ), stat=status)
788 if (status /= 0)
then
789 print *,
"ERROR: Unable to allocate SSA672 data array: ", status
795 edges1 = (/lut672%nssa /)
796 status = nf90_get_var(grp_id, dset_id, lut672%ssa , start=start1, &
797 stride=stride1, count=edges1)
798 err_msg = nf90_strerror(status)
799 if (status /= nf90_noerr)
then
800 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
804 dset_name =
'SR672_Nodes'
805 status = nf90_inq_varid(grp_id, dset_name, dset_id)
806 if (status /= nf90_noerr)
then
807 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
810 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
811 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
812 err_msg = nf90_strerror(status)
813 if (status /= nf90_noerr)
then
814 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
820 allocate(lut672%sfc(lut672%nsfc ), stat=status)
821 if (status /= 0)
then
822 print *,
"ERROR: Unable to allocate SR672 data array: ", status
828 edges1 = (/lut672%nsfc /)
829 status = nf90_get_var(grp_id, dset_id, lut672%sfc , start=start1, &
830 stride=stride1, count=edges1)
831 err_msg = nf90_strerror(status)
832 if (status /= nf90_noerr)
then
833 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
837 allocate(lut672%nvalx(lut672%nsza,lut672%nvza,lut672%nraa,lut672%naot,lut672%nssa, &
838 lut672%nsfc), stat=status)
839 if (status /= 0)
then
840 print *,
"ERROR: Unable to allocate nvalx672 data array: ", status
844 dset_name =
'NVALX672'
845 status = nf90_inq_varid(grp_id, dset_name, dset_id)
846 if (status /= nf90_noerr)
then
847 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
850 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
851 status = nf90_inquire_dimension(grp_id, dimids(1), len = dimlen)
852 err_msg = nf90_strerror(status)
853 if (status /= nf90_noerr)
then
854 print *,
"ERROR: Unable to get info on SDS "//
trim(dset_name)//
": ", status
859 lut672%nvalx = dimlen
860 if (status /= 0)
then
861 print *,
"ERROR: Unable to allocate SR672 data array: ", status
865 start6 = (/1,1,1,1,1,1/)
866 stride6 = (/1,1,1,1,1,1/)
867 edges6 = shape(lut672%nvalx)
868 status = nf90_get_var(grp_id, dset_id, lut672%nvalx , start=start6, &
869 stride=stride6, count=edges6)
870 err_msg = nf90_strerror(status)
871 if (status /= nf90_noerr)
then
872 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
876 status = nf90_close(nc_id)
877 if (status /= nf90_noerr)
then
878 print *,
"ERROR: Failed to close lut_nc4 file: ", status
883 end function read_aerosol_lut_file
891 subroutine aero_470(dflag, refl, x1, x2, x3, mm, nn, ll, ma, imod, &
892 & r470, tau_x470, tau_x470_flag, trflg, model_frac, debug)
896 logical,
intent(inout) :: dflag
897 real,
intent(in) :: refl
898 real,
intent(in) :: x1
899 real,
intent(in) :: x2
900 real,
intent(in) :: x3
901 integer,
intent(in) :: mm
902 integer,
intent(in) :: nn
903 integer,
intent(in) :: ll
904 integer,
intent(in) :: ma
905 integer,
intent(in) :: imod
906 real,
intent(in) :: r470
907 real,
intent(inout) :: tau_x470
908 integer,
intent(inout) :: tau_x470_flag
909 real,
intent(inout) :: trflg
910 real,
intent(in) :: model_frac
911 logical,
intent(in) :: debug
913 real,
dimension(:),
allocatable :: yy
914 real,
dimension(8) :: yy2
924 status = default_lut488%naot
926 if (
allocated(yy))
deallocate(yy)
927 allocate(yy(default_lut488%naot), stat=status)
928 if (status /= 0)
then
929 print *,
"ERROR: Failed to allocate array for reduced AOT 488 table: ", status
933 status = create_reduced_lut_aot(default_lut488, refl, x1,x2,x3, imod, &
934 & r470, model_frac, yy, debug)
935 if (status /= 0)
then
936 deallocate(yy, stat=status)
941 if (refl <= yy(1))
then
943 if (trflg > 0.0) tau_x470 = 0.02
945 if (debug) print *,
'aero_470, hit low bound: ', refl, yy(1)
950 if (refl >= yy(
size(yy)))
then
951 tau_x470 = extrap(refl, yy, default_lut488%aot(1:default_lut488%naot), status)
952 if (status /= 0)
then
953 if (status == 1)
then
956 print *,
'ERROR: Failed to extrapolate AOT: ', status
960 if (tau_x470 > 5.0) tau_x470 = 5.0
962 if (debug) print *,
'aero_470, hit hi bound: ', refl, yy(10)
963 deallocate(yy, stat=status)
971 if (yy(1) < yy(2))
go to 650
973 if (refl < yy(4))
return
978 if (yy2(2) < yy2(1))
return
980 ii =
search(refl, yy2, status, frac=frac)
981 if (status /= 0)
then
986 tau_x470 = frac*default_lut488%aot(ii+1+3) + (1.-frac)*default_lut488%aot(ii+3)
996 ii =
search(refl, yy, status, frac=frac)
997 if (status /= 0)
then
1002 tau_x470 = frac*default_lut488%aot(ii+1) + (1.-frac)*default_lut488%aot(ii)
1007 deallocate(yy, stat=status)
1008 if (status /= 0)
then
1009 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1019 subroutine aero_650(dflag,refl,x1,x2,x3,mm,nn,ll,ma,r650,tau_x650, &
1020 & tau_x650_flag,tau_x470_flag,tau_x412,tau_x470,tau_x412_flag_91,trflg)
1023 logical,
intent(inout) :: dflag
1024 real,
intent(in) :: refl
1025 real,
intent(in) :: x1
1026 real,
intent(in) :: x2
1027 real,
intent(in) :: x3
1028 integer,
intent(in) :: mm
1029 integer,
intent(in) :: nn
1030 integer,
intent(in) :: ll
1031 integer,
intent(in) :: ma
1032 real,
intent(in) :: r650
1033 real,
intent(inout) :: tau_x650
1034 integer,
intent(inout) :: tau_x650_flag
1035 integer,
intent(in) :: tau_x470_flag
1036 real,
intent(in) :: tau_x412
1037 real,
intent(in) :: tau_x470
1038 integer,
intent(in) :: tau_x412_flag_91
1039 real,
intent(in) :: trflg
1042 real,
dimension(:),
allocatable :: yy
1043 real,
dimension(8) :: yy2
1044 real,
dimension(4) :: yy3
1045 real,
dimension(6) :: yy5
1054 tau_x650_flag = -999
1058 if (
allocated(yy))
deallocate(yy)
1059 allocate(yy(default_lut672%naot), stat=status)
1060 if (status /= 0)
then
1061 print *,
"ERROR: Failed to allocate array for reduced AOT 672 table: ", status
1065 status = create_reduced_lut_aot(default_lut672, refl, x1,x2,x3, 1, &
1066 & r650, 1.0, yy, debug)
1067 if (status /= 0)
then
1068 deallocate(yy, stat=status)
1073 if (refl <= yy(1) .and. yy(1) < yy(2))
then
1075 if (trflg > 0.0) tau_x650 = 0.02
1081 if (refl >= yy(10))
then
1082 tau_x650 = extrap(refl, yy, default_lut672%aot(1:default_lut672%naot), status)
1083 if (status /= 0)
then
1084 if (status == 1)
then
1087 print *,
'ERROR: Failed to extrapolate AOT: ', status
1091 if (tau_x650 > 5.0) tau_x650 = 5.0
1094 deallocate(yy, stat=status)
1099 if (refl >= yy(7))
then
1102 if (yy3(2) < yy3(1))
return
1104 ii =
search(refl, yy3, status, frac=frac)
1105 if (status /= 0)
then
1110 tau_x650 = frac*default_lut672%aot(ii+1+6) + (1.-frac)*default_lut672%aot(ii+6)
1112 deallocate(yy, stat=status)
1124 if (yy(1) < yy(2))
go to 650
1126 if (refl < yy(4))
return
1130 if (yy2(2) < yy2(1))
return
1132 ii =
search(refl, yy2, status, frac=frac)
1133 if (status /= 0)
then
1138 tau_x650 = frac*default_lut672%aot(ii+1+3) + (1.-frac)*default_lut672%aot(ii+3)
1157 if (refl < yy(5))
return
1161 if (yy5(2) < yy5(1))
return
1163 ii =
search(refl, yy5, status, frac=frac)
1164 if (status /= 0)
then
1170 tau_x650 = frac*default_lut672%aot(ii+1+4) + (1.-frac)*default_lut672%aot(ii+4)
1179 ii =
search(refl, yy, status, frac=frac)
1180 if (status /= 0)
then
1186 tau_x650 = frac*default_lut672%aot(ii+1) + (1.-frac)*default_lut672%aot(ii)
1189 deallocate(yy, stat=status)
1190 if (status /= 0)
then
1191 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1203 subroutine aero_412(dflag,refl,x1,x2,x3,mm,nn,ll,ma,imod,r412, &
1204 & tau_x412,tau_x412_flag,trflg,model_frac,debug)
1209 logical,
intent(inout) :: dflag
1210 real,
intent(in) :: refl
1211 real,
intent(in) :: x1
1212 real,
intent(in) :: x2
1213 real,
intent(in) :: x3
1214 integer,
intent(in) :: mm
1215 integer,
intent(in) :: nn
1216 integer,
intent(in) :: ll
1217 integer,
intent(in) :: ma
1218 integer,
intent(in) :: imod
1219 real,
intent(in) :: r412
1220 real,
intent(inout) :: tau_x412
1221 integer,
intent(inout) :: tau_x412_flag
1222 real,
intent(in) :: trflg
1223 real,
intent(in) :: model_frac
1224 logical,
intent(in) :: debug
1226 real,
dimension(:),
allocatable :: yy
1227 real,
dimension(8) :: yy2
1235 tau_x412_flag = -999
1237 if (
allocated(yy))
deallocate(yy)
1238 allocate(yy(default_lut412%naot), stat=status)
1239 if (status /= 0)
then
1240 print *,
"ERROR: Failed to allocate array for reduced AOT 412 table: ", status
1244 status = create_reduced_lut_aot(default_lut412, refl, x1,x2,x3, imod, &
1245 & r412, model_frac, yy, debug)
1246 if (status /= 0)
then
1247 deallocate(yy, stat=status)
1252 if (refl <= yy(1))
then
1254 if (trflg > 0.0) tau_x412 = 0.02
1256 if (debug) print *,
'aero_412, hit low bound: ', refl, yy(1)
1261 if (refl >= yy(10))
then
1262 tau_x412 = extrap(refl, yy, default_lut412%aot(1:default_lut412%naot), status)
1263 if (status /= 0)
then
1264 if (status == 1)
then
1267 print *,
'ERROR: Failed to extrapolate AOT: ', status
1271 if (tau_x412 > 5.0) tau_x412 = 5.0
1274 if (debug) print *,
'aero_412, hit hi bound: ', refl, yy(10)
1275 deallocate(yy, stat=status)
1281 if (yy(1) < yy(2))
go to 650
1283 if (refl < yy(4))
return
1288 if (yy2(2) < yy2(1))
return
1290 ii =
search(refl, yy2, status, frac=frac)
1291 if (status /= 0)
then
1296 tau_x412 = frac*default_lut412%aot(ii+1+3) + (1.0-frac)*default_lut412%aot(ii+3)
1305 ii =
search(refl, yy, status, frac=frac)
1306 if (status /= 0)
then
1311 tau_x412 = frac*default_lut412%aot(ii+1) + (1.-frac)*default_lut412%aot(ii)
1315 deallocate(yy, stat=status)
1316 if (status /= 0)
then
1317 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1325 subroutine aero_412_abs(dflag,refl,x1,x2,x3,mm,nn,ll,r412,tau_x,w0_x)
1328 logical,
intent(inout) :: dflag
1329 real,
intent(in) :: refl
1330 real,
intent(in) :: x1
1331 real,
intent(in) :: x2
1332 real,
intent(in) :: x3
1333 integer,
intent(in) :: mm
1334 integer,
intent(in) :: nn
1335 integer,
intent(in) :: ll
1336 real,
intent(in) :: r412
1337 real,
intent(in) :: tau_x
1338 real,
intent(inout) :: w0_x
1340 integer :: index_ii, index_ia
1341 real :: frac, frac_ia
1344 real,
dimension(:,:,:,:),
allocatable :: nnvalxw
1345 real,
dimension(:),
allocatable :: yyw
1349 if (
allocated(nnvalxw))
deallocate(nnvalxw, yyw)
1350 allocate(nnvalxw(4,4,2,default_lut412%nssa), yyw(default_lut412%nssa), stat=status)
1351 if (status /= 0)
then
1352 print *,
"ERROR: Failed to allocate arrays: ", status
1357 index_ia =
search(tau_x, default_lut412%aot, status, frac=frac_ia)
1358 if (status /= 0)
then
1363 status = create_reduced_lut_ssa(default_lut412, refl, x1, x2, x3, index_ia, &
1364 & r412, frac_ia, yyw)
1365 if (status /= 0)
then
1370 if (refl.le.yyw(1))
then
1375 if (refl.ge.yyw(8))
then
1380 index_ii =
search(refl, yyw, status, frac=frac)
1381 if (status /= 0)
then
1385 w0_x = frac*default_lut412%ssa(index_ii+1) + (1.-frac)*default_lut412%ssa(index_ii)
1387 deallocate(nnvalxw, yyw, stat=status)
1388 if (status /= 0)
then
1389 print *,
"WARNING: Failed to deallocate arrays: ", status
1398 subroutine aero_470_abs(dflag2,refl,x1,x2,x3,mm,nn,ll,r470,tau_x,w0_x)
1401 logical,
intent(inout) :: dflag2
1402 real,
intent(in) :: refl
1403 real,
intent(in) :: x1
1404 real,
intent(in) :: x2
1405 real,
intent(in) :: x3
1406 integer,
intent(in) :: mm
1407 integer,
intent(in) :: nn
1408 integer,
intent(in) :: ll
1409 real,
intent(in) :: r470
1410 real,
intent(in) :: tau_x
1411 real,
intent(inout) :: w0_x
1413 integer :: index_ii, index_ia
1414 real :: frac, frac_ia
1417 real,
dimension(:,:,:,:),
allocatable :: nnvalxw
1418 real,
dimension(:),
allocatable :: yyw
1422 if (
allocated(nnvalxw))
deallocate(nnvalxw, yyw)
1423 allocate(nnvalxw(4,4,2,default_lut488%nssa), yyw(default_lut488%nssa), stat=status)
1424 if (status /= 0)
then
1425 print *,
"ERROR: Failed to allocate arrays: ", status
1430 index_ia =
search(tau_x, default_lut488%aot, status, frac=frac_ia)
1431 if (status /= 0)
then
1436 status = create_reduced_lut_ssa(default_lut488, refl, x1, x2, x3, index_ia, &
1437 & r470, frac_ia, yyw)
1438 if (status /= 0)
then
1443 if (refl.le.yyw(1))
then
1448 if (refl.ge.yyw(4))
then
1453 index_ii =
search(refl, yyw, status, frac=frac)
1454 if (status /= 0)
then
1458 w0_x = frac*default_lut488%ssa(index_ii+1) + (1.-frac)*default_lut488%ssa(index_ii)
1460 deallocate(nnvalxw, yyw, stat=status)
1461 if (status /= 0)
then
1462 print *,
"WARNING: Failed to deallocate arrays: ", status
1475 subroutine aero_470_dust(dflag, refl, x1, x2, x3, mm, nn, ll, ma, imod, &
1476 & r470, tau_x470, tau_x470_flag, trflg, model_frac, debug)
1480 logical,
intent(inout) :: dflag
1481 real,
intent(in) :: refl
1482 real,
intent(in) :: x1
1483 real,
intent(in) :: x2
1484 real,
intent(in) :: x3
1485 integer,
intent(in) :: mm
1486 integer,
intent(in) :: nn
1487 integer,
intent(in) :: ll
1488 integer,
intent(in) :: ma
1489 integer,
intent(in) :: imod
1490 real,
intent(in) :: r470
1491 real,
intent(inout) :: tau_x470
1492 integer,
intent(inout) :: tau_x470_flag
1493 real,
intent(inout) :: trflg
1494 real,
intent(in) :: model_frac
1495 logical,
intent(in) :: debug
1497 real,
dimension(:),
allocatable :: yy
1498 real,
dimension(8) :: yy2
1506 tau_x470_flag = -999
1508 if (
allocated(yy))
deallocate(yy)
1509 allocate(yy(dust_lut488%naot), stat=status)
1510 if (status /= 0)
then
1511 print *,
"ERROR: Failed to allocate array for reduced AOT DUST 488 table: ", status
1515 status = create_reduced_lut_aot(dust_lut488, refl, x1,x2,x3, imod, &
1516 & r470, model_frac, yy, debug)
1517 if (status /= 0)
then
1518 deallocate(yy, stat=status)
1523 if (refl <= yy(1))
then
1525 if (trflg > 0.0) tau_x470 = 0.02
1527 if (debug) print *,
'aero_470_dust, hit low bound: ', refl, yy(1)
1532 if (refl >= yy(
size(yy)))
then
1533 tau_x470 = extrap(refl, yy, dust_lut488%aot(1:dust_lut488%naot), status)
1534 if (status /= 0)
then
1535 if (status == 1)
then
1538 print *,
'ERROR: Failed to extrapolate AOT: ', status
1542 if (tau_x470 > 5.0) tau_x470 = 5.0
1544 if (debug) print *,
'aero_470_dust, hit hi bound: ', refl, yy(10)
1545 deallocate(yy, stat=status)
1553 if (yy(1) < yy(2))
go to 650
1555 if (refl < yy(4))
return
1560 if (yy2(2) < yy2(1))
return
1562 ii =
search(refl, yy2, status, frac=frac)
1563 if (status /= 0)
then
1568 tau_x470 = frac*dust_lut488%aot(ii+1+3) + (1.-frac)*dust_lut488%aot(ii+3)
1570 if (debug) print *,
'aero_470_dust, exit 2358, aot: ', tau_x470
1578 ii =
search(refl, yy, status, frac=frac)
1579 if (status /= 0)
then
1584 tau_x470 = frac*dust_lut488%aot(ii+1) + (1.-frac)*dust_lut488%aot(ii)
1586 if (debug) print *,
'aero_470_dust, exit 2371, aot: ', tau_x470
1589 deallocate(yy, stat=status)
1590 if (status /= 0)
then
1591 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1600 subroutine aero_650_dust(dflag,refl,x1,x2,x3,mm,nn,ll,ma,r650,tau_x650, &
1601 & tau_x650_flag,tau_x470_flag,tau_x412,tau_x470,tau_x412_flag_91,trflg)
1604 logical,
intent(inout) :: dflag
1605 real,
intent(in) :: refl
1606 real,
intent(in) :: x1
1607 real,
intent(in) :: x2
1608 real,
intent(in) :: x3
1609 integer,
intent(in) :: mm
1610 integer,
intent(in) :: nn
1611 integer,
intent(in) :: ll
1612 integer,
intent(in) :: ma
1613 real,
intent(in) :: r650
1614 real,
intent(inout) :: tau_x650
1615 integer,
intent(inout) :: tau_x650_flag
1616 integer,
intent(in) :: tau_x470_flag
1617 real,
intent(in) :: tau_x412
1618 real,
intent(in) :: tau_x470
1619 integer,
intent(in) :: tau_x412_flag_91
1620 real,
intent(in) :: trflg
1623 real,
dimension(:),
allocatable :: yy
1624 real,
dimension(8) :: yy2
1625 real,
dimension(4) :: yy3
1626 real,
dimension(6) :: yy5
1635 tau_x650_flag = -999
1639 if (
allocated(yy))
deallocate(yy)
1640 allocate(yy(dust_lut672%naot), stat=status)
1641 if (status /= 0)
then
1642 print *,
"ERROR: Failed to allocate array for reduced AOT DUST 672 table: ", status
1646 status = create_reduced_lut_aot(dust_lut672, refl, x1,x2,x3, 1, &
1647 & r650, 1.0, yy, debug)
1648 if (status /= 0)
then
1649 deallocate(yy, stat=status)
1654 if (refl <= yy(1) .and. yy(1) < yy(2))
then
1656 if (trflg > 0.0) tau_x650 = 0.02
1662 if (refl >= yy(10))
then
1663 tau_x650 = extrap(refl, yy, dust_lut672%aot(1:dust_lut672%naot), status)
1664 if (status /= 0)
then
1665 if (status == 1)
then
1668 print *,
'ERROR: Failed to extrapolate AOT: ', status
1672 if (tau_x650 > 5.0) tau_x650 = 5.0
1675 deallocate(yy, stat=status)
1680 if (refl >= yy(7))
then
1683 if (yy3(2) < yy3(1))
return
1685 ii =
search(refl, yy3, status, frac=frac)
1686 if (status /= 0)
then
1691 tau_x650 = frac*dust_lut672%aot(ii+1+6) + (1.-frac)*dust_lut672%aot(ii+6)
1705 if (yy(1) < yy(2))
go to 650
1707 if (refl < yy(4))
return
1711 if (yy2(2) < yy2(1))
return
1713 ii =
search(refl, yy2, status, frac=frac)
1714 if (status /= 0)
then
1719 tau_x650 = frac*dust_lut672%aot(ii+1+3) + (1.-frac)*dust_lut672%aot(ii+3)
1738 if (refl < yy(5))
return
1742 if (yy5(2) < yy5(1))
return
1744 ii =
search(refl, yy5, status, frac=frac)
1745 if (status /= 0)
then
1751 tau_x650 = frac*dust_lut672%aot(ii+1+4) + (1.-frac)*dust_lut672%aot(ii+4)
1760 ii =
search(refl, yy, status, frac=frac)
1761 if (status /= 0)
then
1767 tau_x650 = frac*dust_lut672%aot(ii+1) + (1.-frac)*dust_lut672%aot(ii)
1770 deallocate(yy, stat=status)
1771 if (status /= 0)
then
1772 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1784 subroutine aero_412_dust(dflag,refl,x1,x2,x3,mm,nn,ll,ma,imod,r412, &
1785 & tau_x412,tau_x412_flag,trflg,model_frac,debug)
1790 logical,
intent(inout) :: dflag
1791 real,
intent(in) :: refl
1792 real,
intent(in) :: x1
1793 real,
intent(in) :: x2
1794 real,
intent(in) :: x3
1795 integer,
intent(in) :: mm
1796 integer,
intent(in) :: nn
1797 integer,
intent(in) :: ll
1798 integer,
intent(in) :: ma
1799 integer,
intent(in) :: imod
1800 real,
intent(in) :: r412
1801 real,
intent(inout) :: tau_x412
1802 integer,
intent(inout) :: tau_x412_flag
1803 real,
intent(in) :: trflg
1804 real,
intent(in) :: model_frac
1805 logical,
intent(in) :: debug
1807 real,
dimension(:),
allocatable :: yy
1808 real,
dimension(8) :: yy2
1816 tau_x412_flag = -999
1818 if (
allocated(yy))
deallocate(yy)
1819 allocate(yy(dust_lut412%naot), stat=status)
1820 if (status /= 0)
then
1821 print *,
"ERROR: Failed to allocate array for reduced AOT DUST 412 table: ", status
1825 status = create_reduced_lut_aot(dust_lut412, refl, x1,x2,x3, imod, &
1826 & r412, model_frac, yy, debug)
1827 if (status /= 0)
then
1828 deallocate(yy, stat=status)
1833 if (refl <= yy(1))
then
1835 if (trflg > 0.0) tau_x412 = 0.02
1837 if (debug) print *,
'aero_412_dust, hit low bound: ', refl, yy(1)
1842 if (refl >= yy(10))
then
1843 tau_x412 = extrap(refl, yy, dust_lut412%aot(1:dust_lut412%naot), status)
1844 if (status /= 0)
then
1845 if (status == 1)
then
1848 print *,
'ERROR: Failed to extrapolate AOT: ', status
1852 if (tau_x412 > 5.0) tau_x412 = 5.0
1855 if (debug) print *,
'aero_412_dust, hit hi bound: ', refl, yy(10)
1856 deallocate(yy, stat=status)
1862 if (yy(1) < yy(2))
go to 650
1864 if (refl < yy(4))
return
1869 if (yy2(2) < yy2(1))
return
1871 ii =
search(refl, yy2, status, frac=frac)
1872 if (status /= 0)
then
1877 tau_x412 = frac*dust_lut412%aot(ii+1+3) + (1.0-frac)*dust_lut412%aot(ii+3)
1879 if (debug) print *,
'aero_412_dust, exit 2355, aot: ', tau_x412
1886 ii =
search(refl, yy, status, frac=frac)
1887 if (status /= 0)
then
1892 tau_x412 = frac*dust_lut412%aot(ii+1) + (1.-frac)*dust_lut412%aot(ii)
1894 if (debug) print *,
'aero_412_dust, exit 2367, aot: ', tau_x412, refl
1896 deallocate(yy, stat=status)
1897 if (status /= 0)
then
1898 print *,
"WARNING: Failed to deallocate reduced AOT table: ", status
1906 subroutine aero_412_abs_dust(dflag,refl,x1,x2,x3,mm,nn,ll,r412,tau_x,w0_x)
1909 logical,
intent(inout) :: dflag
1910 real,
intent(in) :: refl
1911 real,
intent(in) :: x1
1912 real,
intent(in) :: x2
1913 real,
intent(in) :: x3
1914 integer,
intent(in) :: mm
1915 integer,
intent(in) :: nn
1916 integer,
intent(in) :: ll
1917 real,
intent(in) :: r412
1918 real,
intent(in) :: tau_x
1919 real,
intent(inout) :: w0_x
1921 integer :: index_ii, index_ia
1922 real :: frac, frac_ia
1925 real,
dimension(:,:,:,:),
allocatable :: nnvalxw
1926 real,
dimension(:),
allocatable :: yyw
1930 if (
allocated(nnvalxw))
deallocate(nnvalxw, yyw)
1931 allocate(nnvalxw(4,4,2,dust_lut412%nssa), yyw(dust_lut412%nssa), stat=status)
1932 if (status /= 0)
then
1933 print *,
"ERROR: Failed to allocate arrays: ", status
1938 index_ia =
search(tau_x, dust_lut412%aot, status, frac=frac_ia)
1939 if (status /= 0)
then
1944 status = create_reduced_lut_ssa(dust_lut412, refl, x1, x2, x3, index_ia, &
1945 & r412, frac_ia, yyw)
1946 if (status /= 0)
then
1951 if (refl.le.yyw(1))
then
1956 if (refl.ge.yyw(8))
then
1961 index_ii =
search(refl, yyw, status, frac=frac)
1962 if (status /= 0)
then
1966 w0_x = frac*dust_lut412%ssa(index_ii+1) + (1.-frac)*dust_lut412%ssa(index_ii)
1968 deallocate(nnvalxw, yyw, stat=status)
1969 if (status /= 0)
then
1970 print *,
"WARNING: Failed to deallocate arrays: ", status
1979 subroutine aero_470_abs_dust(dflag2,refl,x1,x2,x3,mm,nn,ll,r470,tau_x,w0_x)
1982 logical,
intent(inout) :: dflag2
1983 real,
intent(in) :: refl
1984 real,
intent(in) :: x1
1985 real,
intent(in) :: x2
1986 real,
intent(in) :: x3
1987 integer,
intent(in) :: mm
1988 integer,
intent(in) :: nn
1989 integer,
intent(in) :: ll
1990 real,
intent(in) :: r470
1991 real,
intent(in) :: tau_x
1992 real,
intent(inout) :: w0_x
1994 integer :: index_ii, index_ia
1995 real :: frac, frac_ia
1998 real,
dimension(:,:,:,:),
allocatable :: nnvalxw
1999 real,
dimension(:),
allocatable :: yyw
2003 if (
allocated(nnvalxw))
deallocate(nnvalxw, yyw)
2004 allocate(nnvalxw(4,4,2,dust_lut488%nssa), yyw(dust_lut488%nssa), stat=status)
2005 if (status /= 0)
then
2006 print *,
"ERROR: Failed to allocate arrays: ", status
2011 index_ia =
search(tau_x, dust_lut488%aot, status, frac=frac_ia)
2012 if (status /= 0)
then
2017 status = create_reduced_lut_ssa(dust_lut488, refl, x1, x2, x3, index_ia, &
2018 & r470, frac_ia, yyw)
2019 if (status /= 0)
then
2024 if (refl.le.yyw(1))
then
2029 if (refl.ge.yyw(4))
then
2034 index_ii =
search(refl, yyw, status, frac=frac)
2035 if (status /= 0)
then
2039 w0_x = frac*dust_lut488%ssa(index_ii+1) + (1.-frac)*dust_lut488%ssa(index_ii)
2041 deallocate(nnvalxw, yyw, stat=status)
2042 if (status /= 0)
then
2043 print *,
"WARNING: Failed to deallocate arrays: ", status
2052 integer function create_reduced_lut_aot(lut, refl, sza, vza, raa, imod, &
2053 & rXXX, model_frac, yy, debug)
result(status)
2057 type(viirs_aerosol_lut) :: lut
2058 real,
intent(in) :: refl
2059 real,
intent(in) :: sza
2060 real,
intent(in) :: vza
2061 real,
intent(in) :: raa
2062 integer,
intent(in) :: imod
2063 real,
intent(in) :: rxxx
2064 real,
intent(in) :: model_frac
2065 real,
intent(inout),
dimension(:) :: yy
2066 logical,
intent(in),
optional :: debug
2068 real,
dimension(:,:,:,:),
allocatable :: nnvalx, nnvalx1, nnvalx2
2070 integer :: index_ii, ii, jj, mbeg, nbeg
2072 real :: frac, xfrac, y, dy
2074 real,
parameter ::
pi = 3.14159
2080 if (rxxx < 0.0)
return
2082 index_ii =
search(rxxx, lut%sfc, status, frac=frac)
2083 if (status /= 0)
then
2088 ii =
search(raa, lut%raa, status, frac=xfrac)
2089 if (status /= 0)
then
2094 mbeg =
search(sza, lut%sza, status)
2095 if (status /= 0)
then
2096 print *,
'ERROR: Specified SZA not within table: ', sza, lut%sza(1), lut%sza(lut%nsza)
2099 mbeg =
max(0, mbeg-2)
2100 if (mbeg > lut%nsza-4) mbeg = lut%nsza - 4
2102 nbeg =
search(vza, lut%vza, status)
2103 if (status /= 0)
then
2104 print *,
'ERROR: Specified VZA not within table: ', vza, lut%vza(1), lut%vza(lut%nvza)
2107 nbeg =
max(0, nbeg-2)
2108 if (nbeg > lut%nvza-4) nbeg = lut%nvza - 4
2113 if (
allocated(nnvalx))
deallocate(nnvalx, nnvalx1, nnvalx2)
2114 allocate(nnvalx(4,4,2,lut%naot), nnvalx1(4,4,2,lut%naot), &
2115 & nnvalx2(4,4,2,lut%naot), stat=status)
2116 if (status /= 0)
then
2117 print *,
"ERROR: Failed to allocate reduced LUT arrays: ", status
2121 if (imod < lut%nssa)
then
2122 nnvalx1(:,:,:,:) = -999.0
2123 nnvalx2(:,:,:,:) = -999.0
2127 nnvalx1(i,j,1,ia) = lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod,index_ii)* &
2128 & (1.0-frac) + lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod,index_ii+1)*frac
2129 nnvalx1(i,j,2,ia) = lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod,index_ii)* &
2130 & (1.0-frac) + lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod,index_ii+1)*frac
2132 nnvalx2(i,j,1,ia) = lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod+1,index_ii)* &
2133 & (1.0-frac) + lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod+1,index_ii+1)*frac
2134 nnvalx2(i,j,2,ia) = lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod+1,index_ii)* &
2135 & (1.0-frac) + lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod+1,index_ii+1)*frac
2137 nnvalx(i,j,1,ia) = (1.0-model_frac) * nnvalx1(i,j,1,ia) + &
2138 & model_frac * nnvalx2(i,j,1,ia)
2139 nnvalx(i,j,2,ia) = (1.0-model_frac) * nnvalx1(i,j,2,ia) + &
2140 & model_frac * nnvalx2(i,j,2,ia)
2147 nnvalx(:,:,:,:) = -999.0
2151 nnvalx(i,j,1,ia) = lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod,index_ii)* &
2152 & (1.-frac) + lut%nvalx(mbeg+i,nbeg+j,ii,ia,imod,index_ii+1)*frac
2153 nnvalx(i,j,2,ia) = lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod,index_ii)* &
2154 & (1.-frac) + lut%nvalx(mbeg+i,nbeg+j,ii+1,ia,imod,index_ii+1)*frac
2163 call new_intep(lut%sza, lut%vza, lut%raa, nnvalx, lut%nsza, lut%nvza, lut%nraa, ia, &
2164 & sza,vza,raa,y,dy,mbeg,nbeg,xfrac)
2170 deallocate(nnvalx, nnvalx1, nnvalx2, stat=status)
2171 if (status /= 0)
then
2172 print *,
"WARNING: Failed to deallocate reduced LUT arrays: ", status
2177 end function create_reduced_lut_aot
2180 integer function create_reduced_lut_ssa(lut, refl, sza, vza, raa, index_ia, &
2181 & rXXX, aot_frac, yy, debug)
result(status)
2184 type(viirs_aerosol_lut) :: lut
2185 real,
intent(in) :: refl
2186 real,
intent(in) :: sza
2187 real,
intent(in) :: vza
2188 real,
intent(in) :: raa
2189 integer,
intent(in) :: index_ia
2190 real,
intent(in) :: rxxx
2191 real,
intent(in) :: aot_frac
2192 real,
intent(inout),
dimension(:) :: yy
2193 logical,
intent(in),
optional:: debug
2195 real,
dimension(:,:,:,:),
allocatable :: nnvalx
2197 real,
parameter ::
pi = 3.14159
2199 integer :: index_ii, ii, mbeg, nbeg
2201 real :: frac, xfrac, y, dy
2205 index_ii =
search(rxxx, lut%sfc, status, frac=frac)
2206 if (status /= 0)
then
2207 print *,
"ERROR: Failed to get interpolation index for surface: ", rxxx, status
2211 ii =
search(raa, lut%raa, status, frac=xfrac)
2212 if (status /= 0)
then
2213 print *,
"ERROR: Failed to get interpolation index for RAA: ", raa, status
2217 mbeg =
search(sza, lut%sza, status)
2218 if (status /= 0)
then
2219 print *,
"ERROR: Failed to get interpolation index for SZA: ", sza, status
2222 mbeg =
max(0, mbeg-2)
2223 if (mbeg > lut%nsza-4) mbeg = lut%nsza - 4
2225 nbeg =
search(vza, lut%vza, status)
2226 if (status /= 0)
then
2227 print *,
"ERROR: Failed to get interpolation index for VZA: ", vza, status
2230 nbeg =
max(0, nbeg-2)
2231 if (nbeg > lut%nvza-4) nbeg = lut%nvza - 4
2234 if (
allocated(nnvalx))
deallocate(nnvalx)
2235 allocate(nnvalx(4,4,2,lut%nssa), stat=status)
2236 if (status /= 0)
then
2237 print *,
"ERROR: Failed to allocate nnvalx or yy array: ", status
2244 dd1 = lut%nvalx(mbeg+i,nbeg+j,ii,index_ia,iw,index_ii)* &
2246 & lut%nvalx(mbeg+i,nbeg+j,ii,index_ia,iw,index_ii+1)*frac
2247 dd2= lut%nvalx(mbeg+i,nbeg+j,ii,index_ia+1,iw,index_ii)* &
2249 & lut%nvalx(mbeg+i,nbeg+j,ii,index_ia+1,iw,index_ii+1) &
2252 nnvalx(i,j,1,iw) = dd1* (1.-aot_frac) + dd2*aot_frac
2254 dd1 = lut%nvalx(mbeg+i,nbeg+j,ii+1,index_ia,iw,index_ii)*&
2256 & lut%nvalx(mbeg+i,nbeg+j,ii+1,index_ia,iw,index_ii+1)*frac
2257 dd2= lut%nvalx(mbeg+i,nbeg+j,ii+1,index_ia+1,iw,index_ii)*&
2259 & lut%nvalx(mbeg+i,nbeg+j,ii+1,index_ia+1,iw,index_ii+1) &
2262 nnvalx(i,j,2,iw) = dd1* (1.-aot_frac) + dd2*aot_frac
2270 call new_intep(lut%sza, lut%vza, lut%raa, nnvalx, &
2271 & lut%nsza, lut%nvza, lut%nraa, iw, sza,vza,raa,y, &
2272 & dy,mbeg,nbeg,xfrac)
2277 end function create_reduced_lut_ssa
2280 integer function search(xbar,x,status,frac)
result(i)
2297 real,
intent(in) :: xbar
2298 real,
dimension(:),
intent(in) :: x
2299 integer,
intent(inout) :: status
2300 real,
intent(inout),
optional :: frac
2306 real,
parameter :: b = 0.69314718
2313 print *,
"Search n is less than 2."
2317 if (x(1) > x(2))
then
2318 print *,
"Search table is not in increasing order."
2323 m = int((log(float(n)))/b)
2330 if (k == 0) icnt = icnt + 1
2335 if (xbar >= x(i) .AND. xbar < x(i+1))
then
2339 if (xbar > x(i))
then
2353 if (icnt >= 2 .OR. status /= 0)
then
2355 if (xbar >= x(i) .AND. xbar <= x(i+1))
then
2363 if (status == 0 .AND.
present(frac))
then
2365 frac = (xbar-x(i))/ (x(i+1)-x(i))
2377 real function extrap(x, xx, yy, status) result(res)
2380 real,
intent(in) :: x
2381 real,
dimension(:),
intent(in) :: xx
2382 real,
dimension(:),
intent(in) :: yy
2383 integer,
intent(out) :: status
2385 real,
dimension(2) :: r
2392 status = linfit(xx(n-1:n), yy(n-1:n), r)
2393 if (status /= 0)
then
2394 print *,
"ERROR: linfit failed, skipping: ", status
2398 res = r(1) + (x)*r(2)
2404 do while (res < 3.5 .AND. i >= 2)
2405 status = linfit(xx(i-1:i), yy(i-1:i), r)
2406 if (status /= 0)
then
2407 print *,
"ERROR: linfit failed, skipping: ", status
2411 res = r(1) + (x)*r(2)
2425 integer function linfit(x, y, r)
result(status)
2428 real,
dimension(:),
intent(in) :: x
2429 real,
dimension(:),
intent(in) :: y
2430 real,
dimension(2),
intent(inout) :: r
2433 real :: sxx, syy, sxy
2445 sxx = sxx + (x(i) * x(i))
2446 sxy = sxy + (x(i) * y(i))
2447 syy = syy + (y(i) * y(i))
2450 r(2) = ((n*sxy) - (sx*sy))/((n*sxx)-(sx*sx))
2451 r(1) = (sy/n)-(r(2)*sx/n)
2459 subroutine new_intep(x1a,x2a,x3a,ya,m,n,l,ia,x1,x2,x3,y,dy, &
2463 real,
dimension(:),
intent(in) :: x1a
2464 real,
dimension(:),
intent(in) :: x2a
2465 real,
dimension(:),
intent(in) :: x3a
2466 real,
dimension(:,:,:,:),
intent(in) :: ya
2467 integer,
intent(in) :: m, n, l
2468 integer,
intent(in) :: ia
2469 real,
intent(in) :: x1, x2, x3
2470 real,
intent(inout) :: y, dy
2471 integer,
intent(in) :: mbeg, nbeg
2472 real,
intent(in) :: frac
2474 real,
dimension(4) :: xx2a, xx1a
2475 real,
dimension(4) :: yntmp, ymtmp
2476 real,
dimension(2) :: yltmp
2486 yltmp(1)=ya(j,k,1,ia)
2487 yltmp(2)=ya(j,k,2,ia)
2488 yntmp(k) = yltmp(1)*(1.-frac) + yltmp(2)*frac
2489 xx2a(k) = x2a(k+nbeg)
2491 call polint(xx2a,yntmp,4,x2,ymtmp(j),dy)
2492 xx1a(j) = x1a(j+mbeg)
2496 call polint(xx1a,ymtmp,4,x1,y,dy)
2502 subroutine polint(xa,ya,n,x,y,dy)
2504 real,
dimension(:),
intent(in) :: xa
2505 real,
dimension(:),
intent(in) :: ya
2506 integer,
intent(in) :: n
2507 real,
intent(in) :: x
2508 real,
intent(inout) :: y
2509 real,
intent(inout) :: dy
2511 integer,
parameter :: nmax = 50
2512 real,
dimension(nmax) :: c
2513 real,
dimension(nmax) :: d
2516 real :: ho, hp, dif, dift
2523 if (dift.lt.dif)
then
2544 if (2*ns.lt.n-m)
then