readageclasses.f90 4.2 KB
Newer Older
Matthias Langer's avatar
 
Matthias Langer committed
1
2
3
4
5
6
7
8
9
subroutine readageclasses

  !*****************************************************************************
  !                                                                            *
  !     This routine reads the age classes to be used for the current model    *
  !     run.                                                                   *
  !                                                                            *
  !     Author: A. Stohl                                                       *
  !     20 March 2000                                                          *
10
11
  !     HSO, 1 July 2014                                                       *
  !     Added optional namelist input                                          *
Matthias Langer's avatar
 
Matthias Langer committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  !                                                                            *
  !*****************************************************************************
  !                                                                            *
  ! Variables:                                                                 *
  !                                                                            *
  ! Constants:                                                                 *
  !                                                                            *
  !*****************************************************************************

  use par_mod
  use com_mod

  implicit none

  integer :: i

28
29
30
31
32
33
34
35
36
  ! namelist help variables
  integer :: readerror

  ! namelist declaration
  namelist /ageclass/ &
    nageclass, &
    lage

  nageclass=-1 ! preset to negative value to identify failed namelist input
Matthias Langer's avatar
 
Matthias Langer committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

  ! 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
  !************************************************

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  open(unitageclasses,file=path(1)(1:length(1))//'AGECLASSES',form='formatted',status='old',err=999)

  ! try to read in as a namelist
  read(unitageclasses,ageclass,iostat=readerror)
  close(unitageclasses)

  if ((nageclass.lt.0).or.(readerror.ne.0)) then
    open(unitageclasses,file=path(1)(1:length(1))//'AGECLASSES',status='old',err=999)
    do i=1,13
      read(unitageclasses,*)
    end do
    read(unitageclasses,*) nageclass
    read(unitageclasses,*) lage(1)
    do i=2,nageclass
      read(unitageclasses,*) lage(i)
    end do
    close(unitageclasses)
  endif
Matthias Langer's avatar
 
Matthias Langer committed
70

71
  ! write ageclasses file in namelist format to output directory if requested
72
  if (nmlout.and.lroot) then
73
74
75
76
    open(unitageclasses,file=path(2)(1:length(2))//'AGECLASSES.namelist',err=1000)
    write(unitageclasses,nml=ageclass)
    close(unitageclasses)
  endif
Matthias Langer's avatar
 
Matthias Langer committed
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

  if (nageclass.gt.maxageclass) then
    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
  endif

  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       #### '
  write(*,'(a)') path(1)(1:length(1))
  stop

110
111
112
113
114
115
1000  write(*,*) ' #### FLEXPART MODEL ERROR! FILE "AGECLASSES" #### '
  write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
  write(*,'(a)') path(2)(1:length(2))
  stop


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