NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
reduce.f
Go to the documentation of this file.
1
4
41 SUBROUTINE reduce(JMIN,JMAX,LBIT,NOV,LX,NDG,IBIT,JBIT,KBIT,
42 1 NOVREF,IBXX2,IER)
43
44 CHARACTER*1 CFEED
45C
46 dimension jmin(ndg),jmax(ndg),lbit(ndg),nov(ndg)
47 dimension newbox(ndg),newboxp(ndg)
48C NEWBOX( ) AND NEWBOXP( ) ARE AUTOMATIC ARRAYS.
49 dimension ntotbt(0:31),nboxj(0:31)
50 dimension ibxx2(0:30)
51C
52 DATA ifeed/12/
53C
54 ier=0
55 IF(lx.EQ.1)GO TO 410
56C IF THERE IS ONLY ONE GROUP, RETURN.
57C
58 cfeed=char(ifeed)
59C
60C INITIALIZE NUMBER OF NEW BOXES PER GROUP TO ZERO.
61C
62 DO 110 l=1,lx
63 newbox(l)=0
64 110 CONTINUE
65C
66C INITIALIZE NUMBER OF TOTAL NEW BOXES PER J TO ZERO.
67C
68 DO 112 j=0,31
69 ntotbt(j)=999999999
70 nboxj(j)=0
71 112 CONTINUE
72C
73 iorigb=(ibit+jbit+kbit)*lx
74C IBIT = BITS TO PACK THE JMIN( ).
75C JBIT = BITS TO PACK THE LBIT( ).
76C KBIT = BITS TO PACK THE NOV( ).
77C LX = NUMBER OF GROUPS.
78 ntotbt(kbit)=iorigb
79C THIS IS THE VALUE OF TOTAL BITS FOR THE ORIGINAL LX
80C GROUPS, WHICH REQUIRES KBITS TO PACK THE GROUP
81C LENGHTS. SETTING THIS HERE MAKES ONE LESS LOOPS
82C NECESSARY BELOW.
83C
84C COMPUTE BITS NOW USED FOR THE PARAMETERS DEFINED.
85C
86C DETERMINE OTHER POSSIBILITES BY INCREASING LX AND DECREASING
87C NOV( ) WITH VALUES GREATER THAN THRESHOLDS. ASSUME A GROUP IS
88C SPLIT INTO 2 OR MORE GROUPS SO THAT KBIT IS REDUCED WITHOUT
89C CHANGING IBIT OR JBIT.
90C
91 jj=0
92C
93 DO 200 j=min(30,kbit-1),2,-1
94C VALUES GE KBIT WILL NOT REQUIRE SPLITS. ONCE THE TOTAL
95C BITS START INCREASING WITH DECREASING J, STOP. ALSO, THE
96C NUMBER OF BITS REQUIRED IS KNOWN FOR KBITS = NTOTBT(KBIT).
97C
98 newboxt=0
99C
100 DO 190 l=1,lx
101C
102 IF(nov(l).LT.ibxx2(j))THEN
103 newbox(l)=0
104C NO SPLITS OR NEW BOXES.
105 GO TO 190
106 ELSE
107 novl=nov(l)
108C
109 m=(nov(l)-1)/(ibxx2(j)-1)+1
110C M IS FOUND BY SOLVING THE EQUATION BELOW FOR M:
111C (NOV(L)+M-1)/M LT IBXX2(J)
112C M GT (NOV(L)-1)/(IBXX2(J)-1)
113C SET M = (NOV(L)-1)/(IBXX2(J)-1)+1
114 130 novl=(nov(l)+m-1)/m
115C THE +M-1 IS NECESSARY. FOR INSTANCE, 15 WILL FIT
116C INTO A BOX 4 BITS WIDE, BUT WON'T DIVIDE INTO
117C TWO BOXES 3 BITS WIDE EACH.
118C
119 IF(novl.LT.ibxx2(j))THEN
120 GO TO 185
121 ELSE
122 m=m+1
123C*** WRITE(KFILDO,135)L,NOV(L),NOVL,M,J,IBXX2(J)
124C*** 135 FORMAT(/' AT 135--L,NOV(L),NOVL,M,J,IBXX2(J)',6I10)
125 GO TO 130
126 ENDIF
127C
128C THE ABOVE DO LOOP WILL NEVER COMPLETE.
129 ENDIF
130C
131 185 newbox(l)=m-1
132 newboxt=newboxt+m-1
133 190 CONTINUE
134C
135 nboxj(j)=newboxt
136 ntotpr=ntotbt(j+1)
137 ntotbt(j)=(ibit+jbit)*(lx+newboxt)+j*(lx+newboxt)
138C
139 IF(ntotbt(j).GE.ntotpr)THEN
140 jj=j+1
141C THE PLUS IS USED BECAUSE J DECREASES PER ITERATION.
142 GO TO 250
143 ELSE
144C
145C SAVE THE TOTAL NEW BOXES AND NEWBOX( ) IN CASE THIS
146C IS THE J TO USE.
147C
148 newboxtp=newboxt
149C
150 DO 195 l=1,lx
151 newboxp(l)=newbox(l)
152 195 CONTINUE
153C
154C WRITE(KFILDO,197)NEWBOXT,IBXX2(J)
155C197 FORMAT(/' *****************************************'
156C 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL',
157C 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10
158C 3 /' *****************************************')
159C WRITE(KFILDO,198) (NEWBOX(L),L=1,LX)
160C198 FORMAT(/' '20I6/(' '20I6))
161
162 ENDIF
163C
164C205 WRITE(KFILDO,209)KBIT,IORIGB
165C209 FORMAT(/' ORIGINAL BITS WITH KBIT OF',I5,' =',I10)
166C WRITE(KFILDO,210)(N,N=2,10),(IBXX2(N),N=2,10),
167C 1 (NTOTBT(N),N=2,10),(NBOXJ(N),N=2,10),
168C 2 (N,N=11,20),(IBXX2(N),N=11,20),
169C 3 (NTOTBT(N),N=11,20),(NBOXJ(N),N=11,20),
170C 4 (N,N=21,30),(IBXX2(N),N=11,20),
171C 5 (NTOTBT(N),N=21,30),(NBOXJ(N),N=21,30)
172C210 FORMAT(/' THE TOTAL BYTES FOR MAXIMUM GROUP LENGTHS BY ROW'//
173C 1 ' J = THE NUMBER OF BITS PER GROUP LENGTH'/
174C 2 ' IBXX2(J) = THE MAXIMUM GROUP LENGTH PLUS 1 FOR THIS J'/
175C 3 ' NTOTBT(J) = THE TOTAL BITS FOR THIS J'/
176C 4 ' NBOXJ(J) = THE NEW GROUPS FOR THIS J'/
177C 5 4(/10X,9I10)/4(/10I10)/4(/10I10))
178C
179 200 CONTINUE
180C
181 250 pimp=((iorigb-ntotbt(jj))/float(iorigb))*100.
182C WRITE(KFILDO,252)PIMP,KBIT,JJ
183C252 FORMAT(/' PERCENT IMPROVEMENT =',F6.1,
184C 1 ' BY DECREASING GROUP LENGTHS FROM',I4,' TO',I4,' BITS')
185 IF(pimp.GE.2.)THEN
186C
187C WRITE(KFILDO,255)CFEED,NEWBOXTP,IBXX2(JJ)
188C255 FORMAT(A1,/' *****************************************'
189C 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL',
190C 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10
191C 2 /' *****************************************')
192C WRITE(KFILDO,256) (NEWBOXP(L),L=1,LX)
193C256 FORMAT(/' '20I6)
194C
195C ADJUST GROUP LENGTHS FOR MAXIMUM LENGTH OF JJ BITS.
196C THE MIN PER GROUP AND THE NUMBER OF BITS REQUIRED
197C PER GROUP ARE NOT CHANGED. THIS MAY MEAN THAT A
198C GROUP HAS A MIN (OR REFERENCE) THAT IS NOT ZERO.
199C THIS SHOULD NOT MATTER TO THE UNPACKER.
200C
201 lxnkp=lx+newboxtp
202C LXNKP = THE NEW NUMBER OF BOXES
203C
204 IF(lxnkp.GT.ndg)THEN
205C DIMENSIONS NOT LARGE ENOUGH. PROBABLY AN ERROR
206C OF SOME SORT. ABORT.
207C WRITE(KFILDO,257)NDG,LXNPK
208C 1 2 3 4 5 6 7 X
209C257 FORMAT(/' DIMENSIONS OF JMIN, ETC. IN REDUCE =',I8,
210C 1 ' NOT LARGE ENOUGH FOR THE EXPANDED NUMBER OF',
211C 2 ' GROUPS =',I8,'. ABORT REDUCE.')
212 ier=715
213 GO TO 410
214C AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE
215C WITHOUT CALLING REDUCE.
216 ENDIF
217C
218 lxn=lxnkp
219C LXN IS THE NUMBER OF THE BOX IN THE NEW SERIES BEING
220C FILLED. IT DECREASES PER ITERATION.
221 ibxx2m1=ibxx2(jj)-1
222C IBXX2M1 IS THE MAXIMUM NUMBER OF VALUES PER GROUP.
223C
224 DO 300 l=lx,1,-1
225C
226C THE VALUES IS NOV( ) REPRESENT THOSE VALUES + NOVREF.
227C WHEN VALUES ARE MOVED TO ANOTHER BOX, EACH VALUE
228C MOVED TO A NEW BOX REPRESENTS THAT VALUE + NOVREF.
229C THIS HAS TO BE CONSIDERED IN MOVING VALUES.
230C
231 IF(newboxp(l)*(ibxx2m1+novref)+novref.GT.nov(l)+novref)THEN
232C IF THE ABOVE TEST IS MET, THEN MOVING IBXX2M1 VALUES
233C FOR ALL NEW BOXES WILL LEAVE A NEGATIVE NUMBER FOR
234C THE LAST BOX. NOT A TOLERABLE SITUATION.
235 movmin=(nov(l)-(newboxp(l))*novref)/newboxp(l)
236 left=nov(l)
237C LEFT = THE NUMBER OF VALUES TO MOVE FROM THE ORIGINAL
238C BOX TO EACH NEW BOX EXCEPT THE LAST. LEFT IS THE
239C NUMBER LEFT TO MOVE.
240 ELSE
241 movmin=ibxx2m1
242C MOVMIN VALUES CAN BE MOVED FOR EACH NEW BOX.
243 left=nov(l)
244C LEFT IS THE NUMBER OF VALUES LEFT TO MOVE.
245 ENDIF
246C
247 IF(newboxp(l).GT.0)THEN
248 IF((movmin+novref)*newboxp(l)+novref.LE.nov(l)+novref.
249 1 and.(movmin+novref)*(newboxp(l)+1).GE.nov(l)+novref)THEN
250 GO TO 288
251 ELSE
252C***D WRITE(KFILDO,287)L,MOVMIN,NOVREF,NEWBOXP(L),NOV(L)
253C***D287 FORMAT(/' AT 287 IN REDUCE--L,MOVMIN,NOVREF,',
254C***D 1 'NEWBOXP(L),NOV(L)',5I12
255C***D 2 ' REDUCE ABORTED.')
256C WRITE(KFILDO,2870)
257C2870 FORMAT(/' AN ERROR IN REDUCE ALGORITHM. ABORT REDUCE.')
258 ier=714
259 GO TO 410
260C AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE
261C WITHOUT CALLING REDUCE.
262 ENDIF
263C
264 ENDIF
265C
266 288 DO 290 j=1,newboxp(l)+1
267 move=min(movmin,left)
268 jmin(lxn)=jmin(l)
269 jmax(lxn)=jmax(l)
270 lbit(lxn)=lbit(l)
271 nov(lxn)=move
272 lxn=lxn-1
273 left=left-(move+novref)
274C THE MOVE OF MOVE VALUES REALLY REPRESENTS A MOVE OF
275C MOVE + NOVREF VALUES.
276 290 CONTINUE
277C
278 IF(left.NE.-novref)THEN
279C*** WRITE(KFILDO,292)L,LXN,MOVE,LXNKP,IBXX2(JJ),LEFT,NOV(L),
280C*** 1 MOVMIN
281C*** 292 FORMAT(' AT 292 IN REDUCE--L,LXN,MOVE,LXNKP,',
282C*** 1 'IBXX2(JJ),LEFT,NOV(L),MOVMIN'/8I12)
283 ENDIF
284C
285 300 CONTINUE
286C
287 lx=lxnkp
288C LX IS NOW THE NEW NUMBER OF GROUPS.
289 kbit=jj
290C KBIT IS NOW THE NEW NUMBER OF BITS REQUIRED FOR PACKING
291C GROUP LENGHTS.
292 ENDIF
293C
294C WRITE(KFILDO,406)CFEED,LX
295C406 FORMAT(A1,/' *****************************************'
296C 1 /' THE GROUP SIZES NOV( ) AFTER REDUCTION IN SIZE',
297C 2 ' FOR'I10,' GROUPS',
298C 3 /' *****************************************')
299C WRITE(KFILDO,407) (NOV(J),J=1,LX)
300C407 FORMAT(/' '20I6)
301C WRITE(KFILDO,408)CFEED,LX
302C408 FORMAT(A1,/' *****************************************'
303C 1 /' THE GROUP MINIMA JMIN( ) AFTER REDUCTION IN SIZE',
304C 2 ' FOR'I10,' GROUPS',
305C 3 /' *****************************************')
306C WRITE(KFILDO,409) (JMIN(J),J=1,LX)
307C409 FORMAT(/' '20I6)
308C
309 410 RETURN
310 END
311
subroutine reduce(jmin, jmax, lbit, nov, lx, ndg, ibit, jbit, kbit, novref, ibxx2, ier)
This subroutine determines whether the number of groups should be increased in order to reduce the si...
Definition reduce.f:43