I have the following Octave code which takes the output from executions of a C program and does some calculations on them and creates graphs. To select which data files to process, I have the for loop (and sometimes I have nested for loops to vary
p, too). But I don't want to select files that way.
I'm running in Linux. Linux usually lets you list files and pass them into programs, or pass the output of one program into another, etc. Is there a way to do that for Octave files, too?
In other words, I want to program it so I can do something like this
ls <select-specific-files> | makeGraph.m
where makeGraph.m would then execute in Octave and process each file? Can I do that in Octave? How?
Here is what makeGraph.m (stripped down) looks like now. Notice how I create fn from the current values of N, beta, pTol, and tStep. That requires me to reprogram the loops each time I want to execute it. Don't worry about the lines inside the loop after u1=csvread...
clear; more off;
tol = 1e-8;
pTol=abs(log10(tol));
tStep = 0;
src = '/raid/fpuData/';
tgt = '/raid/fpuData/graphs/';
ftype = '.U.csv';
% for p=4:6
for beta = [6:45]
% Read the solution file
fn = sprintf('N=%03dx%03d_Beta=%04d_tol=1e-%02d_t=%07d', N, N, beta, pTol, tStep);
fprintf('Loading %s:\t', [fn ftype]);
u1 = csvread([src fn ftype]);
% Transform to fourier space
[U,Udot,W,Wdot] = xformFPU(u1, F);
% Plot it
fn = sprintf('%s%s', tgt, fn);
fprintf('Creating graph: %s\t', fn);
h = plotFPU(N, 'Fixed', beta, D, W, Wdot);
print (h, fn, "-dpdf");
end
% end
The files have names like this:
>ls *.csv
...
N=016x016_Beta=0145_tol=1e-08_t=0000000.U.csv N=032x032_Beta=0165_tol=1e-08_t=0000000.U.csv
N=064x064_Beta=0185_tol=1e-08_t=0000000.U.csv N=128x128_Beta=0300_tol=1e-08_t=0000000.U.csv
N=016x016_Beta=0150_tol=1e-08_t=0000000.U.csv N=032x032_Beta=0170_tol=1e-08_t=0000000.U.csv
N=064x064_Beta=0190_tol=1e-08_t=0000000.U.csv N=128x128_Beta=0400_tol=1e-08_t=0000000.U.csv
N=016x016_Beta=0155_tol=1e-08_t=0000000.U.csv N=032x032_Beta=0175_tol=1e-08_t=0000000.U.csv
N=064x064_Beta=0195_tol=1e-08_t=0000000.U.csv N=128x128_Beta=0500_tol=1e-08_t=0000000.U.csv
N=016x016_Beta=0160_tol=1e-08_t=0000000.U.csv N=032x032_Beta=0180_tol=1e-08_t=0000000.U.csv
N=064x064_Beta=0200_tol=1e-08_t=0000000.U.csv N=128x128_Beta=0600_tol=1e-08_t=0000000.U.csv
...