Advertisement
JessiBaughman

Bash NMR Ernst Angle Calculator

Dec 12th, 2024
26
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.28 KB | Science | 0 0
  1. #!/bin/bash
  2. _pi=$(echo "scale=12;4*a(1)"|bc -l)
  3. _d1=0
  4. _at=0
  5. _tr=$_at+$_d1
  6. _t1=0
  7. _angle=0
  8. _pw90=1
  9. _pw=0
  10. clear;echo
  11. function pwToAngle {
  12.     echo "scale=2;90*$1/$_pw90"|bc -l
  13. }
  14. function AngleTopw {
  15.     echo "scale=2;$_pw90*$1/90"|bc -l
  16. }
  17. echo " Ernst Angle Calculator"
  18. echo "------------------------"
  19. echo " 1. Angle"
  20. echo " 2. T1"
  21. echo " 3. Recycle Delay (d1)"
  22. echo " 4. Acq. Time (at)"
  23. echo " 5. d1 + at"
  24. echo
  25. read -p "Solve for?: " response
  26. case "$response" in
  27. 1)  read -p "Enter at (s): " _at
  28.     read -p "Enter d1 (s): " _d1
  29.     read -p "Enter T1 (s): " _t1
  30.     read -p "Enter pw90 (us): " _pw90
  31.     _ans=$(echo "e(-($_at+$_d1)/$_t1)"|bc -l)
  32.     _ans=$(echo "a(sqrt(1-$_ans^2)/$_ans)"|bc -l)
  33.     _ans=$(echo "$_ans*180/$_pi"|bc -l)
  34.     _pw=$(AngleTopw $_ans)
  35.     echo;echo "Angle = $_ans degrees ($_pw microseconds)";echo
  36.    
  37.     ;;
  38. 2)  read -p "Enter angle in degrees (or 's' for pw): " _angle
  39.     if [ "$_angle" == "s" ]; then
  40.         read -p "Enter pw (us): " _angle
  41.         read -p "Enter pw90 (us): " _pw90
  42.         _angle=$(pwToAngle $_angle)
  43.     fi
  44.     read -p "Enter d1 (s): " _d1
  45.     read -p "Enter at (s): " _at
  46.     _angleR=$(echo "$_angle*$_pi/180"|bc -l)
  47.     _ans=$(echo "-($_at+$_d1)/l(c($_angleR))"|bc -l)
  48.     echo;echo "T1 = $_ans seconds";echo
  49.     ;;
  50. 3)  read -p "Enter angle in degrees (or 's' for pw): " _angle
  51.     if [ "$_angle" == "s" ]; then
  52.         read -p "Enter pw (us): " _angle
  53.         read -p "Enter pw90 (us): " _pw90
  54.         _angle=$(pwToAngle $_angle)
  55.     fi
  56.     read -p "Enter at (s): " _at
  57.     read -p "Enter t1 (s): " _t1
  58.     _angleR=$(echo "$_angle*$_pi/180"|bc -l)
  59.     _ans=$(echo "(-l(c($_angleR))*$_t1)-$_at"|bc -l)
  60.     echo;echo "d1 = $_ans seconds";echo
  61.     ;;
  62. 4)  read -p "Enter angle in degrees (or 's' for pw): " _angle
  63.     if [ "$_angle" == "s" ]; then
  64.         read -p "Enter pw (us): " _angle
  65.         read -p "Enter pw90 (us): " _pw90
  66.         _angle=$(pwToAngle $_angle)
  67.     fi
  68.     read -p "Enter d1 (s): " _d1
  69.     read -p "Enter t1 (s): " _t1
  70.     _angleR=$(echo "$_angle*$_pi/180"|bc -l)
  71.     _ans=$(echo "(-l(c($_angleR))*$_t1)-$_d1"|bc -l)
  72.     echo;echo "at = $_ans seconds";echo
  73.     ;;
  74. 5)  read -p "Enter angle in degrees (or 's' for pw): " _angle
  75.     if [ "$_angle" == "s" ]; then
  76.         read -p "Enter pw (us): " _angle
  77.         read -p "Enter pw90 (us): " _pw90
  78.         _angle=$(pwToAngle $_angle)
  79.     fi
  80.     read -p "Enter t1 (s): " _t1
  81.     _angleR=$(echo "$_angle*$_pi/180"|bc -l)
  82.     _ans=$(echo "(-l(c($_angleR))*$_t1)"|bc -l)
  83.     echo;echo "at+d1 = $_ans seconds";echo
  84.     ;;
  85. esac
  86.  
Advertisement
Comments
  • JessiBaughman
    1 hour
    # text 0.21 KB | 0 0
    1. Simple Nuclear Magnetic Resonance Ernst angle calculator for bash. In addition to solving for angle, it can solve for any of the variables in the equation, which can be useful for verifying experimental conditions.
Add Comment
Please, Sign In to add comment
Advertisement