source: branches/UKMO/AMM15_v3_6_STABLE_package_collate_utils366_fabmv1/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90 @ 13451

Last change on this file since 13451 was 13451, checked in by dford, 8 months ago

Modifications to accommodate interaction between NEMO-FABM coupler only saving diagnostics requested in iodef.xml, and the assimilation and 25h/tmb diagnostic code.

File size: 25.9 KB
Line 
1MODULE trcini_fabm
2   !!======================================================================
3   !!                         ***  MODULE trcini_fabm  ***
4   !! TOP :   initialisation of the FABM tracers
5   !!======================================================================
6   !! History :   1.0  !  2015-04  (PML) Original code
7   !! History :   1.1  !  2020-06  (PML) Update to FABM 1.0, improved performance
8   !!----------------------------------------------------------------------
9#if defined key_fabm
10   !!----------------------------------------------------------------------
11   !!   'key_fabm'                                               FABM tracers
12   !!----------------------------------------------------------------------
13   !! trc_ini_fabm   : FABM model initialisation
14   !!----------------------------------------------------------------------
15   USE par_trc         ! TOP parameters
16   USE oce_trc
17   USE trc
18   USE par_fabm
19   USE trcsms_fabm
20   USE fabm, only: fabm_create_model, type_fabm_variable
21   USE fabm_driver
22   USE inputs_fabm,ONLY: initialize_inputs, link_inputs, &
23     type_input_variable,type_input_data,type_river_data, &
24     first_input_data,first_river_data
25#if defined key_git_version
26   USE fabm_version,ONLY: fabm_commit_id=>git_commit_id, &
27                          fabm_branch_name=>git_branch_name
28   USE fabm_types,ONLY: type_version,first_module_version
29#endif
30
31
32   IMPLICIT NONE
33   PRIVATE
34
35#if defined key_git_version
36#  include "gitversion.h90"
37   CHARACTER(len=*),parameter :: git_commit_id = _NEMO_COMMIT_ID_
38   CHARACTER(len=*),parameter :: git_branch_name = _NEMO_BRANCH_
39#endif
40
41   PUBLIC   trc_ini_fabm   ! called by trcini.F90 module
42   PUBLIC   nemo_fabm_configure
43
44   TYPE,extends(type_base_driver) :: type_nemo_fabm_driver
45   contains
46      procedure :: fatal_error => nemo_fabm_driver_fatal_error
47      procedure :: log_message => nemo_fabm_driver_log_message
48   end type
49
50   !!----------------------------------------------------------------------
51   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
52   !! $Id$
53   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
54   !!----------------------------------------------------------------------
55CONTAINS
56
57   SUBROUTINE nemo_fabm_configure()
58      INTEGER :: jn
59      INTEGER, PARAMETER :: xml_unit = 1979
60      TYPE (type_input_data),POINTER :: input_data
61      TYPE (type_river_data),POINTER :: river_data
62      CLASS (type_input_variable),POINTER :: input_pointer
63
64      ALLOCATE(type_nemo_fabm_driver::driver)
65
66      ! Allow FABM to parse fabm.yaml. This ensures numbers of variables are known.
67      model => fabm_create_model()
68
69      jp_fabm = size(model%interior_state_variables)
70      jp_fabm_bottom = size(model%bottom_state_variables)
71      jp_fabm_surface = size(model%surface_state_variables)
72      jp_fabm0 = jptra + 1
73      jp_fabm1 = jptra + jp_fabm
74      jp_fabm_m1=jptra
75      jptra = jptra + jp_fabm
76      jp_fabm_2d = size(model%horizontal_diagnostic_variables)
77      jp_fabm_3d = size(model%interior_diagnostic_variables)
78      jpdia2d = jpdia2d + jp_fabm_2d
79      jpdia3d = jpdia3d + jp_fabm_3d
80      jpdiabio = jpdiabio + jp_fabm
81
82      ! Read inputs (river and additional 2D forcing) from fabm_input.nml
83      ! This must be done before writing field_def_fabm.xml, as that file
84      ! also describes the additional input variables.
85      call initialize_inputs
86
87      ! Get indexes for select state variables
88      jp_fabm_chl1 = fabm_state_index( 'P1_Chl' )
89      jp_fabm_chl2 = fabm_state_index( 'P2_Chl' )
90      jp_fabm_chl3 = fabm_state_index( 'P3_Chl' )
91      jp_fabm_chl4 = fabm_state_index( 'P4_Chl' )
92      jp_fabm_p1c  = fabm_state_index( 'P1_c' )
93      jp_fabm_p1n  = fabm_state_index( 'P1_n' )
94      jp_fabm_p1p  = fabm_state_index( 'P1_p' )
95      jp_fabm_p1s  = fabm_state_index( 'P1_s' )
96      jp_fabm_p2c  = fabm_state_index( 'P2_c' )
97      jp_fabm_p2n  = fabm_state_index( 'P2_n' )
98      jp_fabm_p2p  = fabm_state_index( 'P2_p' )
99      jp_fabm_p3c  = fabm_state_index( 'P3_c' )
100      jp_fabm_p3n  = fabm_state_index( 'P3_n' )
101      jp_fabm_p3p  = fabm_state_index( 'P3_p' )
102      jp_fabm_p4c  = fabm_state_index( 'P4_c' )
103      jp_fabm_p4n  = fabm_state_index( 'P4_n' )
104      jp_fabm_p4p  = fabm_state_index( 'P4_p' )
105      jp_fabm_z4c  = fabm_state_index( 'Z4_c' )
106      jp_fabm_z5c  = fabm_state_index( 'Z5_c' )
107      jp_fabm_z5n  = fabm_state_index( 'Z5_n' )
108      jp_fabm_z5p  = fabm_state_index( 'Z5_p' )
109      jp_fabm_z6c  = fabm_state_index( 'Z6_c' )
110      jp_fabm_z6n  = fabm_state_index( 'Z6_n' )
111      jp_fabm_z6p  = fabm_state_index( 'Z6_p' )
112      jp_fabm_n1p  = fabm_state_index( 'N1_p' )
113      jp_fabm_n3n  = fabm_state_index( 'N3_n' )
114      jp_fabm_n4n  = fabm_state_index( 'N4_n' )
115      jp_fabm_n5s  = fabm_state_index( 'N5_s' )
116      jp_fabm_o2o  = fabm_state_index( 'O2_o' )
117      jp_fabm_o3c  = fabm_state_index( 'O3_c' )
118      jp_fabm_o3ba = fabm_state_index( 'O3_bioalk' )
119      jp_fabm_r4n  = fabm_state_index( 'R4_n' )
120      jp_fabm_r4c  = fabm_state_index( 'R4_c' )
121      jp_fabm_r4p  = fabm_state_index( 'R4_p' )
122      jp_fabm_r6n  = fabm_state_index( 'R6_n' )
123      jp_fabm_r6c  = fabm_state_index( 'R6_c' )
124      jp_fabm_r6p  = fabm_state_index( 'R6_p' )
125      jp_fabm_r6s  = fabm_state_index( 'R6_s' )
126      jp_fabm_r8n  = fabm_state_index( 'R8_n' )
127      jp_fabm_r8c  = fabm_state_index( 'R8_c' )
128      jp_fabm_r8p  = fabm_state_index( 'R8_p' )
129      jp_fabm_r8s  = fabm_state_index( 'R8_s' )
130
131      ! Get indexes for select diagnostic variables
132      jp_fabm_o3ta  = fabm_diag_index( 'O3_TA' )
133      jp_fabm_o3ph  = fabm_diag_index( 'O3_pH' )
134      jp_fabm_o3pc  = fabm_diag_index( 'O3_pCO2' )
135      jp_fabm_xeps  = fabm_diag_index( 'light_xEPS' )
136      jp_fabm_pgrow = fabm_diag_index( 'p_grow_sum_result' )
137      jp_fabm_ploss = fabm_diag_index( 'p_loss_sum_result' )
138
139      IF (lwp) THEN
140         ! write field_def_fabm.xml on lead process
141         OPEN(UNIT=xml_unit, FILE='field_def_fabm.xml', ACTION='WRITE', STATUS='REPLACE')
142
143         WRITE (xml_unit,1000) '<field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" >'
144
145         WRITE (xml_unit,1000) ' <field_group id="ptrc_T" grid_ref="grid_T_3D">'
146         DO jn=1,jp_fabm
147            CALL write_variable_xml(xml_unit,model%interior_state_variables(jn))
148#if defined key_trdtrc
149            CALL write_trends_xml(xml_unit,model%interior_state_variables(jn))
150#endif
151            CALL write_25hourm_xml(xml_unit,model%interior_state_variables(jn))
152            CALL write_tmb_xml(xml_unit,model%interior_state_variables(jn))
153         END DO
154         WRITE (xml_unit,1000) ' </field_group>'
155
156         WRITE (xml_unit,1000) ' <field_group id="sf_T" grid_ref="grid_T_2D">'
157         DO jn=1,jp_fabm_surface
158            CALL write_variable_xml(xml_unit,model%surface_state_variables(jn))
159            CALL write_25hourm_xml(xml_unit,model%surface_state_variables(jn))
160         END DO
161         DO jn=1,jp_fabm_bottom
162            CALL write_variable_xml(xml_unit,model%bottom_state_variables(jn))
163            CALL write_25hourm_xml(xml_unit,model%bottom_state_variables(jn))
164         END DO
165         WRITE (xml_unit,1000) ' </field_group>'
166
167         WRITE (xml_unit,1000) ' <field_group id="diad_T" grid_ref="grid_T_2D">'
168         DO jn=1,size(model%interior_diagnostic_variables)
169            CALL write_variable_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
170            CALL write_25hourm_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
171            CALL write_tmb_xml(xml_unit,model%interior_diagnostic_variables(jn))
172         END DO
173         DO jn=1,size(model%horizontal_diagnostic_variables)
174            CALL write_variable_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
175            CALL write_25hourm_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
176         END DO
177         DO jn=1,size(model%interior_state_variables)
178            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_state_variables(jn)%name)// &
179               &                   '_VINT" long_name="depth-integrated '//TRIM(model%interior_state_variables(jn)%long_name)// &
180               &                   '" unit="'//TRIM(model%interior_state_variables(jn)%units)//'*m" default_value="0.0" />'
181         END DO
182         DO jn=1,size(model%interior_diagnostic_variables)
183            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_diagnostic_variables(jn)%name)// &
184               &                   '_VINT" long_name="depth-integrated '//TRIM(model%interior_diagnostic_variables(jn)%long_name)// &
185               &                   '" unit="'//TRIM(model%interior_diagnostic_variables(jn)%units)//'*m" default_value="0.0" />'
186         END DO
187         WRITE (xml_unit,1000) ' </field_group>'
188
189         WRITE (xml_unit,1000) ' <field_group id="fabm_scalar" grid_ref="grid_0">'
190         DO jn=1,size(model%conserved_quantities)
191            CALL write_variable_xml(xml_unit,model%conserved_quantities(jn))
192         END DO
193         WRITE (xml_unit,1000) ' </field_group>'
194
195         WRITE (xml_unit,1000) ' <field_group id="fabm_input" grid_ref="grid_T_2D">'
196         input_data => first_input_data
197         DO WHILE (ASSOCIATED(input_data))
198           input_pointer => input_data
199           CALL write_input_xml(xml_unit,input_pointer)
200            input_data => input_data%next
201         END DO
202         river_data => first_river_data
203         DO WHILE (ASSOCIATED(river_data))
204           input_pointer => river_data
205           CALL write_input_xml(xml_unit,input_pointer,3)
206            river_data => river_data%next
207         END DO
208         WRITE (xml_unit,1000) ' </field_group>'
209
210         WRITE (xml_unit,1000) '</field_definition>'
211
212         CLOSE(xml_unit)
213      END IF
214      IF( lk_mpp )   CALL mppsync !Ensure field_def_fabm is ready.
215
2161000 FORMAT (A)
217
218   END SUBROUTINE nemo_fabm_configure
219
220   SUBROUTINE write_variable_xml(xml_unit,variable,flag_grid_ref)
221      INTEGER,INTENT(IN) :: xml_unit
222      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
223      CLASS (type_fabm_variable),INTENT(IN) :: variable
224
225      CHARACTER(LEN=20) :: missing_value,string_dimensions
226      INTEGER :: number_dimensions
227
228      ! Check variable dimension for grid_ref specificaiton.
229      ! Default is to not specify the grid_ref in the field definition.
230      IF (present(flag_grid_ref)) THEN
231          number_dimensions=flag_grid_ref
232      ELSE
233          number_dimensions=-1 !default, don't specify grid_ref
234      ENDIF
235
236      WRITE (missing_value,'(E9.3)') variable%missing_value
237      WRITE (string_dimensions,'(I1)') number_dimensions
238      SELECT CASE (number_dimensions)
239      CASE (3)
240         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
241      CASE (2)
242         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
243      CASE (0)
244         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="1point"/>'
245      CASE (-1)
246         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'" long_name="'//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
247      CASE default
248         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise output of variable '//TRIM(variable%name)//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional variables not supported!!!'
249      END SELECT
250
251   END SUBROUTINE write_variable_xml
252
253   SUBROUTINE write_25hourm_xml(xml_unit,variable,flag_grid_ref)
254      INTEGER,INTENT(IN) :: xml_unit
255      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
256      CLASS (type_fabm_variable),INTENT(IN) :: variable
257
258      CHARACTER(LEN=20) :: missing_value,string_dimensions
259      INTEGER :: number_dimensions
260
261      ! Check variable dimension for grid_ref specificaiton.
262      ! Default is to not specify the grid_ref in the field definition.
263      IF (present(flag_grid_ref)) THEN
264          number_dimensions=flag_grid_ref
265      ELSE
266          number_dimensions=-1 !default, don't specify grid_ref
267      ENDIF
268
269      WRITE (missing_value,'(E9.3)') 1.e+20
270      WRITE (string_dimensions,'(I1)') number_dimensions
271      SELECT CASE (number_dimensions)
272      CASE (3)
273         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
274      CASE (2)
275         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
276      CASE (0)
277         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="1point"/>'
278      CASE (-1)
279         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'25h'//'" long_name="'//TRIM(variable%long_name)//' 25-hour mean'//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
280      CASE default
281         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise output of variable '//TRIM(variable%name)//'25h'//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional variables not supported!!!'
282      END SELECT
283
284   END SUBROUTINE write_25hourm_xml
285
286   SUBROUTINE write_tmb_xml(xml_unit,variable)
287      INTEGER,INTENT(IN) :: xml_unit
288      CLASS (type_fabm_variable),INTENT(IN) :: variable
289
290      CHARACTER(LEN=20) :: missing_value
291
292      WRITE (missing_value,'(E9.3)') 1.e+20
293      WRITE (xml_unit,'(A)') '  <field id="top_'//TRIM(variable%name)//'" long_name="Top-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
294      WRITE (xml_unit,'(A)') '  <field id="mid_'//TRIM(variable%name)//'" long_name="Middle-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
295      WRITE (xml_unit,'(A)') '  <field id="bot_'//TRIM(variable%name)//'" long_name="Bottom-level '//TRIM(variable%long_name)//'" unit="'//TRIM(variable%units)//'" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_2D"/>'
296
297   END SUBROUTINE write_tmb_xml
298
299   SUBROUTINE write_trends_xml(xml_unit,variable,flag_grid_ref)
300      INTEGER,INTENT(IN) :: xml_unit
301      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
302      CLASS (type_fabm_variable),INTENT(IN) :: variable
303
304      INTEGER :: number_dimensions,i
305      CHARACTER(LEN=20) :: missing_value,string_dimensions
306#if defined key_tracer_budget
307      CHARACTER(LEN=3),DIMENSION(10),PARAMETER :: trd_tags = (/ &
308        'LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
309        'RDB','RDN','VMV' /)
310      CHARACTER(LEN=3),DIMENSION(3),PARAMETER :: trd_e3t_tags = (/ &
311        'XAD','YAD','ZAD' /)
312#else
313      CHARACTER(LEN=3),DIMENSION(13),PARAMETER :: trd_tags = (/ &
314        'XAD','YAD','ZAD','LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
315        'RDB','RDN','VMV' /)
316#endif
317
318      ! Check variable dimension for grid_ref specificaiton.
319      ! Default is to not specify the grid_ref in the field definition.
320      IF (present(flag_grid_ref)) THEN
321          number_dimensions=flag_grid_ref
322      ELSE
323          number_dimensions=-1 !default, don't specify grid_ref
324      ENDIF
325
326      WRITE (missing_value,'(E9.3)') -2.E20
327      WRITE (string_dimensions,'(I1)') number_dimensions
328      SELECT CASE (number_dimensions)
329      CASE (3)
330        DO i=1,size(trd_tags)
331         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'// &
332            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//            &
333            &                   TRIM(variable%units)//'/s" default_value="'//                                   &
334            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
335        END DO
336#if defined key_tracer_budget
337        DO i=1,size(trd_e3t_tags)
338         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
339            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
340            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
341            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
342        END DO
343        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
344           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'/s" default_value="'//       &
345           &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
346#endif
347      CASE (-1)
348        DO i=1,size(trd_tags)
349         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'//   &
350            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//              &
351            &                   TRIM(variable%units)//'/s" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
352        END DO
353#if defined key_tracer_budget
354        DO i=1,size(trd_e3t_tags)
355         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
356            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
357            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
358            &                   TRIM(ADJUSTL(missing_value))//'" />'
359        END DO
360        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
361           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'/s" default_value="'//       &
362           &                   TRIM(ADJUSTL(missing_value))//'" />'
363#endif
364      CASE default
365         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise trends of variable '//TRIM(variable%name)// &
366            &                    ': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional trends not supported!!!'
367      END SELECT
368
369   END SUBROUTINE write_trends_xml
370
371   SUBROUTINE write_input_xml(xml_unit,variable,flag_grid_ref)
372      INTEGER,INTENT(IN) :: xml_unit
373      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
374      CLASS(type_input_variable),POINTER,INTENT(IN) :: variable
375
376      INTEGER :: number_dimensions,i
377      CHARACTER(LEN=20) :: missing_value,string_dimensions
378
379      ! Check variable dimension for grid_ref specificaiton.
380      ! Default is to not specify the grid_ref in the field definition.
381      IF (present(flag_grid_ref)) THEN
382          number_dimensions=flag_grid_ref
383      ELSE
384          number_dimensions=-1 !default, don't specify grid_ref
385      ENDIF
386
387      WRITE (missing_value,'(E9.3)') -2.E20
388      WRITE (string_dimensions,'(I1)') number_dimensions
389      SELECT CASE (number_dimensions)
390      CASE (3)
391        WRITE (xml_unit,'(A)') '  <field id="'//'INP_'//TRIM(variable%sf(1)%clvar)//'" long_name="'//TRIM(variable%sf(1)%clvar)//' input" unit="" default_value="'//TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
392      CASE (-1)
393        WRITE (xml_unit,'(A)') '  <field id="'//'INP_'//TRIM(variable%sf(1)%clvar)//'" long_name="'//TRIM(variable%sf(1)%clvar)//' input" unit="" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
394      CASE default
395         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise input diagnostic of variable '//TRIM(variable%sf(1)%clvar)//': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional diagnostic not supported!!!'
396      END SELECT
397
398   END SUBROUTINE write_input_xml
399
400   SUBROUTINE trc_ini_fabm
401      !!----------------------------------------------------------------------
402      !!                     ***  trc_ini_fabm  ***
403      !!
404      !! ** Purpose :   initialization for FABM model
405      !!
406      !! ** Method  : - Allocate FABM arrays, configure domain, send data
407      !!----------------------------------------------------------------------
408#if defined key_git_version
409      TYPE (type_version), POINTER :: version
410#endif
411      INTEGER :: jn
412
413      IF(lwp) WRITE(numout,*)
414      IF(lwp) WRITE(numout,*) ' trc_ini_fabm: initialisation of FABM model'
415      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
416#if defined key_git_version
417      IF(lwp) WRITE(numout,*) ' NEMO version:   ',git_commit_id,' (',git_branch_name,' branch)'
418      IF(lwp) WRITE(numout,*) ' FABM version:   ',fabm_commit_id,' (',fabm_branch_name,' branch)'
419      version => first_module_version
420      do while (associated(version))
421         IF(lwp) WRITE(numout,*)  ' '//trim(version%module_name)//' version:   ',trim(version%version_string)
422         version => version%next
423      end do
424#endif
425
426      ! Allocate FABM arrays
427      IF(trc_sms_fabm_alloc() /= 0) CALL ctl_stop( 'STOP', 'trc_ini_fabm: unable to allocate FABM arrays' )
428
429      ! Log mapping of FABM states:
430      IF (lwp) THEN
431         IF (jp_fabm > 0) WRITE(numout,*) " FABM tracers:"
432         DO jn=1,jp_fabm
433            WRITE(numout,*) "   State",jn,":",trim(model%interior_state_variables(jn)%name), &
434               " (",trim(model%interior_state_variables(jn)%long_name), &
435               ") [",trim(model%interior_state_variables(jn)%units),"]"
436         END DO
437         IF (jp_fabm_surface > 0) WRITE(numout,*) "FABM seasurface states:"
438         DO jn=1,jp_fabm_surface
439            WRITE(numout,*) "   State",jn,":",trim(model%surface_state_variables(jn)%name), &
440               " (",trim(model%surface_state_variables(jn)%long_name), &
441               ") [",trim(model%surface_state_variables(jn)%units),"]"
442         END DO
443         IF (jp_fabm_bottom > 0) WRITE(numout,*) "FABM seafloor states:"
444         DO jn=1,jp_fabm_bottom
445            WRITE(numout,*) "   State",jn,":",trim(model%bottom_state_variables(jn)%name), &
446               " (",trim(model%bottom_state_variables(jn)%long_name), &
447               ") [",trim(model%bottom_state_variables(jn)%units),"]"
448         END DO
449      END IF
450     
451      ! Initialise variables required for Hemmings et al. (2008)
452      ! nitrogen balancing for chlorophyll data assimilation
453      MLD_MAX(:,:)   = 0.0
454      PGROW_AVG(:,:) = 0.0
455      PLOSS_AVG(:,:) = 0.0
456      PHYT_AVG(:,:)  = 0.0
457
458   END SUBROUTINE trc_ini_fabm
459
460   SUBROUTINE nemo_fabm_driver_fatal_error(self, location, message)
461      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
462      CHARACTER(len=*),              INTENT(IN)    :: location, message
463
464      CALL ctl_stop('STOP', TRIM(location)//': '//TRIM(message))
465      STOP
466   END SUBROUTINE
467
468   SUBROUTINE nemo_fabm_driver_log_message(self, message)
469      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
470      CHARACTER(len=*),              INTENT(IN)    :: message
471
472      IF(lwp) WRITE (numout,*) TRIM(message)
473   END SUBROUTINE
474
475   INTEGER FUNCTION fabm_state_index( state_name )
476      !!----------------------------------------------------------------------
477      !!                     ***  fabm_state_index  *** 
478      !!
479      !! ** Purpose :   return index of a given FABM state variable
480      !!
481      !! ** Method  : - loop through state variables until found
482      !!----------------------------------------------------------------------
483     
484      IMPLICIT NONE
485     
486      CHARACTER(LEN=*), INTENT(IN) :: state_name
487     
488      INTEGER                      :: jn
489
490      !!----------------------------------------------------------------------
491     
492      fabm_state_index = -1
493      DO jn=1,jp_fabm
494         IF (TRIM(model%interior_state_variables(jn)%name) == TRIM(state_name)) THEN
495            fabm_state_index = jn
496            EXIT
497         ENDIF
498      END DO
499      IF (fabm_state_index == -1) THEN
500         CALL ctl_warn( 'Could not find '//TRIM(state_name)//' state variable' )
501      ELSE
502         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(state_name)//' is: ', fabm_state_index
503      ENDIF
504   
505   END FUNCTION fabm_state_index
506
507   INTEGER FUNCTION fabm_diag_index( diag_name )
508      !!----------------------------------------------------------------------
509      !!                     ***  fabm_state_index  *** 
510      !!
511      !! ** Purpose :   return index of a given FABM diagnostic variable
512      !!
513      !! ** Method  : - loop through diagnostic variables until found
514      !!----------------------------------------------------------------------
515     
516      IMPLICIT NONE
517     
518      CHARACTER(LEN=*), INTENT(IN) :: diag_name
519     
520      INTEGER                      :: jn
521
522      !!----------------------------------------------------------------------
523     
524      fabm_diag_index = -1
525      DO jn = 1, SIZE(model%interior_diagnostic_variables)
526         IF (TRIM(model%interior_diagnostic_variables(jn)%name) == TRIM(diag_name)) THEN
527            fabm_diag_index = jn
528            EXIT
529         ENDIF
530      END DO
531      IF (fabm_diag_index == -1) THEN
532         CALL ctl_warn( 'Could not find '//TRIM(diag_name)//' diagnostic' )
533      ELSE
534         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(diag_name)//' is: ', fabm_diag_index
535      ENDIF
536   
537   END FUNCTION fabm_diag_index
538
539#else
540   !!----------------------------------------------------------------------
541   !!   Dummy module                                        No FABM model
542   !!----------------------------------------------------------------------
543CONTAINS
544   SUBROUTINE nemo_fabm_init
545   END SUBROUTINE nemo_fabm_init
546
547   SUBROUTINE trc_ini_fabm            ! Empty routine
548   END SUBROUTINE trc_ini_fabm
549#endif
550
551   !!======================================================================
552END MODULE trcini_fabm
Note: See TracBrowser for help on using the repository browser.