Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // VnmrJ macro
- // Format plot based on plot panel selections (doplotoptions)
- // for display on Pebble Watch (144x168)
- // Should work for most 1D, 2D, and DOSY spectra.
- //
- // Requires:
- // GraphicsMagick (Linux package)
- // Two printers defined in /vnmr/devicenames and /vnmr/devicetable
- // One set to Mono and the other Color
- //
- // Default is all white-on-black, which displays better with Notification
- // Center using the white-on-black setting
- // Can use any of the following options to change output colors
- // color - plot in color
- // mono - plot in b+w [Default]
- // white - plot white background
- // black - plot black background [Default]
- //
- // Note: 'black' is obtained by inverting the image, so if used with color,
- // contours in 2D's will also be inverted.
- // plpebble('black','color',filename) -> pos = red, neg = blue
- // plpebble('white','color',filename) -> pos = blue, neg = red
- //
- // filename is always assumed to be the last arugment
- // i.e. plpebble(<OPTIONS,>filename)
- //
- // If filename is not supplied, then the image will be saved as
- // $HOME/samplename.png -or- $HOME/pebble.png if samplename is not set
- //
- // 2019-04-02 Jessi A. Baughman - Created
- // Customization
- // A printer is set as Color or Mono based on the layout defined in /vnmr/devicetable
- $colorplotter='MyColorPrinter' // plotter setup as a color plotter
- $monoplotter='MyBWprinter' // plotter setup as a monochrome plotter
- // Set Defaults
- $pslw_orig=pslw
- $plotter_orig=plotter
- pslw=20
- ploption('add','pl') plotoption('add','axis')
- plotoption('remove','header') plotoption('remove','params')
- plotoption('remove','logo')
- plotoption('remove','comments') plotoption('remove','miniplot')
- // remove integration labels and peak labels
- plotoption('remove','intval') plotoption('remove','pklabels')
- // remove integration and peak lists
- plotoption('remove','intlist') plotoption('remove','linelist')
- $color='mono'
- $background='black'
- length(userdir):$udl
- substr(userdir,0,$udl-8):$HOME
- // Process arguments
- if ($#>0) then
- if ($#=2) then
- $file=$2
- if ($1='color' or $1='mono') then
- $color=$1
- $background='black'
- elseif ($1='black' or $1='white') then
- $color='mono'
- $background=$1
- else
- write('error','plpebble: Invalid arguments. Using defaults with supplied filename: %s',$file)
- endif
- elseif ($#>2) then
- $file=$3
- if ($1='color' or $1='mono') then
- $color=$1
- $background=$2
- elseif ($1='black' or $1='white') then
- $color=$2
- $background=$1
- else
- write('error','plpebble: Invalid arguments. Using defaults with supplied filename: %s',$file)
- endif
- else
- $file=$1
- endif
- else
- if ('x'+samplename='x') then
- $file=$HOME+'/pebble'
- else
- $file=$HOME+'/'+samplename
- endif
- endif
- // Set file extension if needed
- length($file):$filelen
- $fileend=' '
- substr($file,$filelen-3,4):$fileend
- if not ($fileend='.png') then
- $file=$file+'.png'
- endif
- // Add directory path if needed
- shell('dirname '+$file):$dirname
- if ($dirname='.') then // directory not supplied
- $file=$HOME+'/'+$file
- endif
- if ($color='color') then
- plotter=$colorplotter
- else
- plotter=$monoplotter
- endif
- sysplotter=plotter
- // Create image
- substr(seqfil,0,2):$sf
- if ($sf='Db') then
- doplotoption ds redosy
- else
- doplotoption ds
- endif
- page('/tmp/tmpplot.ps'):$silent
- exists('/tmp/tmpplot.ps','file'):$eold
- if not $eold then write('error','Error while printing: Could not save to /tmp/tmpplot.ps') return('error') endif
- shell('sed -i -e "s/Courier-Bold findfont [0-9]*/Courier-Bold findfont 90/g" /tmp/tmpplot.ps')
- if ($background='white')then
- shell('gm convert /tmp/tmpplot.ps -trim -rotate 90 -resize 144x168 -background white -density 72 -gravity south -extent 144x168 '+$file)
- else
- shell('gm convert /tmp/tmpplot.ps -trim -negate -rotate 90 -resize 144x168 -background black -density 72 -gravity south -extent 144x168 '+$file)
- endif
- write('line3','Image saved to %s',$file)
- // Delete the second page, if plotted
- rm($file+'.1'):$silent
- mv($file+'.0',$file):$silent
- rm('/tmp/tmpplot.ps'):$silent
- // Reset settings
- pslw=$pslw_orig
- plotter=$plotter_orig
- sysplotter=plotter
- // Return file path/name
- return($file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement