On 05/31/2011 12:54 PM, Edwin Woollett wrote:
> *Hi Paul,*
> *I am not sure of the Hex form of Windows*
> *CRLF sequence of end of line chars, since I*
> *have almost never used Hex forms.*
> **
> *Ted*
>
> ----- Original Message -----
> *From:* Paul Bowyer <mailto:pbowyer at olynet.com>
> *To:* Edwin Woollett <mailto:woollett at charter.net>
> *Sent:* Monday, May 30, 2011 1:47 PM
> *Subject:* Re: Universal read_data function
>
> On 05/30/2011 01:04 PM, Edwin Woollett wrote:
> > Attached is pb-data1.dat which is
> > your ndata1.dat supplemented with the
> > symbols CRLF everywhere I found
> > them in the file, using notepad2
> > (shift-ctrl-9).
> > a. you have incorrect CRLF between lines 6 and 7
> > b. you have incorrect CRLF between lines 7 and 8
> > c. you have an incorrect (ie gives error) CRLF
> > after the last line ending CRLF.
> >
> > In all the above case, you have back to
> > back CRLF's which will give trouble when you try to read in lines.
> >
> > ted
> >
> >
> > ----- Original Message ----- From: Paul Bowyer To: Edwin
> Woollett Cc:
> > Maxima List Sent: Monday, May 30, 2011 12:09 PM
> > Subject: Re: Universal read_data function
> >
> >
> > On 05/30/2011 09:59 AM, Edwin Woollett wrote:
> >> Hi Paul,
> >> Please send me your data files which fail with
> >> my code, as an attachement, so I get all the
> >> correct end of line chars in your files.
> >>
> >> Ted
> >>
> >> ----- Original Message ----- From: Paul Bowyer To: Edwin
> Woollett Cc:
> >> Maxima List Sent: Sunday, May 29, 2011 5:34 PM
> >> Subject: Re: Universal read_data function
> >>
> >>
> >> On 05/29/2011 12:55 PM, Edwin Woollett wrote:
> >>> I meant to include the code for
> >>> the four arg version of read_data:
> >>>
> >>> -----------------------------------------------
> >>>
> >>> read_data([%v]) :=
> >>> block ([%s,%r,%l,%filename,%dsep,%mult:true,%mix:false,
> >>> %whole:[],%ln],
> >>>
> >>> %filename : part (%v,1),
> >>>
> >>> if not stringp (%filename)
> >>> then ( disp (" file name must be a Maxima string "),
> >>> return (false)),
> >>>
> >>> if not file_search (%filename) then
> >>> (disp (" file not found "),return (false)),
> >>>
> >>> if length (%v) = 1 then %mix : true
> >>> else if length(%v) = 2 then %dsep : part (%v,2)
> >>> else if length (%v) = 3 then (%dsep : part (%v,2), %mult :
> >>> part (%v,3))
> >>> else (%dsep : part (%v,2), %mult : part (%v,3),%whole :
> >>> part(%v,4)),
> >>>
> >>>
> >>>
> >>> %s : openr (%filename),
> >>> %r : [],
> >>> %ln : 0,
> >>>
> >>> while (%l : readline(%s)) # false do
> >>> ( %ln : %ln + 1,
> >>> if not lfreeof (%whole,%ln) then
> >>> %r : cons (parse_string (%l),%r)
> >>> else if %mix then
> >>> %r : cons (map(parse_string, split(ssubst ("
> ",",",%l))),
> >>> %r)
> >>> else %r : cons (map(parse_string,
> split(%l,%dsep,%mult)), %r)),
> >>>
> >>> close (%s),
> >>> reverse (%r))$
> >>>
> >>> -----------------
> >>>
> >>> ted
> >>>
> >>>
> >>>
> >>>
> >> Hi Ted:
> >>
> >> I tried the above listed read_data function and it was still
> choking
> >> on the CRs in the data files on my Linux box.
> >> I fiddled with it slightly and this is what it looks like now:
> >>
> >> read_data([%v]) := block (
> >> [%s,%r,%l,%filename,%dsep,%mult:true,%mix:false,%whole:[],%ln ],
> >> %filename : part (%v,1),
> >> if not stringp (%filename)
> >> then ( disp (" file name must be a Maxima string "),
> >> return (false)),
> >> if not file_search (%filename) then
> >> (disp (" file not found "),return (false)),
> >> if length (%v) = 1 then %mix : true
> >> else if length(%v) = 2 then %dsep : part (%v,2)
> >> else if length(%v) = 3 then (%dsep : part (%v,2), %mult :
> part
> >> (%v,3))
> >> else (%dsep : part (%v,2), %mult : part (%v,3),%whole :
> >> part(%v,4)),
> >>
> >> %s : openr (%filename),
> >> %r : [],
> >> %ln : 0,
> >> while (%l : readline(%s)) # false do
> >> ( %ln : %ln + 1,
> >>
> >> /*Added the following two lines and the enclosing parens*/
> >> %l : strim(" ", ssubst(" ", ascii(13), %l ) ),
> >> if %l # "" then
> >> (
> >> if not lfreeof (%whole,%ln) then
> >> %r : cons (parse_string (%l),%r)
> >> else if %mix then
> >> %r : cons (map(parse_string, split(ssubst ("
> ",",",%l))), %r)
> >> else
> >> %r : cons (map(parse_string,
> split(%l,%dsep,%mult)), %r)
> >> )
> >> ),
> >> close (%s),
> >> reverse (%r));
> >>
> >> Now it works on my Linux box, but you'll need to check it on your
> >> Windows box. I tested it against all of the data files you
> listed in
> >> your message where you forgot to post the code.
> >>
> >> I started to go back and modify the ?read\-char method I submitted
> >> earlier, but I soon discovered it was more work than I wanted
> to do
> >> to get it to automatically determine the data types it was
> reading.
> >> Maybe I'll play more with that another time just for fun. I was
> >> having difficulty trying to catch errors in Maxima so I could
> >> gracefully close the file and exit, but I wasn't able to do
> that either.
> >>
> >> Paul
> >>
> > Hi Ted:
> >
> > Here are the data files I used with the read_data function. The
> names
> > might not be the same as they were in your email message. I created
> > ndata1.dat by using a hex editor (Okteta) on regular a text file
> that
> > had extra space chars that could be modified. All the others were
> > copy/pasted directly from your email message without
> modification. I
> > use Thunderbird for email.
> >
> > Paul
> Ted:
>
> I looked at pb-data1.dat in Okteta and the places you changed to 'CR'
> and 'LF' coincide with their locations in ndata1.dat. In addition,
> pb-data1.dat follows 'CR' and 'LF' with a hex 0x0A, a LF in
> hexadecimal,
> but no hexadecimal CR is present. All of the files I copy/pasted from
> your email message show a sequence of hex 0x0D 0x0A.
>
> Am I mistaken to think the normal Windows line endings for text files
> are hex 0x0D 0x0A ?
>
> The back to back CR/LF are just empty lines occuring in the data file
> which the additional lines in the read_data function took care of
> on my
> Linux box.
>
> Paul
>
Hi Ted:
For clarification, hex 0x0D = int 13 and hex 0x0A = int 10. I just put
it in hex form because that's the default in the hex editor, Okteta,
that I use.
My reason for thinking I needed to use Windows text file standards in
the data files was because I copy/pasted them from your email messages.
If I were creating them from scratch on a Linux box, I'd opt for the
default LF that is standard for Linux text files.
When I try to write utility functions, I try to make them robust so they
don't fail when things aren't absolutely perfect. It made sense to me to
handle the case where Windows text file standards were used since you
were working on a Windows machine. I wasn't trying to be a nuisance by
continually marking up your code and I hope I didn't upset you, but
please forgive me if I did.
Paul