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