subroutine read_xbsm(bunches,turns,adc, in_file) implicit none character*100 in_file_0/'one_pass_bsmcxr_adc_4788'/ character*100 in_file, out_file character*2 subdir/'04'/ character*100 file,prefix character*200 string integer number integer iu/1/ integer turn, bunch, adc(0:31,0:4096,183), turns, bunches, adc_count(0:31) integer ios integer ix integer i logical start_flag/.false./ ! prefix = '/nfs/cesr/instr/data/xbsm/dline/raw/'//subdir//'/' prefix = '/nfs/cesrta/xbsm/data/' ! which data file to read print '(a,a,a,$)',' xbsm data file ? ',trim(in_file_0),' ' read(*,'(a)')string call string_trim(string,string,ix) if(ix /= 0 .and. ix /= len(string))in_file_0 = string print *,' ix = ', ix if(ix==4)then read(in_file_0(1:4),'(i4)')number in_file_0 = 'one_pass_bsmcxr_adc_'//in_file_0(1:4)//'.dat' call string_trim(in_file_0, in_file_0, ix) in_file_0 = trim(prefix)//in_file_0(1:ix) endif in_file = in_file_0 print '(a,a)',' in_file = ', in_file print '(a,a)',' in_file = ', in_file ! open file print '(a)',in_file file = in_file open(unit=iu,file = file, type= "old", readonly, IOSTAT=ios ) if(ios /= 0)then if(ios == 6)print *,' File not found ' stop endif start_flag=.false. turn=0 bunch=0 do read(iu,'(a)',IOSTAT=ios)string if(ios /= 0)exit if(index(string,'Here is the data:') /= 0)start_flag = .true. if(index(string,'Here is the data:') /= 0)cycle if(start_flag)then if(turn > 4096 .or. bunch > 170)then print '(a,i,a,a,i,a)',' number of turns is ',turn ,'(4096 allowed) ',' number of bunches =',bunch,'(170 allowed)' stop endif read(string,*,iostat=ios)turn,bunch,adc(0:31,turn,bunch) if(ios /= 0)print '(a,a)',' Error reading string ',string endif end do print '(a,i,a,i)',' number of turns ',turn,' number of bunches ',bunch turns=turn bunches=bunch close(unit=iu) return end