help-octave
[Top][All Lists]
Advanced

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

Re: A Gnuplot question


From: Ben Abbott
Subject: Re: A Gnuplot question
Date: Thu, 27 Nov 2008 23:26:49 -0500

Actually the script did exactly as it should. However, it is not doing what you want.

The pwd refers to the directory from where the script is called, not the directory the script resides.

If the gnuplot script is in your path, and you don't mind not permitting its name to be changed you can create a script named "script.gp" and have it find itself with some system calls. Try the script below, be sure to name the script "script.gp", or change the script_name appropriately.

-------------------
#!/usr/local/bin/gnuplot
script_name = "script.gp"
script_and_path = system(sprintf("which %s",script_name))
path_to_script = system(sprintf("dirname %s",script_and_path))
cd path_to_script
pwd
-------------------

Ben


On Nov 27, 2008, at 10:27 PM, Vic Norton wrote:

Yes, Ben, I saw Dieter's response. It was no help.

And "." doesn't help either, I'm afraid. For example, I have just tested a two line script (shebang line excluded) that reads

  #!/usr/local/bin/gnuplot
  cd ".";
  pwd;

This script resides in my "~/gnuplot/Scripts" scripts directory. According to your theory the script should produce "~/gnuplot/ Scripts". I does not. It produces "/". Apparently my "working directory" was the root "/", and "." just references the root directory. In any case "." has no relation to the "~/gnuplot/Scripts" where my script resides.

I guess I'll give up this quest on the octave list. It's clear I'm getting nowhere. Thanks for your efforts.

Regards,

Vic

On Nov 27, 2008, at 11:21 AM, Ben Abbott wrote:

Vic,

Did you see Dieter's response?

In any event, I assume you are calling your script from the directory "Markowitz_critical_line", correct?

Why not make use of "." ... which is synonymous with the present working directory?

 #!/usr/local/bin/gnuplot

 ## SE_2006-09-15_rank9.plot

 cd "./Gnuplot";
 load './data/assetSEpoints_2006-09-15_rank9.pts';
 load './data/efficientFunctions_2006-09-15_rank9.fcn';


Perhaps you might avoid using "cd"?

 #!/usr/local/bin/gnuplot

 ## SE_2006-09-15_rank9.plot

 load './Gnuplot/data/assetSEpoints_2006-09-15_rank9.pts';
 load './Gnuplot/data/efficientFunctions_2006-09-15_rank9.fcn';

That won't work if you're calling your script from somewhere other than the "Markowitz_critical_line" folder.

Ben

On Nov 27, 2008, at 10:06 AM, Vic Norton wrote:

Here's the situation.

The first lines of a gnuplot script are

 #!/usr/local/bin/gnuplot

 ## SE_2006-09-15_rank9.plot

 cd "~/octave/Markowitz_critical_line/Gnuplot";
 load 'data/assetSEpoints_2006-09-15_rank9.pts';
 load 'data/efficientFunctions_2006-09-15_rank9.fcn';

I want to distribute the folder, "Markowitz_critical_line", but clearly the gnuplot code is NOT portable unless a receiver of the distribution puts this "Markowitz_critical_line" folder in his own "~/octave" directory.

The gnuplot script is in "Markowitz_critical_line/Gnuplot"; so what I really want is

 cd HERE;

where HERE is the directory of the calling script. Then the next two "load" lines will work fine no matter where someone puts the "Markowitz_critical_line" folder.

So my question is this: How do you define HERE in gnuplot?

In octave

 HERE = fileparts(mfilename("fullpath"));

Regards,

Vic

On Nov 26, 2008, at 7:53 PM, Vic Norton wrote:
Unfortunately "help cd" is no help, Thomas.
Syntax:
   cd '<directory-name>'
works if you know the directory-name. I want the Gnuplot script to
tell me the name of the directory in which it resides. Then the code
will be portable.

On Nov 26, 2008, at 8:36 PM, Ben Abbott wrote:

I don't see what that has to do with making code portable. Can you be more specific?






reply via email to

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