-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmo_read_sedpor.F90
122 lines (102 loc) · 3.83 KB
/
mo_read_sedpor.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
! Copyright (C) 2020 S. Gao, I. Bethke, J. Tjiputra, J. Schwinger
!
! This file is part of BLOM/iHAMOCC.
!
! BLOM is free software: you can redistribute it and/or modify it under the
! terms of the GNU Lesser General Public License as published by the Free
! Software Foundation, either version 3 of the License, or (at your option)
! any later version.
!
! BLOM is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
! FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
! more details.
!
! You should have received a copy of the GNU Lesser General Public License
! along with BLOM. If not, see https://www.gnu.org/licenses/.
module mo_read_sedpor
!*************************************************************************************************
! Routine for reading sediment porosity from netcdf file L_SED_POR must be set to true in nml
! to activate lon-lat variable sediment porosity.
!
! The model attempts to read lon-lat-sediment depth variable porosity
! from the input file 'SEDPORFILE' (incl. full path)
!
! sed_por holds then the porosity that can be applied later in mo_sedmnt (ini_sedmnt_por)
!*************************************************************************************************
implicit none
private
! Routintes
public :: read_sedpor ! read sediment porosity file
! Module variables
character(len=512), public :: sedporfile = ''
contains
subroutine read_sedpor(kpie,kpje,ks,omask,sed_por)
use mod_xc, only: mnproc,xchalt
use mo_control_bgc, only: io_stdo_bgc,l_3Dvarsedpor
use netcdf, only: nf90_noerr,nf90_nowrite,nf90_close,nf90_open
use mo_netcdf_bgcrw, only: read_netcdf_var
implicit none
! Arguments
integer, intent(in) :: kpie
integer, intent(in) :: kpje
integer, intent(in) :: ks
real, intent(in) :: omask(kpie,kpje)
real, intent(inout) :: sed_por(kpie,kpje,ks)
!local variables
integer :: i,j,k
real :: sed_por_in(kpie,kpje,ks)
logical :: file_exists = .false.
integer :: ncid,ncstat
! Return if l_3Dvarsedpor is turned off
if (.not. l_3Dvarsedpor) then
if (mnproc.eq.1) then
write(io_stdo_bgc,*) ''
write(io_stdo_bgc,*) 'read_sedpor: spatially variable sediment porosity is not activated.'
endif
return
endif
! Check if sediment porosity file exists. If not, abort.
inquire(file=sedporfile,exist=file_exists)
if (.not. file_exists .and. mnproc.eq.1) then
write(io_stdo_bgc,*) ''
write(io_stdo_bgc,*) 'read_sedpor: Cannot find sediment porosity file... '
call xchalt('(read_sedpor)')
stop '(read_sedpor)'
endif
! read sediment porosity from file
if (mnproc.eq.1) then
write(io_stdo_bgc,*) ''
write(io_stdo_bgc,*) 'read_sedpor: read sediment porosity from ',trim(sedporfile)
endif
! Open netCDF data file
if (mnproc==1) then
ncstat = NF90_OPEN(trim(sedporfile),NF90_NOWRITE, ncid)
if (ncstat /= NF90_NOERR ) then
call xchalt('(read_sedpor: Problem with netCDF1)')
stop '(read_sedpor: Problem with netCDF1)'
end if
end if
! Read data
call read_netcdf_var(ncid,'sedpor',sed_por_in(1,1,1),ks,0,0)
! Close file
if (mnproc==1) then
ncstat = NF90_CLOSE(ncid)
if ( ncstat /= NF90_NOERR ) then
call xchalt('(read_sedpor: Problem with netCDF2)')
stop '(read_sedpor: Problem with netCDF2)'
end if
end if
do k=1,ks
do j=1,kpje
do i=1,kpie
if(omask(i,j).gt. 0.5)then
sed_por(i,j,k)=sed_por_in(i,j,k)
else
sed_por(i,j,k)=0.
endif
enddo
enddo
enddo
end subroutine read_sedpor
end module mo_read_sedpor