Fortran [Fortran] Help Reading Complex 2D data

AI Thread Summary
The discussion revolves around a user seeking assistance with reading a 10 by 10 array of complex data from a text file using Fortran. The user provides a code snippet that attempts to read local arrays and complex data but encounters difficulties. Key points include the format of the data being space or tab delimited, which complicates the reading process. Suggestions are made regarding the potential for converting the data format to simplify the reading process, although the user indicates that conversion has not been attempted due to the specific requirements of handling real and imaginary components. The focus remains on finding effective methods to read the data as it is currently formatted.
komp
Messages
5
Reaction score
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

Last edited by a moderator:
Technology news on Phys.org
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?
 
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

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