简体   繁体   English

在C#中转换Fortran头文件.INC的最佳方法是什么

[英]What is the best way to convert Fortran Header Files .INC in c#

I am currently working on a fortran to c# project & I have come across some header files with extension .INC Foll. 我目前正在将Fortran转换为C#项目,并且遇到了扩展名为.INC Foll的一些头文件。 is an example of the header file 是头文件的示例

**     MAIN.INC
   INTEGER uid
   INTEGER MathsMarks
   INTEGER AWAMarks
   INTEGER ScienceMarks
   LOGICAL isStudent
   REAL*8 percentage
   REAL avg
   CHARACTER*2 sName
   LOGICAL*1 sUpdateStat
   DOUBLE PRECISION d_var
   complex*8 c8_var

Can anyone guide me in the best strategy to be used to convert this header file (.INC) in c# 任何人都可以指导我采用最佳策略来转换C#中的此头文件(.INC)

Do you know how main.inc is used? 您知道如何使用main.inc吗? Does it appear in several files or just in one file? 它出现在几个文件中还是仅出现在一个文件中? Is there a common block associated with these variable names? 是否有与这些变量名关联的通用块?

If there are no common blocks associated with it, then it is probably a bunch of commonly used local variables that are not shared. 如果没有与之关联的公共块,则可能是一堆不共享的常用局部变量。

If there is a common block associated with it, then they are global variables. 如果存在与之关联的公共块,则它们是全局变量。 If it had been done properly, the common should also have been in the inc file. 如果操作正确,则公用文件也应该位于inc文件中。 In C# if everything is in the same class, then these will be class level declarations. 在C#中,如果所有内容都在同一类中,则这些将是类级别的声明。

Translations 翻译

  • Integer = int 整数=整数
  • logical = bool 逻辑=布尔
  • real*4 or real = float 实* 4或实=浮点数
  • real*8 = double 实数* 8 =两倍
  • parameter = const 参数=常量
  • dimension is an array declaration. 维是数组声明。 Remember arrays start at 1 by default but this can be overridden in the declaration. 请记住,默认情况下数组从1开始,但是可以在声明中覆盖它。 They can start at any number. 他们可以从任意数量开始。 eg dimension(-23:10) will start at -23. 例如,维度(-23:10)将在-23开始。
  • equivalence is a union 等价是一个联合
  • character*n is a string on n characters, space padded, not null terminated character * n是n个字符上的字符串,使用空格填充,不以null结尾

[EDITED] Initially, everything is public and static in the initial translation until you figure out what the program is doing. [编辑]最初,所有内容在初始翻译中都是公共的和静态的,直到您弄清楚程序在做什么。 Once you've done that, it can be refactored. 完成此操作后,即可对其进行重构。

If it is named common, put it in a static class of the same name as the named common. 如果将其命名为common,则将其放在与命名common相同名称的静态类中。 If it is unnamed common, then put it in the main class as a static declaration. 如果未命名为common,则将其作为静态声明放入主类。 Normally if something is in a common block, it is shared across functions so don't put it in a struct. 通常,如果某事物位于一个公共块中,则它会在函数之间共享,因此请勿将其放入结构中。

Equivalence is a nasty one: depends on how it is used. 等效是一个讨厌的东西:取决于如何使用它。

  • Sometimes it is used for passing data to routines like passing a class. 有时,它用于将数据传递给例程,例如传递类。 In that case you could just dispense with the equivalence and declare the structure as a class. 在这种情况下,您可以省去等效性并将结构声明为类。
  • Sometimes it is used as a global struct for moving values all over the place. 有时,它用作在各处移动值的全局结构。 You have to watch this one. 你必须看这个。 It is normally a huge array of double precision. 通常,它是双精度的巨大数组。 Every member is equivalenced to something completely different - some integers, some double precision, some characters. 每个成员都等效于完全不同的东西-一些整数,一些双精度,一些字符。 They always have the same index and always have the same name. 它们始终具有相同的索引,并且始终具有相同的名称。
  • Sometimes it is used for conversion 有时用于转换
  • Sometimes they are used for mapping one part of an array to another. 有时,它们用于将数组的一部分映射到另一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM