IDL Problem- passing variables between procedures

  • Thread starter Thread starter TheSource007
  • Start date Start date
  • Tags Tags
    Variables
AI Thread Summary
The discussion revolves around a user seeking help with executing two IDL procedures, hr2altaz and altaz2hr, to convert between hour-angle/declination (HA/DEC) and altitude/azimuth (ALT/AZ) repeatedly to assess precision changes. The user is unsure how to transfer outputs from one procedure to the input of the other and is considering using loops for this process. Suggestions include using batch files for Windows to redirect inputs and outputs, but the user encounters issues with program recognition. It is clarified that IDL is an interactive environment, and a more efficient approach would be to modify the existing procedures to work within a single program that uses loops to handle the conversions directly, allowing for easier variable management and comparisons. The user ultimately resolves their issue by integrating the procedures into one program.
TheSource007
Messages
14
Reaction score
0
Hi all.
This is my problem. I have two IDL procedures
hr2altaz, hour, dec, alt, az -- which takes the HA and DEC and
converts it to ALT and AZ
altaz2hr, hour, dec, alt, az -- which takes ALT and AZ, and converts
it to HA and DEC.

What I need to do, is to begin with a certain HA and DEC, execute
hr2altaz, which will give me the ALT and AZ, and then take those two
outputs to execute altaz2hr, which will convert themj back to HA and
DEC, and then repeat the process many times (say 100).
The purpose being to compare the initial HA, DEC to the final (after
100 reps) HA, DEC. in order to see any changes in precision.
I have no idea how to do this. I think I might need some loops, but I don't know how to tranfer the output of the first procedure to be the input of the other, and back.
Thank you for your help
 
Technology news on Phys.org
Direct the standard output of the first procedure to a file. Direct the standard input of the second procedure from that file output by the first procedure.
 
Ok, but say I do it this way:
the input file has HA, DEC, then execute the first procedure, an it will print the ALT, AZ on the input file. How can I command the code to read the ALT, AZ for the first procedure?
For example I can have the HA, DEC in the first row. How do I print the ALT, AZ on the second row? How do I command the code to read the second row and print the HA,DEC on the third row, which will read the next one and so one?
I don't know how to do that. I am kind of new to this language.
 
What operating system are you using? For MSDOS console window, you use ">" to redirect standard output to a file and "<" to redirect standard input:

programa >file.txt
programb <file.txt
 
I am using Windows 7
 
TheSource007 said:
I am using Windows 7
Then you can create a pair of batch files to run the programs (preferably in a dos console window) multiple times, and redirect standard inputs and outputs so that they are files. Assuming windows 7 dos console window has command extensions enabled you can use two batch files to run a loop. Assume the initial data is in a file called test.txt, and the final output will be in result.txt. (The @echo run %1 statement just displays the current run number, it is not needed).

test.bat
Code:
@copy test.txt filea.txt
@for /L %%c in (1 1 100) do @call doarun.bat %%c
@copy filea.txt result.txt

doarun.bat
Code:
@echo run %1
@programa <filea.txt >fileb.txt
@programb <fileb.txt >filea.txt
 
Last edited:
It doesn't seem to be working. When I run the test.bat file it says that it cannot find the program. Are my procedures suppose to have a different format from .pro for it to work? I might be doing something wrong.
What language are those batch files? Even though I've only used IDL for about 2 weeks I haven't seen that kind of commands.
 
TheSource007 said:
What language are those batch files?
The batch files use the command line syntax for the dos console window environment (the actual program name is CMD.EXE). This syntax dates back to the days of PCDOS and MSDOS. To open the dos console window on Windows XP, you have to click on programs, accessories, command prompt. For Windows 7, the sequence is a bit different, but the last thing you click on to start the dos console window should be "command prompt" that shows a blacked out window for an icon.

TheSource007 said:
Even though I've only used IDL for about 2 weeks I haven't seen that kind of commands.
I didn't know that IDL was an interactive language with it's own environment until I did a web search for it. If you want to use the dos console batch files similar to what I show above, you'll need to change the "doarun.bat" replacing the lines that include "programa" and "programb" into commands that launch the IDL environment with command line options to run your procedures, then exit back to the dos console window environment, something like

idlde -e @programa

where programa.pro is your program.

Since IDL is an interactive environment, couldn't you create a procedure in IDL to run the other pair of procedures 100 times? You're existing procedures would need to be modified to use specific file names in order to share them. I don't know IDL or the syntax you would need to do this.
 
This seems like a rather round-about route. Would it not be possible to create a program that iterated (using for loops) through the data (creating it if necessary) and doing a direct comparison?

I'm presuming (knowing nothing about IDL) that your procedures take and return values through the parameter list? In which case, can you not simply take the variable holding HA and DEC, eg

<loop round this block of code>

hour0 = ...
dec0 = ...

hr2altaz, hour0, dec0, alt, az (alt and az should hold the converted values ...)
altaz2hr, hour1, dec1, alt, az (which now form the input to the 2nd procedure)
hdiff = hour0 - hour1
ddiff = dec0 - dec1
<print hour0,hour1,hdiff,dec0,dec1,ddiff>
hour0 = hour1
dec0 = dec1

<end of loop block>
Alternatively, you could assign the variables to an array for further processing.

(As I say, I don't know anything about IDL but the above would seem to be possible)
 
  • #10
NemoReally said:
This seems like a rather round-about route.
My fault, I didn't realize that IDL is an interactive environment. I incorrectly assumed that the original poster meant he had two existing IDL "programs" (.EXE files, not text files to be run by an interpreter, since there are IDL compilers).

It would seem to be easiest to combine the existing "procedure" code into a single program with a loop.
 
Last edited:
  • #11
I figured it out. Thanks
 
Back
Top