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

  • Context: Fortran 
  • Thread starter Thread starter jpapa
  • Start date Start date
  • Tags Tags
    2d Array File
Click For Summary

Discussion Overview

The discussion revolves around the challenge of writing a 2D array to a file in Fortran in a specific format suitable for creating a 3D graph. Participants explore how to maintain the structure of the array in the output file, ensuring that the data is organized in rows and columns as it appears in the array.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • John expresses a need to write a 2D array to a file in a way that preserves its row and column structure for use in another program.
  • One participant questions the necessity of the 3D graph and suggests that the method of saving data is not crucial as long as the reading program can interpret it correctly.
  • Another participant reiterates the importance of how the data is saved, emphasizing that it should be saved in a linear format that allows for accurate reconstruction of the 2D array.
  • John provides an example of the desired output format, showing a preference for maintaining the visual structure of the array in the file rather than a linear list.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to achieve the desired file format, and there are differing interpretations of the requirements for the 3D graph.

Contextual Notes

There is uncertainty regarding the exact requirements for the file format and how it will be utilized by the other program. The discussion also reflects a lack of clarity on the relationship between the 2D array and the intended 3D graph.

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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 10 ·
Replies
10
Views
26K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K