NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
pack_gp.f
Go to the documentation of this file.
1
5
113 SUBROUTINE pack_gp(IC,NXY,IS523,MINPK,INC,MISSP,MISSS,
114 1 JMIN,JMAX,LBIT,NOV,NDG,LX,IBIT,JBIT,KBIT,
115 2 NOVREF,LBITREF,IER)
116
117 parameter(mallow=2**30+1)
118C
119 CHARACTER*1 CFEED
120 LOGICAL ADDA
121C
122 dimension ic(nxy)
123 dimension jmin(ndg),jmax(ndg),lbit(ndg),nov(ndg)
124 dimension misslx(ndg)
125C MISSLX( ) IS AN AUTOMATIC ARRAY.
126 INTEGER, PARAMETER :: IBXX2(0:30) = (/ 1, 2, 4, 8, 16, 32, 64, &
127 & 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, &
128 & 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, &
129 & 16777216, 33554432, 67108864, 134217728, 268435456, &
130 & 536870912, 1073741824 /)
131C
132
133 parameter(ifeed=12)
134C
135 ier=0
136 iersav=0
137C CALL TIMPR(KFILDO,KFILDO,'START PACK_GP ')
138 cfeed=char(ifeed)
139C
140 ired=0
141C IRED IS A FLAG. WHEN ZERO, REDUCE WILL BE CALLED.
142C IF REDUCE ABORTS, IRED = 1 AND IS NOT CALLED. IN
143C THIS CASE PACK_GP EXECUTES AGAIN EXCEPT FOR REDUCE.
144C
145 IF(inc.LE.0)THEN
146 iersav=717
147C WRITE(KFILDO,101)INC
148C101 FORMAT(/' ****INC ='I8,' NOT CORRECT IN PACK_GP. 1 IS USED.')
149 ENDIF
150C
151C THERE WILL BE A RESTART OF PACK_GP IF SUBROUTINE REDUCE
152C ABORTS. THIS SHOULD NOT HAPPEN, BUT IF IT DOES, PACK_GP
153C WILL COMPLETE WITHOUT SUBROUTINE REDUCE. A NON FATAL
154C DIAGNOSTIC RETURN IS PROVIDED.
155C
156 102 kinc=max(inc,1)
157 lminpk=minpk
158C
159C THERE WILL BE A RESTART AT 105 IS NDG IS NOT LARGE ENOUGH.
160C A NON FATAL DIAGNOSTIC RETURN IS PROVIDED.
161C
162 105 kstart=1
163 ktotal=0
164 lx=0
165 adda=.false.
166 lmiss=0
167 IF(is523.EQ.1)lmiss=1
168 IF(is523.EQ.2)lmiss=2
169C
170C *************************************
171C
172C THIS SECTION COMPUTES STATISTICS FOR GROUP A. GROUP A IS
173C A GROUP OF SIZE LMINPK.
174C
175C *************************************
176C
177 ibita=0
178 mina=mallow
179 maxa=-mallow
180 minak=mallow
181 maxak=-mallow
182C
183C FIND THE MIN AND MAX OF GROUP A. THIS WILL INITIALLY BE OF
184C SIZE LMINPK (IF THERE ARE STILL LMINPK VALUES IN IC( )), BUT
185C WILL INCREASE IN SIZE IN INCREMENTS OF INC UNTIL A NEW
186C GROUP IS STARTED. THE DEFINITION OF GROUP A IS DONE HERE
187C ONLY ONCE (UPON INITIAL ENTRY), BECAUSE A GROUP B CAN ALWAYS
188C BECOME A NEW GROUP A AFTER A IS PACKED, EXCEPT IF LMINPK
189C HAS TO BE INCREASED BECAUSE NDG IS TOO SMALL. THEREFORE,
190C THE SEPARATE LOOPS FOR MISSING AND NON-MISSING HERE BUYS
191C ALMOST NOTHING.
192C
193 nenda=min(kstart+lminpk-1,nxy)
194 IF(nxy-nenda.LE.lminpk/2)nenda=nxy
195C ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY
196C MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS
197C NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP
198C AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING
199C VALUES FOR EFFICIENCY.
200C
201C DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE
202C UNLESS NENDA = NXY. THIS MAY ALLOW A LARGE GROUP A TO
203C START WITH, AS WITH MISSING VALUES. SEPARATE LOOPS FOR
204C MISSING OPTIONS. THIS SECTION IS ONLY EXECUTED ONCE,
205C IN DETERMINING THE FIRST GROUP. IT HELPS FOR AN ARRAY
206C OF MOSTLY MISSING VALUES OR OF ONE VALUE, SUCH AS
207C RADAR OR PRECIP DATA.
208C
209 IF(nenda.NE.nxy.AND.ic(kstart).EQ.ic(kstart+1))THEN
210C NO NEED TO EXECUTE IF FIRST TWO VALUES ARE NOT EQUAL.
211C
212 IF(is523.EQ.0)THEN
213C THIS LOOP IS FOR NO MISSING VALUES.
214C
215 DO 111 k=kstart+1,nxy
216C
217 IF(ic(k).NE.ic(kstart))THEN
218 nenda=max(nenda,k-1)
219 GO TO 114
220 ENDIF
221C
222 111 CONTINUE
223C
224 nenda=nxy
225C FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME.
226C
227 ELSEIF(is523.EQ.1)THEN
228C THIS LOOP IS FOR PRIMARY MISSING VALUES ONLY.
229C
230 DO 112 k=kstart+1,nxy
231C
232 IF(ic(k).NE.missp)THEN
233C
234 IF(ic(k).NE.ic(kstart))THEN
235 nenda=max(nenda,k-1)
236 GO TO 114
237 ENDIF
238C
239 ENDIF
240C
241 112 CONTINUE
242C
243 nenda=nxy
244C FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME.
245C
246 ELSE
247C THIS LOOP IS FOR PRIMARY AND SECONDARY MISSING VALUES.
248C
249 DO 113 k=kstart+1,nxy
250C
251 IF(ic(k).NE.missp.AND.ic(k).NE.misss)THEN
252C
253 IF(ic(k).NE.ic(kstart))THEN
254 nenda=max(nenda,k-1)
255 GO TO 114
256 ENDIF
257C
258 ENDIF
259C
260 113 CONTINUE
261C
262 nenda=nxy
263C FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME.
264 ENDIF
265C
266 ENDIF
267C
268 114 IF(is523.EQ.0)THEN
269C
270 DO 115 k=kstart,nenda
271 IF(ic(k).LT.mina)THEN
272 mina=ic(k)
273 minak=k
274 ENDIF
275 IF(ic(k).GT.maxa)THEN
276 maxa=ic(k)
277 maxak=k
278 ENDIF
279 115 CONTINUE
280C
281 ELSEIF(is523.EQ.1)THEN
282C
283 DO 117 k=kstart,nenda
284 IF(ic(k).EQ.missp)GO TO 117
285 IF(ic(k).LT.mina)THEN
286 mina=ic(k)
287 minak=k
288 ENDIF
289 IF(ic(k).GT.maxa)THEN
290 maxa=ic(k)
291 maxak=k
292 ENDIF
293 117 CONTINUE
294C
295 ELSE
296C
297 DO 120 k=kstart,nenda
298 IF(ic(k).EQ.missp.OR.ic(k).EQ.misss)GO TO 120
299 IF(ic(k).LT.mina)THEN
300 mina=ic(k)
301 minak=k
302 ENDIF
303 IF(ic(k).GT.maxa)THEN
304 maxa=ic(k)
305 maxak=k
306 ENDIF
307 120 CONTINUE
308C
309 ENDIF
310C
311 kounta=nenda-kstart+1
312C
313C INCREMENT KTOTAL AND FIND THE BITS NEEDED TO PACK THE A GROUP.
314C
315 ktotal=ktotal+kounta
316 mislla=0
317 IF(mina.NE.mallow)GO TO 125
318C ALL MISSING VALUES MUST BE ACCOMMODATED.
319 mina=0
320 maxa=0
321 mislla=1
322 ibitb=0
323 IF(is523.NE.2)GO TO 130
324C WHEN ALL VALUES ARE MISSING AND THERE ARE NO
325C SECONDARY MISSING VALUES, IBITA = 0.
326C OTHERWISE, IBITA MUST BE CALCULATED.
327C
328 125 itest=maxa-mina+lmiss
329C
330 DO 126 ibita=0,30
331 IF(itest.LT.ibxx2(ibita))GO TO 130
332C*** THIS TEST IS THE SAME AS:
333C*** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 130
334 126 CONTINUE
335C
336C WRITE(KFILDO,127)MAXA,MINA
337C127 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.',
338C 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 127.')
339 ier=706
340 GO TO 900
341C
342 130 CONTINUE
343C
344C***D WRITE(KFILDO,131)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA
345C***D131 FORMAT(' AT 130, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8,
346C***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3)
347C
348 133 IF(ktotal.GE.nxy)GO TO 200
349C
350C *************************************
351C
352C THIS SECTION COMPUTES STATISTICS FOR GROUP B. GROUP B IS A
353C GROUP OF SIZE LMINPK IMMEDIATELY FOLLOWING GROUP A.
354C
355C *************************************
356C
357 140 minb=mallow
358 maxb=-mallow
359 minbk=mallow
360 maxbk=-mallow
361 ibitbs=0
362 mstart=ktotal+1
363C
364C DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE.
365C THIS WORKS WHEN THERE ARE NO MISSING VALUES.
366C
367 nendb=1
368C
369 IF(mstart.LT.nxy)THEN
370C
371 IF(is523.EQ.0)THEN
372C THIS LOOP IS FOR NO MISSING VALUES.
373C
374 DO 145 k=mstart+1,nxy
375C
376 IF(ic(k).NE.ic(mstart))THEN
377 nendb=k-1
378 GO TO 150
379 ENDIF
380C
381 145 CONTINUE
382C
383 nendb=nxy
384C FALL THROUGH THE LOOP MEANS ALL REMAINING VALUES
385C ARE THE SAME.
386 ENDIF
387C
388 ENDIF
389C
390 150 nendb=max(nendb,min(ktotal+lminpk,nxy))
391C**** 150 NENDB=MIN(KTOTAL+LMINPK,NXY)
392C
393 IF(nxy-nendb.LE.lminpk/2)nendb=nxy
394C ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY
395C MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS
396C NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP
397C AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING
398C
399C USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES
400C FOR EFFICIENCY.
401C
402 IF(is523.EQ.0)THEN
403C
404 DO 155 k=mstart,nendb
405 IF(ic(k).LE.minb)THEN
406 minb=ic(k)
407C NOTE LE, NOT LT. LT COULD BE USED BUT THEN A
408C RECOMPUTE OVER THE WHOLE GROUP WOULD BE NEEDED
409C MORE OFTEN. SAME REASONING FOR GE AND OTHER
410C LOOPS BELOW.
411 minbk=k
412 ENDIF
413 IF(ic(k).GE.maxb)THEN
414 maxb=ic(k)
415 maxbk=k
416 ENDIF
417 155 CONTINUE
418C
419 ELSEIF(is523.EQ.1)THEN
420C
421 DO 157 k=mstart,nendb
422 IF(ic(k).EQ.missp)GO TO 157
423 IF(ic(k).LE.minb)THEN
424 minb=ic(k)
425 minbk=k
426 ENDIF
427 IF(ic(k).GE.maxb)THEN
428 maxb=ic(k)
429 maxbk=k
430 ENDIF
431 157 CONTINUE
432C
433 ELSE
434C
435 DO 160 k=mstart,nendb
436 IF(ic(k).EQ.missp.OR.ic(k).EQ.misss)GO TO 160
437 IF(ic(k).LE.minb)THEN
438 minb=ic(k)
439 minbk=k
440 ENDIF
441 IF(ic(k).GE.maxb)THEN
442 maxb=ic(k)
443 maxbk=k
444 ENDIF
445 160 CONTINUE
446C
447 ENDIF
448C
449 kountb=nendb-ktotal
450 misllb=0
451 IF(minb.NE.mallow)GO TO 165
452C ALL MISSING VALUES MUST BE ACCOMMODATED.
453 minb=0
454 maxb=0
455 misllb=1
456 ibitb=0
457C
458 IF(is523.NE.2)GO TO 170
459C WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY
460C MISSING VALUES, IBITB = 0. OTHERWISE, IBITB MUST BE
461C CALCULATED.
462C
463 165 DO 166 ibitb=ibitbs,30
464 IF(maxb-minb.LT.ibxx2(ibitb)-lmiss)GO TO 170
465 166 CONTINUE
466C
467C WRITE(KFILDO,167)MAXB,MINB
468C167 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.',
469C 1 ' MAXB ='I13,' MINB ='I13,'. ERROR AT 167.')
470 ier=706
471 GO TO 900
472C
473C COMPARE THE BITS NEEDED TO PACK GROUP B WITH THOSE NEEDED
474C TO PACK GROUP A. IF IBITB GE IBITA, TRY TO ADD TO GROUP A.
475C IF NOT, TRY TO ADD A'S POINTS TO B, UNLESS ADDITION TO A
476C HAS BEEN DONE. THIS LATTER IS CONTROLLED WITH ADDA.
477C
478 170 CONTINUE
479C
480C***D WRITE(KFILDO,171)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA,
481C***D 1 MINB,MAXB,IBITB,MISLLB
482C***D171 FORMAT(' AT 171, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8,
483C***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3,
484C***D 2 ' MINB ='I8,' MAXB ='I8,' IBITB ='I3,' MISLLB ='I3)
485C
486 IF(ibitb.GE.ibita)GO TO 180
487 IF(adda)GO TO 200
488C
489C *************************************
490C
491C GROUP B REQUIRES LESS BITS THAN GROUP A. PUT AS MANY OF A'S
492C POINTS INTO B AS POSSIBLE WITHOUT EXCEEDING THE NUMBER OF
493C BITS NECESSARY TO PACK GROUP B.
494C
495C *************************************
496C
497 kounts=kounta
498C KOUNTA REFERS TO THE PRESENT GROUP A.
499 mintst=minb
500 maxtst=maxb
501 mintstk=minbk
502 maxtstk=maxbk
503C
504C USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES
505C FOR EFFICIENCY.
506C
507 IF(is523.EQ.0)THEN
508C
509 DO 1715 k=ktotal,kstart,-1
510C START WITH THE END OF THE GROUP AND WORK BACKWARDS.
511 IF(ic(k).LT.minb)THEN
512 mintst=ic(k)
513 mintstk=k
514 ELSEIF(ic(k).GT.maxb)THEN
515 maxtst=ic(k)
516 maxtstk=k
517 ENDIF
518 IF(maxtst-mintst.GE.ibxx2(ibitb))GO TO 174
519C NOTE THAT FOR THIS LOOP, LMISS = 0.
520 minb=mintst
521 maxb=maxtst
522 minbk=mintstk
523 maxbk=maxtstk
524 kounta=kounta-1
525C THERE IS ONE LESS POINT NOW IN A.
526 1715 CONTINUE
527C
528 ELSEIF(is523.EQ.1)THEN
529C
530 DO 1719 k=ktotal,kstart,-1
531C START WITH THE END OF THE GROUP AND WORK BACKWARDS.
532 IF(ic(k).EQ.missp)GO TO 1718
533 IF(ic(k).LT.minb)THEN
534 mintst=ic(k)
535 mintstk=k
536 ELSEIF(ic(k).GT.maxb)THEN
537 maxtst=ic(k)
538 maxtstk=k
539 ENDIF
540 IF(maxtst-mintst.GE.ibxx2(ibitb)-lmiss)GO TO 174
541C FOR THIS LOOP, LMISS = 1.
542 minb=mintst
543 maxb=maxtst
544 minbk=mintstk
545 maxbk=maxtstk
546 misllb=0
547C WHEN THE POINT IS NON MISSING, MISLLB SET = 0.
548 1718 kounta=kounta-1
549C THERE IS ONE LESS POINT NOW IN A.
550 1719 CONTINUE
551C
552 ELSE
553C
554 DO 173 k=ktotal,kstart,-1
555C START WITH THE END OF THE GROUP AND WORK BACKWARDS.
556 IF(ic(k).EQ.missp.OR.ic(k).EQ.misss)GO TO 1729
557 IF(ic(k).LT.minb)THEN
558 mintst=ic(k)
559 mintstk=k
560 ELSEIF(ic(k).GT.maxb)THEN
561 maxtst=ic(k)
562 maxtstk=k
563 ENDIF
564 IF(maxtst-mintst.GE.ibxx2(ibitb)-lmiss)GO TO 174
565C FOR THIS LOOP, LMISS = 2.
566 minb=mintst
567 maxb=maxtst
568 minbk=mintstk
569 maxbk=maxtstk
570 misllb=0
571C WHEN THE POINT IS NON MISSING, MISLLB SET = 0.
572 1729 kounta=kounta-1
573C THERE IS ONE LESS POINT NOW IN A.
574 173 CONTINUE
575C
576 ENDIF
577C
578C AT THIS POINT, KOUNTA CONTAINS THE NUMBER OF POINTS TO CLOSE
579C OUT GROUP A WITH. GROUP B NOW STARTS WITH KSTART+KOUNTA AND
580C ENDS WITH NENDB. MINB AND MAXB HAVE BEEN ADJUSTED AS
581C NECESSARY TO REFLECT GROUP B (EVEN THOUGH THE NUMBER OF BITS
582C NEEDED TO PACK GROUP B HAVE NOT INCREASED, THE END POINTS
583C OF THE RANGE MAY HAVE).
584C
585 174 IF(kounta.EQ.kounts)GO TO 200
586C ON TRANSFER, GROUP A WAS NOT CHANGED. CLOSE IT OUT.
587C
588C ONE OR MORE POINTS WERE TAKEN OUT OF A. RANGE AND IBITA
589C MAY HAVE TO BE RECOMPUTED; IBITA COULD BE LESS THAN
590C ORIGINALLY COMPUTED. IN FACT, GROUP A CAN NOW CONTAIN
591C ONLY ONE POINT AND BE PACKED WITH ZERO BITS
592C (UNLESS MISSS NE 0).
593C
594 nouta=kounts-kounta
595 ktotal=ktotal-nouta
596 kountb=kountb+nouta
597 IF(nenda-nouta.GT.minak.AND.nenda-nouta.GT.maxak)GO TO 200
598C WHEN THE ABOVE TEST IS MET, THE MIN AND MAX OF THE
599C CURRENT GROUP A WERE WITHIN THE OLD GROUP A, SO THE
600C RANGE AND IBITA DO NOT NEED TO BE RECOMPUTED.
601C NOTE THAT MINAK AND MAXAK ARE NO LONGER NEEDED.
602 ibita=0
603 mina=mallow
604 maxa=-mallow
605C
606C USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES
607C FOR EFFICIENCY.
608C
609 IF(is523.EQ.0)THEN
610C
611 DO 1742 k=kstart,nenda-nouta
612 IF(ic(k).LT.mina)THEN
613 mina=ic(k)
614 ENDIF
615 IF(ic(k).GT.maxa)THEN
616 maxa=ic(k)
617 ENDIF
618 1742 CONTINUE
619C
620 ELSEIF(is523.EQ.1)THEN
621C
622 DO 1744 k=kstart,nenda-nouta
623 IF(ic(k).EQ.missp)GO TO 1744
624 IF(ic(k).LT.mina)THEN
625 mina=ic(k)
626 ENDIF
627 IF(ic(k).GT.maxa)THEN
628 maxa=ic(k)
629 ENDIF
630 1744 CONTINUE
631C
632 ELSE
633C
634 DO 175 k=kstart,nenda-nouta
635 IF(ic(k).EQ.missp.OR.ic(k).EQ.misss)GO TO 175
636 IF(ic(k).LT.mina)THEN
637 mina=ic(k)
638 ENDIF
639 IF(ic(k).GT.maxa)THEN
640 maxa=ic(k)
641 ENDIF
642 175 CONTINUE
643C
644 ENDIF
645C
646 mislla=0
647 IF(mina.NE.mallow)GO TO 1750
648C ALL MISSING VALUES MUST BE ACCOMMODATED.
649 mina=0
650 maxa=0
651 mislla=1
652 IF(is523.NE.2)GO TO 177
653C WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY
654C MISSING VALUES IBITA = 0 AS ORIGINALLY SET. OTHERWISE,
655C IBITA MUST BE CALCULATED.
656C
657 1750 itest=maxa-mina+lmiss
658C
659 DO 176 ibita=0,30
660 IF(itest.LT.ibxx2(ibita))GO TO 177
661C*** THIS TEST IS THE SAME AS:
662C*** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 177
663 176 CONTINUE
664C
665C WRITE(KFILDO,1760)MAXA,MINA
666C1760 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.',
667C 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 1760.')
668 ier=706
669 GO TO 900
670C
671 177 CONTINUE
672 GO TO 200
673C
674C *************************************
675C
676C AT THIS POINT, GROUP B REQUIRES AS MANY BITS TO PACK AS GROUPA.
677C THEREFORE, TRY TO ADD INC POINTS TO GROUP A WITHOUT INCREASING
678C IBITA. THIS AUGMENTED GROUP IS CALLED GROUP C.
679C
680C *************************************
681C
682 180 IF(mislla.EQ.1)THEN
683 minc=mallow
684 minck=mallow
685 maxc=-mallow
686 maxck=-mallow
687 ELSE
688 minc=mina
689 maxc=maxa
690 minck=minak
691 maxck=minak
692 ENDIF
693C
694 nount=0
695 IF(nxy-(ktotal+kinc).LE.lminpk/2)kinc=nxy-ktotal
696C ABOVE STATEMENT CONSTRAINS THE LAST GROUP TO BE NOT LESS THAN
697C LMINPK/2 IN SIZE. IF A PROVISION LIKE THIS IS NOT INCLUDED,
698C THERE WILL MANY TIMES BE A VERY SMALL GROUP AT THE END.
699C
700C USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES
701C FOR EFFICIENCY. SINCE KINC IS USUALLY 1, USING SEPARATE
702C LOOPS HERE DOESN'T BUY MUCH. A MISSING VALUE WILL ALWAYS
703C TRANSFER BACK TO GROUP A.
704C
705 IF(is523.EQ.0)THEN
706C
707 DO 185 k=ktotal+1,min(ktotal+kinc,nxy)
708 IF(ic(k).LT.minc)THEN
709 minc=ic(k)
710 minck=k
711 ENDIF
712 IF(ic(k).GT.maxc)THEN
713 maxc=ic(k)
714 maxck=k
715 ENDIF
716 nount=nount+1
717 185 CONTINUE
718C
719 ELSEIF(is523.EQ.1)THEN
720C
721 DO 187 k=ktotal+1,min(ktotal+kinc,nxy)
722 IF(ic(k).EQ.missp)GO TO 186
723 IF(ic(k).LT.minc)THEN
724 minc=ic(k)
725 minck=k
726 ENDIF
727 IF(ic(k).GT.maxc)THEN
728 maxc=ic(k)
729 maxck=k
730 ENDIF
731 186 nount=nount+1
732 187 CONTINUE
733C
734 ELSE
735C
736 DO 190 k=ktotal+1,min(ktotal+kinc,nxy)
737 IF(ic(k).EQ.missp.OR.ic(k).EQ.misss)GO TO 189
738 IF(ic(k).LT.minc)THEN
739 minc=ic(k)
740 minck=k
741 ENDIF
742 IF(ic(k).GT.maxc)THEN
743 maxc=ic(k)
744 maxck=k
745 ENDIF
746 189 nount=nount+1
747 190 CONTINUE
748C
749 ENDIF
750C
751C***D WRITE(KFILDO,191)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA,
752C***D 1 MINC,MAXC,NOUNT,IC(KTOTAL),IC(KTOTAL+1)
753C***D191 FORMAT(' AT 191, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8,
754C***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3,
755C***D 2 ' MINC ='I8,' MAXC ='I8,
756C***D 3 ' NOUNT ='I5,' IC(KTOTAL) ='I9,' IC(KTOTAL+1) =',I9)
757C
758C IF THE NUMBER OF BITS NEEDED FOR GROUP C IS GT IBITA,
759C THEN THIS GROUP A IS A GROUP TO PACK.
760C
761 IF(minc.EQ.mallow)THEN
762 minc=mina
763 maxc=maxa
764 minck=minak
765 maxck=maxak
766 misllc=1
767 GO TO 195
768C WHEN THE NEW VALUE(S) ARE MISSING, THEY CAN ALWAYS
769C BE ADDED.
770C
771 ELSE
772 misllc=0
773 ENDIF
774C
775 IF(maxc-minc.GE.ibxx2(ibita)-lmiss) GO TO 200
776C
777C THE BITS NECESSARY FOR GROUP C HAS NOT INCREASED FROM THE
778C BITS NECESSARY FOR GROUP A. ADD THIS POINT(S) TO GROUP A.
779C COMPUTE THE NEXT GROUP B, ETC., UNLESS ALL POINTS HAVE BEEN
780C USED.
781C
782 195 ktotal=ktotal+nount
783 kounta=kounta+nount
784 mina=minc
785 maxa=maxc
786 minak=minck
787 maxak=maxck
788 mislla=misllc
789 adda=.true.
790 IF(ktotal.GE.nxy)GO TO 200
791C
792 IF(minbk.GT.ktotal.AND.maxbk.GT.ktotal)THEN
793 mstart=nendb+1
794C THE MAX AND MIN OF GROUP B WERE NOT FROM THE POINTS
795C REMOVED, SO THE WHOLE GROUP DOES NOT HAVE TO BE LOOKED
796C AT TO DETERMINE THE NEW MAX AND MIN. RATHER START
797C JUST BEYOND THE OLD NENDB.
798 ibitbs=ibitb
799 nendb=1
800 GO TO 150
801 ELSE
802 GO TO 140
803 ENDIF
804C
805C *************************************
806C
807C GROUP A IS TO BE PACKED. STORE VALUES IN JMIN( ), JMAX( ),
808C LBIT( ), AND NOV( ).
809C
810C *************************************
811C
812 200 lx=lx+1
813 IF(lx.LE.ndg)GO TO 205
814 lminpk=lminpk+lminpk/2
815C WRITE(KFILDO,201)NDG,LMINPK,LX
816C201 FORMAT(' ****NDG ='I5,' NOT LARGE ENOUGH.',
817C 1 ' LMINPK IS INCREASED TO 'I3,' FOR THIS FIELD.'/
818C 2 ' LX = 'I10)
819 iersav=716
820 GO TO 105
821C
822 205 jmin(lx)=mina
823 jmax(lx)=maxa
824 lbit(lx)=ibita
825 nov(lx)=kounta
826 kstart=ktotal+1
827C
828 IF(mislla.EQ.0)THEN
829 misslx(lx)=mallow
830 ELSE
831 misslx(lx)=ic(ktotal)
832C IC(KTOTAL) WAS THE LAST VALUE PROCESSED. IF MISLLA NE 0,
833C THIS MUST BE THE MISSING VALUE FOR THIS GROUP.
834 ENDIF
835C
836C***D WRITE(KFILDO,206)MISLLA,IC(KTOTAL),KTOTAL,LX,JMIN(LX),JMAX(LX),
837C***D 1 LBIT(LX),NOV(LX),MISSLX(LX)
838C***D206 FORMAT(' AT 206, MISLLA ='I2,' IC(KTOTAL) ='I5,' KTOTAL ='I8,
839C***D 1 ' LX ='I6,' JMIN(LX) ='I8,' JMAX(LX) ='I8,
840C***D 2 ' LBIT(LX) ='I5,' NOV(LX) ='I8,' MISSLX(LX) =',I7)
841C
842 IF(ktotal.GE.nxy)GO TO 209
843C
844C THE NEW GROUP A WILL BE THE PREVIOUS GROUP B. SET LIMITS, ETC.
845C
846 ibita=ibitb
847 mina=minb
848 maxa=maxb
849 minak=minbk
850 maxak=maxbk
851 mislla=misllb
852 nenda=nendb
853 kounta=kountb
854 ktotal=ktotal+kounta
855 adda=.false.
856 GO TO 133
857C
858C *************************************
859C
860C CALCULATE IBIT, THE NUMBER OF BITS NEEDED TO HOLD THE GROUP
861C MINIMUM VALUES.
862C
863C *************************************
864C
865 209 ibit=0
866C
867 DO 220 l=1,lx
868 210 IF(jmin(l).LT.ibxx2(ibit))GO TO 220
869 ibit=ibit+1
870 GO TO 210
871 220 CONTINUE
872C
873C INSERT THE VALUE IN JMIN( ) TO BE USED FOR ALL MISSING
874C VALUES WHEN LBIT( ) = 0. WHEN SECONDARY MISSING
875C VALUES CAN BE PRESENT, LBIT(L) WILL NOT = 0.
876C
877 IF(is523.EQ.1)THEN
878C
879 DO 226 l=1,lx
880C
881 IF(lbit(l).EQ.0)THEN
882C
883 IF(misslx(l).EQ.missp)THEN
884 jmin(l)=ibxx2(ibit)-1
885 ENDIF
886C
887 ENDIF
888C
889 226 CONTINUE
890C
891 ENDIF
892C
893C *************************************
894C
895C CALCULATE JBIT, THE NUMBER OF BITS NEEDED TO HOLD THE BITS
896C NEEDED TO PACK THE VALUES IN THE GROUPS. BUT FIND AND
897C REMOVE THE REFERENCE VALUE FIRST.
898C
899C *************************************
900C
901C WRITE(KFILDO,228)CFEED,LX
902C228 FORMAT(A1,/' *****************************************'
903C 1 /' THE GROUP WIDTHS LBIT( ) FOR ',I8,' GROUPS'
904C 2 /' *****************************************')
905C WRITE(KFILDO,229) (LBIT(J),J=1,MIN(LX,100))
906C229 FORMAT(/' '20I6)
907C
908 lbitref=lbit(1)
909C
910 DO 230 k=1,lx
911 IF(lbit(k).LT.lbitref)lbitref=lbit(k)
912 230 CONTINUE
913C
914 IF(lbitref.NE.0)THEN
915C
916 DO 240 k=1,lx
917 lbit(k)=lbit(k)-lbitref
918 240 CONTINUE
919C
920 ENDIF
921C
922C WRITE(KFILDO,241)CFEED,LBITREF
923C241 FORMAT(A1,/' *****************************************'
924C 1 /' THE GROUP WIDTHS LBIT( ) AFTER REMOVING REFERENCE ',
925C 2 I8,
926C 3 /' *****************************************')
927C WRITE(KFILDO,242) (LBIT(J),J=1,MIN(LX,100))
928C242 FORMAT(/' '20I6)
929C
930 jbit=0
931C
932 DO 320 k=1,lx
933 310 IF(lbit(k).LT.ibxx2(jbit))GO TO 320
934 jbit=jbit+1
935 GO TO 310
936 320 CONTINUE
937C
938C *************************************
939C
940C CALCULATE KBIT, THE NUMBER OF BITS NEEDED TO HOLD THE NUMBER
941C OF VALUES IN THE GROUPS. BUT FIND AND REMOVE THE
942C REFERENCE FIRST.
943C
944C *************************************
945C
946C WRITE(KFILDO,321)CFEED,LX
947C321 FORMAT(A1,/' *****************************************'
948C 1 /' THE GROUP SIZES NOV( ) FOR ',I8,' GROUPS'
949C 2 /' *****************************************')
950C WRITE(KFILDO,322) (NOV(J),J=1,MIN(LX,100))
951C322 FORMAT(/' '20I6)
952C
953 novref=nov(1)
954C
955 DO 400 k=1,lx
956 IF(nov(k).LT.novref)novref=nov(k)
957 400 CONTINUE
958C
959 IF(novref.GT.0)THEN
960C
961 DO 405 k=1,lx
962 nov(k)=nov(k)-novref
963 405 CONTINUE
964C
965 ENDIF
966C
967C WRITE(KFILDO,406)CFEED,NOVREF
968C406 FORMAT(A1,/' *****************************************'
969C 1 /' THE GROUP SIZES NOV( ) AFTER REMOVING REFERENCE ',I8,
970C 2 /' *****************************************')
971C WRITE(KFILDO,407) (NOV(J),J=1,MIN(LX,100))
972C407 FORMAT(/' '20I6)
973C WRITE(KFILDO,408)CFEED
974C408 FORMAT(A1,/' *****************************************'
975C 1 /' THE GROUP REFERENCES JMIN( )'
976C 2 /' *****************************************')
977C WRITE(KFILDO,409) (JMIN(J),J=1,MIN(LX,100))
978C409 FORMAT(/' '20I6)
979C
980 kbit=0
981C
982 DO 420 k=1,lx
983 410 IF(nov(k).LT.ibxx2(kbit))GO TO 420
984 kbit=kbit+1
985 GO TO 410
986 420 CONTINUE
987C
988C DETERMINE WHETHER THE GROUP SIZES SHOULD BE REDUCED
989C FOR SPACE EFFICIENCY.
990C
991 IF(ired.EQ.0)THEN
992 CALL reduce(jmin,jmax,lbit,nov,lx,ndg,ibit,jbit,kbit,
993 1 novref,ibxx2,ier)
994C
995 IF(ier.EQ.714.OR.ier.EQ.715)THEN
996C REDUCE HAS ABORTED. REEXECUTE PACK_GP WITHOUT REDUCE.
997C PROVIDE FOR A NON FATAL RETURN FROM REDUCE.
998 iersav=ier
999 ired=1
1000 ier=0
1001 GO TO 102
1002 ENDIF
1003C
1004 ENDIF
1005C
1006C CALL TIMPR(KFILDO,KFILDO,'END PACK_GP ')
1007 IF(iersav.NE.0)THEN
1008 ier=iersav
1009 RETURN
1010 ENDIF
1011C
1012C 900 IF(IER.NE.0)RETURN1
1013C
1014 900 RETURN
1015 END
subroutine pack_gp(ic, nxy, is523, minpk, inc, missp, misss, jmin, jmax, lbit, nov, ndg, lx, ibit, jbit, kbit, novref, lbitref, ier)
This subroutine determines groups of variable size, but at least of size minpk, the associated max(JM...
Definition pack_gp.f:116
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