I have attached a txt file, what I would like to be able to do is:
Extract Data from Columns labeled E/N and Ko into a new file
Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis.
Lastly I would like to be able to extract multiple data sets and do this in one file so i can plot all my curves and see how they relate to each other.
Thank you as always for your help, you guys are great. Lenny.
I'll assume you're on a UNIX system and Perl and gnuplot are available.
The following (cheap and pretty dirty) Perl script will extract the two columns you're interested in:
#!/usr/bin/perl
#
# Name: extract
# Use: extract data.file
#
if ( $#ARGV == 0 )
{ # First comand line arg is data file name
$input_data = $ARGV[0];
$output_data = $input_data . ".extracted_data";
}
else
{
printf STDERR "Usage: extract data-file-name\n";
exit 1;
}
$extract_data = 0; # Initially "false"
open(OUTPUT, '>', $output_data);
open (DATA, '<', $input_data);
RECORD:
while (<DATA>)
{
chomp;
s/^\s+//; # Remove leading whitespace
if ( length($_) <= 0 )
{ # Skipping empty lines
next RECORD;
}
if ( /E\/N/ )
{
if ( / Ko / )
{ # Found end of the header records. Data follows...
$extract_data = -1;
next RECORD;
}
}
if ( $extract_data )
{
@values = split(/\s+/, $_);
printf OUTPUT "%s %s\n", $values[0], $values[1];
}
}
close(DATA);
close(OUTPUT);
exit;
(Sorry... the forum software does awful things to the indentation of the script and I'm not sure how to prevent that.)
This would be run using:
chmod u+x extract
./extract data.file
and produce
data.file.extracted_data
A simple gnuplot command file to plot two curves might be:
set terminal postscript landscape;
plot "data.file.extracted_data" with lines, "data2.file.extracted_data" with lines;
If these were saved in a file named "gnuplot.cmds", you would generate the plot using:
gnuplot < gnuplot.cmds > plotted_data.ps
If you need to plot more than two curves, add another datafile name containing extracted data file to the end of the "plot" command and rerun the above gnuplot command. You could also add extra commands to control the X and Y axes, etc. (above the line containing the "plot" command).
If you've got Windows and Microsoft Excel, you can open it with that and use the data to columns wizard to put your data in columns, then create the graph.
I extracted the data into Excel for you- here you go.
If you wanna know how I did it, I did it by (I'm using Excel 2003):
copying your data starting with E/N Ko etc. and pasting it into a new Excel workbook,
then click the little paste button to see options, and click Use Text Import Wizard
Choose fixed width, click next
It shows lines between the columns- one of the lines was a little off, I adjusted it (click and drag the line)
Click finish
Now you can insert a char- click Insert, Chart
Choose a scatter plot. Take it from there!
I don't have a lot of experience with charts, etc. in Excel, but see how easy and user-friendly it is with Windows and Microsoft Office, compared to Unix!