Discussion:
write unix textfile with windows idl
(too old to reply)
Klemens Barfus
2004-01-21 13:38:35 UTC
Permalink
Hello together,
it seems to be a quite easy problem but I would like to write unix text
files with idl operating under windows.

How can I manage these ?

Thanks for your help in advance !

Klemens
Norbert Hahn
2004-01-21 16:56:32 UTC
Permalink
Post by Klemens Barfus
Hello together,
it seems to be a quite easy problem but I would like to write unix text
files with idl operating under windows.
HM, I played a little and came up with some text the online help:

"The Windows-Only keywords BINARY and NOAUTOMODE are now obsolete. Input/Output
on Windows is now handled indentically to Unix, and does not require you to be
concerned about the difference between "text" and "binary" modes. These keywords
are still accepted for backwards compatibility, but are ignored."

Those keywords are ignored causing lines written with the printf command
are terminated by carriage return and line feed when Windows is the OS
and line feed only for Unix. Thus "handled indentically to Unix" is at
least hard to understand.
Post by Klemens Barfus
How can I manage these ?
A work-around is to use writeu in stead of printf and use the string
procedure to format the text, i.e. to write some text and a number, the
following code works

writeu, 1, String( "Hello word, the year is", 2004), 10B

but looks ugly. Any other ideas?

Norbert
Michael Wallace
2004-01-21 18:31:02 UTC
Permalink
Post by Norbert Hahn
A work-around is to use writeu in stead of printf and use the string
procedure to format the text, i.e. to write some text and a number, the
following code works
writeu, 1, String( "Hello word, the year is", 2004), 10B
but looks ugly. Any other ideas?
You can use the format keyword of the string function to add a C-style
control character to the string. For UNIX, just add \n (newline) to the
end of your string. For Windows, add \r\n (carriage return and newline).

; UNIX version
writeu, 1, string('Hello World', format = '(%"%s\n")')

; Windows version
writeu, 1, string('Hello World', format = '(%"%s\r\n")')
Klemens Barfus
2004-01-22 09:09:17 UTC
Permalink
Hi Michael,
testing your code I got:

% "(%"%s\n")"
% ^
% Unexpected text in format.

I am not familar with C-style format code, any suggestions ?

Thanks in advance !

Klemens
Post by Michael Wallace
Post by Norbert Hahn
A work-around is to use writeu in stead of printf and use the string
procedure to format the text, i.e. to write some text and a number, the
following code works
writeu, 1, String( "Hello word, the year is", 2004), 10B
but looks ugly. Any other ideas?
You can use the format keyword of the string function to add a C-style
control character to the string. For UNIX, just add \n (newline) to the
end of your string. For Windows, add \r\n (carriage return and newline).
; UNIX version
writeu, 1, string('Hello World', format = '(%"%s\n")')
; Windows version
writeu, 1, string('Hello World', format = '(%"%s\r\n")')
Pepijn Kenter
2004-01-22 09:53:46 UTC
Permalink
Post by Klemens Barfus
Hi Michael,
% "(%"%s\n")"
% ^
% Unexpected text in format.
Because you want a string with quotes in it, you must use single and
double quotes mixed:

'(%"%s\n")'

Pepijn.
Klemens Barfus
2004-01-22 10:00:59 UTC
Permalink
Thanks, but I got the answer now - I am using an old version of IDL,
which does not support c-style format :-(


Klemens
Post by Pepijn Kenter
Post by Klemens Barfus
Hi Michael,
% "(%"%s\n")"
% ^
% Unexpected text in format.
Because you want a string with quotes in it, you must use single and
'(%"%s\n")'
Pepijn.
Michael Wallace
2004-01-22 17:11:52 UTC
Permalink
Post by Klemens Barfus
% "(%"%s\n")"
% ^
% Unexpected text in format.
I am not familar with C-style format code, any suggestions ?
Here's a techtip explaining the basics of how to use C printf-style
escape sequences: http://www.rsinc.com/services/techtip.asp?ttid=3616
David Fanning
2004-01-22 18:08:13 UTC
Permalink
Post by Michael Wallace
Here's a techtip explaining the basics of how to use C printf-style
escape sequences: http://www.rsinc.com/services/techtip.asp?ttid=3616
The tip reads:

IDL> PRINT,'I','like','Interactive','Data','Language', $
FORMAT='(%"%s %s\t%1s",a1,a1)'

Which results in the following output:

I like IDL

IDL is getting like Microsoft, doing all the thinking
for you. How did it know I wanted to abbreviate "Interactive
Data Language" to IDL!? Amazing. :-)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: ***@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
David Fanning
2004-01-22 18:16:42 UTC
Permalink
Post by David Fanning
IDL is getting like Microsoft, doing all the thinking
for you. How did it know I wanted to abbreviate "Interactive
Data Language" to IDL!? Amazing. :-)
What's really amazing is how much faster my mouth works
than my brain. :-(

On re-reading the tip, I find I am really, REALLY
impressed with C style formatting. I've got to start
brushing up on that language....

Cheers,

David

P.S. Let's just say REGEX is on my list.
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: ***@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Klemens Barfus
2004-01-22 07:54:01 UTC
Permalink
OK, I will try your suggestions.
Thanks for your help !

Klemens
Loading...