-2

I use Fortran 95, and now I'm facing a problem as follows:

  • I have 8 datafiles with 4 columns each one, they are generated by other program (each file contains the solutions of differential equations for different sets of initial conditions).
  • The 4th column is my x variable and the 2nd column is my f(x).
  • So, all I want is to create a new file with 9 columns (with the x in the first and the f(x) of each file in the others columns).
  • However, each file has different values for x (and its respective f), like 1.10, 1.30 and 1.40 in one and 1.15, 1.25 and 1.42 in other.
  • So, it's OK for me to take a "band" in x, like [1.00;1.20] and write in my new file this average value as x, and then run the f(x) in this band under it.

But I couldn't managed how to do it.

atMalkyor
  • 1
  • 1
  • Judging by your tags, you want to plot your data with gnuplot? Why not plot every file like this: `plot 'file1.dat' u 4:2`? –  Nov 19 '16 at 22:25
  • Yeas, I want to plot, but i also have to input in other program the fs for the same xs... – atMalkyor Nov 19 '16 at 22:42
  • 2
    it seems you want to use interpolation to give all your data sets the same x-vals. This is really out of scope of this site until you have some code you are having trouble with. – agentp Nov 19 '16 at 22:52
  • Thanks, i guess this is what i want. – atMalkyor Nov 20 '16 at 23:59

1 Answers1

1

I would try plotting the files with a smooth csplines option into a temporary file:

set format x "%10.3f"
set format y "%10.3f"

set xrange [...]
set samples ...

set table "temp1.dat"
plot 'file1.dat' using 4:2 smooth csplines
unset table

This works if you can live with the spline interpolation. There is no way to print linearly interpolated points in csv format. You might want to learn a bit of Fortran (ask whether you will need it for your further research) to do the linear interpolation. Or any other programming language.

To plot all files with one command check for example the answers on Loop structure inside gnuplot?

Then, on linux, you can combine the generated data using colrm and paste.

cat temp1.dat | colrm 11 > x
cat temp1.dat | colrm 1 11 | colrm 12  > y1
cat temp2.dat | colrm 1 11 | colrm 12  > y2
...

paste x y1 y2 ... > combined.dat

Adjust the constants as needed.

Again, learning a programming language might also help.

Community
  • 1
  • 1
maij
  • 4,094
  • 2
  • 12
  • 28