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

Home » Public Forums » archive » Re: Breaking files
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
Re: Breaking files [message #70875] Fri, 14 May 2010 03:12 Go to next message
Timm Weitkamp is currently offline  Timm Weitkamp
Messages: 66
Registered: August 2002
Member
On May 13, 11:05 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> Hello,
>
> I have a code that is designed to read and process text files with
> this format:
>
> =xxx
> id = 1
> a = ...
> b = ...
> c = ...
>
> It starts by reading the data in using file_lines and a string array:
>
> infile = '/path/filename'
> n = file_lines(infile)
> data = strarr(n)
> openr, inunit, infile, /get_lun
> readf, inunit, data
>
> ... and ends by exporting stuff to another text file.
>
> Now I need to deal with input text files that have a slightly
> different format:
>
> =xxx
> id = 1
> a = ...
> b = ...
> c = ...
> =xxx
> id = 2
> a = ...
> b = ...
> c = ...
> =xxx
> id = 3
> a = ...
> b = ...
> c = ...
>
> They are just multiple files appended together. I was wondering if
> there is a simple way of breaking this new big file into multiple
> files with the old format so I don't have to change my code
> considerably (maybe using the "=xxx" lines to indicate where each file
> starts).
>
> Sorry if this is too obvious. I'm new to IDL.
>
> Thank you.

If you are working on a Unix or Linux system, the "split" utility
might be able to do this - at least if all the new small files that
you want to make have the same size or number of lines. Try "man
split" on the Unix command line to see if split is available on your
system and how it works. To launch "split" (or other Unix commands)
from IDL, you can use IDL's SPAWN command.

Good luck
Timm
Re: Breaking files [message #70879 is a reply to message #70875] Thu, 13 May 2010 17:21 Go to previous messageGo to next message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 13, 5:05 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> Hello,
>
> I have a code that is designed to read and process text files with
> this format:
>
> =xxx
> id = 1
> a = ...
> b = ...
> c = ...
>
> It starts by reading the data in using file_lines and a string array:
>
> infile = '/path/filename'
> n = file_lines(infile)
> data = strarr(n)
> openr, inunit, infile, /get_lun
> readf, inunit, data
>
> ... and ends by exporting stuff to another text file.
>
> Now I need to deal with input text files that have a slightly
> different format:
>
> =xxx
> id = 1
> a = ...
> b = ...
> c = ...
> =xxx
> id = 2
> a = ...
> b = ...
> c = ...
> =xxx
> id = 3
> a = ...
> b = ...
> c = ...
>
> They are just multiple files appended together. I was wondering if
> there is a simple way of breaking this new big file into multiple
> files with the old format so I don't have to change my code
> considerably (maybe using the "=xxx" lines to indicate where each file
> starts).
>
> Sorry if this is too obvious. I'm new to IDL.
>
> Thank you.

You can use WHERE(STREGEX(data_array,'=xxx',/boolean) to pick out
where the breaks are.
Re: Breaking files [message #71014 is a reply to message #70875] Fri, 14 May 2010 13:31 Go to previous message
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
Thanks for the suggestions. I can use WHERE to flag the those lines...
I'm just not really sure how to create a loop to run the entire script
for the first block of lines, then for the second and so one.

I use a Mac so I probably have the split utility. I'll take a look.
Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Save file creation rules of the road
Next Topic: Help with something that should be simple:

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

Current Time: Wed Oct 08 15:32:55 PDT 2025

Total time taken to generate the page: 0.00754 seconds