Advertisement
JessiBaughman

plpebble

Sep 3rd, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.21 KB | None | 0 0
  1. // VnmrJ macro
  2.  
  3. // Format plot based on plot panel selections (doplotoptions)
  4. //     for display on Pebble Watch (144x168)
  5. // Should work for most 1D, 2D, and DOSY spectra.
  6. //
  7. // Requires:
  8. //     GraphicsMagick (Linux package)
  9. //     Two printers defined in /vnmr/devicenames and /vnmr/devicetable
  10. //          One set to Mono and the other Color
  11. //
  12. // Default is all white-on-black, which displays better with Notification
  13. //   Center using the white-on-black setting
  14. // Can use any of the following options to change output colors
  15. //   color  - plot in color
  16. //   mono   - plot in b+w [Default]
  17. //   white  - plot white background
  18. //   black  - plot black background [Default]
  19. //
  20. // Note: 'black' is obtained by inverting the image, so if used with color,
  21. //       contours in 2D's will also be inverted.
  22. //   plpebble('black','color',filename) -> pos = red,  neg = blue
  23. //   plpebble('white','color',filename) -> pos = blue, neg = red
  24. //
  25. // filename is always assumed to be the last arugment
  26. // i.e. plpebble(<OPTIONS,>filename)
  27. //
  28. // If filename is not supplied, then the image will be saved as
  29. //       $HOME/samplename.png -or- $HOME/pebble.png if samplename is not set
  30. //
  31. // 2019-04-02 Jessi A. Baughman - Created
  32.  
  33. // Customization
  34. // A printer is set as Color or Mono based on the layout defined in /vnmr/devicetable
  35. $colorplotter='MyColorPrinter' // plotter setup as a color plotter
  36. $monoplotter='MyBWprinter'   // plotter setup as a monochrome plotter
  37.  
  38. // Set Defaults
  39. $pslw_orig=pslw
  40. $plotter_orig=plotter
  41. pslw=20
  42. ploption('add','pl') plotoption('add','axis')
  43. plotoption('remove','header') plotoption('remove','params')
  44. plotoption('remove','logo')
  45. plotoption('remove','comments') plotoption('remove','miniplot')
  46. // remove integration labels and peak labels
  47. plotoption('remove','intval') plotoption('remove','pklabels')
  48. // remove integration and peak lists
  49. plotoption('remove','intlist') plotoption('remove','linelist')
  50. $color='mono'
  51. $background='black'
  52. length(userdir):$udl
  53. substr(userdir,0,$udl-8):$HOME
  54.  
  55. // Process arguments
  56. if ($#>0) then
  57.     if ($#=2) then
  58.         $file=$2
  59.         if ($1='color' or $1='mono') then
  60.             $color=$1
  61.             $background='black'
  62.         elseif ($1='black' or $1='white') then
  63.             $color='mono'
  64.             $background=$1
  65.         else
  66.             write('error','plpebble: Invalid arguments. Using defaults with supplied filename: %s',$file)
  67.         endif
  68.     elseif ($#>2) then
  69.         $file=$3
  70.         if ($1='color' or $1='mono') then
  71.             $color=$1
  72.             $background=$2
  73.         elseif ($1='black' or $1='white') then
  74.             $color=$2
  75.             $background=$1
  76.         else
  77.             write('error','plpebble: Invalid arguments. Using defaults with supplied filename: %s',$file)
  78.         endif
  79.     else
  80.         $file=$1
  81.     endif
  82. else
  83.     if ('x'+samplename='x') then
  84.         $file=$HOME+'/pebble'
  85.     else
  86.         $file=$HOME+'/'+samplename
  87.     endif
  88. endif
  89.  
  90. // Set file extension if needed
  91. length($file):$filelen
  92. $fileend=' '
  93. substr($file,$filelen-3,4):$fileend
  94. if not ($fileend='.png') then
  95.     $file=$file+'.png'
  96. endif
  97.  
  98. // Add directory path if needed
  99. shell('dirname '+$file):$dirname
  100. if ($dirname='.') then // directory not supplied
  101.     $file=$HOME+'/'+$file
  102. endif
  103.  
  104. if ($color='color') then
  105.     plotter=$colorplotter
  106. else
  107.     plotter=$monoplotter
  108. endif
  109. sysplotter=plotter
  110.  
  111. // Create image
  112. substr(seqfil,0,2):$sf
  113. if ($sf='Db') then
  114.         doplotoption ds redosy
  115. else
  116.         doplotoption ds
  117. endif
  118.  
  119. page('/tmp/tmpplot.ps'):$silent
  120. exists('/tmp/tmpplot.ps','file'):$eold
  121. if not $eold then write('error','Error while printing: Could not save to /tmp/tmpplot.ps') return('error') endif
  122.  
  123. shell('sed -i -e "s/Courier-Bold findfont [0-9]*/Courier-Bold findfont 90/g" /tmp/tmpplot.ps')
  124.  
  125. if ($background='white')then
  126.     shell('gm convert /tmp/tmpplot.ps -trim -rotate 90 -resize 144x168 -background white -density 72 -gravity south -extent 144x168 '+$file)
  127. else
  128.     shell('gm convert /tmp/tmpplot.ps -trim -negate -rotate 90 -resize 144x168 -background black -density 72 -gravity south -extent 144x168 '+$file)
  129. endif
  130. write('line3','Image saved to %s',$file)
  131.  
  132. // Delete the second page, if plotted
  133. rm($file+'.1'):$silent
  134. mv($file+'.0',$file):$silent
  135. rm('/tmp/tmpplot.ps'):$silent
  136.  
  137. // Reset settings
  138. pslw=$pslw_orig
  139. plotter=$plotter_orig
  140. sysplotter=plotter
  141.  
  142. // Return file path/name
  143. return($file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement