source: trunk/LMDZ.MARS/libf/phymars/solarlong.F @ 3094

Last change on this file since 3094 was 3094, checked in by emillour, 13 months ago

Mars PCM:
Fix issues with dates when in parallel with OpenMP (missing copyin
statement when opening parallel section in iniphysiq). Added some threadprivate
clauses in saved module variables in comcstfi_h.F90 and planete_h.F90.
Prettyfied solarlong.F and made it a module. Likewise for conf_phys.F
EM

File size: 1.7 KB
Line 
1      MODULE solarlong_mod
2
3      IMPLICIT NONE
4
5      CONTAINS
6     
7      SUBROUTINE solarlong(pday,psollong)
8      use planete_h, only: lsperi, peri_day, year_day, e_elips
9      use comcstfi_h, only: pi
10      IMPLICIT NONE
11
12c=======================================================================
13c   Compute solar longitude psollong (in radians) for a given Mars date
14c   pday (where pday==0 at northern Spring Equinox and pday in sols
15c   and fractions thereof)
16c=======================================================================
17
18c arguments:
19c ----------
20
21      REAL,INTENT(IN) :: pday
22      REAL,INTENT(OUT) :: psollong
23     
24c Local variables:
25c ----------------
26
27      REAL :: xref ! mean anomaly
28      REAL :: zx0 ! eccentric anomaly
29      REAL :: zteta ! true anomaly
30      REAL :: zanom,zdx,zz
31      INTEGER :: iter
32
33
34c  compute mean anomaly
35
36      zz=(pday-peri_day)/year_day
37      pi=2.*asin(1.)
38      zanom=2.*pi*(zz-nint(zz))
39      xref=abs(zanom)
40
41c  solve equation  zx0 - e * sin (zx0) = xref
42c  using Newton method
43
44      zx0=xref+e_elips*sin(xref)
45      DO iter=1,10 ! 10 is overkill, typically converges in 1-3 iterations
46         zdx=-(zx0-e_elips*sin(zx0)-xref)/(1.-e_elips*cos(zx0))
47         if(abs(zdx).le.(1.e-7)) exit
48         zx0=zx0+zdx
49      ENDDO
50
51      zx0=zx0+zdx
52      if(zanom.lt.0.) zx0=-zx0
53
54c compute true anomaly zteta, now that eccentric anomaly zx0 is known
55
56      zteta=2.*atan(sqrt((1.+e_elips)/(1.-e_elips))*tan(zx0/2.))
57
58c compute solar longitude from zteta
59      psollong=zteta+lsperi
60
61c handle limit cases where psollong lands outside [0:2*pi]
62      IF(psollong.LT.0.) psollong=psollong+2.*pi
63      IF(psollong.GT.2.*pi) psollong=psollong-2.*pi
64
65      END SUBROUTINE solarlong
66
67      END MODULE solarlong_mod
Note: See TracBrowser for help on using the repository browser.