SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
write_header_fa.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 !#############################################
7 SUBROUTINE write_header_fa (UG, &
8  cfiletype,hwrite)
9 !#############################################
10 !
11 !! PURPOSE
12 !! -------
13 !! Create and write a header for an ARPEGE FA file
14 !!
15 !! METHOD
16 !! ------
17 !!
18 !! EXTERNAL
19 !! --------
20 !!
21 !! IMPLICIT ARGUMENTS
22 !! ------------------
23 !!
24 !! REFERENCE
25 !! ---------
26 !!
27 !! AUTHOR
28 !! ------
29 !! A. Voldoire Meteo-France
30 !!
31 !! MODIFICATIONS
32 !! -------------
33 !! Original 08/2007
34 !! F. Taillefer 06/2008 : add Gauss and Conf Proj cases
35 !! B. Decharme 01/2009 : FA can be used only if NDIM_FULL >=289 in LATLON
36 !! A. Alias 10/2010 : FA header modified
37 !! R. El Khatib 30-Mar-2012 fanmsg with 2 arguments
38 !!
39 !----------------------------------------------------------------------------
40 !
41 !* 0. DECLARATION
42 ! -----------
43 !
44 !
45 !
47 !
48 USE modd_grid_conf_proj, ONLY : xlatc, xlonc
49 !
51 !
52 USE modd_csts, ONLY : xpi
53 !
57 !
58 !
59 USE yomhook ,ONLY : lhook, dr_hook
60 USE parkind1 ,ONLY : jprb
61 !
62 USE modi_abor1_sfx
63 !
64 USE modi_io_buff_clean
65 !
66 USE modi_get_luout
67 !
68 IMPLICIT NONE
69 !
70 !* 0.1 Declaration of arguments
71 ! ------------------------
72 !
73 !
74 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
75 !
76  CHARACTER(LEN=3), INTENT(IN) :: hwrite ! 'PGD' : only physiographic fields are written
77  CHARACTER(LEN=6), INTENT(IN) :: cfiletype ! 'FA' could also be 'LFI' in future developments
78 !
79 !* 0.2 Declaration of local variables
80 ! ------------------------------
81 !
82 INTEGER :: il
83 INTEGER :: ilon
84 INTEGER :: ilat
85 !
86 REAL :: zlonmin
87 REAL :: zlonmax
88 REAL :: zlatmin
89 REAL :: zlatmax
90 !
91 REAL :: zslapo
92 REAL :: zclopo
93 REAL :: zslopo
94 REAL :: zcodil
95 REAL :: zprpk
96 REAL :: zbeta
97 !
98 REAL :: zlapo
99 REAL :: zlopo
100 !
101 REAL :: zrad
102 !
103 REAL, DIMENSION(:), ALLOCATABLE :: zsinla, zahybr, zbhybr
104 !
105 REAL, DIMENSION(:), ALLOCATABLE :: zlat_xy, zdx, zdy
106 !
107 REAL, DIMENSION(0:1), PARAMETER :: zniva = (/0.,0./)
108 !
109 REAL, DIMENSION(0:1), PARAMETER :: znivb = (/0.,1./)
110 !
111 REAL, PARAMETER :: zrefer = 101325.
112 !
113 INTEGER, DIMENSION(11) :: idate
114 INTEGER, DIMENSION(:), ALLOCATABLE :: inlopa, inozpa
115 INTEGER :: ityptr
116 INTEGER :: inb ! number of articles in the file
117 INTEGER :: iret
118 INTEGER :: itronc
119 INTEGER :: inlati
120 INTEGER :: inxlon
121 INTEGER :: iwork
122 INTEGER :: icount
123 INTEGER :: jlat
124 !
125 INTEGER :: iluout
126 REAL(KIND=JPRB) :: zhook_handle
127 !
128 !----------------------------------------------------------------------------
129 !
130 IF (lhook) CALL dr_hook('WRITE_HEADER_FA',0,zhook_handle)
131 !
132 #ifdef SFX_FA
133 !
134  CALL io_buff_clean
135 !
136 zrad=xpi/180.0
137 !
138 zslapo=0.0
139 zclopo=0.0
140 zslopo=0.0
141 zcodil=0.0
142 !
143 IF (ug%CGRID=="CONF PROJ ") THEN
144 !
145  CALL get_gridtype_conf_proj(ug%XGRID_PAR,zlapo,zlopo,zprpk,zbeta, &
146  zlatmin,zlonmin,ilon,ilat )
147 !
148  icount=ilon*ilat
149  ALLOCATE(zdx(icount))
150  ALLOCATE(zdy(icount))
151 !
152  CALL get_gridtype_conf_proj(ug%XGRID_PAR,pdx=zdx,pdy=zdy)
153 !
154  ALLOCATE(zsinla(18))
155  ALLOCATE(inlopa(8))
156  ALLOCATE(inozpa((1+ilat)/2))
157 !
158  zsinla(:)=0.0
159  inlopa(:)=0
160  inozpa(:)=0
161 !
162  zsinla(1) = -1.0
163  zsinla(2) = zprpk
164  zsinla(3) = zlopo*zrad
165  zsinla(4) = zlapo*zrad
166  zsinla(5) = xlonc*zrad
167  zsinla(6) = xlatc*zrad
168  zsinla(7) = zdx(1)
169  zsinla(8) = zdy(1)
170  zsinla(13) = 0.0
171  zsinla(14) = 0.0
172 !
173  inlopa(1) = 10
174  inlopa(2) = 1
175  inlopa(3) = 1
176  inlopa(4) = ilon
177  inlopa(5) = 1
178  inlopa(6) = ilat
179  inlopa(7) = 8
180  inlopa(8) = 8
181 !
182  ityptr = -int(REAL(ilon-1)/2.)
183  itronc = int(REAL(ilat-1)/2.)
184 !
185  inlati = ilat
186  inxlon = ilon
187 !
188 ELSEIF (ug%CGRID=="CARTESIAN ") THEN
189 !
190  CALL abor1_sfx('WRITE_HEADER_FA: CARTESIAN NOT YET IMPLEMENTED')
191 !
192 ELSEIF (ug%CGRID=="LONLAT REG") THEN
193 !
194  CALL get_gridtype_lonlat_reg(ug%XGRID_PAR,zlonmin,zlonmax, &
195  zlatmin,zlatmax,ilon,ilat )
196 !
197  CALL get_luout(cfiletype,iluout)
198  il=ilon*ilat
199  IF(il<289)THEN
200  WRITE(iluout,*)' When Fa is used, NDIM_FULL must be >= 289, here NDIM_FULL = ',il
201  CALL abor1_sfx(' WRITE_HEADER_FA: LONLAT REG, With Fa, NDIM_FULL must be >= 289')
202  ENDIF
203 !
204  ALLOCATE(zsinla(18))
205  ALLOCATE(inlopa(8))
206  ALLOCATE(inozpa((1+ilat)/2))
207 !
208  itronc= min(int((REAL(ilat-2)/2.0)),21)
209  ityptr=-min(int((REAL(ilon-2)/2.0)),21)
210  inlati=ilat
211  inxlon=ilon
212 !
213  zsinla(:)=0.
214  inlopa(:)=0
215  inozpa(:)=0
216 !
217  zsinla(1) =-1.
218  zsinla(2) =-9.
219  zsinla(5) =(zlonmin+(zlonmax-zlonmin)/2.)*zrad
220  zsinla(6) =(zlatmin+(zlatmax-zlatmin)/2.)*zrad
221  zsinla(7) =((zlonmax-zlonmin)/REAL(ilon))*zrad
222  zsinla(8) =((zlatmax-zlatmin)/REAL(ilat))*zrad
223  zsinla(9) =(zlonmax-zlonmin)*zrad
224  zsinla(10)=(zlatmax-zlatmin)*zrad
225  zsinla(13)=zlonmin*zrad
226  zsinla(14)=zlatmin*zrad
227  zsinla(15)=zlonmax*zrad
228  zsinla(16)=zlatmax*zrad
229 !
230  inlopa(1) = 10
231  inlopa(2) = -1
232  inlopa(3) = 1
233  inlopa(4) = ilon
234  inlopa(5) = 1
235  inlopa(6) = ilat
236  inlopa(7) = 8
237  inlopa(8) = 8
238 !
239 ELSEIF (ug%CGRID=="GAUSS ") THEN
240 !
241  CALL get_gridtype_gauss(ug%XGRID_PAR,knlati=inlati,kl=il)
242 !
243  ALLOCATE(inlopa(inlati))
244  ALLOCATE(zsinla(inlati))
245  ALLOCATE(inozpa(inlati))
246 !
247  ALLOCATE(zlat_xy(il))
248 !
249  CALL get_gridtype_gauss(ug%XGRID_PAR,plapo=zlapo,plopo=zlopo, &
250  pcodil=zcodil,knlopa=inlopa,plat_xy=zlat_xy )
251 !
252 ! voir plus tard si ce parametre n'est pas deja dans un module !
253  IF (zlapo>89.99 .AND. abs(zlopo)<0.00001) THEN
254  ityptr=1
255  ELSE
256  ityptr=2
257  ENDIF
258 !
259  zslapo=sin(zlapo*zrad)
260  zclopo=cos(zlopo*zrad)
261  zslopo=sin(zlopo*zrad)
262 !
263  iwork = int(REAL(inlati)/2.0)
264  inxlon=inlopa(iwork)
265 !
266  IF (ityptr==1) THEN
267  itronc=int(REAL(inxlon-1)/2.)
268  ELSE
269  itronc=int(REAL(inxlon-3)/2.)
270  ENDIF
271 !
272  inozpa(:)=0
273 !
274  icount=1
275  DO jlat = 1,inlati
276  zsinla(jlat)=sin(zlat_xy(icount)*zrad)
277  icount=icount+inlopa(jlat)
278  ENDDO
279 !
280  DEALLOCATE(zlat_xy)
281 !
282 ELSEIF (ug%CGRID=="IGN ") THEN
283 !
284  CALL abor1_sfx('WRITE_HEADER_FA: IGN NOT YET IMPLEMENTED')
285 !
286 ELSEIF (ug%CGRID=="LONLATVAL ") THEN
287 !
288  CALL abor1_sfx('WRITE_HEADER_FA: LONLATVAL NOT YET IMPLEMENTED')
289 !
290 END IF
291 !
292 ALLOCATE(zahybr(0:1))
293 ALLOCATE(zbhybr(0:1))
294 zahybr(0:1)=zniva(0:1)
295 zbhybr(0:1)=znivb(0:1)
296 !
297 ! Reduce verbosity (in case it is not already done)
298  CALL fanmsg(0,nluout)
299  CALL facade(cdnomc,ityptr,zslapo,zclopo,zslopo,zcodil,itronc,inlati,inxlon, &
300  inlopa,inozpa,zsinla,1,zrefer,zahybr,zbhybr,.true.)
301 !
302  CALL faitou(iret,nunit_fa,.true.,cfileout_fa,'UNKNOWN', &
303  .true.,.false.,iverbfa,0,inb,cdnomc)
304 !
305 idate(:)=0
306 idate(1)=1992
307 idate(2)=1
308 idate(3)=1
309 idate(6)=1
310  CALL fandar(iret,nunit_fa,idate)
311 !
312 DEALLOCATE(zsinla)
313 DEALLOCATE(inlopa)
314 DEALLOCATE(inozpa)
315 !
316 DEALLOCATE(zahybr)
317 DEALLOCATE(zbhybr)
318 !
319 #endif
320 !
321 IF (lhook) CALL dr_hook('WRITE_HEADER_FA',1,zhook_handle)
322 !
323 END SUBROUTINE write_header_fa
subroutine get_gridtype_gauss(PGRID_PAR, KNLATI, PLAPO, PLOPO, PCODIL, KNLOPA, KL, PLAT, PLON, PLAT_XY, PLON_XY, PMESH_SIZE, PLONINF, PLATINF, PLONSUP, PLATSUP)
subroutine write_header_fa(UG, CFILETYPE, HWRITE)
subroutine io_buff_clean
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine get_gridtype_conf_proj(PGRID_PAR, PLAT0, PLON0, PRPK, PBETA, PLATOR, PLONOR, KIMAX, KJMAX, PX, PY, PDX, PDY, KL)
subroutine get_gridtype_lonlat_reg(PGRID_PAR, PLONMIN, PLONMAX, PLATMIN, PLATMAX, KLON, KLAT, KL, PLON, PLAT)