emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to call nested bash and gnuplot with babel?
@ 2017-08-25  3:26 edgar
  0 siblings, 0 replies; only message in thread
From: edgar @ 2017-08-25  3:26 UTC (permalink / raw)
  To: emacs-orgmode

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!  

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-25 16:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25  3:26 How to call nested bash and gnuplot with babel? edgar

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).