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