I have some binary data (list of integer and float values) stored in a memory-mapped file. I need to read this data. I know how to do this in Delphi and C, but Fortran completely stalled me. So far I managed to open my virtual file (OpenFileMapping) and create a mapview (MapViewOfFile). I believe I have a pointer to the starting byte :) But how do I read, say, first 4 bytes and turn them into an integer value? And then next 8 bytes and turn them into double float? In Delphi, I use move procedure for this. You just give it a pointer to the source, a pointer to the destination and a number of bytes to read - works like a charm.
So, 1) how to read bytes and write them into variables? 2) how to perform pointer arithmetics in Fortran (for example, to move pointer X bytes forward in address space)?
Here is the listing of my subroutine (it's a dll, btw):
! Func returns error code, 0 for success
!DEC$ ATTRIBUTES DLLEXPORT::FSReadGridData
USE Kernel32, ONLY: OpenFileMapping, MapViewOfFile
Integer(4) :: FSReadGridData
Character(LEN=63) :: MapName
Byte, Pointer :: GM_start, GM_caret
Integer(SHANDLE) :: GeometryMH ! SHANDLE =4 for Win32
Integer(4), Dimension(1:10) :: test1 ! arrays to store test data from memory file
Real(8), Dimension(1:10) :: test2
MapName = 'PKSigma_Grid_Map'//CHAR(0) ! We need a null-terminated string
GeometryMH = OpenFileMapping(FILE_MAP_READ,.FALSE.,MapName)
if (GeometryMH.EQ.0) then
! return error code if could not open mapped file
GM_start = MapViewOfFile(GeometryMH,FILE_MAP_READ,0,0,0);
GM_caret = GM_start;
! GM_start holds pointer to starting byte, we 'll need it later to unmap view
! Using GM_caret for current location
! ......NOW I need to read 40 bytes from GM_caret and write them to test1 array, how do I do that?!
end function FSReadGridData