forked from paulricchiazzi/SBDART
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrt.f
1740 lines (1488 loc) · 55 KB
/
drt.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module outblk
use params, only: mxly, kr, nstrms
integer, parameter :: maxulv=mxly+1
real(kr) :: phidw,topdn,topup,topdir,botdn,botup,botdir,
& fxup(maxulv),fxdn(maxulv),fxdir(maxulv),
& uurs(nstrms,nstrms),uurl(nstrms,nstrms,maxulv)
integer, parameter :: nu1=nstrms*nstrms,
& nu2=nu1*maxulv
data uurs/nu1*0.0/
data uurl/nu2*0.0/
data phidw,topdn,topup,topdir,botdn,botup,botdir/7*0./
data fxup,fxdn,fxdir/maxulv*0.,maxulv*0.,maxulv*0./
end module outblk
c=======================================================================
c sbdart
c
c PURPOSE: COMPUTE PLANE-PARALLEL RADIATIVE TRANSFER IN THE EARTH'S ATMOSPHERE
c
c INPUT/OUTPUT VARIABLES described in rt.doc
c
c modules:
c
c params grid sizes, physical constants
c outblk output quantities
c albblk surface albedo quantities
c sunblk solar spectra
c fltblk sensor filter function
c aeroblk aerosol properties
c gasblk gaseous absorption quantities
c trcblk gaseous absorption due to trace gases
c kdstblk k-distribution quantities
c
c
c subroutines called from the main routine
c
c absint lowtran gas absorption integrals
c atms atmospheric profile
c bdrefchk check brdf function
c chkin check input parameters
c chkprn diagnostic print out
c depthscl combine gas absorption with scattering optical depth
c disort discrete ordinate radiative tranfer module
c gasinit set up k-distribution parameters
c gasset set up k-distribution parameters for a particular iteration
c helper output format description
c locate search for a value in a 1-d monotonic array
c modatm modify atmospheric profile
c modmix modify profile of trace gases
c nearest find index of array element closest to a given value
c normom normalize phase function moments
c rayleigh find rayleigh scattering optical depth
c satcloud put saturate water vapor in cloudy parts of atmosphere
c saturate find fully saturated water vapor density
c setfilt initialize sensor filter function
c stdout0 write head records of standard output format
c stdout1 write wavelength dependent output records
c stdout2 write cumulative output record(s)
c suralb compute surface albedo
c tauaero compute aerosol optical properties
c taucloud compute cloud optical properties
c usrcloud read file for cloud properties
c vuangles set radiance viewing angles
c wllimits coordinate wavelength iteration
c zensun solar ephemeris
c zeroit zero out an array
c zgrid change vertical resolution of atmospheric grid
c zlayer find layer positions given atititude ranges
c
c logical units files
c
c 11 INPUT (stays open)
c
c 12 CKATM and CKTAU k-distribution files (stays open)
c
c 13 usrcld.dat, atms.dat, filter.dat, albedo.dat,
c solar.dat (each file is closed after read)
c
c 15 aerosol.dat (stays open)
c
c 16 disort warning messages
c
c=======================================================================
program sbdart
use params, only: mxly, nstrms, ncldz, mxkd, mxq, maxmom,
& zip, nan, kr, one, zero, pi
use outblk, only: maxulv ! passes information to stdout2
use aeroblk, only:
& zaer,taerst,zbaer,dbaer,vis,tbaer,abaer,
& wlbaer,qbaer,wbaer,gbaer,pmaer,rhaer,iaer,imoma,jaer
implicit none
integer, parameter ::
& nta=9, ! number of gas transmission values
& ndb=20 ! idb array size
integer :: nnn, nz, idatm, isat, nf, isalb, iout, idb(ndb)=0,
& imomc, iday, nosct, ntau, numu, nzen, nphi, nothrm, ibcnd,
& kdist, ngrid, krhclr, ipth, maxumu, maxphi, nstr, ios, nvzen,
& numset, i, ii, j, k, nstrsv, mcldz, nbot, ntop, nwl, il,
& nmom, kd, nk, lcld(ncldz), ib=1, nb=1
real(kr) :: z(mxly), p(mxly), t(mxly), wh(mxly), wo(mxly),
& gwk(mxkd), dtauk(mxly,mxkd), dtaugc(mxly), dtauc(mxly),
& wcld(mxly), dtaus(mxly), wreal(mxly), dtor, dtaur(mxly),
& dtaua(mxly), waer(mxly), dtaug(mxly), umu(nstrms),
& utau(mxly), uzen(nstrms), phi(nstrms), vzen(nstrms), sc(5),
& uu(mxq, mxly), zout(2),
& zcloud(ncldz), tcloud(ncldz), pmom(0:maxmom,mxly),
& temper(0:mxly), lwp(ncldz), nre(ncldz), wvnmlo, wvnmhi,
& accur, wlinf, wlsup, wlinc, albcon, sza, csza, rhcld, amix,
& alat, alon, time, solfac, sclh2o, pbar, uw, uo3, o3trp, ztrp,
& xn2, xo2, xco2, xch4, xn2o, xco, xno2, xso2, xnh3, xno,
& xhno3, xo4, xrsc, zpres, phi0, fisot, temis, btemp, ttemp,
& zgrid1, zgrid2, saza, fj, amu0, wl1, wl2, wl, dw, dwl, ff,
& flxin, test, rsfc, tauaertot, wt, dtauctot, rfldir(maxulv),
& rfldn(maxulv), flup(maxulv), dfdt(maxulv), uavg(maxulv),
& uur(nstrms,maxulv,nstrms), albmed(nstrms), trnmed(nstrms),
& ewcoef, etirr, dref, szabar
logical :: prnt(7), lamber, azmavg, usrtau, usrang, plank,
& onlyfl, radcalc, zflag=.false., corint=.false.,
& spowder=.false., first=.true.
real(kr), external :: filter, relhum, solirr, salbedo, albave
character*(127) header
c=======================================================================
data wvnmlo/0.0/,wvnmhi/0.0/,accur/0.0/
data nz, idatm,isat,nf,isalb,iout,imomc
& / 33, 4, 0, 2, 0, 10, 3 /
data wlinf, wlsup, wlinc
& / .55, .55, 0./
data albcon, sza, saza, csza, rhcld, amix
& / 0., 0., 180., zip, zip, zip /
data dtaua /mxly*0./
data waer /mxly*0./
data iday,alat,alon,time /0,-64.767,-64.067,16./
data solfac /1.0/
data sclh2o, pbar, uw, uo3, o3trp, ztrp
& / zip, zip, zip, zip, zip, 0./
data xn2, xo2, xco2, xch4, xn2o
& / zip, zip, zip, zip, zip/
data xco, xno2, xso2, xnh3, xno, xhno3
& / zip, zip, zip, zip, zip, zip/
data xo4/one/
data xrsc/one/
data nosct/0/
data zpres/zip/
c
data zcloud, tcloud, nre, lcld
& /ncldz*0., ncldz*0., ncldz*8., ncldz*0/
data prnt/ 7*.false./
data lamber, azmavg, usrang, usrtau
& / .true., .true., .false., .false./
data ntau,numu,nzen,nphi/4*0/
data umu/nstrms*0./
data uzen/nstrms*zip/
data vzen/nstrms*90./
data phi/nstrms*zip/
data nothrm,ibcnd,phi0,fisot,temis/-1,0,0.,0.,0./
data btemp,ttemp /zip,zip/
data zout/0.,100./
data kdist/3/
data zgrid1,zgrid2,ngrid /1.,30.,0/
data krhclr /0/
data ipth /0/
data maxumu,maxphi/2*nstrms/
data nstr/0/
data lwp/ncldz*0./
data sc/5*nan/
namelist /input/
& idatm, amix, isat, wlinf, wlsup, wlinc, sza, csza, solfac,
& nf, iday, time, alat, alon, zpres, pbar, sclh2o, uw, uo3,
& o3trp, ztrp, xrsc, xn2, xo2, xco2, xch4, xn2o, xco, xno2,
& xso2, xnh3, xno, xhno3, xo4, isalb, albcon, sc, zcloud,
& tcloud, lwp, nre, rhcld, krhclr, jaer, zaer, taerst, iaer,
& vis, rhaer, tbaer, wlbaer, qbaer, abaer, wbaer, gbaer, pmaer,
& zbaer, dbaer, nothrm, nosct, kdist, zgrid1, zgrid2, ngrid,
& idb, zout, iout, prnt, temis, nstr, nzen, uzen, vzen, nphi,
& phi, saza, imomc, imoma, ttemp, btemp, corint, spowder
namelist /dinput/
& ibcnd,phi0,prnt,ipth,fisot,temis,nstr,
& nzen,uzen,vzen,nphi,phi,ttemp,btemp
c-----------------------------------------------------------------------
open(unit=11,file='INPUT',status='old',iostat=ios)
if(ios.eq.0) then
read(11,input,end=1)
read(11,dinput,end=2)
goto 2
1 continue
stop 'error: namelist block $INPUT not found'
2 continue
else
write(*,input)
stop
endif
rewind 11
dtor=pi/180.
if(idb(1).ne.0) call helper(iout)
radcalc=any(iout.eq.(/5,6,20,21,22,23/))
onlyfl=.not. radcalc
if(nstr.eq.0) then
if(radcalc) then
nstr=min(20,nstrms)
else
nstr=4
endif
endif
select case (abs(isalb))
case (7)
! chlor, wndspd, salin
where(sc.eq.nan) sc=(/0.01,5.,34.3,0.,0./)
case (8)
! ssa, asym, hotpeak, hotwidth
where(sc.eq.nan) sc=(/0.101,-0.263,0.589,0.046,0./)
case (9)
! isotropic, volumetric, geometric, aspect1, aspect2
where(sc.eq.nan) sc=(/1.,0.,0.,2.,1./)
case default
! fraction of snow, ocean, sand, vegetation
where(sc.eq.nan) sc=(/1.,0.,0.,0.,0./)
end select
c assign user radiance angles
if(radcalc) call vuangles(nphi,phi,nzen,uzen,nvzen,vzen,iout)
c check input parameters
call chkin
c solar spectrum, atmosphric profile, satellite sensor
c filtering, surface albedo and aerosol parameters
if(iday.ne.0) then
call zensun(abs(iday),time,alat,alon,sza,saza,solfac)
elseif(csza.ne.zip) then
sza=acos(csza)/dtor
endif
if(abs(sza-90).lt..01) sza=95.
phi0=mod(saza-180.0_kr+360.0_kr, 360.0_kr)
if(iday.lt.0) then
print '(a5,6a9)','day','time','lat','lon','sza','azm','solfac'
print '(i5,6f9.3)',abs(iday),time,alat,alon,sza,saza,solfac
if(radcalc) then
print '(2a9)','phi','rel_az'
do i=1,nphi
if(phi0.gt.180..and.phi(nphi)+phi0.gt.360) then
print '(2f9.3)',phi(i),phi(i)+phi0-360.
else
print '(2f9.3)',phi(i),phi(i)+phi0
endif
enddo
endif
stop
endif
call setfilt(isat,wlinf,wlsup,wlinc,wl1,wl2,nwl)
if (iout == 2) kdist = 0
if(kdist.ge.0) then
call atms(idatm,amix,nz,z,p,t,wh,wo)
if(ngrid.ne.0.) call zgrid(nz,z,p,t,wh,wo,zgrid1,zgrid2,ngrid)
if(zpres.ne.zip) then
call locate(z,nz,zpres,j)
fj=(zpres-z(j))/(z(j+1)-z(j))
pbar=p(j)*(p(j+1)/p(j))**fj
endif
call modatm(nz,sclh2o,uw,uo3,o3trp,ztrp,pbar,z,p,wh,wo)
call modmix(xn2,xo2,xco2,xch4,xn2o,xco,xno2,xso2,xnh3,
& xno,xhno3,xo4)
if(rhaer.lt.0.) rhaer=relhum(t(1),wh(1))
elseif(kdist.eq.-1) then
call gasinit(wl1,wl2,nwl,nz,z,p,t,rhaer,idb(3))
endif
if(maxval(idb).eq.0) call stdout0(iout,nwl,nz)
temper(0)=t(nz)
do j=1,nz
temper(j)=t(nz+1-j)
enddo
if(btemp.lt.0.) btemp=temper(nz)
if(ttemp.lt.0.) ttemp=temper(0)
if(spowder) then ! add a sub-surface bottom layer
if(nz.ge.mxly) then
print *,'Error --- nz < mxly is required with spowder option'
stop
endif
z(2:nz+1)=z(1:nz) ; z(1)=-1.
p(2:nz+1)=p(1:nz) ; p(1)=1.1*p(2)
t(2:nz+1)=t(1:nz) ; t(1)=btemp
wh(2:nz+1)=wh(1:nz) ; wh(1)=0.
wo(2:nz+1)=wo(1:nz) ; wo(1)=0.
nz=nz+1
endif
nstrsv=nstr
mcldz=max(numset(zero,tcloud,ncldz),
& numset(zero,lwp,ncldz))
call zlayer(nz,z,mcldz,zcloud,lcld)
if(kdist.ge.0) then
if(rhcld.ge.0) then
if(krhclr.eq.1) then
call satcloud(nz,ncldz,lcld,t,rhcld,wh,idb(2))
else
call saturate(nz,ncldz,lcld,z,t,rhcld,wh,idb(2))
endif
endif
if(ngrid.lt.0.or.idatm.lt.0) call prnatm
call absint(uu,nz,z,p,t,wh,wo,idb(3))
endif
c find nearest computational levels to given output altitudes
if(minval(zout).lt.0.) then
zout(1)=abs(zout(1))
zout(2)=abs(zout(2))
zflag=.true.
endif
call nearest(z,nz,zout(1),nbot)
call nearest(z,nz,zout(2),ntop)
nbot=nz-nbot+2
ntop=nz-ntop+2
if(ntop.eq.2) ntop=1
if(zflag) then
print '(a,3i5,2f12.3)','nz,ntop,nbot,z(ntop),z(nbot): ',
& nz,ntop,nbot,z(nz-nbot+2),z(nz-ntop+2)
stop
endif
c set up for radiance calculation
if(radcalc) then
usrang=.true.
numu=nzen
do j=1,numu
umu(j)=min(one,max(cos(uzen(numu+1-j)*dtor),-one))
if(umu(j).eq.0.) then
if(j.eq.numu) then
umu(j)=-.0001
else
umu(j)=.0001
endif
endif
enddo
if(nphi.ne.0) then
azmavg=.false.
else
nphi=1
phi(1)=0.
endif
endif
if(idb(4).ne.0) call chkprn
c mfl
c print *, 'drt: isalb = ', isalb
call suralb(isalb,albcon,sc)
c load extinction, absorption, and asymmetry parameters for boundary
c layer aerosols, i.e., either rural, urban, oceanic or tropospheric aerosols
c and performs interpolation over relative humidity
amu0=cos(sza*dtor)
c beginning of wavelength looping
do ! wl_loop
if(kdist.lt.0) then
call readk(nz,wl1,wl2,wl,wvnmlo,wvnmhi,
& ib,nb,nk,etirr,ewcoef,gwk,dtauk,idb(7))
if(nk.eq.0) exit ! end of file, stop looping
else
call wllimits(nwl,wlinc,wl1,wl2,wl,wvnmhi,wvnmlo)
if(nwl.eq.0) exit ! wl beyond wl2, stop looping
call gasset(kdist,wl,uu,amu0,nz,z,nk,gwk,dtauk,dtaugc,idb(7))
ewcoef=1.
endif
dwl=10000./wvnmlo-10000./wvnmhi
if (iout.eq.2) then
if (first) print *, "nwl", nwl
call taugas(wl,uu,amu0,nz,z,dtauc,dtauk(:,1),1)
first=.false.
cycle
endif
if(nf.ne.-2) etirr=solirr(wl,nf)*dwl
flxin=etirr*solfac
c flxin set to et solar spectra (W/m2) or a uniform constant
if(nf.eq.0) flxin=dwl
if(sza.ge.90.) then
flxin=0.
amu0=1.
endif
ff=filter(wl)*ewcoef
if(nothrm.lt.0) then
plank=wl.gt.2.
else
plank=nothrm.eq.0
endif
if(any(isalb.eq.(/7,8,9/))) then
lamber=.false.
if(idb(8).ne.0) rsfc=dref(wvnmlo,wvnmhi,cos(dtor*sza))
if(idb(8).eq.1) then
print '(2f11.4)',wl,rsfc
elseif(idb(8).eq.2) then
call bdrefchk(wvnmlo,wvnmhi,sza,nphi,phi,nzen,uzen,rsfc)
endif
else
lamber=.true.
if(any(isalb.eq.(/-7,-8,-9/))) then
rsfc=dref(wvnmlo,wvnmhi,cos(dtor*sza))
else
rsfc=salbedo(wl)
endif
rsfc=max(zero,(min(rsfc,one)))
if(idb(8).ne.0) print '(2f11.4)',wl,rsfc
endif
c calculate cloud optical depth and scattering parameters
if(radcalc.and.corint) then
nmom=maxmom
else
nmom=min(nstr+2,nstrms) ! add two to allow for nstr dithering
endif
dtaus=0.
wreal=0.
pmom=0.
dtauc=0
wcld=0
c setting wcld to zero causes problems
if(mcldz.gt.0) then
call taucloud(nz,ncldz,wl,lcld,lwp,tcloud,nre,
& dtauc,wcld,imomc,nmom,pmom)
elseif(nre(1).eq.zero) then
call usrcloud(nz,wl,p,dtauc,wcld,imomc,nmom,pmom,idb(5))
endif
if(idb(5).gt.0) call taucdb
c aerosol optical depth
call tauaero(wl,nz,z,nosct,dtaua,waer,nmom,pmom,idb(6))
if(maxval(idb(1:8)).gt.0) cycle
c rayleigh scattering
call rayleigh(wl,z,p,t,nz,dtaur)
if(xrsc.ne.one) dtaur(1:nz)=xrsc*dtaur(1:nz)
c normalize phase function moments
call normom(nz,dtauc,wcld,dtaua,waer,dtaur,nmom,pmom)
c loop through k-distribution terms, calculate total optical
c thickness (gases, rayleigh, aerosols and clouds)
do kd=1,nk ! kd_loop
call depthscl(kdist, kd, nk, ib, nz, wl, dtaur, dtaua,
& waer, dtauc, wcld, spowder, gwk, dtauk, dtaugc, wt,
& dtaus, wreal, idb(9))
if(idb(9).gt.0) cycle
do j=0,2 ! retry loop in case radiance is negative
nstr=nstrsv+j*(3*j-5)
if(nstr.lt.4) cycle
if(nstr.gt.nstrms.or.ff.eq.0.) exit
call disort(nz,dtaus,wreal,corint,nmom,pmom,temper,
& wvnmlo,wvnmhi,usrtau,ntau,utau,nstr,usrang,
& numu,umu,nphi,phi,ibcnd,flxin,amu0,phi0,fisot,
& lamber,rsfc,btemp,ttemp,temis,plank,onlyfl,accur,
& prnt,header,mxly,maxulv,maxumu,maxphi,maxmom,
& rfldir,rfldn,flup,dfdt,uavg,uur,albmed,trnmed)
if(nstr.gt.0) exit ! success
enddo
if(nstr.lt.0.or.nstr.gt.nstrms) then
write(*,*)'Error --- NSTR dithering procedure failed'
stop
endif
nstr=nstrsv
call stdout1(nz,z,ntop,nbot,iout,wl,dwl,wt,rfldir,rfldn,
& flup,ff,nphi,nzen,phi,uzen,uur,ib,nb,kd,nk)
enddo ! kd_loop
enddo ! wl_loop
call stdout2(nz,iout,wl1,wl2,nphi,nzen,phi,uzen,z,p)
contains
c.......................................................................
subroutine chkin ! internal procedure
c PURPOSE check input for invalid values. does not change anything.
c if input is suspect, issue warnings and continue
c if input is bad print error messages and stop
c
c input: a bunch of the namelist input parameters, by use association
c output: none
c
integer :: kill
character (len=132) :: line
! warnings
if(iaer.eq.0 .and. (vis.ne.zip.or.tbaer.ne.zip))
& call errmsg(16,'CHKIN--IAER=0, though VIS or TBAER set')
if(corint .and. onlyfl)
& call errmsg(17,'CHKIN--CORINT=t, but flux output selected')
! fatal errors
kill=0
if(idatm.lt.-6.or.idatm.gt.6) then
call ck(kill,'idatm','[-6,6]')
print *,'idatm=',idatm
endif
if(wlinf.lt.0.199) then
call ck(kill,'wlinf','[0.2,-]')
print *,'wlinf=',wlinf
endif
if(isat.le.-2) then
if(wlsup.lt.0..or.wlsup.ge.wlinf) then
call ck(kill,'wlsup','[0,wlinf]')
print *,'wlsup=',wlsup
endif
else
if(wlsup.lt.wlinf.or.wlsup.gt.100.) then
call ck(kill,'wlsup','[wlinf,100]')
print *,'wlsup=',wlsup
endif
endif
if(isat.lt.-4.or.isat.gt.29) then
call ck(kill,'isat','[-4,29]')
print *,'isat=',isat
endif
if(solfac.lt.0.) then
call ck(kill,'solfac','[0,inf]')
print *,'solfac=',solfac
endif
if(minval(zcloud).lt.-100..or.maxval(zcloud).gt.100) then
call ck(kill,'zcloud','[-100,100]')
print *,'zcloud=',zcloud(1:ncldz)
endif
if(minval(abs(nre)).lt.2 .or. maxval(abs(nre)).gt.128) then
if(nre(1).ne.0.) then
call ck(kill,'nre','[2,128]')
print *,'nre',nre(1:ncldz)
endif
endif
if(any(tcloud.eq.0.and.zcloud.lt.0)) then
print *,'CHKIN --- Error detected in input'
print *,'TCLOUD(k)=0 when ZCLOUD(k)<0'
print '(a,100f10.2)','zcloud',zcloud(1:ncldz)
print '(a,100f10.2)','tcloud',tcloud(1:ncldz)
kill=1
endif
if(minval(lwp).lt.0.) then
call ck(kill,'lwp','[0,inf]')
print *,'lwp=',lwp
endif
if(maxval(abs(zaer)).gt.100.) then
call ck(kill,'zaer','[-100,100]')
print *,'zaer=',zaer
endif
if(minval(taerst).lt.0.) then
call ck(kill,'taerst','[0,inf]')
print *,'taerst',taerst
endif
if(minval(jaer).lt.0.or.maxval(jaer).gt.4) then
call ck(kill,'jaer','[0,4]')
print *,'jaer',jaer
endif
if(nf.lt.-2.or.nf.gt.3) then
call ck(kill,'nf','[-2,3]')
print *,'nf',nf
endif
if(iaer.lt.-1.or.iaer.gt.5) then
call ck(kill,'iaer','[-1,5]')
print *,'iaer',iaer
endif
if(.not.any(isalb.eq.(/-7,-8,-9,-1,0,1,2,3,4,5,6,7,8,9,10/))) then
call ck(kill,'isalb','[-7,-8,-9,-1,0,1,2,3,4,5,6,7,8,9,10]')
print *,'isalb',isalb
endif
if(isalb.eq.0.and.albcon.lt.0.) then
call ck(kill,'albcon','[0,inf]')
print *,'albedo set by albcon',albcon
endif
if(minval(zout).lt.0..or.maxval(zout).gt.100)then
call ck(kill,'zout','[0,100]')
print *,'zout',zout
endif
if(.not. any(iout.eq.(/1,2,5,6,7,10,11,20,21,22,23/))) then
call ck(kill,'iout','[1,2,5,6,7,10,11,20,21,22,23]')
print *,'iout',iout
endif
if(nphi.lt.0.or.nphi.gt.nstrms) then
call ck(kill,'nphi','[0,nstrms]')
print *,'nphi',nphi
endif
if(any(iout.eq.(/20,21,22,23/)).and.nzen.eq.0) then
write(*,'(1x,a,i2,a,a)') 'iout =',iout,
& ' implies radiance calculation, ',
& 'but nzen=0 produces no radiance output'
kill=1
endif
if(zpres.ne.zip.and.pbar.ne.zip) then
write(*,'(1x,a)') 'set zpres or pbar but not both'
write(*,*) 'zpres,pbar ',zpres,pbar
kill=1
endif
if((numset(zero,tcloud,ncldz).ne.0).and.
& (numset(zero,lwp,ncldz).ne.0)) then
write (*,*) 'set TCLOUD or LWP, but not both'
kill=1
endif
if(kill.eq.1) then
do
read(11,'(a)',end=100) line
write(16,'(a)') trim(line)
enddo
100 continue
stop
endif
return
end subroutine chkin
c.......................................................................
subroutine ck(kill,name,range) ! internal procedure (used in chkin)
character*(*) name,range
integer :: kill
if(kill.eq.0) print '(a)','CHKIN --- Errors detected in INPUT'
print '(/5x,4a)','Input parameter ',name,' not within ',range
kill=1
return
end subroutine ck
c.......................................................................
subroutine chkprn ! internal procedure
c purpose: print some info on variables defined within main program
c does not change anything
integer :: i
character*(30) :: form='("default value used for",a)'
if(iday.ne.0) then
print '(a,i3)', 'Day of year: ',abs(iday)
print '(a,f8.4)', ' GMT: ',time
print '(a,2f10.4)', ' lat,lon: ',alat,alon
print *, ' '
endif
print '(a,2f10.4)', ' sza,solfac: ',sza,solfac
print '(a,2f10.4)', ' zout: ',zout
print '(a,3i10)', 'nbot,ntop,nz: ',nbot,ntop,nz
print *, ' '
if(pbar.lt.0) print form,'PBAR'
if(uw.lt.0) print form,'UW'
if(uo3.lt.0) print form,'UO3'
if(o3trp.lt.0) print form,'O3TRP'
if(sclh2o.lt.0) print form,'SCLH2O'
print *, ' '
if(tcloud(1).ne.0.) then
call zlayer(nz,z,numset(zero,tcloud,ncldz),zcloud,lcld)
print '(a,5f10.4)',' zcloud:' ,zcloud
print '(a,5i10)', ' lcld:' ,lcld
endif
print *,'"ATM'
print *,nz
print '(a/(10es11.3))', 'z',(z(i),i=1,nz)
print '(a/(10es11.3))', 'p',(p(i),i=1,nz)
print '(a/(10es11.3))', 't',(t(i),i=1,nz)
print '(a/(10es11.3))', 'h2o',(wh(i),i=1,nz)
print '(a/(10es11.3))', 'o3',(wo(i),i=1,nz)
return
end subroutine chkprn
c.......................................................................
subroutine taucdb ! internal procedure
! print cloud diagnostic
integer :: ifirst=1
if(ifirst.eq.1) print '(a,20i5)','lcld: ',lcld(1:mcldz)
write(*,'(5x,4a11)',advance='no') 'wl','z','dtauc','ssa'
do i=1,min(nmom,9)
write(*,'(" pmom(",i1,")")',advance='no') i
enddo
print *
do j=1,nz
if(dtauc(j).eq.0) cycle
print '(i5,13(f11.5))',j,wl,z(nz-j+1),dtauc(j),wcld(j),
& (pmom(i,j)/(dtauc(j)*wcld(j)),i=1,min(nmom,9))
enddo
end subroutine taucdb
c.......................................................................
subroutine prnatm
print *,nz
do i=1,nz
write(*,'(f11.3,4es11.3)') z(i),p(i),t(i),wh(i),wo(i)
enddo
stop
end subroutine prnatm
end program sbdart
c=======================================================================
subroutine vuangles(nphi,phi,nzen,uzen,nvzen,vzen,iout)
c
c modifies values of nphi, phi, nzen, uzen
c
use params, only: nstrms, kr, zip
real(kr) :: p1,p2,z1,z2,xxx,zipp
real(kr) phi(nstrms),uzen(nstrms),vzen(nstrms)
integer :: i,ii,nphi,nzen,nvzen,iout
! finds radiance viewing angles
if(nphi.gt.0) then
if(numset(zip,phi,nstrms).ne.2)
& write(*,'(a)') 'Error in MAIN -- ' //
& 'must specify exactly 2 values of phi when nphi is set'
if(nphi.gt.nstrms)
& write(*,'(a)') 'Error in Main -- ' //
& 'specified nphi larger than nstrms'
p1=min(phi(1),phi(2))
p2=max(phi(1),phi(2))
do i=1,nphi
phi(i)=p1+(i-1)*(p2-p1)/float(nphi-1)
enddo
else
nphi=numset(zip,phi,nstrms)
if(nphi.eq.0) then ! set default
nphi=19
p1=0.
p2=180.
do i=1,nphi
phi(i)=p1+(i-1)*(p2-p1)/float(nphi-1)
enddo
endif
endif
zipp=90. ! convert to real(real_kind)
nvzen=numset(zipp,vzen,nstrms)
do i=1,nvzen
uzen(i)=180.-vzen(i)
enddo
if(nzen.gt.0) then
if(numset(zip,uzen,nstrms).ne.2)
& write(*,'(a)') 'Error in MAIN -- ' //
& 'must specify exactly 2 values of uzen when nzen is set'
if(nzen.gt.2*nstrms)
& write(*,'(a)') 'Error in Main -- ' //
& 'specified nzen larger than nstrms'
z1=min(uzen(1),uzen(2))
z2=max(uzen(1),uzen(2))
ii=0
do i=1,nzen
xxx=z1+(i-1)*(z2-z1)/float(nzen-1)
if(abs(xxx-90.).gt..05) then
ii=ii+1
uzen(ii)=xxx
endif
enddo
nzen=ii
else
nzen=numset(zip,uzen,nstrms)
if(nzen.eq.0) then ! set default radiance grid
select case (iout)
case (5,20) ; nzen=18 ; z1=0. ; z2=85. ! toa looking down
case (6,21) ; nzen=18 ; z1=95. ; z2=180. ! surface looking up
case default ; nzen=36 ; z1=0. ; z2=180.
end select
do i=1,nzen
uzen(i)=z1+(z2-z1)*(i-1)/float(nzen-1)
enddo
! assume a reasonable number of streams if nstr unset by user
if(nstr.eq.4) nstr=min( 2*(max(nphi,nzen)/2), nstrms)
endif
endif
return
end subroutine vuangles
c=======================================================================
subroutine stdout0(iout,nwl,nz)
implicit none
integer :: iout, nwl, nz
select case (iout)
case (1,5,6)
write(*,'(/,a)') '"tbf'
write(*,'(i15)') nwl
case (7)
write(*,'(/,a)') '"fzw'
write(*,'(i15)') nz
end select
return
end
c=======================================================================
subroutine stdout1(nz,z,ntop,nbot,iout,wl,dwl,wt,
& rfldir,rfldn,flup,ff,nphi,nzen,phi,uzen,uur,
& ib,nb,kd,nk)
c
c performs these functions (depending on value of iout):
c input:
c nz number of levels
c z altitude array [z(1) at bottom]
c ntop output level top
c nbot output level bottom
c iout
c 1 print output at each wavelength (fluxes in w/m2/micron)
c 5 print radiance output at top at each wavelength
c 6 print radiance output at bot at each wavelength
c 10 total inband flux (w/m2) summed over wavelength
c 11 flux at each level integrated over wavelength
c 20 total inband radiance (w/m2/str) at ZOUT(2)
c 21 total inband radiance (w/m2/str) at ZOUT(1)
c 22 inband radiance (w/m2/str) at each level
c 23 inband radiance (w/m2/str) at zout(1) and zout(2)
c upper hemisphere radiance at zout(2)
c lower hemisphere radiance at zout(1)
c wl current wavelength (um)
c dwl wavelength increment (um)
c wt weighting factor for this iteration
c rfldir direct flux
c rfldn downward flux
c flup upward flux
c ff filter function
c nphi number of azimuth angles in radiance viewing array
c nzen number of zenith angles in radiance viewing array
c phi azimuth viewing angle array
c uzen zenith viewing angle array
c uur radiance array
c ib band index.
c nb total number of sub-bands
c kd k-distribution index
c nk number k-distribution intervals
c
use params, only: mxly, kr, nstrms
use outblk, only: topdn,topup,topdir,botdn,botup,botdir,
& maxulv, uurs, phidw, fxdn, fxup, fxdir, uurl
implicit none
integer, parameter :: nr=mxly*3, nta=9
integer :: iout, kd, ntop, nbot, nk, i, j, k, nphi, nzen,
& nz, im, ib, nb
real(kr) :: rfldir(*),rfldn(*),flup(*),phi(*),uzen(*),z(*),
& uur(nstrms,maxulv,nstrms), dwt, wt, dwl, ff, wl,
& dwx, weq, wfull
1000 format(10es12.4)
dwt=wt*ff ! flxin in w/m2
if(iout.eq.1 .or. iout.eq.5 .or. iout.eq.6) then
if(kd.eq.1.and.ib.eq.nb) then
topdn=0.
topup=0.
topdir=0.
botdn=0.
botup=0.
botdir=0.
weq=0.
wfull=0.
endif
topdn = topdn + (rfldn(ntop)+rfldir(ntop))*dwt
topup = topup + flup(ntop)*dwt
topdir = topdir + rfldir(ntop)*dwt
botdn = botdn + (rfldn(nbot)+rfldir(nbot))*dwt
botup = botup + flup(nbot)*dwt
botdir = botdir + rfldir(nbot)*dwt
if(kd.eq.nk) then
weq=weq+dwl*ff ! finished sub-band, increment equiv width
wfull=wfull+dwl ! finished sub-band, increment full width
endif
if(kd.eq.nk.and.ib.eq.1) then
if(weq.eq.0.) weq=1.e-30
write(*,'(f12.8,f9.5,6es12.4)') wl,weq/wfull,
& real(topdn/weq),real(topup/weq),real(topdir/weq),
& real(botdn/weq),real(botup/weq),real(botdir/weq)
endif
if(iout.eq.5 .or. iout.eq.6 ) then
j=ntop
if(iout.eq.6) j=nbot
if(kd.eq.1.and.ib.eq.nb) uurs(1:nzen,1:nphi)=0.