|
|||
|
Thanks a lot for the quick answer... So that is what my code looks
like now: pro testif nx=findgen(64) ny=findgen(64) x0=(30./32.*(0.5+nx))-30. y0=(30./32.*(0.5+ny))-30. N=findgen(10) S=dblarr(n_elements(nx),n_elements(ny),n_elements( N)) phi=N*36*!pi/180 for i=0,n_elements(nx) do begin for j=0,n_elements(ny) do begin nrows=1. dfov=60. mu=438.689 ri=0.1 wdet=45. r=50. a=73.73 N=10 d=0.736 f=29.33 r0=sqrt(x0[i]^2+y0[j]^2) if (r0 gt 30.) then S[i,j,*]=0 else begin x=abs(x0*cos(phi)+y0*sin(phi)) y=-x0*sin(phi)+y0*cos(phi) h=50.-y deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180)) S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100 deffr=d+alog(2)/mu*tan(a/2*!pi/180) R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2) endelse endfor endfor S_plot=total(S,3) print, x0, y0, s_plot ;isurface,S_plot,x0,y0 end However the r0 did not work. And there is another error. The error message says "subscript range values of the form low:high must be >=0, < size, with low <= high: S" and the error is in the S[i,j,*]=... line... What does that mean??? |
|
|
||||
|
||||
|
|
|
|||
|
On Oct 28, 9:12*pm, Nicki <nickireite...@yahoo.de> wrote:
> However the r0 did not work. And there is another error. The error > message says "subscript range values of the form low:high must be >=0, > < size, with low *<= high: S" and the error is in the S[i,j,*]=... > line... > What does that mean??? There were a few typos. This should work: pro testif nrows=1. dfov=60. mu=438.689 ri=0.1 wdet=45. r=50. a=73.73 N=10 d=0.736 f=29.33 nx=findgen(64) ny=findgen(64) x0=(30./32.*(0.5+nx))-30. y0=(30./32.*(0.5+ny))-30. N=findgen(10) S=dblarr(n_elements(nx),n_elements(ny),n_elements( N)) phi=N*36*!pi/180 for i=0,n_elements(nx)-1 do begin for j=0,n_elements(ny)-1 do begin r0=sqrt(x0[i]^2+y0[j]^2) if (r0 gt 30.) then S[i,j,*]=0 else begin x=abs(x0[i]*cos(phi)+y0[j]*sin(phi)) y=-x0[i]*sin(phi)+y0[j]*cos(phi) h=50.-y deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180)) S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100 deffr=d+alog(2)/mu*tan(a/2*!pi/180) R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2) endelse endfor endfor S_plot=total(S,3) print, x0, y0, s_plot isurface,S_plot,x0,y0 end |
|
|||
|
On Oct 28, 8:40*pm, pp <pp.pente...@gmail.com> wrote:
> On Oct 28, 9:12*pm, Nicki <nickireite...@yahoo.de> wrote: > > > However the r0 did not work. And there is another error. The error > > message says "subscript range values of the form low:high must be >=0, > > < size, with low *<= high: S" and the error is in the S[i,j,*]=.... > > line... > > What does that mean??? > > There were a few typos. This should work: > > pro testif > nrows=1. > dfov=60. > mu=438.689 > ri=0.1 > wdet=45. > r=50. > a=73.73 > N=10 > d=0.736 > f=29.33 > nx=findgen(64) > ny=findgen(64) > x0=(30./32.*(0.5+nx))-30. > y0=(30./32.*(0.5+ny))-30. > N=findgen(10) > S=dblarr(n_elements(nx),n_elements(ny),n_elements( N)) > phi=N*36*!pi/180 > for i=0,n_elements(nx)-1 do begin > * for j=0,n_elements(ny)-1 do begin > * * r0=sqrt(x0[i]^2+y0[j]^2) > * * if (r0 gt 30.) then S[i,j,*]=0 else begin > * * * x=abs(x0[i]*cos(phi)+y0[j]*sin(phi)) > * * * y=-x0[i]*sin(phi)+y0[j]*cos(phi) > * * * h=50.-y > * * * deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180)) > * * * S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100 > * * * deffr=d+alog(2)/mu*tan(a/2*!pi/180) > * * * R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2) > * * endelse > * endfor > endfor > S_plot=total(S,3) > print, x0, y0, s_plot > isurface,S_plot,x0,y0 > end Can't you replace the for loops with: nnx = n_elements(nx) nny = n_elements(ny) nN = n_elements(N) x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN) y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN) phi = rebin(reform(phi,1,1,nN),nnx,nny,nN) r0 = sqrt(x0^2 + y0^2) x = abs(x0*cos(phi) + y0*sin(phi)) y = -x0*sin(phi) + y0*cos(phi) h = 50.-y deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.)) S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100. deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.) R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2) -Jeremy. |
|
|||
|
On Oct 30, 1:55*am, Jeremy Bailin <astroco...@gmail.com> wrote:
> Can't you replace the for loops with: > > nnx = n_elements(nx) > nny = n_elements(ny) > nN = n_elements(N) > x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN) > y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN) > phi = rebin(reform(phi,1,1,nN),nnx,nny,nN) > r0 = sqrt(x0^2 + y0^2) > x = abs(x0*cos(phi) + y0*sin(phi)) > y = -x0*sin(phi) + y0*cos(phi) > h = 50.-y > deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.)) > S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100. > deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.) > R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2) > > -Jeremy. Yes, that is about what I was hinting at when I said it could be done without loops. But given the initial question, I thought that jumping directly to this level might make it difficult to understand. |
|
|||
|
On Oct 30, 12:12*am, pp <pp.pente...@gmail.com> wrote:
> On Oct 30, 1:55*am, Jeremy Bailin <astroco...@gmail.com> wrote: > > > > > > > Can't you replace the for loops with: > > > nnx = n_elements(nx) > > nny = n_elements(ny) > > nN = n_elements(N) > > x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN) > > y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN) > > phi = rebin(reform(phi,1,1,nN),nnx,nny,nN) > > r0 = sqrt(x0^2 + y0^2) > > x = abs(x0*cos(phi) + y0*sin(phi)) > > y = -x0*sin(phi) + y0*cos(phi) > > h = 50.-y > > deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.)) > > S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100. > > deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.) > > R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2) > > > -Jeremy. > > Yes, that is about what I was hinting at when I said it could be done > without loops. But given the initial question, I thought that jumping > directly to this level might make it difficult to understand. Oddly enough, I think this version is much more readable than the looped version... I think that's a sign of doing too mcuh IDL programming! ;-) -Jeremy. |
|
|
![]() |
| Popular Tags in the Forum |
| plot, summation |
| Thread Tools | |
| Display Modes | |
|
|