SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
read_pgd_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 read_pgd_netcdf (USS, &
7  hprogram,hscheme,hsubroutine,hfilename,hfield,pfield)
8 !#################################################################################
9 !
10 !!**** *READ_PGD_NETCDF* - read data from NETCDF files during PGD (altitude)
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 11/2012
29 !!------------------------------------------------------------------
30 !
31 
32 !
33 !
35 !
36 USE modi_abor1_sfx
37 
39 ! USE MODD_PGD_GRID, ONLY : NL ! grid dimension length
40 USE modi_pt_by_pt_treatment
41 USE modi_get_luout
42 
43 USE yomhook ,ONLY : lhook, dr_hook
44 USE parkind1 ,ONLY : jprb
45 !
46 IMPLICIT NONE
47 
48 include 'netcdf.inc'
49 !
50 !* 0.1 declarations of arguments
51 !
52 
53 !
54 TYPE(surf_atm_sso_t), INTENT(INOUT) :: uss
55 !
56  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! Type of program
57  CHARACTER(LEN=6), INTENT(IN) :: hscheme ! Scheme treated
58  CHARACTER(LEN=6), INTENT(IN) :: hsubroutine ! Name of the subroutine to call
59  CHARACTER(LEN=28), INTENT(IN) :: hfilename ! Name of the field file.
60  CHARACTER(LEN=20), INTENT(IN) :: hfield ! name of variable
61 REAL,DIMENSION(:),INTENT(OUT),OPTIONAL :: pfield ! output a variable
62 
63 REAL,DIMENSION(:),POINTER :: zlat,zlon
64 REAL,DIMENSION(:),POINTER :: zlat2d,zlon2d
65 REAL,DIMENSION(:),POINTER,SAVE :: zfield ! field to read
66 !
67 !* 0.2 declarations of local variables
68 !
69 ! CHARACTER(LEN=28) :: YNCVAR
70 !
71 INTEGER::ierror !error status
72 INTEGER::id_file ! id of netcdf file
73 INTEGER::infield,inlat,inlon ! dimension lengths
74 INTEGER::iluout
75 INTEGER::jpoint !loop counter
76 !
77 REAL(KIND=JPRB) :: zhook_handle
78 !
79 IF (lhook) CALL dr_hook('READ_PGD_NETCDF',0,zhook_handle)
80 !
81  CALL get_luout(hprogram,iluout)
82 !
83 SELECT CASE (trim(hfield))
84  CASE ('ZS','slope')
85  CASE default
86  CALL abor1_sfx('READ_PGD_NETCDF: '//trim(hfield)//" initialization not implemented !")
87 END SELECT
88 
89 !------------------------------------------------------------------------------------
90 ! ---------
91 
92 !
93 !* 2. Reading of field
94 ! ----------------
95 
96 ! Open netcdf file
97 ierror=nf_open(hfilename,nf_nowrite,id_file)
98  CALL handle_err_cdf(ierror,"can't open file "//trim(hfilename))
99 
100  CALL read_field_netcdf(id_file,'LAT ',zlat,inlat)
101  CALL read_field_netcdf(id_file,'LON ',zlon,inlon)
102  CALL read_field_netcdf(id_file,hfield,zfield,infield)
103 
104 ! Close netcdf file
105 ierror=nf_close(id_file)
106 
107 IF (present(pfield)) THEN
108 
109  DO jpoint=1,infield
110 
111 ! On pourrait faire un controle des coordonnées ?
112 ! IF ((ABS(ZLAT(JPOINT)-????XLAT???)<0.001) .AND. (ABS(ZLON(JPOINT)-????XLON???)<0.001)) THEN
113 
114  pfield(jpoint)=zfield(jpoint)
115 
116 ! END IF
117  END DO
118 
119 ELSE
120 
121  ALLOCATE(zlat2d(infield))
122  ALLOCATE(zlon2d(infield))
123 
124  IF (inlat*inlon==infield) THEN
125  CALL abor1_sfx('READ_PGD_NETCDF: 1D LAT and LON not implemented')
126  ELSEIF ((inlat==infield) .AND. (infield==inlon)) THEN
127  zlat2d(:)=zlat(:)
128  zlon2d(:)=zlon(:)
129  ELSE
130  CALL abor1_sfx('READ_PGD_NETCDF: problem with dimensions lengths between LAT LON and FIELD')
131  END IF
132 
133  DO jpoint=1,infield
134  !* 5. Call to the adequate subroutine (point by point treatment)
135  ! ----------------------------------------------------------
136  !
137  CALL pt_by_pt_treatment(uss, &
138  iluout, (/ zlat2d(jpoint)/) , (/zlon2d(jpoint)/) , (/ zfield(jpoint)/) , &
139  hsubroutine )
140 
141  ENDDO
142 
143  DEALLOCATE(zlat2d)
144  DEALLOCATE(zlon2d)
145 
146 END IF
147 
148 DEALLOCATE(zlat)
149 DEALLOCATE(zlon)
150 
151 DEALLOCATE(zfield)
152 
153 IF (lhook) CALL dr_hook('READ_PGD_NETCDF',1,zhook_handle)
154 !-------------------------------------------------------------------------------------
155 
156  CONTAINS
157 
158 SUBROUTINE read_field_netcdf(ID_FILE,HFIELD,PFIELD,ILENDIM)
159 
160 USE mode_read_cdf, ONLY :handle_err_cdf
161 
162 IMPLICIT NONE
163 
164 include 'netcdf.inc'
165 
166 INTEGER,INTENT(IN)::id_file
167  CHARACTER(LEN=20), INTENT(IN) :: hfield ! name of variable
168 REAL,DIMENSION(:),POINTER::pfield
169 
170 INTEGER::id_var ! Netcdf IDs for file and variable
171 INTEGER::invardims !number of dimensions of netcdf input variable
172 INTEGER,DIMENSION(:),ALLOCATABLE::ivardimsid
173 INTEGER::ilendim1,ilendim2
174 INTEGER,INTENT(OUT)::ilendim
175 INTEGER::ierror !error status
176 INTEGER::itype
177 
178 ! Look for variable ID for HFIELD
179 ierror=nf_inq_varid(id_file,trim(hfield),id_var)
180  CALL handle_err_cdf(ierror,"can't find variable "//trim(hfield))
181 
182 ! Number of dimensions
183 ierror=nf_inq_varndims(id_file,id_var,invardims)
184 if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions number")
185 
186 ! Id of dimensions
187 ALLOCATE(ivardimsid(invardims))
188 
189 ierror=nf_inq_vardimid(id_file,id_var,ivardimsid)
190 if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions ids")
191 
192 
193 SELECT CASE (invardims)
194  CASE (1)
195  ! Check dimension length
196  ierror=nf_inq_dimlen(id_file,ivardimsid(1),ilendim)
197  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
198 
199  CASE (2)
200  ierror=nf_inq_dimlen(id_file,ivardimsid(1),ilendim1)
201  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
202  ierror=nf_inq_dimlen(id_file,ivardimsid(2),ilendim2)
203  if (ierror/=nf_noerr) CALL handle_err_cdf(ierror,"can't get variable dimensions lengths")
204 
205  ilendim=ilendim1*ilendim2
206 
207  CASE default
208  CALL abor1_sfx('READ_PGD_NETCDF: incorrect number of dimensions for variable '//trim(hfield))
209 
210 END SELECT
211 
212 DEALLOCATE(ivardimsid)
213 
214 ! IF(ILENDIM/=NL) CALL ABOR1_SFX('READ_PGD_NETCDF: incorrect number of points &
215 ! & in netcdf file for variable '//TRIM(HFIELD))
216 
217 ALLOCATE(pfield(ilendim))
218 
219 ierror=nf_inq_vartype(id_file,id_var,itype)
220 IF (itype/=nf_double) THEN
221  CALL abor1_sfx('READ_PGD_NETCDF: incorrect type for variable '//trim(hfield))
222 END IF
223 
224 ! Read 1D variable
225 ierror=nf_get_var_double(id_file,id_var,pfield)
226 
227  CALL handle_err_cdf(ierror,"can't read variable "//trim(hfield))
228 
229 END SUBROUTINE read_field_netcdf
230 
231 
232 END SUBROUTINE read_pgd_netcdf
subroutine pt_by_pt_treatment(USS, KLUOUT, PLAT, PLON, PVALUE, HSUBROUTINE, KNBLINES, PNODATA)
subroutine handle_err_cdf(status, line)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine read_field_netcdf(ID_FILE, HFIELD, PFIELD, ILENDIM)
subroutine read_pgd_netcdf(USS, HPROGRAM, HSCHEME, HSUBROUTINE, HFILENAME, HFIELD, PFIELD)