source: trunk/LMDZ.COMMON/libf/evolution/phys_constants.F90

Last change on this file was 3991, checked in by jbclement, 20 hours ago

PEM:
Apply documentation template everywhere: standardized headers format with short description, separators between functions/subroutines, normalized code sections, aligned dependencies/arguments/variables declaration.
JBC

File size: 3.3 KB
RevLine 
[3985]1MODULE phys_constants
[3991]2!-----------------------------------------------------------------------
3! NAME
4!     phys_constants
5!
6! DESCRIPTION
7!     Physical constants used across PEM modules.
8!
9! AUTHORS & DATE
10!     JB Clement, 12/2025
11!
12! NOTES
13!     Constants are initialized from NetCDF 'startfi.nc' via read_constants.
14!-----------------------------------------------------------------------
[3985]15
[3991]16! DECLARATION
17! -----------
[3985]18implicit none
19
[3991]20! MODULE PARAMETERS
21! -----------------
[3985]22real, parameter :: pi = 4.*atan(1.) ! PI = 3.14159...
23
24real :: g     ! Gravity (m/s2)
25real :: r     ! Reduced gas constant,r = 8.314511/(mugaz/1000.0)
26real :: mugaz ! Molar mass of the atmosphere (g/mol)
27real :: rad   ! Radius of the planet (m)
28real :: cpp   ! Cp of the atmosphere
29real :: rcp   ! r/cpp
30
31contains
[3991]32!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
[3985]34!=======================================================================
[3989]35SUBROUTINE read_constants(filename)
[3991]36!-----------------------------------------------------------------------
37! NAME
38!     read_constants
39!
40! DESCRIPTION
41!     Read physical constants from NetCDF file 'startfi.nc' in variable
42!     'controle' and initialize module-level constants.
43!
44! AUTHORS & DATE
45!     JB Clement, 12/2025
46!
47! NOTES
48!     Reads controle(5,7,8,9) for rad, g, mugaz, rcp and computes r.
49!-----------------------------------------------------------------------
[3985]50
[3991]51! DEPENDENCIES
52! ------------
[3985]53use netcdf
54
[3991]55! DECLARATION
56! -----------
[3985]57implicit none
58
[3991]59! ARGUMENTS
60! ---------
[3989]61character(*), intent(in) :: filename
[3985]62
[3991]63! LOCAL VARIABLES
64! ---------------
[3985]65real, dimension(:), allocatable :: controle
66integer :: ncid           ! File ID
67integer :: varid_controle ! Variable ID for 'controle'
68integer :: dimid_index    ! Dimension ID for 'index'
69integer :: nindex         ! Size of dimension 'index'
70integer :: ierr           ! Return codes
71
[3991]72! CODE
73! ----
[3985]74! Open the NetCDF file
[3989]75ierr = nf90_open(trim(filename),NF90_NOWRITE,ncid)
[3985]76if (ierr /= nf90_noerr) then
77    write(*,*) "Error opening file:", trim(nf90_strerror(ierr))
78    error stop
79endif
80
81! Get the dimension size of 'index'
82ierr = nf90_inq_dimid(ncid,"index",dimid_index)
83if (ierr /= nf90_noerr) then
84    write(*,*) "Error getting dimid 'index':", trim(nf90_strerror(ierr))
85    error stop
86endif
87ierr = nf90_inquire_dimension(ncid,dimid_index,len = nindex)
88if (ierr /= nf90_noerr) then
89    write(*,*) "Error getting dimension length:", trim(nf90_strerror(ierr))
90    error stop
91endif
92
93! Get the variable ID for 'controle'
94allocate(controle(nindex))
95ierr = nf90_inq_varid(ncid,"controle",varid_controle)
96if (ierr /= nf90_noerr) then
97    write(*,*) "Error getting variable ID 'controle':", trim(nf90_strerror(ierr))
98    error stop
99endif
100ierr = nf90_get_var(ncid,varid_controle,controle)
101if (ierr /= nf90_noerr) then
102    write(*,*) "Error reading 'controle':", trim(nf90_strerror(ierr))
103    error stop
104endif
105
106! Close the file
107ierr = nf90_close(ncid)
108if (ierr /= nf90_noerr) then
109    write(*,*) "Error closing file:", trim(nf90_strerror(ierr))
110    error stop
111endif
112
113! Initialize the constants with 'controle' data
114rad   = controle(5)
115g     = controle(7)
116mugaz = controle(8)
117rcp   = controle(9)
118r     = 8.314511*1000./mugaz
119cpp   = r/rcp
120deallocate(controle)
121
122END SUBROUTINE read_constants
[3991]123!=======================================================================
[3985]124
125END MODULE phys_constants
Note: See TracBrowser for help on using the repository browser.