View Full Version : Question about File reading
I'm trying to load a heightmap but I've run into some problems. :P
I know thinBasic has got an instruction called 'FILE_LineInput' which will read in a line but I need to read a set of values from a file one at a time.
Is there a command in thinBasic that will read from a file but stop when it encounters some Whitespace?
ErosOlmi
14-02-2008, 21:54
Matthew,
have you seen example \thinBasic\SampleScripts\Parsing\CSV_Parser.tBasic
In one line it loads all the value of a CSV file in a matrix (2 dims):
'....
PARSE(FILE_Load(FileToLoad), MyMatrix(), $crlf , ",")
'...
Have a look at it. If it doesn't do what you need, please give me more info about file structure and how you would like to load it and I will see if I can create new functions.
Ciao
Eros
ErosOlmi
14-02-2008, 22:05
To give more details:
FILE_Load (http://www.thinbasic.com/public/products/thinBasic/help/html/file_load.htm) loads a file into a string in one go. It can work on many megabytes files without any problem.
PARSE (http://www.thinbasic.com/public/products/thinBasic/help/html/parse.htm) function is very powerful because it can automatically fill an array or a matrix depending on how many separators you pass.
Together they can do a great job.
For example:
Load a file and fill an array with all tokens that are separated by a space:
PARSE(FILE_Load(FileToLoad), MyArray(), $SPC)
The biggest problem is that more spaces are considered as subsequent separators so two spaces are considered as having a field inside them, and so on. In any case there are some technique to remove double field separators.
Let me know.
Eros
Petr Schreiber
14-02-2008, 22:24
Hi Matthew,
if you want heightmap for 3D & TBGL, you could try TBGL BMP2M15 (http://community.thinbasic.com/index.php?topic=1117.msg7524#msg7524) tool. It is very basic, but can do BMP heightmap to M15 model for you.
Bye,
Petr
The tool Petr mentions is awesome. I play with it all the time.
The only thing to be aware of is it doesn't center the map to 0,0,0 but places one of the corners at 0,0,0
For now you can easily translate the m15 model or display list to adjust for it, but Petr mentioned he will add the centering feature in a future release.
Thank's for all the help. :)
I'm going to make a few changes to the data in the heightmap then I'm going to try and use the PARSE method to read the data into the array.
Petr Schreiber
15-02-2008, 11:12
The only thing to be aware of is it doesn't center the map to 0,0,0 but places one of the corners at 0,0,0
Kent, what about the checkbox "Center final mesh at...", it is already present in v1.3 ? ;)
Matthew, not sure which kind of heightmap you use, but you could consider DIM ... AT overlay construction. It can save some parsing, if data for height are fixed byte size.
Bye,
Petr
Thanks Petr for the update!!