Creating 2-d array from a text file in fortran

In summary, to read a text file of the format "x1 y1, x2 y2, ..." into an array in Fortran, you will need to declare array variables, open the file, and use a do-loop to read the values into the array using the loop variable as the index. With these instructions, feel free to write the code and experiment without fear of causing any harm.
  • #1
tcmoore3
1
0
I have a text file of the format

x1 y1
x2 y2
. .
. .
. .

I need to read this into an array. How is this done in Fortran?
 
Technology news on Phys.org
  • #2
you start by declaring a couple of array variables long enough to accommodate your values.
then, you open the file
write a do-loop
read values into array with the loop variable as the index


If I tell you more, I will be writing more than what it takes to simply write the code and give it to you.

with those hints, go ahead and take a shot at it, don't be shy, write some code and see what happens...you are not going to break anything nor set the room on fire or anything...that's what so wonderful about software!
 

Related to Creating 2-d array from a text file in fortran

What is a 2-d array in Fortran?

A 2-d array in Fortran is a data structure that stores data in a grid-like format with rows and columns. It is useful for storing and manipulating large amounts of data.

How do I create a 2-d array from a text file in Fortran?

To create a 2-d array from a text file in Fortran, you can use the READ statement to read data from the file into an array variable. You will need to specify the correct dimensions for the array and use a DO loop to read the data into the array.

What is the syntax for creating a 2-d array in Fortran?

The syntax for creating a 2-d array in Fortran is REAL, DIMENSION(rows, columns) :: array_name. This declares a 2-d array with the specified number of rows and columns and assigns it the name array_name.

Can I create a 2-d array with different data types in Fortran?

Yes, you can create a 2-d array with different data types in Fortran by using the KIND parameter when declaring the array. This allows you to specify the data type and precision for each element in the array.

What are some common errors when creating a 2-d array from a text file in Fortran?

Some common errors when creating a 2-d array from a text file in Fortran include not specifying the correct dimensions for the array, not using a DO loop to read the data into the array, and not properly formatting the data in the text file. It is also important to ensure that the data types in the text file match the data types declared for the array.

Similar threads

  • Programming and Computer Science
Replies
25
Views
918
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
33
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top