'reads data file of equally spaced data as (x,y<-->real,real) pairs separated by comma or space 'calculates the mean and standard deviation of x and y and autoplots #include "vbcompat.bi" declare sub adjust declare sub help dim as integer im, icount, jcount dim as single dummy, y(1 to 10000), x(1 to 10000), xmin, xmax, ymin, ymax, used, delx, dely, xtextoffset, ytextoffset, digits dim as string strx, stry, filename dim shared as single xr, yr, xx, yy dim shared as string stra, strb dim shared as integer flip1, flip2 'screen resolutions available 'screen 20,24,,, '1024x768 screen 19,24,,, '800x600 'screen 15,24,,, '400x300 filename=command() if filename = "" then filename = "infile.dat" 'filename = "/home/john/Desktop/allords/infile.dat" flip1=1:flip2=0 'next 4 lines initiate linear scaling in y and allow flipping between linear and logarithmic startagain: 'start point when flipping from linear to logarithmic swap flip1, flip2 open filename for input as #1 im=0:ymax=-1.0e+37:xmax=-1.0e+37:ymin=+1.0e+37:xmin=+1.0e+37 do until eof(1) im=im+1 input #1, x(im),y(im) if flip1=1 then y(im)=log(y(im)) if xmax < x(im) then xmax =x(im) if ymax < y(im) then ymax =y(im) if ymin > y(im) then ymin =y(im) if xmin > x(im) then xmin =x(im) loop used=0.08 used=.5-used xr=xmax-xmin:yr=ymax-ymin:xr=xr/2./used:yr=yr/2./used xx=(xmax+xmin)/2.0:yy=(ymax+ymin)/2.0 close #1 color RGB(37,37,208),RGB(240,240,255) do Cls locate 1,1:print "h for help" window (xx-xr/2.,yy-yr/2.)-(xx+xr/2.,yy+yr/2.) delx=used*xr:dely=used*yr:xtextoffset=0.1*delx:ytextoffset=0.025*dely for jcount=0 to 5 line (xx-delx+jcount*.4*delx,yy-0.975*dely)-(xx-delx+jcount*.4*delx,yy-1.025*dely) dummy=xx-delx+jcount*.4*delx strx=Str(Fix(dummy)) Draw String (xx-delx+jcount*.4*delx-xtextoffset,yy-1.025*dely),strx line (xx-0.975*delx,yy-dely+jcount*.4*dely)-(xx-1.025*delx,yy-dely+jcount*.4*dely) dummy=yy-dely+jcount*.4*dely if flip1 = 1 then dummy=Exp(dummy) stry=Str(Fix(dummy)) Draw String (xx-xr/2.,yy-dely+jcount*.4*dely+ytextoffset),stry next jcount line (xx-used*xr,yy-used*yr)-(xx+used*xr,yy-used*yr) 'x-axis line (xx-used*xr,yy-used*yr)-(xx-used*xr,yy+used*yr) 'y-axis line (xx-xr/80,yy)-(xx+xr/80,yy) 'central crosshairs x line (xx,yy-yr/80)-(xx,yy+yr/80) 'central crosshairs y for icount = 2 to im dummy=1 if x(icount-1) < xx-used*xr then dummy=0 if y(icount-1) < yy-used*yr then dummy=0 if x(icount) > xx+used*xr then dummy=0 if y(icount) > yy+used*yr then dummy=0 if dummy=1 then line (x(icount-1),y(icount-1)) - (x(icount),y(icount)),RGB(180,0,0) next icount adjust() if stra ="h" then help() if stra ="f" then if ymin > 0 then reset:goto startagain stry="Can't do Ln(negative number)." Draw String (xx-xr/4.,yy+yr/4.),stry,RGB(255,0,0):sleep 2000 do while inkey <> "":loop 'flush backed up keypresses swap flip1, flip2:reset:goto startagain end if do while inkey <> "":loop 'flush backed up keypresses loop while stra <> "q" end '=========================== sub adjust() dim as integer CurrentX, CurrentY, Mousebuttons dim as single xtrue, ytrue Do stra = Inkey GetMouse CurrentX, CurrentY, , MouseButtons xtrue=xx+xr*(CurrentX/400.-1.)/2. ytrue=yy-yr*(CurrentY/300.-1.)/2 If CurrentY <> -1 then ' If its on the window get result as follows If MouseButtons And 1 Then ' This is left button xx=xx+xr*(CurrentX/400.-1.)/2. yy=yy-yr*(CurrentY/300.-1.)/2. stra ="x":sleep 300 End if ''''''''' If MouseButtons And 4 Then (middle) If MouseButtons And 2 Then ' This is right button xx=xx-xr*(CurrentX/400.-1.)/2. yy=yy+yr*(CurrentY/300.-1.)/2. stra ="x":sleep 300 End if End If if flip1 = 1 then ytrue=Exp(ytrue) end if locate 4,15:print"X,Y Coordinates: ";:print using "#####.##"; xtrue,ytrue Loop While stra = "" if stra="-" then xr=1.1*xr if stra="+" then xr=xr/1.1 if stra="c" then yr=1.1*yr if stra="e" then yr=yr/1.1 if len(stra) > 1 then mid(stra, 1, 1) = chr(255) 'change chr(0) to chr(255) select case lcase(stra) 'make sure is lower case case chr(255) + "h" 'up yy=yy-.01*yr case chr(255) + "p" 'down yy=yy+.01*yr case chr(255) + "k" 'left xx=xx+.01*xr case chr(255) + "m" 'right xx=xx-.01*xr end select end sub '=========================== sub help() cls:print print " Move the chart: up, down, right, left = "+chr(24,0,25,0,26,0,27,0):print print " Move Centre to X,Y Coordinates: Right Click":print print " Move X,Y Coordinates to Center: Left Click":print print " X-axis: expand the scale with +; compress it with -":print print " Y-axis: expand the scale with e; compress it with c":print print " Start again and flip between logarithmic and linear = f":print print " Quit the programme = q":print print " Quit help screen = press any key":print sleep end sub '===========================