C   11/07/79 C9071101   MEMBER NAME  ZBOS12   (S)           FORTRAN
      SUBROUTINE BSCOM
C     ------------------------------------------------------------------
C
C
C     APPENDIX B.    APPLICATION PROGRAMS
C
C
C
C     THE SUBROUTINE DESCRIBED HERE USE BANK STORAGE OF LOW
C     PRIORITY. THEY CAN BE USED FOR COUNTING, HISTOGRAMMING,
C     STORING OF VECTORS ETC. AND MAY BE USEFUL IN THE TESTING
C     PHASE OF LARGE PROGRAMS.
C     THE TOTAL NUMBER OF WORDS USED IN THE BANK COMMON /BCS/ CAN
C     NEVER EXCEED NADD WORDS (NADD IS AN ARGUMENT OF BINT).
C     THE SUBROUTINES START WITH A LETTER U FOR A NEW ENTRY, AND
C     WITH A LETTER P FOR PRINTOUT.
C
C     THE ARGUMENT N IN THE CALLS SHOULD ALWAYS BE A POSITIVE
C     INTEGER WITH LESS THAN 9 DIGITS.
C
C
C     B.1  PRINTOUT AND COMMENTS
C
C     FOR ALL APPLICATION PROGRAMS DESCRIBED IN APPENDIX A.2 TO A.6
C     PRINTOUT CAN BE DONE USING ONE CALL
C
C     CALL PALL
C
C
C
C     FOR SEVERAL APPLICATION PROGRAMS DESCRIBED IN THIS APPENDIX
C     COMMENT CAN BE DEFINED BY THE FOLLOWING CALLS. THIS COMMENT
C     IS PRINTED TOGETHER WITH THE RESULT
C
C                                         -NOT YET AVAILABLE-
C     CALL TCOND(N,'COMMENT    $')
C        COMMENT FOR UCOND
C
C     CALL TTABL(N,'COMMENT    $')
C        COMMENT FOR UTABL
C
C     CALL THIST(N,'COMMENT    $')
C        COMMENT FOR UHIST
C
C     CALL TCORR(N,'COMMENT    $')
C        COMMENT FOR UCORR
C
C     CALL TSTOR(N,'COMMENT    $')
C        COMMENT FOR USTOR/USTOS
C
C     CALL TMEAN(N,'COMMENT    $')
C        COMMENT FOR UMEAN
C
C     CALL TPEAK(N,'COMMENT    $')
C        COMMENT FOR UPEAK
C
C     CALL TLIND(N,'COMMENT    $')
C        COMMENT FOR ULIND
C
C     CALL TEMPF(N,'COMMENT    $')
C        COMMENT FOR UEMPF
C
C     THE COMMENT-TEXT IS DELIMITED BY A $ SIGN, MAXIMUM NUMBER
C     OF CHARACTERS IS 60.
C
C
C     A BANK WITH NAME 'TEX*' IS USED FOR EACH COMMENT.
C
C
C     B.2  COUNT IN A 32768 * 32768 ARRAY
C
C                - -
C     CALL UCOND(I,J)
C        INCREASE COUNT IN ELEMENT I,J BY ONE.
C        0 .LE. I .LE. 32767  AND 0 .LE. J .LE. 32767
C
C     CALL PCOND
C        PRINT ALL ELEMENTS .NE. 0. ALL BANKS USED ARE DELETED.
C
C                - -
C     CALL QCOND(I,J,NR)
C                    --
C        WHERE I,J = INDICES OF ELEMENT
C               NR = NUMBER OF COUNTS IN ELEMENT
C
C     BANKS (CON*,IJ) OF LENGTH 8(+4) ARE USED, WHERE IJ IS CALCULATED
C     FROM I AND J.
C
C
C     B.3  COUNT IN A 256 * 16 ARRAY
C
C                - - -
C     CALL UTABL(N,I,J)
C        INCREASE COUNT IN ELEMENT I,J BY ONE.
C        0 .LE. I .LE. 255  AND  0 .LE. J .LE. 15.
C        MAXIMUM COUNT IN ONE ELEMENT IS 65535.
C
C                -
C     CALL PTABL(N)
C        THE I/J ARRAY NUMBER N IS PRINTED. FOR N=0 ALL ARRAYS
C        ARE PRINTED.
C
C                - -
C     CALL QTABL(N,I,AR)
C                    --
C        WHERE AR( ) = ARRAY OF LENGTH 16 CONTAINING THE COUNTS
C                      IN THE I-ROW OF ARRAY NUMBER N.
C
C     A BANK (TAB*,N*16+I/16) OF LENGTH 128(+4) IS USED FOR EACH
C     FILLED 16 * 16 SUBARRAY.
C
C
C     B.4  HISTOGRAM
C
C                - -
C     CALL UHIST(N,X)
C        ADD NEW ENTRY X INTO HISTOGRAM N WITH 100 BINS. THE BIN SIZE
C        IS CHOOSEN AUTOMATICALLY, UNLESS DHIST IS USED.
C
C                - -- --
C     CALL DHIST(N,XL,XH)
C        FOR HISTOGRAM N THE VALUES XL AND XH ARE DEFINED AS LOWER
C        AND UPPER LIMITS, RESP.. (MUST BE CALLED BEFORE UHIST).
C
C                -
C     CALL PHIST(N)
C        THE HISTOGRAM N IS PRINTED, TOGETHER WITH MEAN VALUES ETC.
C        FOR N=0 ALL HISTOGRAMS ARE PRINTED.
C
C                -
C     CALL QHIST(N,Q)
C                  -
C
C        WHERE Q( ) = ARRAY OF LENGTH 115 FOR CONTENT OF
C        HISTOGRAM N (SEE BELOW).
C
C        I               Q(I)
C
C        1 . . . 100     CONTENT OF HISTOGRAM BINS
C        101             NR OF ENTRIES (TOTAL)
C        102             LOWEST BIN LEFT EDGE
C        103             BIN SIZE
C        104             NR OF ENTRIES OUTSIDE LOW
C        105             NR OF ENTRIES OUTSIDE HIGH
C        106             MIMIMUM VALUE OF X
C        107             MAXIMUM VALUE OF X
C        108             MEAN VALUE
C        109             MEDIAN (50 PC VALUE)
C        110             STANDARD DEVIATION
C        111                   . . .        FROM QUANTILES
C        112             QUANTILES   16 PC
C        113                . . .    84 PC
C        114                . . .   2.3 PC
C        115                . . .  97.7 PC
C
C     A BANK (HST*,N) OF LENGTH 120(+4) IS USED FOR EACH HISTOGRAM.
C
C
C     B.5  CORRELATION PLOT
C
C                - - -
C     CALL UCORR(N,Y,X)
C        ADD NEW ENTRY Y,X TO CORRELATION PLOT N WITH
C        50 * 100 BINS. BIN SIZE IS ALWAYS CHOOSEN AUTOMATICALLY.
C
C                -
C     CALL PCORR(N)
C        THE CORRELATION PLOT N IS PRINTED ON ONE PAGE TOGETHER
C        WITH PROJECTIONS AND MEAN VALUES.
C        BINS WITH CONTENT .NE. 0 ARE PRINTED AS A X. FOR N=0
C        ALL CORRELATION PLOTS ARE PRINTED.
C
C     A BANK (COR*,N) OF LENGTH 380(+4) IS USED FOR EACH
C     CORRELATION PLOT.
C
C
C
C     B.6  STORE VECTORS
C
C                - -- ----
C     CALL USTOR(N,AR,NDIM)
C        STORE VECTOR AR(1) . . . AR(NDIM) IN STORAGE N. THE
C        ARGUMENT NDIM SHOULD ALWAYS BE THE SAME FOR A GIVEN
C        STORAGE N.
C
C     NOTE. USTOR IS AN ENTRY OF USTOS. IF USTOS IS NOT CALLED,
C     USE A STATEMENT
C        EXTERNAL USTOS
C
C
C
C
C                - -- -- -- --
C     CALL USTOS(N,A1,A2,A3,A4)
C        STORE VECTOR A1, . . . IN STORAGE N. THE NUMBER OF ELEMENTS
C        IN A VECTOR MAY BE BETWEEN 1 AND 4 (VARIABLE NR OF ARGUMENTS
C        ALLOWED), BUT SHOULD ALWAYS BE THE SAME FOR A GIVEN
C        STORAGE N.
C
C     THE NUMBER OF VECTORS STORED IN A STORAGE IS LIMITED TO 100.
C     THIS LIMIT CAN BE CHANGED BY DSTOR.
C
C                ---
C     CALL DSTOR(LIM)
C        THE LIMIT ON THE NR OF VECTORS IS SET TO LIM.
C
C                -
C     CALL PSTOR(N)
C        THE VECTORS STORED IN STORAGE N ARE PRINTED. FOR N=0
C        THE VECTORS OF ALL STORAGES ARE PRINTED.
C
C     A BANK (STO*,N) IS USED FOR EACH STORAGE. THE STORAGE IS USED
C     AS FOLLOWS.
C
C     INDEX OF THE BANK       CONTENT
C            +1               NUMBER OF STORED VECTORS
C            +2               LENGTH OF ONE VECTOR
C            +3               (USED INTERNAL)
C            +4               1. ELEMENT OF 1. VECTOR
C            +5               2. ELEMENT OF 1. VECTOR
C            +6                    ETC
C
C
C     B.7  DETERMINE MEAN VALUES
C
C     THE MEAN VALUE IS DETERMINED FOR ENTRIES X. ENTRIES
C     HAVING A LARGE DEVIATION FROM THE AVERAGE X VALUE ARE
C     NOT USED. INTERNALLY A SMALL HISTOGRRAM IS MADE.
C     THREE DIFFERENT MEASURES FOR THE CENTER OF THE DISTRI-
C     BUTION ARE CALCULATED, THE USUAL MEAN FOR THE ENTRIES
C     INSIDE THE HISTOGRAM, THE TRIMMED MEAN, WHICH DETERMINES
C     THE MEAN FROM THE INNER 54 PERCENT OF THE HISTOGRAM,
C     AND THE MEDIAN (50 PERCENT VALUE OF HISTOGRAM). USUALLY
C     THE TRIMMED MEAN IS THE BEST MEASURE.
C
C                -- -- -
C     CALL UMEAN(N,KA,X)
C
C        ADD NEW ENTRY X TO MEAN VALUES N,KA.
C        THE KA-VALUE MAY BE BETWEEN 0 AND KAMAX,
C        IF SPACE IS RESERVED BY DMEAN(NA,KAMAX)
C
C                -- -----
C     CALL DMEAN(N,KAMAX)
C
C        FOR MEAN VALUES N,0 TO N,KAMAX SPACE IS RESERVED.
C        IF NOT CALLED, KAMAX=0 IS ASSUMED.
C
C
C                --
C     CALL PMEAN(N)
C        MEAN VALUES N,... ARE PRINTED. FOR N=0 ALL
C        MEAN VALUES ARE PRINTED.
C
C                -- --
C     CALL QMEAN(N,KA,Q)
C                      -
C        WHERE Q( ) = ARRAY OF LENGTH 10 FOR MEAN VALUE
C                     INFORMATION
C
C         I       Q(I)
C         1       NR OF ENTRIES TOTAL
C         2       MEAN
C         3       TRIMMED MEAN
C         4       MEDIAN
C         5       SIGMA (AVERAGE)
C         6       SIGMA (LEFT)
C         7       SIGMA (RIGHT)
C         8       NR OF ENTRIES OUTSIDE X-RANGE
C         9       LOWER LIMIT OF X-RANGE
C        10       UPPER LIMIT OF X-RANGE
C
C     A BANK (MEA*,N) IS USED WITH LENGTH 50*(KAMAX+1).
C
C
C
C     B.8  DETERMINE PEAK VALUES        -NOT YET AVAILABLE-
C
C     THE PEAK VALUE IS SEARCHED FOR IN THE DISTRIBUTION OF
C     ENTRIES X. INTERNALLY A HISTOGRRAM IS MADE, WHICH IS
C     ANALYSED USING STATISTICAL METHODS TO FIND THE LARGEST
C     PEAK CONSISTENT WITH A RAW DESCRIPTION.
C
C                -- -- -
C     CALL UPEAK(N,KA,X)
C
C        ADD NEW ENTRY X TO PEAK SEARCH N,KA.
C        THE KA-VALUE MAY BE BETWEEN 0 AND KAMAX,
C        AS GIVEN IN DPEAK.
C
C                - ----- -- -- ----
C     CALL DPEAK(N,KAMAX,XA,XZ,FWHM)
C
C        FOR PEAK SEARCHES N,0 TO N,KAMAX SPACE IS RESERVED.
C        IF NOT CALLED, FOLLOWING CALLS TO UPEAK ARE IGNORED.
C        THE ARGUMENTS GIVE A RAW DESCIPTION OF THE PEAK.
C        XA,XZ  = LOWER AND UPPER POSSIBLE VALUES OF PEAK POSITION
C        FWHM   = EXPECTED FULL WIDTH AT HALF MAXIMUM OF THE PEAK
C
C                -
C     CALL PPEAK(N)
C        RESULTS ON PEAK SEARCHES N,... ARE PRINTED, TOGETHER WITH
C        HISTOGRAMS. FOR N=0 ALL RESULTS ARE PRINTED, BUT WITHOUT
C        HISTOGRAMS.
C
C
C                - --
C     CALL QPEAK(N,KA,Q)
C                     -
C        WHERE Q( ) = ARRAY OF LENGTH 6 FOR PEAK SEARCH RESULTS
C
C         I       Q(I)
C         1       NR OF ENTRIES TOTAL
C         2       PEAK POSITION
C         3       SIGMA
C         4       FWHM
C         5       FRACTION OF ENTRIES WITHIN +- 1 STANDARD DEVIATIONS
C         6       FRACTION OF ENTRIES WITHIN +- 3 STANDARD DEVIATIONS
C
C     A BANK (PEA*,N) IS USED WITH LENGTH UP TO 10+100*(KAMAX+1).
C
C
C
C     B.9  STORE SINGLE VALUES
C
C                - -- -
C     CALL USSTO(N,KA,X)
C        STORE VALUE X IN STORAGE N,KA. KA VALUES ARE ALLOWED
C        BETWEEN 0 AND KAMAX, IF SPACE IS RESERVED BY
C        DSSTO(N,KAMAX).
C
C
C                - ----- ---
C     CALL DSSTO(N,KAMAX,IEN)
C        FOR STORAGE N,0 TO N,KAMAX SPACE IS RESERVED FOR UP TO
C        IEN ENTRIES EACH. IF NOT CALLED, KAMAX=0 AND IEN=100.
C
C                - --
C     CALL QSSTO(N,KA,Q,NQ,NENT)
C                     - -- ----
C
C        WHERE Q( ) = ARRAY OF LENGTH IEN, CONTAINING NQ SINGLE
C                     X-VALUES FROM A TOTAL OF NENT X-VALUES
C
C     A BANK (SST*,N) IS USED WITH LENGTH 1+(IEN+1)*KAMAX.
C
C
C
C
C     B.10  BIN DEFINITION
C
C     THE BIN NUMBER LB OF A VALUE X IN A BIN DEFINITION
C     DEFINED BY A BANK ('$BIN',NC) IS OBTAINED BY
C              -- -
C     LB = LBN(NX,X)
C
C     THE BANK ('$BIN',NX) MAY BE DEFINED BY DATA CARDS, READ BY
C     BREADC, AND MUST BE OF ONE OF THE FOLLOWING FORMS.
C
C     $BIN NX  XL XH                        ( NB=100 ASSUMED)
C     $BIN NX  XL XH NB                     ( NB LESS EQUAL 1000)
C     $BIN NX  X1 X2 X3 X4 . . . XL         ( NB = L-1, L AT LEAST 4)
C
C     XL AND XH ARE THE LOWER AND UPPER LIMITS OF ALL NB BINS.
C     X1, X2, X3 . . . ARE THE LOWER LEFT EDGES OF THE BINS,
C     SORTED IN ASCENDING ORDER.
C
C     FUNCTION LBN(N,X) RETURNS WITH 0, IF NO CORRESPONDING
C     BANK IS STORED. IT RETURNS 0 OR NB+1 FOR X VALUES OUTSIDE
C     THE BIN DEFINITION.
C
C     THE LIMITS XL AND XH OF A GIVEN BIN NR LB FOR BIN DEFINITION NX
C     IS OBTAINED BY
C               -- --
C     CALL VLBN(NX,LB,XL,XH,NB)
C                     -- -- --
C     NB IS THE TOTAL NR OF BINS.
C
C
C     B.11  INTERPOLATION OF TABULATED DATA
C
C     USING THE SPLINE INTERPOLATION PROGRAM CUBSPL THE FUNCTION
C     BFUN GIVES THE INTERPOLATED FUNCTION VALUE (BDER THE FIRST
C     DERIVATIVE) AT A GIVEN X VALUE FOR TABULATED DATA, WHICH ARE
C     STORED IN A BANK ('$FUN',N) AND E.G. READ IN FROM CARDS
C     BY BREADC.
C
C     $FUN N  Y1 X1  Y2 X2  Y3 X3  Y4 X4 . . .
C
C     (X VALUES IN ASCENDING ORDER, AT LEAST 3 Y,X PAIRS)
C
C                 - -
C     YI   = BFUN(N,X)        INTERPOLATED FUNCTION VALUE
C
C                 - -
C     YDER = BDER(N,X)        FIRST DERIVATIVE
C
C
C     AT THE FIRST ENTRY A BANK ('+FUN',N) IS CREATED, WHICH CONTAINS
C     THE SPLINE COEFFICIENTS. ITSLENGTH IS 5*NR OF Y,X PAIRS.
C
C     A PLOT OF THE FUNCTION N IS OBTAINED BY
C
C     CALL PFUN(N)
C
C
C     B.11  DETERMINATION OF A LINEAR DEPENDENCE Y(X)-NOT YET AVAILABLE-
C
C     A LINEAR DEPENDENCE OF Y ON X CAN BE DETERMINED BY THE FOLLOWING
C     CALL FROM PAIRS OF Y,X VALUES. INTERNALLY USSTO IS USED.
C
C                -- ----- --- -- -- -- --
C     CALL DLIND(NA,KAMAX,IEN,YL,YH,XL,XH)
C
C     FOR LINEAR DEPENDENCES N,0 TO N,KAMAX SPACE IS RESERVED FOR UP
C     TO IEN PAIRS. YL,YH AND XL,XH ARE THE LIMITS FOR THE Y AND
C     X VALUES.
C
C
C
C                - -- - -
C     CALL ULIND(N,KA,Y,X)
C
C     ADD NEW Y,X PAIR TO LINEAR DEPENDENCE N,KA, IF Y AND X ARE
C     WITHIN THE LIMITS DEFINED BY DLIND.
C
C                -
C     CALL PLIND(N)
C
C     THE RESULT INCLUDING INTERCEPT AND SLOPE OF THE LINEAR
C     DEPENDENCES NA,0 TO NA,KAMAX ARE PRINTED.
C
C                - --
C     CALL QLIND(N,KA,Q)
C                     -
C
C        WHERE Q( ) = ARRAY OF LENGTH 10 FOR INFORMATION ON
C                     LINEAR DEPENDENCE N,KA
C
C      I      Q(I)
C      1      NR OF ENTRIES STORED
C      2      INTERCEPT
C      3      SLOPE
C      4      ERROR OF SLOPE
C      5      MEAN X
C      6      MEAN Y
C      7      ERROR OF MEAN Y
C      8      MEAN SIGMA OF SINGLE POINT
C      9      NR OF DELETED POINTS
C     10      NR OF TOTAL ENTRIES
C
C     THE METHOD USED FOR THE DETERMINATION OF THE LINEAR
C     DEPENDENCE ALLOWS A BACKGROUND CONTRIBUTION OF ABOUT
C     20 PERCENT OF RANDOMLY DISTRIBUTED Y,X PAIRS. THE FRACTION
C     OF DELETED POINTS BEFORE THE ACTUAL LINEAR FIT IS GIVEN
C     IN Q(9).
C
C     A BANK (LIN*,N) IS USED OF LENGTH 6 WORDS PLUS THE
C     CORRESPONDING BANK (SST*,N)
C
C
C
C     B.13  DETERMINATION OF AN EMPIRICAL FUNCTION
C
C
C     A FUNCTIONAL DEPENDENCE OF Y ON X CAN BE DETREMINED BY THE
C     FOLLOWING CALLS FROM PAIRS OF Y,X VALUES. INTERNALLY UMEAN
C     IS USED, THE RESULT IS STORED A BANK $FUN,N.
C
C                - --
C     CALL DEMPF(N,NX)
C
C     FOR EMPIRICAL FUNCTION N, THE BIN DEFINITION NX IS TO BE
C     USED FOR THE X-VALUES. THE MEAN OF THE Y-VALUES WITHIN
C     EACH X-BIN WILL BE DETERMINED.
C
C
C                - - -
C     CALL UEMPF(N,Y,X)
C
C     ADD NEW Y VALUE INTO THE BIN DEFINED BY THE X VALUE AND THE
C     BIN DEFINITION NX.
C
C     CALL PEMPF(N)
C
C     THE RESULT IS PRINTED, A BANK $FUN,N IS CREATED WITH MEAN
C     Y VALUES AND THE CENTRAL X VALUE FOR EACH BIN.
C
C     THE METHOD ALLOWS A CERTAIN BACKGROUND IN THE DATA.
C
C     A BANK (EMP*,N) IS USED OF LENGTH 2+LENGTH OF $BIN BANK
C     PLUS THE CORRESPONDING BANK (MEA*,N).
C
C
C
C
C
C
C
      RETURN
      END
