source: trunk/LMDZ.MARS/libf/phymars/write_output_mod.F90 @ 4058

Last change on this file since 4058 was 4058, checked in by emillour, 4 days ago

Mars PCM:
Add a "output_diagfi" (default .true.) flag so that the user can decide if
a diagfi.nc file should be outputted.
Also do some cleaning around the few remaining calls to writediagfi
or reference to it througout the code; write_output() should be used.
EM

File size: 9.8 KB
Line 
1MODULE write_output_mod
2
3implicit none
4
5private
6
7INTERFACE write_output
8    MODULE PROCEDURE write_output_d0, write_output_d1, write_output_d2, &
9                     write_output_i0, write_output_i1, write_output_i2, &
10                     write_output_l0, write_output_l1, write_output_l2
11END INTERFACE write_output
12
13public write_output
14
15logical,public,save :: output_diagfi ! global flag to trigger generating
16                      ! a diagfi.nc file or not. Initialized in conf_phys()
17!$OMP THREADPRIVATE(output_diagfi)
18
19
20!-----------------------------------------------------------------------
21contains
22!-----------------------------------------------------------------------
23
24SUBROUTINE write_output_d0(field_name,title,units,field)
25! For a scalar
26
27#ifdef CPP_XIOS
28    use xios_output_mod, only: xios_is_active_field
29    use xios_output_mod, only: send_xios_field
30#endif
31
32implicit none
33
34include "dimensions.h"
35
36integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
37character(*), intent(in) :: field_name
38character(*), intent(in) :: title
39character(*), intent(in) :: units
40real,         intent(in) :: field
41
42logical :: is_active ! For XIOS, should this field be sent or not
43
44if (output_diagfi) call writediagfi(ngrid,field_name,title,units,0,(/field/))
45#ifdef CPP_XIOS
46!is_active=xios_is_active_field(field_name)
47is_active=.true.
48    ! only send the field to xios if the user asked for it
49    if (is_active) call send_xios_field(field_name,field)
50#endif
51
52END SUBROUTINE write_output_d0
53
54!-----------------------------------------------------------------------
55
56SUBROUTINE write_output_d1(field_name,title,units,field)
57! For a surface field
58
59#ifdef CPP_XIOS
60    use xios_output_mod, only: xios_is_active_field
61    use xios_output_mod, only: send_xios_field
62#endif
63
64implicit none
65
66include "dimensions.h"
67
68integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
69character(*),       intent(in) :: field_name
70character(*),       intent(in) :: title
71character(*),       intent(in) :: units
72real, dimension(:), intent(in) :: field
73
74logical :: is_active ! For XIOS, should this field be sent or not
75
76if (output_diagfi) call writediagfi(ngrid,field_name,title,units,2,field)
77#ifdef CPP_XIOS
78!is_active=xios_is_active_field(field_name)
79is_active=.true.
80    ! only send the field to xios if the user asked for it
81    if (is_active) call send_xios_field(field_name,field)
82#endif
83
84END SUBROUTINE write_output_d1
85
86!-----------------------------------------------------------------------
87
88SUBROUTINE write_output_d2(field_name,title,units,field)
89! For a "3D" horizontal-vertical field
90
91#ifdef CPP_XIOS
92    use xios_output_mod, only: xios_is_active_field
93    use xios_output_mod, only: send_xios_field
94#endif
95
96use comsoil_h,         only: nsoilmx
97use writediagsoil_mod, only: writediagsoil
98
99implicit none
100
101include "dimensions.h"
102
103integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
104character(*),         intent(in) :: field_name
105character(*),         intent(in) :: title
106character(*),         intent(in) :: units
107real, dimension(:,:), intent(in) :: field
108
109logical :: is_active ! For XIOS, should this field be sent or not
110
111if (size(field,2) == nsoilmx) then
112    call writediagsoil(ngrid,field_name,title,units,3,field)
113else
114  if (output_diagfi) call writediagfi(ngrid,field_name,title,units,3,field)
115endif
116
117#ifdef CPP_XIOS
118!is_active=xios_is_active_field(field_name)
119is_active=.true.
120    ! only send the field to xios if the user asked for it
121    if (is_active) call send_xios_field(field_name,field)
122#endif
123
124END SUBROUTINE write_output_d2
125
126!-----------------------------------------------------------------------
127
128SUBROUTINE write_output_i0(field_name,title,units,field)
129! For a scalar
130
131#ifdef CPP_XIOS
132    use xios_output_mod, only: xios_is_active_field
133    use xios_output_mod, only: send_xios_field
134#endif
135
136implicit none
137
138include "dimensions.h"
139
140integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
141character(*), intent(in) :: field_name
142character(*), intent(in) :: title
143character(*), intent(in) :: units
144integer,      intent(in) :: field
145
146logical :: is_active ! For XIOS, should this field be sent or not
147
148if (output_diagfi) call writediagfi(ngrid,field_name,title,units,0,(/real(field)/))
149
150#ifdef CPP_XIOS
151!is_active=xios_is_active_field(field_name)
152is_active=.true.
153    ! only send the field to xios if the user asked for it
154    if (is_active) call send_xios_field(field_name,(/real(field)/))
155#endif
156
157END SUBROUTINE write_output_i0
158
159!-----------------------------------------------------------------------
160
161SUBROUTINE write_output_i1(field_name,title,units,field)
162! For a surface field
163
164#ifdef CPP_XIOS
165    use xios_output_mod, only: xios_is_active_field
166    use xios_output_mod, only: send_xios_field
167#endif
168
169implicit none
170
171include "dimensions.h"
172
173integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
174character(*),          intent(in) :: field_name
175character(*),          intent(in) :: title
176character(*),          intent(in) :: units
177integer, dimension(:), intent(in) :: field
178
179logical :: is_active ! For XIOS, should this field be sent or not
180
181if (output_diagfi) call writediagfi(ngrid,field_name,title,units,2,real(field))
182
183#ifdef CPP_XIOS
184!is_active=xios_is_active_field(field_name)
185is_active=.true.
186    ! only send the field to xios if the user asked for it
187    if (is_active) call send_xios_field(field_name,real(field))
188#endif
189
190END SUBROUTINE write_output_i1
191
192!-----------------------------------------------------------------------
193
194SUBROUTINE write_output_i2(field_name,title,units,field)
195! For a "3D" horizontal-vertical field
196
197#ifdef CPP_XIOS
198    use xios_output_mod, only: xios_is_active_field
199    use xios_output_mod, only: send_xios_field
200#endif
201
202use comsoil_h,         only: nsoilmx
203use writediagsoil_mod, only: writediagsoil
204
205implicit none
206
207include "dimensions.h"
208
209integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
210character(*),            intent(in) :: field_name
211character(*),            intent(in) :: title
212character(*),            intent(in) :: units
213integer, dimension(:,:), intent(in) :: field
214
215logical :: is_active ! For XIOS, should this field be sent or not
216
217if (size(field,2) == nsoilmx) then
218    call writediagsoil(ngrid,field_name,title,units,3,real(field))
219else
220  if (output_diagfi) call writediagfi(ngrid,field_name,title,units,3,real(field))
221endif
222#ifdef CPP_XIOS
223!is_active=xios_is_active_field(field_name)
224is_active=.true.
225    ! only send the field to xios if the user asked for it
226    if (is_active) call send_xios_field(field_name,real(field))
227#endif
228
229END SUBROUTINE write_output_i2
230
231!-----------------------------------------------------------------------
232
233SUBROUTINE write_output_l0(field_name,title,units,field)
234! For a scalar
235 
236#ifdef CPP_XIOS
237    use xios_output_mod, only: xios_is_active_field
238    use xios_output_mod, only: send_xios_field
239#endif
240
241implicit none
242
243include "dimensions.h"
244
245integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
246character(*), intent(in) :: field_name
247character(*), intent(in) :: title
248character(*), intent(in) :: units
249logical,      intent(in) :: field
250! Local argument used to convert logical to real array
251real, dimension(1) :: field_real
252logical :: is_active ! For XIOS, should this field be sent or not
253
254field_real = 0.
255if (field) field_real = 1.
256
257if (output_diagfi) call writediagfi(ngrid,field_name,title,units,0,field_real)
258#ifdef CPP_XIOS
259!is_active=xios_is_active_field(field_name)
260is_active=.true.
261    ! only send the field to xios if the user asked for it
262    if (is_active) call send_xios_field(field_name,field_real)
263#endif
264
265END SUBROUTINE write_output_l0
266
267!-----------------------------------------------------------------------
268
269SUBROUTINE write_output_l1(field_name,title,units,field)
270! For a surface field
271
272#ifdef CPP_XIOS
273    use xios_output_mod, only: xios_is_active_field
274    use xios_output_mod, only: send_xios_field
275#endif
276
277implicit none
278
279include "dimensions.h"
280
281integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
282character(*),          intent(in) :: field_name
283character(*),          intent(in) :: title
284character(*),          intent(in) :: units
285logical, dimension(:), intent(in) :: field
286! Local argument used to convert logical to real
287real, dimension(ngrid) :: field_real
288logical :: is_active ! For XIOS, should this field be sent or not
289
290field_real = 0.
291where (field) field_real = 1.
292
293if (output_diagfi) call writediagfi(ngrid,field_name,title,units,2,field_real)
294
295#ifdef CPP_XIOS
296!is_active=xios_is_active_field(field_name)
297is_active=.true.
298    ! only send the field to xios if the user asked for it
299    if (is_active) call send_xios_field(field_name,field_real)
300#endif
301
302END SUBROUTINE write_output_l1
303
304!-----------------------------------------------------------------------
305
306SUBROUTINE write_output_l2(field_name,title,units,field)
307! For a "3D" horizontal-vertical field
308
309#ifdef CPP_XIOS
310    use xios_output_mod, only: xios_is_active_field
311    use xios_output_mod, only: send_xios_field
312#endif
313
314use comsoil_h,         only: nsoilmx
315use writediagsoil_mod, only: writediagsoil
316
317implicit none
318
319include "dimensions.h"
320
321integer, parameter :: ngrid = 2 + (jjm - 1)*iim - 1/jjm
322character(*),            intent(in) :: field_name
323character(*),            intent(in) :: title
324character(*),            intent(in) :: units
325logical, dimension(:,:), intent(in) :: field
326! Local argument used to convert logical to real
327real, allocatable, dimension(:,:) :: field_real
328logical :: is_active ! For XIOS, should this field be sent or not
329
330allocate(field_real(size(field,1),size(field,2)))
331field_real = 0.
332where (field) field_real = 1.
333
334if (size(field,2) == nsoilmx) then
335    call writediagsoil(ngrid,field_name,title,units,3,field_real)
336else
337  if (output_diagfi) call writediagfi(ngrid,field_name,title,units,3,field_real)
338endif
339
340#ifdef CPP_XIOS
341!is_active=xios_is_active_field(field_name)
342is_active=.true.
343    ! only send the field to xios if the user asked for it
344    if (is_active) call send_xios_field(field_name,field_real)
345#endif
346
347deallocate(field_real)
348
349END SUBROUTINE write_output_l2
350
351END MODULE write_output_mod
Note: See TracBrowser for help on using the repository browser.