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

Home » Public Forums » archive » Writing an 8 Column array into a data file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Writing an 8 Column array into a data file [message #87560] Fri, 14 February 2014 20:14 Go to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
I'm trying to write a large array into a data file.

The array is 8 columns with up to 6000 rows. I have tried to do this using printf mainly. Now below you will see a main problem with one of the columns, but overall the 8 columns keep stacking. I can't seem to get 8 individual columns with 6000 rows, each column having the correct set of data. Instead I get 8 columns where the data is being written horizontally instead of vertically.

An even bigger problem I am having is trying to printf an array of hexadecimal values into a data file. The values '2b40e2200ff00007' are only showing up as ' 2' in the data file. It seems that the printf function is only writing the first digit. I've been using the 'Z' format code just FYI.



PS. the 8 column array was constructed from 8 separate arrays each containing 6000 values.



Thanks in advance
Re: Writing an 8 Column array into a data file [message #87562 is a reply to message #87560] Sat, 15 February 2014 01:29 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den lördagen den 15:e februari 2014 kl. 05:14:01 UTC+1 skrev drewc...@gmail.com:
> I'm trying to write a large array into a data file.
>
> The array is 8 columns with up to 6000 rows. I have tried to do this using printf mainly. Now below you will see a main problem with one of the columns, but overall the 8 columns keep stacking. I can't seem to get 8 individual columns with 6000 rows, each column having the correct set of data. Instead I get 8 columns where the data is being written horizontally instead of vertically.

Instead of 8 columns and 6000 rows you get 8 rows and 6000 columns? Maybe you want to do printf, transpose(data) rather than printf, data.
Re: Writing an 8 Column array into a data file [message #87565 is a reply to message #87562] Sat, 15 February 2014 07:31 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
Thanks for the response, but what I'm getting is 8 columns by 6000. The problem is that the data keeps on getting layered by row instead of column. Each column needs it's own set of data, belo is what I want where one column contains 1's data, the second contains 2's...
1-2-3-4
1-2-3-4
1-2-3-4
1-2-3-4
1-2-3-4

Instead I get:
1-1-1-1
1-2-2-2
2-2-3-3
3-3-3-4
4-4-4-4

Does that make sense?
Re: Writing an 8 Column array into a data file [message #87566 is a reply to message #87565] Sat, 15 February 2014 07:33 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
Let me also point out that this 8 column array was is really 8 separate 1 column arrays, each with it's own set of data.
Re: Writing an 8 Column array into a data file [message #87567 is a reply to message #87565] Sat, 15 February 2014 07:34 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

> Thanks for the response, but what I'm getting is 8 columns by 6000. The problem is that the data keeps on getting layered by row instead of column. Each column needs it's own set of data, belo is what I want where one column contains 1's data, the second contains 2's...
> 1-2-3-4
> 1-2-3-4
> 1-2-3-4
> 1-2-3-4
> 1-2-3-4
>
> Instead I get:
> 1-1-1-1
> 1-2-2-2
> 2-2-3-3
> 3-3-3-4
> 4-4-4-4
>
> Does that make sense?

What would make sense is you showing us some code so we have some idea
what the hell it is you are talking about. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87568 is a reply to message #87566] Sat, 15 February 2014 07:43 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

>
> Let me also point out that this 8 column array was is really 8 separate 1 column arrays, each with it's own set of data.

I presume your code doesn't look like this:

FOR j=0,N_Elements(A)-1 DO BEGIN
PrintF, lun, A[j], B[j], C[j], D[j], E[j], F[j], G[j], H[j]
ENDFOR

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87570 is a reply to message #87566] Sat, 15 February 2014 09:33 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den lördagen den 15:e februari 2014 kl. 16:33:52 UTC+1 skrev drewc...@gmail.com:
> Let me also point out that this 8 column array was is really 8 separate 1 column arrays, each with it's own set of data.

Let me point out that you originally wrote that you had constructed the 8-column array. Now you are saying you are not constructing it at all?

I agree with David, show us what you are doing!
Re: Writing an 8 Column array into a data file [message #87571 is a reply to message #87568] Sat, 15 February 2014 09:46 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
Ahh stupid me, I assumed when I created my array using 'tbget' that it would put it in a 1 column array. Unfortunately it created an array with 6000 columns and 1 row haha, this is why the data is stacking. Sorry about the stupid question!

Also, maybe you guys could still help with whats going on with the hexadecimal data. That array contains string type variable, and when I write it to a file I only get the first number of each element. some sample code is below:

array1 STRING = Array[1, 5]

the array contains:
[2b40e2200ff00007, 2b40e2200ff00009, 2b40e2200ff0000c, 2b40e2200ff00011, 2b40e2200ff00019]

openw, lun, 'test.dat', /get_lun
printf, lun, array1, FORMAT='(Z16)'
close,lun

what I get is:
2
2
2
2
2

Any clue why this might be?
Re: Writing an 8 Column array into a data file [message #87572 is a reply to message #87571] Sat, 15 February 2014 09:48 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

> Ahh stupid me, I assumed when I created my array using 'tbget' that it would put it in a 1 column array. Unfortunately it created an array with 6000 columns and 1 row haha, this is why the data is stacking. Sorry about the stupid question!

This seems totally unlikely to me. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87573 is a reply to message #87571] Sat, 15 February 2014 09:48 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
Im not good at this am I haha sorry


I had 8 arrays and I used the concatenating function to combine them. The structure is now fine, my problem is the string array.

My apologies
Re: Writing an 8 Column array into a data file [message #87574 is a reply to message #87572] Sat, 15 February 2014 09:51 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
>
>> Ahh stupid me, I assumed when I created my array using 'tbget' that it would put it in a 1 column array. Unfortunately it created an array with 6000 columns and 1 row haha, this is why the data is stacking. Sorry about the stupid question!
>
>
>
> This seems totally unlikely to me. :-)
>

*One-Dimensional array rather than a two-dimensional array [1,*]
Re: Writing an 8 Column array into a data file [message #87575 is a reply to message #87571] Sat, 15 February 2014 09:59 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

> Also, maybe you guys could still help with whats going on with the hexadecimal data. That array contains string type variable, and when I write it to a file I only get the first number of each element. some sample code is below:
>
> array1 STRING = Array[1, 5]
>
> the array contains:
> [2b40e2200ff00007, 2b40e2200ff00009, 2b40e2200ff0000c, 2b40e2200ff00011, 2b40e2200ff00019]
>
> openw, lun, 'test.dat', /get_lun
> printf, lun, array1, FORMAT='(Z16)'
> close,lun
>
> what I get is:
> 2
> 2
> 2
> 2
> 2
>
> Any clue why this might be?

Confusion on your part, I'm going to guess. :-)

What exactly are you trying to do? The array does NOT look like it
contains string variables. If it *did* contain string variables, you
could just write them out as strings. If you are trying to write the
strings out as hexadecimal numbers, then IDL has to convert them to
hexadecimals to write them. A number "b" doesn't make much sense in this
conversion process, so IDL does what I would do, gives up and goes gets
a beer. What would you do?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87576 is a reply to message #87575] Sat, 15 February 2014 10:06 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
>
>
> Confusion on your part, I'm going to guess. :-)
>
>
>
> What exactly are you trying to do? The array does NOT look like it
>
> contains string variables. If it *did* contain string variables, you
>
> could just write them out as strings. If you are trying to write the
>
> strings out as hexadecimal numbers, then IDL has to convert them to
>
> hexadecimals to write them. A number "b" doesn't make much sense in this
>
> conversion process, so IDL does what I would do, gives up and goes gets
>
> a beer. What would you do?
>


I got it working. The Format Code '(Z)' was not the right choice. Instead I should've used '(A)' just to transfer character data. This now gives me the proper strings and written into a file correctly. Guess it just took a little bit of trial and error.

Thanks for the help. And David, the Coyote webpage is great, better than any language tutorial and resource location I've used. Keep it going


Thanks again
Re: Writing an 8 Column array into a data file [message #87577 is a reply to message #87576] Sat, 15 February 2014 10:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

> Thanks for the help. And David, the Coyote webpage is great, better than any language tutorial and resource location I've used. Keep it going

Well, it is in danger of disappearing unless people support it. There is
a limit to how much free information I am willing to give away and some
days frustration and cynicism pushes me closer to it. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87578 is a reply to message #87577] Sat, 15 February 2014 10:29 Go to previous messageGo to next message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
>
> Well, it is in danger of disappearing unless people support it. There is
>
> a limit to how much free information I am willing to give away and some
>
> days frustration and cynicism pushes me closer to it. ;-)
>
>

Well I do have one last question. Hopefully it is simple. Now that I have my 8 arrays each with 1 column, I'm trying to combine them using 'combine=[a1,a2,a3,a4,a5,a6,a7,a8]' but my first array is a STRING array...the rest being FLOAT or DOUBLE. After I combine the arrays my final array becomes a DOUBLE variable array and my STRING array becomes decimals. So now when I print out the final array, the first column is only numbers rather than the string variable.

Using concatenation, can I maintain the string throughout the process?

Thanks
Re: Writing an 8 Column array into a data file [message #87579 is a reply to message #87578] Sat, 15 February 2014 10:32 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
drewciampa@gmail.com writes:

> Well I do have one last question. Hopefully it is simple. Now that I have my 8 arrays each with 1 column, I'm trying to combine them using 'combine=[a1,a2,a3,a4,a5,a6,a7,a8]' but my first array is a STRING array...the rest being FLOAT or DOUBLE. After I combine the arrays my final array becomes a DOUBLE variable array and my STRING array becomes decimals. So now when I print out the final array, the first column is only numbers rather than the string variable.
>
> Using concatenation, can I maintain the string throughout the process?

No.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Writing an 8 Column array into a data file [message #87580 is a reply to message #87571] Sat, 15 February 2014 10:40 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Saturday, February 15, 2014 12:46:12 PM UTC-5, drewc...@gmail.com wrote:
> Ahh stupid me, I assumed when I created my array using 'tbget' that it would put it in a 1 column array. Unfortunately it created an array with 6000 columns and 1 row haha, this is why the data is stacking. Sorry about the stupid question!

Yes, this is a subtlety of FITS files, which start with a basic table structure of rows and columns. But each element of the table can be an array, so some users choose to store their data in a single row with each element containing a "column" of data. This is why TBGET() can return a 1 x 6000 array. --Wayne
Re: Writing an 8 Column array into a data file [message #87581 is a reply to message #87578] Sat, 15 February 2014 10:51 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Saturday, February 15, 2014 1:29:17 PM UTC-5, drewc...@gmail.com wrote:

> Well I do have one last question. Hopefully it is simple. Now that I have my 8 arrays each with 1 column, I'm trying to combine them using 'combine=[a1,a2,a3,a4,a5,a6,a7,a8]' but my first array is a STRING array...the rest being FLOAT or DOUBLE. After I combine the arrays my final array becomes a DOUBLE variable array and my STRING array becomes decimals. So now when I print out the final array, the first column is only numbers rather than the string variable.

As David said you can't do this with ordinary arrays, but this is why IDL now has lists
http://www.exelisvis.com/docs/LIST.html
Re: Writing an 8 Column array into a data file [message #87582 is a reply to message #87581] Sat, 15 February 2014 11:19 Go to previous message
drewciampa is currently offline  drewciampa
Messages: 9
Registered: February 2014
Junior Member
>
>
> As David said you can't do this with ordinary arrays, but this is why IDL now has lists
>
> http://www.exelisvis.com/docs/LIST.html

Awesome thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: MPFIT2DFUN- use for a time series of images?
Next Topic: Adding Legends to Coyote Graphics Windows

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

Current Time: Wed Oct 08 11:36:13 PDT 2025

Total time taken to generate the page: 0.00732 seconds