# Static QCPMG 
# Corresponds to Fig. 6b and 7h in 
# F. H. Larsen, H. J. Jakobsen, P. D. Ellis, N. Chr. Nielsen
# J. Phys. Chen. A vol 101, no 46, p 8597-8606 (1997)
# 1024 seconds on a 166 mHz Pentium II w/Linux

spinsys {
  channels 87Rb
  nuclei 87Rb
  shift 1 12.4p -13.0p 1.00 118 32 97 
  quadrupole 1 2 3.28e6 0.24 0 0 0
}

par {
  spin_rate        0
  sw               250000
  crystal_file     zcw4180
  start_operator   I1z
  detect_operator  I1p
  verbose          1101
  proton_frequency 400e6
  variable rf      78000
  variable N       125
  variable R       60
}


proc pulseq {} { 
  global par

  set tsw  [expr 1.0e6/$par(sw)]
  set t90  [expr 0.25e6/$par(rf)/2.0]
  set t180 [expr 0.5e6/$par(rf)/2.0]


  set t1 25.0
  set t2 26.0
  set t3 26.0
  set t4 27.0
  
  matrix set 1 coherence {-1 1}

  reset
  delay  $tsw
  store 1

  reset 
  pulse $t90 $par(rf) x
  filter 1
  delay $t1
  pulse $t180 $par(rf) y
  filter 1
  delay $t2
  acq $par(N) 1
  prop 1
  delay $t3
  pulse $t180 $par(rf) y
  filter 1
  delay $t3 
  acq [expr 2*$par(N)] 1
}


proc main {} {
  global par

  set par(np) [expr 2*$par(N)*(1+$par(R))+$par(N)]
  set f [fsimpson]
  
  set N2 [expr 2*$par(N)]

  for {set i 1} {$i <= $N2} {incr i} {
    set c [findex $f [expr $i + $par(N)]]
    set re [lindex $c 0]
    set im [lindex $c 1]
    for {set j 1} {$j <= $par(R)} {incr j} {
      fsetindex $f [expr $i+$j*$N2+$par(N)] $re $im
    }
  }
  fsave $f $par(name).fid
  fzerofill $f 65536
  faddlb $f 30 0
  fft $f
  fphase $f -rp 90
  fsave $f $par(name).spe 
  fsave [fssbint $f 1000 0 1000] $par(name)-int.spe
}
