-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModWeimer.f
2112 lines (1644 loc) · 55.3 KB
/
ModWeimer.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 EIE_ModWeimer
contains
c
c The code has been made to implicit real*8 by Mei-Ching Fok on
c Jan. 30, 2002
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
*
* Subroutines to calculate the electric potentials from the "Weimer 2K" model of
* the polar cap ionospheric electric potentials described in the publication:
* Weimer, D. R., An improved model of ionospheric electric potentials including
* substorm perturbations and application to the Geospace Environment Modeling
* November 24, 1996 event, Journal of Geophysical Research, Vol. 106, p. 407, 2001.
*
* To use, first call procedure SETMODEL00 with the specified input parameters:
* angle: IMF Y-Z clock angle in degrees, 0=northward, 180=southward
* Bt: Magnitude of IMF in Y-Z plane in nT
* Tilt: dipole tilt angle in degrees.
* SWVel: solar wind velocity in km/sec
* SWDen: solar wind density in #/cc
* ALindex: (optional) AL index in nT
*
* The function EPOTVAL00(gLAT,gMLT) can then be used repeatively to get the
* electric potential in kV at the desired location.
* Input coordinates assume use of 'altitude adjusted' corrected geomagnetic
* coordinates for R=1, also refered to as AACGM0.
*
* The function BOUNDARYLAT00(gMLT) can be used to get the latitude of the boundary
* where the potential goes to zero. This boundary is a function of MLT, and
* varies with the SETMODEL00 parameters. The potential is zero everywhere below
* this boundary.
*
* Two data files are provided:
* 'w2klittle.dat' for LITTLE_ENDIAN machines.
* 'w2kbig.dat' for BIG_ENDIAN machines.
* You must copy or rename the correct one to the file 'w2k.dat'
*
* This code is protected by copyright and is distributed
* for research or educational use only.
* Commerical use without written permission from Dan Weimer/MRC is prohibited.
*
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
SUBROUTINE DLEGENDRE00(x,lmax,mmax,Plm,dPlm)
* compute Double Precision Associate Legendre Function P_l^m(x), as well as optional
* derivatives, for all L up to lmax and all M up to mmax.
* Returns results in array Plm, which should be dimensioned as double precision
* with size (0:10,0:10).
* If the first element of dPlm is not zero, then the first derivatives are also
* computed, and put into array dPlm. To skip the derivatives it is only necessary
* to put a scalar 0.D0 in the dPlm parameter. Otherwise, dPlm should also be a
* double precision array of size (0:10,0:10).
* The recursion formulas keep a count of the exponents of the factor SQRT(1-x^2)
* in both the numerator and denominator, which may cancel each other in the
* final evaluation, particularly with the derivatives. This prevents infinities
* at x=-1 or +1.
* If X is out of range ( abs(x)>1 ) then value is returns as if x=1.
implicit real*8 (a-h,o-z)
real*8 x,xx,Plm(0:10,0:10),P(0:10,0:10,0:1),fact,sfact
real*8 dPlm(0:10,0:10),dP(0:10,0:10,0:2),anum,term
LOGICAL DodPlm
DodPlm=dPlm(0,0) .NE. 0.d0
DO l=0,lmax
DO m=0,mmax
Plm(l,m)=0.D0
P(l,m,0)=0.D0
P(l,m,1)=0.D0
ENDDO
ENDDO
IF(lmax .LT. 0 .OR. mmax .LT. 0 .OR. mmax .GT. lmax )THEN
Print *,'Bad arguments to DLegendre00'
RETURN
ENDIF
* Copy x to xx, and make sure it is in range of -1. to +1.
xx=MIN(x,1.D0)
xx=MAX(xx,-1.D0)
P(0,0,1)=1.D0
IF(lmax.GT.0) P(1,0,1)=xx
IF(lmax.GT.1)THEN
DO L=2,lmax
P(L,0,1)=( (2.D0*L-1)*xx*P(L-1,0,1) - (L-1)*P(L-2,0,1) ) / L
ENDDO
ENDIF
fact=1.D0-xx**2
sfact=DSQRT(fact)
IF(mmax .GT. 0)THEN
DO M=1,mmax
DO L=M,lmax
L2=MAX( L-2 , 0 )
P(L,M,1)= P(L2,M,1) -(2*L-1)*P(L-1,M-1,0)*fact
P(L,M,0)= P(L2,M,0) -(2*L-1)*P(L-1,M-1,1)
ENDDO
ENDDO
ENDIF
IF(DodPlm)Then !do derivatives
* First zero arrays
DO l=0,lmax
DO m=0,mmax
dPlm(l,m)=0.D0
dP(l,m,0)=0.D0
dP(l,m,1)=0.D0
dP(l,m,2)=0.D0
ENDDO
ENDDO
IF(lmax .GT. 0) dP(1,0,1)=1.D0
IF(lmax .GT. 1)THEN
DO L=2,lmax
dP(L,0,1)=( (2*L-1)*P(L-1,0,1) +
$ (2*L-1)*xx*dP(L-1,0,1) -
$ (L-1)*dP(L-2,0,1) ) / L
ENDDO
ENDIF
IF(mmax .GT. 0)THEN
DO M=1,mmax
DO L=M,lmax
L2=MAX( L-2 , 0 )
dP(L,M,1)= dP(L2,M,1) - (2*L-1)*fact*dP(L-1,M-1,0) -
$ (2*L-1)*dP(L-1,M-1,2) + (2*L-1)*xx*P(L-1,M-1,0)
dP(L,M,0)= dP(L2,M,0) - (2*L-1)*dP(L-1,M-1,1)
dP(L,M,2)=dP(L2,M,2) +(2*L-1)*xx*P(L-1,M-1,1)
ENDDO
ENDDO
ENDIF
DO L=0,lmax
mlimit=MIN(mmax,L)
DO M=0,mlimit
* Prevent a divide by zero
anum=dP(L,M,2) !numerator
IF(sfact.NE.0.)Then !denominator is OK
term=anum/sfact
ELSE !denominator is zero
IF(DABS(anum).LT.1.D-7)THEN
term=0.D0 !return 0 in cases where numerator is near zero
ELSE !return nearly infinity with same sign as numerator
term=DSIGN(1.D36,anum)
ENDIF
ENDIF
dPlm(L,M)=dP(L,M,1) + dP(L,M,0)*sfact + term
ENDDO
ENDDO
ENDIF !End doing derivative
DO L=0,lmax
mlimit=MIN(mmax,L)
DO M=0,mlimit
Plm(L,M)=P(L,M,1) + P(L,M,0)*sfact
ENDDO
ENDDO
RETURN
END SUBROUTINE DLEGENDRE00
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
* FUNCTION FSVal00(omega,MaxN,FSC)
*
** Fourier Series Value
*
** Return value of Sine/Cosine Fourier series for N terms up to MaxN
*
** at angle omega, given the F.S. coeficients in array FSC
*
* implicit real*8 (a-h,o-z)
* REAL*8 omega,FSC(0:1,0:*)
*
* INTEGER MaxN,n
*
* REAL*8 Y,theta
*
* Y=0.
*
* DO n=0,MaxN
*
* theta=omega*n
*
* Y=Y + FSC(0,n)*COS(theta) + FSC(1,n)*SIN(theta)
*
* ENDDO
*
* FSVal=Y
*
* RETURN
*
* END
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
SUBROUTINE SetModel00(angle,Bt,Tilt,SWVel,SWDen,ALindex,UseAL)
*
* Calculate the complete set of spherical harmonic coeficients,
* given an aribitrary IMF angle (degrees from northward toward +Y),
* magnitude Bt (nT), dipole tilt angle (degrees),
* solar wind velocity (km/sec), SWDen (#/cc),
* ALindex (nT), and Logical flag to use optional AL index.
*
* Sets the value of Coef and Boundfit in the common block SetW00Coef.
*
implicit real*8 (a-h,o-z)
REAL*8 angle,Bt,Tilt,SWVel,SWDen,ALindex
LOGICAL First,UseAL
DATA First/.TRUE./
SAVE First
INTEGER unit
CHARACTER*15 cfile
CHARACTER*30 Copyright
PARAMETER (MJ=3,ML=4,MM=3,MN=2,MO=2)
integer :: iMJ,iMO,iML,iMM,iMN
REAL*4 CS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL*4 BCS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:MN)
REAL*4 SS( 0:1 , 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL*4 BSS( 0:1 , 0:1 , 0:MO, 0:1 , 0:MN)
REAL*8 XA(0:MJ),XB(0:MJ),FSC(0:1,0:4),PSS(0:1)
REAL*8 Coef(0:1,0:5,0:5),BoundFit(0:1,0:5),pi
real*8 dpi
INTEGER*4 i,j,k,l,m,n,o
INTEGER*4 maxj,MaxL,MaxM,MaxN,MaxO
COMMON /EIE_AllW00Coefs/MaxJ,MaxO,CS,BCS,SS,BSS
COMMON /EIE_SetW00Coef/Coef,BoundFit,pi,dpi,MaxL,MaxM,MaxN
If(First)Then
cfile='EIE/w2k.dat' !make sure correct ENDIAN type file is used.
unit=9
c OPEN(UNIT=unit,FILE=cfile,STATUS='OLD',form='UNFORMATTED')
OPEN(UNIT=unit,FILE=cfile,STATUS='old',form='FORMATTED')
READ(unit,*) Copyright
c PRINT *,Copyright
read(unit,*) Maxj,MaxL,MaxM,MaxN,MaxO
If(maxj.NE.MJ .OR. MaxL.NE.ML .OR. MaxM.NE.MM .OR.
$ MaxN.NE.MN .OR. MaxO.NE.MO)Then
PRINT *,'Data File Error'
STOP !Data file did not match sixe expected for arrays
Endif
do iMJ=0,MJ
do i=0,1
do iMO=0,MO
do j=0,1
do iML=0,ML
do iMM=0,MM
read(unit,*) CS( iMJ, i , iMO, j , iML, iMM)
enddo
enddo
enddo
enddo
enddo
enddo
do iMJ=0,MJ
do i=0,1
do iMO=0,MO
do j=0,1
do iMN=0,MN
read(unit,*) BCS( iMJ, i , iMO, j , iMN)
enddo
enddo
enddo
enddo
enddo
do i=0,1
do j=0,1
do iMO=0,MO
do k=0,1
do iML=0,ML
do iMM=0,MM
read(unit,*) SS( i , j , iMO, k , iML, iMM)
enddo
enddo
enddo
enddo
enddo
enddo
do i=0,1
do j=0,1
do iMO = 0,MO
do k=0,1
do iMN=0,MN
read(unit,*) BSS( i , j , iMO, k , iMN)
enddo
enddo
enddo
enddo
enddo
CLOSE(unit)
pi=2.*ASIN(1.)
dpi=2.D0*DASIN(1.D0)
First=.FALSE.
Endif
SinTilt=SIN(Tilt)
omega=angle*pi/180.
XA(0)=1.
XA(1)=Bt**(2./3.) *SWvel
XA(2)=SinTilt
XA(3)=SWvel**2 *SWDen
XB(0)=1.
XB(1)=Bt
XB(2)=SinTilt
XB(3)=SWvel**2 *SWDen
DO l=0,MaxL
mlimit=MIN(l,MaxM)
DO m=0,mlimit
klimit=MIN(m,1)
DO k=0,klimit
acoef=0. !rezero for summation
DO j=0,MaxJ
DO o=0,MaxO
DO i=0,1
FSC(i,o)=CS(j,i,o,k,l,m)
ENDDO
ENDDO
acoef=acoef+ XA(j)*FSVAL(omega,MaxO,fsc)
ENDDO
IF(UseAL)THEN
DO j=0,1
DO o=0,MaxO
DO i=0,1
FSC(i,o)=SS(j,i,o,k,l,m)
ENDDO
ENDDO
PSS(j)=FSVAL(omega,MaxO,fsc)
ENDDO
acoef=acoef + PSS(0) + PSS(1)*ALindex
ENDIF
Coef(k,l,m)=acoef
ENDDO
ENDDO
ENDDO
DO n=0,MaxN
klimit=MIN(n,1)
DO k=0,klimit
acoef=0. !rezero for summation
DO j=0,MaxJ
DO o=0,MaxO
DO i=0,1
FSC(i,o)=BCS(j,i,o,k,n)
ENDDO
ENDDO
acoef=acoef+ XB(j)*FSVAL(omega,MaxO,fsc)
ENDDO
IF(UseAL)THEN
DO j=0,1
DO o=0,MaxO
DO i=0,1
FSC(i,o)=BSS(j,i,o,k,n)
ENDDO
ENDDO
PSS(j)=FSVAL(omega,MaxO,fsc)
ENDDO
acoef=acoef + PSS(0) + PSS(1)*ALindex
ENDIF
BoundFit(k,n)=acoef
ENDDO
ENDDO
RETURN
END SUBROUTINE SetModel00
****************** Copyright 1996, 2001, Dan Weimer/MRC ***********************
FUNCTION BoundaryLat00(gmlt)
implicit real*8 (a-h,o-z)
REAL*8 gmlt
REAL*8 Coef(0:1,0:5,0:5),BoundFit(0:1,0:5),pi
real*8 dpi
integer*4 MaxL,MaxM,MaxN
COMMON /EIE_SetW00Coef/Coef,BoundFit,pi,dpi,MaxL,MaxM,MaxN
BoundaryLat00 = FSVal(gmlt*pi/12.,MaxN,BoundFit)
RETURN
END FUNCTION BoundaryLat00
****************** Copyright 1996, 2001, Dan Weimer/MRC ***********************
FUNCTION EpotVal00(gLAT,gMLT)
* Return the value of the electric potential in kV at
* corrected geomagnetic coordinates gLAT (degrees) and gMLT (hours).
*
* Must first call SetModel00 to set up the model coeficients for
* the desired values of Bt, IMF clock angle, Dipole tilt angle, SW Vel,
* number density, and (optional) AL index.
*
implicit real*8 (a-h,o-z)
REAL*8 gLAT,gMLT
real*8 Phi,Z,O,x,ct,Phim
real*8 Plm(0:10,0:10),OPlm(0:10,0:10)
real*8 dPlm(0:10,0:10)
REAL*8 Coef(0:1,0:5,0:5),BoundFit(0:1,0:5),pi
real*8 dpi
integer*4 MaxL,MaxM,MaxN
COMMON /EIE_SetW00Coef/Coef,BoundFit,pi,dpi,MaxL,MaxM,MaxN
blat = BoundaryLat00(gmlt)
IF(glat .GT. blat)THEN
Phi=DBLE(gMLT)*dpi/12.D0
colat=90.-glat
bcolat=90.-blat
x=DBLE(colat)*dpi/DBLE(bcolat)
DC=DBLE(Coef(0,0,0))
Z=DC
O=DC
ct=DCOS(x)
dPlm(:,:)=0.D0
CALL DLegendre00(ct,MaxL,MaxM,Plm,dPlm)
!Also find value at outer boundary at angle Pi, or cos(pi)=-1.
CALL DLegendre00(-1.D0,MaxL,MaxM,OPlm,dPlm)
DO l=1,MaxL
Z=Z + Plm(l,0)*DBLE(Coef(0,l,0))
O=O + OPlm(l,0)*DBLE(Coef(0,l,0))
mlimit=MIN(l,MaxM)
DO m=1,mlimit
phim=phi*m
Z=Z + Plm(l,m)*(DBLE(Coef(0,l,m))*DCOS(phim) +
$ DBLE(Coef(1,l,m))*DSIN(phim) )
O=O +OPlm(l,m)*DBLE(Coef(0,l,m))
ENDDO
ENDDO
EpotVal00 = SNGL(Z-O)
ELSE
EpotVal00 = 0.
ENDIF
RETURN
END FUNCTION EpotVal00
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
*
* Subroutines to calculate the electric potentials from the "Weimer 01" model of
* the polar cap ionospheric electric potentials described in the publication:
* Weimer, D. R., An improved model of ionospheric electric potentials including
* substorm perturbations and application to the Geospace Environment Modeling
* November 24, 1996 event, Journal of Geophysical Research, Vol. 106, p. 407, 2001.
*
* To use, first call procedure SETMODEL01 with the specified input parameters:
* angle: IMF Y-Z clock angle in degrees, 0=northward, 180=southward
* Bt: Magnitude of IMF in Y-Z plane in nT
* Tilt: dipole tilt angle in degrees.
* SWVel: solar wind velocity in km/sec
* SWDen: solar wind density in #/cc
* ALindex: (optional) AL index in nT
*
* The function EPOTVAL01(gLAT,gMLT) can then be used repeatively to get the
* electric potential in kV at the desired location.
* Input coordinates assume use of 'altitude adjusted' corrected geomagnetic
* coordinates for R=1, also refered to as AACGM0.
*
* The function BOUNDARYLAT01(gMLT) can be used to get the latitude of the boundary
* where the potential goes to zero. This boundary is a function of MLT, and
* varies with the SETMODEL01 parameters. The potential is zero everywhere below
* this boundary.
*
* This code is protected by copyright and is distributed
* for research or educational use only.
* Commerical use without written permission from Dan Weimer/MRC is prohibited.
CNCAR Revisions for use at NCAR:
C (1) Change behavior at minimum magnetic latitude. When approaching
C the model equatorial edge (which varies with MLT) the electric
C potential returned used to go to zero discontinuously; although
C intended as a flag, it created artificial gradients in the
C electric field calculation. Now the potential returned is
C constant (that of the minimum latitude) for any latitude at
C or equatorward of the minimum.
C (2) Accomodate running simultaneously 1996 and 2001 versions. To
C avoid name collisions this required: (i) revising names (e.g.,
C adding '01') for differing subprograms, and (ii) relocating
C common routines into another file (weicom.f).
C (3) Pass the coefficients file name and unit number into READCOEF01
C rather than using hard coded values.
C (4) Add wrapper subroutines for non-ANSI trig functions which
C input angles in degrees.
C (5) Add electric field routine (GECMP01) to deterine the electric
C potential gradient.
C (6) Add wrapper routine (WEIEPOT01) for use with AMIE; this is a
C substitute for calling SETMODEL01 and EPOTVAL01.
C (7) Remove blanks in some statements to fit in 72 columns to
C adhere to ANSI Fortran 77.
CNCAR NCAR changes are delimited by "CNCAR"
*
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
SUBROUTINE DLEGENDRE01(x,lmax,mmax,Plm)
* compute Double Precision Associate Legendre Function P_l^m(x)
* for all l up to lmax and all m up to mmax.
* Returns results in array Plm.
* The recursion formulas keep a count of the exponents of the factor SQRT(1-x^2)
* in both the numerator and denominator, which may cancel each other in the
* final evaluation, particularly with the derivatives. This prevents infinities
* at x=-1 or +1.
* If X is out of range ( abs(x)>1 ) then value is returns as if x=1.
DOUBLE PRECISION x,xx,Plm(0:10,0:10),P(0:10,0:10,0:1),fact,sfact
DOUBLE PRECISION dP(0:10,0:10,0:2),anum,term
DO l=0,lmax
DO m=0,mmax
Plm(l,m)=0.D0
P(l,m,0)=0.D0
P(l,m,1)=0.D0
ENDDO
ENDDO
IF(lmax .LT. 0 .OR. mmax .LT. 0 .OR. mmax .GT. lmax )THEN
Print *,'Bad arguments to DLegendre'
RETURN
ENDIF
* Copy x to xx, and make sure it is in range of -1. to +1.
xx=MIN(x,1.D0)
xx=MAX(xx,-1.D0)
P(0,0,1)=1.D0
IF(lmax.GT.0) P(1,0,1)=xx
IF(lmax.GT.1)THEN
DO L=2,lmax
P(L,0,1)=( (2.D0*L-1)*xx*P(L-1,0,1) - (L-1)*P(L-2,0,1) ) / L
ENDDO
ENDIF
fact=1.D0-xx**2
sfact=DSQRT(fact)
IF(mmax .GT. 0)THEN
DO M=1,mmax
DO L=M,lmax
L2=MAX( L-2 , 0 )
P(L,M,1)= P(L2,M,1) -(2*L-1)*P(L-1,M-1,0)*fact
P(L,M,0)= P(L2,M,0) -(2*L-1)*P(L-1,M-1,1)
ENDDO
ENDDO
ENDIF
DO L=0,lmax
mlimit=MIN(mmax,L)
DO M=0,mlimit
Plm(L,M)=P(L,M,1) + P(L,M,0)*sfact
ENDDO
ENDDO
RETURN
END SUBROUTINE DLEGENDRE01
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
SUBROUTINE READCOEF01 (udat)
CNCAR Feb 01: Make a subroutine (a.k.a. ReadCoef) from FIRST=TRUE block
C of SETMODEL01 (a.k.a. SetModel) so that one can load the coefficients
C independently of defining geophysical conditions. This mimics the
C 1996 model.
C Sep 01: Change argument list to pass both unit number and file name
C rather than hard coding
CNCAR
INTEGER udat
CHARACTER*30 Copyright
PARAMETER (MJ=3,ML=4,MM=3,MN=2,MO=2)
REAL CS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL BCS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:MN)
REAL SS( 0:1 , 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL BSS( 0:1 , 0:1 , 0:MO, 0:1 , 0:MN)
REAL Coef(0:1,0:5,0:5),BoundFit(0:1,0:5),pi
DOUBLE PRECISION dpi
INTEGER*4 maxj,MaxL,MaxM,MaxN,MaxO
COMMON /EIE_AllW01Coefs/MaxJ,MaxO,CS,BCS,SS,BSS
COMMON /EIE_SetW01Coef/MaxL,MaxM,MaxN,Coef,BoundFit,pi,dpi
CNCAR Feb 01: Initialize constants used in GECMP01
C Sep 01: Omit unneeded min lat variables because of switch to
C constant potential at and below min lat (hardcoded
C in EPOTVAL01).
COMMON /EIE_W01CECMP/ ALAMX,STPD,STP2,CSTP,SSTP
C ALAMX = Absolute max latitude (deg) for normal gradient calc.
C STPD = Angular dist (deg) of step @ 300km above earth (r=6371km)
C STP2 = Denominator in gradient calc
PARAMETER ( D2R = 0.0174532925199432957692369076847 ,
+ R2D = 57.2957795130823208767981548147)
STEP = 10.
STPR = STEP/6671.
STPD = STPR*R2D
STP2 = 2.*STEP
CSTP = COS (STPR)
SSTP = SQRT (1. - CSTP*CSTP)
ALAMX = 90. - STPD
CNCAR
CNCAR Sep 01: udat is now an argument
C Assume file has been opened at unit elsewhere
CNCAR
c OPEN (UNIT=udat,FILE=cfile,STATUS='OLD',form='UNFORMATTED')
READ (udat) Copyright
PRINT *,Copyright
READ (udat) Maxj,MaxL,MaxM,MaxN,MaxO
If (maxj.NE.MJ .OR. MaxL.NE.ML .OR. MaxM.NE.MM .OR.
$ MaxN.NE.MN .OR. MaxO.NE.MO) Then
PRINT *,'Data File Error'
STOP !Data file did not match size expected for arrays
Endif
READ (udat) CS
READ (udat) BCS
READ (udat) SS
READ (udat) BSS
CLOSE (udat)
pi=2.*ASIN(1.)
dpi=2.D0*DASIN(1.D0)
RETURN
END SUBROUTINE READCOEF01
************************ Copyright 1996,2001 Dan Weimer/MRC ***********************
CNCAR Sep 01: Change name from SetModel to be distinct
SUBROUTINE SetModel01 (angle,Bt,Tilt,SWVel,SWDen,ALindex,UseAL)
C SUBROUTINE SetModel (angle,Bt,Tilt,SWVel,SWDen,ALindex,UseAL)
CNCAR
*
* Calculate the complete set of spherical harmonic coeficients,
* given an aribitrary IMF angle (degrees from northward toward +Y),
* magnitude Bt (nT), dipole tilt angle (degrees),
* solar wind velocity (km/sec), SWDen (#/cc),
* ALindex (nT), and Logical flag to use optional AL index.
*
* Sets the value of Coef and Boundfit in the common block SetW01Coef.
*
REAL angle,Bt,Tilt,SWVel,SWDen,ALindex
C LOGICAL First,UseAL
LOGICAL UseAL
CNCAR Feb 01: Move logic block to subroutine RdCoef01
C DATA First/.TRUE./
C SAVE First
C INTEGER unit
C CHARACTER*15 cfile
C CHARACTER*30 Copyright
PARAMETER (MJ=3,ML=4,MM=3,MN=2,MO=2)
REAL CS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL BCS( 0:MJ, 0:1 , 0:MO, 0:1 , 0:MN)
REAL SS( 0:1 , 0:1 , 0:MO, 0:1 , 0:ML, 0:MM)
REAL BSS( 0:1 , 0:1 , 0:MO, 0:1 , 0:MN)
REAL XA(0:MJ),XB(0:MJ),FSC(0:1,0:4),PSS(0:1)
REAL Coef(0:1,0:5,0:5),BoundFit(0:1,0:5),pi
DOUBLE PRECISION dpi
INTEGER*4 i,j,k,l,m,n,o
INTEGER*4 maxj,MaxL,MaxM,MaxN,MaxO
COMMON /EIE_AllW01Coefs/MaxJ,MaxO,CS,BCS,SS,BSS
COMMON /EIE_SetW01Coef/MaxL,MaxM,MaxN,Coef,BoundFit,pi,dpi
CNCAR Feb 01: Move logic block to subroutine RdCoef01
C All First=TRUE in new subroutine ReadCoef
C If(First)Then
C cfile='w01.dat' !make sure correct ENDIAN type file is used.
C unit=99
C OPEN(UNIT=unit,FILE=cfile,STATUS='OLD',form='UNFORMATTED')
C READ(unit) Copyright
C PRINT *,Copyright
C READ(unit) Maxj,MaxL,MaxM,MaxN,MaxO
C If(maxj.NE.MJ .OR. MaxL.NE.ML .OR. MaxM.NE.MM .OR.
C $ MaxN.NE.MN .OR. MaxO.NE.MO)Then
C PRINT *,'Data File Error'
C STOP !Data file did not match sixe expected for arrays