| 1 | MODULE phys_constants |
|---|
| 2 | |
|---|
| 3 | implicit none |
|---|
| 4 | |
|---|
| 5 | real, parameter :: pi = 4.*atan(1.) ! PI = 3.14159... |
|---|
| 6 | |
|---|
| 7 | real :: g ! Gravity (m/s2) |
|---|
| 8 | real :: r ! Reduced gas constant,r = 8.314511/(mugaz/1000.0) |
|---|
| 9 | real :: mugaz ! Molar mass of the atmosphere (g/mol) |
|---|
| 10 | real :: rad ! Radius of the planet (m) |
|---|
| 11 | real :: cpp ! Cp of the atmosphere |
|---|
| 12 | real :: rcp ! r/cpp |
|---|
| 13 | |
|---|
| 14 | !======================================================================= |
|---|
| 15 | contains |
|---|
| 16 | !======================================================================= |
|---|
| 17 | |
|---|
| 18 | SUBROUTINE read_constants(fname) |
|---|
| 19 | |
|---|
| 20 | use netcdf |
|---|
| 21 | |
|---|
| 22 | implicit none |
|---|
| 23 | |
|---|
| 24 | ! Arguments |
|---|
| 25 | !---------- |
|---|
| 26 | character(*), intent(in) :: fname |
|---|
| 27 | |
|---|
| 28 | ! Local variables |
|---|
| 29 | !---------------- |
|---|
| 30 | real, dimension(:), allocatable :: controle |
|---|
| 31 | integer :: ncid ! File ID |
|---|
| 32 | integer :: varid_controle ! Variable ID for 'controle' |
|---|
| 33 | integer :: dimid_index ! Dimension ID for 'index' |
|---|
| 34 | integer :: nindex ! Size of dimension 'index' |
|---|
| 35 | integer :: ierr ! Return codes |
|---|
| 36 | |
|---|
| 37 | ! Code |
|---|
| 38 | !----- |
|---|
| 39 | ! Open the NetCDF file |
|---|
| 40 | ierr = nf90_open(trim(fname),NF90_NOWRITE,ncid) |
|---|
| 41 | if (ierr /= nf90_noerr) then |
|---|
| 42 | write(*,*) "Error opening file:", trim(nf90_strerror(ierr)) |
|---|
| 43 | error stop |
|---|
| 44 | endif |
|---|
| 45 | |
|---|
| 46 | ! Get the dimension size of 'index' |
|---|
| 47 | ierr = nf90_inq_dimid(ncid,"index",dimid_index) |
|---|
| 48 | if (ierr /= nf90_noerr) then |
|---|
| 49 | write(*,*) "Error getting dimid 'index':", trim(nf90_strerror(ierr)) |
|---|
| 50 | error stop |
|---|
| 51 | endif |
|---|
| 52 | ierr = nf90_inquire_dimension(ncid,dimid_index,len = nindex) |
|---|
| 53 | if (ierr /= nf90_noerr) then |
|---|
| 54 | write(*,*) "Error getting dimension length:", trim(nf90_strerror(ierr)) |
|---|
| 55 | error stop |
|---|
| 56 | endif |
|---|
| 57 | |
|---|
| 58 | ! Get the variable ID for 'controle' |
|---|
| 59 | allocate(controle(nindex)) |
|---|
| 60 | ierr = nf90_inq_varid(ncid,"controle",varid_controle) |
|---|
| 61 | if (ierr /= nf90_noerr) then |
|---|
| 62 | write(*,*) "Error getting variable ID 'controle':", trim(nf90_strerror(ierr)) |
|---|
| 63 | error stop |
|---|
| 64 | endif |
|---|
| 65 | ierr = nf90_get_var(ncid,varid_controle,controle) |
|---|
| 66 | if (ierr /= nf90_noerr) then |
|---|
| 67 | write(*,*) "Error reading 'controle':", trim(nf90_strerror(ierr)) |
|---|
| 68 | error stop |
|---|
| 69 | endif |
|---|
| 70 | |
|---|
| 71 | ! Close the file |
|---|
| 72 | ierr = nf90_close(ncid) |
|---|
| 73 | if (ierr /= nf90_noerr) then |
|---|
| 74 | write(*,*) "Error closing file:", trim(nf90_strerror(ierr)) |
|---|
| 75 | error stop |
|---|
| 76 | endif |
|---|
| 77 | |
|---|
| 78 | ! Initialize the constants with 'controle' data |
|---|
| 79 | rad = controle(5) |
|---|
| 80 | g = controle(7) |
|---|
| 81 | mugaz = controle(8) |
|---|
| 82 | rcp = controle(9) |
|---|
| 83 | r = 8.314511*1000./mugaz |
|---|
| 84 | cpp = r/rcp |
|---|
| 85 | deallocate(controle) |
|---|
| 86 | |
|---|
| 87 | END SUBROUTINE read_constants |
|---|
| 88 | |
|---|
| 89 | END MODULE phys_constants |
|---|