SURFEX v8.1
General documentation of Surfex
prep_ocean_ascllv.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_ocean_ascllv (DTCO, UG, U, HPROGRAM,HSURF,HFILE, KLUOUT,PFIELD)
7 ! #################################################################################
8 !
9 !!**** *PREP_OCEAN_ASCLLDV* - prepares oceanic fields from personal data in ascii
10 !! formed as lat,lon, depth, value
11 !!
12 !! PURPOSE
13 !! -------
14 !
15 !!** METHOD
16 !! ------
17 !! Read the input file which must be ascii typed, lat,lon,depth, value
18 !! Version 1:
19 !! The data must be on the same grid as the pgd and on the same
20 !! vertical grid as prescribed in oceanvergrid.f90
21 !! NDEPTH= a definirtn nlev=NOCKMAX (modd_ocean_gridn)
22 !!
23 !! Version 2: (not done yet)
24 !! - dummy or namlist for nb verticals levels
25 !! - file prescribing the vertical grid
26 !!
27 !! REFERENCE
28 !! ---------
29 !!
30 !!
31 !! AUTHOR
32 !! ------
33 !! P. PEYRILLE
34 !!
35 !! MODIFICATIONS
36 !! -------------
37 !! Original 01/2011
38 !! J.Escobar 11/2013 Add USE MODI_ABOR1_SFX and USE MODI_GET_SURF_MASK_N
39 !!------------------------------------------------------------------
40 !
42 !
43 !
44 !
47 USE modd_surf_atm_n, ONLY : surf_atm_t
48 !
49 USE modd_prep, ONLY : cinterp_type
51 USE modd_ocean_grid , ONLY : nockmax
52 USE modd_pgdwork, ONLY : catype
53 !
54 USE modi_open_file
55 USE modi_close_file
56 USE modi_get_luout
57 USE modi_get_latlonmask_n
59 USE modi_abor1_sfx
60 USE modi_get_surf_mask_n
61 !
62 USE modi_get_type_dim_n
63 USE yomhook ,ONLY : lhook, dr_hook
64 USE parkind1 ,ONLY : jprb
65 !
66 IMPLICIT NONE
67 !
68 #ifdef SFX_MPI
69 include "mpif.h"
70 #endif
71 !
72 !* 0.1 declarations of arguments
73 !
74 !
75 TYPE(data_cover_t), INTENT(INOUT) :: DTCO
76 TYPE(surf_atm_grid_t), INTENT(INOUT) :: UG
77 TYPE(surf_atm_t), INTENT(INOUT) :: U
78 !
79  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! program calling surf. schemes
80  CHARACTER(LEN=7), INTENT(IN) :: HSURF ! type of field
81  CHARACTER(LEN=28), INTENT(IN) :: HFILE ! file name
82 INTEGER, INTENT(IN) :: KLUOUT ! output listing logical unit
83 !CHARACTER(LEN=28), INTENT(IN), OPTIONAL :: HNCVARNAME!var to read
84 REAL, POINTER, DIMENSION(:,:,:) :: PFIELD ! field to interpolate horizontally
85 !
86 !
87 !* 0.2 declarations of local variables
88 REAL,DIMENSION(:), ALLOCATABLE :: ZLAT
89 REAL,DIMENSION(:), ALLOCATABLE :: ZLON
90 REAL,DIMENSION(:), ALLOCATABLE :: ZDEPTH
91 REAL,DIMENSION(:,:,:), ALLOCATABLE :: ZFIELD
92 REAL,DIMENSION(:,:,:,:), ALLOCATABLE :: ZFIELDR
93 !
94 INTEGER, DIMENSION(0:NPROC-1) :: INB
95 !
96 INTEGER :: IL
97 INTEGER :: IGLB ! logical unit
98 INTEGER :: IDIM, ILU
99 INTEGER :: JI,JK
100 INTEGER :: INFOMPI, JJ
101 !
102 INTEGER, DIMENSION(:), POINTER :: IMASK ! mask for packing from complete field to nature field
103  CHARACTER(LEN=6) :: YMASK
104 REAL(KIND=JPRB) :: ZHOOK_HANDLE
105 
106 !-------------------------------------------------------------------------------------
107 IF (lhook) CALL dr_hook('PREP_OCEAN_ASCLLV',0,zhook_handle)
108 !
109 IF (.NOT.ALLOCATED(nnum)) THEN
110  ALLOCATE(nnum(u%NDIM_FULL))
111  IF (nrank/=npio) THEN
112  IF (ALLOCATED(nindex)) DEALLOCATE(nindex)
113  ALLOCATE(nindex(u%NDIM_FULL))
114  ENDIF
115  IF (nrank==npio) THEN
116  inb(:) = 0
117  DO jj=1,u%NDIM_FULL
118  inb(nindex(jj)) = inb(nindex(jj))+1
119  nnum(jj) = inb(nindex(jj))
120  ENDDO
121  ENDIF
122  IF (nproc>1) THEN
123 #ifdef SFX_MPI
124  CALL mpi_bcast(nindex,SIZE(nindex)*kind(nindex)/4,mpi_integer,npio,ncomm,infompi)
125  CALL mpi_bcast(nnum,SIZE(nnum)*kind(nnum)/4,mpi_integer,npio,ncomm,infompi)
126  CALL mpi_bcast(ug%NGRID_FULL_PAR,kind(ug%NGRID_FULL_PAR)/4,mpi_integer,npio,ncomm,infompi)
127 #endif
128  IF (nrank/=npio) ALLOCATE(ug%XGRID_FULL_PAR(ug%NGRID_FULL_PAR))
129 #ifdef SFX_MPI
130  CALL mpi_bcast(ug%XGRID_FULL_PAR,&
131  SIZE(ug%XGRID_FULL_PAR)*kind(ug%XGRID_FULL_PAR)/4,mpi_real,npio,ncomm,infompi)
132 #endif
133  ENDIF
134 ENDIF
135 !
136 catype = 'ARI'
137 !
138 !* 1. get full dimension of grid
139  CALL get_type_dim_n(dtco, u, 'FULL ',nl)
140 !* 2. get Ocean dimension
141 !
142  CALL get_type_dim_n(dtco, u, 'SEA ',il)
143 
144 !* 3. get grid informations known over full grid
145 !
147 !
148 !!
149 
150 WRITE(kluout,*) "==================================== "
151 WRITE(kluout,*) "Control print in prep_ocean_ascllv "
152 WRITE(kluout,*) "NL, NOCKMAX", nl,nockmax
153 
154 ALLOCATE(zlat(nl))
155 ALLOCATE(zlon(nl))
156 ALLOCATE(zdepth(nockmax))
157 
158 ALLOCATE(zfieldr(nl,nockmax,4, 1))
159 ALLOCATE(zfield(nl,nockmax, 1))
160 
161 
162 WRITE(kluout,*) "ZFIELDR",shape(zfieldr)
163 WRITE(kluout,*) "File name used in ocean ascllv", hfile
164 
165 WRITE(kluout,*) "USURF= " , hsurf
166 WRITE(kluout,*) "NL (dim)=", nl
167 WRITE(kluout,*) "IL (dim)=", il
168 !
169 !* 2. Reading of field
170 ! ----------------
171  CALL open_file(hprogram,iglb,hfile,'FORMATTED',haction='READ')
172 !
173 
174 DO ji=1,nl
175  DO jk=1,nockmax
176  READ(iglb,*,end=99) zlat(ji),zlon(ji), zdepth(jk), &
177  zfieldr(ji,jk,1,1), zfieldr(ji,jk,2,1),zfieldr(ji,jk,3,1), &
178  zfieldr(ji,jk,4,1)
179  END DO
180 END DO
181 
182 
183 
184 ! 3. Close the file
185 
186 99 CONTINUE
187  CALL close_file (hprogram,iglb)
188 
189 WRITE(kluout,*) minval(zfieldr), maxval(zfieldr)
190 
191 !
192 ! Get the correct varaibles
193 SELECT CASE (hsurf)
194  CASE('TEMP_OC')
195  zfield(:,:,1) = zfieldr(:,:,1,1)
196  CASE('SALT_OC')
197  zfield(:,:,1) = zfieldr(:,:,2,1)
198  CASE('UCUR_OC')
199  zfield(:,:,1) = zfieldr(:,:,3,1)
200  CASE('VCUR_OC')
201  zfield(:,:,1) = zfieldr(:,:,4,1)
202 END SELECT
203 
204 
205 
206 !* 3. Interpolation method
207 ! --------------------
208 !
209 cinterp_type='NONE '
210 !CINTERP_TYPE='HORIBL'
211 !
212 
213 ymask = 'SEA '
214  CALL get_type_dim_n(dtco, u, ymask,idim)
215 WRITE(kluout,*) "IDIM (dim sea) =", idim
216 
217 ALLOCATE(pfield(1:idim,1:SIZE(zfield,2),1:SIZE(zfield,3)))
218 
219 IF (idim/=SIZE(pfield,1)) THEN
220  WRITE(kluout,*)'Wrong dimension of MASK: ',idim,SIZE(pfield)
221  CALL abor1_sfx('PGD_FIELD: WRONG DIMENSION OF MASK')
222 ENDIF
223 
224 ALLOCATE(imask(idim))
225 ilu=0
226  CALL get_surf_mask_n(dtco, u, ymask,idim,imask,ilu,kluout)
227 DO jk=1,nockmax
228  CALL pack_same_rank(imask,zfield(:,jk,1),pfield(:,jk,1))
229 END DO
230 DEALLOCATE(imask)
231 
232 !* 4. Deallocations
233 ! -------------
234 !
235 IF (ALLOCATED(zlon )) DEALLOCATE(zlon )
236 IF (ALLOCATED(zlat )) DEALLOCATE(zlat )
237 IF (ALLOCATED(zdepth )) DEALLOCATE(zdepth )
238 IF (ALLOCATED(zfield )) DEALLOCATE(zfield )
239 IF (ALLOCATED(zfieldr )) DEALLOCATE(zfieldr )
240 !
241 DEALLOCATE(nnum)
242 IF (nrank/=npio) THEN
243  DEALLOCATE(nindex,ug%XGRID_FULL_PAR)
244  ALLOCATE(nindex(0))
245 ENDIF
246 !
247 IF (lhook) CALL dr_hook('PREP_OCEAN_ASCLLV',1,zhook_handle)
248 !
249 !-------------------------------------------------------------------------------------
250 END SUBROUTINE prep_ocean_ascllv
subroutine get_type_dim_n(DTCO, U, HTYPE, KDIM)
subroutine get_latlonmask_n(UG, OLATLONMASK, HGRID, PGRID_PAR, KGRID_PAR
subroutine open_file(HPROGRAM, KUNIT, HFILE, HFORM, HACTION, HACCESS, KR
Definition: open_file.F90:7
character(len=3) catype
logical, dimension(720, 360) llatlonmask
character(len=6) cinterp_type
Definition: modd_prep.F90:40
subroutine prep_ocean_ascllv(DTCO, UG, U, HPROGRAM, HSURF, HFILE, KLUOUT, PFIELD)
integer, dimension(:), allocatable nnum
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
subroutine get_surf_mask_n(DTCO, U, HTYPE, KDIM, KMASK, KLU, KLUOUT)
integer, parameter jprb
Definition: parkind1.F90:32
real, dimension(:), pointer xgrid_par
subroutine close_file(HPROGRAM, KUNIT)
Definition: close_file.F90:7
logical lhook
Definition: yomhook.F90:15
character(len=10) cgrid
integer, save nockmax
integer, dimension(:), allocatable nindex