I have to analyze about 70 PFG-NMR data (maybe more..), it’s not fun when deal with each data point routinely. Here is the goal I have and the solution I did.
Goal: using shell script (awk, UNIX tools and sed) to do simple calculation; then use gnuplot to generate a lots of plots.
Solution:
- use shell script to format correct files that gnuplot can take as inputs
- run gnuplot by calling run.gnu (a gnuplot script)
- look at the PNG file generated by gnuplot
Result: see the figure here:

content of shell script:
————————–
#!/bin/sh
rm -f fit.log
for INP in *k.dat
do
newname=`basename $INP .dat`
paste gzlvl6.dat $INP > _temp1
cat _temp1 |awk ‘{printf \
“%4.3f%10.3f%10.3f%12.3f\n”,($1*0.00235)^2,log($5/100),$1,$5 }’ >_temp2
## make a proper script to generate gnuplot with good title
cp run.gnu _temp.gnu
echo “plot f(x) with lines ls 1 title ‘fitting line’, ‘”_temp2″‘ using 1:2 title ‘dioxane $newname’ with points 6″ >> _temp.gnu
/usr/bin/gnuplot _temp.gnu
## post-filename-modification
mv fit.log $newname-fit.log
mv test.png $newname.png
cat _temp2 |sort -n > $newname-all-info.txt
rm _temp*
done
—————————-
Content of run.gnu:
set terminal png
set output “test.png”
f(x)=a*x+b
fit f(x) “_temp2″ using 1:2 via a,b
set xlabel “G^2″
set ylabel “ln(I/I0)”
set yrange [-4:0]
set style line 1 lt 1 lw 3
I also did something like this when I was a research student. Sometimes I even used the script to put everything into a report in HTML format. It’s funny to see everything ready in a second.
Do you use plotmtv? It’s good for plotting 3D surfaces.
Comment by 有涯 — July 19, 2007 @ 2:59 pm |
Thanks for the information of “plotmtv”. It looks nice and easy to learn.
Currently, I make 3D plots by the ProFit on my MacBook Pro. I don’t need to generate some 3D plots by gnuplot+scripts.
Comment by kpwu — July 20, 2007 @ 2:11 pm |
In addition to gnuplot, xmgr (now called Grace) is also very nice for 2D. I like the feature of doing Fourier Transform, finite differences, etc. on the source data without requiring more programming.
Just for your information.
Comment by 有涯 — July 21, 2007 @ 10:58 am |
Yes, XMGR/Grace is a very good plot software. I had used it for several course reports last year. It works well by scripts and by its GUI. I didn’t successfully install it on my MacBookPro, therefore, I still use xmgr to do some data analysis by accessing to a remote Linux cluster.
Comment by kpwu — July 21, 2007 @ 6:54 pm |