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

Home » Public Forums » archive » Cut down a big file into several files based on its a column.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Cut down a big file into several files based on its a column. [message #53061 is a reply to message #53012] Fri, 16 March 2007 08:34 Go to previous messageGo to previous message
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
On Mar 16, 9:46 am, "DirtyHarry" <kim20...@gmail.com> wrote:
> Thanks, Maarten... but... T.T
>
> Is there any way to do this in Windows version of IDL?

This was my first try. It doesn't quite work, because I can't get the
format statment right (how do you insert linebreaks?)

;;; failed attempt.
file='hum.txt'
ndata=file_lines(file)
data=intarr(28, ndata)

for year=2000,2005 do begin
openw, unit, string(format="('HumNWS_',I04,'.txt')", year), /get_lun

idx = where(data[1,*] eq year, cnt)
if cnt gt 0 then begin
fmt=string(format="('(',I04,'(28i6))')", cnt)
; it would ne neat if IDL actually allowed to add newlines between
the blocks here.
printf, unit, format=fmt, data[*,idx]
endif

free_lun, unit
endfor
end

;;; Second attempt: use explicit for loop.
file='hum.txt'
ndata=file_lines(file)
data=intarr(28, ndata)

for year=2000,2005 do begin
openw, unit, string(format="('HumNWS_',I04,'.txt')", year), /get_lun

idx = where(data[1,*] eq year, cnt)
fmt='(28i6)'
if cnt gt 0 then $
for ii=0,cnt-1 do $
printf, unit, format=fmt, data[*,idx[ii]]

free_lun, unit
endfor
end

HTMH,

Maarten
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Change in Map_Contintent behavior?
Next Topic: Re: Histogram looks like spiky bars

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

Current Time: Wed Oct 22 15:49:10 PDT 2025

Total time taken to generate the page: 0.88170 seconds