comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » outputting 2D arrays into a txt file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
outputting 2D arrays into a txt file [message #79220] Sun, 12 February 2012 16:00 Go to next message
Kemal Ramic is currently offline  Kemal Ramic
Messages: 1
Registered: February 2012
Junior Member
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?
Re: outputting 2D arrays into a txt file [message #79301 is a reply to message #79220] Mon, 13 February 2012 12:08 Go to previous message
Russell[1] is currently offline  Russell[1]
Messages: 101
Registered: August 2011
Senior Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Required Classes
Next Topic: Re: pth order auto-regressive process with a specified mean and variance

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:05:33 PDT 2025

Total time taken to generate the page: 0.00667 seconds