I have the following code for writing to a binary file:
CALL system_clock(Time1, rate)
OPEN( 1, FILE='Test.bin', STATUS='UNKNOWN', ACCESS='STREAM')
DO 275 I=1,NDOF
DO 274 J=1,UBW
IF (S(I,J).NE.0) THEN
WRITE (1) I
WRITE (1) J+I-1
WRITE (1) (S(I,J))
ENDIF
274 CONTINUE
275 CONTINUE
CLOSE(1)
CALL system_clock(Time2)
print *, "elapsed time: ", real(Time2-Time1) / real(rate)
I know by using less WRITE statement I can make it faster. So inside the loop I am using the following code and it is faster:
IF (S(I,J).NE.0) THEN
WRITE (1) I, J+I-1, (S(I,J))
ENDIF
Is there any way to get rid of the loop (since it is time consuming) or make any other change to have a more efficient code?
Please note that I want to have the order of I, J+I-1 and S(I,J) (only non zero values) in my writing. Also since I am using a C++ program to read the binary file I have to use stream access.
Any suggestions are greatly appreciated.