help-octave
[Top][All Lists]
Advanced

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

Re: sourcing files in a different directory


From: Ben Abbott
Subject: Re: sourcing files in a different directory
Date: Mon, 16 Jun 2008 07:20:55 -0400


On Jun 16, 2008, at 12:48 AM, Kamaraju S Kusumanchi wrote:

Consider the following directory structure.

$tree dir1
dir1
|-- dir2
|   `-- scriptA.m
|-- script1.m
|-- script2.m
`-- script3.m

where the files are defined as

$cat dir1/script1.m
1;
a=1

$cat dir1/script2.m
1;
b=2

$cat dir1/script3.m
1;
script1;
script2;
c=a+b

$cat dir1/dir2/scriptA.m
1;
../script1;
../script2;
d=2*a+b


In general dir1/script3.m depends upon the functions/variables defined in
dir1/script1.m, dir1/script2.m.
dir1/dir2/scriptA.m depends upon the functions/variables defined in
dir1/script1.m, dir1/script2.m but conflicts with dir1/script3.m.

I am able to execute dir1/script3.m

$cd dir1

$octave -q
octave:1> script3
a =  1
b =  2
c =  3
octave:2> exit


but not dir1/dir2/scriptA.m.

$cd ..

$cd dir1/dir2

$octave -q
octave:1> scriptA
parse error near line 2 of
file /home/rajulocal/work/octave/dir1/dir2/scriptA.m

 syntax error

../script1;
   ^

parse error near line 2 of
file /home/rajulocal/work/octave/dir1/dir2/scriptA.m

 syntax error

../script1;
     ^

error: near line 2 of file `/home/rajulocal/work/octave/dir1/dir2/ scriptA.m'
octave:1>



Is there any way to overcome this problem and be able to source specific files from other directories? I do not want to use addpath and add dir1 to the list of directories for searching the functions since that would add dir1/script3.m besides dir1/script1.m, dir2/script2.m as well. I want to
have access only to dir1/script1.m, dir1/script2.m but not to
dir1/script3.m

Any ideas/comments/suggestions regarding this issue are very welcome. I am
using Debian Etch, octave 3.0.0-9

thanks
raju

In scriptA, you might replace "../script1;" with

        addpath ("..")
        script1;

I haven't yet had my coffee this morning. However, I expect someone will come along momentarily and give a nice explanation for why your approach didn't work :-)

Ben




reply via email to

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