0

I write a code in Fortran that allows me to draw data directly from a file using gnuplot.

write(10,*) 'plot "Test18.Stop.TXT" u 1:8 title "Force" lt -1 lc rgb "#808080" w lines'

I want to change the name of the data file every time I compile. The problem is that I do not know how to enter the file name as a variable. I have made a few attempts, such as:

open(11,file=Filename)
write(10,*) Filename
write(10,*) 'plot '<Filename>' u 1:8 title "Force" lt -1 lc rgb "#808080" w lines' 
close(11)

and

open(11,file=Filename)
write(10,*) Filename
write(10,*) 'plot "'Filename'" u 1:8 title "Force" lt -1 lc rgb "#808080" w lines' 
close(11).

Filename is a character which has the name of the file data, which should be drawn. When I compile it, I get always this error Error: Syntax error in Write statement at <1> (i.e. at File name).

  • I don't know Fortran, but how would you concatenate strings in Fortran? maybe something like this? `write(10,*) 'plot "' // Filename // '" u 1:8 title "Force" lt -1 lc rgb "#808080" w lines' ` – theozh Jun 07 '20 at 10:28

1 Answers1

0

The comment again as answer, according to the StackOverflow rule: "no answers in comments".

You have to concatenate the strings. Without knowing Fortran but doing a short search, I guess it should be something like this:

write(10,*) 'plot "' // Filename // '" u 1:8 title "Force" lt -1 lc rgb "#808080" w lines'  
theozh
  • 22,244
  • 5
  • 28
  • 72