IDL Problem- passing variables between procedures

  • Thread starter TheSource007
  • Start date
  • Tags
    Variables
In summary: 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.
  • #1
TheSource007
15
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
  • #2
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.
 
  • #3
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.
 
  • #4
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
 
  • #5
I am using Windows 7
 
  • #6
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:
  • #7
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.
 
  • #8
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.
 
  • #9
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
 

FAQ: IDL Problem- passing variables between procedures

1. How can I pass variables between procedures in IDL?

The easiest way to pass variables between procedures in IDL is by using the PRO keyword when defining a procedure. This allows the variable to be accessed by other procedures that call it.

2. Can I pass multiple variables between procedures in IDL?

Yes, you can pass multiple variables between procedures in IDL by simply separating them with a comma after the PRO keyword. For example: PRO myproc, var1, var2, var3.

3. How do I pass variables by reference in IDL?

To pass variables by reference in IDL, you can use the BYREF keyword after the variable name when calling a procedure. This allows the procedure to directly modify the original variable instead of creating a copy.

4. What happens if I don't specify a variable type when passing it between procedures in IDL?

If you don't specify a variable type when passing it between procedures in IDL, the default type will be DOUBLE (64-bit floating point). It is recommended to always specify the variable type to avoid potential errors.

5. Can I pass arrays between procedures in IDL?

Yes, you can pass arrays between procedures in IDL by using the [] syntax when defining and calling the procedure. This will allow the procedure to access and modify the elements of the array.

Similar threads

Back
Top