#/usr/local/bin/perl
$d1=time;
open( INTEXT,
"<c\:\\seer\\populations\\white_black_other\\yr1973_2007.seer9\\19agegroups.txt"
);
open( OUTTEXT, ">c\:\\seer\\stx\\pops.txt" );
@popsw = ( 4, 7, 2, 1, 1, 1, 2, 10 );
@popvars = (
	'popyear', 'X0',     'popseer', 'poprace',
	'origin',  'popsex', 'popage',  'population'
);
print @popsw + 0;
@picks = ( 0, 2, 3, 5 .. 7 );
@popvars = @popvars[@picks];
print "\n@popsw\n";
print "@popvars\n";
printf OUTTEXT ( "%s\t" x @popvars ) . "\n", @popvars;
$line = " ";
while ( $line ne "" ) {  # this only takes about 10 seconds
#for ( $i = 0 ; $i < 2 ; $i++ ) {
	$line = <INTEXT>;

	#	print "$line";
	$pnt = 0;
	for ( $j = 0 ; $j < ( @popsw - 0 ) ; $j++ ) {

		#		print $j;
		$fld[$j] = substr( $line, $pnt, $popsw[$j] );
		$pnt = $pnt + $popsw[$j];
	}
	@fld    = @fld[@picks];
	$format = ( "%d\t" x @fld ) . "\n";
#	print "$format\n";
#	@format=split /\t/, $format;   
#	@format=split /\s+/, $format;   
#	print @format;
#	$format=(join "\t",@format) . "\n";   
#	print "$format\n";
	#	printf $format, @fld;
	#	print  "\n@fld\n";
	printf OUTTEXT $format, @fld;
}
close INTEXT;
close OUTTEXT;
print "done!\n";
$d2=time;
print $d2-$d1;
exit
