*-------------------------------------------------------------------------- * File and Version Information: * $Id$ * * Description: * KUIP macro IDFINDER tries to find a histogram or ntuple given * its title. Returns histogram ID as a macro return value. Returns 0 * when cannot find histo with the specified name * * Typical usage: * * exec idfinder 'My funny histo' | call IDFINDER * ID = [@] | get its return value * * always check it and do some nice things when it is absent * if [ID] = 0 then * message 'ALERT: someone has stolen my funny histo' * exec ASK 'Who has stolen my funny histo?' * exec ASK 'Who has stolen my funny histo?!!' * exec ASK 'WHO HAS STOLEN MY FUNNY HISTO?!!!!!!!!!' * exec CALL_FBI 'My funny histo was stollen by aliens.' * endif * * Environment: * Software developed for the BaBar Detector at the SLAC B-Factory. * * Author List: * A.Salnikov * * Copyright Information: * Copyright (C) 1997 Saclay * *-------------------------------------------------------------------------- macro idfinder Application Comis Quit integer function idfinder(t1,t2,t3) character *30 t1, t2 character *20 t3 character *80 title integer LUN logical opened character *98 line idfinder = 0 ! return value title = t1//t2//t3 c --- find free lun --- do lun = 15,99 inquire ( UNIT=LUN, OPENED=opened ) if ( .not. opened ) goto 10 enddo print *,'*** IDFINDER: cannot find free LUN ***' return 10 open( LUN, STATUS='SCRATCH', IOSTAT=istat, ERR=98 ) 98 if ( istat .ne. 0 ) then return endif c --- make H/LIST in the temporary file --- call HOUTPU(LUN) call HLDIR(' ',' ') call HOUTPU(6) c --- scan all histogram lines --- rewind(LUN) do while ( .true. ) read ( LUN, '(A)', END=99, ERR=99 ) line if ( line(13:13) .eq. '(' .and. line(15:15) .eq. ')' ) then if ( line(19:) .eq. title ) then read ( line, '(I11)' ) id close(LUN) idfinder = id return endif endif enddo 99 close(LUN) end Quit * handle 32-symbols parameter limit for KUIP t1 = $substring([1],1,30) t2 = ' ' t3 = ' ' if ( $len([1]) > 30 ) then t2 = $substring([1],31,30) endif if ( $len([1]) > 60 ) then t3 = $substring([1],61,20) endif * call COMIS' idfinder exitm $icall('idfinder('$QUOTE([t1])','$QUOTE([t2])','$QUOTE([t3])')') return