source: branches/UKMO/AMM15_v3_6_STABLE_package_collate_utils305/NEMOGCM/NEMO/TOP_SRC/FABM/trcini_fabm.F90 @ 11979

Last change on this file since 11979 was 11979, checked in by dford, 10 months ago

Bug fixes: update indexing, and initialise arrays after allocation.

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