[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: 531
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.
 

FAQ: [Fortran] Help Reading Complex 2D data

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.

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.

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.

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.

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

Replies
6
Views
2K
Replies
10
Views
25K
Replies
8
Views
4K
Replies
16
Views
2K
Replies
4
Views
8K
Replies
5
Views
2K
Replies
11
Views
7K
Replies
11
Views
2K
Back
Top