views:

96

answers:

0

I am new to C#; I need to get my fortran dll to communicate with my C# program. I am able to pass variables from my program into C# using set (subroutines) and get (functions) (i.e.,

! fortran
function getSwitch() result(value)
   use module
   implicit none
   dll_export :: getSwitch
   logical :: value
   value = getkSwitch()
end function

module
 contains

  function getkSwitch() result(value)
     implicit none
     integer :: value
     value = Switch
  end function
end module

// C# code
public override int Switch
{
   get
   {
      return getSwitch_();
   }
}

[DllImport(@"fortran.dll")]
protected static extern int getSwitch_();

My issue is this. I need to keep the fortran memory alive during repeated calls to it from C#; I have a simulation model that runs on an annual time-step. I need to retain state variables (among other variables) from year to year, but I want to control it from C# (after a one-year run I want to pass data into C#, manage that data, and then send back data to the fortran dll at the start of a new year simulation).

I have read the posts on this site but none (in my assessment) address this directly. Any help would be appreciated. I am using MS visual C# 2005 Express Edition and the MS visual Studio (2008) interface [ver 9.0.30729.1 sp and the MS .NET Framework ver. 3.5 SP1] environment - using lahey-Fujitsu 7.2 fortran v7.2 complier.