LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2010, 04:31 PM   #1
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Rep: Reputation: 2
Question Specifying a file path in IDL


Hello,

I've been dabbling in IDL lately, and it seems useful enough, but occasionally I come across a problem like this:

I'm trying to call an IDL procedure from within an IDL script which is called from a .csh script. (Don't ask, trust me, you don't want to know.)

The IDL procedure may or may not be in the same directory as the .csh, so I'm calling it by it's full path: /home/ic/rad_sim

However, all IDL will do is give me a syntax error and tell me ic is an undefined variable. Putting ic in double quotes makes the undefined variable error go away, but it still reports a syntax error.

Any ideas?
Lost
 
Old 07-19-2010, 07:23 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
you might want to export the path on boot
/home/ic/rad_sim add that to the system $PATH

i do not use idl ( i use GDAL and ISIS3 ) that is what i do
in a isis startup script i export the paths i need
 
Old 07-20-2010, 05:41 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Can you give a code example that causes the syntax error please (I use IDL, so may be able to help)?

Last edited by Nylex; 07-20-2010 at 05:42 AM.
 
Old 07-20-2010, 08:57 AM   #4
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
i suppose that would help, wouldn't it?

Here's my test.chs:

Code:
#!/bin/csh

cd ~/rad_sim
idl << BEGIN
idltest
BEGIN
exit

and here's the idltest.pro


Code:
pro idltest

CD, /home/ic   <- Syntax error occurs on this line. I tried typing the path multiple ways.
end
As far as exporting the paths goes, I suspect that might fix my problem on this one machine, but the code I'm writing is part of a group effort and needs to be entirely portable. Ideally I need to be able to specify a directory from the command line, but I figured mastering the simple CD was the first step.

PS, any words of wisdom about using variables in file paths would also be appreciated, but that issue will probably resolve itself if I can get this part working.
 
Old 07-20-2010, 09:09 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You need to give the directory as a string. Either single quotes or double quotes should be fine.

Do you want to use a variable defined in your shell script in IDL? You can do this as normal:

#!/bin/csh

set var="/some/directory"
idl << EOF
cd, '$var'
spawn, 'pwd', pwd_var
print, pwd_var
EOF

This will change to the directory stored in var, run the pwd command, putting the result in pwd_var and finally prints pwd_var to show that the directory has been changed.

Does that help? If not, post exactly how you tried specifying the paths and the error messages.

Last edited by Nylex; 07-20-2010 at 09:12 AM.
 
1 members found this post helpful.
Old 07-20-2010, 09:58 AM   #6
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
Thanks Nylex, your solution worked for the test case, but when I
put it into a more complicated framework, I get the same syntax error I've been getting all along.

Code:
#!bin/csh

