comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Writing 2 arrays of a different type into one text file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Writing 2 arrays of a different type into one text file [message #92176 is a reply to message #92175] Fri, 23 October 2015 06:57 Go to previous message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Am Freitag, 23. Oktober 2015 14:13:54 UTC+2 schrieb Helder:
> On Friday, October 23, 2015 at 1:52:59 PM UTC+2, Kai Heckel wrote:
>> Am Freitag, 23. Oktober 2015 11:25:37 UTC+2 schrieb Helder:
>>> On Friday, October 23, 2015 at 10:10:38 AM UTC+2, Kai Heckel wrote:
>>>> Hello!
>>>>
>>>> Is it possible to write 2 arrays into one text file?
>>>> What I have are 2 arrays: 1) float, 2) string.
>>>> I would like to write the string array into the 1st column and the float array into the 2nd column. Is this somehow possible?
>>>>
>>>> Thanks in advance
>>>>
>>>> Cheers,
>>>> Kai
>>>
>>> Yes.
>>> arrayFloat = randomu(s, 10)
>>> arrayStrings = strtrim(findgen(10),2)
>>> fileName = 'testFileOutput.txt'
>>> get_lun, fileUnit
>>> openw, fileUnit, fileName
>>> printf, fileUnit, transpose(arrayStrings+', '+string(arrayFloat,FORMAT='(f0.3)'))
>>> close, fileUnit
>>> free_lun, fileUnit
>>>
>>> Play a bit around with string() and the format keyword. A way or another, you will get what you want (constant width for the columns or number of decimals, separator, ...).
>>>
>>> Cheers,
>>> Helder
>>
>> Thanks Helder!
>>
>> But I'd like to have the strings in the 1st column and the according float value in the 2nd column... I looked it up under FORMAT but I couldn't find the right thing. Do you have a solution for this?
>>
>> Cheers,
>> Kai
>
> Hi Kai,
> did you try the solution I gave? It gives *exactly* what you're asking for. Of course you need to have strings in the "arrayStrings" and numbers in the "arrayFloat"...
> Then you get two columns, that in my case look like:
> 0.000000, 0.590
> 1.00000, 0.135
> 2.00000, 0.196
> 3.00000, 0.020
> 4.00000, 0.190
> 5.00000, 0.604
> 6.00000, 0.286
> 7.00000, 0.527
> 8.00000, 0.510
> 9.00000, 0.570
>
> Make sure you have two arrays with the same number of elements:
> IDL> help, arrayStrings
> ARRAYSTRINGS STRING = Array[10]
> IDL> help, arrayFloat
> ARRAYFLOAT FLOAT = Array[10]
>
> Cheers,
> Helder

I tried it but the separation didn't work. I solved the case by using 'WIDTH=2' when using the 'OPENW' command.

Thank you very much Helder and enjoy your weekend!

Cheers,
Kai
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Clip 2D Array in IDL
Next Topic: Read irregular data problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 01:50:32 PDT 2025

Total time taken to generate the page: 1.13228 seconds