IDL Problem- passing variables between procedures

  • Thread starter Thread starter TheSource007
  • Start date Start date
  • Tags Tags
    Variables
Click For Summary

Discussion Overview

The discussion revolves around a problem related to passing variables between two IDL procedures, specifically hr2altaz and altaz2hr, which convert between hour angle/declination and altitude/azimuth. Participants explore methods to execute these procedures in a loop to assess changes in precision after multiple iterations.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes the need to repeatedly convert between HA/DEC and ALT/AZ using two IDL procedures and expresses uncertainty about how to transfer outputs between them.
  • Another participant suggests redirecting the standard output of the first procedure to a file and using that file as input for the second procedure.
  • A participant questions how to manage file outputs and inputs effectively, particularly how to structure the data in the file for sequential processing.
  • Discussion about the use of batch files in Windows to automate the execution of the procedures, with participants providing examples of batch file commands.
  • Some participants express confusion regarding the compatibility of the batch file commands with IDL procedures and the need for specific syntax to launch IDL from the command line.
  • One participant proposes an alternative approach of creating a single program with a loop to handle the conversions directly within IDL, rather than relying on file redirection.
  • Another participant acknowledges the misunderstanding regarding the nature of IDL as an interactive environment and suggests combining the procedures into a single program for efficiency.
  • Finally, one participant indicates they have resolved their issue without further details.

Areas of Agreement / Disagreement

The discussion features multiple competing views on how to effectively implement the variable passing between procedures, with no clear consensus on the best approach. Participants express differing opinions on using batch files versus modifying IDL procedures directly.

Contextual Notes

Participants mention limitations regarding their familiarity with IDL and the command line, which may affect their ability to implement suggested solutions. There is also uncertainty about the specific syntax required for IDL procedures when invoked from the command line.

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
 

Similar threads

Replies
3
Views
18K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 28 ·
Replies
28
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 35 ·
2
Replies
35
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K