Looking for best way to import column of values in a TXT file into Spin program
tomboardman
Posts: 68
I have a text file with one column of about 50 integer values and want to access the values in Spin. I would like to import the values into an array. I understand that the DAT file works with binary data, but not sure if it is adaptable for my needs. Any help would be appreciated!
Comments
@kuroneko, in the line, v := table[4]. HTH does v = the 4th element in the table data? What does .HTH mean? Does the table directive recognize the commas as delimiters and I can then treat the values in the order they are listed as elements of an array? I am new to Spin so please excuse my ignorance.
Exactly! FWIW, table is just a label so you can reference the DAT array from SPIN, it can be anything (except a reserved word).
stuff like:
echo "DAT" >> file.spin
echo "table" >> file.spin
awk '{print "\tlong\t",$1}' < data.table >>file.spin
That would produce a file.spin that looks like:
DAT
table
long 1244564
long 2452352
.
.
.
You beat me to it! But since I already went to the trouble, and for the benefit of others, here are the steps:
1. Copy the column of numbers from the text file and paste into column C of Excel.
2. In cell A1, type the name of the array.
3. In cell B1, type long:
4. Select cell B1, and drag the little dot down to the last row of data. This will repeat the long in every row of column B.
5. Select however many rows of columns A through C have stuff in them, and hit ctrl-C to copy it to the clipboard.
6. Go to the PropTool, place the cursor where you want the data to appear, and hit ctrl-V to paste it:
Et voila! No nerdy Unix tools required!
-Phil
Note: For those who have not spent the money on Excel, the spreadsheet app in OpenOffice should work just as well.
You can also use formulae to combinecolumns of data, strip characters, insert, etc. Excel is extremely powerful. I expect Oppen Office has the same abilities.