Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: read numerical text file by fixed column width, no delimiters
Replies: 11   Last Post: Jun 20, 2013 4:50 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: read numerical text file by fixed column width, no delimiters
Posted: Jun 19, 2013 11:11 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Thursday, June 20, 2013 12:22:09 PM UTC+12, dpb wrote:
> On 6/19/2013 4:44 PM, TideMan wrote:
>

> > On Thursday, June 20, 2013 8:06:42 AM UTC+12, dpb wrote:
>
> >> On 6/19/2013 2:36 PM, Kristin wrote:
>
> >>
>
> >> ...
>
> >>
>
> >>
>
> >>
>
> >> OK, here's a very rough, not terribly user=friendly outline, but should
>
> >>
>
> >> get the job done...
>
> >>
>
> >>
>
> >>
>
> >> program tentoeleven
>
> >>
>
> >> character(len=132):: fold, fnew ! A filename for old, new file
>
> >>
>
> >> real :: v(8) ! Data array of 8 floats
>
> >>
>
> >>
>
> >>
>
> >> read(*,*) fold ! It'll wait for you...
>
> >>
>
> >> open(11,file=fold,action='read',status='old')
>
> >>
>
> >>
>
> >>
>
> >> read(*,*) fnew ! It'll wait for you...
>
> >>
>
> >> open(12,file=fnew,action='write',status='new')
>
> >>
>
> >>
>
> >>
>
> >> ios=0
>
> >>
>
> >> do while(ios.eq.0)
>
> >>
>
> >> read(11,'(F10.4)',iostat=ios) v ! read the old file F10.4
>
> >>
>
> >> write(12,'(F11.4)') v ! F11.4 will insert space delimiter
>
> >>
>
> >> end do
>
> >>
>
> >>
>
> >>
>
> >> close(11)
>
> >>
>
> >> close(12)
>
> >>
>
> >> end
>
> >>
>
> >>
>
> >>
>
> >> Will continue 'til EOF condition on the old file at which time the
>
> >>
>
> >> IOSTATUS variable will become<0. Of course, other errors will also
>
> >>
>
> >> abort, but one presumes the files are otherwise, clean.
>
> >>
>
> >>
>
> >>
>
> >> --
>
> >
>
> > Here's an alternative that can be run within Matlab using:
>
> > dos(['tentoeleven ' infile ' ' outfile])
>
> > where infile and outfile are strings with the filenames.
>
> >
>
> > program tentoeleven
>
> > character(len=132):: fold, fnew ! A filename for old, new file
>
> > real :: v(8) ! Data array of 8 floats
>
> > integer :: na ! No of args on command line
>
> > integer :: ios ! Error code for read
>
> >
>
> > na=iargc()
>
> > if(na< 2)stop 'Must specify infile and outfile on command line'
>
> > call getarg(1,fold)
>
> > call getarg(2,fnew)
>
> >
>
> > open(11,file=fold,action='read',status='old')
>
> > open(12,file=fnew,action='write',status='new')
>
> >
>
> > ios=0
>
> > do while(ios.eq.0)
>
> > read(11,'(F10.4)',iostat=ios) v ! read the old file F10.4
>
> > write(12,'(F11.4)') v ! F11.4 will insert space delimiter
>
> > end do
>
> >
>
> > close(11)
>
> > close(12)
>
> > end
>
>
>
> Man, Tide, next you'll be giving a GUI file dialog... :) Gotta' leave
>
> _something_ as "exercise for the student" <vbg>
>
>
>
> _WHY_ can't TMW see this is a need to fix? I've asked in C groups and
>
> get the expected response there that one shouldn't write files that
>
> aren't human-readable (namely, delimited) which is, of course, less than
>
> helpful.
>
>
>
> To best of my recollection I filed bug reports/enhancement requests
>
> clear back w/ the first Windows version I had along about V4.0 or
>
> thereabouts and a few later times over the years when had support in
>
> place but never got a workaround suggestion (or, as best I can recall, a
>
> response even). It just seems incomprehensible it can be so and that's
>
> considered "ok". Along with it that could possibly get fixed as part of
>
> the same is the case of fixed-width input w/ blank as input being
>
> significant.
>
>
>
> --


Oh, dpb

You, like me, date back to the days when we communicated with computers via Hollerith cards. The cards were 80 columns wide and that's why we often used 10f8.0 or 8f10.0 for formatting. Who cared if the numbers ran in together? You could hardly read them on the top of the card anyway.

But C was not invented until much later and the johnny-come-latelies who developed it had no appreciation of (nor cared) about heritage code.

And so it is with TMW.
I believe Matlab was originally Fortran code.
Why did Moler et al not do it properly way back then?
There's no hope now.
And it's pointless fighting battles that have already been lost.
Adapt and live on..............



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.