Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/readoutgrid.f90

    r27 r20  
    2929  !                                                                            *
    3030  !     4 June 1996                                                            *
    31   !     HSO, 1 July 2014
    32   !     Added optional namelist input
    3331  !                                                                            *
    3432  !*****************************************************************************
     
    5553  real,parameter :: eps=1.e-4
    5654
    57   ! namelist variables
    58   integer, parameter :: maxoutlev=500
    59   integer :: readerror
    60   real,allocatable, dimension (:) :: outheights
    6155
    62   ! declare namelist
    63   namelist /outgrid/ &
    64     outlon0,outlat0, &
    65     numxgrid,numygrid, &
    66     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
    7656
    7757  ! Open the OUTGRID file and read output grid specifications
    7858  !**********************************************************
    7959
    80   open(unitoutgrid,file=path(1)(1:length(1))//'OUTGRID',status='old',form='formatted',err=999)
     60  open(unitoutgrid,file=path(1)(1:length(1))//'OUTGRID',status='old', &
     61       err=999)
    8162
    82   ! try namelist input
    83   read(unitoutgrid,outgrid,iostat=readerror)
    84   close(unitoutgrid)
    8563
    86   if ((dxout.le.0).or.(readerror.ne.0)) then
     64  call skplin(5,unitoutgrid)
    8765
    88     readerror=1
    8966
    90     open(unitoutgrid,file=path(1)(1:length(1))//'OUTGRID',status='old',err=999)
     67  ! 1.  Read horizontal grid specifications
     68  !****************************************
    9169
    92     call skplin(5,unitoutgrid)
     70  call skplin(3,unitoutgrid)
     71  read(unitoutgrid,'(4x,f11.4)') outlon0
     72  call skplin(3,unitoutgrid)
     73  read(unitoutgrid,'(4x,f11.4)') outlat0
     74  call skplin(3,unitoutgrid)
     75  read(unitoutgrid,'(4x,i5)') numxgrid
     76  call skplin(3,unitoutgrid)
     77  read(unitoutgrid,'(4x,i5)') numygrid
     78  call skplin(3,unitoutgrid)
     79  read(unitoutgrid,'(4x,f12.5)') dxout
     80  call skplin(3,unitoutgrid)
     81  read(unitoutgrid,'(4x,f12.5)') dyout
    9382
    94     ! 1.  Read horizontal grid specifications
    95     !****************************************
    96 
    97     call skplin(3,unitoutgrid)
    98     read(unitoutgrid,'(4x,f11.4)') outlon0
    99     call skplin(3,unitoutgrid)
    100     read(unitoutgrid,'(4x,f11.4)') outlat0
    101     call skplin(3,unitoutgrid)
    102     read(unitoutgrid,'(4x,i5)') numxgrid
    103     call skplin(3,unitoutgrid)
    104     read(unitoutgrid,'(4x,i5)') numygrid
    105     call skplin(3,unitoutgrid)
    106     read(unitoutgrid,'(4x,f12.5)') dxout
    107     call skplin(3,unitoutgrid)
    108     read(unitoutgrid,'(4x,f12.5)') dyout
    109 
    110   endif
    11183
    11284  ! Check validity of output grid (shall be within model domain)
     
    11991  if ((outlon0+eps.lt.xlon0).or.(outlat0+eps.lt.ylat0) &
    12092       .or.(xr.gt.xr1+eps).or.(yr.gt.yr1+eps)) then
     93    write(*,*) 'outlon0,outlat0:'
    12194    write(*,*) outlon0,outlat0
     95    write(*,*) 'xr1,yr1,xlon0,ylat0,xr,yr,dxout,dyout:'
    12296    write(*,*) xr1,yr1,xlon0,ylat0,xr,yr,dxout,dyout
    12397    write(*,*) ' #### FLEXPART MODEL ERROR! PART OF OUTPUT    ####'
     
    130104  ! 2. Count Vertical levels of output grid
    131105  !****************************************
    132 
    133   if (readerror.ne.0) then
    134     j=0
    135 100 j=j+1
     106  j=0
     107100   j=j+1
    136108    do i=1,3
    137109      read(unitoutgrid,*,end=99)
     
    140112    if (outhelp.eq.0.) goto 99
    141113    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
     11499   numzgrid=j-1
    149115
    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'
     116    allocate(outheight(numzgrid) &
     117         ,stat=stat)
     118    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     119    allocate(outheighthalf(numzgrid) &
     120         ,stat=stat)
     121    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     122
     123
     124  rewind(unitoutgrid)
     125  call skplin(29,unitoutgrid)
    154126
    155127  ! 2. Vertical levels of output grid
    156128  !**********************************
    157129
    158   if (readerror.ne.0) then
     130  j=0
     1311000   j=j+1
     132    do i=1,3
     133      read(unitoutgrid,*,end=990)
     134    end do
     135    read(unitoutgrid,'(4x,f7.1)',end=990) outhelp
     136    if (outhelp.eq.0.) goto 99
     137    outheight(j)=outhelp
     138    goto 1000
     139990   numzgrid=j-1
    159140
    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 
    179   endif
    180 
    181   ! write outgrid file in namelist format to output directory if requested
    182   if (nmlout.eqv..true.) 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)
    194     close(unitoutgrid)
    195   endif
    196141
    197142  ! Check whether vertical levels are specified in ascending order
     
    215160  end do
    216161
     162
    217163  xoutshift=xlon0-outlon0
    218164  youtshift=ylat0-outlat0
     165  close(unitoutgrid)
    219166
    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'
     167    allocate(oroout(0:numxgrid-1,0:numygrid-1) &
     168         ,stat=stat)
     169    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     170    allocate(area(0:numxgrid-1,0:numygrid-1) &
     171         ,stat=stat)
     172    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     173    allocate(volume(0:numxgrid-1,0:numygrid-1,numzgrid) &
     174         ,stat=stat)
     175    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     176    allocate(areaeast(0:numxgrid-1,0:numygrid-1,numzgrid) &
     177         ,stat=stat)
     178    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
     179    allocate(areanorth(0:numxgrid-1,0:numygrid-1,numzgrid) &
     180         ,stat=stat)
     181    if (stat.ne.0) write(*,*)'ERROR: could not allocate outh'
    230182  return
    231183
    232184
    233 999 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID"    #### '
     185999   write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID"    #### '
    234186  write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
    235   write(*,'(a)') path(1)(1:length(1))
    236   stop
    237 
    238 1000 write(*,*) ' #### FLEXPART MODEL ERROR! FILE "OUTGRID"    #### '
    239   write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
    240   write(*,'(a)') path(2)(1:length(2))
     187  write(*,*) ' #### xxx/flexpart/options                    #### '
    241188  stop
    242189
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG