Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Unformatted file write and read

Raj
Beginner
127 Views

Hi All,

I am trying to write unformatted file. However, the binary file size is always 1kb. Hence, I feel it is not writing the file correctly.

 What is the error in this piece of code ?

      inquire(file="../coords_bin", exist=exist)
        if (exist) then
 
         open(99,file="../coords_bin",status='old',
     *      action='write', form='unformatted', access='seqential'
     *     ,position='append')
        
        else
          open(99,file="../coords_bin",status='new',action='write',
     *            form='unformatted',access='seqential',position='append')
             
        end if      
       
C! EDIT2: adding  position='append' could increase the .dat file.       
        write(6,*), JLTYP,NOEL,NPT,COORDS(iLoadDIR) !ascii file
        WRITE(99) JLTYP,NOEL,NPT,COORDS(iLoadDIR)   !binary file 
        
     
        close(99) 
        
        open (unit=99,file='../coords_bin',access='stream',
     *        form="unformatted",status="OLD") 
                read(99), IJLTYP, IEID, INT_PT, Y0
         write(6,*), 'search for:', JLTYP,NOEL,NPT           ! = search for:          42       46439           1 
         write(6,*), 'read out:', IJLTYP, IEID, INT_PT,Y0   ! =  read out:          180388626452            4295014401  -4584610301207151303   4.243991582918676E-313

When I read out, I am seeing different values. Is there a bug in my code ?

Thanks !

 

 

0 Kudos
2 Replies
andrew_4619
Honored Contributor I
127 Views

COORDS(iLoadDIR) is writing 1 element of the array. COORDS(1:iLoadDIR) would write that range or COORDS would write the whole array.

Raj
Beginner
127 Views

Hi Andrew,

Sorry for not being clear. Please see the revised. Thanks ! I intended to use only coords(iLoadDir).

In my previous version, I was not using position='append' hence, it was probably additing to the file and hence always my binary file was 1kb.

Reply