The program makes use of Perl's file manipulation features as well as powerful string and array control capabilities.
#!/usr/bin/perl $name=$ARGV[0]; ($code,$alt)=split(/\//,$name); $line=`grep $code ../REFINE.CODES`; ($code,$name,$user)=split(/\t/,$line); $code2=$code; $code2=~tr/[A-Z]/[a-z]/; print "TITLE $code - \"$name\" by $user\n"; print "compid $code2\n"; print "master yes\n\n"; print "ADDREF\nreduce ftof2\nhklin hkl frel sigf\nsetid hkl\n"; $h="0"; $k="0"; $l="0"; $page=1; $line=1; do{ while(pop(@page)){} while(<>){ next if(length($_) < 10); next if(/^#/); next if(! /\w/); if(/Page(| )([0-9]+)/) {last if(int($2) > $page);} next if($_=~/[A-Z]/); push(@page,$_); } $n=1; while($n < 5) { print STDERR "Page $page column $n\n"; foreach $_ (@page) { $i=i+20*$n; $HKL=substr($_,$i,18); next if(length($HKL) < 8); if($HKL=~/l/) { ($h,$k,$l)=split(/,/,$HKL); $h=~s/\s//g; $k=~s/\s//g; $l=~s/\s//g; if($l ne "l") {print "Error:($h,$k,$l) \$l ne \"l\"\t\t\"$HKL\"\n";} next; } $HKL=~s/^\s*//; $HKL=~s/ +/,/g; ($l,$fo,$fc,$sf)=split(/,/,$HKL); $hkl=sprintf("%4s%4s%4s%10.2f%8.2f",$h,$k,$l,$fo/10.0,$sf/100.0); print "$hkl\n"; } $n++; } $page=$2; }while(!eof()); print "setid\n\nFINISH\n";
DPPM-H OXO ANION Page 1 Columns are 10Fo 10Fc 100Sig, * for Insignificant l kFo Fc Sig l kFo Fc Sig l kFo Fc Sig l kFo Fc Sig -11, 0, l 10 58 506 3311* 5 68 274 2408* 12 163 94 328 2 194 192 320 11 57 506 3415* 6 362 304 200 13 110 94 1457* 4 275 289 234 -11, 5, l 7 196 149 336 14 57 94 2294* 6 176 177 336 1 125 506 1312* 8 68 149 3105* -10, 5, l 8 62 177 2600* 2 61 506 3167* 9 480 494 186 1 99 94 2037* 10 370 377 171 3 169 153 359 10 71 494 857* 2 360 361 229 -11, 1, l 4 132 153 2006* 11 531 539 160 3 102 361 1798* 1 273 294 237 5 62 153 3013* 12 64 539 845* 4 600 588 171 2 99 294 585* 6 437 481 192 13 365 394 186 5 193 92 373 3 315 328 229 7 66 481 2827* 14 59 394 2489* 6 508 564 200 4 157 328 404* 8 475 534 178 -10, 2, l 7 127 564 1831* 5 162 174 374 9 59 534 3385* 1 71 394 2890* 8 501 559 193 6 64 174 951* 10 338 391 210 2 320 282 225 9 427 432 198 7 63 174 3407* -11, 6, l 3 68 282 3309* 10 229 263 301 8 128 174 468* 1 59 391 3382* 4 122 282 561* 11 363 305 196 .... rest cut off for brevityNote that the flow of incremental hkl values goes down each column of an page in turn before starting on the next page, so the script needs to read in one page at a time and then read each column in turn before proceeding to the next page, all the time keeping track of the current h and k values.
TITLE XXX012 - "sharp7" by P.R.Sharp compid xxx012 master yes ADDREF reduce ftof2 hklin hkl frel sigf setid hkl 0 0 10 5.80 33.11 0 0 11 5.70 34.15 -11 5 1 12.50 13.12 -11 5 2 6.10 31.67 -11 5 3 16.90 3.59 .... lines cut here for brevity 11 4 1 14.60 3.73 11 4 2 5.70 23.88 11 5 0 5.90 24.64 11 5 1 5.80 32.65 11 6 0 31.50 2.22 setid FINISH