I have the following problem. I Have to read a binary file written in single precision:
OPEN(1,file=input_rain_file,STATUS='old', form='BINARY') !TEMP A SINGLE PRECISION VARIABLE DO i=1,nmacro READ(1) TEMP(:,i) ! in [mm], single precision END DO
and then I apply
DOUBLEP = TEMP
I do not know if this is formally correct and if I can directly read the single precision file using a variable in double precision.
Thanks in advance for any help
I do not know ... if I can directly read the single precision file using a variable in double precision.
The number of bytes in the record being read is equal to the byte-size of the I/O list. If you write a number of REALS and then read them as DOUBLE, chaos will result, because record length bytes and enough bytes from the next input record will be read in order to fulfill the READ request.
You can conserve memory by reading one row at a time:
OPEN(1,file=input_rain_file,STATUS='old', form='BINARY') ! TEMP A SINGLE PRECISION VARIABLE ! REAL(4) :: TEMP(nCols) REAL(8) :: DOUBLEP(nCols,nMarco) ... DO i=1,nmacro READ(1) TEMP(:) ! one row in [mm], single precision DOUBLEP(:,i) = TEMP END DO
If memory is not an issue, you can (may be able to) read the whole array as sp in one READ, then convert as done before.