FeResPost Web Site                     FeResPost Online User Manual

IX.1.1.1 Reading a Nastran model with C#

The first C# example is very simple and illustrates the use of .NET assembly with C# programming language. The example is provided in “TESTSAT/NETEX/EX01/readBdf.cs” source file. The compilation is done with script “readBdf.bat” that contains the following lines:

@SET FRP=../../../SRC/OUTPUTS/NET  
C:/Windows/Microsoft.NET/Framework/v3.5/csc.exe -platform:x86 '  
        -r:%FRP%/FeResPost.dll ..' UTIL' util.cs readBdf.cs  
readBdf.exe

(You may have to change the “%FRP%” path to FeResPost .NET assembly before compiling the example.) Note also that one uses the 3.5 version of .NET Framework. This is not strictly necessary in this example, but it might be useful for some examples in which classes are extended with extension methods. Once the compilation is done, the compiled program is run by line “readBdf.exe”.

The file “readBdf.cs” begins with several “using” directives:

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.Text;  
using System.Globalization;  
using System.Threading;  
 
using FeResPost ;  
using std ;

These directives allow to reduce the length of type names used in the program. For example, the “using FeResPost” directive allows to use “NastranDb” keyword instead of “FeResPost.NastranDb”.

The first example is very simple and contains only one static “Main” function:

namespace ConsoleApplication1 {  
 
    class readBdf {  
 
        static void Main(string[] args) {  
 
            ...  
 
        } // static void Main(string[] args)  
 
    } // class readBdf  
 
} // namespace ConsoleApplication1

Note however, that the static function is contained in a class. (C# does not allow to define a function outside of a class.) The “readBdf” class is also contained in a “ConsoleApplication1” namespace.

The other lines defining the program are very simple and considered as “classical” C# programming:

            NastranDb db = new NastranDb();  
            db.Name="tmpDB1";  
            db.readBdf("../../MODEL/MAINS/unit_xyz.bdf");  
 
            // A Second DataBase is created :  
 
            db = new NastranDb();  
            db.Name="tmpDB2";  
            db.readBdf("unit_xyz_V1.bdf","../../MODEL/MESH/","bdf",  
                    new Dictionary<string,string>(),true);

(The reader is referred to chapter III.1 for the description of “readBdf” arguments.) Note that in the second call to “readBdf”, one uses a void “Dictionary” instead of a ruby “Hash” object as parameter.

One presents in “readBdf_V2.cs” and “readBdf_V3.cs” variants on of this first example.