[Fortran] Help Reading Complex 2D data

Click For Summary
SUMMARY

The forum discussion centers on reading complex 2D data in Fortran, specifically using a local array structure within a program named "readdata". The user is attempting to read a 10x10 complex array from a text file ('datain.txt') but is encountering difficulties with the format. The provided code snippet demonstrates the use of the READ statement to extract both local array components and the complex data, but the user seeks clarification on handling the data format effectively.

PREREQUISITES
  • Understanding of Fortran programming, particularly version 90 or later.
  • Familiarity with complex data types in Fortran.
  • Knowledge of file I/O operations in Fortran.
  • Experience with array manipulation in Fortran.
NEXT STEPS
  • Research Fortran file I/O best practices for reading complex data formats.
  • Learn about the Fortran complex data type and its manipulation.
  • Explore techniques for converting data formats to simplify reading in Fortran.
  • Investigate the use of formatted versus unformatted input in Fortran.
USEFUL FOR

This discussion is beneficial for Fortran developers, data scientists working with complex datasets, and anyone involved in scientific computing requiring efficient data reading techniques.

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.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 10 ·
Replies
10
Views
26K
Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
8K
  • · Replies 11 ·
Replies
11
Views
3K