Re: Writing to ASCII files [message #21329] |
Tue, 22 August 2000 00:00 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Jasmeet Judge <jjudge@indiana.edu> writes:
> 1. When I use printf (and even writeu), it gives me
> non-sensible results. Here is what I am doing
>
> openw,unitno,filename
> some loop with i
> printf,unitno,item1(i),item2(i)
> end loop
> close,unitno
>
> What I would like is:
> item1(0) item2(0)
> item1(1) item2(1)
> item1(2) item2(2)
> item1(3) item2(3)
Hi Jasmeet, what you have here looks like the right invocations, so I
am a little confused why you get garbage out. You can use a FORMAT
keyword as the other poster suggested, but by default you should get
something reasonable. Can you post the actual code (+ snippet of
data)? The only way I know to get unformatted/binary data out is to
use the WRITEU procedure.
> 2. Is there a way to open a file to write (with openw) but have
> it keep appending data at the end of file with every call to printf?
>
> It would simplify my life considerably, if I can figure this
> out! I have avoided dealing with this for too long....
The documentation is your friend. How about,
openu, unit, filename, /append
printf, unit, snorgle
close, unit
OPENU is for "update", and APPEND ensures that the file pointer is at
the end of the file.
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Writing to ASCII files [message #21333 is a reply to message #21329] |
Tue, 22 August 2000 00:00  |
Ivan Zimine
Messages: 40 Registered: February 1999
|
Member |
|
|
Jasmeet Judge wrote:
>
> Hi,
> I just started reading this newsgroup. I found out
> about its existence after 6 yrs of IDL-use on UNIX!! I never
> could write an ascii file with columns of no.s from IDL.
> I have two specific qs. regarding this:
>
> 1. When I use printf (and even writeu), it gives me
> non-sensible results. Here is what I am doing
>
> openw,unitno,filename
> some loop with i
> printf,unitno,item1(i),item2(i)
> end loop
> close,unitno
>
> What I would like is:
> item1(0) item2(0)
> item1(1) item2(1)
> item1(2) item2(2)
> item1(3) item2(3)
>
> Instead, I get some unreadable jargon (I guess it is writing
> binary?). Is there a way to do this in IDL?
>
> 2. Is there a way to open a file to write (with openw) but have
> it keep appending data at the end of file with every call to printf?
>
IDL> print, !version
{ x86 linux unix 5.2.1L Aug 2 1999}
IDL> x=indgen(10)
IDL> y = x*2
IDL> openw, lun, 'test.txt', /get_lun
IDL> for i=0,9 do printf, lun, x[i], y[i], format='(i4, i4)'
IDL> free_lun, lun
IDL> openw, 1, 'test.txt', /append
IDL> for i=0,9 do printf, 1, x[i]+10, y[i]*2, format='(i4, i4)'
IDL> close,1
prompt% cat test.txt
0 0
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
10 0
11 4
12 8
13 12
14 16
15 20
16 24
17 28
18 32
19 36
regards,
Ivan
--
Ivan Zimine | ivan.zimine@physics.unige.ch
Dpt. of Radiology | (+41 22) 372 70 70
Geneva University Hospitals |
|
|
|