*------------------------------------------------------ * ntuplify.F - read data from a text file into a ntuple * * Richard Jones * June 16, 2006 * * The input is read from standard input. The format of * the data is a table with a fixed number of columns * containing numbers with white space separators. The * first line in the file contains the variable names * separated by commas. The variable names can contain * type and range information that are used in the ntuple * column definition according to the following format. * * [][:] * + : any valid Fortran variable name * + : expression [low_limit,high_limit] * + : R for real, I for integer * *------------------------------------------------------ program ntuplify implicit none integer hspace parameter (hspace=60000000) common /pawc/ hq(hspace) common /quest/ iquest(100) common /ntdata/ table(999) real hq integer iquest real table integer itable(999) equivalence (table(1),itable(1)) character*1 ttable(999) integer istat,icycle integer id integer bsize data bsize/1024/ character*80 title character*500 chform character*500 outfile character*500 argv integer iargc integer lenocc external lenocc integer columns integer i C---- Initialization of HBOOK call HLIMIT(hspace) C---- Read and process the data header read(5,'(a500)') chform outfile='ntuple.hbook' title='tabular data' id=1 do i=1,iargc() call getarg(i,argv) if (index(argv,'--id=').eq.1) then read(argv(6:),*) id elseif (index(argv,'--output=').eq.1) then read(argv(10:),'(a490)') outfile elseif (index(argv,'--title=').eq.1) then read(argv(9:),'(a80)') title elseif (index(argv,'--bsize=').eq.1) then read(argv(9:),*) bsize call HBSET('BSIZE',bsize,istat) elseif (argv(1:2).eq.'--') then write(6,*) 'Usage: ntuplify [--id=nn] [--output=fn]', + ' [--bsize=nn] [--title=\'your title\' < inputfile' call exit(9) endif enddo open(unit=50,file=outfile,status='old',err=9) close(unit=50) call HROPEN(50,'RZfile',outfile,'U',bsize,istat) call HSCR(id,0,'') go to 10 9 iquest(10) = 256000 ! extend RZ quota to 2^32 bits call HROPEN(50,'RZfile',outfile,'NQE',bsize,istat) 10 continue C---- Now declare the ntuple and count the columns call HBNT(id,title," "); call HBNAME(id,"data",table,chform) columns=1 i=1 do do while ((i.lt.lenocc(chform)).and. + (chform(i:i).eq.' '.or.chform(i:i).eq.'\t')) i=i+1 enddo if ((ichar(chform(i:i)).ge.ichar('I').and. + ichar(chform(i:i)).le.ichar('N')).or. + (ichar(chform(i:i)).ge.ichar('i').and. + ichar(chform(i:i)).le.ichar('n'))) then ttable(columns)='i' else ttable(columns)='r' endif do while ((i.lt.lenocc(chform)).and. + (chform(i:i).ne.':'.and.chform(i:i).ne.',')) i=i+1 enddo if (chform(i:i).eq.':') then ttable(columns)=chform(i+1:i+1) call CUTOL(ttable(columns)) endif if (index(chform(i:),',').ne.0) then i=i+index(chform(i:),',') else exit endif columns=columns+1 enddo write(6,*) 'There are',columns,' data columns' C---- Now fill the ntuple do read(5,*,end=99) (table(i),i=1,columns) do i=1,columns if (ttable(i).eq.'i') then itable(i)=table(i) endif enddo call HFNT(id); enddo C---- Termination of HBOOK 99 call HROUT(0,icycle,' ') call HREND('RZfile') call exit(0) END