SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
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, &
7  hprogram,hsurf,hfile,kluout,pfield)
8 ! #################################################################################
9 !
10 !!**** *PREP_ISBA_NETCDF* - prepares ISBA fields from initialization files in NETCDF
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !!
18 !! REFERENCE
19 !! ---------
20 !!
21 !!
22 !! AUTHOR
23 !! ------
24 !! M. Lafaysse
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! Original 04/2012
29 !! J.Escobar 11/2013 Add USE MODI_GET_TYPE_DIM_n
30 !!------------------------------------------------------------------
31 !
32 !
33 !
35 USE modd_surf_atm_n, ONLY : surf_atm_t
36 !
37 USE modd_prep, ONLY : cinterp_type
38 !
39 USE modi_abor1_sfx
40 USE modi_get_type_dim_n
41 !
42 USE mode_read_cdf
43 !
44 USE yomhook ,ONLY : lhook, dr_hook
45 USE parkind1 ,ONLY : jprb
46 !
47 IMPLICIT NONE
48 
49 include 'netcdf.inc'
50 !
51 !* 0.1 declarations of arguments
52 !
53 !
54 TYPE(data_cover_t), INTENT(INOUT) :: dtco
55 TYPE(surf_atm_t), INTENT(INOUT) :: u
56 !
57  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling surf. schemes
58  CHARACTER(LEN=7), INTENT(IN) :: hsurf ! type of field
59  CHARACTER(LEN=28), INTENT(IN) :: hfile ! name of file
60 INTEGER, INTENT(IN) :: kluout ! logical unit of output listing
61 REAL,DIMENSION(:,:,:), POINTER :: pfield ! field to interpolate horizontally
62 !
63 !* 0.2 declarations of local variables
64 !
65 REAL, DIMENSION(:), POINTER :: zfield ! field read
66 
67 REAL,DIMENSION(:,:),ALLOCATABLE:: zfield_2d
68 
69 ! CHARACTER(LEN=28) :: YNCVAR
70 REAL(KIND=JPRB) :: zhook_handle
71 !
72 INTEGER::ierror !error status
73 INTEGER::jj,jk,jloop ! loop counters
74 INTEGER::inlayers ! vertical dimension length
75 INTEGER::il ! nature dimension length
76 INTEGER::id_file,id_var ! Netcdf IDs for file and variable
77 INTEGER::invardims !number of dimensions of netcdf input variable
78 INTEGER,DIMENSION(:),ALLOCATABLE::ivardimsid
79 INTEGER::ilendim,ilendim1,ilendim2
80 
81 SELECT CASE (trim(hsurf))
82  CASE ('TG','WG','WGI')
83  inlayers=3 ! 3 soil layers for initialization
84  CASE default
85  CALL abor1_sfx('PREP_ISBA_NETCDF: '//trim(hsurf)//" initialization not implemented !")
86 END SELECT
87 !
88 inlayers=3
89 !
90 !------------------------------------------------------------------------------------
91 ! ---------
92 IF (lhook) CALL dr_hook('PREP_ISBA_NETCDF',0,zhook_handle)
93 
94 !* 1. get nature dimension
95 !
96  CALL get_type_dim_n(dtco, u, &
97  'NATURE',il)
98 !
99 !* 2. Reading of field
100 ! ----------------
101 
102 ! Open netcdf file
103 ierror=nf_open(hfile,nf_nowrite,id_file)
104  CALL handle_err_cdf(ierror,"can't open file "//trim(hfile))
105 
106 ! Look for variable ID
107 ierror=nf_inq_varid(id_file,trim(hsurf),id_var)
108  CALL handle_err_cdf(ierror,"can't find variable "//trim(hsurf))
109 
110 ! Number of dimensions
111 ierror=nf_inq_varndims(id_file,id_var,invardims)
112 if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions number")
113 
114 ! Id of dimensions
115 ALLOCATE(ivardimsid(invardims))
116 ierror=nf_inq_vardimid(id_file,id_var,ivardimsid)
117 if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions ids")
118 
119 ALLOCATE(zfield(il))
120 
121 SELECT CASE (invardims)
122  CASE (1)
123  ! Check dimension length
124  ierror=nf_inq_dimlen(id_file,ivardimsid(1),ilendim)
125  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
126  CASE (2)
127  ierror=nf_inq_dimlen(id_file,ivardimsid(1),ilendim1)
128  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
129  ierror=nf_inq_dimlen(id_file,ivardimsid(2),ilendim2)
130  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
131 
132  ilendim=ilendim1*ilendim2
133 
134  CASE default
135  CALL abor1_sfx('PREP_ISBA_NETCDF: incorrect number of dimensions for variable '//trim(hsurf))
136 
137 END SELECT
138 !
139 IF(ilendim/=il) CALL abor1_sfx('PREP_ISBA_NETCDF: incorrect number of points '// &
140  'in netcdf file for variable '//trim(hsurf))
141 !
142 ! Read 1D variable
143 ierror=nf_get_var_double(id_file,id_var,zfield)
144  CALL handle_err_cdf(ierror,"can't read variable "//trim(hsurf))
145 !
146 ! Close netcdf file
147 ierror=nf_close(id_file)
148 !
149 ALLOCATE(pfield(il,inlayers,1)) !will be deallocated later by prep_hor_isba_field
150 !
151 ! For now initial values are identical for all tiles / soil layers.
152 DO jj=1,inlayers
153  pfield(:,jj,1)=zfield
154 END DO
155 !
156 DEALLOCATE(zfield)
157 !
158 !Interpolation method
159  cinterp_type='NONE'
160 !
161 IF (lhook) CALL dr_hook('PREP_ISBA_NETCDF',1,zhook_handle)
162 !-------------------------------------------------------------------------------------
163 END SUBROUTINE prep_isba_netcdf
subroutine get_type_dim_n(DTCO, U, HTYPE, KDIM)
subroutine prep_isba_netcdf(DTCO, U, HPROGRAM, HSURF, HFILE, KLUOUT, PFIELD)
subroutine handle_err_cdf(status, line)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6