SURFEX v8.1
General documentation of Surfex
decompress.f90
Go to the documentation of this file.
1 !-----------------------------------------------------------------
2 !--------------- special set of characters for RCS information
3 !-----------------------------------------------------------------
4 ! $Source: /home/cvsroot/mesonh/libtools/lib/COMPRESS/src/decompress.f90,v $ $Revision: 1.1 $ $Date: 2005/04/12 15:06:20 $
5 !-----------------------------------------------------------------
6 SUBROUTINE get_compheader(KTAB,SIZEKTAB,KNBELT,KTYPECOD)
7 
8 INTEGER, INTENT(IN) :: SIZEKTAB
9 INTEGER(KIND=8), DIMENSION(SIZEKTAB), INTENT(IN) :: KTAB
10 INTEGER, INTENT(OUT) :: KNBELT ! size of decompressed array
11 INTEGER, INTENT(OUT) :: KTYPECOD ! code for compression type
12 
13  CHARACTER(LEN=8) :: STRKEY
14 
15 INTEGER :: INTCHAR
16 INTEGER :: JI
17 
18  CALL set_extractidx(0,0)
19 ! extract string header
20 DO ji=1,8
21  CALL extract_bbuff(ktab,8,intchar)
22  strkey(ji:ji) = char(intchar)
23 END DO
24 
25 ! Treat array if it is compressed
26 IF (strkey == 'COMPRESS') THEN
27  CALL extract_bbuff(ktab,32,ktypecod)
28  CALL extract_bbuff(ktab,32,knbelt)
29 ELSE
30  knbelt =-1
31  ktypecod = 0
32 END IF
33 
34 END SUBROUTINE get_compheader
35 
36 SUBROUTINE decompress_field(XTAB,NBELT,COMPTAB,NBCOMPELT,CODINGTYPE)
39 
40 IMPLICIT NONE
41 INTEGER, INTENT(IN) :: NBELT
42 INTEGER, INTENT(IN) :: NBCOMPELT
43 REAL (KIND=8),DIMENSION(NBELT),TARGET,INTENT(OUT) :: XTAB
44 INTEGER(KIND=8),DIMENSION(NBCOMPELT), INTENT(IN) :: COMPTAB
45 INTEGER, INTENT(IN) :: CODINGTYPE
46 
47 INTEGER,DIMENSION(:), ALLOCATABLE :: ITAB
48 LOGICAL,DIMENSION(:), ALLOCATABLE :: GMASK
49 
50 REAL :: XREF, XCOEFF
51 INTEGER :: INBLEV
52 INTEGER :: ILEVNBELT
53 INTEGER :: JI
54 INTEGER :: IND1, IND2
55 INTEGER :: IDIMX,IDIMY
56 INTEGER :: IEXTCOD
57 REAL(KIND=8),DIMENSION(:),POINTER :: XPTRTAB
58 REAL :: XMIN,XMAX
59 
60 SELECT CASE (codingtype)
61 CASE (jpcstencod)
62  CALL extract_bbuff(comptab,32,xref)
63  xtab(:) = xref
64 
65 CASE (jpsopencod)
66  CALL extract_bbuff(comptab,32,idimx)
67  CALL extract_bbuff(comptab,32,idimy)
68  ilevnbelt = idimx * idimy
69  inblev = nbelt/(ilevnbelt)
70  ALLOCATE(itab(ilevnbelt))
71  DO ji=1,inblev
72  ind1=(ji-1)*ilevnbelt+1
73  ind2=ji*ilevnbelt
74  xptrtab=>xtab(ind1:ind2)
75  IF (lpdebug) print *,'###### Decompress(SOPENCOD) LEVEL ',ji,'######'
76  CALL extract_bbuff(comptab,32,xref)
77  CALL extract_bbuff(comptab,32,xcoeff)
78  CALL extractintarray(itab)
79  CALL decomp_fop(xptrtab,itab,xref,xcoeff)
80  END DO
81 
82 CASE (jpextencod)
83  CALL extract_bbuff(comptab,32,idimx)
84  CALL extract_bbuff(comptab,32,idimy)
85  ilevnbelt = idimx * idimy
86  inblev = nbelt/(ilevnbelt)
87  ALLOCATE(itab(ilevnbelt))
88  ALLOCATE(gmask(ilevnbelt))
89  DO ji=1,inblev
90 
91  IF (lpdebug) print *,'###### Decompress(EXTENCOD) LEVEL ',ji,'######'
92  ind1=(ji-1)*ilevnbelt+1
93  ind2=ji*ilevnbelt
94  xptrtab=>xtab(ind1:ind2)
95  !
96  CALL extract_bbuff(comptab,3,iextcod)
97  IF (iextcod == jpother) THEN
98  CALL extract_bbuff(comptab,3,iextcod)
99  iextcod = iextcod + 8
100  END IF
101  IF (lpdebug) print *, "IEXTCOD = ",iextcod
102  SELECT CASE(iextcod)
103  CASE(jplog)
104  ! Conversion to log values of original data 0<=x<1
105  CALL extract_bbuff(comptab,32,xref)
106  CALL extract_bbuff(comptab,32,xcoeff)
107  CALL extractintarray(itab)
108  gmask(:) = .true.
109  WHERE (itab == 0)
110  gmask = .false.
111  xptrtab = 0.0
112  END WHERE
113  CALL decomp_fop(xptrtab,itab,xref,xcoeff,gmask,1)
114  WHERE(gmask)
115  xptrtab = exp(xptrtab)
116  END WHERE
117 
118  CASE(jpconst)
119  ! constant value array
120  CALL extract_bbuff(comptab,32,xref)
121  xptrtab(:) = xref
122  IF (lpdebug) print *," CONST value=",xref
123 
124  CASE(jp2val)
125  ! 2 different values in array
126  CALL extract_bbuff(comptab,32,xmin)
127  CALL extract_bbuff(comptab,32,xmax)
128  CALL extractintarray(itab)
129  WHERE (itab == 0)
130  xptrtab = xmin
131  ELSEWHERE
132  xptrtab = xmax
133  END WHERE
134  IF (lpdebug) print *," 2 values:",xmin,xmax
135 
136  CASE(jp3val)
137  ! 3 different values in array
138  CALL extract_bbuff(comptab,32,xmin)
139  CALL extract_bbuff(comptab,32,xref)
140  CALL extract_bbuff(comptab,32,xmax)
141  CALL extractintarray(itab)
142  WHERE (itab == 0)
143  xptrtab = xmin
144  ELSEWHERE
145  xptrtab = xref
146  END WHERE
147  WHERE (itab == 2) xptrtab = xmax
148  IF (lpdebug) print *," 3 values:",xmin,xref,xmax
149 
150  CASE(jpnorm)
151  ! same as JPSOPENCOD
152  CALL extract_bbuff(comptab,32,xref)
153  CALL extract_bbuff(comptab,32,xcoeff)
154  CALL extractintarray(itab)
155  CALL decomp_fop(xptrtab,itab,xref,xcoeff)
156  IF (lpdebug) print *," normal, XREF/XCOEFF = ",xref,xcoeff
157 
158  CASE(jpminexcl)
159  ! Min value is isolated
160  CALL extract_bbuff(comptab,32,xmin)
161  CALL extract_bbuff(comptab,32,xref)
162  CALL extract_bbuff(comptab,32,xcoeff)
163  CALL extractintarray(itab)
164  gmask(:) = .true.
165  WHERE (itab == 0)
166  gmask = .false.
167  xptrtab = xmin
168  END WHERE
169  CALL decomp_fop(xptrtab,itab,xref,xcoeff,gmask,1)
170  IF (lpdebug) print *," Min exclus, MIN/XREF/XCOEFF = ",xmin,xref,xcoeff
171 
172  CASE(jpmaxexcl)
173  ! Max value is isolated
174  CALL extract_bbuff(comptab,32,xmax)
175  CALL extract_bbuff(comptab,32,xref)
176  CALL extract_bbuff(comptab,32,xcoeff)
177  CALL extractintarray(itab)
178  gmask(:) = .true.
179  WHERE (itab == 65535)
180  gmask = .false.
181  xptrtab = xmax
182  END WHERE
183  CALL decomp_fop(xptrtab,itab,xref,xcoeff,gmask,0)
184  IF (lpdebug) print *," Max exclus, MAX/XREF/XCOEFF = ",xmax,xref,xcoeff
185 
186  CASE(jpminmaxexcl)
187  ! Min&Max value are isolated
188  CALL extract_bbuff(comptab,32,xmin)
189  CALL extract_bbuff(comptab,32,xmax)
190  CALL extract_bbuff(comptab,32,xref)
191  CALL extract_bbuff(comptab,32,xcoeff)
192  CALL extractintarray(itab)
193  gmask(:) = .true.
194  WHERE (itab == 0)
195  gmask = .false.
196  xptrtab = xmin
197  END WHERE
198  WHERE (itab == 65535)
199  gmask = .false.
200  xptrtab = xmax
201  END WHERE
202  CALL decomp_fop(xptrtab,itab,xref,xcoeff,gmask,1)
203  IF (lpdebug) print *," Min et Max exclus, MIN/MAX/XREF/XCOEFF = ",&
204  &xmin,xmax,xref,xcoeff
205  END SELECT
206  END DO
207 
208 CASE DEFAULT
209  print *,'Error in CODINGTYPE : program aborted'
210  stop
211 END SELECT
212 
213 CONTAINS
214 
215 SUBROUTINE decomp_fop(PTAB,KTAB,PREF,PCOEFF,OMASK,KINDCOR)
216 REAL(KIND=8), DIMENSION(:), INTENT(INOUT) :: PTAB
217 ! Attention: avec le compilateur PGF, utiliser INTENT(OUT) provoque une recopie
218 ! complete du tableau dans PTAB (avec ecrasement possible des valeurs
219 ! presentes a l'appel de la procedure). Le phenomene est genant lorsque
220 ! DECOMP_FOP ne calcule que sur une portion de PTAB (valeurs min et/ou max
221 ! sont presentes). En declarant PTAB en INOUT, les valeurs en entree de la routine
222 ! sont conservees si elles n'ont pas ete modifiees.
223 
224 INTEGER, DIMENSION(:), INTENT(IN) :: KTAB
225 REAL, INTENT(IN) :: PREF
226 REAL, INTENT(IN) :: PCOEFF
227 LOGICAL, DIMENSION(:),INTENT(IN),OPTIONAL :: OMASK
228 INTEGER,INTENT(IN),OPTIONAL :: KINDCOR ! 1 if Min value is isolated, 0 otherwise
229 
230 INTEGER :: INDCOR
231 
232 IF (.NOT. PRESENT(kindcor)) THEN
233  indcor = 0
234 ELSE
235  indcor = kindcor
236 END IF
237 
238 IF (PRESENT(omask)) THEN
239  WHERE (omask)
240  ptab(:) = pcoeff*(ktab(:)-indcor)+pref
241  END WHERE
242 ELSE
243  IF (pcoeff == 0.0) THEN
244  ptab(:) = pref
245  ELSE
246  ptab(:) = pcoeff*ktab(:)+pref
247  END IF
248 END IF
249 
250 END SUBROUTINE decomp_fop
251 
252 SUBROUTINE extractintarray(KTAB)
253 INTEGER,DIMENSION(:),INTENT(OUT) :: KTAB
254 !
255 ! COMPTAB, IDIMX and IDIMY are defined in the calling routine
256 !
257 INTEGER :: NBGRP
258 INTEGER :: IBE
259 INTEGER :: CPT
260 INTEGER :: JJ
261 INTEGER :: ALONE
262 INTEGER :: NBITCOD,IMIN
263 INTEGER :: GELT
264 INTEGER :: JELT
265 INTEGER :: IEPS
266 
267  CALL extract_bbuff(comptab,32,nbgrp)
268 ! PRINT *,'Nbre de groupes =',NBGRP
269  CALL extract_bbuff(comptab,5,ibe)
270 ! PRINT *,'Nbre de bits pour coder le nombre d''elements:',IBE
271 cpt = 1
272 DO jj=1,nbgrp
273  ! PRINT *,'Groupe ',JJ,' : '
274  CALL extract_bbuff(comptab,1,alone)
275  CALL extract_bbuff(comptab,16,imin)
276  ! PRINT *,'IREF=',IMIN
277 
278  IF (alone == 1) THEN
279  ! 1 seul elt dans le groupe
280  ! PRINT *,'--> un seul element dans le groupe'
281  ktab(cpt)=imin
282  cpt=cpt+1
283  ELSE
284  CALL extract_bbuff(comptab,4,nbitcod)
285  CALL extract_bbuff(comptab,ibe,gelt)
286  ! PRINT *,'--> ',GELT,' elts, codage ecart sur ',nbitcod,'bits'
287  IF (nbitcod > 0) THEN
288  DO jelt=1,gelt
289  CALL extract_bbuff(comptab,nbitcod,ieps)
290  ktab(cpt) = imin+ieps
291  cpt=cpt+1
292  END DO
293  ELSE
294  ktab(cpt:cpt+gelt-1) = imin
295  cpt = cpt+gelt
296  END IF
297  END IF
298 END DO
299  CALL invertcol(ktab,idimx,idimy)
300 END SUBROUTINE extractintarray
301 
302 END SUBROUTINE decompress_field
303 
integer, parameter jpcstencod
subroutine extractintarray(KTAB)
Definition: decompress.f90:253
integer, parameter jpother
integer, parameter jpnorm
subroutine decomp_fop(PTAB, KTAB, PREF, PCOEFF, OMASK, KINDCOR)
Definition: decompress.f90:216
integer, parameter jp2val
subroutine invertcol(ITAB, KX, KY)
integer, parameter jpminmaxexcl
integer, parameter jpsopencod
integer, parameter jpextencod
logical, parameter lpdebug
integer, parameter jpconst
integer, parameter jplog
subroutine get_compheader(KTAB, SIZEKTAB, KNBELT, KTYPECOD)
Definition: decompress.f90:7
subroutine decompress_field(XTAB, NBELT, COMPTAB, NBCOMPELT, CODINGTYPE)
Definition: decompress.f90:37
integer, parameter jp3val
integer, parameter jpminexcl
integer, parameter jpmaxexcl