if ($#argv != 3) then
  echo "Usage: rpsdriver.csh <.h5 file ie. LO80400340342001213EDC00_B02>
  <WODIR> <rad_simdir>"
  exit
endif

set curdir = `pwd`
idl << BEGIN
'$3/drive_gnb_reversal,' '$1', '$2', '$3' # This chunk works, but I'd like to be
 able to insert the $3 variable before the drive_gnb_reversal. IDL doesn't
 seem to like that. ie. '$3/drive_gnb_reversal' I tried with and without
 spawn, and in all sorts of patterns of double and single quotes.
BEGIN
cd $curdir
Code:
pro drive_gnb_reversal, filename, WODIR, RADDIR

filename = strmid(filename,0,24)
bands = 12

for i = 1,9 DO BEGIN
  current_file = strcompress(filename+'_B0'+string(i)+'.h5',/remove_all)
  'RADDIR/gainnbias_reversal', current_file, WODIR, RADDIR
endfor

for i=10,bands DO BEGIN
 ;current_file = strcompress(filename+'_B'+string(i)+'.h5',/remove_all)
 ;gainnbias_reversal,current_file, WODIR, RADDIR
 ;not dealing with this part just yet
endfor

end
And here's the error I'm getting:

'RADDIR/gainnbias_reversal', current_file, WODIR, RADDIR
^
% Syntax error.
At: /home/ic/rad_sim/drive_gnb_reversal.pro, Line 8
% Compiled module: DRIVE_GNB_REVERSAL.
% Attempt to call undefined procedure/function: 'DRIVE_GNB_REVERSAL'.
% Execution halted at: $MAIN$

I suppose I could just CD around through the directories, but
I'd rather not do that.
 
Old 07-20-2010, 11:25 AM   #7
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
I've done some playing around.

If I use
Code:
 $3/drive_gnb_reversal $1 $2 $3
I get
Code:
 /home/ic/rad_sim/drive_gnb_reversal LO80400340342001213EDC00_B02
 /edclxs111/data1/testdata/workorder/4034 /home/ic/rad_sim
 ^
% Syntax error.
If I use

Code:
`$3/drive_gnb_reversal $1 $2 $3`
I get

Code:
/home/ic/rad_sim/drive_gnb_reversal: Command not found.
Throwing quotes and parenthesis in only gave me different syntax errors.
Any ideas?

Thanks,
Lost
 
Old 07-20-2010, 02:52 PM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Ah, so you're trying to run your procedure that's the directory stored in $3? You need to compile the procedure first with .r, e.g.

set var="/some/directory"

idl<<EOF
.r $var/my_procedure
my_procedure, arg1, arg2
EOF

Does that help?
 
1 members found this post helpful.
Old 07-20-2010, 04:49 PM   #9
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
Awesome, thanks! It works. Sort of. At least it worked the first time. I've done some tweaking, and here's what I've got now.

Code:
#!/bin/csh

#if ($#argv != 2) then
#	echo "Usage: rpsdriver.csh <.h5 file ie. LO80400340342001213EDC00_B02>
#<WODIR ie. $WODIR/4034> <RADDIR currently ~/rad_sim>"
#	exit
#endif

set WorkDir = '$WODIR/4034'
# set WorkDir = $2
set RadDir = ~/rad_sim
# set RadDir = $3
set filename = LO80400340342001213EDC00_B02
# set filename = $1
echo $RadDir
set curdir = `pwd`

idl << BEGIN
print, '$WorkDir'
print, '$RadDir'
print, '$filename'
.run '$RadDir/drive_gnb_reversal'
drive_gnb_reversal, '$filename', '$WorkDir', '$RadDir'
BEGIN
That works fine, but in the drive_gnb_reversal, I used the same format:

Code:
pro drive_gnb_reversal, filename, WorkDir, RadDir

filename = strmid(filename,0,24)
bands = 12
for i = 1,9 DO BEGIN
  current_file = strcompress(filename+'_B0'+string(i)+'.h5',/remove_all)
  .run 'RadDir/gainnbias_reversal'
  gainnbias_reversal, 'current_file', 'WorkDir', 'RadDir'
endfor

for i=10,bands DO BEGIN
 current_file = strcompress(filename+'_B'+string(i)+'.h5',/remove_all)
 .run 'RadDir/Gainnbais_reversal'
  gainnbias_reversal, 'current_file', 'WorkDir', 'RadDir'
endfor

end
but I get:

Code:
.run 'RadDir/gainnbias_reversal'
 ^
% Syntax error.
  At: /home/icarlson/rad_sim/drive_gnb_reversal.pro, Line 7

 .run 'RadDir/Gainnbais_reversal'
  ^
% Syntax error.
  At: /home/icarlson/rad_sim/drive_gnb_reversal.pro, Line 13
% 2 Compilation error(s) in module DRIVE_GNB_REVERSAL.
% Attempt to call undefined procedure/function: 'DRIVE_GNB_REVERSAL'.
% Execution halted at: $MAIN$
I suspect the problem has something to do with the way I'm trying to handle IDL variables. I hate to ask such a simplistic question on this forum, but I can't find good documentation or readable examples anywhere. Am I treating the variables correctly? If so, any ideas what the problem is?

Thanks again,
Lost

Edit: The first file still has some leftovers from troubleshooting, but just ignore those. I hardcoded some variables in to make calling the program easier while working on it.

Last edited by Lost_Oracle; 07-20-2010 at 04:52 PM.
 
Old 07-20-2010, 04:54 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
A stupid/childish question o the OP: are you sure it's ".run" and not './run' ?
 
Old 07-20-2010, 05:02 PM   #11
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
A valid question as far as I'm concerned. I went ahead and tried ./run, along with .r and. .r appears to be equivalent to .run but when I used ./run it returned

%No such executive command: ./run

Thanks for the suggestion though. I've missed things like that before.

Lost
 
Old 07-21-2010, 06:06 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by Lost_Oracle View Post
Code:
.run 'RadDir/gainnbias_reversal'
Originally, I thought that the problem was that you had been using a string literal ("RadDir"), as opposed to your variable of the same name. In that case, the solution would have been to simply concatenate the variable and the rest (e.g. RadDir + '/gainnbias_reversal'). However, this doesn't work - it doesn't seem to be possible to use strings as normal with commands like .run.

Unfortunately, I don't know how to get it to work the way you want. What you could do, though, is put your procedures in some directory and then update IDL's !PATH environment variable (which you can put in a startup file, usually ~/.idl/idlstart.pro). Then you'll just be able to run gainnbias_reversal, since IDL will know where to find it.

You might want to post on some IDL newsgroups or mailing lists (do some googling, as I'm unable to recommend any, I'm afraid), because you're probably likely to get better help.

Sorry I couldn't be of more help .

Out of pure curiosity, what kind of work are you doing where you're using IDL?

Last edited by Nylex; 07-21-2010 at 06:28 AM.
 
1 members found this post helpful.
Old 07-21-2010, 08:52 AM   #13
Lost_Oracle
LQ Newbie
 
Registered: Jul 2010
Distribution: Red Hat Commercial
Posts: 16

Original Poster
Rep: Reputation: 2
I'm doing a summer internship, mostly writing scrips to automate long processing tasks. For that we mostly use Perl and cshell. We are also using IDL to do some calculations on images, which it's very useful for. I have no idea why the team we're working with used IDL to do this particular part of the work. It's just calling other processes and modifying strings mostly. Perl would have been so much easier, and even cshell would have been better.

Anyway, thanks for you help. I'll try setting the IDL path- which I'm sure will be another adventure in itself. Never a dull moment.

Lost
 
Old 07-21-2010, 01:15 PM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Cool.

Setting the path shouldn't be too difficult, just string concatenation, e.g.

!PATH = !PATH + '/new/directory'

In IDL, : is used to separate directory entries in !PATH. So, you should first check your !PATH to see if it ends in a : and if not, add it when you add the new directory. In the example above, I just assumed that !PATH ended with a :, so have just written '/new/directory', rather than ':/new/directory'.
 
1 members found this post helpful.
Old 09-29-2014, 08:13 AM   #15
mAIOR
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Rep: Reputation: Disabled
Same problem... Slightly more complicated

Hello. I am having the same problem as the thread creator with some added spice if you will.

I am trying to run a program in IDL that uses a lot of user created variables. The caveat is that I am running it through a server instead of using my own machine (licensing issues). Now, this is what I do:

I run idl with a .csh file in the beginning which adds the paths for the custom variables like so:

!path = extend_path('+/home/Wavemill/WE2ES')+':'+!path
pref_set,'IDL_PATH',!path,/commit

After adding the paths, I check the !path variable and the paths are all there as they should be. The problem is that whenever I try to run the program, it tells me it cannot find the target function within the paths I specified with the following message:

% Attempt to call undefined procedure/function: 'GEO'.

Now, I tried pretty much everything I could think of within these variations but with no luck.

This is really causing me headaches. I fear it may be an issue of permissions/compatibility and if so, I don't suppose there is much I could do but, I hope I am just missing something and some of you who are more used to IDL can shed some light in the matter.


Cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Spex and IDL bmedvar Programming 0 05-19-2009 03:03 PM
SpeX and IDL bmedvar Linux - Newbie 0 05-19-2009 12:17 PM
Find a file path and directory path ak.lokesh Linux - Newbie 3 02-19-2009 12:37 PM
idl to h file eantoranz Programming 1 04-23-2005 03:08 AM
IDL on redhat ajoshay9 Linux - Software 0 11-21-2003 03:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration