Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
5 Views

Unformatted file write and read

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
Highlighted
Valued Contributor II
5 Views

COORDS(iLoadDIR) is writing 1

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

0 Kudos
Highlighted
Beginner
5 Views

Hi Andrew,

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.

0 Kudos