UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:octave_datalogger

This is just some quick code to display a logfile of CSV floating point numbers, refreshing at 1Hz. If there is no data for 30s, the program will quit, and save a postscript file of the graph.

directory="/home/laurence/Desktop/octave/";
write=sprintf("%sdatadump.txt",directory);
read=sprintf("%sdatalog.txt",directory);
filename=sprintf("%sresults.eps",directory);
[fid,msg]=fopen(write,"w");
disp(msg);
[fir,msg2]=fopen(read,"r");
disp(msg2);
fputs(fid,"Octave logger control");
count=zeros(1,10);
disp("\nsetup done\n");
count(30)=1;
while(count(30)>count(1))            #our file is getting bigger
 [fir,msg2]=fopen("/home/laurence/Desktop/octave/datalog.txt","r");
 #puts(msg2);
 [x,count(30)]=fscanf(fir,"%f,%f",Inf);
 #disp(count(30));
 for n=1:29
  count(n)=count(n+1);               #buffer
 endfor
 if count(29)>count(28)
  b=length(x);
  a=x(1:2:b);
  b=x(2:2:b);
  plot(a,"3")
  hold on;
  plot(b,"1");
  title("Datatrace");
  replot();
 endif
 sleep(1)
endwhile
print(filename,"-depsc2");
closeplot();
fclose(fid);
fclose(fir);
code/octave_datalogger.txt ยท Last modified: 2008/07/19 23:33 (external edit)