1

I want to plot JCAMP-DX formatted spectrum. It has multiple records for y axis in one row and specified increment for x axis.

Simple example: linear plot (1,1) to (12,12)
1 1 2 3
4 4 5 6
7 7 8 9
10 10 11 12

First column represents x axis and second to fourth column represent y axis with each consequent y data belonging to x incremented by one. I can plot it with command:
plot "test.gnuplot" using 1:2 linecolor "black" with dots, "test.gnuplot" using ($1+1):3 linecolor "black" with dots, "test.gnuplot" using ($1+2):4 linecolor "black" with dots
However, the spectrum is much more complicated and I would like to plot it with lines, which is not possible using above mentioned method (lines wouldn´t connect and would create ugly intersections at nonlinear regions of plot).
For now I plot just the second column (using 1:2), but that lowers the resolution.
I want to avoid using external filters (awk etc.) and editing the input file (vim etc.).

real data (skip first 35 lines -- data specification): http://webbook.nist.gov/cgi/cbook.cgi?JCAMP=C7664417&Index=1&Type=IR

andowero
  • 439
  • 4
  • 13

1 Answers1

0

You want to avoid external tools, but maybe creating a temporary file with gnuplot itself is acceptable?

I have taken the real data from webbook.nist.gov, and I have removed the comment lines and the last data line which has less y values than the other lines.

This is my suggestion:

datafile = "7664-41-7-IR.jdx2"
dx = 0.935253
col_count=6

# Build a function that will create a new datafile by converting
# single lines of the form "x y1 y2 y3 ..." into multiple
# lines of the form "x y1", "x+dx  y2", "x+2*dx y3", ...
#  
# We will call this function later for each input line and append
# the new data values.

all_command = "all = sprintf(\"%s"
do for [i=2:col_count] {
   all_command = all_command."%f %f\n"
}
all_command = all_command."\", all"
do for [t=2:col_count] {
   all_command = all_command.", column(1)+dx*(".t."-2), column(".t.")"
} 
all_command = all_command.")"

# Just to check: 
print all_command

# Now we call the function for each input line. The variable "all" will contain
# the "expanded" data. Note, the "plot" command is a dummy plot.
all = ""
plot datafile using 1:( @all_command, 1)

# Generate the temporary data file
set print "temp_file.dat"
print all

plot datafile w p, "temp_file.dat" w l

This a part of the output:

data

For counting the lines generically please check this question.

maij
  • 4,094
  • 2
  • 12
  • 28