-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_ra_mars_common_f90.f90
2489 lines (2051 loc) · 95.8 KB
/
module_ra_mars_common_f90.f90
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
!WRF:MODEL_LAYER:PHYSICS
!
MODULE module_ra_mars_common
USE module_wrf_error
USE module_nrutils, only: linear_interpolate
use module_mars24
use netcdf
use module_model_constants, only: pi2
use module_planet_utilities, only: read_wrf_profile_file, &
check_ncdf, dimension_size
IMPLICIT NONE
PRIVATE
public :: newton20, dust_distrib_fixed, dust_distribution, oxford_dust, &
mcd_mgs, mcd_mgsx2, mcd_viking, mcs_dust, init_mcd_mgs, &
sw_aerosol_scatter, lw_aerosol_heat, demiss3, &
inject_mcd_mgs, delta_mcd_mgs, da_mcd_mgs, diagnose_tau_2d, &
mars_msr_fit, chicagodust, get_lower_pbl_ir_heat, cp_mars, &
dust_distrib_truly_fixed, forced_opac_profile, fop_init, &
prescribed_dust_storm_init
PUBLIC :: dust_tes_limb
PUBLIC :: dust_tes_limb_init
PUBLIC :: dust_montabone,dust_montabone_init
INTEGER, SAVE :: n_ls_tes
INTEGER, SAVE :: n_times_tes
INTEGER, SAVE :: n_altitudes_tes
INTEGER, SAVE :: n_latitudes_tes
INTEGER, SAVE :: n_longitudes_tes
INTEGER, SAVE :: n_aerosol_types = 2 ! This does *not* include co2 ice, which is done elsewhere
REAL, SAVE :: dseason_avg_tes
REAL, SAVE :: dtime_tes, time_offset_tes
REAL, SAVE :: dlat_tes
REAL, SAVE :: dlon_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: seasons_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: local_times_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: altitudes_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: latitudes_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: longitudes_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: ls_tes
REAL, SAVE, ALLOCATABLE, DIMENSION(:,:,:,:,:,:) :: tes_avg_tau
REAL, SAVE, ALLOCATABLE, DIMENSION(:,:,:,:,:,:) :: tes_avg_tau_err
!montabone dust
REAL, SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: montabone_cdod610
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: montabone_longitude, &
montabone_latitude, &
montabone_ls
! imposed dust storms from file
REAL, SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: storm_cdod610
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: storm_longitude, &
storm_latitude, &
storm_ls
REAL, SAVE :: montabone_old_ls = 0.
INTEGER, SAVE :: montabone_old_year = 0
INTEGER, SAVE :: montabone_rec_len
!end montabone dust
!forced opacity profile
INTEGER, SAVE :: fop_n_heights, fop_n_times
REAL, SAVE, ALLOCATABLE, DIMENSION(:,:) :: fop_pres, fop_opac
REAL, SAVE, ALLOCATABLE, DIMENSION(:) :: fop_time
!end forced opacity profile
CONTAINS
!-----------------------------------------------------------------------
!+ Function generates specific heat values (cp) to be used in flux !
! calculations. The gas mixture assumes a modern-day composition !
! of CO2 and N2. Coefficients are derived from cp/R vs T data in !
! Hilsenrath (1955). !
!-----------------------------------------------------------------------
FUNCTION cp_mars(t)
#ifdef mpas
USE mpas_atmphys_constants, only : co2_mixing_ratio, cp
#else
USE module_model_constants, ONLY: co2_mixing_ratio, cp
#endif
IMPLICIT NONE
logical, parameter :: fixed_cp = .true.
REAL(KIND(0.d0)), INTENT(IN ) :: t
real(kind(0.d0)) :: cp_mars
if(fixed_cp) then
cp_mars = cp
else
cp_mars=(((3.47D-07*t*t*t)-(1.269D-03*t*t)+(1.688*t)+443.1)* & ! First term is for CO2, second is
co2_mixing_ratio)+(1059.*(1.-co2_mixing_ratio)) ! for N2.
endif
END FUNCTION
!====================================================================
SUBROUTINE newton20( RTHRATEN, t, znu, pi3d, &
ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
its, ite, jts, jte, kts, kte)
!--------------------------------------------------------------------
! newton20 is an old subroutine that calculates the
! Newtonian damping of temperature.
! The 20 is in reference to the vertical levels in the GFDL Skyhi
! setup, and the the subsequent "tuning" of parameters (decay constants,
! height dependence, etc.) to that vertical structure.
!------------------------------------------------------------------
IMPLICIT NONE
!------------------------------------------------------------------
INTEGER , INTENT(IN ) :: ids, ide, jds, jde, kds, kde, &
ims, ime, jms, jme, kms, kme, &
its, ite, jts, jte, kts, kte
REAL , DIMENSION( ims:ime , kms:kme, jms:jme ) , INTENT(INOUT) :: RTHRATEN
REAL , DIMENSION( ims:ime , kms:kme, jms:jme ) , INTENT(IN ) :: t,pi3d
REAL , DIMENSION( kms:kme ) :: znu
INTEGER, PARAMETER :: nlevels = 5
REAL, PARAMETER :: t_naught = 140. ! Kelvin
REAL, PARAMETER :: damp_time = 5.e4 ! seconds
REAL, PARAMETER :: eta_naught = 9.447012e-06 ! "q" level (like sigma)
INTEGER :: i, j, k
REAL :: rnx, tbar, vfac, deltat
! Use these variables to choose the type of newtonian damping
! If both are false, default is point to zonal average
LOGICAL :: zonal_to_t0 = .FALSE.
LOGICAL :: point_to_t0 = .FALSE.
! This subroutine is meaningless unless we have full access to all grid
! points in the E/W direction. Check for that now.
IF ((its /= ids) .OR. (ite /= ide)) THEN
WRITE ( wrf_err_message , * ) 'module_damping: damptop: (its /= ids) or (ite /= ide)',its,ids,ite,ide
CALL wrf_error_fatal ( TRIM( wrf_err_message ) )
END IF
rnx = 1./REAL(ide-ids) ! Remember that ide has extra point for u wind...
! so that this is (ide-1) - ids + 1 = ide-ids
DO j=jts,jte ! We don't care if we are averaging an extra row or not
DO k=kde-nlevels,kde-1
vfac = ( (LOG(znu(k))/LOG(eta_naught))**6 )/damp_time
tbar = SUM(t(ids:ide-1,k,j))*rnx
DO i=its,ite
IF (zonal_to_t0) THEN
deltat = tbar - t_naught
ELSE IF (point_to_t0) THEN
deltat = t(i,k,j) - t_naught
ELSE
deltat = t(i,k,j) - tbar
END IF
RTHRATEN(i,k,j)=RTHRATEN(i,k,j)-vfac*deltat/pi3D(i,k,j)
END DO
END DO
END DO
END SUBROUTINE newton20
subroutine diagnose_tau_2d(tau_3d, psurf, tau_2d, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
tau_3d
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(OUT ) :: &
tau_2d
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: &
psurf
tau_2d(its:ite,jts:jte) = tau_3d(its:ite,kts,jts:jte) * ( 700. / psurf(its:ite,jts:jte) )
return
end subroutine
!====================================================================
SUBROUTINE dust_distrib_fixed(pph,pp,opt_depth,a,optdpth_array, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! Based on formula of Conrath (1975)
! Evaluate optical depth at given pressure levels
! Assume pressure increases with index number.
! The parameter a serves to pick at a height above which
! the dust mixing ratio decreases stongly.
! For a=0.01, this is at about 35 km.
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, INTENT(IN ) :: opt_depth, a
!
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( OUT) :: &
optdpth_array
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
pp, &
pph
! pph is our full sigma level, pp is our half sigma level
INTEGER:: i,j,k
REAL, DIMENSION(kts:kte+1) :: opt
REAL :: tau, rnorm, pbar, pbarinv
pbar = 758.8782 ! reference pressure level (optical depth
! refers to a mass of this pressure)
pbarinv= 1.0/pbar
! Array indices are reversed in WRF compared to MM5
DO j=jts,jte
DO i=its,ite
! kte+1 is the top border (full-eta level) of the model
opt(kte+1)= 0.0
DO k= kte, kts, -1
tau=exp( a*(1.0 - (pbar/pp(i,k,j))**(70./55.) ) )
opt(k)= opt(k+1) + tau*( pph(i,k,j)-pph(i,k+1,j) )
END DO
rnorm= opt_depth * pph(i,kts,j)*pbarinv / opt(kts)
DO k= kts, kte+1
optdpth_array(i,k,j)= opt(k)*rnorm
END DO
END DO
END DO
RETURN
END SUBROUTINE dust_distrib_fixed
!====================================================================
SUBROUTINE dust_distrib_truly_fixed(pph,pp,opt_depth,a,optdpth_array, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
! The "truly" means that opt_depth is always the optical depth at the
! actual surface - this will give weird results in a GCM with topography
! but is useful as a proper control in 1D or flat topo idealized sims
!---------------------------------------------------------------------
! Based on formula of Conrath (1975)
! Evaluate optical depth at given pressure levels
! Assume pressure increases with index number.
! The parameter a serves to pick at a height above which
! the dust mixing ratio decreases stongly.
! For a=0.01, this is at about 35 km.
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, INTENT(IN ) :: opt_depth, a
!
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( OUT) :: &
optdpth_array
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
pp, &
pph
! pph is our full sigma level, pp is our half sigma level
INTEGER:: i,j,k
REAL, DIMENSION(kts:kte+1) :: opt
REAL :: tau, rnorm
! assumes pph(i,kts,j) = psfc(i,j)
DO j=jts,jte
DO i=its,ite
! kte+1 is the top border (full-eta level) of the model
opt(kte+1)= 0.0
DO k= kte, kts, -1
tau=exp( a*(1.0 - (pph(i,kts,j)/pp(i,k,j))**(70./55.) ) )
opt(k)= opt(k+1) + tau*( pph(i,k,j)-pph(i,k+1,j) )
END DO
rnorm= opt_depth / opt(kts)
DO k= kts, kte+1
optdpth_array(i,k,j)= opt(k)*rnorm
END DO
END DO
END DO
RETURN
END SUBROUTINE dust_distrib_truly_fixed
!====================================================================
SUBROUTINE forced_opac_profile(p_in, optdpth_array, looper, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
! this routine forces the dust opacity to be that read in from a horizontal
! averge profile file, but with time and vertical variation
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
INTEGER, INTENT(IN) :: looper ! 0 = match time exactly to the second
! 1 = day looper, match local time to second
! 2 = year looper, match ls
!
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( OUT) :: &
optdpth_array
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
p_in
INTEGER:: i,j,k, it
! put code in here to find right it, or instead do bilinear interp
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kts:kte,j)=0.
DO k= kts, kte+1
optdpth_array(i,k,j)=linear_interpolate(x0=p_in(i,k,j), &
x=fop_pres(:,it),y=fop_opac(:,it), &
log_x=.true., &
out_of_range_use_nearest_edge=.true.)
END DO
END DO
END DO
RETURN
END SUBROUTINE forced_opac_profile
SUBROUTINE fop_init(filename)
implicit none
character(len=*), intent(in) :: filename
CALL read_wrf_profile_file(filename=filename, &
memo="forced opacity", &
n_times=fop_n_times, &
n_heights=fop_n_heights, &
pres=fop_pres, &
opac=fop_opac, &
time=fop_time )
END SUBROUTINE fop_init
!====================================================================
!!! LJS
SUBROUTINE chicagodust(pph,pp,xlat,xlong, &
dust_prs, dust_vsc, &
opt_depth,optdpth_array, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! Scheme used to test cloud formation and heating in past climates
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: xlat, xlong
REAL, INTENT(IN ) :: opt_depth, dust_prs, dust_vsc
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( OUT) :: &
optdpth_array
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
pp, pph
INTEGER:: i,j,k
REAL, DIMENSION(kts:kte+1) :: opt
REAL :: tau, rnorm, pref, vscale_fac, optdepth, od_inc
if((dust_prs > -1.) .and. (dust_vsc > -1.)) then ! dust_prs and _vsc come from namelist
pref = dust_prs
vscale_fac = dust_vsc
else
! if they were set to -1. then use average surface pressure over whole domain
pref = 0.
DO j=jds,jde
DO i=ids,ide
pref = pref + pph(i,1,j)/(jde-jds+1)/(ide-ids+1)
ENDDO
ENDDO
vscale_fac = 0.03
endif
DO j=jts,jte
DO i=its,ite
! Calculate vertical opacity profile
opt(kte+1) = 0.0
DO k=kte,kts,-1
tau = exp(vscale_fac*(1.0-pref/pp(i,k,j)))
opt(k) = opt(k+1) + tau*(pph(i,k,j)-pph(i,k+1,j))
END DO
optdepth = opt_depth
! ! Alter optical depth (specified in namelist) so it decreases from
! ! full value at +/-50 deg lat to 1/10 of its value at the poles
! if (abs(xlat(i,j)) .gt. 50.) then
! od_inc = (1./900.)*(abs(xlat(i,j))-50.)**2
! optdepth = opt_depth*(1 - 0.9*od_inc)
! endif
! Normalize for surface pressure
rnorm = optdepth*pph(i,kts,j)/pref/opt(kts)
DO k=kts,kte+1
optdpth_array(i,k,j) = max(opt(k)*rnorm,1e-10)
END DO
END DO
END DO
RETURN
END SUBROUTINE chicagodust
!====================================================================
SUBROUTINE dust_distribution(qst01,qst02,p,optdpth_array, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! evaluate optical depth at given pressure levels give the
! chemical tracer array
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
qst01, &
qst02, &
p
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
! Local variables
INTEGER:: i,j,k
REAL :: dust, wt1, wt2
wt1 = 0.25
wt2 = 1.0
! Remember that the order of K's is reversed between WRF and MM5.
! Arrays will be reversed to MM5 order in the actual radiation scheme
! so keep them in WRF order here
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kte+1,j)= 0.
DO k=kte, kts, -1
dust = wt1*qst01(i,k,j) + wt2*qst02(i,k,j)
dust = max( 1.e-8, dust ) !CEN 25 MAY 2007 - using this lower lim
optdpth_array(i,k,j)= optdpth_array(i,k+1,j) + &
dust*(p(i,k,j)-p(i,k+1,j))
END DO
END DO
END DO
RETURN
END SUBROUTINE dust_distribution
!====================================================================
!CEN aug 2011 - adding in rad ac dust the 'oxford' way with only one psize:
SUBROUTINE oxford_dust(dust1,p,dust_array,g,ddpp,rhod, qext, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! evaluate optical depth at given pressure levels give the
! chemical tracer array
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: &
dust1, &
p
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
dust_array
REAL, INTENT(IN) :: g, ddpp, qext, rhod
! Local variables
INTEGER:: i,j,k
REAL, parameter :: dustmin=1.e-8 !CEN 25 MAY 2007 - using this lower lim
REAL :: aerosol, qextrhor
qextrhor=0.75*qext/(rhod*(0.5*ddpp)) !!ddpp is diameter, want radius.
! Remember that the order of K's is reversed between WRF and MM5.
! Arrays will be reversed to MM5 order in the actual radiation scheme
! so keep them in WRF order here
DO j=jts,jte
DO i=its,ite
dust_array(i,kte+1,j)= 0.
DO k=kte, kts, -1
! aerosol(ig,l)=qextrhor*(pq(ig,l)+1.e-8)*(pplev(ig,l)-pplev(ig,l+1))/g
! where qextrhor=(3./4.)*qext/(1250.*ddpp)
! We want to ignore negative dust amounts in radiation scheme
aerosol = max(dustmin,qextrhor*dust1(i,k,j)*(p(i,k,j)-p(i,k+1,j))/g)
dust_array(i,k,j)= dust_array(i,k+1,j) + aerosol
END DO
END DO
END DO
RETURN
END SUBROUTINE oxford_dust
!====================================================================
subroutine inject_mcd_mgs(optdpth_array,tau_od, &
l_s,glat,glon,p, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte, &
julian, julday, gmt, &
secs_into_sol, dt )
!---------------------------------------------------------------------
! calculate dust injection rate necessary to match mcd dust
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: p
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT ) :: &
tau_od
real, intent(in) :: julian, dt
integer, intent(in) :: julday
real, intent(in) :: gmt, secs_into_sol
!local
REAL, dimension( ims:ime, jms:jme) :: delta
real(kind(0d0)) :: dls_prev, j2000, j2000_ott
real(kind(0d0)) :: djulian_prev, djulian, tmp
real :: ls_prev, delta_ls
real :: pi
pi = ACOS(-1.)
!dt in minutes
!tmp is the number of minutes into a day, negative for the day before.
tmp = mod((gmt*60. + (secs_into_sol/60.)),1440.) - dt
!again, julday is the start day, not the truncated current day
!bad code djulian_prev = mod(gmt*60 + xtime - dt, 1440.)/1440.0d0 + (julday-1)
!okay djulian_prev = (gmt*60 + xtime - dt)/1440.0d0 + (julday-1)
djulian_prev = mod((gmt*60 + (secs_into_sol/60.) - dt), 1440.0)/1440.0d0 + (floor(julian))
if (tmp < 0) then
!subtract 1 because I have gone to the previous day
djulian_prev=djulian_prev-1
endif
call mars24_j2000_ott_from_Mars_Solar_Date(djulian_prev, j2000_ott)
call mars24_mars_ls(j2000_ott, dls_prev)
ls_prev = dls_prev
delta_ls = l_s - ls_prev
if(ls_prev .gt. l_s) then
!we wrapped
delta_ls = delta_ls + 360.
endif
call delta_mcd_mgs(tau_od, delta,l_s,glat,glon, &
ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte )
tau_od = tau_od + delta * delta_ls * pi/180.
where(tau_od < 0) tau_od = 0.0
call da_mcd_mgs(optdpth_array, tau_od, l_s, glat, glon,p, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
end subroutine inject_mcd_mgs
!====================================================================
SUBROUTINE delta_mcd_mgs(tau_od, delta, l_s,glat,glon, &
ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte )
!---------------------------------------------------------------------
! calculate delta dust amount at given pressure levels using formula
! given in Mars Climate Database for an "MGS scenario"
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(OUT ) :: &
delta
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT ) :: &
tau_od
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, tauref, zp
real :: delta_zls, delta_taueq, &
delta_tauS, delta_tauN, delta_topdust, &
delta_tempval, delta_res, delta_zp, delta_tauref
real :: omin, omin_log, tempval
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
taueq = 0.2 + (0.5-0.2)*(COS(0.5*(gls-4.363))**14)
tauS = 0.1 + (0.5-0.1)*(COS(0.5*(gls-4.363))**14)
tauN = 0.1
delta_zls = cos(gls - 2.76)
delta_taueq = -(0.5-0.2)*14*0.5*(cos(0.5*(gls-4.363))**13)*sin(0.5*(gls-4.363))
delta_tauS = -(0.5-0.1)*14*0.5*(cos(0.5*(gls-4.363))**13)*sin(0.5*(gls-4.363))
delta_tauN = 0.0
DO j=jts,jte
DO i=its,ite
IF (glat(i,j) >= 0.) THEN
! Northern Hemisphere
tauref = tauN + (taueq-tauN)*0.5*(1+TANH(4.5-glat(i,j)*18./pi))
delta_tauref = delta_tauN + 0.5*(delta_taueq-delta_tauN)*(1+TANH(4.5-glat(i,j)*18./pi))
ELSE
! Southern Hemisphere
tauref = tauS + (taueq-tauS)*0.5*(1+TANH(4.5+glat(i,j)*18./pi))
delta_tauref = delta_tauS + 0.5*(delta_taueq-delta_tauS)*(1+TANH(4.5+glat(i,j)*18./pi))
END IF
delta(i,j) = delta_tauref
END DO
END DO
RETURN
END SUBROUTINE delta_mcd_mgs
!====================================================================
SUBROUTINE init_mcd_mgs(tau_od, l_s,glat,glon, &
ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte )
!---------------------------------------------------------------------
! Evaluate optical depth at given pressure levels using formula
! given in Mars Climate Database for an "MGS scenario"
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT ) :: &
tau_od
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, tauref, zp
real :: omin, omin_log, tempval
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
taueq = 0.2 + (0.5-0.2)*(COS(0.5*(gls-4.363))**14)
tauS = 0.1 + (0.5-0.1)*(COS(0.5*(gls-4.363))**14)
tauN = 0.1
DO j=jts,jte
DO i=its,ite
IF (glat(i,j) >= 0.) THEN
! Northern Hemisphere
! glat is in degrees here
tauref = tauN + (taueq-tauN)*0.5*(1+TANH(4.5-glat(i,j)*0.1))
ELSE
! Southern Hemisphere
tauref = tauS + (taueq-tauS)*0.5*(1+TANH(4.5+glat(i,j)*0.1))
END IF
tau_od(i,j) = tauref
END DO
END DO
RETURN
END SUBROUTINE init_mcd_mgs
!====================================================================
SUBROUTINE da_mcd_mgs(optdpth_array,tau_od, l_s,glat,glon,p, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! Evaluate optical depth at given pressure levels using formula
! given in Mars Climate Database for an "MGS scenario"
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: p
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: &
tau_od
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, tauref, zp
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kte+1,j) = 0.
topdust = 60.+18.*zls - (32.+18.*zls)*(SIN(glat(i,j))**4) &
- 8.*zls*(SIN(glat(i,j))**5)
tauref = tau_od(i,j)
DO k=kts,kte
zp=(700./p(i,k,j))**(70./topdust)
optdpth_array(i,k,j)= (tauref/700.) * p(i,k,j) * &
MAX( EXP(.007*(1.-MAX(zp,1.))) , 1.e-3 )
END DO
END DO
END DO
RETURN
END SUBROUTINE da_mcd_mgs
!====================================================================
SUBROUTINE mcd_mgs(optdpth_array,l_s,glat,glon,p, &
optical_depth_multiplier, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! Evaluate optical depth at given pressure levels using formula
! given in Mars Climate Database for an "MGS scenario"
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: p
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: optical_depth_multiplier ! coopted 'optical depth' namelist parameter
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, tauref, zp
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
taueq = 0.2 + (0.5-0.2)*(COS(0.5*(gls-4.363))**14)
tauS = 0.1 + (0.5-0.1)*(COS(0.5*(gls-4.363))**14)
tauN = 0.1
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kte+1,j) = 0.
topdust = 60.+18.*zls - (32.+18.*zls)*(SIN(glat(i,j))**4) &
- 8.*zls*(SIN(glat(i,j))**5)
IF (glat(i,j) >= 0.) THEN
! Northern Hemisphere
tauref = tauN + (taueq-tauN)*0.5*(1+TANH(4.5-glat(i,j)*18./pi))
ELSE
! Southern Hemisphere
tauref = tauS + (taueq-tauS)*0.5*(1+TANH(4.5+glat(i,j)*18./pi))
END IF
DO k=kts,kte
zp=(700./p(i,k,j))**(70./topdust)
optdpth_array(i,k,j)= optical_depth_multiplier * &
(tauref/700.) * p(i,k,j) * &
MAX( EXP(.007*(1.-MAX(zp,1.))) , 1.e-3 )
END DO
END DO
END DO
RETURN
END SUBROUTINE mcd_mgs
!====================================================================
SUBROUTINE mcd_mgsx2(optdpth_array,l_s,glat,glon,p, & !CEN May 27 2010 - added
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! Evaluate optical depth at given pressure levels using formula
! given in Mars Climate Database for an "MGS scenario"
! HOWEVER, worried about this definition being for IR (not VIS as assumed)
! am doubling amounts to look at result
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: p
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, tauref, zp
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
taueq = 0.2 + (0.5-0.2)*(COS(0.5*(gls-4.363))**14)
tauS = 0.1 + (0.5-0.1)*(COS(0.5*(gls-4.363))**14)
tauN = 0.1
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kte+1,j) = 0.
topdust = 60.+18.*zls - (32.+18.*zls)*(SIN(glat(i,j))**4) &
- 8.*zls*(SIN(glat(i,j))**5)
IF (glat(i,j) >= 0.) THEN
! Northern Hemisphere
tauref = tauN + (taueq-tauN)*0.5*(1+TANH(4.5-glat(i,j)*18./pi))
ELSE
! Southern Hemisphere
tauref = tauS + (taueq-tauS)*0.5*(1+TANH(4.5+glat(i,j)*18./pi))
END IF
DO k=kts,kte
zp=(700./p(i,k,j))**(70./topdust)
optdpth_array(i,k,j)= 2.*(tauref/700.) * p(i,k,j) * &
MAX( EXP(.007*(1.-MAX(zp,1.))) , 1.e-3 )
END DO
END DO
END DO
RETURN
END SUBROUTINE mcd_mgsx2
!====================================================================
SUBROUTINE mcs_dust(optdpth_array,l_s,glat,glon,p, &
ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte )
!---------------------------------------------------------------------
! calculate dust amount using a very simplistic "fit" to the MCS
! "High Altitude Tropical Dust Maximum"
!---------------------------------------------------------------------
IMPLICIT NONE
!---------------------------------------------------------------------
INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde, &
ims,ime, jms,jme, kms,kme, &
its,ite, jts,jte, kts,kte
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(IN ) :: p
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: glat, glon
REAL, INTENT(IN ) :: l_s
REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT(OUT ) :: &
optdpth_array
! Local variables
INTEGER:: i,j,k
REAL :: pi, gls, zls
REAL :: taueq, tauS, tauN
REAL :: topdust, zp
real :: pmax, log_pmax, pref, &
log_pref, frac, inv_frac, scale, &
q_con, phi, log_pval
REAL, DIMENSION( ims:ime, jms:jme ) :: tau_od
pi = ACOS(-1.)
gls = l_s*pi/180.
zls = SIN(gls-2.76)
call init_mcd_mgs(tau_od, l_s, glat, glon, &
ids,ide, jds,jde, &
ims,ime, jms,jme, &
its,ite, jts,jte )
pmax = 40.
log_pmax = log(pmax)
pref = 700.
log_pref=log(pref)
frac = 0.5
inv_frac=1./frac
DO j=jts,jte
DO i=its,ite
optdpth_array(i,kte+1,j) = 0.
topdust = 60.+18.*zls - (32.+18.*zls)*(SIN(glat(i,j))**4) &
- 8.*zls*(SIN(glat(i,j))**5)
DO k=kts,kte
zp=(pref/p(i,k,j))**(70./topdust)
q_con = MAX(EXP(.007*(1.-MAX(zp,1.))), 1e-3)
log_pval=log_pmax
if (p(i,k,j) > pmax) log_pval = log(p(i,k,j))
if(p(i,k,j) < pref) then
phi = pi - (pi/2.) * (log_pmax-log_pval)/(log_pmax-log_pref)
scale = (1-frac)*cos(phi)**2 + frac
scale = scale*inv_frac
else
scale = 1.0
endif
optdpth_array(i,k,j)= (tau_od(i,j)/700.) * p(i,k,j) * scale * q_con
END DO
END DO
END DO
RETURN
END SUBROUTINE mcs_dust
!====================================================================
SUBROUTINE mcd_viking(optdpth_array,l_s,glat,glon,p, &