Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

IDL Problem- passing variables between procedures

  1. Jul 8, 2012 #1
    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 dont know how to tranfer the output of the first procedure to be the input of the other, and back.
    Thank you for your help
     
  2. jcsd
  3. Jul 8, 2012 #2

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  4. Jul 8, 2012 #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 dont know how to do that. I am kind of new to this language.
     
  5. Jul 8, 2012 #4

    rcgldr

    User Avatar
    Homework Helper

    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
     
  6. Jul 8, 2012 #5
    I am using Windows 7
     
  7. Jul 8, 2012 #6

    rcgldr

    User Avatar
    Homework Helper

    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 (Text):

    @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 (Text):

    @echo run %1
    @programa <filea.txt >fileb.txt
    @programb <fileb.txt >filea.txt
     
     
    Last edited: Jul 8, 2012
  8. Jul 8, 2012 #7
    It doesnt 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 havent seen that kind of commands.
     
  9. Jul 9, 2012 #8

    rcgldr

    User Avatar
    Homework Helper

    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.

    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.
     
  10. Jul 9, 2012 #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)
     
  11. Jul 9, 2012 #10

    rcgldr

    User Avatar
    Homework Helper

    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: Jul 9, 2012
  12. Jul 9, 2012 #11
    I figured it out. Thanks
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: IDL Problem- passing variables between procedures
  1. Unzipping in IDL (Replies: 1)

Loading...