Shop OBEX P1 Docs P2 Docs Learn Events
Help on read external data file — Parallax Forums

Help on read external data file

El PaisaEl Paisa Posts: 375
edited 2006-07-23 15:10 in Propeller 1
I am using a tv mode, using the FILE keyword.
I need to read and display a external file which contains 10,000 pairs of x,y bytes.
I do not want to store all these data, only to read a pair of x,y bytes at the time.
I really appreciate any help on this.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-21 04:43
    You are going to store all the data anyway since the FILE keyword incorporates the file contents into the memory image loaded into RAM/EEPROM.
    Read the page in the Propellor Manual on the FILE keyword. It effectively declares a BYTE array in the DAT section of a program. You have to name
    it (as you would any DAT variable) and you can use that name as the name of a BYTE array and index it any way you like ... so:
    DAT
      stuff file "filename.dat"
    PUB example | x,y,i
      repeat i from 0 to 9999
        x := stuff[noparse][[/noparse]i*2]
        y := stuff[noparse][[/noparse]i*2+1]
    
    
  • El PaisaEl Paisa Posts: 375
    edited 2006-07-22 01:54
    Now I need more help than ever.

    I can not understand the usage of the FILE command.

    For instance, the attached file reads an a external file but the results are very weird.

    Please somebody help.
  • El PaisaEl Paisa Posts: 375
    edited 2006-07-22 01:59
    in regard to my previous post,·the first.dat was created with Edit+.
    This is the txt file version.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-22 03:06
    I think the problem is that you used "byte[noparse][[/noparse]index]" which won't work
    byte[noparse][[/noparse]@index][noparse][[/noparse]xx] is equivalent to index[noparse][[/noparse]xx] and with both you get the "xx th" byte in the file.
    
    


    Remember, the compiler has just copied your file into the EEPROM and
    given you a name to access the contents. It's just the raw byte stream.

    Post Edited (Mike Green) : 7/22/2006 3:10:43 AM GMT

  • El PaisaEl Paisa Posts: 375
    edited 2006-07-22 18:00
    This is getting very frustating.

    I hope somebody from Parallax give me a better detailed explanation of the usage of the FILE command.

    I know I am doing something wrong but I need some help.

    Why the program does not read the first character of the file?

    Why when I read a entry (data(0)) a bunch of characters shows up?

    Can I insert delimiters in the file?

    Probably the FILE command needs a better examples.

    Parallax please help.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-22 20:57
    Please, please, read the manual page for the FILE command. Characters show up because that's what you put there. You have to do the processing, either on the PC side or the Propellor side. This is not, repeat NOT, like a read command or anything similar. Your PC file contains a sequence of bytes. If you create the file with an editor, the sequence of bytes is usually a sequence of ASCII characters. You can put delimiters in the file, but they're just bytes like any other. The compiler/IDE does no, NO!, conversion and simply puts a copy of the file contents as it appears on your PC's disk into your EEPROM image where it's loaded into the Propellor RAM. Since no one has done it yet, you'll have to write your own conversion routines, either in SPIN code or you can write a program on your PC that will make a file in the format you want for the Propellor. If you declare 'index FILE "myData.dat"', the byte array 'index' will contain all the bytes of your PC file "myData.dat" without changes or interpretation.
  • El PaisaEl Paisa Posts: 375
    edited 2006-07-23 01:23
    This is part of the FILE definition,
    '
    PUB GetData | Index, Temp
    Index := 0
    repeat
    Temp := byte[noparse][[/noparse]Data][noparse][[/noparse]Index++] 'Read data into Temp 1 byte at a time
    <do something with Temp> 'Perform task with value in Temp
    while Temp > 0 'Loop until end found
    This example will read the imported data, one byte at a time, until it finds a byte equal to 0.
    '
    I assume that temp will hold ONE byte for each Index++
    This is not true.
    If· I wrote·· temp:=data[noparse][[/noparse]0] and print temp, the result is a bunch of bytes NOT ONE.


  • CJCJ Posts: 470
    edited 2006-07-23 01:40
    the graphics.text method is for displaying zero terminated strings, it expects the ADDRESS of the first byte in the string not the value

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • El PaisaEl Paisa Posts: 375
    edited 2006-07-23 02:53
    Thanks CJ,

    Where I can get more info about this?
  • CJCJ Posts: 470
    edited 2006-07-23 03:18
    I got that from the comments in the graphics.spin file, there doesn't seem to be any built in facility for single bytes, but if you have an empty variable declared immediately after your temp variable, you should be able to read the value into temp then use @temp as an argument to graphics.text to print a single byte

    hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • El PaisaEl Paisa Posts: 375
    edited 2006-07-23 15:10
    CJ,

    Thanks a lot, I got it.

    Your help really help.
Sign In or Register to comment.