emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] How to call nested bash and gnuplot with babel?


From: edgar
Subject: [O] How to call nested bash and gnuplot with babel?
Date: Fri, 25 Aug 2017 03:26:58 +0000
User-agent: Roundcube Webmail/1.2.4

Hello, I am trying to run a "nested" babel code with bash and gnuplot.

* Configuration
I did the test like this
#+BEGIN_SRC bash
  emacs -Q
#+END_SRC

#+BEGIN_SRC emacs-lisp
  (require 'package)
  (package-initialize)

  (require 'org)
  ;; Org mode version 9.0.9

  (org-babel-do-load-languages ; babel, for executing
     'org-babel-load-languages   ; code in org-mode.
     '((shell . t)
       (python . t)
       (emacs-lisp . t)
       (org . t)
       (gnuplot . t)))
#+END_SRC

* Original code
#+NAME: bash-tjp-displ-stress
#+HEADER: :var file1="file1.csv"
#+HEADER: :var col1="3"
#+HEADER: :var file2="file2.csv"
#+HEADER: :var col2="7"
#+HEADER: :dir "Data"
#+BEGIN_SRC bash :results value :exports code
  paste "$file1" "$file2" | awk -F',' '/^[^#]/{print $'$col1' $'$col2'}'
#+END_SRC

#+NAME: gplt-tjp-febio-results
#+CAPTION: Gnuplot to plot
#+HEADER: :var data=bash-tjp-displ-stress
#+BEGIN_SRC gnuplot :results graphics :file /tmp/orig-out.png
  set xlabel 'var1'
  set ylabel 'var2'
  plot data u ($1 + 1):2 with lp notitle
#+END_SRC

** Alternative 1: ~:file~ after the function
 The result of this gives me the original output file
 #+CALL: gplt-tjp-febio-results() :file /tmp/test.png

 #+RESULTS:
 [[file:/tmp/orig-out.png]]

** Alternative 2: ~:file~ as a prefix to the function
 The result of this gives me the original output file
 #+CALL: gplt-tjp-febio-results[:file /tmp/test.png]()

 #+RESULTS:
 [[file:/tmp/orig-out.png]]

* Modified code
If I do this, I get the desired output file (add variable ~outfile~
and ~:results none~)

#+NAME: gplt-tjp-febio-results-new
#+CAPTION: Gnuplot to plot
#+HEADER: :var data=bash-tjp-displ-stress
#+HEADER: :var outfile="/tmp/test.png"
#+BEGIN_SRC gnuplot :results graphics
  set output outfile
  set xlabel 'var1'
  set ylabel 'var2'
  plot data u ($1 + 1):2 with lp notitle
#+END_SRC

#+CALL: gplt-tjp-febio-results-new[:results none](outfile="/tmp/new_out.png")

I type this manually:
[[/tmp/new_out.png]]

* What I expected
To call
#+BEGIN_EXAMPLE
  ,#+CALL: gplt-tjp-febio-results() :file /tmp/new_out.png
#+END_EXAMPLE

and get
#+BEGIN_EXAMPLE
  ,#+RESULTS:
  [[file:/tmp/orig-out.png]]
#+END_EXAMPLE

How do I achieve this?

* Thanks
Thank you! :D

-------------------------------------------------

ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the 
NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features! 15GB disk! No bandwidth quotas! Commercial and Bulk Mail Options!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]