/[PAMELA software]/DarthVader/OrbitalInfo/src/igrf_sub.for
ViewVC logotype

Annotation of /DarthVader/OrbitalInfo/src/igrf_sub.for

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Mon Jan 19 12:32:13 2015 UTC (9 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +21 -99 lines
Bugs in OrbitalInfo code fixed: wrong Earth B-field computation, OICore memory leaks, Rotation tables bug + new IGRF12 parameters added

1 mocchiut 1.12 C
2 mocchiut 1.1 C SHELLIG.FOR, Version 2.0, January 1992
3     C
4     C 11/01/91-DKB- SHELLG: lowest starting point for B0 search is 2
5     C 1/27/92-DKB- Adopted to IGRF-91 coeffcients model
6     C 2/05/92-DKB- Reduce variable-names: INTER(P)SHC,EXTRA(P)SHC,INITI(ALI)ZE
7     C 8/08/95-DKB- Updated to IGRF-45-95; new coeff. DGRF90, IGRF95, IGRF95S
8     C 5/31/00-DKB- Updated to IGRF-45-00; new coeff.: IGRF00, IGRF00s
9     C 3/24/05-DKB- Updated to IGRF-45-10; new coeff.: IGRF05, IGRF05s
10     C 4/25/05-DKB- CALL FELDI and DO 1111 I=1,7 [Alexey Petrov]
11     C
12     C*********************************************************************
13     C SUBROUTINES FINDB0, SHELLG, STOER, FELDG, FELDCOF, GETSHC, *
14     C INTERSHC, EXTRASHC, INITIZE *
15     C*********************************************************************
16     C*********************************************************************
17     C
18     C
19     SUBROUTINE FINDB0(STPS,BDEL,VALUE,BEQU,RR0)
20     C--------------------------------------------------------------------
21     C FINDS SMALLEST MAGNETIC FIELD STRENGTH ON FIELD LINE
22     C
23     C INPUT: STPS STEP SIZE FOR FIELD LINE TRACING
24     C COMMON/FIDB0/
25     C SP DIPOLE ORIENTED COORDINATES FORM SHELLG; P(1,*),
26     C P(2,*), P(3,*) CLOSEST TO MAGNETIC EQUATOR
27     C BDEL REQUIRED ACCURACY = [ B(LAST) - BEQU ] / BEQU
28     C B(LAST) IS FIELD STRENGTH BEFORE BEQU
29     C
30     C OUTPUT: VALUE =.FALSE., IF BEQU IS NOT MINIMAL VALUE ON FIELD LINE
31     C BEQU MAGNETIC FIELD STRENGTH AT MAGNETIC EQUATOR
32     C RR0 EQUATORIAL RADIUS NORMALIZED TO EARTH RADIUS
33     C BDEL FINAL ACHIEVED ACCURACY
34     C--------------------------------------------------------------------
35     DIMENSION P(8,4),SP(3)
36     LOGICAL VALUE
37     COMMON/FIDB0/ SP
38     SAVE /FIDB0/
39     C
40     STEP=STPS
41     IRUN=0
42     7777 IRUN=IRUN+1
43     IF(IRUN.GT.5) THEN
44     VALUE=.FALSE.
45     GOTO 8888
46     ENDIF
47     C*********************FIRST THREE POINTS
48     P(1,2)=SP(1)
49     P(2,2)=SP(2)
50     P(3,2)=SP(3)
51     STEP=-SIGN(STEP,P(3,2))
52     CALL STOER(P(1,2),BQ2,R2)
53     P(1,3)=P(1,2)+0.5*STEP*P(4,2)
54     P(2,3)=P(2,2)+0.5*STEP*P(5,2)
55     P(3,3)=P(3,2)+0.5*STEP
56     CALL STOER(P(1,3),BQ3,R3)
57     P(1,1)=P(1,2)-STEP*(2.*P(4,2)-P(4,3))
58     P(2,1)=P(2,2)-STEP*(2.*P(5,2)-P(5,3))
59     P(3,1)=P(3,2)-STEP
60     CALL STOER(P(1,1),BQ1,R1)
61     P(1,3)=P(1,2)+STEP*(20.*P(4,3)-3.*P(4,2)+P(4,1))/18.
62     P(2,3)=P(2,2)+STEP*(20.*P(5,3)-3.*P(5,2)+P(5,1))/18.
63     P(3,3)=P(3,2)+STEP
64     CALL STOER(P(1,3),BQ3,R3)
65     C******************INVERT SENSE IF REQUIRED
66     IF(BQ3.LE.BQ1) GOTO 2
67     STEP=-STEP
68     R3=R1
69     BQ3=BQ1
70     DO 1 I=1,5
71     ZZ=P(I,1)
72     P(I,1)=P(I,3)
73     1 P(I,3)=ZZ
74     C******************INITIALIZATION
75     2 STEP12=STEP/12.
76     VALUE=.TRUE.
77     BMIN=1.E4
78     BOLD=1.E4
79     C******************CORRECTOR (FIELD LINE TRACING)
80     N=0
81     5555 P(1,3)=P(1,2)+STEP12*(5.*P(4,3)+8.*P(4,2)-P(4,1))
82     N=N+1
83     P(2,3)=P(2,2)+STEP12*(5.*P(5,3)+8.*P(5,2)-P(5,1))
84     C******************PREDICTOR (FIELD LINE TRACING)
85     P(1,4)=P(1,3)+STEP12*(23.*P(4,3)-16.*P(4,2)+5.*P(4,1))
86     P(2,4)=P(2,3)+STEP12*(23.*P(5,3)-16.*P(5,2)+5.*P(5,1))
87     P(3,4)=P(3,3)+STEP
88     CALL STOER(P(1,4),BQ3,R3)
89     DO 1111 J=1,3
90     C DO 1111 I=1,8
91     DO 1111 I=1,7
92     1111 P(I,J)=P(I,J+1)
93     B=SQRT(BQ3)
94     IF(B.LT.BMIN) BMIN=B
95     IF(B.LE.BOLD) THEN
96     BOLD=B
97     ROLD=1./R3
98     SP(1)=P(1,4)
99     SP(2)=P(2,4)
100     SP(3)=P(3,4)
101     GOTO 5555
102     ENDIF
103     IF(BOLD.NE.BMIN) THEN
104     VALUE=.FALSE.
105     ENDIF
106     BDELTA=(B-BOLD)/BOLD
107     IF(BDELTA.GT.BDEL) THEN
108     STEP=STEP/10.
109     GOTO 7777
110     ENDIF
111     8888 RR0=ROLD
112     BEQU=BOLD
113     BDEL=BDELTA
114     RETURN
115     END
116     C
117     C
118     SUBROUTINE SHELLG(GLAT,GLON,ALT,DIMO,FL,ICODE,B0)
119     C--------------------------------------------------------------------
120     C CALCULATES L-VALUE FOR SPECIFIED GEODAETIC COORDINATES, ALTITUDE
121     C AND GEMAGNETIC FIELD MODEL.
122     C REF: G. KLUGE, EUROPEAN SPACE OPERATIONS CENTER, INTERNAL NOTE
123     C NO. 67, 1970.
124     C G. KLUGE, COMPUTER PHYSICS COMMUNICATIONS 3, 31-35, 1972
125     C--------------------------------------------------------------------
126     C CHANGES (D. BILITZA, NOV 87):
127     C - USING CORRECT DIPOL MOMENT I.E.,DIFFERENT COMMON/MODEL/
128     C - USING IGRF EARTH MAGNETIC FIELD MODELS FROM 1945 TO 1990
129     C--------------------------------------------------------------------
130     C INPUT: ENTRY POINT SHELLG
131     C GLAT GEODETIC LATITUDE IN DEGREES (NORTH)
132     C GLON GEODETIC LONGITUDE IN DEGREES (EAST)
133     C ALT ALTITUDE IN KM ABOVE SEA LEVEL
134     C
135     C ENTRY POINT SHELLC
136     C V(3) CARTESIAN COORDINATES IN EARTH RADII (6371.2 KM)
137     C X-AXIS POINTING TO EQUATOR AT 0 LONGITUDE
138     C Y-AXIS POINTING TO EQUATOR AT 90 LONG.
139     C Z-AXIS POINTING TO NORTH POLE
140     C
141     C DIMO DIPOL MOMENT IN GAUSS (NORMALIZED TO EARTH RADIUS)
142     C
143     C COMMON
144     C X(3) NOT USED
145     C H(144) FIELD MODEL COEFFICIENTS ADJUSTED FOR SHELLG
146     C-----------------------------------------------------------------------
147     C OUTPUT: FL L-VALUE
148     C ICODE =1 NORMAL COMPLETION
149     C =2 UNPHYSICAL CONJUGATE POINT (FL MEANINGLESS)
150     C =3 SHELL PARAMETER GREATER THAN LIMIT UP TO
151     C WHICH ACCURATE CALCULATION IS REQUIRED;
152     C APPROXIMATION IS USED.
153     C B0 MAGNETIC FIELD STRENGTH IN GAUSS
154     C-----------------------------------------------------------------------
155     DIMENSION V(3),U(3,3),P(8,100),SP(3)
156 mocchiut 1.6 COMMON X(3),H(196)
157 mocchiut 1.1 COMMON/FIDB0/ SP
158     SAVE /FIDB0/
159 mocchiut 1.9 COMMON/GENER/ UMR,ERA,AQUAD,BQUAD
160 mocchiut 1.1 SAVE /GENER/
161 mocchiut 1.11 REAL FLS
162 mocchiut 1.1 C
163     C-- RMIN, RMAX ARE BOUNDARIES FOR IDENTIFICATION OF ICODE=2 AND 3
164     C-- STEP IS STEP SIZE FOR FIELD LINE TRACING
165     C-- STEQ IS STEP SIZE FOR INTEGRATION
166     C
167     DATA RMIN,RMAX /0.05,1.01/
168     DATA STEP,STEQ /0.20,0.03/
169 mocchiut 1.11 BEQU=1.E10
170     FLS = FL
171 mocchiut 1.1 C*****ENTRY POINT SHELLG TO BE USED WITH GEODETIC CO-ORDINATES
172     RLAT=GLAT*UMR
173     CT=SIN(RLAT)
174     ST=COS(RLAT)
175     D=SQRT(AQUAD-(AQUAD-BQUAD)*CT*CT)
176     X(1)=(ALT+AQUAD/D)*ST/ERA
177     X(3)=(ALT+BQUAD/D)*CT/ERA
178     RLON=GLON*UMR
179     X(2)=X(1)*SIN(RLON)
180     X(1)=X(1)*COS(RLON)
181     GOTO9
182     ENTRY SHELLC(V,FL,B0)
183     C*****ENTRY POINT SHELLC TO BE USED WITH CARTESIAN CO-ORDINATES
184     X(1)=V(1)
185     X(2)=V(2)
186     X(3)=V(3)
187     C*****CONVERT TO DIPOL-ORIENTED CO-ORDINATES
188     DATA U/ +0.3511737,-0.9148385,-0.1993679,
189     A +0.9335804,+0.3583680,+0.0000000,
190     B +0.0714471,-0.1861260,+0.9799247/
191     9 RQ=1./(X(1)*X(1)+X(2)*X(2)+X(3)*X(3))
192     R3H=SQRT(RQ*SQRT(RQ))
193     P(1,2)=(X(1)*U(1,1)+X(2)*U(2,1)+X(3)*U(3,1))*R3H
194     P(2,2)=(X(1)*U(1,2)+X(2)*U(2,2) )*R3H
195     P(3,2)=(X(1)*U(1,3)+X(2)*U(2,3)+X(3)*U(3,3))*RQ
196     C*****FIRST THREE POINTS OF FIELD LINE
197     STEP=-SIGN(STEP,P(3,2))
198     CALL STOER(P(1,2),BQ2,R2)
199     B0=SQRT(BQ2)
200     P(1,3)=P(1,2)+0.5*STEP*P(4,2)
201     P(2,3)=P(2,2)+0.5*STEP*P(5,2)
202     P(3,3)=P(3,2)+0.5*STEP
203     CALL STOER(P(1,3),BQ3,R3)
204     P(1,1)=P(1,2)-STEP*(2.*P(4,2)-P(4,3))
205     P(2,1)=P(2,2)-STEP*(2.*P(5,2)-P(5,3))
206     P(3,1)=P(3,2)-STEP
207     CALL STOER(P(1,1),BQ1,R1)
208     P(1,3)=P(1,2)+STEP*(20.*P(4,3)-3.*P(4,2)+P(4,1))/18.
209     P(2,3)=P(2,2)+STEP*(20.*P(5,3)-3.*P(5,2)+P(5,1))/18.
210     P(3,3)=P(3,2)+STEP
211     CALL STOER(P(1,3),BQ3,R3)
212     C*****INVERT SENSE IF REQUIRED
213     IF(BQ3.LE.BQ1)GOTO2
214     STEP=-STEP
215     R3=R1
216     BQ3=BQ1
217     DO 1 I=1,7
218     ZZ=P(I,1)
219     P(I,1)=P(I,3)
220     1 P(I,3)=ZZ
221     C*****SEARCH FOR LOWEST MAGNETIC FIELD STRENGTH
222     2 IF(BQ1.LT.BEQU) THEN
223     BEQU=BQ1
224     IEQU=1
225     ENDIF
226     IF(BQ2.LT.BEQU) THEN
227     BEQU=BQ2
228     IEQU=2
229     ENDIF
230     IF(BQ3.LT.BEQU) THEN
231     BEQU=BQ3
232     IEQU=3
233     ENDIF
234     C*****INITIALIZATION OF INTEGRATION LOOPS
235     STEP12=STEP/12.
236     STEP2=STEP+STEP
237     STEQ=SIGN(STEQ,STEP)
238     FI=0.
239     ICODE=1
240     ORADIK=0.
241     OTERM=0.
242     STP=R2*STEQ
243     Z=P(3,2)+STP
244     STP=STP/0.75
245     P(8,1)=STEP2*(P(1,1)*P(4,1)+P(2,1)*P(5,1))
246     P(8,2)=STEP2*(P(1,2)*P(4,2)+P(2,2)*P(5,2))
247     C*****MAIN LOOP (FIELD LINE TRACING)
248     DO 3 N=3,3333
249     C*****CORRECTOR (FIELD LINE TRACING)
250     P(1,N)=P(1,N-1)+STEP12*(5.*P(4,N)+8.*P(4,N-1)-P(4,N-2))
251     P(2,N)=P(2,N-1)+STEP12*(5.*P(5,N)+8.*P(5,N-1)-P(5,N-2))
252     C*****PREPARE EXPANSION COEFFICIENTS FOR INTERPOLATION
253     C*****OF SLOWLY VARYING QUANTITIES
254     P(8,N)=STEP2*(P(1,N)*P(4,N)+P(2,N)*P(5,N))
255     C0=P(1,N-1)**2+P(2,N-1)**2
256     C1=P(8,N-1)
257     C2=(P(8,N)-P(8,N-2))*0.25
258     C3=(P(8,N)+P(8,N-2)-C1-C1)/6.0
259     D0=P(6,N-1)
260     D1=(P(6,N)-P(6,N-2))*0.5
261     D2=(P(6,N)+P(6,N-2)-D0-D0)*0.5
262     E0=P(7,N-1)
263     E1=(P(7,N)-P(7,N-2))*0.5
264     E2=(P(7,N)+P(7,N-2)-E0-E0)*0.5
265     C*****INNER LOOP (FOR QUADRATURE)
266     4 T=(Z-P(3,N-1))/STEP
267     IF(T.GT.1.)GOTO5
268     HLI=0.5*(((C3*T+C2)*T+C1)*T+C0)
269     ZQ=Z*Z
270     R=HLI+SQRT(HLI*HLI+ZQ)
271 mocchiut 1.11 IF(R.NE.R)THEN
272     FL = FLS
273     RETURN
274     ENDIF
275 mocchiut 1.1 IF(R.LE.RMIN)GOTO30
276     RQ=R*R
277     FF=SQRT(1.+3.*ZQ/RQ)
278     RADIK=B0-((D2*T+D1)*T+D0)*R*RQ*FF
279 mocchiut 1.3 IF((R-RMAX).le.0.) goto 44
280     IF((R-RMAX).gt.0.) goto 45
281 mocchiut 1.1 45 ICODE=2
282     RADIK=RADIK-12.*(R-RMAX)**2
283     44 IF(RADIK+RADIK.LE.ORADIK) GOTO 10
284     TERM=SQRT(RADIK)*FF*((E2*T+E1)*T+E0)/(RQ+ZQ)
285     FI=FI+STP*(OTERM+TERM)
286     ORADIK=RADIK
287     OTERM=TERM
288     STP=R*STEQ
289     Z=Z+STP
290     GOTO4
291     C*****PREDICTOR (FIELD LINE TRACING)
292     5 P(1,N+1)=P(1,N)+STEP12*(23.*P(4,N)-16.*P(4,N-1)+5.*P(4,N-2))
293     P(2,N+1)=P(2,N)+STEP12*(23.*P(5,N)-16.*P(5,N-1)+5.*P(5,N-2))
294     P(3,N+1)=P(3,N)+STEP
295     CALL STOER(P(1,N+1),BQ3,R3)
296     C*****SEARCH FOR LOWEST MAGNETIC FIELD STRENGTH
297     IF(BQ3.LT.BEQU) THEN
298     IEQU=N+1
299     BEQU=BQ3
300     ENDIF
301     3 CONTINUE
302     10 IF(IEQU.lt.2) IEQU=2
303     SP(1)=P(1,IEQU-1)
304     SP(2)=P(2,IEQU-1)
305     SP(3)=P(3,IEQU-1)
306     IF(ORADIK.LT.1E-15)GOTO11
307     FI=FI+STP/0.75*OTERM*ORADIK/(ORADIK-RADIK)
308     C
309     C-- The minimal allowable value of FI was changed from 1E-15 to 1E-12,
310     C-- because 1E-38 is the minimal allowable arg. for ALOG in our envir.
311     C-- D. Bilitza, Nov 87.
312     C
313 mocchiut 1.4 11 FI=0.5*ABS(FI)/SQRT(B0)+1E-12
314 mocchiut 1.1 C
315     C*****COMPUTE L FROM B AND I. SAME AS CARMEL IN INVAR.
316     C
317     C-- Correct dipole moment is used here. D. Bilitza, Nov 87.
318     C
319     DIMOB0=DIMO/B0
320 mocchiut 1.9 arg1=alog(FI)
321     arg2=alog(DIMOB0)
322 mocchiut 1.4 c arg = FI*FI*FI/DIMOB0
323     c if(abs(arg).gt.88.0) arg=88.0
324 mocchiut 1.1 XX=3*arg1-arg2
325     IF(XX.GT.23.0) GOTO 776
326     IF(XX.GT.11.7) GOTO 775
327     IF(XX.GT.+3.0) GOTO 774
328     IF(XX.GT.-3.0) GOTO 773
329     IF(XX.GT.-22.) GOTO 772
330 mocchiut 1.3 c 771 GG=3.33338E-1*XX+3.0062102E-1
331     GG=3.33338E-1*XX+3.0062102E-1
332 mocchiut 1.1 GOTO777
333     772 GG=((((((((-8.1537735E-14*XX+8.3232531E-13)*XX+1.0066362E-9)*XX+
334     18.1048663E-8)*XX+3.2916354E-6)*XX+8.2711096E-5)*XX+1.3714667E-3)*
335     2XX+1.5017245E-2)*XX+4.3432642E-1)*XX+6.2337691E-1
336     GOTO777
337     773 GG=((((((((2.6047023E-10*XX+2.3028767E-9)*XX-2.1997983E-8)*XX-
338     15.3977642E-7)*XX-3.3408822E-6)*XX+3.8379917E-5)*XX+1.1784234E-3)*
339     2XX+1.4492441E-2)*XX+4.3352788E-1)*XX+6.228644E-1
340     GOTO777
341     774 GG=((((((((6.3271665E-10*XX-3.958306E-8)*XX+9.9766148E-07)*XX-
342     11.2531932E-5)*XX+7.9451313E-5)*XX-3.2077032E-4)*XX+2.1680398E-3)*
343     2XX+1.2817956E-2)*XX+4.3510529E-1)*XX+6.222355E-1
344     GOTO777
345     775 GG=(((((2.8212095E-8*XX-3.8049276E-6)*XX+2.170224E-4)*XX-6.7310339
346     1E-3)*XX+1.2038224E-1)*XX-1.8461796E-1)*XX+2.0007187E0
347     GOTO777
348     776 GG=XX-3.0460681E0
349 mocchiut 1.9 777 FL=EXP(ALOG((1.+EXP(GG))*DIMOB0)/3.0)
350 mocchiut 1.1 RETURN
351     C*****APPROXIMATION FOR HIGH VALUES OF L.
352     30 ICODE=3
353     T=-P(3,N-1)/STEP
354     FL=1./(ABS(((C3*T+C2)*T+C1)*T+C0)+1E-15)
355     RETURN
356     END
357     C
358     C
359     SUBROUTINE STOER(P,BQ,R)
360     C*******************************************************************
361     C* SUBROUTINE USED FOR FIELD LINE TRACING IN SHELLG *
362     C* CALLS ENTRY POINT FELDI IN GEOMAGNETIC FIELD SUBROUTINE FELDG *
363     C*******************************************************************
364     DIMENSION P(7),U(3,3)
365 mocchiut 1.6 COMMON XI(3),H(196)
366 mocchiut 1.1 C*****XM,YM,ZM ARE GEOMAGNETIC CARTESIAN INVERSE CO-ORDINATES
367     ZM=P(3)
368     FLI=P(1)*P(1)+P(2)*P(2)+1E-15
369     R=0.5*(FLI+SQRT(FLI*FLI+(ZM+ZM)**2))
370     RQ=R*R
371     WR=SQRT(R)
372     XM=P(1)*WR
373     YM=P(2)*WR
374     C*****TRANSFORM TO GEOGRAPHIC CO-ORDINATE SYSTEM
375     DATA U/ +0.3511737,-0.9148385,-0.1993679,
376     A +0.9335804,+0.3583680,+0.0000000,
377     B +0.0714471,-0.1861260,+0.9799247/
378     XI(1)=XM*U(1,1)+YM*U(1,2)+ZM*U(1,3)
379     XI(2)=XM*U(2,1)+YM*U(2,2)+ZM*U(2,3)
380     XI(3)=XM*U(3,1) +ZM*U(3,3)
381     C*****COMPUTE DERIVATIVES
382     C CALL FELDI(XI,H)
383     CALL FELDI
384     Q=H(1)/RQ
385     DX=H(3)+H(3)+Q*XI(1)
386     DY=H(4)+H(4)+Q*XI(2)
387     DZ=H(2)+H(2)+Q*XI(3)
388     C*****TRANSFORM BACK TO GEOMAGNETIC CO-ORDINATE SYSTEM
389     DXM=U(1,1)*DX+U(2,1)*DY+U(3,1)*DZ
390     DYM=U(1,2)*DX+U(2,2)*DY
391     DZM=U(1,3)*DX+U(2,3)*DY+U(3,3)*DZ
392     DR=(XM*DXM+YM*DYM+ZM*DZM)/R
393     C*****FORM SLOWLY VARYING EXPRESSIONS
394     P(4)=(WR*DXM-0.5*P(1)*DR)/(R*DZM)
395     P(5)=(WR*DYM-0.5*P(2)*DR)/(R*DZM)
396     DSQ=RQ*(DXM*DXM+DYM*DYM+DZM*DZM)
397     BQ=DSQ*RQ*RQ
398     P(6)=SQRT(DSQ/(RQ+3.*ZM*ZM))
399     P(7)=P(6)*(RQ+ZM*ZM)/(RQ*DZM)
400     RETURN
401     END
402     C
403     C
404     SUBROUTINE FELDG(GLAT,GLON,ALT,BNORTH,BEAST,BDOWN,BABS)
405     C-------------------------------------------------------------------
406     C CALCULATES EARTH MAGNETIC FIELD FROM SPHERICAL HARMONICS MODEL
407     C REF: G. KLUGE, EUROPEAN SPACE OPERATIONS CENTRE, INTERNAL NOTE 61,
408     C 1970.
409     C--------------------------------------------------------------------
410     C CHANGES (D. BILITZA, NOV 87):
411     C - FIELD COEFFICIENTS IN BINARY DATA FILES INSTEAD OF BLOCK DATA
412     C - CALCULATES DIPOL MOMENT
413     C--------------------------------------------------------------------
414     C INPUT: ENTRY POINT FELDG
415     C GLAT GEODETIC LATITUDE IN DEGREES (NORTH)
416     C GLON GEODETIC LONGITUDE IN DEGREES (EAST)
417     C ALT ALTITUDE IN KM ABOVE SEA LEVEL
418     C
419     C ENTRY POINT FELDC
420     C V(3) CARTESIAN COORDINATES IN EARTH RADII (6371.2 KM)
421     C X-AXIS POINTING TO EQUATOR AT 0 LONGITUDE
422     C Y-AXIS POINTING TO EQUATOR AT 90 LONG.
423     C Z-AXIS POINTING TO NORTH POLE
424     C
425     C COMMON BLANK AND ENTRY POINT FELDI ARE NEEDED WHEN USED
426     C IN CONNECTION WITH L-CALCULATION PROGRAM SHELLG.
427     C
428     C COMMON /MODEL/ AND /GENER/
429     C UMR = ATAN(1.0)*4./180. <DEGREE>*UMR=<RADIANT>
430     C ERA EARTH RADIUS FOR NORMALIZATION OF CARTESIAN
431     C COORDINATES (6371.2 KM)
432     C AQUAD, BQUAD SQUARE OF MAJOR AND MINOR HALF AXIS FOR
433     C EARTH ELLIPSOID AS RECOMMENDED BY INTERNATIONAL
434     C ASTRONOMICAL UNION (6378.160, 6356.775 KM).
435     C NMAX MAXIMUM ORDER OF SPHERICAL HARMONICS
436     C TIME YEAR (DECIMAL: 1973.5) FOR WHICH MAGNETIC
437     C FIELD IS TO BE CALCULATED
438     C G(M) NORMALIZED FIELD COEFFICIENTS (SEE FELDCOF)
439     C M=NMAX*(NMAX+2)
440     C------------------------------------------------------------------------
441     C OUTPUT: BABS MAGNETIC FIELD STRENGTH IN GAUSS
442     C BNORTH, BEAST, BDOWN COMPONENTS OF THE FIELD WITH RESPECT
443     C TO THE LOCAL GEODETIC COORDINATE SYSTEM, WITH AXIS
444     C POINTING IN THE TANGENTIAL PLANE TO THE NORTH, EAST
445     C AND DOWNWARD.
446     C-----------------------------------------------------------------------
447 mocchiut 1.6 DIMENSION V(3),B(3),G(196)
448 mocchiut 1.1 CHARACTER*258 NAME
449     INTEGER NMAX
450     REAL TIME
451 mocchiut 1.6 COMMON XI(3),H(196)
452 mocchiut 1.1 COMMON/MODEL/ G,NMAX,TIME,NAME
453     SAVE/MODEL/
454 mocchiut 1.9 COMMON/GENER/ UMR,ERA,AQUAD,BQUAD
455 mocchiut 1.1 SAVE/GENER/
456     C
457     C-- IS RECORDS ENTRY POINT
458     C
459     C*****ENTRY POINT FELDG TO BE USED WITH GEODETIC CO-ORDINATES
460     IS=1
461     RLAT=GLAT*UMR
462     CT=SIN(RLAT)
463     ST=COS(RLAT)
464     D=SQRT(AQUAD-(AQUAD-BQUAD)*CT*CT)
465     RLON=GLON*UMR
466     CP=COS(RLON)
467     SP=SIN(RLON)
468     ZZZ=(ALT+BQUAD/D)*CT/ERA
469     RHO=(ALT+AQUAD/D)*ST/ERA
470     XXX=RHO*CP
471     YYY=RHO*SP
472     GOTO10
473     ENTRY FELDC(V,B)
474     C*****ENTRY POINT FELDC TO BE USED WITH CARTESIAN CO-ORDINATES
475     IS=2
476     XXX=V(1)
477     YYY=V(2)
478     ZZZ=V(3)
479     10 RQ=1./(XXX*XXX+YYY*YYY+ZZZ*ZZZ)
480     XI(1)=XXX*RQ
481     XI(2)=YYY*RQ
482     XI(3)=ZZZ*RQ
483     GOTO20
484     ENTRY FELDI
485     C*****ENTRY POINT FELDI USED FOR L COMPUTATION
486     IS=3
487     20 IHMAX=NMAX*NMAX+1
488     LAST=IHMAX+NMAX+NMAX
489     IMAX=NMAX+NMAX-1
490     DO 8 I=IHMAX,LAST
491     8 H(I)=G(I)
492     DO 6 K=1,3,2
493     I=IMAX
494     IH=IHMAX
495     1 IL=IH-I
496     F=2./FLOAT(I-K+2)
497     X=XI(1)*F
498     Y=XI(2)*F
499     Z=XI(3)*(F+F)
500     I=I-2
501 mocchiut 1.3 c print *,' I ',I
502     IF((I-1).lt.0) goto 5
503     IF((I-1).eq.0) goto 4
504     IF((I-1).gt.0) goto 2
505 mocchiut 1.1 2 DO 3 M=3,I,2
506     H(IL+M+1)=G(IL+M+1)+Z*H(IH+M+1)+X*(H(IH+M+3)-H(IH+M-1))
507     A -Y*(H(IH+M+2)+H(IH+M-2))
508     3 H(IL+M)=G(IL+M)+Z*H(IH+M)+X*(H(IH+M+2)-H(IH+M-2))
509     A +Y*(H(IH+M+3)+H(IH+M-1))
510     4 H(IL+2)=G(IL+2)+Z*H(IH+2)+X*H(IH+4)-Y*(H(IH+3)+H(IH))
511     H(IL+1)=G(IL+1)+Z*H(IH+1)+Y*H(IH+4)+X*(H(IH+3)-H(IH))
512     5 H(IL)=G(IL)+Z*H(IH)+2.*(X*H(IH+1)+Y*H(IH+2))
513     IH=IL
514     IF(I.GE.K)GOTO1
515     6 CONTINUE
516     IF(IS.EQ.3)RETURN
517     S=.5*H(1)+2.*(H(2)*XI(3)+H(3)*XI(1)+H(4)*XI(2))
518     T=(RQ+RQ)*SQRT(RQ)
519     BXXX=T*(H(3)-S*XXX)
520     BYYY=T*(H(4)-S*YYY)
521     BZZZ=T*(H(2)-S*ZZZ)
522     IF(IS.EQ.2)GOTO7
523     BABS=SQRT(BXXX*BXXX+BYYY*BYYY+BZZZ*BZZZ)
524     BEAST=BYYY*CP-BXXX*SP
525     BRHO=BYYY*SP+BXXX*CP
526     BNORTH=BZZZ*ST-BRHO*CT
527     BDOWN=-BZZZ*CT-BRHO*ST
528     RETURN
529     7 B(1)=BXXX
530     B(2)=BYYY
531     B(3)=BZZZ
532     RETURN
533     END
534     C
535     C
536 mocchiut 1.3 SUBROUTINE FELDCOF(YEAR,DIMO)
537 mocchiut 1.1 C------------------------------------------------------------------------
538 mocchiut 1.3 C DETERMINES COEFFICIENTS AND DIPOL MOMENT FROM IGRF MODELS
539     C
540     C INPUT: YEAR DECIMAL YEAR FOR WHICH GEOMAGNETIC FIELD IS TO
541     C BE CALCULATED
542     C OUTPUT: DIMO GEOMAGNETIC DIPOL MOMENT IN GAUSS (NORMALIZED
543     C TO EARTH'S RADIUS) AT THE TIME (YEAR)
544     C D. BILITZA, NSSDC, GSFC, CODE 633, GREENBELT, MD 20771,
545     C (301)286-9536 NOV 1987.
546     C ### updated to IGRF-2000 version -dkb- 5/31/2000
547     C ### updated to IGRF-2005 version -dkb- 3/24/2000
548 mocchiut 1.1 C-----------------------------------------------------------------------
549 mocchiut 1.3 CHARACTER*258 FIL1, FIL2
550     CHARACTER*258 FILMOD
551 mocchiut 1.12 DIMENSION GH1(196),GH2(196),GHA(196),FILMOD(2)
552 mocchiut 1.3 DOUBLE PRECISION X,F0,F
553 mocchiut 1.12 INTEGER L1,L2,I1
554 mocchiut 1.3 INTEGER NMAX
555     REAL TIME
556 mocchiut 1.12 CHARACTER *258 P1,P2
557     COMMON/PPATH/ I1,L1,L2,P1,P2
558 mocchiut 1.3 SAVE/PPATH/
559     COMMON/MODEL/ GH1,NMAX,TIME,FIL1
560     SAVE/MODEL/
561 mocchiut 1.9 COMMON/GENER/ UMR,ERAD,AQUAD,BQUAD
562 mocchiut 1.3 SAVE/GENER/
563 mocchiut 1.7 c print *, "qui"
564 mocchiut 1.1 FILMOD(1) = P1(1:L1)
565     FILMOD(2) = P2(1:L2)
566 mocchiut 1.7 c print *, "qua"
567 mocchiut 1.3 C
568     C IS=0 FOR SCHMIDT NORMALIZATION IS=1 GAUSS NORMALIZATION
569     C IU IS INPUT UNIT NUMBER FOR IGRF COEFFICIENT SETS
570     C
571     IU = 10
572     IS = 0
573     C-- DETERMINE IGRF-YEARS FOR INPUT-YEAR
574     TIME = YEAR
575     IYEA = INT(YEAR/5.)*5
576 mocchiut 1.12 L = IYEA + 5
577     C
578     DTE1 = REAL(IYEA)
579     FIL1 = FILMOD(1)
580     DTE2 = REAL(L)
581     FIL2 = FILMOD(2)
582     c print *,'IYEA ',IYEA,' L ',L
583 mocchiut 1.7 c WRITE(*,*) FIL1
584     c WRITE(*,*) FIL2
585     c print *, "que"
586 mocchiut 1.3 C-- GET IGRF COEFFICIENTS FOR THE BOUNDARY YEARS
587     CALL GETSHC (IU, FIL1, NMAX1, ERAD, GH1, IER)
588     IF (IER .NE. 0) STOP
589 mocchiut 1.7 c print *, "quessss"
590 mocchiut 1.3 CALL GETSHC (IU, FIL2, NMAX2, ERAD, GH2, IER)
591     IF (IER .NE. 0) STOP
592 mocchiut 1.7 c print *, "quj"
593 mocchiut 1.3 C-- DETERMINE IGRF COEFFICIENTS FOR YEAR
594 mocchiut 1.12 IF (I1.EQ.0) THEN
595 mocchiut 1.3 CALL INTERSHC (YEAR, DTE1, NMAX1, GH1, DTE2,
596     1 NMAX2, GH2, NMAX, GHA)
597     ELSE
598     CALL EXTRASHC (YEAR, DTE1, NMAX1, GH1, NMAX2,
599     1 GH2, NMAX, GHA)
600     ENDIF
601 mocchiut 1.7 c print *, "quw"
602 mocchiut 1.3 C-- DETERMINE MAGNETIC DIPOL MOMENT AND COEFFIECIENTS G
603     F0=0.D0
604     DO 1234 J=1,3
605     F = GHA(J) * 1.D-5
606     F0 = F0 + F * F
607     1234 CONTINUE
608 mocchiut 1.9 DIMO = REAL(DSQRT(F0))
609 mocchiut 1.3
610     GH1(1) = 0.0
611     I=2
612     F0=1.D-5
613     IF(IS.EQ.0) F0=-F0
614     SQRT2=SQRT(2.)
615 mocchiut 1.1
616 mocchiut 1.3 c print *, "quq"
617    
618 mocchiut 1.1 DO 9 N=1,NMAX
619 mocchiut 1.3 X = N
620     F0 = F0 * X * X / (4.D0 * X - 2.D0)
621     IF(IS.EQ.0) F0 = F0 * (2.D0 * X - 1.D0) / X
622     F = F0 * 0.5D0
623     IF(IS.EQ.0) F = F * SQRT2
624 mocchiut 1.9 GH1(I) = GHA(I-1) * REAL(F0)
625 mocchiut 1.3 I = I+1
626     DO 9 M=1,N
627     F = F * (X + M) / (X - M + 1.D0)
628     IF(IS.EQ.0) F = F * DSQRT((X - M + 1.D0) / (X + M))
629 mocchiut 1.9 GH1(I) = GHA(I-1) * REAL(F)
630     GH1(I+1) = GHA(I) * REAL(F)
631 mocchiut 1.3 I=I+2
632     9 CONTINUE
633     RETURN
634     END
635     C
636     C
637     SUBROUTINE GETSHC (IU, FSPEC, NMAX, ERAD, GH, IER)
638 mocchiut 1.9
639 mocchiut 1.1 C ===============================================================
640     C
641 mocchiut 1.3 C Version 1.01
642     C
643     C Reads spherical harmonic coefficients from the specified
644     C file into an array.
645     C
646     C Input:
647     C IU - Logical unit number
648     C FSPEC - File specification
649     C
650     C Output:
651     C NMAX - Maximum degree and order of model
652     C ERAD - Earth's radius associated with the spherical
653     C harmonic coefficients, in the same units as
654     C elevation
655     C GH - Schmidt quasi-normal internal spherical
656     C harmonic coefficients
657     C IER - Error number: = 0, no error
658     C = -2, records out of order
659     C = FORTRAN run-time error number
660     C
661     C A. Zunde
662     C USGS, MS 964, Box 25046 Federal Center, Denver, CO 80225
663     C
664     C ===============================================================
665    
666     CHARACTER FSPEC*(*), FOUT*258
667     DIMENSION GH(*)
668     C ---------------------------------------------------------------
669     C Open coefficient file. Read past first header record.
670     C Read degree and order of model and Earth's radius.
671     C ---------------------------------------------------------------
672 mocchiut 1.1 WRITE(FOUT,667) FSPEC
673 mocchiut 1.3 c 667 FORMAT('/usr/local/etc/httpd/cgi-bin/natasha/IRI/',A12)
674     667 FORMAT(A258)
675 mocchiut 1.7 c print *," gui"
676 mocchiut 1.1 OPEN (IU, FILE=FOUT, STATUS='OLD', IOSTAT=IER, ERR=999)
677 mocchiut 1.7 c print *," gua"
678 mocchiut 1.1 READ (IU, *, IOSTAT=IER, ERR=999)
679 mocchiut 1.7 c print *," gue"
680 mocchiut 1.1 READ (IU, *, IOSTAT=IER, ERR=999) NMAX, ERAD
681 mocchiut 1.7 c print *," guo"
682 mocchiut 1.1 C ---------------------------------------------------------------
683     C Read the coefficient file, arranged as follows:
684     C
685     C N M G H
686     C ----------------------
687     C / 1 0 GH(1) -
688     C / 1 1 GH(2) GH(3)
689     C / 2 0 GH(4) -
690     C / 2 1 GH(5) GH(6)
691     C NMAX*(NMAX+3)/2 / 2 2 GH(7) GH(8)
692     C records \ 3 0 GH(9) -
693     C \ . . . .
694     C \ . . . .
695     C NMAX*(NMAX+2) \ . . . .
696     C elements in GH \ NMAX NMAX . .
697     C
698     C N and M are, respectively, the degree and order of the
699     C coefficient.
700     C ---------------------------------------------------------------
701    
702     I = 0
703 mocchiut 1.3 DO 2211 NN = 1, NMAX
704     DO 2233 MM = 0, NN
705 mocchiut 1.1 READ (IU, *, IOSTAT=IER, ERR=999) N, M, G, H
706     IF (NN .NE. N .OR. MM .NE. M) THEN
707     IER = -2
708     GOTO 999
709     ENDIF
710     I = I + 1
711     GH(I) = G
712     IF (M .NE. 0) THEN
713     I = I + 1
714     GH(I) = H
715     ENDIF
716     2233 CONTINUE
717     2211 CONTINUE
718 mocchiut 1.7 c print *," guj"
719 mocchiut 1.1
720     999 CLOSE (IU)
721 mocchiut 1.7 c print *," guw IER",IER
722 mocchiut 1.3 if ( IER .eq. -1 ) IER = 0 ! gfortran 4.1.2 bug workaround... hoping not to create problems with other versions
723 mocchiut 1.1
724     RETURN
725     END
726     C
727     C
728     SUBROUTINE INTERSHC (DATE, DTE1, NMAX1, GH1, DTE2,
729     1 NMAX2, GH2, NMAX, GH)
730 mocchiut 1.9
731 mocchiut 1.1 C ===============================================================
732     C
733     C Version 1.01
734     C
735     C Interpolates linearly, in time, between two spherical
736     C harmonic models.
737     C
738     C Input:
739     C DATE - Date of resulting model (in decimal year)
740     C DTE1 - Date of earlier model
741     C NMAX1 - Maximum degree and order of earlier model
742     C GH1 - Schmidt quasi-normal internal spherical
743     C harmonic coefficients of earlier model
744     C DTE2 - Date of later model
745     C NMAX2 - Maximum degree and order of later model
746     C GH2 - Schmidt quasi-normal internal spherical
747     C harmonic coefficients of later model
748     C
749     C Output:
750     C GH - Coefficients of resulting model
751     C NMAX - Maximum degree and order of resulting model
752     C
753     C A. Zunde
754     C USGS, MS 964, Box 25046 Federal Center, Denver, CO 80225
755     C
756     C ===============================================================
757    
758     DIMENSION GH1(*), GH2(*), GH(*)
759    
760     C ---------------------------------------------------------------
761     C The coefficients (GH) of the resulting model, at date
762     C DATE, are computed by linearly interpolating between the
763     C coefficients of the earlier model (GH1), at date DTE1,
764     C and those of the later model (GH2), at date DTE2. If one
765     C model is smaller than the other, the interpolation is
766     C performed with the missing coefficients assumed to be 0.
767     C ---------------------------------------------------------------
768    
769     FACTOR = (DATE - DTE1) / (DTE2 - DTE1)
770    
771     IF (NMAX1 .EQ. NMAX2) THEN
772     K = NMAX1 * (NMAX1 + 2)
773     NMAX = NMAX1
774     ELSE IF (NMAX1 .GT. NMAX2) THEN
775     K = NMAX2 * (NMAX2 + 2)
776     L = NMAX1 * (NMAX1 + 2)
777 mocchiut 1.3 DO 1122 I = K + 1, L
778 mocchiut 1.1 1122 GH(I) = GH1(I) + FACTOR * (-GH1(I))
779     NMAX = NMAX1
780     ELSE
781     K = NMAX1 * (NMAX1 + 2)
782     L = NMAX2 * (NMAX2 + 2)
783 mocchiut 1.3 DO 1133 I = K + 1, L
784 mocchiut 1.1 1133 GH(I) = FACTOR * GH2(I)
785     NMAX = NMAX2
786     ENDIF
787    
788 mocchiut 1.3 DO 1144 I = 1, K
789 mocchiut 1.1 1144 GH(I) = GH1(I) + FACTOR * (GH2(I) - GH1(I))
790    
791     RETURN
792     END
793     C
794     C
795     SUBROUTINE EXTRASHC (DATE, DTE1, NMAX1, GH1, NMAX2,
796     1 GH2, NMAX, GH)
797    
798     C ===============================================================
799     C
800     C Version 1.01
801     C
802     C Extrapolates linearly a spherical harmonic model with a
803     C rate-of-change model.
804     C
805     C Input:
806     C DATE - Date of resulting model (in decimal year)
807     C DTE1 - Date of base model
808     C NMAX1 - Maximum degree and order of base model
809     C GH1 - Schmidt quasi-normal internal spherical
810     C harmonic coefficients of base model
811     C NMAX2 - Maximum degree and order of rate-of-change
812     C model
813     C GH2 - Schmidt quasi-normal internal spherical
814     C harmonic coefficients of rate-of-change model
815     C
816     C Output:
817     C GH - Coefficients of resulting model
818     C NMAX - Maximum degree and order of resulting model
819     C
820     C A. Zunde
821     C USGS, MS 964, Box 25046 Federal Center, Denver, CO 80225
822     C
823     C ===============================================================
824    
825     DIMENSION GH1(*), GH2(*), GH(*)
826    
827     C ---------------------------------------------------------------
828     C The coefficients (GH) of the resulting model, at date
829     C DATE, are computed by linearly extrapolating the coef-
830     C ficients of the base model (GH1), at date DTE1, using
831     C those of the rate-of-change model (GH2), at date DTE2. If
832     C one model is smaller than the other, the extrapolation is
833     C performed with the missing coefficients assumed to be 0.
834     C ---------------------------------------------------------------
835    
836     FACTOR = (DATE - DTE1)
837    
838     IF (NMAX1 .EQ. NMAX2) THEN
839     K = NMAX1 * (NMAX1 + 2)
840     NMAX = NMAX1
841     ELSE IF (NMAX1 .GT. NMAX2) THEN
842     K = NMAX2 * (NMAX2 + 2)
843     L = NMAX1 * (NMAX1 + 2)
844 mocchiut 1.3 DO 1155 I = K + 1, L
845 mocchiut 1.1 1155 GH(I) = GH1(I)
846     NMAX = NMAX1
847     ELSE
848     K = NMAX1 * (NMAX1 + 2)
849     L = NMAX2 * (NMAX2 + 2)
850 mocchiut 1.3 DO 1166 I = K + 1, L
851 mocchiut 1.1 1166 GH(I) = FACTOR * GH2(I)
852     NMAX = NMAX2
853     ENDIF
854    
855 mocchiut 1.3 DO 1177 I = 1, K
856 mocchiut 1.1 1177 GH(I) = GH1(I) + FACTOR * GH2(I)
857    
858     RETURN
859     END
860     C
861     C
862 mocchiut 1.12 SUBROUTINE INITIZE(ISSEC,TP1,TL1,TP2,TL2)
863 mocchiut 1.1 C----------------------------------------------------------------
864     C Initializes the parameters in COMMON/GENER/
865     C
866     C UMR = ATAN(1.0)*4./180. <DEGREE>*UMR=<RADIANT>
867     C ERA EARTH RADIUS FOR NORMALIZATION OF CARTESIAN
868     C COORDINATES (6371.2 KM)
869     C EREQU MAJOR HALF AXIS FOR EARTH ELLIPSOID (6378.160 KM)
870     C ERPOL MINOR HALF AXIS FOR EARTH ELLIPSOID (6356.775 KM)
871     C AQUAD SQUARE OF MAJOR HALF AXIS FOR EARTH ELLIPSOID
872     C BQUAD SQUARE OF MINOR HALF AXIS FOR EARTH ELLIPSOID
873     C
874     C ERA, EREQU and ERPOL as recommended by the INTERNATIONAL
875     C ASTRONOMICAL UNION .
876     C-----------------------------------------------------------------
877 mocchiut 1.12 INTEGER TL1,TL2,ISSEC
878     CHARACTER (len=*) :: TP1,TP2
879     INTEGER L1,L2
880     CHARACTER *258 P1,P2
881     COMMON/PPATH/ I1,L1,L2,P1,P2
882 mocchiut 1.1 SAVE/PPATH/
883    
884 mocchiut 1.9 COMMON/GENER/UMR,ERA,AQUAD,BQUAD
885 mocchiut 1.1 SAVE/GENER/
886    
887 mocchiut 1.12 I1 = ISSEC
888 mocchiut 1.1 L1 = TL1
889     L2 = TL2
890 mocchiut 1.12
891 mocchiut 1.2 P1 = TP1(1:L1)
892     P2 = TP2(1:L2)
893 mocchiut 1.1
894     ERA=6371.2
895     EREQU=6378.16
896     ERPOL=6356.775
897     AQUAD=EREQU*EREQU
898     BQUAD=ERPOL*ERPOL
899     UMR=ATAN(1.0)*4./180.
900     RETURN
901     END

  ViewVC Help
Powered by ViewVC 1.1.23