Shop OBEX P1 Docs P2 Docs Learn Events
Importing Data into Dat Array — Parallax Forums

Importing Data into Dat Array

Kurt FinnieKurt Finnie Posts: 21
edited 2009-04-14 12:44 in Propeller 1
I would like to create an array of words, 11 per row with 99 rows, all initially assigned a zero value, such as...
DAT
C1 word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
C2 word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
... C99

Symbolically, the C(n) stands for Competitor(n), the first array element is a unique number that identifies the competitor and the second array element identifies the XBee transceiver serial number associated with that competitor. The remaining array elements per row will be filled in with numbers representing the finish time per (up to 9) races.


I would then create an external dat file comprised of two words per row, with as many as 99 rows, such as...
1234, 5678
2345, 6789
3456, 7890
etc, these being the unique number identifying the competitor and the XBee transceiver serial number.


I then want to write the contents of the external dat file into the program so that the values in the DAT array become:
C1 1234, 5678, 0, 0, 0, 0, 0, 0, 0, 0, 0
C2 2345, 6789, 0, 0, 0, 0, 0, 0, 0, 0, 0
C3 3456, 7890, 0, 0, 0, 0, 0, 0, 0, 0, 0
etc

Subsequently, I will do a lookup on the competitor identification and the race number, and assign the finish time to the appropriate array element.


Anyone able to help me figure this out?

Kurt

Comments

  • mparkmpark Posts: 1,305
    edited 2009-04-13 22:49
    It's not clear to me if you want to copy the external data file into the DAT array at run time or at compile time. If you want to do it at run time, perhaps you can read the data off an SD card and stuff it into the DAT array. At compile time, you might be able to use the FILE directive if your data file is in the appropriate format.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-04-14 01:22
    the following 3 line awk program
    BEGIN {i = 1}
    {printf("C%d %d,%d,0, 0, 0, 0, 0, 0, 0, 0, 0\n", i, $1, $2)
    i++}

    with the following input file
    1234, 5678
    2345, 6789
    3456, 7890

    produces the following output
    C1 1234,5678,0, 0, 0, 0, 0, 0, 0, 0, 0
    C2 2345,6789,0, 0, 0, 0, 0, 0, 0, 0, 0
    C3 3456,7890,0, 0, 0, 0, 0, 0, 0, 0, 0

    It could probably also be done in Emacs or vi or other programming editors.

    John Abshier
  • Kurt FinnieKurt Finnie Posts: 21
    edited 2009-04-14 12:44
    What I envision is attaching a flash drive, pressing a menu selection and the contents of the dat file (on flash drive) populate the first two positions of the DAT data array. As each boat finishes a race, time of day is entered in the appropriate array position.
    At the end of the day, the now filled data array is then copied back to flash drive as a dat file and then downloaded to Excel for calculation of handicaps and printing out of the day's results.

    John, I don't see that printf is available.
Sign In or Register to comment.