View Full Version : .CSV files
TAB12
11-17-2003, 08:22 AM
I am relatively new to Fortran. How do you READ a comma-delimited (.CSV) data file? The file contains both character and numeric data. Char fields vary in length from null to 120+ bytes. Since I do not know field len in advance, I cannot define the format.
Any help is appreciated.
tzeis
11-17-2003, 09:17 PM
This should not be overly difficult, but it is not exactly trivial, either.
I would approach the problem by first reading one entire line of data into a character variable, and then parsing the line. You will need to make sure that the variable is large enough, make it at least 1000 character long, if you like overkill, make it 2000 characters long.
One complicating factor is that the character data might contain a comma which does not separate data. When this occurs, the character string will be enclosed in quotes. To parse a line of data, use the INDEX function to look for quotation marks, and commas. Everything in between a set of quotes is character data, and everything between commas that are outside of quotes are data of some kind. Hopefully you can take advantage of knowing the context of the file, as far as when header or titles appear, and what sort of data follows.
See if you can find a discussion group or mailing list that serves your field. It might be that someone has solved the problem already and is willing to share their code.
TAB12
11-18-2003, 09:20 PM
Thanks for the info--I'll give it a try.
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.