SABER
bump_main.F90
Go to the documentation of this file.
1 !----------------------------------------------------------------------
2 ! subroutine: bump_main
3 !> Call to the BUMP library
4 ! Author: Benjamin Menetrier
5 ! Licensing: this code is distributed under the CeCILL-C license
6 ! Copyright © 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
7 !----------------------------------------------------------------------
8 subroutine bump_main(n1,arg1,n2,arg2) bind (c,name='bump_main_f90')
9 
10 use fckit_mpi_module, only: fckit_mpi_comm
11 use iso_c_binding
12 use iso_fortran_env, only : output_unit
13 use type_bump, only: bump_type
14 use type_model, only: model_type
15 use type_mpl, only: mpl_type
16 use type_timer, only: timer_type
17 
18 implicit none
19 
20 ! Passed variables
21 integer(c_int),intent(in) :: n1 !< First argument size
22 character(c_char),intent(in) :: arg1(n1) !< First argument
23 integer(c_int),intent(in) :: n2 !< Second argument size
24 character(c_char),intent(in) :: arg2(n2) !< Second argument
25 
26 ! Local variables
27 integer :: i,ppos,iproc,ie,ifileunit
28 character(len=1024) :: inputfile,logdir,ext,filename
29 type(bump_type) :: bump
30 type(fckit_mpi_comm) :: f_comm
31 type(model_type) :: model
32 type(mpl_type) :: mpl
33 type(timer_type) :: timer
34 
35 ! Initialize MPI
36 f_comm = fckit_mpi_comm()
37 
38 ! Copy inputfile and logdir
39 inputfile = ''
40 do i=1,n1
41  inputfile(i:i) = arg1(i)
42 end do
43 logdir = ''
44 do i=1,n2
45  logdir(i:i) = arg2(i)
46 end do
47 
48 ! Set missing values
49 mpl%msv%vali = -999
50 mpl%msv%valr = -999.0
51 
52 ! Initialize MPL
53 call mpl%init(f_comm)
54 
55 ! Initialize timer
56 call timer%start(mpl)
57 
58 ! Initialize namelist
59 call bump%nam%init(mpl%nproc)
60 
61 ! Find whether input file is a namelist (xxx.nam) or a yaml (xxxx.yaml) and read it
62 ppos = scan(inputfile,".",back=.true.)
63 ext = inputfile(ppos+1:)
64 select case (trim(ext))
65 case ('nam')
66  ! Namelist
67  call bump%nam%read(mpl,inputfile)
68 case ('yaml')
69  ! yaml
70  call bump%nam%read_yaml(mpl,inputfile)
71 case default
72  ! Wrong extension
73  write(output_unit,'(a)') 'Error: input file has a wrong extension (should be .nam or .yaml)'
74  call flush(output_unit)
75  error stop 3
76 end select
77 
78 ! Broadcast namelist
79 call bump%nam%bcast(mpl)
80 
81 ! Define info unit and open file
82 do iproc=1,mpl%nproc
83  if ((trim(bump%nam%verbosity)=='all').or.((trim(bump%nam%verbosity)=='main').and.(iproc==mpl%rootproc))) then
84  if (iproc==mpl%myproc) then
85  ! Find a free unit
86  call mpl%newunit(mpl%lunit)
87 
88  ! Open listing file
89  write(filename,'(a,i6.6,a)') trim(bump%nam%prefix)//'.',mpl%myproc-1,'.out'
90  inquire(file=filename,number=ifileunit)
91  if (ifileunit<0) then
92  open(unit=mpl%lunit,file=trim(logdir)//'/'//trim(filename),action='write',status='replace')
93  else
94  close(ifileunit)
95  open(unit=mpl%lunit,file=trim(logdir)//'/'//trim(filename),action='write',status='replace')
96  end if
97  end if
98  call mpl%f_comm%barrier
99  end if
100 end do
101 
102 ! Header
103 write(mpl%info,'(a)') '-------------------------------------------------------------------'
104 call mpl%flush
105 write(mpl%info,'(a)') '--- You are running the BUMP main program -------------------------'
106 call mpl%flush
107 
108 ! Model setup
109 write(mpl%info,'(a)') '-------------------------------------------------------------------'
110 call mpl%flush
111 write(mpl%info,'(a)') '--- Setup model'
112 call mpl%flush
113 call model%setup(mpl,bump%nam)
114 
115 ! Load ensembles
116 if (bump%nam%ens1_ne>0) then
117  write(mpl%info,'(a)') '-------------------------------------------------------------------'
118  call mpl%flush
119  write(mpl%info,'(a)') '--- Load ensemble 1'
120  call mpl%flush
121  call model%load_ens(mpl,bump%nam,'ens1')
122 end if
123 if (bump%nam%ens2_ne>0) then
124  write(mpl%info,'(a)') '-------------------------------------------------------------------'
125  call mpl%flush
126  write(mpl%info,'(a)') '--- Load ensemble 2'
127  call mpl%flush
128  call model%load_ens(mpl,bump%nam,'ens2')
129 end if
130 
131 if (bump%nam%new_obsop) then
132  ! Generate observations locations
133  write(mpl%info,'(a)') '-------------------------------------------------------------------'
134  call mpl%flush
135  write(mpl%info,'(a)') '--- Generate observations locations'
136  call mpl%flush
137  call model%generate_obs(mpl,bump%nam)
138 end if
139 
140 ! BUMP setup
141 if (bump%nam%new_obsop) then
142  call bump%setup(f_comm,model%afunctionspace,model%fieldset, &
143  & nobs=model%nobsa,lonobs=model%lonobs,latobs=model%latobs, &
144  & lunit=mpl%lunit,msvali=mpl%msv%vali,msvalr=mpl%msv%valr)
145 else
146  call bump%setup(f_comm,model%afunctionspace,model%fieldset, &
147  & lunit=mpl%lunit,msvali=mpl%msv%vali,msvalr=mpl%msv%valr)
148 end if
149 
150 ! Add members
151 if (bump%nam%ens1_ne>0) then
152  write(mpl%info,'(a)') '-------------------------------------------------------------------'
153  call mpl%flush
154  write(mpl%info,'(a)') '--- Add members of ensemble 1'
155  call mpl%flush
156  do ie=1,bump%nam%ens1_ne
157  write(mpl%info,'(a7,a,i4,a,i4)') '','Member ',ie,' / ',bump%nam%ens1_ne
158  call mpl%flush
159  call bump%add_member(model%ens1(ie),ie,1)
160  end do
161 end if
162 if (bump%nam%ens2_ne>0) then
163  write(mpl%info,'(a)') '-------------------------------------------------------------------'
164  call mpl%flush
165  write(mpl%info,'(a)') '--- Add members of ensemble 2'
166  call mpl%flush
167  do ie=1,bump%nam%ens2_ne
168  write(mpl%info,'(a7,a,i4,a,i4)') '','Member ',ie,' / ',bump%nam%ens2_ne
169  call mpl%flush
170  call bump%add_member(model%ens2(ie),ie,2)
171  end do
172 end if
173 
174 ! Test set_parameters interfaces
175 if (bump%nam%check_set_param_cor.or.bump%nam%check_set_param_hyb.or.bump%nam%check_set_param_lct) then
176  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
177  call bump%mpl%flush
178  write(bump%mpl%info,'(a)') '--- Test set_parameters interfaces'
179  call bump%mpl%flush()
180  call bump%test_set_parameter
181  if (bump%nam%default_seed) call bump%rng%reseed(mpl)
182 end if
183 
184 ! Run drivers
185 write(mpl%info,'(a)') '-------------------------------------------------------------------'
186 call mpl%flush
187 write(mpl%info,'(a)') '--- Run drivers'
188 call mpl%flush
189 call bump%run_drivers
190 
191 ! Test get_parameter interfaces
192 if (bump%nam%check_get_param_cor.or.bump%nam%check_get_param_hyb.or.bump%nam%check_get_param_Dloc &
193  & .or.bump%nam%check_get_param_lct) then
194  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
195  call bump%mpl%flush
196  write(bump%mpl%info,'(a)') '--- Test get_parameter interfaces'
197  call bump%mpl%flush()
198  call bump%test_get_parameter
199  if (bump%nam%default_seed) call bump%rng%reseed(mpl)
200 end if
201 
202 ! Release memory (partial)
203 write(mpl%info,'(a)') '-------------------------------------------------------------------'
204 call mpl%flush
205 write(mpl%info,'(a)') '--- Release memory (partial)'
206 call mpl%flush
207 call bump%partial_dealloc
208 
209 ! Test interfaces
210 write(mpl%info,'(a)') '-------------------------------------------------------------------'
211 call mpl%flush
212 write(mpl%info,'(a)') '--- Test apply interfaces'
213 call mpl%flush
214 call bump%test_apply_interfaces
215 
216 ! Execution stats
217 write(mpl%info,'(a)') '-------------------------------------------------------------------'
218 call mpl%flush
219 write(mpl%info,'(a)') '--- Execution stats'
220 call timer%display(mpl)
221 call mpl%flush
222 
223 if ((trim(bump%nam%verbosity)=='all').or.((trim(bump%nam%verbosity)=='main').and.mpl%main)) then
224  ! Close listings
225  write(mpl%info,'(a)') '-------------------------------------------------------------------'
226  call mpl%flush
227  write(mpl%info,'(a)') '--- Close listings'
228  call mpl%flush
229  write(mpl%info,'(a)') '-------------------------------------------------------------------'
230  call mpl%flush
231  close(unit=mpl%lunit)
232 end if
233 
234 ! Finalize MPL
235 call mpl%final
236 
237 ! Release memory
238 call bump%dealloc
239 call model%dealloc
240 
241 end subroutine bump_main
type_bump
BUMP derived type.
Definition: type_bump.F90:8
type_timer
Timer data derived type.
Definition: type_timer.F90:8
type_model::model_type
Definition: type_model.F90:30
type_model
Model routines.
Definition: type_model.F90:8
type_bump::bump_type
Definition: type_bump.F90:38
type_timer::timer_type
Definition: type_timer.F90:16
bump_main
subroutine bump_main(n1, arg1, n2, arg2)
Call to the BUMP library.
Definition: bump_main.F90:9
type_mpl
MPI parameters derived type.
Definition: type_mpl.F90:8
type_mpl::mpl_type
Definition: type_mpl.F90:24