Fortran Help with reading file into FORTRAN

Click For Summary
The discussion revolves around challenges faced while attempting to read and manipulate .CSV files in FORTRAN for a Suggested Reorder Program. The primary issue arises from the presence of spaces within item descriptions, which disrupts the use of the unformatted READ command, as it treats spaces as delimiters. The formatted READ command is also problematic due to non-uniform field lengths, making it difficult to set fixed column widths for data separation. Suggestions sought include methods to either configure the formatted READ command to recognize commas as separators or to modify the unformatted command to ignore spaces. An alternative approach considered is reading the entire line as a single string and parsing it character by character, although this is seen as a less desirable solution due to the complexity of string manipulation in FORTRAN.
DoktorD
Messages
6
Reaction score
0
Hey all,

I'm in the process of writing a Suggested Reorder Program for my father's small business..

His current computer program exports its item data in the form of .CSV files. I'm trying to read the file into FORTRAN to manipulate. However, I run into the following problem:

Even though the file is Comma Separated, I can't use the unformatted READ command because the file also contains the item descriptions which contain spaces... If I try to use the unformatted READ command, ever line is broken down differently after getting to the item description because it uses the spaces as breaks just like the commas..

To further complicate things, I can't use (to my knowledge) a formatted READ command because some fields (such as the item number) are not of uniform length.. This makes it so I can't set column widths to separate the data.. It seems as though no matter if I use the formatted or unformatted READ command, some of the data ends up getting split into two columns..

Is there any suggestions on how I could either tell the formatted READ command to separate by commas or tell the unformatted command to ignore spaces?

Or ANY other ideas? I know my knowledge of FORTRAN command options/formatting isn't the best.. I basically know the commands and only the most common of their options/formatting.

Heres an example of the data I need to read:

0560380,560380,HWH DRILL SCREW 1/4*14X1-1/2,008236127317, 1, 1,N,H,2, $22.99,EA, 1, 1,099,010,00/00/00,00/00/00, $0.00, 1,560380, $20.69, $19.54, $18.39, $17.24,00003,02/13/09

If all else fails, I guess I could read it as a single STRING and check that character by character for the appropriate number of commas for the column desired then assign them to a variable to store.. But I'd REALLY rather avoid that.
 
Technology news on Phys.org
I don't see a way to do this simply in Fortran. It is not the best language for processing input or string manipulation.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K