cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

MATHCAD User-defined functions in FORTRAN

gianfry
10-Marble

MATHCAD User-defined functions in FORTRAN

Good evening.

I am trying to use user-defined FORTRAN functions in MATHCAD PRIME 10. Unfortunately I do not have the Compaq compiler mentioned in the online help. Does anyone know if other compiler such as Intel OneAPI can be used and if the procedure is the same as described in the online help? My concern is about the libraries that MATHCAD PRIME needs that are Compaq proprietary and the compiler is no longer on the market. Thanks.

ACCEPTED SOLUTION

Accepted Solutions

Hi,

The help states:-

"Creating New Custom Functions

The process of creating user custom functions involves the following steps:
Writing the source code in C or C++ (or wrapping Fortran code in a C wrapper).
About Using Fortran in Your Custom Functions
You can wrap compiled Fortran code in C or C++, allowing PTC Mathcad to run it. In this way, legacy Fortran code can be reused as a PTC Mathcad Prime function
 
This means you can use any fortran compiler that can have its code wrapped in C or C++ will work
 
Cheers
Terry
 

View solution in original post

6 REPLIES 6

Hi,

The help states:-

"Creating New Custom Functions

The process of creating user custom functions involves the following steps:
Writing the source code in C or C++ (or wrapping Fortran code in a C wrapper).
About Using Fortran in Your Custom Functions
You can wrap compiled Fortran code in C or C++, allowing PTC Mathcad to run it. In this way, legacy Fortran code can be reused as a PTC Mathcad Prime function
 
This means you can use any fortran compiler that can have its code wrapped in C or C++ will work
 
Cheers
Terry
 

Thank you Terry for the answer.

I tried  your hint and after some tests I was able to do it.

To be honest I was stuck because of the information in the MATHCAD PRIME online help, also mentioning the FORTRAN libraries.

 

I wanted to create an exportable fortran library as DLL, but the C++ code wrapping the FORTRAN one is a better idea.

Regards,

Gianfranco

 

PR_9168273
5-Regular Member
(To:gianfry)

Hi Gianfranco, could you give an example of the implementation? Best regards, Peter

I will Peter.

I am debugging the implementation at the moment, so it can be used by my colleagues at work and I will publish here as well to help other friends.

 

Kindest regards,

Gianfranco

Good evening, Peter.

Just to start, I would recommend to follow the PRIME help online (F1) where you can find some initial information on how to compile some user-defined functions in C language. The examples are found in your PRIME installation folder under the subfolder Custom Functions.

 

The first thing I did is to try compile and use the examples provided and get familiar with the code and how it works. Compiling the given example, will tell you that your compiler is set-up correctly and that the *.DLL file is recognized and works with MATHCAD PRIME.

 

Once the above is done, then it is time to implement the FORTRAN wrapper by writing the example user-defined functions in FORTRAN, compiling them in a static library. And this is the easy part.

 

Once the static library *.lib is created, then we need again to use C language and here the MATHCAD online help becomes unclear to say least.

The C code to be modified should look like the one below:

gianfry_0-1713543643454.png

When I tried I got several errors I am fixing. Moreover the help online indicates FORTRAN runtime libraries which are valid for and old compiler. The current one from INTEL is different and when I checked for mixed-language C/FORTRAN the C codes are not comparable from the examples given in the help online.

 

Long story short...and lesson learnt...

I thought it might work straight, but I was wrong. So please be patient for the timing you will receive a fully working solution that will work probably only using the OneAPI free compilers (FORTRAN and C/C++).

 

Meantime I wish you a nice weekend...

...and. Stay tuned.

 

Regards,

Gianfranco

 

 

 

PR_9168273
5-Regular Member
(To:gianfry)

Thank you, Gianfranco! I will check the documentation. Looking forward to you post. Have a nice weekend, Peter

Announcements

Top Tags