How to sum spectra in xmgrace? - batch-file

I have a batch file for xmgrace. When I plot several sets of voltage signal measurements, the batch file Fourier-transforms them all and moves them to a different graph. I would like to add a command to the batch file, that will sum the Fourier-transformed plots of frequency. By that I mean that I want xmgrace to sum together the y values of all the data sets for each x value. All the data sets are the same length. Is there a way to do this?

Never mind, it was very easy. Added s0.y = s0.y + s1.y + s2.y + s3.y to my batch file. This sums all the y-values into one of the sets. I then added kill s1, kill s2, etc. to get rid of the others.

Related

Loop over files of same length and add their column respectively

I have a directory that contains Nfiles text files called myfile_i.txt (with i and integer).
Each text file contains 2 columns (let's call them x and y) and Nsteps rows of floating numbers.
I would like to loop over all the files in the directory and do the following computation in C:
while [condition to go through all files called myfile_i.txt in the directory]
{
for (ii= istart;ii<Nsteps; i++) // with istart>=0 and istart<Nsteps otherwise error
{
dsq[ii]=(x[ii]-x[istart])*(x[ii]-x[istart])+(y[ii]-y[istart])*(y[ii]-y[istart]);
}
}
where istart is an input parameter (integer) that I choose as a starting point in terms of iteration (or if you will, time steps).
Then at the end I would need to devide this result (which I believe it a column vector) by the number of steps (basically, Nsteps-istart).
I used to do something like this in Matlab but I have lots of these large files and loading them all and computing this is too slow for my computer, this is why I want to use (and learn) C.
What should my program look like in order to accomplish this computation?

How do I rename a file with custom pattern in camel?

I am splitting a large file and need to generate filenames like
file.x.y.txt
x is the file split number and y is the total number of splits.
The files are already generated as file.x.txt through some complicated process.
I have this so far:
from("file://out?include=*.txt&move=${file:name}.<how to set this>.txt")
I could not figure out how to pass this to the consumer the y number.

Reading many (1000+) files with dlmread - Loop with varying filenames?

I'm very new to matlab, or coding for that matter.
I'm running a simulation which outputs thousands of files. These files are .vtk and are read correctly by dlmread.
I tried reading one of them, defining it as a matrix and extracting column vectors out of this matrix. This works fine. What i need now is to not only read one of them, but all. The filenames vary by a number, for example cover1000.vtk, cover2000.vtk, ...., cover1200000.vtk.
I want all of them to be read with dlmread and stored as a different matrix. How do i do that? Here is what i have right now, working with one file at a time:
A_1000 = dlmread ('cover1000.vtk') %matrix a containing values from vtk file_in_loadpath
fx_1000 = A(1:20,1) %extracting vector with specific values
fx_ave_1000 = sum(fx_1000)/length(fx_1000) % average of the values in extracted vector
I'm thinking of a loop, but how do i create a loop with varying file names?
Also I've read that a loop is not the best idea, cell arrays would be better. But i have absolutely no idea how to implement any of this.
Thanks for your help!
cheers
You can use the function dir to list all the vtk files in your directory then loop over those files.
filename = dir('*.vtk'); %list all the vtk files in your current directory.
for ii = 1:length(filename)
A = dlmread (filename(ii).name) %matrix a containing values from vtk file_in_loadpath
fx{ii} = A(1:20,1) %extracting vector with specific value
fx_ave{ii} = sum(fx{ii})/length(fx{ii}) % average of the values in extracted vector
end
The results are now stored in two cells: fx and fx_ave.

How to plot several datafiles in consecutive graphs using gnuplot

I have a large number of ASCII files named in order of the form data.xxxx.tab, where "xxxx" is a number between 0000 and 9999. Each file contains 5 columns, where the first is for X-coordinate, second is for Y-coordinate and the remaining three are for variables which I wish to plot against X-coordinate. I need to know how to write a loop in gnuplot 4.6, that could plot consecutive graphs of one of the variables against X-coordinate.
I already tried the instructions given in the following posts:
Plotting with gnuplot from several files
and
gnuplot : plotting data from multiple input files in a single graph
but these created a single graph containing all the curves from all the data files together, whereas what I need are consecutive graphs that are plotted one after another, thus showing the evolution in time of the variable graph.
The following should work:
# fix axes for proper comparison between graphs
set xrange [0:10]
set yrange [0:10]
# if you want an animated gif
set term gif animate
set output 'output.gif'
# then plot your data
do for [n=0:9999]{
plot sprintf("data.%04d.tab", n) using 1:2 title 'case '.n
}
The %04d string inside the sprintf command prints the number n with until four zeros before the minimum field width of n, i.e. n=2 is printed as 0002, and n=9999 is printed as 9999.
I would suggest using a shell script that calls a gnuplot file
file plot.gp:
set term png
set out fname.".png"
set title fname
plot fname w l
and then in the shell:
for fname in data.????.tab; do gnuplot -e fname=\"$i\" plot.gp; done
you'll get a file named data.xxxx.tab.png file for each data.xxxx.tab.

gnuplot Real Time Plotting C Implementation

I'm completely new to gnuplot and have only learned the basics to start plotting. I'm writing a C program that does DSP and needs to plot the result in real time. In addition, I've setup my program in such following manner to incorporate the plot '-' feature from gnuplot. The parent process will perform the DSP computation constantly, and sends the result to the child using pipe in real time. The child will receive a signal from parent, wake up, and sends the result to gnuplot via pipe.
Basically, the path of data goes as such:
Parent(Computation) -> Pipe -> Child (Wait on Input from parent) -> Pipe -> gnuplot (Plotting)
For example, in the child, enclosed in a conditional wait
getline(&lineBuffer, lineSize, stdin);
printf("%s", lineBuffer);
fflush(stdout);
where lineBuffer can be any arbitrary char*, will redirect data from parent to gnuplot. I have all the necessary data for plotting, and it can be formatted in any format. However, after trying the following, there has been no success.
If not yet defined appearances and label,
set terminal x11 persist noraise
set xlabel "Frequency"
set ylabel "Decibel"
set xrange [0:2000]
set yrange [-100:100]
set style data lines
Start initial plot command,
plot '-' using 1:2 smooth unique
Start sending data, each point is a new line, where I formatted my data to be
Frequency Decibel
at a particular time, for example
1000 -30.00
1001 -31.00
....
End data by sending
e\n
Then I restart the process sending the data, and end it with
replot
Does this seem right? On the other hand, I'm also interested in plotting the time series of a particular frequency, and after numerous searches, apparently I need a buffer or a temporary file to accomplish this, is that correct also?

Resources