C C C----------------------------------------------------------------------------- C C SUBROUTINE: G E M I N D C C AUTHOR: Han Lasance C C DATE: 15-FEB-82 C C VERSION: 1.0 C C MODIFIED BY: C C PURPOSE: To fill array GEM with interpolated indices in the C order of descending corresponding values in array C IKL. C C DESCRIPTION: C Example: C In the figure below GEM(1) will be a value C between 5 and 6, GEM(2) a value between 1 and 2 C C l C IKL(I) l l C l l l C l l l l l C l l l l l . . . . . l l C ----------------------------- . . . . . ------------ C Index I: 1 2 3 4 5 NKL-1 NKL C ^ ^ ^ ^ C Values: 0-99 100-199 .. .. .. .. . . . . . .. 3900-4095 C (NKL=40) C C SEARCH PROCEDURE: C C - Find maximum (MAX) and biggest neighbour (BNE) in array IKL C starting from the top(J=1), from the beginning (J=3) and C between those two maxima(J=2). C - If BNE > MAX/2 then FAC:= BNE/MAX (0 < FAC <= 1.) C else FAC:= 0. C - GEM(J) := (Index(MAX)+FAC*Index(BNE))/(FAC+1) so that if: C FAC = 0: GEM(J) = Index(MAX) C FAC = 1: GEM(J) = (Index(MAX)+Index(BNE))/2 C C C INPUT FILES: None C C OUTPUT FILES: None C C LUNS: None C C BATCH: Not used C C EVENT FLAGS: None C C CALL: GEMIND (IKL, NKL, GEM, NGEM) C C ARGUMENTS: NAME DESCRIPTOIN C I IKL Histogram array containing the number of C occurrences of a certain value range. C I NKL Number of elements in array IKL. C O GEM Array which will be filled with real numbers, C indicating an interpolated index pointing to a C max. in the histogram. The order in which they C are stored is from high to low. C I NGEM The number of maxima wanted in array GEM. C O NGEM: The number of maxima wanted in array GEM. C C CALLS TO: None C C PARAMETERS: NAME DESCRIPTION C C BUILDING: None C C----------------------------------------------------------------------------- C C C C SUBROUTINE GEMIND (IKL, NKL, GEM, NGEM) C C INTEGER IKL(1) REAL GEM(1) DO 30 J=1,NGEM MAX=IKL(1) DO 10 I=2,NKL IF(IKL(I).LE.MAX) GO TO 10 MAX=IKL(I) ISAV=I 10 CONTINUE IS1=ISAV-1 IF(ISAV.EQ.NKL) GO TO 20 IF(IKL(ISAV+1).GT.IKL(ISAV-1)) IS1=ISAV+1 20 FAC=0. IF(IKL(IS1).GT.IKL(ISAV)/2) FAC=FLOAT(IKL(IS1))/FLOAT(IKL(ISAV)) GEM(J)=(FLOAT(ISAV)+FAC*FLOAT(IS1))/(1.+FAC) IKL(ISAV)=-1 ! Don't look at this one any more IF(ISAV.NE.1) IKL(ISAV-1)=-1 ! Don't look at this one any more IF(ISAV.NE.NKL) IKL(ISAV+1)=-1 ! Don't look at this one any more 30 CONTINUE DO 50 I=1,NGEM ISAV=0 RMAX=GEM(I) DO 40 J=I+1,NGEM IF(GEM(J).LE.RMAX) GO TO 40 RMAX=GEM(J) ISAV=J 40 CONTINUE IF(ISAV.EQ.0) GO TO 50 TEMP=GEM(I) GEM(I)=GEM(ISAV) GEM(ISAV)=TEMP 50 CONTINUE RETURN END