|
Re: Passing variables between procedures [message #80780 is a reply to message #80778] |
Tue, 10 July 2012 10:47  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 7/10/12 10:13 AM, Thesource007 wrote:
> On Monday, July 9, 2012 7:36:00 AM UTC-10, Mike Galloy wrote:
>> On 7/6/12 10:28 PM, Thesource007 wrote:
>> > On Friday, July 6, 2012 8:42:48 PM UTC-7, Craig Markwardt wrote:
>> >> On Friday, July 6, 2012 5:43:30 PM UTC-4, Thesource007 wrote:
>> >>> 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.
>> >>> Is there a simple way to do this? Or I just have to use an input file
>> >>> and loops?
>> >>
>> >> Applying the function and its inverse: yes, just use a loop. The overhead of executing a loop 100 times is minimal.
>> >>
>> >> "An input file" : that's up to you. But you can always read your values into an array once at the beginning.
>> >>
>> >> Craig
>> >
>> > Ok. But now the question is... how do I "transfer" the output of one procedure to be the input of the other? I dont have a clue of how to do that.
>> > Thank you
>> >
>>
>> From what I understand, you just need to do this:
>>
>> for i = 0, 99 do begin
>> hr2altaz, orig_hour, orig_dec, alt, az
>> altaz2hr, hour, dec, alt, az
>> ; compare orig_hour/orig_dec to hour/dec
>> endfor
>>
>> IDL passes "named variables" like orig_hour, orig_dec, etc. by
>> reference, meaning changes to them inside the routine are passed out of
>> the routine. So when alt/az are modified in hr2altaz, the new values are
>> passed into altaz2hr.
>>
>> On the other hand, expressions like orig_hour[*], alt[0], my_struct.x,
>> etc. are passed by value and modifications to them inside a routine are
>> only local to that routine.
>>
>> Mike
>> --
>> Michael Galloy
>> www.michaelgalloy.com
>> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
>> Research Mathematician
>> Tech-X Corporation
>
> Thank you for your response. But now I have a question.
> How would I input the firts HA and DEC, and where should I write the code? Should be a new procedure?
> What I did was to create a new procedure like this
> pro doarun, hour, dec
> for i = 0, 99 do begin
> hr2altaz, hour, dec, alt, az
> altaz2hr, hour, dec, alt, az
> endfor
> END
> It seems to work, but I have some problems.
> The numbers used to change a bit. Something like the original inputs would be dorun, 18.5666, -16.7313
> and the last hour and dec(after 100 reps) would be 18.566597 & -16.730573. Good.
> Now what I wanted to do is to minimize this change, so I changed my codes to calculate in double precision. Now, for every hour, dec, alt, az, they just repeat 100 times, without any change. I dont know if this is suppose to happen, or maybe every time the loop runs, it takes my initial inputs again and again, which I dont think so because the numbers used to change (they were FLOAT before, now they are DOUBLE). Could you tell me if what I did was correct? I mean, I wanted to minimize the difference between the original inputs and outputs, but now they dont change at all. I dont know if I fixed it or I just messed it up.
> Thank you for your help
>
If you are doing it as above, the results of the last calculation are
used for the next -- they are not getting reset to the original values.
Of course, it's hard to vouch for them without seeing the entire code,
but since they were changing with float arrays, I would say it is highly
likely you are doing it right now.
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
Re: Passing variables between procedures [message #80781 is a reply to message #80780] |
Tue, 10 July 2012 09:13  |
Thesource007
Messages: 4 Registered: July 2012
|
Junior Member |
|
|
On Monday, July 9, 2012 7:36:00 AM UTC-10, Mike Galloy wrote:
> On 7/6/12 10:28 PM, Thesource007 wrote:
> > On Friday, July 6, 2012 8:42:48 PM UTC-7, Craig Markwardt wrote:
> >> On Friday, July 6, 2012 5:43:30 PM UTC-4, Thesource007 wrote:
> >>> 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.
> >>> Is there a simple way to do this? Or I just have to use an input file
> >>> and loops?
> >>
> >> Applying the function and its inverse: yes, just use a loop. The overhead of executing a loop 100 times is minimal.
> >>
> >> "An input file" : that's up to you. But you can always read your values into an array once at the beginning.
> >>
> >> Craig
> >
> > Ok. But now the question is... how do I "transfer" the output of one procedure to be the input of the other? I dont have a clue of how to do that.
> > Thank you
> >
>
> From what I understand, you just need to do this:
>
> for i = 0, 99 do begin
> hr2altaz, orig_hour, orig_dec, alt, az
> altaz2hr, hour, dec, alt, az
> ; compare orig_hour/orig_dec to hour/dec
> endfor
>
> IDL passes "named variables" like orig_hour, orig_dec, etc. by
> reference, meaning changes to them inside the routine are passed out of
> the routine. So when alt/az are modified in hr2altaz, the new values are
> passed into altaz2hr.
>
> On the other hand, expressions like orig_hour[*], alt[0], my_struct.x,
> etc. are passed by value and modifications to them inside a routine are
> only local to that routine.
>
> Mike
> --
> Michael Galloy
> www.michaelgalloy.com
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
> Research Mathematician
> Tech-X Corporation
Thank you for your response. But now I have a question.
How would I input the firts HA and DEC, and where should I write the code? Should be a new procedure?
What I did was to create a new procedure like this
pro doarun, hour, dec
for i = 0, 99 do begin
hr2altaz, hour, dec, alt, az
altaz2hr, hour, dec, alt, az
endfor
END
It seems to work, but I have some problems.
The numbers used to change a bit. Something like the original inputs would be dorun, 18.5666, -16.7313
and the last hour and dec(after 100 reps) would be 18.566597 & -16.730573. Good.
Now what I wanted to do is to minimize this change, so I changed my codes to calculate in double precision. Now, for every hour, dec, alt, az, they just repeat 100 times, without any change. I dont know if this is suppose to happen, or maybe every time the loop runs, it takes my initial inputs again and again, which I dont think so because the numbers used to change (they were FLOAT before, now they are DOUBLE). Could you tell me if what I did was correct? I mean, I wanted to minimize the difference between the original inputs and outputs, but now they dont change at all. I dont know if I fixed it or I just messed it up.
Thank you for your help
|
|
|
Re: Passing variables between procedures [message #80789 is a reply to message #80781] |
Mon, 09 July 2012 10:36  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 7/6/12 10:28 PM, Thesource007 wrote:
> On Friday, July 6, 2012 8:42:48 PM UTC-7, Craig Markwardt wrote:
>> On Friday, July 6, 2012 5:43:30 PM UTC-4, Thesource007 wrote:
>>> 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.
>>> Is there a simple way to do this? Or I just have to use an input file
>>> and loops?
>>
>> Applying the function and its inverse: yes, just use a loop. The overhead of executing a loop 100 times is minimal.
>>
>> "An input file" : that's up to you. But you can always read your values into an array once at the beginning.
>>
>> Craig
>
> Ok. But now the question is... how do I "transfer" the output of one procedure to be the input of the other? I dont have a clue of how to do that.
> Thank you
>
From what I understand, you just need to do this:
for i = 0, 99 do begin
hr2altaz, orig_hour, orig_dec, alt, az
altaz2hr, hour, dec, alt, az
; compare orig_hour/orig_dec to hour/dec
endfor
IDL passes "named variables" like orig_hour, orig_dec, etc. by
reference, meaning changes to them inside the routine are passed out of
the routine. So when alt/az are modified in hr2altaz, the new values are
passed into altaz2hr.
On the other hand, expressions like orig_hour[*], alt[0], my_struct.x,
etc. are passed by value and modifications to them inside a routine are
only local to that routine.
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
Re: Passing variables between procedures [message #80796 is a reply to message #80789] |
Fri, 06 July 2012 21:28  |
Thesource007
Messages: 4 Registered: July 2012
|
Junior Member |
|
|
On Friday, July 6, 2012 8:42:48 PM UTC-7, Craig Markwardt wrote:
> On Friday, July 6, 2012 5:43:30 PM UTC-4, Thesource007 wrote:
>> 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.
>> Is there a simple way to do this? Or I just have to use an input file
>> and loops?
>
> Applying the function and its inverse: yes, just use a loop. The overhead of executing a loop 100 times is minimal.
>
> "An input file" : that's up to you. But you can always read your values into an array once at the beginning.
>
> Craig
Ok. But now the question is... how do I "transfer" the output of one procedure to be the input of the other? I dont have a clue of how to do that.
Thank you
|
|
|
Re: Passing variables between procedures [message #80798 is a reply to message #80796] |
Fri, 06 July 2012 20:42  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Friday, July 6, 2012 5:43:30 PM UTC-4, Thesource007 wrote:
> 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.
> Is there a simple way to do this? Or I just have to use an input file
> and loops?
Applying the function and its inverse: yes, just use a loop. The overhead of executing a loop 100 times is minimal.
"An input file" : that's up to you. But you can always read your values into an array once at the beginning.
Craig
|
|
|