$! FIELDEXTRACTOR.COM $! $! This procedure reads a text file and extracts fields from $! various lines. The positions of the fields must be fixed, $! as must be their sizes. $! David Mathog, Biology Division, Caltech $! 23-JUL-1996 $! $! P1 is wildcarded search list of file(s) to search $! P2 is the output file name $! P3 is a comma delimited list containing the extraction triplets $! each quad is LINE,START,WIDTH, and each quad is $! separated from the next by a /, for instance: $! 1,1,10/12,30,10/10,15,5 $! P4 first character fills fields that aren't found $! P5 string to put between output fields, default is nothing (adjoining) $! $! Note, the output of this program could easily be way too wide to look $! at on a terminal! This should only be used for a few files at a time, $! I'm not sure what the limits are. $! $ if (P1 .eqs. "") $ then $ type sys$Input @fieldextractor P1 P2 P3 P4 P5 P1 is a (wildcarded ) file specification = input file(s) to process P2 is the output filename P3 is a comma delimited list of selector triads LINE,COLUMN,WIDTH. Multiple triads are separated by /. Example: "1,1,10/12,30,10/10,15,5" P4 first character fills fields that are not found. Default is a "*". P5 separator string, which is placed between output fields. Default is nothing (output fields abut each other) $ exit $ else $ files = P1 $ endif $ if (P2 .eqs. "") $ then $ write sys$output "FIELDEXTRACTOR: fatal error, no output file specified" $ exit $ else $ open/write/error=badoutput ofil: 'P2' $ endif $ if (P3 .eqs. "") $ then $ write sys$output "FIELDEXTRACTOR: fatal error, no fields specified" $ exit $ else $ rawfields = P3 $ endif $ if (P4 .eqs. "") $ then $ fill = "*" $ else $ fill = f$extract(0,1,P4) $ endif $ if (P5 .eqs. "") $ then $ gap = "" $ else $ gap = P5 $ endif $! $! make up the bigfill string $! $ bigfill = fill + fill $ count = 8 $ topfill: $ bigfill = bigfill + bigfill $ count = count - 1 $ if(count .gt. 0)then goto topfill $! $! break out the triplet information $! $ tcount = 0 $ minline = 2000000000 $ maxline = 0 $ toptriple: $ frag = f$element(tcount,"/",rawfields) $ if(frag .eqs. "/")then goto allfields $ tcount = tcount + 1 $ fl_'tcount' = f$element(0,",",frag) $ fs_'tcount' = f$element(1,",",frag) - 1 $ fw_'tcount' = f$element(2,",",frag) $ if(fl_'tcount' .eqs. "" .or. fs_'tcount' .eqs. "" .or. - fw_'tcount' .eqs. "") $ then $ write sys$output "FIELDEXTRACTOR: fatal error, no fields specified" $ exit $ endif $ if(fl_'tcount' .gt. maxline)then maxline = fl_'tcount' $ if(fl_'tcount' .lt. minline)then minline = fl_'tcount' $ goto toptriple $! $ allfields: $ count = 0 $ loopfile = "#" $ topopen: $ file = f$search(files) $ if(file .eqs. loopfile)then goto allempty $ if(count .eq. 0)then loopfile = file $ if(file .eqs. "")then goto allempty $ open/read/error=badinfile ifil: 'file' $! $! fill output pieces with chunks from bigfill, just $! in case the lines are never encountered $! $ mcount = 1 $ prefill: $ piece_'mcount' = f$extract(0,fw_'mcount',bigfill) $ mcount = mcount + 1 $ if(mcount .le. tcount)then goto prefill $! $! search this file $! $ count = 0 $ topsearch: $ read/end=next/error=next ifil: string $ string = string + bigfill $ count = count + 1 $ if(count .lt. minline)then goto topsearch $ mcount = 1 $ topmatch: $ if(count .eq. fl_'mcount')then piece_'mcount' = - f$extract(fs_'mcount',fw_'mcount',string) $ mcount = mcount + 1 $ if(mcount .le. tcount)then goto topmatch $ if(count .lt. maxline)then goto topsearch $! $! at this point either the whole file, or just as much as lies $! between minline/maxline will have been searched, so write the $! output line $! $ next: $ close/nolog ifil: $ mcount = 1 $ outline = "" $ topout: $ if(mcount .gt. 1)then outline = outline + gap $ outline = outline + piece_'mcount' $ mcount = mcount + 1 $ if(mcount .le. tcount)then goto topout $ write/symbol ofil: outline $! $! return to the top of the input file loop $! $ goto topopen $! $allempty: $ close ofil: $ write sys$output "FIELDEXTRACTOR: normal completion" $ exit $badoutput: $ write sys$output "FIELDEXTRACTOR: fatal error, could not open output file" $ exit $badinfilet: $ write sys$output "FIELDEXTRACTOR: fatal error, could not open an input file" $ write sys$output "FIELDEXTRACTOR: file = ''file'" $ close ofil: $ exit $!