Fortran Can Fortran read input data from Excel?

AI Thread Summary
The discussion centers on importing coordinate data from an Excel file into a FORTRAN program. The user has prepared a pipe layout in Excel and seeks an efficient way to transfer this data without manually recreating it in FORTRAN. The suggestion to save the Excel file as a CSV is acknowledged, as CSV files can be easily read by FORTRAN. The user attempts to read coordinates from the CSV file using a specific FORTRAN code but encounters an error at the first read command. The issue is identified as a misunderstanding of how to handle CSV formatting, specifically the need to account for commas rather than tabs or cell separations. Recommendations are made to use list format input in the read command, which simplifies the process by allowing FORTRAN to handle the delimiters automatically. Additionally, there are noted errors in the user's code, including writing uninitialized variables and incorrect indexing, which need to be addressed for successful execution.
yabi
Messages
23
Reaction score
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
Output the excel as a CSV file and then you can definitely read it into FORTRAN
 
Thanks. I will tr it.
 
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:
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.
 
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
2
Views
1K
Replies
12
Views
3K
Replies
5
Views
5K
Replies
2
Views
2K
Replies
59
Views
11K
Replies
3
Views
2K
Replies
6
Views
2K
Back
Top