Ignore:
Timestamp:
Nov 6, 2012, 12:02:45 PM (12 years ago)
Author:
emillour
Message:

Mars GCM utility:

update of zrecast utility: now the planetary constants (radius, gravity,

reduced gas constant) are read from the "controle" array in the file and
not hard coded. That way zrecast can also be used for the generic model.
Note that the "distance to center of Mars" and "MCD" options still contain
some hard coded Mars constants.

EM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.MARS/util/zrecast.F90

    r788 r829  
    1 
     1module planet_const
     2! planetary constants (set via init_planet_const routine)
     3implicit none
     4real :: a0 ! Mean planetary radius (a0=3396.E3 for Mars)
     5real :: g0 ! gravity at a0  (Mars: g0=3.7257964 ; Lemoine et al. 2001)
     6real :: Rmean ! reduced gaz constant (Mars: R=191)
     7end module planet_const
    28
    39program zrecast
     
    5157! EM 03/2011 : Add possibility to have outputs as distance to center
    5258!              of planet
     59! EM 11/2012 : Adapted so it can be used on "generic" model outputs; planet
     60!              constants (radius, R, etc.) are now read from file
    5361implicit none
    5462
     
    154162endif
    155163
     164! load planet constants (radius, gravity, ...)
     165
     166call init_planet_const(infid)
     167 
    156168!===============================================================================
    157169! 1.2 Get # and names of variables in input file
     
    17431755end program
    17441756
     1757!===============================================================================
     1758
     1759subroutine init_planet_const(infid)
     1760! initialize planetary constants using the "controle" array in the file
     1761! if "cointrole" array not found in file, look for it in "diagfi.nc"
     1762use planet_const
     1763use netcdf
     1764implicit none
     1765
     1766integer,intent(in) :: infid ! input file ID
     1767
     1768! local variables
     1769character(len=100) :: varname
     1770integer :: varid ! variable ID
     1771integer :: status
     1772integer :: infid2 ! for an alternate input file
     1773real :: controle(100) ! to store "controle" array
     1774
     1775! look for "controle" in input file
     1776infid2=infid ! initialization
     1777varname="controle"
     1778status=nf90_inq_varid(infid,trim(varname),varid)
     1779if (status.ne.nf90_noerr) then
     1780  write(*,*) "init_planet_const: Failed to find ",trim(varname)
     1781  write(*,*) " looking for it in file diagfi.nc"
     1782  status=nf90_open("diagfi.nc",NF90_NOWRITE,infid2)
     1783  if (status.ne.nf90_noerr) then
     1784    write(*,*) " no diafi.nc file ... looking for diagfi1.nc"
     1785    status=nf90_open("diagfi1.nc",NF90_NOWRITE,infid2)
     1786    if (status.ne.nf90_noerr) then
     1787      write(*,*) "might as well stop here..."
     1788      stop
     1789    endif
     1790  endif
     1791  status=nf90_inq_varid(infid2,trim(varname),varid)
     1792  if (status.ne.nf90_noerr) then
     1793    write(*,*) " Failed to find ",trim(varname)," in file!!"
     1794    stop
     1795  endif
     1796  write(*,*) "OK, found ",trim(varname)
     1797endif
     1798status=nf90_get_var(infid2,varid,controle)
     1799if (status.ne.nf90_noerr) then
     1800  write(*,*) "init_planet_const: Failed to load ",trim(varname)
     1801  stop
     1802endif
     1803
     1804! now that we have "controle"; extract relevent informations
     1805a0=controle(5) ! = radius of planet (m)
     1806g0=controle(7) ! = gravity (m.s-2) at a0
     1807Rmean=1000.*8.314511/controle(8) ! controle(8)=mugaz = molar mass (g.mol-1) of atm.
     1808
     1809end subroutine init_planet_const
    17451810
    17461811!===============================================================================
     
    17521817!          surface altitudes" corresponding to GCM atmospheric levels
    17531818!==============================================================================
     1819use planet_const, only : a0,g0
    17541820implicit none
    17551821!==============================================================================
     
    17851851
    17861852! Parameters needed to integrate hydrostatic equation:
    1787 real,parameter :: g0=3.7257964
     1853!real,parameter :: g0=3.7257964
    17881854!g0: exact mean gravity at radius=3396.km (Lemoine et al. 2001)
    1789 real,parameter :: a0=3396.E3
     1855!real,parameter :: a0=3396.E3
    17901856!a0: 'mean' Mars radius=3396.km
    17911857real :: gz
     
    18711937!===============================================================================
    18721938
    1873 !#include"build_gcm_alt.F90"
    18741939subroutine build_gcm_za(lonlength,latlength,altlength,timelength, &
    18751940                         phis,ps,press,temp,rho,za_gcm)
     
    18781943!          altitudes" corresponding to GCM atmospheric levels
    18791944!==============================================================================
     1945use planet_const, only : a0,g0
    18801946implicit none
    18811947!==============================================================================
     
    19111977
    19121978! Parameters needed to integrate hydrostatic equation:
    1913 real,parameter :: g0=3.7257964
     1979!real,parameter :: g0=3.7257964
    19141980!g0: exact mean gravity at radius=3396.km (Lemoine et al. 2001)
    1915 real,parameter :: a0=3396.E3
     1981!real,parameter :: a0=3396.E3
    19161982!a0: 'mean' Mars radius=3396.km
    19171983real :: gz
     
    20622128!          surface altitudes" corresponding to GCM atmospheric levels
    20632129!==============================================================================
     2130use planet_const, only : a0,g0,Rmean
    20642131implicit none
    20652132!==============================================================================
     
    20862153!===============================================================================
    20872154real,dimension(:),allocatable :: sigma ! GCM sigma levels
    2088 real,parameter :: R=191 ! molecular gas constant
     2155!real,parameter :: R=191 ! molecular gas constant
    20892156!real,dimension(:,:,:,:),allocatable :: zlocal ! local above surface altitude
    20902157real :: Tmean ! "mean" value of temperature for a given level
     
    20922159
    20932160! Parameters needed to integrate hydrostatic equation:
    2094 real,parameter :: g0=3.7257964
     2161!real,parameter :: g0=3.7257964
    20952162!g0: exact mean gravity at radius=3396.km (Lemoine et al. 2001)
    2096 real,parameter :: a0=3396.E3
     2163!real,parameter :: a0=3396.E3
    20972164!a0: 'mean' Mars radius=3396.km
    20982165real :: gz
     
    21142181      sigma(1)=press(iloop,jloop,1,tloop)/ps(iloop,jloop,tloop)
    21152182      zs_gcm(iloop,jloop,1,tloop)=-log(sigma(1))* &
    2116                                                R*temp(iloop,jloop,1,tloop)/g0
     2183                                           Rmean*temp(iloop,jloop,1,tloop)/g0
    21172184!      za_gcm(iloop,jloop,1,tloop)=zlocal(iloop,jloop,1,tloop)+ &
    21182185!                                  phis(iloop,jloop)/g0
     
    21392206        ! compute zs_gcm(iloop,jloop,kloop,tloop)
    21402207        zs_gcm(iloop,jloop,kloop,tloop)=zs_gcm(iloop,jloop,kloop-1,tloop)- &
    2141                 log(sigma(kloop)/sigma(kloop-1))*R*Tmean/gz
     2208                log(sigma(kloop)/sigma(kloop-1))*Rmean*Tmean/gz
    21422209       
    21432210        ! compute za_gcm(kloop)
     
    21572224!===============================================================================
    21582225
    2159 !#include"crude_gcm_alt.F90"
    21602226subroutine crude_gcm_za(lonlength,latlength,altlength,timelength, &
    21612227                         phis,ps,press,temp,za_gcm)
     
    21642230!          altitudes" corresponding to GCM atmospheric levels
    21652231!==============================================================================
     2232use planet_const, only : a0,g0,Rmean
    21662233implicit none
    21672234!==============================================================================
     
    21882255!===============================================================================
    21892256real,dimension(:),allocatable :: sigma ! GCM sigma levels
    2190 real,parameter :: R=191 ! molecular gas constant
     2257!real,parameter :: R=191 ! molecular gas constant
    21912258real,dimension(:,:,:,:),allocatable :: zlocal ! local above surface altitude
    21922259real :: Tmean ! "mean" value of temperature for a given level
     
    21942261
    21952262! Parameters needed to integrate hydrostatic equation:
    2196 real,parameter :: g0=3.7257964
     2263!real,parameter :: g0=3.7257964
    21972264!g0: exact mean gravity at radius=3396.km (Lemoine et al. 2001)
    2198 real,parameter :: a0=3396.E3
     2265!real,parameter :: a0=3396.E3
    21992266!a0: 'mean' Mars radius=3396.km
    22002267real :: gz
     
    22162283      sigma(1)=press(iloop,jloop,1,tloop)/ps(iloop,jloop,tloop)
    22172284      zlocal(iloop,jloop,1,tloop)=-log(sigma(1))* &
    2218                                                R*temp(iloop,jloop,1,tloop)/g0
     2285                                            Rmean*temp(iloop,jloop,1,tloop)/g0
    22192286      za_gcm(iloop,jloop,1,tloop)=zlocal(iloop,jloop,1,tloop)+ &
    22202287                                  phis(iloop,jloop)/g0
     
    22392306        ! compute zlocal(kloop)
    22402307        zlocal(iloop,jloop,kloop,tloop)=zlocal(iloop,jloop,kloop-1,tloop)- &
    2241                 log(sigma(kloop)/sigma(kloop-1))*R*Tmean/gz
     2308                log(sigma(kloop)/sigma(kloop-1))*Rmean*Tmean/gz
    22422309       
    22432310        ! compute za_gcm(kloop)
     
    23322399!===============================================================================
    23332400
    2334 !#include"za_coord_interp.F90"
    23352401subroutine z_coord_interp(lonlen,latlen,altlen,tlen,newaltlen, &
    23362402                          missing,z_gcm,gcmdata,flag,z_new,newdata)
     
    24622528!       if flag=0, and extrapolated (exponentially) if flag=1.
    24632529!==============================================================================
     2530use planet_const, only : a0,g0,Rmean
    24642531implicit none
    24652532!==============================================================================
     
    25032570real :: x,y ! temporary variables
    25042571integer :: iloop,jloop,kloop,tloop
    2505 real,parameter :: g0=3.7257964
     2572!real,parameter :: g0=3.7257964
    25062573!g0: exact mean gravity at radius=3396.km (Lemoine et al. 2001)
    2507 real,parameter :: a0=3396.E3
     2574!real,parameter :: a0=3396.E3
    25082575!a0: 'mean' Mars radius=3396.km
    2509 real,parameter :: Rmean=191 ! molecular gas constant
     2576!real,parameter :: Rmean=191 ! molecular gas constant
    25102577real :: gz
    25112578! gz: gravitational acceleration at a given (above areoid) altitude
Note: See TracChangeset for help on using the changeset viewer.