readOHfield.f90 6.81 KB
Newer Older
Matthias Langer's avatar
 
Matthias Langer committed
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
!**********************************************************************
! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
!                                                                     *
! This file is part of FLEXPART.                                      *
!                                                                     *
! FLEXPART is free software: you can redistribute it and/or modify    *
! it under the terms of the GNU General Public License as published by*
! the Free Software Foundation, either version 3 of the License, or   *
! (at your option) any later version.                                 *
!                                                                     *
! FLEXPART 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 General Public License for more details.                        *
!                                                                     *
! You should have received a copy of the GNU General Public License   *
! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
!**********************************************************************

subroutine readOHfield

  !*****************************************************************************
  !                                                                            *
  ! Reads the OH field into memory                                             *
  !                                                                            *
28
  ! AUTHOR: R.L. Thompson, Nov 2014                                            *
Matthias Langer's avatar
 
Matthias Langer committed
29
30
31
32
33
  !                                                                            *
  !*****************************************************************************
  !                                                                            *
  ! Variables:                                                                 *
  !                                                                            *
34
35
36
37
38
39
40
  ! path(numpath)              contains the path names                         *
  ! lonOH(nxOH)                longitude of OH fields                          *
  ! latOH(nyOH)                latitude of OH fields                           *
  ! altOH(nzOH)                altitude of OH fields                           *
  ! etaOH(nzOH)                eta-levels of OH fields                         *
  ! OH_field(nxOH,nyOH,nzOH,m) OH concentration (molecules/cm3)                *
  !                                                                            *
Matthias Langer's avatar
 
Matthias Langer committed
41
42
43
44
45
46
47
48
49
  !                                                                            *
  !*****************************************************************************

  use oh_mod
  use par_mod
  use com_mod

  implicit none

50
51
52
53
54
55
  include 'netcdf.inc'

  character(len=150) :: thefile
  character(len=2) :: mm
  integer :: nid,ierr,xid,yid,zid,vid,m
  real, dimension(:), allocatable :: etaOH
Matthias Langer's avatar
 
Matthias Langer committed
56

57
58
59
60
61
!  real, parameter :: gasct=8.314   ! gas constant
!  real, parameter :: mct=0.02894   ! kg mol-1
!  real, parameter :: g=9.80665     ! m s-2
!  real, parameter :: lrate=0.0065  ! K m-1
  real, parameter :: scalehgt=7000. ! scale height in metres
Matthias Langer's avatar
 
Matthias Langer committed
62

63
  ! Read OH fields and level heights
Matthias Langer's avatar
 
Matthias Langer committed
64
65
66
  !********************************

  do m=1,12
67
68
69
  
    ! open netcdf file
    write(mm,fmt='(i2.2)') m
70
71
!    thefile=trim(path(1))//'OH_FIELDS/'//'geos-chem.OH.2005'//mm//'01.nc'
    thefile=trim(ohfields_path)//'OH_FIELDS/'//'geos-chem.OH.2005'//mm//'01.nc'
72
73
    ierr=nf_open(trim(thefile),NF_NOWRITE,nid)
    if(ierr.ne.0) then
74
75
76
      write (*,*) 'The OH field at: '//thefile// ' could not be opened'
      write (*,*) 'please copy the OH fields there, or change the path in the'
      write (*,*) 'COMMAND namelist!'
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
      write(*,*) nf_strerror(ierr)
      stop
    endif

    ! inquire about variables
    ierr=nf_inq_dimid(nid,'Lon-000',xid)
    if(ierr.ne.0) then
      write(*,*) nf_strerror(ierr)
      stop
    endif
    ierr=nf_inq_dimid(nid,'Lat-000',yid)
    if(ierr.ne.0) then
      write(*,*) nf_strerror(ierr)
      stop
    endif
    ierr=nf_inq_dimid(nid,'Alt-000',zid)
    if(ierr.ne.0) then
      write(*,*) nf_strerror(ierr)
      stop
    endif

    if(m.eq.1) then

      ! read dimension sizes
      ierr=nf_inq_dimlen(nid,xid,nxOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif
      ierr=nf_inq_dimlen(nid,yid,nyOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif
      ierr=nf_inq_dimlen(nid,zid,nzOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif  

      ! allocate variables
      allocate(lonOH(nxOH))
      allocate(latOH(nyOH))
      allocate(etaOH(nzOH))
      allocate(altOH(nzOH))
      allocate(OH_field(nxOH,nyOH,nzOH,12))
      allocate(OH_hourly(nxOH,nyOH,nzOH,2))

      ! read dimension variables
      ierr=nf_inq_varid(nid,'LON',xid)
      ierr=nf_get_var_real(nid,xid,lonOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif
      ierr=nf_inq_varid(nid,'LAT',yid)
      ierr=nf_get_var_real(nid,yid,latOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif
      ierr=nf_inq_varid(nid,'ETAC',zid)
      ierr=nf_get_var_real(nid,zid,etaOH)
      if(ierr.ne.0) then
        write(*,*) nf_strerror(ierr)
        stop
      endif

      ! convert eta-level to altitude (assume surface pressure of 1010 hPa)
      altOH=log(1010./(etaOH*1010.))*scalehgt
Matthias Langer's avatar
 
Matthias Langer committed
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    endif ! m.eq.1

    ! read OH_field
    ierr=nf_inq_varid(nid,'CHEM-L_S__OH',vid)
    ierr=nf_get_var_real(nid,vid,OH_field(:,:,:,m))
    if(ierr.ne.0) then
      write(*,*) nf_strerror(ierr)
      stop
    endif

    ierr=nf_close(nid)

  end do 
 
  deallocate(etaOH)

  ! Read J(O1D) photolysis rates
  !********************************  

  ! open netcdf file
168
169
!  thefile=trim(path(1))//'OH_FIELDS/jrate_average.nc'
  thefile=trim(ohfields_path)//'OH_FIELDS/jrate_average.nc'
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  ierr=nf_open(trim(thefile),NF_NOWRITE,nid)
  if(ierr.ne.0) then
    write(*,*) nf_strerror(ierr)
    stop
  endif

  ! read dimension variables
  ierr=nf_inq_varid(nid,'longitude',xid)
  ierr=nf_get_var_real(nid,xid,lonjr)
  if(ierr.ne.0) then
    write(*,*) nf_strerror(ierr)
    stop
  endif
  ierr=nf_inq_varid(nid,'latitude',yid)
  ierr=nf_get_var_real(nid,yid,latjr)
  if(ierr.ne.0) then
    write(*,*) nf_strerror(ierr)
    stop
  endif

  ! read jrate_average
  ierr=nf_inq_varid(nid,'jrate',vid)
  ierr=nf_get_var_real(nid,vid,jrate_average)
  if(ierr.ne.0) then
    write(*,*) nf_strerror(ierr)
    stop
  endif

  ierr=nf_close(nid) 

  return
Matthias Langer's avatar
 
Matthias Langer committed
201

202
end subroutine readOHfield
Matthias Langer's avatar
 
Matthias Langer committed
203