On Feb 12, 7:00 pm, Kemal Ramic <krami...@gmail.com> wrote:
> Hello guys,
> I am completely new to IDL. I have problems with outputting 2D arrays
> into a txt file. What i have to do is run the procedure a 1000 times,
> and the procedure is looking for a number of clumps hit in X-ray and
> optical area, and it goes through different inclination and azimuthal
> angle, and stores all the values into a 2D arrays, one for X-ray and
> one for Optical region. Here is my code:
>
> function satellite,clumps,nasteps,nisteps,fnamex,fnameo
>
> azi=0.0
> observer_azi=0.0
> ii=0.0
> observer_i=0.0
>
> lines_x=fltarr(nisteps+1,nasteps+1)
> lines_o=fltarr(nisteps+1,nasteps+1)
>
> ; each row has same azi
> for i=0L,nasteps-1 do lines_x[0,i+1]=(360.0/(nasteps-1))*i
> for i=0L,nasteps-1 do lines_o[0,i+1]=(360.0/(nasteps-1))*i
>
> ; each column has same inclination from -90 to 90
> for i=0L,nisteps-1 do lines_x[i+1,0]=(180.0/(nisteps-1))*i-90.0
> for i=0L,nisteps-1 do lines_o[i+1,0]=(180.0/(nisteps-1))*i-90.0
>
> for j=1L,nisteps do begin
>
> for i=1L,nasteps do begin
>
> intersect_x=fltarr(2,50)
> intersect_o=fltarr(2,600)
>
> print, 'Azimuth=', lines_x[0,i]
> print, 'Inclination=', lines_x[j,0]
>
> line_sphere_test,clumps,lines_x[0,i],lines_x[j,
> 0],intersect_x,intersect_o
> print, moment(intersect_x[0,*])
> print, moment(intersect_o[0,*])
>
> lines_x[j,i]=(moment(intersect_x[0,*]))[0]
> lines_o[j,i]=(moment(intersect_o[0,*]))[0]
> print,'end of a step'
>
> endfor
> endfor
>
> openw,1,fnamex
> openw,2,fnameo
> for j=0L,nasteps do begin
>
> printf,1,lines_x[*,j]
> printf,2,lines_o[*,j]
>
> endfor
> close,1
> close,2
>
> return, lines_o
>
> end
> and this is how i run the code 1000 times:pro run_satellite
>
> N = 1000
> root='datarun5_kemal'
> nasteps=3
> nisteps=3
>
> for i=0,N-1 do begin
>
> fxray=root+strtrim(i,2)+'_xray.txt'
> fopt=root+strtrim(i,2)+'_opt.txt'
>
> clumps=clumps_generator(1000,0.5,2,30,0.02,1.5)
>
> test=satellite(clumps,nasteps,nisteps,fxray,fopt)
>
> endfor
>
> return
> end
>
> The problem that occurs is the way tables(arrays) are formated. First
> it doesnt output 1000 txt files for each, but it crams them up in a
> few, and then I cant figure out formatting at all. What i want is
> having them, in tables where i can later go through each column, and
> analyze data. Can somebody please help me?
So, everything have will probably work just fine if you simply add
some formatting to your data. IDL will accept both the ForTran and C-
style formats, personally I use the ForTran ones. If you're not
familiar with them, here's a quick run down of the basics.
F = floating point (or double)
I = Integer (or long)
E = exponential notation (such as 4.22E+01)
X = white space
For the floats, you use the notation Fx.y where x = total number of
characters (including + or - sign, and decimal point), and y = number
of digits after the decimal point. So F5.3 would be a format of
4.221.
For the integers, you simply do Ix where x = number of characters
(including + or - sign). So I3 would be a number like 888.
For exponential notation, you do Ex.y, where x=total number of
characters (including +/- sign, decimal point, the big "E", another
+/- sign for the exponent, and 2 more characters for the exponent).
SO the format E10.4 would be 1.2345E+02.
For white space, you do nX, where n is the number of white spaces you
want.
Suppose you have data within IDL of the form: x=1.03348475627687495d0,
y=4L, z=-2.304E-03 and wnat to write them to (either a file or
formatted print to the screen), you could do:
printf,lun,x,y,z,f='(F5.3,1X,I1,1X,E10.3)'
This is on the tip of the iceberg, have a look at:
http://physics.nyu.edu/grierlab/idl_html_help/files12.html#w p168597
-Russell
|