#!/usr/bin/perl open IFILE,"sst.ppm"; $mxv=-100.; $mnv=100.; $h=0; #read data file once to find min and max: while ($aline=){ next if $aline=~m/^#/; @vals=split /\s+/,$aline; $h++; foreach $v (@vals){ next if $v>9999; $mxv=$v if $v>$mxv; $mnv=$v if $v<$mnv; } } $w=@vals; close IFILE ; print "min value=$mnv max value=$mxv width=$w height=$h\n"; $sc=255./($mxv-$mnv); #print header use P3 for ascii, P6 for binary: print PFILE "P6 $w $h 255 "; #read data file again to assign colors: open IFILE,"){ next if $aline=~m/^#/; @vals=split /\s+/,$aline; foreach $v (@vals){ if ($v>9999){ ($r,$g,$b)=(0,0,0); } else{ #STUDENTS: fix the following three lines to assign colors to the $v: #(hint: you may want to use the value of $sc to help you) $g=int 0.; $r=int 255.; $b=int 0.; } #print PFILE "$r $g $b\n"; #use with P3 print PFILE pack("c",$r),pack("c",$g),pack("c",$b); #use with P6 } } close PFILE; print "file sst.ppm was written\n";