Changeset d7935de in flexpart.git for src/readoutgrid.f90
- Timestamp:
- Sep 11, 2018, 6:06:31 PM (6 years ago)
- Branches:
- univie
- Children:
- 93786a1
- Parents:
- 34f1452
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/readoutgrid.f90
r8a65cb0 rd7935de 29 29 ! * 30 30 ! 4 June 1996 * 31 ! HSO, 1 July 2014 32 ! Added optional namelist input 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 * 33 34 ! * 34 35 !***************************************************************************** … … 51 52 implicit none 52 53 53 integer :: i, j,stat54 real :: outhelp,xr,xr1,yr,yr154 integer :: i,kz,istat 55 real :: xr,xr1,yr,yr1 55 56 real,parameter :: eps=1.e-4 56 57 57 58 ! namelist variables 58 59 integer, parameter :: maxoutlev=500 59 integer :: readerror 60 real,allocatable, dimension (:) :: outheights 60 integer :: ios 61 real,allocatable, dimension (:) :: outheights,outaux 62 logical :: lnml 61 63 62 64 ! declare namelist 63 namelist / outgrid/ &65 namelist /nml_outgrid/ & 64 66 outlon0,outlat0, & 65 67 numxgrid,numygrid, & 66 68 dxout,dyout, & 67 outheights 68 69 ! allocate large array for reading input 70 allocate(outheights(maxoutlev),stat=stat) 71 if (stat.ne.0) write(*,*)'ERROR: could not allocate outheights' 72 73 ! helps identifying failed namelist input 74 dxout=-1.0 75 outheights=-1.0 69 outheight 70 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' 76 74 77 75 ! Open the OUTGRID file and read output grid specifications 78 76 !********************************************************** 79 77 80 open(unitoutgrid,file=path(1)(1:length(1))//'OUTGRID',status='old',form='formatted',err=999) 78 outheight(:) = -999. ! initialise for later finding #valid levels 79 open(unitoutgrid,file=trim(path(1))//'OUTGRID',status='old',& 80 form='formatted',err=999) 81 81 82 82 ! try namelist input 83 read(unitoutgrid, outgrid,iostat=readerror)83 read(unitoutgrid,nml_outgrid,iostat=ios) 84 84 close(unitoutgrid) 85 85 86 if ((dxout.le.0).or.(readerror.ne.0)) then 87 88 readerror=1 89 90 open(unitoutgrid,file=path(1)(1:length(1))//'OUTGRID',status='old',err=999) 91 86 if (ios .eq. 0) then ! namelist works 87 88 lnml = .true. 89 90 else ! read as regular text 91 92 lnml = .false. 93 94 open(unitoutgrid,file=trim(path(1))//'OUTGRID',status='old',err=999) 92 95 call skplin(5,unitoutgrid) 93 96 94 ! 1.Read horizontal grid specifications97 ! Read horizontal grid specifications 95 98 !**************************************** 96 99 97 100 call skplin(3,unitoutgrid) 98 read(unitoutgrid, '(4x,f11.4)') outlon099 call skplin(3,unitoutgrid) 100 read(unitoutgrid, '(4x,f11.4)') outlat0101 call skplin(3,unitoutgrid) 102 read(unitoutgrid, '(4x,i5)') numxgrid103 call skplin(3,unitoutgrid) 104 read(unitoutgrid, '(4x,i5)') numygrid105 call skplin(3,unitoutgrid) 106 read(unitoutgrid, '(4x,f12.5)') dxout107 call skplin(3,unitoutgrid) 108 read(unitoutgrid, '(4x,f12.5)') dyout109 110 endif 101 read(unitoutgrid,*) outlon0 102 call skplin(3,unitoutgrid) 103 read(unitoutgrid,*) outlat0 104 call skplin(3,unitoutgrid) 105 read(unitoutgrid,*) numxgrid 106 call skplin(3,unitoutgrid) 107 read(unitoutgrid,*) numygrid 108 call skplin(3,unitoutgrid) 109 read(unitoutgrid,*) dxout 110 call skplin(3,unitoutgrid) 111 read(unitoutgrid,*) dyout 112 113 endif ! read OUTGRID file 111 114 112 115 ! Check validity of output grid (shall be within model domain) … … 124 127 write(*,*) ' #### GRID IS OUTSIDE MODEL DOMAIN. CHANGE ####' 125 128 write(*,*) ' #### FILE OUTGRID IN DIRECTORY ####' 126 write(*,'(a)') path(1)(1:length(1))129 write(*,'(a)') trim(path(1)) 127 130 stop 128 131 endif 129 132 130 ! 2. Count Vertical levels of output grid 131 !**************************************** 132 133 if (readerror.ne.0) then 134 j=0 135 100 j=j+1 136 do i=1,3 137 read(unitoutgrid,*,end=99) 138 end do 139 read(unitoutgrid,'(4x,f7.1)',end=99) outhelp 140 if (outhelp.eq.0.) goto 99 141 goto 100 142 99 numzgrid=j-1 143 else 144 do i=1,maxoutlev 145 if (outheights(i).lt.0) exit 146 end do 147 numzgrid=i-1 148 end if 149 150 allocate(outheight(numzgrid),stat=stat) 151 if (stat.ne.0) write(*,*)'ERROR: could not allocate outheight' 152 allocate(outheighthalf(numzgrid),stat=stat) 153 if (stat.ne.0) write(*,*)'ERROR: could not allocate outheighthalf' 154 155 ! 2. Vertical levels of output grid 156 !********************************** 157 158 if (readerror.ne.0) then 159 160 rewind(unitoutgrid) 161 call skplin(29,unitoutgrid) 162 163 do j=1,numzgrid 164 do i=1,3 165 read(unitoutgrid,*) 166 end do 167 read(unitoutgrid,'(4x,f7.1)') outhelp 168 outheight(j)=outhelp 169 outheights(j)=outhelp 170 end do 171 close(unitoutgrid) 172 173 else 174 175 do j=1,numzgrid 176 outheight(j)=outheights(j) 177 end do 178 133 ! Read (if .not. lmnl) and count vertical levels of output grid 134 !************************************************************** 135 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 145 146 numzgrid = kz - 1 ! number of outgrid levels 147 148 ! allocate the required length only, shuffle data 149 outaux = outheight ! shuffle 150 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' 179 156 endif 180 157 181 ! write outgrid file in namelist format to output directory if requested 182 if (nmlout.and.lroot) then 183 ! reallocate outheights with actually required dimension for namelist writing 184 deallocate(outheights) 185 allocate(outheights(numzgrid),stat=stat) 186 if (stat.ne.0) write(*,*)'ERROR: could not allocate outheights' 187 188 do j=1,numzgrid 189 outheights(j)=outheight(j) 190 end do 191 192 open(unitoutgrid,file=path(2)(1:length(2))//'OUTGRID.namelist',err=1000) 193 write(unitoutgrid,nml=outgrid) 158 outheight=outaux(1:numzgrid) ! shuffle back 159 deallocate (outaux) 160 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) 194 165 close(unitoutgrid) 195 166 endif … … 198 169 !*************************************************************** 199 170 200 do j=2,numzgrid 201 if (outheight(j).le.outheight(j-1)) then 202 write(*,*) ' #### FLEXPART MODEL ERROR! YOUR SPECIFICATION#### ' 203 write(*,*) ' #### OF OUTPUT LEVELS IS CORRUPT AT LEVEL #### ' 204 write(*,*) ' #### ',j,' #### ' 205 write(*,*) ' #### PLEASE MAKE CHANGES IN FILE OUTGRID. #### ' 206 endif 171 do kz=2,numzgrid 172 if (outheight(kz) .le. outheight(kz-1)) goto 998 207 173 end do 208 174 … … 210 176 !***************************************************************** 211 177 212 outheighthalf(1) =outheight(1)/2.213 do j=2,numzgrid214 outheighthalf( j)=(outheight(j-1)+outheight(j))/2.178 outheighthalf(1) = 0.5*outheight(1) 179 do kz = 2,numzgrid 180 outheighthalf(kz) = 0.5*(outheight(kz-1)+outheight(kz)) 215 181 end do 216 182 … … 218 184 youtshift=ylat0-outlat0 219 185 220 allocate(oroout(0:numxgrid-1,0:numygrid-1),stat=stat) 221 if (stat.ne.0) write(*,*)'ERROR: could not allocate oroout' 222 allocate(area(0:numxgrid-1,0:numygrid-1),stat=stat) 223 if (stat.ne.0) write(*,*)'ERROR: could not allocate area' 224 allocate(volume(0:numxgrid-1,0:numygrid-1,numzgrid),stat=stat) 225 if (stat.ne.0) write(*,*)'ERROR: could not allocate volume' 226 allocate(areaeast(0:numxgrid-1,0:numygrid-1,numzgrid),stat=stat) 227 if (stat.ne.0) write(*,*)'ERROR: could not allocate areaeast' 228 allocate(areanorth(0:numxgrid-1,0:numygrid-1,numzgrid),stat=stat) 229 if (stat.ne.0) write(*,*)'ERROR: could not allocate areanorth' 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 230 197 return 231 198 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' 232 205 233 206 999 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID" #### ' 234 207 write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY #### ' 235 write(*,'(a)') path(1)(1:length(1))208 write(*,'(a)') trim(path(1)) 236 209 stop 237 210 238 211 1000 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID" #### ' 239 212 write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY #### ' 240 write(*,'(a)') path(2)(1:length(2))213 write(*,'(a)') trim(path(2)) 241 214 stop 242 215
Note: See TracChangeset
for help on using the changeset viewer.