从FORTRAN到c#的类型转换

本文关键字:类型转换 FORTRAN | 更新日期: 2023-09-27 18:15:07

我在F2008

module mod_Blood
use mod_liquid
implicit none
type, public :: typ_BloodComponents
    character(len=5) :: name
    real(DP):: salt
    real(DP):: RBC
end type typ_BloodComponents
type, public :: typ_BloodWork
    real(DP) :: DrugConc
    real(DP) :: Dilution
    real(DP) :: volume  
    type(typ_BloodComponents) :: vein, artery
    contains
          procedure :: SetParameters => blood_SetParameters
          procedure :: BloodProteinParams  => blood_BloodProteinParams   
end type typ_BloodWork
end mod_Blood

我知道静脉和动脉都有变量静脉%name,静脉%salt,静脉%RBC和动脉%name,动脉%salt和动脉%RBC。

我如何将其转移到c# ?模块是一个命名空间吗?FORTRAN"类型"是c#中的类吗?

如果我这样做会有意义吗:

class BloodComponents
{
string name;
double salt;
double RBC;
}
class BloodWork
{
    double drugConc
    double dil
    double volume
    class Vein : BloodComponents
    {}
    class Artery : BloodComponents
    {}
    void SetParameters()
    {...}
    void BloodComponentParameter()
    {...}
}

或者我解释错了FORTRAN ?

从FORTRAN到c#的类型转换

我想这就是你想要的:

namespace Blood
{
    public struct BloodComponents
    {
        public string name;
        public double salt, RBC;
    }
    public struct BloodWork
    {
        public double drugConc, dilution, volume;
        public BloodComponents vein, artery;
        public void SetParameters()
        {
        }
        public void BloodProteintParams()
        {
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var work=new BloodWork()
            {
                drugConc=0.1,
                dilution=0.2,
                volume=0.3,
                vein=new BloodComponents() { name="A", RBC=0.2, salt=0.6 },
                artery=new BloodComponents() { name="B", RBC=0.5, salt=0.9 }
            };
        }
    }
}

所有内容都是struct,因此仅复制值。例如,如果您想在多个地方引用BloodWork的同一瞬间,则需要将类型更改为class