Patran的PCL用户手册 - 图文(8)

2019-03-10 22:21

PCL Variables and Constants

Datatypes

?

LOGICAL Boolean value: TRUE or FALSE

LOGICAL done, created

INTEGER Value between +/- (231-1)

INTEGER i, num_nodes, node_id

REAL Single precision floating value between 1.0E-30 and 1.0E+30 (positive or negative)

REAL x, y, z, force, pressure

STRING Character string surrounded by double quotes, “Have you seen Elvis?”. Size or string length is defined with brackets, [ ]

STRING FileName[80], GroupName[32]

WIDGET Value is assigned by calls to

UI_WIDGET_NAME_CREATE(…), used to create and manipulate forms, etc.

WIDGET main_form, MyButton, group_lbox

?

?

?

?

MSC.Patran PCL Workshop Notes 04/13/16 36/236

PCL Variables and Constants

Variable Scope

?

GLOBAL LOCAL STATIC CLASSWIDE

Available to all functions during the MSC.Patran session

Default, only visible within the defining function Same as LOCAL, but retains its value between calls

Available to all functions in the CLASS and

retains its value during the MSC.Patran session

? ?

?

GLOBAL REAL a, b, c FUNCTION FindElvis() GLOBAL REAL b STATIC INTEGER c FUNCTION WheresWaldo(x) GLOBAL REAL a REAL c, d, e INTEGER x CLASS training CLASSWIDE REAL d, e FUNCTION MyFunc(q, r) INTEGER f GLOBAL REAL a, b, c REAL q, r FUNCTION init() INTEGER c, f, g Note that variables passed as arguments must be declared If you are going to change the value of a global variable within a function, you must declare the global variable within your function.

MSC.Patran PCL Workshop Notes 04/13/16 37/236

PCL Variables and Constants

Directly Allocated Arrays

?

Directly allocated arrays can have any number of subscripts (dimensions), defined within parentheses ()

Assigned upper and lower bounds, ArrayName(Lower:Upper)

INTEGER MyArray(2:10)

?

? ? ?

Default lower bound is 1 (not 0) Available for all datatypes

Row major (unlike Fortran which is column major)

INTEGER MyArray(2, 3) = 1, 2, 3, 4, 5, 6

1 2 3 4 5 6 ?

Array dimensions are inherited from the argument list, i.e., PCL passes by reference

FUNCTION MyFunc() STRING MyString[32](32) YourFunc(MyString) END FUNCTION

?

FUNCTION YourFunc(MyVal) STRING MyVal[]() END FUNCTION Declaration Examples

REAL displacements(6, 200) STRING group_names[32](20) INTEGER ids(0:2, 0:4, 0:10) LOGICAL exists(12)

MSC.Patran PCL Workshop Notes 04/13/16 38/236

PCL Variables and Constants

Virtual arrays

?

Any variable can be defined as a VIRTUAL array instead of a directly allocated array. Virtual arrays do not have storage locations assigned to them at program initialization. The size and amount of storage is allocated as requested and can be reused for other virtual arrays.

To declare a virtual array, use the keyword VIRTUAL in place of the subscripts for the declaration, i.e.,

REAL MyVals(VIRTUAL) INTEGER NodeIds(VIRTUAL)

?

?

Storage is allocated using the function, sys_allocate_array(), or

sys_allocate_array(MyVals, 1, 300)

sys_allocate_array(MyVals, 1, 300, 1, 3)

sys_allocate_array(MyVals, 1, 300, 1, 3, 0, 5) etc.

?

Storage may be reallocated using the function, sys_reallocate_array(),

sys_reallocate_array(MyVals, 1, 300, 1, 3)

?

Storage may be freed using the function, sys_free_array(),

sys_free_array(MyVals)

MSC.Patran PCL Workshop Notes 04/13/16 39/236

PCL Variables and Constants

Virtual array example

FUNCTION CompareNodes(num_nodes, node_ids) INTEGER i, j, status INTEGER num_nodes, node_ids() INTEGER num_db_nodes, db_node_ids(VIRTUAL) LOGICAL found_node $ Determine the total number of nodes in the database status = db_count_nodes(num_db_nodes) IF (status != 0) THEN RETURN status /* If no nodes in the db, then don’t compare */ IF (num_db_nodes == 0) THEN RETURN –1 $ Allocate array to hold the Ids of all nodes in the db status = sys_allocate_array(db_node_ids, 1, num_db_nodes) IF (status != 0) THEN RETURN status $ Get all of the nodes in the db status = db_get_node_ids(num_db_nodes, db_node_ids) IF (status != 0) THEN RETURN status $ Compare node_ids() to node Ids in the database, db_node_ids() $ Note: This is an inefficient way to compare nodes FOR (i = 1 to num_nodes) found_node = FALSE FOR (j = 1 to num_db_nodes) IF (node_ids(i) == db_node_ids(j)) THEN found_node = TRUE BREAK END IF END FOR IF (!found_node) THEN ui_write(“Node “//str_from_integer(node_ids(i))//” not found!”) END IF END FOR RETURN 0 END FUNCTION /* CompareNodes */

MSC.Patran PCL Workshop Notes 04/13/16 40/236


Patran的PCL用户手册 - 图文(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:12年7月劳动法串讲资料

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: