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