#!/usr/bin/perl -w @todo= `ls *.dat`; $count=0; foreach(@todo){ chomp; $this=$_; open TMP, ">fit_tmp"; print TMP "f1(x) = c*(-a + cos(3.14159*2*j*x))*exp(-2*x*r) \n"; #defines the fitting function for the NH J-modulated data. print TMP "c=1; a=0.01; r=20; j=90;\n"; #may need to changed for proper initialization for curve fitting. print TMP "fit f1(x) \'$this\' using 1:2 via c,a,r,j\n"; #fits the data according to the equation f1(x) with the variable parameters c, a, j, and r. close TMP; system ("rm","-f","fit.log"); system ("gnuplot","fit_tmp"); $count++; $c=0;$delta_c=0; #c is the initial intensity of the peak $a=0;$delta_a=0; #a accounts for imperfection of pi pulses during the experiment (usually 0 < a < 0.05) $j=0;$delta_j=0; #j is the one-bond N-H j-coupling value in Hz $r=0;$delta_r=0; #r is the R2 relaxation rate in sec open DATA,"fit.log"; while (){ if (/Final set of parameters\s*Asymptotic Standard Error/){ while (){ @_ = split; if ( defined $_[0] && $_[0] eq 'c'){ $c = $_[2]; $delta_c = $_[4]; } elsif ( defined $_[0] && $_[0] eq 'a'){ $a = $_[2]; $delta_a = $_[4]; } elsif ( defined $_[0] && $_[0] eq 'j'){ $j = $_[2]; $delta_j = $_[4]; } elsif ( defined $_[0] && $_[0] eq 'r'){ $r = $_[2]; $delta_r = $_[4]; } last if ($c !=0 && $a !=0 && $j !=0 && $r !=0); } } } open TMP2,">plot_tmp"; print TMP2 "plot [0:0.015] \'$this\',$c*(-$a + cos(3.14159*2*$j*x))*exp(-2*x*$r) title 'c = $c +- $delta_c a = $a +- $delta_a j = $j +- $delta_j r = $r +- $delta_r'"; print TMP2 "\npause -1"; system ("gnuplot","plot_tmp"); }