source: branches/UKMO/AMM15_v3_6_STABLE_package_collate/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90 @ 10728

Last change on this file since 10728 was 10728, checked in by dford, 19 months ago

Changes for assimilation of biogeochemical variables. See https://code.metoffice.gov.uk/trac/utils/ticket/174.

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