How to Write a 2D Array to a File in Fortran for 3D Graph Creation?

  • Thread starter Thread starter jpapa
  • Start date Start date
  • Tags Tags
    2d Array File
AI Thread Summary
The discussion centers on the challenge of writing a 2D array to a file in Fortran in a specific format that preserves its row and column structure for use in generating a 3D graph in another program. The original poster seeks to ensure that the data is saved in a way that maintains its two-dimensional layout rather than being flattened into a single column. Clarification is provided that the format of saving the data is not critical, as long as the reading program can interpret it correctly. An example is given to illustrate the desired output format, emphasizing the need for the array to be written in rows and columns rather than as a linear sequence. The conversation invites further questions for additional assistance.
jpapa
Messages
4
Reaction score
0
Hello,

i have a problem and i was wondering whether anyone in here can give me a hand. I want to write a 2D array to a file in format that can be read from another program in order to make a 3D graph. I'm using fortran. In few words i want to place the data in columns and rows in the file exactly as they are written to the array.

I appreciate any help and i thank you in advance.


John
 
Technology news on Phys.org
I'm not at all clear what you want to do here. I thought for a moment that you wanted to be able to just "print" the data file on the screen or printer, but you talk about "read from another program". HOW you save the data isn't important (they will, in any case, be saved linearly). As long as your other program reads the data back in exactly the same way the file was written you will get back exactly the same 2D array and can do whatever you want with it. That's one reason why most people today use "Object Oriented Programming": with the routines for writing to and reading from a file are part of the data definition, you are sure to do it right.
 
I'm puzzled as to where the 3D graph comes from.
 
HallsofIvy said:
I'm not at all clear what you want to do here. I thought for a moment that you wanted to be able to just "print" the data file on the screen or printer, but you talk about "read from another program". HOW you save the data isn't important (they will, in any case, be saved linearly). As long as your other program reads the data back in exactly the same way the file was written you will get back exactly the same 2D array and can do whatever you want with it. That's one reason why most people today use "Object Oriented Programming": with the routines for writing to and reading from a file are part of the data definition, you are sure to do it right.

I give an example. Let's say i have an array like this:


1 2 3 4 5
6 7 8 9 10
11 12 13 14 15


I want to be written in the file as it is and not like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


Is that possible?


John
 
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 have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
11
Views
3K
Replies
4
Views
2K
Replies
10
Views
25K
Replies
4
Views
1K
Replies
5
Views
5K
Replies
1
Views
3K
Replies
3
Views
4K
Replies
33
Views
5K
Back
Top