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