- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a byte array in Fortran that has been serialised in vb. I was wondering if it's possible to deserialize it in Fortran using a custom TYPE or something?
In VB the object format is:
Public Class CustomClass Property1 as Double Property2 as Double Property3 as Double End Class
and I serialize it with:
Public Shared Function ObjectToByteArray(inputObject As Object) As Byte() Dim binaryFormatter As New BinaryFormatter() ' Create new BinaryFormatter Dim memoryStream As New MemoryStream() ' Create target memory stream binaryFormatter.Serialize(memoryStream, inputObject) ' Serialize object to stream Return memoryStream.ToArray() ' Return stream as byte array End Function
I then write it to a Memory Map File and read it into Fortran:
byte, pointer, dimension(:) :: BYT ... call c_f_pointer(cdata, BYT, [4096])
Which all works fine, but now I'm stuck on how to deserialise this byte array. The Fortran structure might be something like:
TYPE CUSTOM_CLASS REAL(8) :: PROPERTY1 REAL(8) :: PROPERTY2 REAL(8) :: PROPERTY3 END TYPE CUSTOM_CLASS
But I'm passed the limit of my Fortran knowledge! Any help would be appreciated.
Thanks,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You appear to be using VB in Microsoft .NET, so have you looked into ISO_C_BINDING and BIND(C) in standard Fortran (starting with Fortran 2003) and C interoperability. This is because with .NET, the P/Invoke layer used by Microsoft .NET for marshaling between managed .NET side and unmanaged Fortran side is C-like and the companion processor that comes into play can be seen as being compatible with standard Fortran interoperation with C. So with this, a derived type such as
type, bind(c) :: CustomClass real(c_double) :: Property1 real(c_double) :: Property2 real(c_double) :: Property3 end type CustomClass
can interoperate with a struct in VB:
Public Structure CustomClass Public Property1 As Double Public Property2 As Double Public Property3 As Double End Structure
So is it possible you can directly use something along these lines instead of serializing and deserializing?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page