ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
#!/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.
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.
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
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.
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.
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?
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.
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'.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.