[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sourcing files in a different directory
From: |
Sergei Steshenko |
Subject: |
Re: sourcing files in a different directory |
Date: |
Mon, 16 Jun 2008 15:07:09 -0700 (PDT) |
Applications From Scratch: http://appsfromscratch.berlios.de/
--- On Mon, 6/16/08, Ben Abbott <address@hidden> wrote:
> From: Ben Abbott <address@hidden>
> Subject: Re: sourcing files in a different directory
> To: "Kamaraju S Kusumanchi" <address@hidden>
> Cc: address@hidden
> Date: Monday, June 16, 2008, 4:20 AM
> 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
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
In general, regardless of application, search paths are much more evil
than good.
Because of the above I resolve full path of current file:
this_file = mfilename("fullpathext");
and then calculate _full_ paths according to the scripts directory tree
structure.
Doing "source" with full path pretty much neutralizes the evil nature
of search paths.
Regards,
Sergei.