forked from mikedurand/EnKFYampa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss_model.f90
2413 lines (2053 loc) · 67 KB
/
ss_model.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
SUBROUTINE SS_MODEL(CTRL,FREQ,TETAD,Y,TB_UBC,AUX_INS,TB_OUT,pixel,replicate,&
rank,meas)
! -----------------------------------------------------------------------------
!
! SOIL AND SNOW RADIATIVE TRANSFER MODEL
!
! FORTRAN 90 VERSION OF MEMLS PROGRAM (ORIGINALLY WRITTEN IN MATLAB BY
! WIESMANN AND MATZLER TO COMPUTE BRIGHTNESS TEMPERATURES OF N-LAYERED
! SNOWPACKS) INTEGRATED WITH A SOIL RADIATIVE TRANSFER SCHEME. THIS
! VERSION OF THE CODE IS SET UP TO PERFORM CALCULATIONS BASED ON DATA FROM
! A SINGLE SNOWPACK AT THE FREQUENCIES AND ANGLES SPECIFIED IN THE INPUTS.
! IF THE NUMBER OF LAYERS SPECIFIED IN CTRL(2) IS ZERO, THEN THIS CODE
! WILL COMPUTE THE BARE SOIL BRIGHTNESS TEMPERATURE
!
! IN THE CURRENT VERSION, EACH SNOWPACK MUST HAVE THE SAME NUMBER OF LAYERS.
! IN ADDITION, THIS CODE IS DESIGNED TO WORK WITH SNOWPACKS WITH INCOHERENT
! LAYERS OR WITH ONE COHERENT LAYER. MORE SPECIFICALLY, THE CODE
! CANNOT HANDLE THE CASE WHERE THERE ARE SUCCEEDING COHERENT LAYERS. IN
! THIS CASE, THE PROGRAM WILL WRITE 999 TO THE OUTPUT FILE.
!
! ----------------------------------------------------------------------------
!
! DESCRIPTION OF INPUTS AND OUTPUTS (SEE JOURNAL ENTRY 19 SEP 05)
!
! THE CTRL VECTOR SPECIFIES NINE OVERALL RUN CONTROLS, NOT ALL OF WHICH
! ARE USED IN THIS MODEL. CTRL=(N_CACLS,N_LYRS,ATM_SWITCH,CAN_SWITCH,
! N_AUX_INS,N_SNOW_INS,N_CAN_INS,N_ATM_INS,N_FREQ)
! THE FREQ AND TETAD VECTORS SPECIFY AT WHICH FREQUENCIES CALCULATIONS
! ARE TO BE DONE.
! THE Y ARRAY SPECIFIES SNOW INPUTS. THERE IS ONE ROW FOR EACH SNOW
! LAYER SPECIFIED IN CTRL(2), ONE COLUMN SPECIFIED FOR EACH SNOW
! VARIABLE,IN ORDER: LAYER THICKNESS [M], LAYER DENSITY [KG/M3],
! LAYER GRAIN DIAMETER [M], LAYER LIQUID WATER CONTENT [FRAC],
! LAYER TEMPERATURE [K].
! THE TB_UBC ARRAY SPECIFIES THE UPPER BOUNDARY CONDITION BRIGHTNESS
! TEMPERATURE (SKY, VEGETATION, COSMIC). IT HAS TWO ROWS (FOR H AND V
! POLARIZATION) AND CTRL(9) COLUMNS: ONE FOR EACH FREQUENCY.
! THE AUX_INS ARRAY SPECIFIES SOME AUXILIARY INPUTS. THESE INCLUDE (IN
! ORDER): N_LYRS, SOIL TEMPERATURE [K], SOIL SATURATION [FRAC], SOIL
! POROSITY [FRAC], AND THE CONSTANT OF PROPORTIONALITY BETWEEN THE
! GRAIN SIZE AND THE CORRELATION LENGTH.
!
! THE TB_OUT ARRAY CONTAINS THE CALCULATED BRIGHTNESS TEMPERATURE OUTPUTS
! AT EACH POLARIZATION (ROWS) AND FREQUENCY (COLUMNS).
!
! ----------------------------------------------------------------------------
!
! 1.DESCRIPTION. THE CODE IS A TRANSLATION OF THE MEMLS2 CODE RECEIVED
! THROUGH CORRESPONDENCE WITH MATZLER AND A SOIL RADIATIVE TRANSFER
! MODEL RECEIVED THROUGH CORRESPONDENCE WITH PULLIAINEN SOMETIME IN 2003.
! THE MEMLS CODE USES THE GROUND REFLECTIVITY AND THE SNOWPACK DATA TO
! COMPUTE THE BRIGHTNESS TEMPERATURE OF THE SNOWPACK. THE CODE WAS
! TRANSLATED TO FORTRAN IN ORDER TO SAVE COMPUTATION TIME IN A DATA
! ASSIMILATION SCHEME IN WHICH MILLIONS OF CALLS MUST BE MADE TO THE
! RADIATIVE TRANSFER MODEL . IN TESTS, ONE HUNDRED BRIGHTNESS TEMPERATURE
! CALCULATIONS TOOK TEN TIMES LESS PROCESSOR TIME IN THIS FORTRAN VERSION
! THAN IN THE ORIGINAL MATLAB. EXTENSIVE VERIFICATION WAS PERFORMED USING
! SNOWPIT DATA FOR NINE DAYS IN ONE WINTER DURING THE CLPX PROGRAM AS WELL
! AS 3-LAYER SNOWMODEL RESULTS FROM THE MODIFIED SAST (SUN ET AL, 99 IN
! IN JGR) + SSIB MODEL RUN AT MAMMOTH MOUNTAIN, TO ENSURE THAT THE FORTRAN
! CODE PRODUCES IDENTICAL RESULTS AS THE MATLAB CODE.
!
! 2. MODIFICATION. THE MAIN CHANGE MADE TO THE MEMLS CODE IN THE
! TRANSLATION PROCESS WAS THAT THE VAN POLDER APPROXIMATION (EFFECTIVE
! MIXING THEORY) WAS NO LONGER BEING USED IN THE MATLAB CODES WHEN I
! RECEIVED THEM. IN FACT, THE REAL PART OF THE SNOW DIELECTRIC WAS USED
! INSTEAD IN SEVERAL SUBROUTINES. THIS WAS SLIGHTLY INCONSISTENT WITH THE
! PAPERS, SO (FOLLOWING MATZLER'S ADVICE VIA EMAIL) I WROTE A NEW 'POLDER'
! SUBROUTINE WHICH USES THE NEWTON-RAPHSON APPROXIMATION TO SOLVE FOR THE
! SNOW EFFECTIVE PERMITTIVITY - SEE MATZLER'S 1996 PAPER IN IEEE FOR THE
! EQUATIONS AND THE SUBROUTINE COMMENTS BELOW. ACCORDING TO COMPARISON
! WITH THE SNOWPIT DATA RESULTS, THE EFFECT OF USING THE SNOW DIELECTRIC
! INSTEAD OF EFFECTIVE PERMITTIVITY ON THE BRIGHTNESS TEMPREATURE WAS
! MINIMAL (~0.1 DEGREE). HOWEVER, BECAUSE I COULD NOT TEST WITH A MORE
! EXTENSIVE DATASET, I LEFT THE SLIGHTLY MORE COMPUTATIONALLY EXPENSIVE
! EFFECTIVE PERMITTIVITY CALCULATION IN PLACE FOR THE SAKE OF INTERNAL
! CONSISTENCY.
!
! ANOTHER CHANGE THAT I MADE TO MEMLS WAS TO SET UP THE PROGRAM TO PASS IN
! SNOW GRAIN DIAMETER SINCE THIS IS USUALLY WHAT IS MEASUSRED IN SNOWPITS
! AND MODELED BY PROGNOSTIC EQUATIONS IN SNOW MODELS. THE CONSTANT OF
! PROPORTIONALITY BETWEEN THE GRAIN DIAMETER AND THE CORRELATION LENGTH (SEE
! MATLZER, 2002 IN JOURNAL OF GLACIOLOGY) IS ALSO PASSED IN.
!
! A THIRD CHANGE I MADE TO MEMLS WAS TO USE A SWITCH TO DETERMINE WHETHER
! THE BORN APPROXIMATION OR THE EMPIRICAL SCATTERING COEFFICIENT WOULD BE
! USED. IF THE MAXIMUM CORRELATION LENGTH IN THE SNOWPACK IS GREATER THAN
! 0.33 MM, THE BORN APPROXIMATION IS USED; OTHERWISE, THE EMPIRICAL FORMULA
! IS USED.
!
! 3. COMPLETENESS. I TRANSLATED EVERYTHING PRECISELY AS IT WAS IN THE
! MATLAB CODE AS CLOSELY AS POSSIBLE. THE ONLY EXCEPTION WAS THAT (BECAUSE
! I TYPICALLY DON'T WORK WITH SNOWPIT DATA WITH VERY THIN LAYERS) I REMOVED
! THE ABILITY TO DEAL WITH SUCCEEDING COHERENT SNOWPACK LAYERS IN THE
! INTEREST OF FINISHING THE TRANSLATION IN A TIMELY MANNER. I TRANSLATED
! ONLY THE BEGINNING OF THE SLRED SUBROUTINE, AND SET IT UP TO WRITE 999 TO
! THE OUTPUT FILE IF IT FINDS SUCCEEDING COHERENT LAYERS. ISOLATED COHERENT
! LAYERS ARE HANDLED CORRECTLY. THE EXCEPTION IS FOR THREE-LAYER SNOWPACKS;
! ANY COMBINATION OF COHERENT LAYERS SHOULD GIVE CORRECT RESULTS FOR THREE-
! LAYER PACKS.
!
IMPLICIT NONE
! 0. PRELIMINARIES
! A. DECLARATIONS
! 0.INPUTS AND OUTPUTS
INTEGER,INTENT(IN) :: CTRL(9)
REAL,INTENT(IN) :: AUX_INS(5),TB_UBC(2,CTRL(9)),FREQ(CTRL(9)),TETAD(CTRL(9))
REAL,INTENT(IN) :: Y(CTRL(2),CTRL(6))
REAL,INTENT(OUT):: TB_OUT(2,CTRL(9))
! 1.FOR PART 1
REAL, DIMENSION(:), ALLOCATABLE :: SNOWDATA,TI,WIFR,ROIKG,DI,GDI,&
ROI,GDIMM,PCI,EPSI,EPSII,GAI,NS,TEI,DEI,SIH,SIV
REAL,DIMENSION(:), ALLOCATABLE :: XNUM,XROI,XEPSI,XEPSII,XTEI,&
XSIH,XSIV,XDI,XDEI,XTI,XPCI,XWIFR,XGAI
REAL,DIMENSION(:), ALLOCATABLE :: RROI,REPSI,REPSII,RTEI,RSIH,&
RSIV,RDI,RDEI,RTI,RPCI,RWIFR,RGAI
REAL GND_SIG,GND_EPS,MJU0,EPS0,PI,TGS,SNGDPCI,TSKYH,&
TSKYV,SASTPOROS,TETA,SOILSATURATION,GND_TEMP,GND_MV,MAXPCI,&
VEG_HEIGHT,VEG_TEMP,MG,S,NDL_THK,NDL_LGTH,NDL_NUM,T0,P0,MOIST0
INTEGER SCCHO,I,NUM,NFREQ,K,RNUM,MONTH,VEG_SWITCH,ATM_SWITCH
! 2.FOR PART 2
REAL EPS_T,TETAD_SOIL,EPS_B
COMPLEX, DIMENSION(:), ALLOCATABLE :: EPSR
COMPLEX EPS_UPPER
REAL KSIG,S0H,S0V
! 3.FOR PART 3
REAL,DIMENSION(:),ALLOCATABLE :: GBIH,GBIV,GS6,GA2I,TSCAT,&
RSIHLONG,RSIVLONG
! 4.FOR PART 4
REAL,DIMENSION(:),ALLOCATABLE :: RI,TRI,DH,DV
!REAL TSG_H,TSG_V,ESG_H,ESG_V
! 5.FOR PART 5
COMPLEX EVEG,ESW
REAL TCAN_V,TCAN_H,CAN_LOSS_H,CAN_LOSS_V,EFSG_H,EFSG_V,TFSG_H,&
TFSG_V,TATM,ATM_TRAN,TAFSG_H,TAFSG_V
integer,intent(in):: pixel,replicate,rank,meas
! B. CONTROL STATEMENTS
NFREQ=CTRL(9) ! THIS CODE LOOPS OVER THE NUMBER OF FREQUENCIES FOR ONE SET
! OF SNOW PROPERTIES.
!NUM=aux_ins(1) ! NUMBER OF LAYERS IN THE SNOWPACK
NUM=ctrl(2) ! NUMBER OF LAYERS IN THE SNOWPACK
! C. ALLOCATE AND EXTRACT STATEMENTS
ALLOCATE(DI(1:NUM),ROIKG(1:NUM),GDI(1:NUM),WIFR(1:NUM),TI(1:NUM))
DI(1:NUM)= Y(1:NUM,1)
ROIKG(1:NUM)=Y(1:NUM,2)
GDI(1:NUM)= Y(1:NUM,3)
WIFR(1:NUM)= Y(1:NUM,4)
TI(1:NUM)= Y(1:NUM,5)
GND_TEMP=AUX_INS(2)
SOILSATURATION=AUX_INS(3)
SASTPOROS=AUX_INS(4)
SNGDPCI=AUX_INS(5)
GND_MV=SOILSATURATION*SASTPOROS
MJU0=1.2566e-006
EPS0=8.8542e-012
! 1. CHECK TO MAKE SURE THERE IS SNOW. OTHERWISE DEAL WITH SOIL ONLY
! NOTE: AUX_INS(1) CONTAINS 0 IN THE CASE OF NO SNOW, THOUGH NUM
! WILL BE 1 TO AVOID INCORRECT ARRAY ALLOCATIONS
IF (AUX_INS(1).EQ.0) THEN
DO K=1,NFREQ
! THERE IS NO SNOWPACK, SO COMPUTE REFLECTIVITY OF GROUND AND OBTAIN
! OUTPUT BRIGHTNESS TEMPERATURES
EPS_T=1.
TETAD_SOIL=TETAD(K)
EPS_UPPER=1.0003 !DIELECTRIC PERMITTIVITY OF AIR
gnd_sig=0.002 !i think...
KSIG=REAL(2*PI*FREQ(K)*1E9*(MJU0*EPS0*EPS_UPPER)**0.5)*GND_SIG
CALL RUFFSOIL(FREQ(K)*1E9,GND_MV,GND_TEMP,KSIG,TETAD_SOIL,&
EPS_UPPER,S0H,S0V)
TSKYH=TB_UBC(1,K)
TSKYV=TB_UBC(2,K)
TB_OUT(1,K)=(1-S0H)*GND_TEMP+S0H*TSKYH
TB_OUT(2,K)=(1-S0V)*GND_TEMP+S0V*TSKYV
END DO
RETURN !TO MAIN PROGRAM
END IF
! 2. COMPUTE BRIGHTNESS TEMPERATURE OF SNOWPACK AND SOIL
DO K=1,NFREQ
! A. PRELIMINARIES
! A.1. DEFINE CONSTANTS
GND_SIG=0.002
GND_EPS=0
! MJU0=1.2566e-006
! EPS0=8.8542e-012
PI=3.14159
! A.2. ALLOCATE AND UNIT CONVERSION STATEMENTS
ALLOCATE(ROI(1:NUM),GDIMM(1:NUM),PCI(1:NUM))
ROI=ROIKG/1000
TETA=TETAD(K)*PI/180
GDIMM=GDI*1000
PCI=GDIMM*SNGDPCI
! A.3. DETERMINE WHICH SCATTERING COEFFICIENT COMPUTATION METHOD TO
! USE THE VALUE OF 0.33 USED HERE FROM PERSONAL CORRESPONDENCE WITH
! MATZLER
MAXPCI=MAXVAL(PCI)
IF (MAXPCI<0.33) THEN
SCCHO=1 ! USE EMPIRICAL SCATTERING COEFFICIENT FROM W&M 99
ELSE
SCCHO=2 ! USE BORN APPROXIMATION FROM MATZLER AND WIESMANN 99
ENDIF
!THIS OPTION OUGHT TO BE AUTOMATED:
!DURING MY WORK WITH SSIB3+MEMLS TO MODEL GBMR-7 TB, I NEEDED TO USE SCCHO=2
!SCCHO=2
!IN ORDER TO SAVE TIME FOR THE SYNTHETIC TESTS, HOWEVER, I USED SCCHO=1
SCCHO=1
! B. COMPUTE RADIATIVE TRANSFER PROPERTIES OF SNOW
ALLOCATE(EPSI(1:NUM),EPSII(1:NUM),GAI(1:NUM),NS(1:NUM),&
TEI(1:NUM+1),DEI(1:NUM),SIH(1:NUM),SIV(1:NUM),XROI(1:NUM),&
XEPSI(1:NUM),XEPSII(1:NUM),XTEI(1:NUM+1),XSIH(1:NUM),&
XSIV(1:NUM),XDI(1:NUM),XDEI(1:NUM),XTI(1:NUM),XPCI(1:NUM),&
XWIFR(1:NUM),XGAI(1:NUM))
CALL RO2EPSD(ROI,TI,FREQ(K),EPSI,EPSII,NUM,pixel,replicate,rank,meas,k)
CALL MIXMOD(FREQ(K),TI,WIFR,EPSI,EPSII,NUM)
CALL ABSCOEFF(EPSI,EPSII,TI,FREQ(K),WIFR,GAI,NUM)
NS=EPSI**0.5
TEI(1:NUM)=ASIN(SIN(TETA)/NS)
TEI(NUM+1)=TETA
CALL PFADI(TEI,DI,DEI,NUM)
CALL FRESNELC(TEI,EPSI,SIH,SIV,NUM)
CALL SLRED(NUM,ROI,EPSI,EPSII,TEI,SIH,SIV,DI,DEI,TI,PCI,WIFR,&
GAI,FREQ(K),RNUM,XROI,XEPSI,XEPSII,XTEI,XSIH,XSIV,XDI,XDEI,&
XTI,XPCI,XWIFR,XGAI,pixel,replicate,rank,meas)
ALLOCATE(RROI(RNUM),REPSI(RNUM),REPSII(RNUM),&
RTEI(RNUM+1),RSIH(RNUM),RSIV(RNUM),RDI(RNUM),&
RDEI(RNUM),RTI(RNUM),RPCI(RNUM),RWIFR(RNUM),&
RGAI(RNUM))
DO I=1,RNUM
RROI(I)=XROI(I)
REPSI(I)=XEPSI(I)
REPSII(I)=XEPSII(I)
RSIH(I)=XSIH(I)
RSIV(I)=XSIV(I)
RDI(I)=XDI(I)
RDEI(I)=XDEI(I)
RTI(I)=XTI(I)
RPCI(I)=XPCI(I)
RWIFR(I)=XWIFR(I)
RGAI(I)=XGAI(I)
END DO
DO I=1,RNUM+1
RTEI(I)=XTEI(I)
END DO
! C. COMPUTE GROUND REFLECTIVITIES
ALLOCATE(EPSR(1:RNUM))
EPS_T=1.
TETAD_SOIL=TETAD(K)
DO I=RNUM,1,-1
EPS_B=EPSI(I)
CALL AOT(EPS_T,EPS_B,TETAD_SOIL)
EPS_T=EPS_B
END DO
EPSR=CMPLX(REPSI,(-1*REPSII))
EPS_UPPER=EPSR(1)
KSIG=REAL(2*PI*FREQ(K)*1E9*(MJU0*EPS0*EPS_UPPER)**0.5)*GND_SIG
CALL RUFFSOIL(FREQ(K)*1E9,GND_MV,GND_TEMP,KSIG,TETAD_SOIL,&
EPS_UPPER,S0H,S0V)
! D. COMPUTE SCATTERING COEFFICIENTS, REFLECTIVITIES AND
! TRANSMISSIVITIES
DEALLOCATE(RTEI,RDEI) ! BECAUSE THESE ARRAYS WILL CHANGE SIZES
ALLOCATE(GBIH(RNUM),GBIV(RNUM),GS6(RNUM),GA2I(RNUM),&
TSCAT(RNUM),RTEI(RNUM),RDEI(RNUM),RSIHLONG(RNUM+1),&
RSIVLONG(RNUM+1))
CALL SCCOEFF(RROI,RTI,RPCI,FREQ(K),RWIFR,RGAI,SCCHO,GBIH,GBIV,&
GS6,GA2I,RNUM,REPSI,REPSII,pixel,replicate,rank,meas)
CALL PFADC(TETA,RDI,REPSI,GS6,RDEI,RTEI,TSCAT,RNUM)
RSIHLONG(1)=S0H
RSIHLONG(2:RNUM+1)=RSIH
RSIVLONG(1)=S0V
RSIVLONG(2:RNUM+1)=RSIV
CALL POLMIX(TSCAT,RSIHLONG,RSIVLONG,RNUM)
! E. COMPUTE BRIGHTNESS TEMPERATURES AND EMISSIVITIES OF SNOWPACK AND
! GROUND
ALLOCATE(RI(1:RNUM),TRI(1:RNUM),DH(1:RNUM),DV(1:RNUM))
TSKYH=TB_UBC(1,K)
TSKYV=TB_UBC(2,K)
CALL RT(GA2I,GBIH,DEI,RI,TRI,RNUM)
CALL LAYER(RI,RSIHLONG,TRI,RTI,GND_TEMP,TSKYH,DH,RNUM,pixel)
TB_OUT(1,K)=(1-RSIHLONG(RNUM+1))*DH(RNUM)+RSIHLONG(RNUM+1)*TSKYH
CALL RT(GA2I,GBIV,RDEI,RI,TRI,RNUM)
CALL LAYER(RI,RSIVLONG,TRI,TI,GND_TEMP,TSKYV,DV,RNUM,pixel)
TB_OUT(2,K)=(1-RSIVLONG(RNUM+1))*DV(RNUM)+RSIVLONG(RNUM+1)*TSKYV
! CALL EMISSIVITY(GA2I,GBIH,GBIV,RDEI,RSIHLONG,RSIVLONG,GND_TEMP,RTI,&
! ESG_H,ESG_V,RNUM)
! F. DEALLOCATE VARIABLE SPACE
DEALLOCATE(ROI,GDIMM,PCI,EPSI,&
EPSII,GAI,NS,TEI,DEI,SIH,SIV,EPSR,GBIH,GBIV,GS6,GA2I,TSCAT,&
RSIHLONG,RSIVLONG,RI,TRI,DH,DV)
DEALLOCATE(RROI,REPSI,REPSII,RTEI,RSIH,RSIV,RDI,RDEI,RTI,RPCI,RWIFR,RGAI,&
XROI,XEPSI,XEPSII,XTEI,XSIH,XSIV,XDI,XDEI,XTI,XPCI,XWIFR,XGAI)
END DO
END SUBROUTINE SS_MODEL
! -------------------------------------------------------------------------
!
SUBROUTINE ABSCOEFF(EPSI,EPSII,TI,FREQ,WIFR,GAI,NUM)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER
!
! COMPUTES THE ABSORPTION COEFFICIENT FROM THE DIELECTRIC PROPERTIES
!
!
! [GAI] = ABSCOEFF(EPSI,EPSII,TI,FREQ,WI)
! GAI: ABSORPTION COEFFICIENT [M^-1]
! EPSI: REAL PART DIEL
! EPSII: IMAGINARY PART DIEL
! TI: PHYSICAL TEMPERATURE
! FREQ: FREQUENCY [GHZ]
! WI: VOLUMETRIC LIQUID WATER CONTENT
!
! VERSION HISTORY:
! 1.0 WI 15.7.95
! 1.1 WI 12.11.97 MORE PRECISE FORMULA FOR GAI USED
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES: NONE
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL, INTENT(IN) :: EPSI(NUM),EPSII(NUM),TI(NUM),FREQ,WIFR(NUM)
REAL, INTENT(OUT) :: GAI(NUM)
REAL C,PI
C=2.99793
PI=3.14159
GAI=((2*PI*10*FREQ)*EPSII)/(C*(EPSI-(EPSII**2/4*EPSI))**0.5)
END SUBROUTINE ABSCOEFF
! -------------------------------------------------------------------------
!
SUBROUTINE AOT(EPS_T,EPS_B,TETAD_SOIL)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM PULLIAINEN
!
! FUNCTION FOR CALCULATING THE ANGLE OF TRANSMISSION
! IN THE CASE OF A PLANE BOUNDARY BETWEEN TWO
! MEDIAS WITH COMPLEX PERMITTIVITIES
! K. TIGERSTEDT/97
!
! INPUT PARAMETERS:
! EPS_T = TOP LAYER EPSILON_R [COMPLEX],
! EPS_B = BOTTOM LAYER EPSILON_R [COMPLEX]
! THETAD = INCIDENCE ANGLE [DEG]
! OUTPUT:
! KSID = TRANSMISSION ANGLE IN BOTTOM LAYER [DEG]
!
! VERSION HISTORY:
! 1.0 KT ?.?.97
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
IMPLICIT NONE
REAL, INTENT(IN) :: EPS_T,EPS_B
REAL, INTENT(INOUT) :: TETAD_SOIL
REAL THETA,KSI,PI
COMPLEX NUMERATOR,DENOMINATOR
PI=3.14159
THETA=TETAD_SOIL/180*PI
NUMERATOR=EPS_T**0.5*SIN(THETA)
DENOMINATOR=(EPS_B-EPS_T*(1-COS(THETA)**2))**0.5
KSI=ATAN(REAL(NUMERATOR)/REAL(DENOMINATOR))
TETAD_SOIL=KSI/PI*180
END SUBROUTINE AOT
! -------------------------------------------------------------------------
!
SUBROUTINE BORN(K,VFI,PCIMM,EPSI,EICE,GB6,GC6,GF6,GS6,NUM,pixel,replicate,&
rank,meas)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER, MODIFIED BY MIKE... SEE
! VERSION HISTORY
!
! CALCULATES THE SCATTERING COEFFICIENT USING BORN APPROXIMATION
!
! [GB6,GC6,GF6,GS6] = BORNA(K,VFI,PCI,EPSI,EICE,EPSEFF,KP)
! GB6: 6-FLUX BACK SCATTERING COEFFICIENT
! GC6: 6-FLUX CROSS SCATTERING COEFFICIENT
! GF6: 6-FLUX FORWARD SCATTERING COEFFICIENT
! GS6: 6-FLUX SCATTERING COEFFICIENT
! K: WAVE NUMBER
! VFI: VOLUME FRACTION OF ICE
! PCI: CORRELATION LENGTH
! EPSI: DIELECTRIC CONSTANT OF SNOW
! EICE: DIELECTRIC CONSTANT OF SNOW
! EPSEFF: EFFECTIVE PERMITTIVITY
!
! VERSION HISTORY:
! 1.0 WI 27.05.98
! 2.0 WI 31.03.05. TRANSLATED TO FORTRAN BY MIKE. BORNA AND
! BORNSNK COMBINED INTO ONE. CALL TO POLDER
! IS USED TO COMPUTE EFFECTIVE PERMITTIVITY
! 3.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES:
!
! COPYRIGHT (C) 1998 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL, INTENT(IN) :: K,VFI(NUM),PCIMM(NUM),EPSI(NUM),EICE
REAL, INTENT(OUT) :: GB6(NUM),GC6(NUM),GF6(NUM),GS6(NUM)
REAL,DIMENSION(:),ALLOCATABLE :: PCI,A,A3,EA,EA3,K1,K3,KP,MUC,AA,XX,BB,BT,BF,&
BTOT, EPSEFF,NEGMUC
INTEGER STEPS,ROW,ARG_LENGTH(2),I
integer,intent(in) :: pixel,replicate,rank,meas
ALLOCATE( PCI(NUM),A(NUM),A3(NUM),EA(NUM),EA3(NUM),K1(NUM),K3(NUM),KP(NUM),&
MUC(NUM),AA(NUM),XX(NUM),BB(NUM),BT(NUM),BF(NUM),BTOT(NUM),&
EPSEFF(NUM),NEGMUC(NUM) )
! 0) CONSTANTS AND CONVERSION
STEPS=11
PCI=PCIMM*0.001
! 1) COMPUTE FIELD FACTOR AND DEPOLARIZATION RATIO, FROM BORNSNK
! 'A' AFTER NOTE 10, MATZLER 1997, COMMENT AND CALL FROM BORNSNK
CALL SNOWAO(VFI,A,NUM)
! 2) COMPUTE EFFECTIVE PERMITTIVITY USING NEW FUNCTION POLDER.M
CALL POLDER(VFI,A,EICE,EPSI,EPSEFF,NUM)
! 3) COMPUTE KP, THE SQUARED RATIO BETWEEN INTERNAL / EXTERNAL FIELDS
! THIS CODE ORIGINALLY IN BORNSNK, STARTING AT LINE 41
A3=1-2*A
EA=EPSEFF*(1-A)+A
EA3=EPSEFF*(1-A3)+A3
K1=(EA/(EA+A*(EICE-1)))**2
K3=(EA3/(EA3+A3*(EICE-1)))**2
KP=(2*K1+K3)/3
! 4) COMPUTE SCATTERING COEFFICIENTS, FROM BORNA, STARTING AT LINE 34
!NOTE: THE NEXT LINE CONSISTENT WITH MATZLER AND WIESMANN 99 PAPER EQUATION (7).
! BASED ON CORRESPONDENCE WITH MATZLER, EPSEFF=N^2
MUC=((EPSEFF-1)/EPSEFF)**0.5
AA=2*(PCI*K)**3*K*VFI*(1-VFI)*(EICE-1)**2*KP
XX=PCI*K*EPSI**0.5
! 5) TRIPLE INTEGRATION
! A) BACKWARD SCATTERING
ARG_LENGTH=(/1, NUM/)
NEGMUC=-1.*MUC
!CALL INTEGRMUI(XX,MUC,1.,-1.,-1.*MUC,STEPS,NUM,BB,ARG_LENGTH)
CALL INTEGRMUI(XX,MUC,1.,-1.,NEGMUC,STEPS,NUM,BB,ARG_LENGTH)
! B) TRANSVERSE SCATTERING
ARG_LENGTH=(/NUM, NUM/)
!CALL INTEGRMUI(XX,MUC,1.,-1.*MUC,MUC,STEPS,NUM,BT,ARG_LENGTH)
CALL INTEGRMUI(XX,MUC,1.,NEGMUC,MUC,STEPS,NUM,BT,ARG_LENGTH)
! C) FORWARD SCATTERING
ARG_LENGTH=(/NUM, 1/)
CALL INTEGRMUI(XX,MUC,1.,MUC,1.,STEPS,NUM,BF,ARG_LENGTH)
! 6) CALCULATION OF SCATTERING COEFFICIENTS
BTOT=BB+BT+BF
GB6=AA*BB
GC6=0.25*AA*BT
GF6=AA*BF
GS6=AA*BTOT
DEALLOCATE( PCI,A,A3,EA,EA3,K1,K3,KP,MUC,AA,XX,BB,BT,BF,BTOT, EPSEFF,NEGMUC)
END SUBROUTINE BORN
! -------------------------------------------------------------------------
!
SUBROUTINE EMISSIVITY(GA2I,GBIH,GBIV,DEI,SIHLONG,SIVLONG,GND_TEMP,TI,&
EH,EV,NUM)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER, MODIFIED BY MIKE.
! SEE VERSION HISTORY
!
! CALCULATES THE SCATTERING COEFFICIENT USING BORN APPROXIMATION
!
! GA2I: ABSORPTION COEFFICIENT
! GBIH: 2-FLUX SCATTERING COEFFICIENT, H POLARIZATION
! GBIV: 2-FLUX SCATTERING COEFFICIENT, V POLARIZATION
! DEI: EFFECTIVE PATH LENGTH [M]
! SIHLONG: LAYER INTERFACE REFLECTIVITY, H POLARIZATION
! SIVLONG: LAYER INTERFACE REFLECTIVITY, V POLARIZATION
! EH: EMISSIVITY, H POLARIZATION
! EV: EMISSIVITY, V POLARIZATION
!
! VERSION HISTORY:
! 1.0 MD 1 APR 05 THIS CODE WAS PART OF LMAIN. I TRANSLATED TO
! FORTRAN FROM MATLAB AND MOVED IT TO A SEPARATE SUBROUTINE.
! COMPARE WIESMANN AND MATZLER, 99 EQN (8)
!
! USES: RT, LAYER
!
! COPYRIGHT (C) 1998 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL,INTENT(IN) :: GA2I(NUM),GBIH(NUM),GBIV(NUM),DEI(NUM),&
SIHLONG(NUM+1),SIVLONG(NUM+1),GND_TEMP,&
TI(NUM)
REAL,INTENT(OUT) :: EH,EV
REAL RI(NUM),TRI(NUM),DH(NUM),DV(NUM),TBH0,TBH100,TBV0,TBV100,TSKY
! HORIZONTAL BRIGHTNESS TEMPERATURES UNDER DIFFERENT TSKY VALS
CALL RT(GA2I,GBIH,DEI,RI,TRI,NUM)
TSKY=0.
CALL LAYER(RI,SIHLONG,TRI,TI,GND_TEMP,TSKY,DH,NUM)
TBH0=(1-SIHLONG(NUM+1))*DH(NUM)+SIHLONG(NUM+1)*TSKY
TSKY=100.
CALL LAYER(RI,SIHLONG,TRI,TI,GND_TEMP,TSKY,DH,NUM)
TBH100=(1-SIHLONG(NUM+1))*DH(NUM)+SIHLONG(NUM+1)*TSKY
! VERTICAL BRIGHTNESS TEMPERATUERS UNDER DIFFERENT TSKY VALS
CALL RT(GA2I,GBIV,DEI,RI,TRI,NUM)
TSKY=0.
CALL LAYER(RI,SIVLONG,TRI,TI,GND_TEMP,TSKY,DV,NUM)
TBV0=(1-SIVLONG(NUM+1))*DV(NUM)+SIVLONG(NUM+1)*TSKY
TSKY=100.
CALL LAYER(RI,SIVLONG,TRI,TI,GND_TEMP,TSKY,DV,NUM)
TBV100=(1-SIVLONG(NUM+1))*DV(NUM)+SIVLONG(NUM+1)*TSKY
! COMPUTE EMISSIVITIES
EH=1-(TBH100-TBH0)/100
EV=1-(TBV100-TBV0)/100
END SUBROUTINE EMISSIVITY
! -------------------------------------------------------------------------
!
SUBROUTINE EPSICE(TI,FREQ,EICE,NUM)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER
!
! CALCULATES THE DIELECTRIC PERMITTIVITY OF ICE
! AFTER HUFFORD, MITZIMA AND MATZLER
!
! EICE = EPSICE(TI,FREQ)
! EICE: DIELECTRIC PERMITTIVITY OF ICE
! TI: TEMPERATURE IN K
! FREQ: FREQUENCY IN GHZ
!
! VERSION HISTORY:
! 1.0 WI 15.7.95
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES: NONE
!
! COPYRIGHT (C) 1997 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL, INTENT(IN) :: TI(NUM),FREQ
REAL, INTENT(OUT) :: EICE(NUM)
REAL PP(NUM),B,B1,B2,DB(NUM),BETA(NUM),ALPHA(NUM)
PP=(300/TI)-1
B=335.25
B1=0.0207
B2=1.16E-11
DB=EXP(-10.02+0.0364*(TI-273))
BETA=((B1*EXP(B/TI))/(TI*(EXP(B/TI)-1)**2))+B2*FREQ**2+DB
ALPHA=(0.00504+0.0062*PP)*EXP(-22.1*PP)
EICE=ALPHA/FREQ+BETA*FREQ
END SUBROUTINE EPSICE
! -------------------------------------------------------------------------
!
SUBROUTINE EPSR(ROI,NUM,EPSI)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER
!
! CALCULATES THE DIELECTRIC PERMITTIVITY FOR DRY SNOW FROM
! DENSITY .
!
! EPSI = EPSR(ROI)
! EPSI: REAL PART OF DIELECTRIC PERMITTIVITY
! ROI: DENSITY G/CM^3
!
! VERSION HISTORY:
! 1.0 WI 15.7.95
! 1.1 WI 23.9.97 ADDED LOOYENGA FOR SNOW DENSER THAN 0.4 G/CM^3
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES:
! EPSICE
!
!
!
! COPYRIGHT (C) 1997 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL, INTENT(IN) :: ROI(NUM)
REAL, INTENT(OUT) :: EPSI(NUM)
INTEGER :: I
REAL :: EHB, ESB
REAL,DIMENSION(:),ALLOCATABLE :: VFI
ALLOCATE(VFI(NUM))
VFI=ROI/0.917
EHB=0.99913
ESB=1.4759
DO I=1,NUM
IF (ROI(I)<=0.4) THEN
EPSI(I)=1+1.5995*ROI(I)+1.861*ROI(I)**3
ELSE
EPSI(I)=((1-VFI(I))*EHB+VFI(I)*ESB)**3
END IF
END DO
DEALLOCATE(VFI)
END SUBROUTINE EPSR
! -------------------------------------------------------------------------
!
SUBROUTINE EPSS(MV,T,F,EPSS_VAR)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM PULLIAINEN
!
! FUNCTION FOR CALCULATING EPSILON FOR SOIL USING FREQUENCY,
! TEMPERATURE AND VOLUMETRIC SOIL MOSITURE. USES EPSW.M FOR
! DIELECTRICITY OF WATER.
!
! BY J. PULLIAINEN (MOD. BY K. TIGERSTEDT)
!
! MV [0..1]
! T [C]
! F [HZ]
!
! NOTE: SOME FINNISH COMMENTS WERE NOT COPIED IN ENTIRETY -MD
! VERSION HISTORY:
! 1.0 JP ?.?.?
! 1.1 KT ?.?.?
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
IMPLICIT NONE
REAL,INTENT(IN) :: MV,T,F
COMPLEX,INTENT(OUT) :: EPSS_VAR
REAL S,CLAY,RHOS,BETA,ALFA,REI,A,B,C,M,IEI_S,A_P,B_P,C_P,IEI_P,&
DELTA_IEI,INVT,ALF,B_1,B_2,BB,BET_M,BET_DELTA,BET,IEI,SS,EW_R,EW_I
COMPLEX EW,EPSALF
S=0.4 ! SAND FRACTION
CLAY=0.3 ! CLAY FRACTION
RHOS=1.1 ! DRY-MATTER DENSITY
BETA=1.09-0.11*S+0.18*CLAY
ALFA=0.65
IF(T>0)THEN
CALL EPSW(F,T,EW_R,EW_I)
ELSE
REI=3.1884+9.1E-4*T ! MATZLER AND WEGMULLER 1987
A=0.0026 ! IMPURE ICE -5 ASTETTA (MATZLER)
B=0.00023
C=0.87
M=F/1E9
IEI_S=A/M+B*M**C
A_P=6E-4 ! PURE ICE -5 ASTETTA (MATZLER)
B_P=6.5E-5
C_P=0.7
IEI_P=A_P/M+B_P*M**C_P
DELTA_IEI=IEI_S-IEI_P
! HUFFORD 1991
INVT=300/(T+273)-1
ALF=(0.00504+0.0062*INVT)*EXP(-22.1*INVT)
! (MISHIMA,MATZLER)
B_1=0.0207
B_2=1.16E-11
BB=335
BET_M=B_1/(T+273)*EXP(BB/(T+273))/(EXP(BB/(T+273))-1)**2+B_2*M**2
BET_DELTA=EXP(-10.02+0.0364*T)
BET=BET_M+BET_DELTA
IEI=ALF/M+BET*M
SS=10
IEI=IEI+DELTA_IEI*SS/13
EW_R=REI
EW_I=IEI
END IF
EW=CMPLX(EW_R,(-1*EW_I))
EPSALF=1+0.65*RHOS+MV**BETA*(EW**ALFA-1)
EPSS_VAR=EPSALF**(1/ALFA)
END SUBROUTINE EPSS
! -------------------------------------------------------------------------
!
SUBROUTINE EPSW(F,T,EW_R,EW_I)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM PULLIAINEN
!
! LASKEE PUHTAAN VEDEN EPSILONIN TAAJUUDEN F,
! L MP TILAN T FUNKTIONA
! 5.12.89 JPK; 17.2.1993 JP
! VERSION HISTORY:
! 1.0 JPK 5.12.89
! 1.1 JP 17.02.93
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! NOTE: ADDITIONAL COMMENTS IN FINNISH NOT COPIED HERE -MD
IMPLICIT NONE
REAL,INTENT(IN) :: F,T
REAL,INTENT(OUT) :: EW_R,EW_I
REAL S,E0,EW_INF,EW0,N,D,ALFA,SIGMA_25,SIGMA_VAR,TW,PI,SIGMA
PI=3.14159
S=0
E0=8.854E12
EW_INF=4.9
EW0=87.74-0.40008*T+9.398E-4*T**2+1.410E-6*T**3
N=0
D=25-T
ALFA=2.033E-2+1.266E-4*D+2.462E-6*D**2-S*(1.849E-5-2.551E-7*D+&
2.551E-8*D**2)
SIGMA_25=S*(0.182521-1.46192E-3*S+2.09324E-5*S**2-1.28205E-7*S**3)
SIGMA=SIGMA_25*EXP(-D*ALFA)
TW=1/(2*PI)*(1.1109E-10-3.824E-12*T+6.938E-14*T*T-5.096E-16*T*T*T)
EW_R=EW_INF+(EW0-EW_INF)/(1+(2*PI*F*TW)**2)
EW_I=(EW0-EW_INF)*2*PI*F*TW/(1+(2*PI*F*TW)**2)+SIGMA/(2*PI*E0*F)
END SUBROUTINE EPSW
! -------------------------------------------------------------------------
!
SUBROUTINE FRESNELC(TEI,EPSI,SIH,SIV,NUM)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER
!
! FRESNEL REFLECTION COEFFICIENTS (ASSUMING EPS'' = 0)
! (LAYER N+1 IS THE AIR ABOVE THE SNOWPACK)
!
! [SIH,SIV] = FRESNEL(TEI,ROI)
! SIH: INTERFACE REFLECTIVITY AT H POL
! SIV: INTERFACE REFLECTIVITY AT V POL
! TEI: LOCAL INCIDENCE ANGLE
! EPSI: REAL PART OF DIELECTRIC PERMITTIVITY
!
! VERSION HISTORY:
! 1.0 WI 15.7.97
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES:
! EPSR
!
!
! COPYRIGHT (C) 1997 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER, INTENT(IN) :: NUM
REAL, INTENT(IN) :: TEI(NUM+1),EPSI(NUM)
!ctvs REAL, INTENT(OUT) :: SIH(NUM-1),SIV(NUM-1)
REAL, INTENT(OUT) :: SIH(NUM),SIV(NUM)
INTEGER :: I
REAL EPSO,EPSU,TEIN
REAL,DIMENSION(:),ALLOCATABLE:: EPSI_LOCAL
ALLOCATE(EPSI_LOCAL(NUM+1))
EPSI_LOCAL(1:NUM)=EPSI
EPSI_LOCAL(NUM+1)=1
DO I=1,NUM
EPSO=EPSI_LOCAL(I+1)
EPSU=EPSI_LOCAL(I)
TEIN=TEI(I+1)
SIH(I)=((EPSO**0.5*COS(TEIN)-(EPSU-EPSO*SIN(TEIN)**2)**0.5)/&
(EPSO**0.5*COS(TEIN)+(EPSU-EPSO*SIN(TEIN)**2)**0.5))**2
SIV(I)=((EPSU*COS(TEIN)-EPSO**0.5*(EPSU-EPSO*SIN(TEIN)**2)**0.5)/&
(EPSU*COS(TEIN)+EPSO**0.5*(EPSU-EPSO*SIN(TEIN)**2)**0.5))**2
END DO
DEALLOCATE(EPSI_LOCAL)
END SUBROUTINE FRESNELC
! -------------------------------------------------------------------------
!
SUBROUTINE FRESNELRC(TEI,EPSI,FH,FV,NUM)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM MATZLER
!
!
! FRESNEL REFLECTION COEFFICIENTS (ASSUMING EPS'' = 0)
! (LAYER N+1 IS THE AIR ABOVE THE SNOWPACK)
!
! [FH,FV] = FRESNELRC(TEI,EPSR)
! FH: FRESNEL REFLECTION COEFFICIENT AT H POL
! FV: FRESNEL REFLECTION COEFFICIENT AT V POL
! TEI: LOCAL INCIDENCE ANGLE
! EPSR: (REAL PART) DIELECTRIC PERMITTIVITY
!
! VERSION HISTORY:
! 1.0 WI 15.7.95
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! USES:
!
!
!
! COPYRIGHT (C) 1997 BY THE INSTITUTE OF APPLIED PHYSICS,
! UNIVERSITY OF BERN, SWITZERLAND
IMPLICIT NONE
INTEGER,INTENT(IN) :: NUM
REAL,INTENT(IN) :: TEI(NUM+1),EPSI(NUM+1)
REAL,INTENT(OUT) :: FH(NUM),FV(NUM)
INTEGER N
REAL EPSN,TEIN,SINQ,QEPS,WURZ,WSUB,ND
DO N=1,NUM
EPSN=EPSI(N)/EPSI(N+1)
TEIN=TEI(N+1)
SINQ=SIN(TEIN)**2
QEPS=SINQ/EPSN
WURZ=(1-QEPS)**0.5
WSUB=EPSN-SINQ
ND=EPSN**0.5
FH(N)=((ND*WURZ-COS(TEIN))/(ND*WURZ+COS(TEIN)))
FV(N)=((WURZ-ND*COS(TEIN))/(WURZ+ND*COS(TEIN)))
END DO
END SUBROUTINE FRESNELRC
! -------------------------------------------------------------------------
!
SUBROUTINE GAMMAH(EPSS,THETA,GAMMAH_VAR)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM PULLIAINEN
!
! VERSION HISTORY:
! 1.0 JPK 5.12.89
! 1.1 JP 17.03.93
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! NOTE: ADDITIONAL FINNISH COMMENTS NOT COPIED HERE
IMPLICIT NONE
REAL,INTENT(IN) :: THETA
COMPLEX,INTENT(IN) :: EPSS
REAL,INTENT(OUT) :: GAMMAH_VAR
REAL THETA_RAD,PI,COSTHETA
COMPLEX NELIO
PI=3.14159
THETA_RAD=THETA/180*PI
COSTHETA=COS(THETA_RAD)
NELIO=SQRT(EPSS-SIN(THETA_RAD)**2)
GAMMAH_VAR=(ABS((COSTHETA-NELIO)/(COSTHETA+NELIO)))**2
END SUBROUTINE GAMMAH
! -------------------------------------------------------------------------
!
SUBROUTINE GAMMAV(EPSS,THETA,GAMMAV_VAR)
!
! -------------------------------------------------------------------------
!
! CODE ORIGINALLY OBTAINED IN MATLAB FROM PULLIAINEN
!
! VERSION HISTORY:
! 1.0 JPK 5.12.89
! 1.1 JP 17.03.93
! 2.0 MD 1 APR 05 TRANSLATED TO FORTRAN FROM MATLAB
!
! NOTE: ADDITIONAL FINNISH COMMENTS NOT COPIED HERE
IMPLICIT NONE
REAL,INTENT(IN) :: THETA
COMPLEX,INTENT(IN) :: EPSS
REAL,INTENT(OUT) :: GAMMAV_VAR
REAL THETA_RAD,PI,COSTHETA
COMPLEX NELIO
PI=3.14159
THETA_RAD=THETA/180*PI
COSTHETA=COS(THETA_RAD)