Help with reading file into FORTRAN

  • Context: Fortran 
  • Thread starter Thread starter DoktorD
  • Start date Start date
  • Tags Tags
    File Fortran Reading
Click For Summary
SUMMARY

The discussion centers on reading CSV files in FORTRAN for a Suggested Reorder Program. The user faces challenges using both formatted and unformatted READ commands due to item descriptions containing spaces and non-uniform field lengths. The user seeks solutions to either modify the formatted READ command to separate by commas or adjust the unformatted command to ignore spaces. Alternative suggestions include reading the entire line as a single string and parsing it manually, although this is not preferred.

PREREQUISITES
  • Understanding of FORTRAN programming language
  • Familiarity with CSV file structure and parsing
  • Knowledge of FORTRAN I/O commands, specifically READ
  • Basic string manipulation techniques in programming
NEXT STEPS
  • Research FORTRAN string manipulation functions
  • Learn about custom parsing techniques for CSV files in FORTRAN
  • Explore the use of external libraries for CSV handling in FORTRAN
  • Investigate alternative programming languages for CSV processing, such as Python or R
USEFUL FOR

This discussion is beneficial for FORTRAN developers, programmers dealing with CSV data, and anyone looking to enhance their skills in file I/O operations within 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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
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