How can I read a 2D character array in Fortran using f90?

In summary, the conversation discusses how to read data stored in a 2D character array using f90. The original code is in f77 and the individual is having trouble declaring the array in f90. After some attempts and errors, they discover that the issue lies in how the parameters are declared and the correct way to declare them.
  • #1
Gugga
2
0
Hello all,

I have some data stored in character*1 array(value,value) apparently the code is in f77, i got the original reading code for the data as a text...
I am working in f90, and to the extend of my knowledge (not much in fortran) I can not declare such 2D array as character? http://www.ibiblio.org/pub/languages/fortran/ch2-13.html
How can I read this data using f90?
When I tried compiling the code, I declared it like this:

character(1) :: array(value,value)

and I get the error: "array requires initializer"

perhaps I am blind and super easy, but I am stuck and i need this to continue my thesis... thanks!
 
Technology news on Phys.org
  • #2
So I figured it out... for future reference, depending on the compiler it is possible that won't accept a parameter declaration if it is in parenthesis... so I had declared like this:

integer(4), parameter :: (value1=4596, value2=1345)
character(1), dimension(value1,value2) :: array

instead it should be

integer(4), parameter :: value1=4596, value2=1345
character(1), dimension(value1,value2) :: array

Cheers.
 

1. What is a Fortran character array?

A Fortran character array is a data structure that stores a collection of characters in a sequential manner. It is a type of array in Fortran that can hold multiple characters, such as letters, numbers, and symbols, in a single element.

2. How is a Fortran character array declared?

To declare a Fortran character array, you need to specify the name of the array, the number of elements, and the length of each element. For example, "CHARACTER(LEN=10) :: my_array(5)" declares an array named "my_array" with 5 elements, each with a length of 10 characters.

3. How can I access and manipulate elements in a Fortran character array?

You can access and manipulate elements in a Fortran character array using their index number. For example, to access the third element in the array "my_array," you would use "my_array(3)." You can also use various built-in functions and operators to manipulate the characters within an element, such as concatenation, substring, and comparison.

4. Can a Fortran character array hold non-alphabetic characters?

Yes, a Fortran character array can hold any character, including non-alphabetic characters, such as numbers, symbols, and special characters. However, the length of each element may vary depending on the character set being used.

5. Are there any limitations to the size of a Fortran character array?

Yes, there are limitations to the size of a Fortran character array. The maximum size of an array is determined by the amount of memory available on the computer system. However, you can use dynamic memory allocation to overcome this limitation and create larger character arrays at runtime.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
20
Views
2K
  • Programming and Computer Science
Replies
6
Views
966
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
4
Views
735
  • Programming and Computer Science
Replies
33
Views
4K
  • Programming and Computer Science
Replies
21
Views
2K
  • Programming and Computer Science
Replies
16
Views
2K
Back
Top