#!/usr/bin/env python from os import system import sys, string ifile=open('bathym.dat','r') pfile=open('plot.ppm','w') mxv=-100. mnv=100. h=0 while 1: aline=ifile.readline() if not aline: break if aline[0]=="#": continue #splits aline at white space, then eval turn strings to number. #map appies eval to each member of the list: vals=map(eval,string.split(aline)) h=h+1 for v in (vals): if (v>9999): continue mxv=max(mxv,v) mnv=min(mnv,v) w=len(vals) ifile.close() print "min value=",mnv," max value=",mxv,' width=',w,' height=',h sc=255./(mxv-mnv) sc=255./mxv #print header pfile.write("P3\n") #use P3 for ascii, P6 for binary pfile.write("%d %d\n" % (w, h)) pfile.write("255\n") ifile=open('bathym.dat','r') while 1: aline=ifile.readline() if not aline: break if aline[0]=="#": continue vals=map(eval,string.split(aline)) for v in (vals): if (v<0): (r,g,b)=(0.,0.,0.) else: g=0. r=sc*(v-0.) b=255-r pfile.write("%d %d %d\n" % (r,g,b)) #use with P3 # pfile.write("%c%c%c" % (red,green,blue))#use with P6 ifile.close pfile.close()