Re: Write a vector into a file [message #73413] |
Tue, 09 November 2010 07:41  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Nov 9, 1:36 pm, Paolo <pgri...@gmail.com> wrote:
> On the other hand, text format most likely can be read by anyone
> in any situations. 20 years down the line a binary format may be
> so obsolete that nobody can read it anymore...
On another hand, many text files cannot be read next week, by their
own author, because they are a mess. Or even if read, are causing lost
precision, or just too much work.
By the way, I was not saying text files are never good. Just that they
are not always good, as many users assume without even thinking about
it.
|
|
|
Re: Write a vector into a file [message #73414 is a reply to message #73413] |
Tue, 09 November 2010 07:36   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On Nov 9, 10:18 am, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Nov 9, 1:07 pm, David Fanning <n...@dfanning.com> wrote:
>
>> But I think it works for the wrong reasons, and
>> I think there is a danger, especially if the data
>> is not all of the same magnitude, that what ends
>> up in the file is not exactly what you *expect*
>> will end up in the file.
>
> I agree. That way is relying on IDL's guess of how to make a string
> out of the array, which is just intended to be a handy default (and
> most often used interactively for the console). But since we do not
> know what is getting written (might not even be numbers), that is a
> neat generic trick.
>
>> Much better, it seems to me, to do this correctly
>> so that the precision of the data is maintained
>> in the way you specify. Of course, we can't do
>> this "correctly" since the end user hasn't told
>> us anything about his data. It may be he is
>> content with solutions that just look like they
>> work. Many people are. :-)
>
> That is a common problem. Too many are content with always using text
> files, as if none of the binary formats existed or ever were useful.
On the other hand, text format most likely can be read by anyone
in any situations. 20 years down the line a binary format may be
so obsolete that nobody can read it anymore...
Ciao,
Paolo
|
|
|
Re: Write a vector into a file [message #73415 is a reply to message #73414] |
Tue, 09 November 2010 07:18   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Nov 9, 1:07 pm, David Fanning <n...@dfanning.com> wrote:
> But I think it works for the wrong reasons, and
> I think there is a danger, especially if the data
> is not all of the same magnitude, that what ends
> up in the file is not exactly what you *expect*
> will end up in the file.
I agree. That way is relying on IDL's guess of how to make a string
out of the array, which is just intended to be a handy default (and
most often used interactively for the console). But since we do not
know what is getting written (might not even be numbers), that is a
neat generic trick.
> Much better, it seems to me, to do this correctly
> so that the precision of the data is maintained
> in the way you specify. Of course, we can't do
> this "correctly" since the end user hasn't told
> us anything about his data. It may be he is
> content with solutions that just look like they
> work. Many people are. :-)
That is a common problem. Too many are content with always using text
files, as if none of the binary formats existed or ever were useful.
|
|
|
Re: Write a vector into a file [message #73417 is a reply to message #73415] |
Tue, 09 November 2010 07:07   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
jeanh writes:
> try the format keyword:
> printf, 1, jobs, format = '(A)'
Well, it's a neat solution, I'll give you that!
But I think it works for the wrong reasons, and
I think there is a danger, especially if the data
is not all of the same magnitude, that what ends
up in the file is not exactly what you *expect*
will end up in the file.
Much better, it seems to me, to do this correctly
so that the precision of the data is maintained
in the way you specify. Of course, we can't do
this "correctly" since the end user hasn't told
us anything about his data. It may be he is
content with solutions that just look like they
work. Many people are. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
Re: Write a vector into a file [message #73419 is a reply to message #73418] |
Tue, 09 November 2010 06:30   |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 08/11/2010 9:08 PM, Paulo Penteado wrote:
> On Nov 8, 11:56 pm, David Fanning<n...@dfanning.com> wrote:
>> jeanh writes:
>>> try the format keyword:
>>> printf, 1, jobs, format = '(A)'
>>
>> Alright, Jean, you are going to have to explain this one
>> to us. :-)
>
> At this point we do not even know the vector's type or shape. So that
> is not a bad guess, as it will try to stringify the vector's elements,
> one per output line.
Thanks Paulo,
It does work as you say for various arrays (what is a vector according
to the OP by the way??). I tried with a 4*3 float array and it does
print it 1 entry per line, as required!
Jean
|
|
|
Re: Write a vector into a file [message #73423 is a reply to message #73419] |
Mon, 08 November 2010 18:08   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Nov 8, 11:56 pm, David Fanning <n...@dfanning.com> wrote:
> jeanh writes:
>> try the format keyword:
>> printf, 1, jobs, format = '(A)'
>
> Alright, Jean, you are going to have to explain this one
> to us. :-)
At this point we do not even know the vector's type or shape. So that
is not a bad guess, as it will try to stringify the vector's elements,
one per output line.
|
|
|
|
Re: Write a vector into a file [message #73426 is a reply to message #73424] |
Mon, 08 November 2010 17:24   |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 08/11/2010 8:18 PM, sravani vaddi wrote:
> Hi,
> Can somebody let me know how to write a vector into a file, and the
> file should contain data only in one column
> When i used the following code, it prints in some 4 x 3 matrix form.
>
> openw, 1, 'jobs.csv'
> printf, 1, jobs
> close, 1
>
> Thanks,
> Sravani
Hi
try the format keyword:
printf, 1, jobs, format = '(A)'
Jean
|
|
|
Re: Write a vector into a file [message #73427 is a reply to message #73426] |
Mon, 08 November 2010 17:21   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
sravani vaddi writes:
> Can somebody let me know how to write a vector into a file, and the
> file should contain data only in one column
> When i used the following code, it prints in some 4 x 3 matrix form.
>
> openw, 1, 'jobs.csv'
> printf, 1, jobs
> close, 1
Well, if "jobs" is some 4x3 matrixy thing, I'd
say IDL was just doing its job. :-)
Cheers,
David
P.S. It *is* a 4x3 matrixy thing, isn't it?
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Write a vector into a file [message #73465 is a reply to message #73414] |
Thu, 11 November 2010 18:20  |
MC
Messages: 50 Registered: September 1996
|
Member |
|
|
On Nov 10, 4:36 am, Paolo <pgri...@gmail.com> wrote:
> On Nov 9, 10:18 am, Paulo Penteado <pp.pente...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Nov 9, 1:07 pm, David Fanning <n...@dfanning.com> wrote:
>
>>> But I think it works for the wrong reasons, and
>>> I think there is a danger, especially if the data
>>> is not all of the same magnitude, that what ends
>>> up in the file is not exactly what you *expect*
>>> will end up in the file.
>
>> I agree. That way is relying on IDL's guess of how to make a string
>> out of the array, which is just intended to be a handy default (and
>> most often used interactively for the console). But since we do not
>> know what is getting written (might not even be numbers), that is a
>> neat generic trick.
>
>>> Much better, it seems to me, to do this correctly
>>> so that the precision of the data is maintained
>>> in the way you specify. Of course, we can't do
>>> this "correctly" since the end user hasn't told
>>> us anything about his data. It may be he is
>>> content with solutions that just look like they
>>> work. Many people are. :-)
>
>> That is a common problem. Too many are content with always using text
>> files, as if none of the binary formats existed or ever were useful.
>
> On the other hand, text format most likely can be read by anyone
> in any situations. 20 years down the line a binary format may be
> so obsolete that nobody can read it anymore...
>
You don't need 20 years just look at the evolution of (say) HDF or big
endian vs little endian!
Cheers
|
|
|
Re: Write a vector into a file [message #73466 is a reply to message #73418] |
Thu, 11 November 2010 18:18  |
MC
Messages: 50 Registered: September 1996
|
Member |
|
|
On Nov 10, 3:37 am, David Fanning <n...@dfanning.com> wrote:
> jeanh writes:
>> It does work as you say for various arrays (what is a vector according
>> to the OP by the way??). I tried with a 4*3 float array and it does
>> print it 1 entry per line, as required!
>
> Yes, it is that exclamation mark at the end of your
> sentence that I am interested in. :-)
>
> Cheers,
>
> David
Note also the file extension ".csv" which I would think implies commas
between the thingy variables so you could get more than one value per
line...
Cheers
|
|
|
Re: Write a vector into a file [message #73509 is a reply to message #73413] |
Tue, 09 November 2010 09:01  |
Gray
Messages: 253 Registered: February 2010
|
Senior Member |
|
|
On Nov 9, 10:41 am, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Nov 9, 1:36 pm, Paolo <pgri...@gmail.com> wrote:
>
>> On the other hand, text format most likely can be read by anyone
>> in any situations. 20 years down the line a binary format may be
>> so obsolete that nobody can read it anymore...
>
> On another hand, many text files cannot be read next week, by their
> own author, because they are a mess. Or even if read, are causing lost
> precision, or just too much work.
>
> By the way, I was not saying text files are never good. Just that they
> are not always good, as many users assume without even thinking about
> it.
This is why I write all of my data as FITS ascii tables. For
everything. It will always work!
Just kidding.
|
|
|