Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing of CSV File as it relates to character data/string

Status
Not open for further replies.

alyee

Technical User
Mar 26, 2010
1
US
I am currently working with two CSV files that has columns of either numerical data or alphabetical data. I am having problems with reading in the data for one of the files. The 1st CSV file has character data in this format:

,"NO EXCEED",
For this situation I have one character variable that reads the data. When I output the character variable it looks like NO EXCEED, without quotation marks.

However for the 2nd CSV file, character data is in this format:
,NO EXCEED,
For this situation fortran does not recognize NO EXCEED as one entry. It takes two character variables to read in this data: one character variable for NO and a second character variable for EXCEED. I guess for this case fortran recognizes both the comma and the space as delimiters, however I only want the comma as the delimiter.

When I open the files in excel, the columns are all correctly separated. That is for both files the column will look like NO EXCEED, without quotation marks (which is good). Only when I open the files using WordPad can I see the quotation marks for the 1st file.

The character variables are defined like:
character*12 A

How do I work around this problem or does the CSV file have to be changed? In order for fortran to process CSV files with character data, does the character data have to be put in quotation marks? If I have to change the CSV file what is the best method to do this? The files are bigger than 1 gig.

The 2nd CSV file is exactly the same as the 1st CSV file, except the 2nd file has more data and the character data does not have quotation marks. The CSV files are sent from third/fourth party and the data is sent as a favor so if it's possible I would like to resolve this problem on my own. I am programming with fortran 77 using Microsoft Visual Studio 2008.

I hope there is enough information, if not please tell me what is missing and I will supply. Thank you for your help.
 
I don't know if this is the right way of doing it but it is how I'd do it

1) Read in the whole line as a character array
2) Scan the line and create a list of indices of where every element starts and ends. This will be the first position and after a comma as long as the comma is not within quotes.
3) Scan the elements: if they start and end with quotes or primes, move one character in on both the start and end.

You now have a list of items you can process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top