Convert Function to Procedure [message #93237] |
Tue, 17 May 2016 09:33  |
dmfl0590
Messages: 17 Registered: December 2015
|
Junior Member |
|
|
Hi
I have the following function:
FUNCTION CREATE_NEW, Im1, Im2, B, step=step, itmax=itmax
Bnew = B
ffd_precompute,Im1,size(REFORM(B[0,*,*]), /dimensions)
ffd_grad_precompute, size(REFORM(B[0,*,*]), /dimensions)
for it=1L, itmax do begin
FIRST_FUN, Im1, Im2, Bnew, G=G
Bnew = SECOND_FUN(Im1, Im2, Bnew, G, conv=converged,step=step)
if converged then return, Bnew
endfor
return, Bnew
END
Then I changed this Function to Procedure like this:
PRO CREATE_NEW, Im1, Im2, B, step=step, itmax=itmax
Breg = B
ffd_precompute,Im1,size(REFORM(B[0,*,*]), /dimensions)
ffd_grad_precompute, size(REFORM(B[0,*,*]), /dimensions)
for it=1L, itmax do begin
FIRST_FUN, Im1, Im2, Bnew, G=G
Bnew = SECOND_FUN(Im1, Im2, Bnew, G, conv=converged,step=step)
if converged then begin
B=Bnew
return
endif
endfor
B=Bnew
END
I don't get the same results for some reason. I thought that I can put the output variables in the calling statement. The output variable in this case is the B. However, I don't get the output variable. Can anyone help with this?
|
|
|
Re: Convert Function to Procedure [message #93238 is a reply to message #93237] |
Tue, 17 May 2016 10:57   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Tuesday, May 17, 2016 at 12:33:52 PM UTC-4, dmfl...@gmail.com wrote:
> Hi
>
> I have the following function:
>
> FUNCTION CREATE_NEW, Im1, Im2, B, step=step, itmax=itmax
> Bnew = B
> ffd_precompute,Im1,size(REFORM(B[0,*,*]), /dimensions)
> ffd_grad_precompute, size(REFORM(B[0,*,*]), /dimensions)
> for it=1L, itmax do begin
> FIRST_FUN, Im1, Im2, Bnew, G=G
> Bnew = SECOND_FUN(Im1, Im2, Bnew, G, conv=converged,step=step)
> if converged then return, Bnew
> endfor
> return, Bnew
> END
>
> Then I changed this Function to Procedure like this:
>
> PRO CREATE_NEW, Im1, Im2, B, step=step, itmax=itmax
> Breg = B
> ffd_precompute,Im1,size(REFORM(B[0,*,*]), /dimensions)
> ffd_grad_precompute, size(REFORM(B[0,*,*]), /dimensions)
> for it=1L, itmax do begin
> FIRST_FUN, Im1, Im2, Bnew, G=G
> Bnew = SECOND_FUN(Im1, Im2, Bnew, G, conv=converged,step=step)
> if converged then begin
> B=Bnew
> return
> endif
> endfor
> B=Bnew
> END
>
>
> I don't get the same results for some reason. I thought that I can put the output variables in the calling statement. The output variable in this case is the B. However, I don't get the output variable. Can anyone help with this?
What do you mean you "don't get the output variable" Do you mean that the variable B is undefined? or that the values are not the same as the output of CREATE_NEW()?
> PRO CREATE_NEW, Im1, Im2, B, step=step, itmax=itmax
> Breg = B
What is the variable Breg ? Why didn't you set this to Bnew like in the function?
I would put stop statements (or breakpoints) in your procedure, and make sure that values are what you expect (or the same as the function) at each step.
|
|
|
|