Help with reading file into FORTRAN

In summary, the author is trying to read a CSV file that contains item descriptions that contain spaces, and is having difficulty with either the formatted or unformatted READ command. They mention that the language FORTRAN is not the best for this task, and suggest either a different method of reading the file or storing the data in a variable.
  • #1
DoktorD
6
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
  • #2
I don't see a way to do this simply in Fortran. It is not the best language for processing input or string manipulation.
 

What is FORTRAN and why is it used for reading files?

FORTRAN (short for Formula Translation) is a high-level programming language commonly used for scientific and engineering applications. It was designed specifically for numerical and scientific computations, making it well-suited for reading and manipulating data files.

How do I read a file in FORTRAN?

The most common way to read a file in FORTRAN is by using the OPEN, READ, and CLOSE statements. First, you need to open the file with the OPEN statement, specifying the file name and other necessary parameters. Then, you can use the READ statement to read data from the file into variables. Finally, use the CLOSE statement to close the file after you are done reading from it.

What is the difference between reading a text file and a binary file in FORTRAN?

A text file is a file that contains human-readable characters, while a binary file contains machine-readable data. In FORTRAN, reading a text file is usually done using formatted input, which interprets the data as characters and converts them into the appropriate data types. Reading a binary file, on the other hand, requires using unformatted input, which reads the data as they are stored in memory.

How do I handle errors when reading a file in FORTRAN?

To handle errors when reading a file in FORTRAN, you can use the IOSTAT or ERR keywords in the READ statement. These keywords will return a value indicating the success or failure of the read operation, which you can then use to take appropriate actions in your program.

Are there any built-in functions or libraries in FORTRAN for reading files?

Yes, FORTRAN has several built-in functions and libraries for reading files, such as GETARG, GETENV, and READF. Additionally, many third-party libraries also provide functions for file input/output in FORTRAN, such as the NetCDF library for reading and writing scientific data files.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
Back
Top