【原创-申精】Adams2013编译C语言用户子程序生成动态链接库dll

浏览:175307

1.操作系统:Windows xp 32

2.软件版本:Adams 2013 32位、Visual Studio 2010专业版 32

3.编译软件:Intel Visual Fortran 11.0

4.环境配置:

(1) 在操作系统环境变量Path中增加Adams启动文件mdi.bat的路径,如D:\MSC.Software\Adams\2013\common\mdi.bat

(2) 把Fortran安装路径,如

D:\IVF2011\Intel\ComposerXE-2011\compiler\lib\ia32

(3) 把libifcoremd.lib、libifcoremd.lib、libmmd.lib、libifportmd.lib、libirc.lib、svml_dispmd.lib这6个库文件复制到Adams安装路径下win32文件夹下

5.编写用户子程序

Adams安装程序D:\MSC.Software\Adams\2013\solver\c_usersubs文件夹下有C语言编写的常用的用户子程序,其中slv_c_utils.h文件是用户子程序的头文件。编写用户子程序时,在这些程序的基础上进行更改会有事半功倍的效果。

本文以编写VForce用户子程序为例,对其编写、编译操作过程进行说明。

复制vfosub.c和slv_c_utils.h两个文件到个人工作文件夹Adams_Matlab,本文直接使用vfosub.c的原始代码,其代码为:

#include "slv_c_utils.h"

adams_c_Vfosub Vfosub;

/*

* Note:

* Use mixed case names for the Adams subroutine names when using the C

* style interface. For the default subroutine name capitalize the first

* letter and have the remaining letters lower case; Gfosub for example.

* Doing this insures that Adams Solver correctly distinguishes a C style

* subroutine from Fortran and calls with the appropriate interface.

*

*/

void Vfosub(const struct sAdamsVforce* vfo, double time, int dflag, int iflag, double* result)

{

/* Assign readable variable names to passed parameters */

double c=vfo->PAR[0];

int ipar[3]={(int)vfo->PAR[1], (int)vfo->PAR[2],(int)vfo->PAR[1]};

/* Local variables */

double vel[3];

int nstates;

int errflg;

/* call SYSARY for translation velocities TVEL */

c_sysary("TVEL", ipar, 3, vel, &nstates, &errflg);

c_errmes(errflg, "Error calling SYSARY for TVEL", vfo->ID, "STOP");

/* --- Evaluate VFORCE components ------------------------- */

result[0] = -c * vel[0];

result[2] = -c * vel[1];

result[2] = -c * vel[2];

}

注意:因为代码中引用了slv_c_utils.h,复制时必须同时复制slv_c_utils.h文件,否则编译时会报错。

6.编译操作

(1) 在开始菜单下,启动Visual Studio 2010命令提示工具。


(2) 把工作路径设置到用户子程序文件所在路径D:\Adams_Matlab,

输入指令cd D:\Adams_Matlab并按回车。


(3) 输入指令D:\MSC.Software\Adams\2013\common\mdi.bat并按回车,

(4) 系统进入Adams环境中,


(5) 输入cr-u并按回车,


(6) 进入编译子程序,这时系统提示是否在调试状态下连接,直接输入回车。


(7) 输入C语言用户子程序的文件名vfosub.c并回车(注意:该文件必须是以.c为后缀名,不能以.cpp为后缀名,并且该文件必须在当前路径下存在)


(8) 系统提示输入下一个文件名称,这时直接点击回车;


(9) 然后输入生成的dll文件的名称,这个文件名可不与c文件同名,比如输入myvfosub.dll,


(10) 然后点击回车,系统进行编译。编译完成后,如果系统提示编译成功,会在vfosu.c所在的文件夹中生成编译成功的dll文件,至此完成用户子程序的编译。

过程见附件吧:


邀请回答 我来回答

当前暂无回答

回答可获赠 200金币

没解决?试试专家一对一服务

换一批
    App下载
    技术邻APP
    工程师必备
    • 项目客服
    • 培训客服
    • 平台客服

    TOP