Original Delphi code:
Code: Select all
type
TGeoidGrid = Array[0..719, 0..1439] of SmallInt;
var
GeoidData: TGeoidGrid;
dH,H,H0: Double;
// Reading the WW15MGH.DAC file
Procedure LoadGeoidFile(const FileName: string);
var
fs: TFileStream;
i, j: Integer;
tmp: SmallInt;
begin
//create a stream To Read the file
fs:= TFileStream.Create('WW15MGH.DAC', fmOpenRead Or fmShareDenyWrite);
try
//go through all the rows (latitude) And columns (longitude)
For i := 0 To 719 do
For j := 0 To 1439 do
begin
//Reading 2 bytes (SmallInt) from the stream
fs.Read(tmp, SizeOf(SmallInt));
//Convert byte order (Big Endian into Little Endian)
tmp:=((tmp And $FF) shl 8) Or ((tmp And $FF00) shr 8);
//save the value into an Array
GeoidData[i,j]:=tmp;
End;
finally
//Release of the stream
fs.Free;
End;
End;Code: Select all
EnableExplicit
Define.i File, i, j, result = #False
Define *File, *Ptr.Word, *FileEnd
Define Filename$
Dim GeoidData.w(719, 1439)
;Filename$ = OpenFileRequester("Choose a file", "", "All|*.*", 0)
Filename$ = "c:\WW15MGH.DAC"
If Filename$
File = ReadFile(#PB_Any, Filename$)
If File
*File = AllocateMemory(Lof(File), #PB_Memory_NoClear)
If *File
If ReadData(File, *File, MemorySize(*File)) = MemorySize(*File)
result = #True
EndIf
EndIf
CloseFile(File)
EndIf
EndIf
If result = #True
*Ptr = *File
;Temporary limited. The file size is 2 Mb.
*FileEnd = *File + 1000 ;+ MemorySize(*File) - 1
While *Ptr <= *FileEnd
;Convert byte order (Big Endian into Little Endian)
GeoidData(i, j) = ((*Ptr\w & $FF) << 8) | ((*Ptr\w & $FF00) >> 8)
*Ptr + 2 ; SizeOf(Word) = 2 bytes
i+1 : j+1
Wend
FreeMemory(*File)
EndIfThank you.

