SURFEX v8.1
General documentation of Surfex
prep_isba_netcdf.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6 SUBROUTINE prep_isba_netcdf (DTCO, U, HPROGRAM,HSURF,HFILE,KLUOUT,PFIELD)
7 ! #################################################################################
8 !
9 !!**** *PREP_ISBA_NETCDF* - prepares ISBA fields from initialization files in NETCDF
10 !!
11 !! PURPOSE
12 !! -------
13 !
14 !!** METHOD
15 !! ------
16 !!
17 !! REFERENCE
18 !! ---------
19 !!
20 !!
21 !! AUTHOR
22 !! ------
23 !! M. Lafaysse
24 !!
25 !! MODIFICATIONS
26 !! -------------
27 !! Original 04/2012
28 !! J.Escobar 11/2013 Add USE MODI_GET_TYPE_DIM_n
29 !!------------------------------------------------------------------
30 !
31 !
32 !
34 USE modd_surf_atm_n, ONLY : surf_atm_t
35 !
36 USE modd_surf_par, ONLY : xundef
37 USE modd_surfex_mpi, ONLY : nrank, npio
38 USE modd_prep, ONLY : cinterp_type
39 !
40 USE modi_abor1_sfx
41 USE modi_get_type_dim_n
44 !
45 USE mode_read_cdf
46 !
47 USE yomhook ,ONLY : lhook, dr_hook
48 USE parkind1 ,ONLY : jprb
49 !
50 USE netcdf
51 !
52 IMPLICIT NONE
53 
54 !
55 !* 0.1 declarations of arguments
56 !
57 !
58 TYPE(data_cover_t), INTENT(INOUT) :: DTCO
59 TYPE(surf_atm_t), INTENT(INOUT) :: U
60 !
61  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! program calling surf. schemes
62  CHARACTER(LEN=7), INTENT(IN) :: HSURF ! type of field
63  CHARACTER(LEN=28), INTENT(IN) :: HFILE ! name of file
64 INTEGER, INTENT(IN) :: KLUOUT ! logical unit of output listing
65 REAL,DIMENSION(:,:,:), POINTER :: PFIELD ! field to interpolate horizontally
66 !
67 !* 0.2 declarations of local variables
68 !
69 REAL, DIMENSION(:), ALLOCATABLE :: ZNATURE
70 REAL, DIMENSION(:), ALLOCATABLE :: ZFIELD, ZFIELD0 ! field read
71 
72 ! CHARACTER(LEN=28) :: YNCVAR
73 REAL(KIND=JPRB) :: ZHOOK_HANDLE
74 !
75 INTEGER :: JI, ICPT
76 INTEGER::IERROR !error status
77 INTEGER::JJ,JK,JLOOP ! loop counters
78 INTEGER::INLAYERS ! vertical dimension length
79 INTEGER::IL ! nature dimension length
80 INTEGER::ID_FILE,ID_VAR ! Netcdf IDs for file and variable
81 INTEGER::INVARDIMS !number of dimensions of netcdf input variable
82 INTEGER,DIMENSION(:),ALLOCATABLE::IVARDIMSID
83 INTEGER::ILENDIM,ILENDIM1,ILENDIM2
84 
85 SELECT CASE (trim(hsurf))
86  CASE ('TG','WG','WGI')
87  inlayers=3 ! 3 soil layers for initialization
88  CASE DEFAULT
89  CALL abor1_sfx('PREP_ISBA_NETCDF: '//trim(hsurf)//" initialization not implemented !")
90 END SELECT
91 !
92 inlayers=3
93 !
94 !------------------------------------------------------------------------------------
95 ! ---------
96 IF (lhook) CALL dr_hook('PREP_ISBA_NETCDF',0,zhook_handle)
97 
98 !* 1. get nature dimension
99 !
100  CALL get_type_dim_n(dtco, u, 'NATURE',il)
101 !
102 !* 2. Reading of field
103 ! ----------------
104 !
105 IF (nrank==npio) THEN
106  ! Open netcdf file
107  ierror=nf90_open(hfile,nf90_nowrite,id_file)
108  CALL handle_err_cdf(ierror,"can't open file "//trim(hfile))
109 
110  ! Look for variable ID
111  ierror=nf90_inq_varid(id_file,trim(hsurf),id_var)
112  CALL handle_err_cdf(ierror,"can't find variable "//trim(hsurf))
113 
114  ! Number of dimensions
115  ierror=nf90_inquire_variable(id_file,id_var,ndims=invardims)
116  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions number")
117  ! Id of dimensions
118  ALLOCATE(ivardimsid(invardims))
119  ierror=nf90_inquire_variable(id_file,id_var,dimids=ivardimsid)
120  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions ids")
121 
122  ALLOCATE(zfield(u%NDIM_NATURE))
123 
124  SELECT CASE (invardims)
125  CASE (1)
126  ! Check dimension length
127  ierror=nf90_inquire_dimension(id_file,ivardimsid(1),len=ilendim)
128  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
129  CASE (2)
130  ierror=nf90_inquire_dimension(id_file,ivardimsid(1),len=ilendim1)
131  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
132  ierror=nf90_inquire_dimension(id_file,ivardimsid(2),len=ilendim2)
133  if (ierror/=nf90_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
134 
135  ilendim=ilendim1*ilendim2
136 
137  CASE DEFAULT
138  CALL abor1_sfx('PREP_ISBA_NETCDF: incorrect number of dimensions for variable '//trim(hsurf))
139 
140  END SELECT
141  !
142  IF(ilendim/=u%NDIM_NATURE) CALL abor1_sfx('PREP_ISBA_NETCDF: incorrect number of points '// &
143  'in netcdf file for variable '//trim(hsurf))
144  !
145  ! Read 1D variable
146  ierror=nf90_get_var(id_file,id_var,zfield)
147  CALL handle_err_cdf(ierror,"can't read variable "//trim(hsurf))
148  !
149  ! Close netcdf file
150  ierror=nf90_close(id_file)
151  !
152 ELSE
153  ALLOCATE(zfield(0))
154 ENDIF
155 !
156 IF (nrank==npio) THEN
157  ALLOCATE(znature(u%NDIM_FULL))
158 ELSE
159  ALLOCATE(znature(0))
160 ENDIF
161  CALL gather_and_write_mpi(u%XNATURE,znature)
162 !
163 IF (nrank==npio) THEN
164  ALLOCATE(zfield0(u%NDIM_FULL))
165  zfield0(:) = xundef
166  icpt = 0
167  DO ji=1,u%NDIM_FULL
168  IF (znature(ji)/=0.) THEN
169  icpt = icpt + 1
170  zfield0(ji) = zfield(icpt)
171  ENDIF
172  ENDDO
173 ELSE
174  ALLOCATE(zfield0(0))
175 ENDIF
176 !
177 DEALLOCATE(znature,zfield)
178 ALLOCATE(pfield(il,inlayers,1)) !will be deallocated later by prep_hor_isba_field
179 !
180  CALL read_and_send_mpi(zfield0,pfield(:,1,1),u%NR_NATURE)
181 !
182 ! For now initial values are identical for all tiles / soil layers.
183 DO jj=2,inlayers
184  pfield(:,jj,1)=pfield(:,1,1)
185 END DO
186 !
187 DEALLOCATE(zfield0)
188 !
189 !Interpolation method
190 cinterp_type='NONE'
191 !
192 IF (lhook) CALL dr_hook('PREP_ISBA_NETCDF',1,zhook_handle)
193 !-------------------------------------------------------------------------------------
194 END SUBROUTINE prep_isba_netcdf
subroutine get_type_dim_n(DTCO, U, HTYPE, KDIM)
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
subroutine prep_isba_netcdf(DTCO, U, HPROGRAM, HSURF, HFILE, KLUOUT, PFIELD)
subroutine handle_err_cdf(status, line)
character(len=6) cinterp_type
Definition: modd_prep.F90:40
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
logical lhook
Definition: yomhook.F90:15