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

  • Context: Fortran 
  • Thread starter Thread starter Gugga
  • Start date Start date
  • Tags Tags
    Array Fortran
Click For Summary
SUMMARY

This discussion addresses the proper declaration and initialization of a 2D character array in Fortran 90 (f90). The original issue stemmed from an incorrect parameter declaration syntax that resulted in a compilation error. The correct approach involves declaring parameters separately from the array dimensions, specifically using "integer(4), parameter :: value1=4596, value2=1345" followed by "character(1), dimension(value1,value2) :: array". This solution is crucial for anyone transitioning from Fortran 77 to Fortran 90.

PREREQUISITES
  • Understanding of Fortran programming language, specifically Fortran 90 syntax
  • Familiarity with character arrays in Fortran
  • Knowledge of parameter declarations in Fortran
  • Basic experience with compiling Fortran code
NEXT STEPS
  • Study Fortran 90 array declarations and initialization techniques
  • Learn about parameter handling in Fortran, focusing on the differences between Fortran 77 and Fortran 90
  • Explore compiler-specific behaviors and error messages in Fortran
  • Review best practices for transitioning code from Fortran 77 to Fortran 90
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those transitioning from Fortran 77 to Fortran 90, as well as students working on Fortran-based projects or theses.

Gugga
Messages
2
Reaction score
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
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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
Replies
7
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 5 ·
Replies
5
Views
4K