Writing an 8 Column array into a data file [message #87560] |
Fri, 14 February 2014 20:14  |
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 #87568 is a reply to message #87566] |
Sat, 15 February 2014 07:43   |
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 #87571 is a reply to message #87568] |
Sat, 15 February 2014 09:46   |
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 #87575 is a reply to message #87571] |
Sat, 15 February 2014 09:59   |
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 #87578 is a reply to message #87577] |
Sat, 15 February 2014 10:29   |
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   |
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 #87581 is a reply to message #87578] |
Sat, 15 February 2014 10:51   |
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
|
|
|
|