[e200b7a] | 1 | !********************************************************************** |
---|
| 2 | ! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010 * |
---|
| 3 | ! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa, * |
---|
| 4 | ! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann * |
---|
| 5 | ! * |
---|
| 6 | ! This file is part of FLEXPART. * |
---|
| 7 | ! * |
---|
| 8 | ! FLEXPART is free software: you can redistribute it and/or modify * |
---|
| 9 | ! it under the terms of the GNU General Public License as published by* |
---|
| 10 | ! the Free Software Foundation, either version 3 of the License, or * |
---|
| 11 | ! (at your option) any later version. * |
---|
| 12 | ! * |
---|
| 13 | ! FLEXPART is distributed in the hope that it will be useful, * |
---|
| 14 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 15 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
---|
| 16 | ! GNU General Public License for more details. * |
---|
| 17 | ! * |
---|
| 18 | ! You should have received a copy of the GNU General Public License * |
---|
| 19 | ! along with FLEXPART. If not, see <http://www.gnu.org/licenses/>. * |
---|
| 20 | !********************************************************************** |
---|
| 21 | |
---|
| 22 | subroutine readoutgrid |
---|
| 23 | |
---|
| 24 | !***************************************************************************** |
---|
| 25 | ! * |
---|
| 26 | ! This routine reads the user specifications for the output grid. * |
---|
| 27 | ! * |
---|
| 28 | ! Author: A. Stohl * |
---|
| 29 | ! * |
---|
| 30 | ! 4 June 1996 * |
---|
[d7935de] | 31 | ! HSO, 1 July 2014: Add optional namelist input * |
---|
| 32 | ! PS, 6/2015-9/2018: read regular input with free format * |
---|
| 33 | ! simplify code and rename some variables * |
---|
[e200b7a] | 34 | ! * |
---|
| 35 | !***************************************************************************** |
---|
| 36 | ! * |
---|
| 37 | ! Variables: * |
---|
| 38 | ! dxout,dyout grid distance * |
---|
| 39 | ! numxgrid,numygrid,numzgrid grid dimensions * |
---|
| 40 | ! outlon0,outlat0 lower left corner of grid * |
---|
| 41 | ! outheight(maxzgrid) height levels of output grid [m] * |
---|
| 42 | ! * |
---|
| 43 | ! Constants: * |
---|
| 44 | ! unitoutgrid unit connected to file OUTGRID * |
---|
| 45 | ! * |
---|
| 46 | !***************************************************************************** |
---|
| 47 | |
---|
| 48 | use outg_mod |
---|
| 49 | use par_mod |
---|
| 50 | use com_mod |
---|
| 51 | |
---|
| 52 | implicit none |
---|
| 53 | |
---|
[d7935de] | 54 | integer :: i,kz,istat |
---|
| 55 | real :: xr,xr1,yr,yr1 |
---|
[e200b7a] | 56 | real,parameter :: eps=1.e-4 |
---|
| 57 | |
---|
[b4d29ce] | 58 | ! namelist variables |
---|
| 59 | integer, parameter :: maxoutlev=500 |
---|
[d7935de] | 60 | integer :: ios |
---|
| 61 | real,allocatable, dimension (:) :: outheights,outaux |
---|
| 62 | logical :: lnml |
---|
[e200b7a] | 63 | |
---|
[b4d29ce] | 64 | ! declare namelist |
---|
[d7935de] | 65 | namelist /nml_outgrid/ & |
---|
[b4d29ce] | 66 | outlon0,outlat0, & |
---|
| 67 | numxgrid,numygrid, & |
---|
| 68 | dxout,dyout, & |
---|
[d7935de] | 69 | outheight |
---|
[b4d29ce] | 70 | |
---|
[d7935de] | 71 | ! allocate outheights for nml read with max dimension |
---|
| 72 | allocate(outheights(maxoutlev),outaux(maxoutlev),stat=istat) |
---|
| 73 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate outheights' |
---|
[e200b7a] | 74 | |
---|
| 75 | ! Open the OUTGRID file and read output grid specifications |
---|
| 76 | !********************************************************** |
---|
| 77 | |
---|
[d7935de] | 78 | outheight(:) = -999. ! initialise for later finding #valid levels |
---|
| 79 | open(unitoutgrid,file=trim(path(1))//'OUTGRID',status='old',& |
---|
| 80 | form='formatted',err=999) |
---|
[e200b7a] | 81 | |
---|
[b4d29ce] | 82 | ! try namelist input |
---|
[d7935de] | 83 | read(unitoutgrid,nml_outgrid,iostat=ios) |
---|
[b4d29ce] | 84 | close(unitoutgrid) |
---|
[e200b7a] | 85 | |
---|
[d7935de] | 86 | if (ios .eq. 0) then ! namelist works |
---|
| 87 | |
---|
| 88 | lnml = .true. |
---|
[e200b7a] | 89 | |
---|
[d7935de] | 90 | else ! read as regular text |
---|
[e200b7a] | 91 | |
---|
[d7935de] | 92 | lnml = .false. |
---|
[e200b7a] | 93 | |
---|
[d7935de] | 94 | open(unitoutgrid,file=trim(path(1))//'OUTGRID',status='old',err=999) |
---|
[b4d29ce] | 95 | call skplin(5,unitoutgrid) |
---|
[e200b7a] | 96 | |
---|
[d7935de] | 97 | ! Read horizontal grid specifications |
---|
[b4d29ce] | 98 | !**************************************** |
---|
| 99 | |
---|
| 100 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 101 | read(unitoutgrid,*) outlon0 |
---|
[b4d29ce] | 102 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 103 | read(unitoutgrid,*) outlat0 |
---|
[b4d29ce] | 104 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 105 | read(unitoutgrid,*) numxgrid |
---|
[b4d29ce] | 106 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 107 | read(unitoutgrid,*) numygrid |
---|
[b4d29ce] | 108 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 109 | read(unitoutgrid,*) dxout |
---|
[b4d29ce] | 110 | call skplin(3,unitoutgrid) |
---|
[d7935de] | 111 | read(unitoutgrid,*) dyout |
---|
[b4d29ce] | 112 | |
---|
[d7935de] | 113 | endif ! read OUTGRID file |
---|
[e200b7a] | 114 | |
---|
| 115 | ! Check validity of output grid (shall be within model domain) |
---|
| 116 | !************************************************************* |
---|
| 117 | |
---|
| 118 | xr=outlon0+real(numxgrid)*dxout |
---|
| 119 | yr=outlat0+real(numygrid)*dyout |
---|
| 120 | xr1=xlon0+real(nxmin1)*dx |
---|
| 121 | yr1=ylat0+real(nymin1)*dy |
---|
| 122 | if ((outlon0+eps.lt.xlon0).or.(outlat0+eps.lt.ylat0) & |
---|
| 123 | .or.(xr.gt.xr1+eps).or.(yr.gt.yr1+eps)) then |
---|
| 124 | write(*,*) outlon0,outlat0 |
---|
| 125 | write(*,*) xr1,yr1,xlon0,ylat0,xr,yr,dxout,dyout |
---|
| 126 | write(*,*) ' #### FLEXPART MODEL ERROR! PART OF OUTPUT ####' |
---|
| 127 | write(*,*) ' #### GRID IS OUTSIDE MODEL DOMAIN. CHANGE ####' |
---|
| 128 | write(*,*) ' #### FILE OUTGRID IN DIRECTORY ####' |
---|
[d7935de] | 129 | write(*,'(a)') trim(path(1)) |
---|
[e200b7a] | 130 | stop |
---|
| 131 | endif |
---|
| 132 | |
---|
[d7935de] | 133 | ! Read (if .not. lmnl) and count vertical levels of output grid |
---|
| 134 | !************************************************************** |
---|
[e200b7a] | 135 | |
---|
[d7935de] | 136 | do kz = 1,maxoutlev |
---|
| 137 | if (lnml) then ! we have read them already |
---|
| 138 | if (outheight(kz) .lt. 0.) exit ! 1st nondefined level |
---|
| 139 | else |
---|
| 140 | call skplin(3,unitoutgrid) |
---|
| 141 | read(unitoutgrid,*,end=10) outheight(kz) |
---|
| 142 | endif |
---|
| 143 | end do |
---|
| 144 | 10 continue |
---|
[b4d29ce] | 145 | |
---|
[d7935de] | 146 | numzgrid = kz - 1 ! number of outgrid levels |
---|
[b4d29ce] | 147 | |
---|
[d7935de] | 148 | ! allocate the required length only, shuffle data |
---|
| 149 | outaux = outheight ! shuffle |
---|
[b4d29ce] | 150 | |
---|
[d7935de] | 151 | deallocate(outheights) |
---|
| 152 | allocate(outheight(numzgrid),outheighthalf(numzgrid),stat=istat) |
---|
| 153 | if (istat .ne. 0) then |
---|
| 154 | write(*,*) 'ERROR: could not allocate outheight and outheighthalf' |
---|
| 155 | stop 'readoutgrid error' |
---|
| 156 | endif |
---|
[b4d29ce] | 157 | |
---|
[d7935de] | 158 | outheight=outaux(1:numzgrid) ! shuffle back |
---|
| 159 | deallocate (outaux) |
---|
[b4d29ce] | 160 | |
---|
[d7935de] | 161 | ! write outgrid file in namelist format to output directory if requested |
---|
| 162 | if (nmlout) then |
---|
| 163 | open(unitoutgrid,file=trim(path(2))//'OUTGRID.namelist',err=1000) |
---|
| 164 | write(unitoutgrid,nml=nml_outgrid) |
---|
[b4d29ce] | 165 | close(unitoutgrid) |
---|
| 166 | endif |
---|
[e200b7a] | 167 | |
---|
| 168 | ! Check whether vertical levels are specified in ascending order |
---|
| 169 | !*************************************************************** |
---|
| 170 | |
---|
[d7935de] | 171 | do kz=2,numzgrid |
---|
| 172 | if (outheight(kz) .le. outheight(kz-1)) goto 998 |
---|
[e200b7a] | 173 | end do |
---|
| 174 | |
---|
| 175 | ! Determine the half levels, i.e. middle levels of the output grid |
---|
| 176 | !***************************************************************** |
---|
| 177 | |
---|
[d7935de] | 178 | outheighthalf(1) = 0.5*outheight(1) |
---|
| 179 | do kz = 2,numzgrid |
---|
| 180 | outheighthalf(kz) = 0.5*(outheight(kz-1)+outheight(kz)) |
---|
[e200b7a] | 181 | end do |
---|
| 182 | |
---|
| 183 | xoutshift=xlon0-outlon0 |
---|
| 184 | youtshift=ylat0-outlat0 |
---|
| 185 | |
---|
[d7935de] | 186 | allocate(oroout(0:numxgrid-1,0:numygrid-1),stat=istat) |
---|
| 187 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate oroout' |
---|
| 188 | allocate(area(0:numxgrid-1,0:numygrid-1),stat=istat) |
---|
| 189 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate area' |
---|
| 190 | allocate(volume(0:numxgrid-1,0:numygrid-1,numzgrid),stat=istat) |
---|
| 191 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate volume' |
---|
| 192 | allocate(areaeast(0:numxgrid-1,0:numygrid-1,numzgrid),stat=istat) |
---|
| 193 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate areaeast' |
---|
| 194 | allocate(areanorth(0:numxgrid-1,0:numygrid-1,numzgrid),stat=istat) |
---|
| 195 | if (istat .ne. 0) write(*,*)'ERROR: could not allocate areanorth' |
---|
| 196 | |
---|
[e200b7a] | 197 | return |
---|
| 198 | |
---|
[d7935de] | 199 | 998 continue |
---|
| 200 | write(*,*) ' #### FLEXPART MODEL ERROR! YOUR SPECIFICATION#### ' |
---|
| 201 | write(*,*) ' #### OF OUTPUT LEVELS NOT INCREASING AT LEVEL#### ' |
---|
| 202 | write(*,*) ' #### ',kz,' #### ' |
---|
| 203 | write(*,*) ' #### PLEASE MAKE CHANGES IN FILE OUTGRID. #### ' |
---|
| 204 | STOP 'readoutgrid error' |
---|
[e200b7a] | 205 | |
---|
[b4d29ce] | 206 | 999 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID" #### ' |
---|
| 207 | write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY #### ' |
---|
[d7935de] | 208 | write(*,'(a)') trim(path(1)) |
---|
[b4d29ce] | 209 | stop |
---|
| 210 | |
---|
| 211 | 1000 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID" #### ' |
---|
[e200b7a] | 212 | write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY #### ' |
---|
[d7935de] | 213 | write(*,'(a)') trim(path(2)) |
---|
[e200b7a] | 214 | stop |
---|
| 215 | |
---|
| 216 | end subroutine readoutgrid |
---|