Structure of a PCL Function
Simple PCL function Example
Function declaration Function arguments (null) FUNCTION a_very_simple_function() /* This is a simple function that writes: Comments (Who we “$# My favorite number is 29” kidding? We all know that everyone loathes in the MSC.Patran history window using 3 different commenting their “write” or “print” statements. code!) */ /* This is a comment. */ $ This is also a comment. Variable declaration INTEGER MyFavoriteNumber Variable initialization MyFavoriteNumber = 29 ui_writec(“My favorite number is %d \\n”, MyFavoriteNumber) ui_writef(“A21,1X,I3”, “My favorite number is”, MyFavoriteNumber) ui_write(“My favorite number is “//STR_FROM_INTEGER(MyFavoriteNumber)) END FUNCTION /* a_very_simple_function */ Statements or expressions Function terminator
MSC.Patran PCL Workshop Notes 04/13/16 31/236
Structure of a PCL Function
Sample output. The ui_write functions write text to the history window, the session file (patran.ses.##), and the journal file (model.db.jou)
Calling statement ? Another simple PCL function Function argument FUNCTION another_simple_function(MyFavoriteNumber) Note all variables must be INTEGER MyFavoriteNumber declared, including function INTEGER MyLeastFavoriteNumber arguments MyLeastFavoriteNumber = 13 ui_write(“My favorite number is “//str_from_integer(MyFavoriteNumber)) ui_write(“My least favorite number is “// @ str_from_integer(MyLeastFavoriteNumber)) END FUNCTION /* another_simple_function */
another_simple_function(29)
$#My favorite number is 29
$#My least favorite number is 13
Calling statement Sample output
MSC.Patran PCL Workshop Notes 04/13/16 32/236
Exercise 2: Hello World!
Write and execute a PCL function that accepts a single real number argument and echoes
Hello World, my favorite number is ….
to the MSC.Patran session file and history window.
Your function will use either the ui_write(…), ui_writef(…), or ui_writec(…) functions.
If you use the ui_writef(…) and ui_writec(…) functions, refer to the documentation for the correct format specifiers.
Extra credit: How would this function change if you wanted to
echo your favorite 10 numbers to the session file? Extra credit: How would this function change if you wanted to
echo your favorite color to the session file?
MSC.Patran PCL Workshop Notes 04/13/16 33/236
Exercise 3: Effective PCL
Write an essay on how the effective use of PCL could:
a) b) c) d)
Help create a lasting world peace Eliminate world hunger Conquer the common cold Stop global warming
Extra credit: How could PCL be used to find Elvis?
MSC.Patran PCL Workshop Notes 04/13/16 34/236
PCL Operators
Operators + ** * + // < || += - / - > -= ! <= = >= == != Comments Unary plus, minus, logical not Exponentiation Multiplication and division Additions and subtraction String concatenation Relational operators Logical or, logical and Increment, decrement, assignment && Examples
Dist = mth_sqrt((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2) MyString3 = MyString2//”hijk” IF (a == b) THEN c = d
IF (a == b && a == c) THEN ui_write(“Equilibrium”) x += 1 (this is equivalent to x = x + 1)
String comparisons
?
The string comparison operators are special in that they ignore trailing blanks and uppercase and lowercase. Therefore, all of the following expressions are TRUE
“ABC” == “ABC “ “ABC” == “abc”
? ?
Leading blanks are compared, i.e., “TEST” != “ TEST” To perform case sensitive comparisons use the str_equal() function, i.e.,
IF (str_equal(GroupName1, GroupName2)) THEN RETURN 0
MSC.Patran PCL Workshop Notes 04/13/16 35/236
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Patran的PCL用户手册 - 图文(7)在线全文阅读。
相关推荐: