Can Fortran read input data from Excel?

In summary, the coordinate data from Excel could not be imported into Fortran. There are some bugs in the code and it is not sensible.
  • #1
yabi
23
1
I have prepared the coordinate of a pipe layout in excel.
Now I have to input them into a FORTRAN code.
Although I know it is possible to generate these coordinates inside FORTRAN, but working with Excel is much easier for me. Making these coordinate data inside FORTRAN is a very hard work and time consuming for me.

I want to know is there a way to import or read the coordinates I have made in Excel, into Fortran?
 
Technology news on Phys.org
  • #2
Output the excel as a CSV file and then you can definitely read it into FORTRAN
 
  • #3
Thanks. I will tr it.
 
  • #4
Dear Phinds
Thanks for your reply.
I didn't have enough lock to succeed.
I want to read I,x, z from excel (file='z-dir coordinates.csv') and write them into file='Tpipe-coordinates.txt'
I use following code:

Dimension x(279),z(279)
open (21, file='z-dir coordinates.csv')
open (22, file='Tpipe-coordinates.txt')
y=0.0
DO 1 j=1,279
read (21,100) x(j),z(j)
write (22,101) j,x,y,z(j)
1 continue
100 format(f15.7)
101 format (I5,3f15.7)
close (21)
close (22)
end

But it gives error. It stops at the first read command.
What is wrong?
I don't know how to define tab or next cell in FORTRAN format command?
 
Last edited:
  • #5
yabi said:
I don't know how to define tab or next cell in FORTRAN format command?

Did you actually save the excel file as a CSV? There ARE no "tabs" or "next cell" in a CSV file, just variables separated by commas.

I don't know FORTRAN so can't help you with that, but you DO have to take the commas into account somehow.
 
  • #6
Fortran will handle the commas (and tabs) automatically if you use "list format" input like

read (21,*) x(j),z(j)

There are some more bugs in your program, because you are eading x(j) and z(j), but then writing the whole of the x array (just "x", not "x(j)"), an uninitialized variable y, and then z(j). We can't guess what you want to write to the file, but that doesn't look very sensible.
 

1. Can Fortran read data from an Excel file?

Yes, Fortran has built-in functions and libraries that allow it to read data from Excel files.

2. How do I import an Excel file into Fortran?

You can use the "READ" statement in Fortran to import data from an Excel file. This statement allows you to specify the file path and format of the data.

3. Can Fortran handle different data types from an Excel file?

Yes, Fortran can handle different data types such as integers, floating-point numbers, and characters when reading data from an Excel file.

4. Do I need to have Microsoft Excel installed to read data in Fortran?

No, Fortran has its own functions and libraries that allow it to read data from Excel files, so you do not need to have Microsoft Excel installed on your computer.

5. Can Fortran read data from multiple sheets in an Excel file?

Yes, Fortran has the capability to read data from multiple sheets in an Excel file. You can specify the sheet name or index in the "READ" statement to read data from a specific sheet.

Similar threads

  • Programming and Computer Science
Replies
2
Views
859
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
920
Back
Top