Msc. Patran pcl handbook In a Nutshell 7



Download 1.08 Mb.
Page5/25
Date05.08.2017
Size1.08 Mb.
#26706
1   2   3   4   5   6   7   8   9   ...   25

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?


Exercise 3: Effective PCL


    Write an essay on how the effective use of PCL could:

  1. Help create a lasting world peace

  2. Eliminate world hunger

  3. Conquer the common cold

  4. Stop global warming

Extra credit: How could PCL be used to find Elvis?


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

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

PCL Variables and Constants


Variable Scope


  • GLOBAL Available to all functions during the MSC.Patran session

  • LOCAL Default, only visible within the defining function

  • STATIC Same as LOCAL, but retains its value between calls

  • CLASSWIDE Available to all functions in the CLASS and retains its value during the MSC.Patran session

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

  • R
    1 2 3

    4 5 6
    ow major (unlike Fortran which is column major)

    INTEGER MyArray(2, 3) = 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)


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)

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 */



PCL Variables and Constants

Virtual strings


  • Any string variable can be defined as a VIRTUAL length string instead of a fixed length string. Virtual length strings do not have storage locations assigned to them at program initialization. The string length is allocated as requested and can be reused.

  • To declare a virtual length string, use the keyword in place of the subscripts for the declaration, i.e.,

    STRING picklist[VIRTUAL]

  • The string length is allocated using the sys_allocate_string() function

    sys_allocate_string(picklist, 1000)


  • The string length may be modified using the sys_reallocate_string() function

    sys_reallocate_string(picklist, 2000)


  • The string storage may be freed using the sys_free_string() function

    sys_free_string(picklist)


  • A virtual length string can also be a virtual array, i.e.,

    STRING picklists[VIRTUAL](VIRTUAL)






Download 1.08 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   25




The database is protected by copyright ©ininet.org 2024
send message

    Main page