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

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

Mars PCM:
Some code tidying:
Made pi in module comcstfi_h a parameter (and not a variable recomputed at
various points by various routines) and added module routine init_comcstfi_h
to cleanly initialize module variables.
Moved iniorbit.F to be a module routine of planete_h since it initializes
(some of ) the module variables it contains.
EM

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