- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dear all,
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
Diego
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
thanks. There is a smart way to overcome this?
For example, imposing a format in the reading statement?
Thanks again
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page