Re: FORMAT codes and tabs - why not use STR_SEP? [message #15346] |
Wed, 12 May 1999 00:00 |
Justin Ashmall
Messages: 15 Registered: May 1999
|
Junior Member |
|
|
> I think I've missed something. Who said IDL can't handle
> a tab-delimited file? Tabs are treated as white space
> the same as commas and spaces in reading free-format
> input.
> Cheers, David
>
OK, so I was being a bit hasty there, what I should have said is that I'm a
bit disappointed I can't get IDL to handle *my* tab-delimited file just
using a FORMAT statement rather than string slicing, etc.
Justin
|
|
|
|
Re: FORMAT codes and tabs - why not use STR_SEP? [message #15352 is a reply to message #15346] |
Tue, 11 May 1999 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Justin Ashmall (Justin_Ashmall@hotmail.com) writes:
> Thanks Robert, another good solution. I have to say, though, that I'm
> disappointed that IDL seems unable to handle something as simple as a
> tab-delimited file.
I think I've missed something. Who said IDL can't handle
a tab-delimited file? Tabs are treated as white space
the same as commas and spaces in reading free-format
input.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
Re: FORMAT codes and tabs - why not use STR_SEP? [message #15366 is a reply to message #15352] |
Mon, 10 May 1999 00:00  |
Robert King
Messages: 9 Registered: March 1999
|
Junior Member |
|
|
Justin Ashmall <ashmall@my-dejanews.com> wrote in article
<3736e5d7.252843619@news.cc.ic.ac.uk>...
>
> I'm having trouble reading in a text file with dates and times in the
form:
> 11/10/99<tab><sp>16<sp>:<sp>47
> where <tab> and <sp> represent tabs and spaces.
> Sometimes the day/months are consist of only 1 char (e.g. 3/4/99). I
> can write a separate FORMAT statement for each case but when I try to
> use I0 to deal with both cases it doesn't work and it seems to be due
> to the TAB char.
Dear Justin,
I've tried out your program and understand what you're trying to do (I
think :-). However, I think that you'd have less trouble by doing it using
strings and STR_SEP.
I've only read line2 so that you can see the workings easier, but it works
for line1 as well, in fact, it'll work no matter how many digets the
day,month or year has.
Hope this is so some help :-)
Robert
___________________
Pro test_read_too
;Create a Tab character
tab = STRING(9B)
;Create 2 lines of dummy input
line1 = '10/11/99' + tab + ' 19 : 42'
line2 = '1/3/99' + tab + ' 19 : 42'
;Read line2 as a string
textline=''
READS, line2, textline
print, 'line 2 =', textline
;Use STR_SEP to break up the line into the date elements.
date = STR_SEP( textline , '/' )
help, date
day = date(0)
month = date(1)
;The last part [date(2)] will contain the year, tab and time so break
this up
;this time looking for spaces rather than slashes.
rest = STR_SEP( date(2), ' ' )
year = rest(0)
;Print out the full date
print, day
print, month
print, year
;You could continue to get the time as well
END
|
|
|