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

Last change on this file since 13459 was 13459, checked in by dford, 7 months ago

Fix for getting SWR.

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_swr   = fabm_diag_index( 'light_swr_abs' )
137      jp_fabm_pgrow = fabm_diag_index( 'p_grow_sum_result' )
138      jp_fabm_ploss = fabm_diag_index( 'p_loss_sum_result' )
139
140      IF (lwp) THEN
141         ! write field_def_fabm.xml on lead process
142         OPEN(UNIT=xml_unit, FILE='field_def_fabm.xml', ACTION='WRITE', STATUS='REPLACE')
143
144         WRITE (xml_unit,1000) '<field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" >'
145
146         WRITE (xml_unit,1000) ' <field_group id="ptrc_T" grid_ref="grid_T_3D">'
147         DO jn=1,jp_fabm
148            CALL write_variable_xml(xml_unit,model%interior_state_variables(jn))
149#if defined key_trdtrc
150            CALL write_trends_xml(xml_unit,model%interior_state_variables(jn))
151#endif
152            CALL write_25hourm_xml(xml_unit,model%interior_state_variables(jn))
153            CALL write_tmb_xml(xml_unit,model%interior_state_variables(jn))
154         END DO
155         WRITE (xml_unit,1000) ' </field_group>'
156
157         WRITE (xml_unit,1000) ' <field_group id="sf_T" grid_ref="grid_T_2D">'
158         DO jn=1,jp_fabm_surface
159            CALL write_variable_xml(xml_unit,model%surface_state_variables(jn))
160            CALL write_25hourm_xml(xml_unit,model%surface_state_variables(jn))
161         END DO
162         DO jn=1,jp_fabm_bottom
163            CALL write_variable_xml(xml_unit,model%bottom_state_variables(jn))
164            CALL write_25hourm_xml(xml_unit,model%bottom_state_variables(jn))
165         END DO
166         WRITE (xml_unit,1000) ' </field_group>'
167
168         WRITE (xml_unit,1000) ' <field_group id="diad_T" grid_ref="grid_T_2D">'
169         DO jn=1,size(model%interior_diagnostic_variables)
170            CALL write_variable_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
171            CALL write_25hourm_xml(xml_unit,model%interior_diagnostic_variables(jn),3)
172            CALL write_tmb_xml(xml_unit,model%interior_diagnostic_variables(jn))
173         END DO
174         DO jn=1,size(model%horizontal_diagnostic_variables)
175            CALL write_variable_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
176            CALL write_25hourm_xml(xml_unit,model%horizontal_diagnostic_variables(jn))
177         END DO
178         DO jn=1,size(model%interior_state_variables)
179            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_state_variables(jn)%name)// &
180               &                   '_VINT" long_name="depth-integrated '//TRIM(model%interior_state_variables(jn)%long_name)// &
181               &                   '" unit="'//TRIM(model%interior_state_variables(jn)%units)//'*m" default_value="0.0" />'
182         END DO
183         DO jn=1,size(model%interior_diagnostic_variables)
184            WRITE (xml_unit,'(A)') '  <field id="'//TRIM(model%interior_diagnostic_variables(jn)%name)// &
185               &                   '_VINT" long_name="depth-integrated '//TRIM(model%interior_diagnostic_variables(jn)%long_name)// &
186               &                   '" unit="'//TRIM(model%interior_diagnostic_variables(jn)%units)//'*m" default_value="0.0" />'
187         END DO
188         WRITE (xml_unit,1000) ' </field_group>'
189
190         WRITE (xml_unit,1000) ' <field_group id="fabm_scalar" grid_ref="grid_0">'
191         DO jn=1,size(model%conserved_quantities)
192            CALL write_variable_xml(xml_unit,model%conserved_quantities(jn))
193         END DO
194         WRITE (xml_unit,1000) ' </field_group>'
195
196         WRITE (xml_unit,1000) ' <field_group id="fabm_input" grid_ref="grid_T_2D">'
197         input_data => first_input_data
198         DO WHILE (ASSOCIATED(input_data))
199           input_pointer => input_data
200           CALL write_input_xml(xml_unit,input_pointer)
201            input_data => input_data%next
202         END DO
203         river_data => first_river_data
204         DO WHILE (ASSOCIATED(river_data))
205           input_pointer => river_data
206           CALL write_input_xml(xml_unit,input_pointer,3)
207            river_data => river_data%next
208         END DO
209         WRITE (xml_unit,1000) ' </field_group>'
210
211         WRITE (xml_unit,1000) '</field_definition>'
212
213         CLOSE(xml_unit)
214      END IF
215      IF( lk_mpp )   CALL mppsync !Ensure field_def_fabm is ready.
216
2171000 FORMAT (A)
218
219   END SUBROUTINE nemo_fabm_configure
220
221   SUBROUTINE write_variable_xml(xml_unit,variable,flag_grid_ref)
222      INTEGER,INTENT(IN) :: xml_unit
223      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
224      CLASS (type_fabm_variable),INTENT(IN) :: variable
225
226      CHARACTER(LEN=20) :: missing_value,string_dimensions
227      INTEGER :: number_dimensions
228
229      ! Check variable dimension for grid_ref specificaiton.
230      ! Default is to not specify the grid_ref in the field definition.
231      IF (present(flag_grid_ref)) THEN
232          number_dimensions=flag_grid_ref
233      ELSE
234          number_dimensions=-1 !default, don't specify grid_ref
235      ENDIF
236
237      WRITE (missing_value,'(E9.3)') variable%missing_value
238      WRITE (string_dimensions,'(I1)') number_dimensions
239      SELECT CASE (number_dimensions)
240      CASE (3)
241         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" />'
242      CASE (2)
243         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"/>'
244      CASE (0)
245         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"/>'
246      CASE (-1)
247         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))//'" />'
248      CASE default
249         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!!!'
250      END SELECT
251
252   END SUBROUTINE write_variable_xml
253
254   SUBROUTINE write_25hourm_xml(xml_unit,variable,flag_grid_ref)
255      INTEGER,INTENT(IN) :: xml_unit
256      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
257      CLASS (type_fabm_variable),INTENT(IN) :: variable
258
259      CHARACTER(LEN=20) :: missing_value,string_dimensions
260      INTEGER :: number_dimensions
261
262      ! Check variable dimension for grid_ref specificaiton.
263      ! Default is to not specify the grid_ref in the field definition.
264      IF (present(flag_grid_ref)) THEN
265          number_dimensions=flag_grid_ref
266      ELSE
267          number_dimensions=-1 !default, don't specify grid_ref
268      ENDIF
269
270      WRITE (missing_value,'(E9.3)') 1.e+20
271      WRITE (string_dimensions,'(I1)') number_dimensions
272      SELECT CASE (number_dimensions)
273      CASE (3)
274         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" />'
275      CASE (2)
276         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"/>'
277      CASE (0)
278         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"/>'
279      CASE (-1)
280         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))//'" />'
281      CASE default
282         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!!!'
283      END SELECT
284
285   END SUBROUTINE write_25hourm_xml
286
287   SUBROUTINE write_tmb_xml(xml_unit,variable)
288      INTEGER,INTENT(IN) :: xml_unit
289      CLASS (type_fabm_variable),INTENT(IN) :: variable
290
291      CHARACTER(LEN=20) :: missing_value
292
293      WRITE (missing_value,'(E9.3)') 1.e+20
294      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"/>'
295      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"/>'
296      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"/>'
297
298   END SUBROUTINE write_tmb_xml
299
300   SUBROUTINE write_trends_xml(xml_unit,variable,flag_grid_ref)
301      INTEGER,INTENT(IN) :: xml_unit
302      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
303      CLASS (type_fabm_variable),INTENT(IN) :: variable
304
305      INTEGER :: number_dimensions,i
306      CHARACTER(LEN=20) :: missing_value,string_dimensions
307#if defined key_tracer_budget
308      CHARACTER(LEN=3),DIMENSION(10),PARAMETER :: trd_tags = (/ &
309        'LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
310        'RDB','RDN','VMV' /)
311      CHARACTER(LEN=3),DIMENSION(3),PARAMETER :: trd_e3t_tags = (/ &
312        'XAD','YAD','ZAD' /)
313#else
314      CHARACTER(LEN=3),DIMENSION(13),PARAMETER :: trd_tags = (/ &
315        'XAD','YAD','ZAD','LDF','BBL','FOR','ZDF','DMP','SMS','ATF', &
316        'RDB','RDN','VMV' /)
317#endif
318
319      ! Check variable dimension for grid_ref specificaiton.
320      ! Default is to not specify the grid_ref in the field definition.
321      IF (present(flag_grid_ref)) THEN
322          number_dimensions=flag_grid_ref
323      ELSE
324          number_dimensions=-1 !default, don't specify grid_ref
325      ENDIF
326
327      WRITE (missing_value,'(E9.3)') -2.E20
328      WRITE (string_dimensions,'(I1)') number_dimensions
329      SELECT CASE (number_dimensions)
330      CASE (3)
331        DO i=1,size(trd_tags)
332         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'// &
333            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//            &
334            &                   TRIM(variable%units)//'/s" default_value="'//                                   &
335            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
336        END DO
337#if defined key_tracer_budget
338        DO i=1,size(trd_e3t_tags)
339         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
340            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
341            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
342            &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
343        END DO
344        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
345           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'/s" default_value="'//       &
346           &                   TRIM(ADJUSTL(missing_value))//'" grid_ref="grid_T_3D" />'
347#endif
348      CASE (-1)
349        DO i=1,size(trd_tags)
350         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_tags(i))//'_'//TRIM(variable%name)//'" long_name="'//   &
351            &                   TRIM(variable%long_name)//' '//TRIM(trd_tags(i))//' trend" unit="'//              &
352            &                   TRIM(variable%units)//'/s" default_value="'//TRIM(ADJUSTL(missing_value))//'" />'
353        END DO
354#if defined key_tracer_budget
355        DO i=1,size(trd_e3t_tags)
356         WRITE (xml_unit,'(A)') '  <field id="'//TRIM(trd_e3t_tags(i))//'_'//TRIM(variable%name)//                     &
357            &                   '_e3t" long_name="'//TRIM(variable%long_name)//' cell depth integrated '//             &
358            &                   TRIM(trd_e3t_tags(i))//' trend" unit="'//TRIM(variable%units)//'/s" default_value="'// &
359            &                   TRIM(ADJUSTL(missing_value))//'" />'
360        END DO
361        WRITE (xml_unit,'(A)') '  <field id="'//TRIM(variable%name)//'_e3t" long_name="'//TRIM(variable%long_name)// &
362           &                   ' cell depth integrated" unit="'//TRIM(variable%units)//'/s" default_value="'//       &
363           &                   TRIM(ADJUSTL(missing_value))//'" />'
364#endif
365      CASE default
366         IF(lwp) WRITE(numout,*) ' trc_ini_fabm: Failing to initialise trends of variable '//TRIM(variable%name)// &
367            &                    ': Output of '//TRIM(ADJUSTL(string_dimensions))//'-dimensional trends not supported!!!'
368      END SELECT
369
370   END SUBROUTINE write_trends_xml
371
372   SUBROUTINE write_input_xml(xml_unit,variable,flag_grid_ref)
373      INTEGER,INTENT(IN) :: xml_unit
374      INTEGER,INTENT(IN),OPTIONAL :: flag_grid_ref
375      CLASS(type_input_variable),POINTER,INTENT(IN) :: variable
376
377      INTEGER :: number_dimensions,i
378      CHARACTER(LEN=20) :: missing_value,string_dimensions
379
380      ! Check variable dimension for grid_ref specificaiton.
381      ! Default is to not specify the grid_ref in the field definition.
382      IF (present(flag_grid_ref)) THEN
383          number_dimensions=flag_grid_ref
384      ELSE
385          number_dimensions=-1 !default, don't specify grid_ref
386      ENDIF
387
388      WRITE (missing_value,'(E9.3)') -2.E20
389      WRITE (string_dimensions,'(I1)') number_dimensions
390      SELECT CASE (number_dimensions)
391      CASE (3)
392        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" />'
393      CASE (-1)
394        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))//'" />'
395      CASE default
396         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!!!'
397      END SELECT
398
399   END SUBROUTINE write_input_xml
400
401   SUBROUTINE trc_ini_fabm
402      !!----------------------------------------------------------------------
403      !!                     ***  trc_ini_fabm  ***
404      !!
405      !! ** Purpose :   initialization for FABM model
406      !!
407      !! ** Method  : - Allocate FABM arrays, configure domain, send data
408      !!----------------------------------------------------------------------
409#if defined key_git_version
410      TYPE (type_version), POINTER :: version
411#endif
412      INTEGER :: jn
413
414      IF(lwp) WRITE(numout,*)
415      IF(lwp) WRITE(numout,*) ' trc_ini_fabm: initialisation of FABM model'
416      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
417#if defined key_git_version
418      IF(lwp) WRITE(numout,*) ' NEMO version:   ',git_commit_id,' (',git_branch_name,' branch)'
419      IF(lwp) WRITE(numout,*) ' FABM version:   ',fabm_commit_id,' (',fabm_branch_name,' branch)'
420      version => first_module_version
421      do while (associated(version))
422         IF(lwp) WRITE(numout,*)  ' '//trim(version%module_name)//' version:   ',trim(version%version_string)
423         version => version%next
424      end do
425#endif
426
427      ! Allocate FABM arrays
428      IF(trc_sms_fabm_alloc() /= 0) CALL ctl_stop( 'STOP', 'trc_ini_fabm: unable to allocate FABM arrays' )
429
430      ! Log mapping of FABM states:
431      IF (lwp) THEN
432         IF (jp_fabm > 0) WRITE(numout,*) " FABM tracers:"
433         DO jn=1,jp_fabm
434            WRITE(numout,*) "   State",jn,":",trim(model%interior_state_variables(jn)%name), &
435               " (",trim(model%interior_state_variables(jn)%long_name), &
436               ") [",trim(model%interior_state_variables(jn)%units),"]"
437         END DO
438         IF (jp_fabm_surface > 0) WRITE(numout,*) "FABM seasurface states:"
439         DO jn=1,jp_fabm_surface
440            WRITE(numout,*) "   State",jn,":",trim(model%surface_state_variables(jn)%name), &
441               " (",trim(model%surface_state_variables(jn)%long_name), &
442               ") [",trim(model%surface_state_variables(jn)%units),"]"
443         END DO
444         IF (jp_fabm_bottom > 0) WRITE(numout,*) "FABM seafloor states:"
445         DO jn=1,jp_fabm_bottom
446            WRITE(numout,*) "   State",jn,":",trim(model%bottom_state_variables(jn)%name), &
447               " (",trim(model%bottom_state_variables(jn)%long_name), &
448               ") [",trim(model%bottom_state_variables(jn)%units),"]"
449         END DO
450      END IF
451     
452      ! Initialise variables required for Hemmings et al. (2008)
453      ! nitrogen balancing for chlorophyll data assimilation
454      MLD_MAX(:,:)   = 0.0
455      PGROW_AVG(:,:) = 0.0
456      PLOSS_AVG(:,:) = 0.0
457      PHYT_AVG(:,:)  = 0.0
458
459   END SUBROUTINE trc_ini_fabm
460
461   SUBROUTINE nemo_fabm_driver_fatal_error(self, location, message)
462      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
463      CHARACTER(len=*),              INTENT(IN)    :: location, message
464
465      CALL ctl_stop('STOP', TRIM(location)//': '//TRIM(message))
466      STOP
467   END SUBROUTINE
468
469   SUBROUTINE nemo_fabm_driver_log_message(self, message)
470      CLASS (type_nemo_fabm_driver), INTENT(INOUT) :: self
471      CHARACTER(len=*),              INTENT(IN)    :: message
472
473      IF(lwp) WRITE (numout,*) TRIM(message)
474   END SUBROUTINE
475
476   INTEGER FUNCTION fabm_state_index( state_name )
477      !!----------------------------------------------------------------------
478      !!                     ***  fabm_state_index  *** 
479      !!
480      !! ** Purpose :   return index of a given FABM state variable
481      !!
482      !! ** Method  : - loop through state variables until found
483      !!----------------------------------------------------------------------
484     
485      IMPLICIT NONE
486     
487      CHARACTER(LEN=*), INTENT(IN) :: state_name
488     
489      INTEGER                      :: jn
490
491      !!----------------------------------------------------------------------
492     
493      fabm_state_index = -1
494      DO jn=1,jp_fabm
495         IF (TRIM(model%interior_state_variables(jn)%name) == TRIM(state_name)) THEN
496            fabm_state_index = jn
497            EXIT
498         ENDIF
499      END DO
500      IF (fabm_state_index == -1) THEN
501         CALL ctl_warn( 'Could not find '//TRIM(state_name)//' state variable' )
502      ELSE
503         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(state_name)//' is: ', fabm_state_index
504      ENDIF
505   
506   END FUNCTION fabm_state_index
507
508   INTEGER FUNCTION fabm_diag_index( diag_name )
509      !!----------------------------------------------------------------------
510      !!                     ***  fabm_state_index  *** 
511      !!
512      !! ** Purpose :   return index of a given FABM diagnostic variable
513      !!
514      !! ** Method  : - loop through diagnostic variables until found
515      !!----------------------------------------------------------------------
516     
517      IMPLICIT NONE
518     
519      CHARACTER(LEN=*), INTENT(IN) :: diag_name
520     
521      INTEGER                      :: jn
522
523      !!----------------------------------------------------------------------
524     
525      fabm_diag_index = -1
526      DO jn = 1, SIZE(model%interior_diagnostic_variables)
527         IF (TRIM(model%interior_diagnostic_variables(jn)%name) == TRIM(diag_name)) THEN
528            fabm_diag_index = jn
529            EXIT
530         ENDIF
531      END DO
532      IF (fabm_diag_index == -1) THEN
533         CALL ctl_warn( 'Could not find '//TRIM(diag_name)//' diagnostic' )
534      ELSE
535         IF (lwp) WRITE(numout,*) 'Index for '//TRIM(diag_name)//' is: ', fabm_diag_index
536      ENDIF
537   
538   END FUNCTION fabm_diag_index
539
540#else
541   !!----------------------------------------------------------------------
542   !!   Dummy module                                        No FABM model
543   !!----------------------------------------------------------------------
544CONTAINS
545   SUBROUTINE nemo_fabm_init
546   END SUBROUTINE nemo_fabm_init
547
548   SUBROUTINE trc_ini_fabm            ! Empty routine
549   END SUBROUTINE trc_ini_fabm
550#endif
551
552   !!======================================================================
553END MODULE trcini_fabm
Note: See TracBrowser for help on using the repository browser.