Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28434 Discussions

Complex array writing into/reading from file

Jurkowski__Piotr
Beginner
517 Views

Dear users,

I'm trying to find out why my code for writing complex arrays into a file and then reading from file into a complex array gives me wrong results. My code is divided into 2 programs: first program calculates values for the array cust_no and writes them into a file.cust_no.dat, the second program reads the data from file into array and processes the data further. 

 

Piece of code for writing data into file:

    allocate(cust_no(n_ions,no))
    open(222, FILE="cust_no.dat", ACTION="WRITE", Status='unknown', FORM="FORMATTED")
    do i=1,n_ions
        do j=1,no
            write(222,*) cust_no(i,j)
        enddo
    enddo
    close(222)

Piece of code for reading data from file:

    allocate(cust_no(n_ions,no))
    open(222, FILE="cust_no.dat", ACTION="READ", Status='unknown', FORM="FORMATTED")
    do i=1,n_ions
        do j=1,no
            read(222,*) cust_no(i,j)
        enddo
    enddo
    close(222)

Surprisingly, this code works perfectly fine for small number of values in the array, however for large array cust_no values written into the file differ from the values read from the file. 

I'd be grateful for ideas on why this method of writing/reading complex arrays does not work correctly for large arrays, or how to better write/read complex data.

Best regards

0 Kudos
1 Reply
Steve_Lionel
Honored Contributor III
517 Views

Impossible to tell from these snippets. Please come up with a small (if possible) but complete test case that demonstrates the problem, and I'm sure we'll be able to help you.

0 Kudos
Reply