[Fortran] Help Reading Complex 2D data

In summary, the conversation discusses the difficulties in reading data in array form, with the data being 10 by 10 and depicted by a local array. The code used to try and read the data is shown, and a suggestion is made to convert the format to a space or tab delimited format for easier reading. It is also mentioned that the data is in real and imaginary format per bracket.
  • #1
komp
5
0
Dear All, Please, I am trying to read in a data shown in array form but no luck. The data is 10 by 10 with each 10 by 10 depicted by a local array, for e.g. 0 0 0 0 0 0. A sample of the code I tried using is as shown below and the data is as attached. Please, any help or suggestion will be highly appreciated.
Code:
Program readdata

real*8 r1,r2,r3,r4,r5,r6,r7,r8,r9,fill,akx,aky,akz,akx1,aky1,akz1
real*8 w(2500)
complex*16 Gsc(100,100)
integer i,j,k,l,m,i1
character*80 linemc

open(unit=40,file='datain.txt',status='unknown')

do i=1,1000
  READ(40,*) akx, aky,akz,akx1,aky1,akz1 ! local array
  READ(40,*) (Gsc(:,l),l=1,10) ! Read an array corresponding to each local component
!   do k=1,10
!  read(40,'(2f8.2)',advance='no') (Gsc(k,l),l=1,10 )
  ! read(40,*) (Gsc(k,l),l=1,10 )
READ (40,*) ((Gsc(k,l), l = 1, 10), k = 1, 10)

!enddo
   read(40,*)
enddo

end program readdata
 

Attachments

  • datain.txt
    48.3 KB · Views: 508
Last edited by a moderator:
Technology news on Phys.org
  • #2
Space or tab delimited data is much easier to read.

Have you tried converting the format, or do you really need to handle this awkward format?
 
  • #3
This is how the data is supplied. I haven't tried converting the data. As data are in real and then imaginary per bracket.

Thanks for your help.
 

1. What is Fortran?

Fortran is a programming language used primarily for scientific and numerical computing. It was developed in the 1950s and has been widely used in scientific and engineering applications.

2. How do I read complex 2D data in Fortran?

To read complex 2D data in Fortran, you can use the "read" statement along with the "complex" specifier. This will allow you to read in complex numbers in both the real and imaginary parts.

3. What is the format for complex 2D data in Fortran?

The most commonly used format for complex 2D data in Fortran is the "column-major" format, where the real and imaginary parts are stored in separate columns. However, there are other formats that can be used as well, such as the "row-major" format.

4. How can I manipulate complex 2D data in Fortran?

Fortran has a variety of functions and subroutines that can be used to manipulate complex 2D data, such as complex arithmetic operations, complex exponential and logarithmic functions, and complex trigonometric functions. You can also use array operations and loops to manipulate complex 2D data.

5. Can I visualize complex 2D data in Fortran?

Yes, there are various libraries and tools available for visualizing complex 2D data in Fortran, such as the DISLIN library and the GNU plotutils package. You can also write your own code to create plots and graphs using the data you have read in Fortran.

Similar threads

  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
10
Views
25K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
11
Views
7K
  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
2
Views
24K
Back
Top