readageclasses.f90 6.14 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
28
29
30
!**********************************************************************
! 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 readageclasses

  !*****************************************************************************
  !                                                                            *
  !     This routine reads the age classes to be used for the current model    *
  !     run.                                                                   *
  !                                                                            *
  !     Author: A. Stohl                                                       *
  !     20 March 2000                                                          *
pesei's avatar
pesei committed
31
  !
32
33
  !     HSO, 1 July 2014                                                       *
  !     Added optional namelist input                                          *
Matthias Langer's avatar
 
Matthias Langer committed
34
  !                                                                            *
pesei's avatar
pesei committed
35
36
37
  !     PS, 6/2015-9/2018 some variable names changed as in readreleases.f90   *
  !       catch nageclass>maxage properly                                      *
  !                                                                            *
Matthias Langer's avatar
 
Matthias Langer committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  !*****************************************************************************
  !                                                                            *
  ! Variables:                                                                 *
  !                                                                            *
  ! Constants:                                                                 *
  !                                                                            *
  !*****************************************************************************

  use par_mod
  use com_mod

  implicit none

  integer :: i

pesei's avatar
pesei committed
53
54
  ! namelist aux variables
  integer :: ios
55
56

  ! namelist declaration
pesei's avatar
pesei committed
57
  namelist /nml_ageclass/ &
58
59
60
61
    nageclass, &
    lage

  nageclass=-1 ! preset to negative value to identify failed namelist input
Matthias Langer's avatar
 
Matthias Langer committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

  ! If age spectra calculation is switched off, set number of age classes
  ! to 1 and maximum age to a large number
  !**********************************************************************

  if (lagespectra.ne.1) then
    nageclass=1
    lage(nageclass)=999999999
    return
  endif

  ! If age spectra claculation is switched on,
  ! open the AGECLASSSES file and read user options
  !************************************************

pesei's avatar
pesei committed
77
78
  open(unitageclasses,file=path(1)(1:length(1))//'AGECLASSES', &
    form='formatted',status='old',err=999)
79
80

  ! try to read in as a namelist
pesei's avatar
pesei committed
81
  read(unitageclasses, nml_ageclass, iostat=ios)
82
83
  close(unitageclasses)

pesei's avatar
pesei committed
84
85
86
87
88
89
90
91
  if (ios .ne. 0) then ! failed to read nml, assume simple text
    open(unitageclasses,file=path(1)(1:length(1))// &
      'AGECLASSES',status='old',err=999)
    call skplin(13,unitageclasses)
    read(unitageclasses,*) nageclass ! number of classes
    if (nageclass.gt.maxageclass) goto 1001
    do i=1,nageclass
      read(unitageclasses,*) lage(i) ! max age per classes
92
93
94
    end do
    close(unitageclasses)
  endif
Matthias Langer's avatar
 
Matthias Langer committed
95

pesei's avatar
pesei committed
96
97
  if (nageclass.lt.1) goto 1002

98
  ! write ageclasses file in namelist format to output directory if requested
99
  if (nmlout.and.lroot) then
pesei's avatar
pesei committed
100
101
102
    open(unitageclasses,file=path(2)(1:length(2))//'AGECLASSES.namelist', &
      err=1000)
    write(unitageclasses,nml=nml_ageclass)
103
104
    close(unitageclasses)
  endif
Matthias Langer's avatar
 
Matthias Langer committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

  if (lage(1).le.0) then
    write(*,*) ' #### FLEXPART MODEL ERROR! AGE OF FIRST      #### '
    write(*,*) ' #### CLASS MUST BE GREATER THAN ZERO. CHANGE #### '
    write(*,*) ' #### SETTINGS IN FILE AGECLASSES.            #### '
    stop
  endif

  do i=2,nageclass
    if (lage(i).le.lage(i-1)) then
      write(*,*) ' #### FLEXPART MODEL ERROR! AGE CLASSES     #### '
      write(*,*) ' #### MUST BE GIVEN IN TEMPORAL ORDER.      #### '
      write(*,*) ' #### CHANGE SETTINGS IN FILE AGECLASSES.   #### '
      stop
    endif
  end do

  return

999   write(*,*) ' #### FLEXPART MODEL ERROR! FILE "AGECLASSES" #### '
  write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
pesei's avatar
pesei committed
126
  write(*,'(a)') trim(path(1))
Matthias Langer's avatar
 
Matthias Langer committed
127
128
  stop

129
130
131
132
133
1000  write(*,*) ' #### FLEXPART MODEL ERROR! FILE "AGECLASSES" #### '
  write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
  write(*,'(a)') path(2)(1:length(2))
  stop

pesei's avatar
pesei committed
134
135
136
137
138
139
140
141
142
143
144
145
146
1001 continue
    write(*,*) ' #### FLEXPART MODEL ERROR! NUMBER OF AGE     #### '
    write(*,*) ' #### CLASSES GREATER THAN MAXIMUM ALLOWED.   #### '
    write(*,*) ' #### CHANGE SETTINGS IN FILE AGECLASSES OR   #### '
    write(*,*) ' #### RECOMPILE WITH LARGER MAXAGECLASS IN    #### '
    write(*,*) ' #### FILE PAR_MOD.                           #### '
    stop

1002 continue
    write(*,*) ' #### FLEXPART MODEL ERROR! NUMBER OF AGE     #### '
    write(*,*) ' #### CLASSES < 1                             #### '
    write(*,*) ' #### CHANGE SETTINGS IN FILE AGECLASSES      #### '
    stop
147

Matthias Langer's avatar
 
Matthias Langer committed
148
end subroutine readageclasses