SURFEX v8.1
General documentation of Surfex
readhead.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 readhead(KGLB,PGLBLATMIN,PGLBLATMAX,PGLBLONMIN,PGLBLONMAX,&
7  KNBLAT,KNBLON,PCUTVAL,PDLAT,PDLON,PLAT,PLON,KERR,KFACT,&
8  OCOMPRESS)
9 ! ################################################################
10 !
11 !!**** *READHEAD* writes the head a the local 'latlon' file.
12 !!
13 !! PURPOSE
14 !! -------
15 !!
16 !! METHOD
17 !! ------
18 !!
19 !! A header of a data set is of the form:
20 !!
21 !! 1 line of comment
22 !! nodata: -999
23 !! north: 90N (or S or nothing)
24 !! south: 50N (or S or nothing)
25 !! east: 90W (or E or nothing)
26 !! west: 110W (or E or nothing)
27 !! rows: 180
28 !! cols: 60
29 !!
30 !! EXTERNAL
31 !! --------
32 !!
33 !!
34 !! IMPLICIT ARGUMENTS
35 !! ------------------
36 !!
37 !!
38 !! REFERENCE
39 !! ---------
40 !!
41 !! AUTHOR
42 !! ------
43 !!
44 !! V. Masson Meteo-France
45 !!
46 !! MODIFICATION
47 !! ------------
48 !!
49 !! Original 29/08/95
50 !! J.Escobar 06/2013 for REAL4/8 add EPSILON management
51 !!
52 !----------------------------------------------------------------------------
53 !
54 !* 0. DECLARATION
55 ! -----------
56 !
57 !
58 USE yomhook ,ONLY : lhook, dr_hook
59 USE parkind1 ,ONLY : jprb
60 USE modd_csts ,ONLY : xsurf_epsilon
61 !
62 IMPLICIT NONE
63 !
64 !* 0.1 Declaration of arguments
65 ! ------------------------
66 !
67 INTEGER, INTENT(IN) :: KGLB ! logical unit of the file
68 REAL, INTENT(OUT) :: PGLBLATMIN ! min latitude of the file.
69 REAL, INTENT(OUT) :: PGLBLATMAX ! max latitude of the file.
70 REAL, INTENT(OUT) :: PGLBLONMIN ! min longitude of the file.
71 REAL, INTENT(OUT) :: PGLBLONMAX ! min longitude of the file.
72 INTEGER, INTENT(OUT) :: KNBLAT ! number of latitude rows in file
73 INTEGER, INTENT(OUT) :: KNBLON ! number of longitude rows in file
74 REAL, INTENT(OUT) :: PCUTVAL ! special value in data file
75 REAL, INTENT(OUT) :: PDLAT ! latitude mesh in the data file
76 REAL, INTENT(OUT) :: PDLON ! longitude mesh in the data file
77 REAL, DIMENSION(:), POINTER :: PLAT ! latitude of data points
78 REAL, DIMENSION(:), POINTER :: PLON ! longitude of data points
79 INTEGER, INTENT(OUT) :: KERR ! return code
80 LOGICAL, INTENT(OUT) :: OCOMPRESS
81 INTEGER, INTENT(OUT) :: KFACT
82 !
83 !* 0.2 Declaration of local variables
84 ! ------------------------------
85 !
86 INTEGER :: JLAT ! loop control
87 INTEGER :: JLON ! loop control
88 INTEGER :: JHEAD ! loop control
89 INTEGER :: ININDEX ! index of character 'N' in YSTRING1
90 INTEGER :: ISINDEX ! index of character 'S' in YSTRING1
91 INTEGER :: IEINDEX ! index of character 'E' in YSTRING1
92 INTEGER :: IWINDEX ! index of character 'W' in YSTRING1
93 REAL, DIMENSION(9) :: ZVAL ! values of the head data
94 INTEGER :: IHEAD ! index of the data in the array ZVAL
95  CHARACTER(LEN=100) :: YSTRING ! total string in the head
96  CHARACTER(LEN=100) :: YSTRING1 ! string less the begining line descriptor
97  CHARACTER(LEN=100) :: YVAL ! absolute value of the data of the line
98 INTEGER :: IPOINT ! index of '.' in the string YVAL
99 INTEGER :: ILENGTH ! length of the string YVAL
100 INTEGER :: IFRACLENGTH! length of the fractional part in string YVAL
101  CHARACTER(LEN=2) :: YLENGTH ! length of the string YVAL
102  CHARACTER(LEN=2) :: YFRACLENGTH! length of the fractional part in string YVAL
103  CHARACTER(LEN=10) :: YINTERNALFORMAT ! format to read YVAL in real ZVAL
104 REAL(KIND=JPRB) :: ZHOOK_HANDLE
105 !-------------------------------------------------------------------------------
106 !
107 IF (lhook) CALL dr_hook('READHEAD',0,zhook_handle)
108 kerr=0
109 !
110 !* 1. Line of comments
111 ! ----------------
112 !
113 zval(1:8) = 1.
114 zval(9) = 0.
115 !
116 READ (kglb,'(A100)',end=99) ystring
117 !
118 !-------------------------------------------------------------------------------
119 !
120 !* 2. Other lines
121 ! -----------
122 !
123 DO jhead=1,9
124  READ (kglb,'(A100)',end=99) ystring
125  ystring=adjustl(ystring)
126 !
127 !* 2.1 Selection of the line
128 ! ---------------------
129 !
130  SELECT CASE (ystring(1:5))
131  CASE('cutva')
132  ihead=1
133  ystring1=ystring(10:100)
134  CASE('nodat')
135  ihead=1
136  ystring1=ystring(8:100)
137  CASE('north')
138  ihead=2
139  ystring1=ystring(7:100)
140  CASE('south')
141  ihead=3
142  ystring1=ystring(7:100)
143  CASE('east:')
144  ihead=4
145  ystring1=ystring(6:100)
146  CASE('west:')
147  ihead=5
148  ystring1=ystring(6:100)
149  CASE('rows:')
150  ihead=6
151  ystring1=ystring(6:100)
152  CASE('cols:')
153  ihead=7
154  ystring1=ystring(6:100)
155  CASE('fact:')
156  ihead=8
157  ystring1=ystring(6:100)
158  CASE('compr')
159  ihead=9
160  ystring1=ystring(10:100)
161  END SELECT
162 !
163 !* 2.2 Test on presence of geographical descritor (N, E, S or W)
164 ! ---------------------------------------------------------
165 !
166  inindex=index(ystring1,'N')
167  isindex=index(ystring1,'S')
168  ieindex=index(ystring1,'E')
169  iwindex=index(ystring1,'W')
170  yval=adjustl(ystring1)
171  IF (inindex/=0) yval=adjustl(ystring1(1:inindex-1))
172  IF (isindex/=0) yval='-'//adjustl(ystring1(1:isindex-1))
173  IF (ieindex/=0) yval=adjustl(ystring1(1:ieindex-1))
174  IF (iwindex/=0) yval='-'//adjustl(ystring1(1:iwindex-1))
175 !
176 !* 2.3 Transformation of the data in real
177 ! ----------------------------------
178 !
179  ipoint=index(yval,'.')
180  IF (ipoint==0) yval=adjustl(adjustr(yval)//'.')
181 !
182 !* 2.4 Definition of the format of the data
183 ! ------------------------------------
184 !
185  ilength=len_trim(adjustl(adjustr(yval)))
186  ifraclength=ilength-index(yval,'.')
187  WRITE(ylength,'(I2)') ilength
188  WRITE(yfraclength,'(I2)') ifraclength
189  yinternalformat='(F'//ylength//'.'//yfraclength//')'
190 !
191 !* 2.5 Data definition
192 ! ---------------
193 !
194  READ(yval,adjustl(yinternalformat)) zval(ihead)
195 !
196 ENDDO
197 !
198 99 CONTINUE
199 !-------------------------------------------------------------------------------
200 !
201 !* 3. Initialization of arguments, longitudes and latitudes
202 ! -----------------------------------------------------
203 !
204 pcutval=zval(1)
205 pglblatmax=zval(2)
206 pglblatmin=zval(3)
207 pglblonmin=zval(5)
208 pglblonmax=zval(4)+nint((zval(5)-zval(4)+180.*(1.0+xsurf_epsilon))/360.)*360.
209 knblat=nint(zval(6))
210 knblon=nint(zval(7))
211 kfact=nint(zval(8))
212 ocompress = .false.
213 IF (zval(9)==1.) ocompress = .true.
214 !
215 pdlat=(pglblatmax-pglblatmin)/knblat
216 pdlon=(pglblonmax-pglblonmin)/knblon
217 ALLOCATE(plat(knblat))
218 ALLOCATE(plon(knblon))
219 plat(:)=(/ (pglblatmax-(jlat-0.5)*pdlat, jlat=1,knblat) /)
220 plon(:)=(/ (pglblonmin+(jlon-0.5)*pdlon, jlon=1,knblon) /)
221 !
222 !IF (LHOOK) CALL DR_HOOK('READHEAD',1,ZHOOK_HANDLE)
223 !RETURN
224 !KERR=-1
225 IF (lhook) CALL dr_hook('READHEAD',1,zhook_handle)
226 !-------------------------------------------------------------------------------
227 END SUBROUTINE readhead
integer, parameter jprb
Definition: parkind1.F90:32
real, save xsurf_epsilon
Definition: modd_csts.F90:88
logical lhook
Definition: yomhook.F90:15
subroutine readhead(KGLB, PGLBLATMIN, PGLBLATMAX, PGLBLONMIN, PGLBLONM
Definition: readhead.F90:7
ERROR in index
Definition: ecsort_shared.h:90