内容案例msc.patran courses课程_第1页
内容案例msc.patran courses课程_第2页
内容案例msc.patran courses课程_第3页
内容案例msc.patran courses课程_第4页
内容案例msc.patran courses课程_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Lecture 2Virtual ArraysVirtual ArraysA Virtual Array is an array that allocates memory (heap or free space) during the program execution and then releases the memory when it is no longer needed or reuses the memory.REAL array(VIRTUAL)INTEGER array(VIRTUAL)LOGICAL array(VIRTUAL)STRING arrayVIRTUAL(VI

2、RTUAL)Virtual Arrays (cont.)sys_allocate_array (array, lb1, hb1 , lb2, hb2 , lb3, hb3 , lb4, hb4 )Function:Allocate memory for a PCL virtual array variable.Input:lb1INTEGERLower bound for first dimension.hb1INTEGERHigher bound for first dimension.lb2INTEGEROptional lower bound for a second dimension

3、.hb2INTEGEROptional upper bound for a second dimension.lb3INTEGEROptional lower bound for a third dimension.hb3INTEGEROptional upper bound for a third dimension.lb4INTEGEROptional lower bound for a fourth dimension.hb4INTEGEROptional upper bound for a fourth dimension.Output:arrayANY(VIRTUAL)Virtual

4、 array with storage allocated if available.INTEGERZero for success, else error code.sys_free_array ( array )Function:Free memory for a PCL virtual array variable.Input:arrayANY(VIRTUAL)Virtual array.Output:arrayANY(VIRTUAL)Virtual array now de-allocated.INTEGERZero for success, else error code.Virtu

5、al Arrays (cont.)Virtual Arrays (cont.)sys_reallocate_array( array, lb1, hb1 , lb2, hb2 , lb3, hb3 , lb4, hb4 )Function:Re-allocate memory for a PCL virtual array variable.Input:arrayANY(VIRTUAL)Original virtual array.lb1INTEGERLower bound for first dimension.hb1INTEGERHigher bound for first dimensi

6、on.lb2INTEGEROptional lower bound for a second dimension.hb2INTEGEROptional upper bound for a second dimension.lb3INTEGEROptional lower bound for a third dimension.lb3INTEGEROptional upper bound for a third dimension.lb4INTEGEROptional lower bound for a fourth dimension.hb4INTEGEROptional upper boun

7、d for a fourth dimension.Output:arrayANY(VIRTUAL)Virtual array with storage reallocated if available.INTEGERZero for success, else error code.Virtual Stringssys_allocate_string ( string, size )Function:Allocate memory for a PCL virtual string variable.Input:sizeINTEGERNew maximum size for the virtua

8、l string variable.Output:stringSTRINGVirtual string with storage allocated if available.INTEGERZero for success, else error code.sys_free_string ( string )Function:Free memory for a PCL virtual array variable.Input:stringSTRINGVirtual string.Output:stringSTRINGVirtual string now deallocated.INTEGERZ

9、ero for success, else error code.Virtual Strings (cont.)sys_reallocate_string ( string, size )Function:Re-allocate memory for a PCL virtual string variable.Input:stringSTRINGOriginal virtual string.sizeINTEGERNew maximum size for the virtual string variable.Output:stringSTRINGVirtual string with sto

10、rage allocated if available.INTEGERZero for success, else error code.Virtual Array ExampleFUNCTION read_text_record(filename)$ Read the numbers contained in col. 5$ (Separated by blanks)contained in filename into a virtual array STRING filename, textline80 INTEGER counter=0, numbers(VIRTUAL), increm

11、ent=3, column = 5 INTEGER total=0, lengthline, file_id$ Open external file text_open (filename, OV, 0, 0, file_id)IF (text_open () != 0) THENwrite_line(Couldnt open file, file)return -1 /*FILE OPEN FAILURE*/END IF$ Loop through each record, get the record number, until the end$ of file is readVirtua

12、l Array Example (cont.)WHILE ( text_read_string (file_id, textline, lengthline) = 0) counter += 1 IF ( counter total ) THEN total += increment sys_reallocate_array (numbers,1,total ) write (Memory increased to:, total) END IF numbers(counter)=str_to_integer(str_token(textline, ,column,TRUE)END WHILE

13、 dump numbers$ Close the text file text_close (file_id, )END FUNCTIONInitialization Files of MSC.Patranp3epilog.pcl and p3prolog.pclOptional PCL files read at session startupUseful for referring to libraries and modifying the pathDo not affect databaseLocated in the PCL directory path (., /., Patran

14、_install_dir)p3prolog.pcl is read prior to initializing interfacep3epilog.pcl is used to define new menus on the main menu (for customization), read after displaying main MSC.Patran formInit.pcl/* * Allow loading of user pre-init pcl */ !INPUT p3prolog.pcl NOERROR/* * Initialize the file search path

15、 based on P3_HOME * to achieve relocatable execution environment.The initial path * has the home directory and the P3_HOME directory. Simply add * the new ones to the end of the path. */STRING p3_home128, path_cmd1024IF( sys_get_env(P3_HOME, p3_home) != 0) THENp3_home = /patran/patran3END IFfile_add

16、_path( 999, p3_home / /helpfiles )file_add_path( 999, p3_home / /alters )file_add_path( 999, p3_home / /icons )file_add_path( 999, p3_home / /bin )Init.pcl (cont.)/* * Load the standard pcl libraries */! LIBRARY p3patran.plb! LIBRARY KEEPOPEN p3patran.plbIF( file_exists( insight.plb, PV ) ) THENsys_

17、library( add, insight.plb )ENDIF/* * Declare and initialize Global Variables */uil_init()Init.pcl (cont.)IF( !is_batch() ) THEN ui_exec_function(uil_primary,DISPLAY)ENDIF/* The following lines are not required, but MAY be included * if initial session files are desired. The boolean argument* for sf_

18、record_default & sf_play_default control record * rotations and single step respectively. See the session* file documentation for more information about these options.*sf_play_default( patran.ses.01, FALSE)*/* * Start recording the session file */Init.pcl (cont.)/* * Allow loading of additional MSC

19、released pcl */!INPUT p3patran.pcl NOERROR/* * Allow loading of user post-init pcl */!INPUT p3epilog.pcl NOERRORTo use !input must have GREEN light.Example p3 logsSample p3prolog.pclglobal real radius = 1.,width = .5, length = 5.global real thickness = .125, amplitude = 100.Sample p3epilog.pcl!libra

20、ry pat304.plbtraining.init()Note: Most of these lines of code can be placed in any of these files. What is shown here is just a suggestion. However, training.init() must be in the p3epilog.pcl file. It is mandatory that the main form be created before calling training.init() to add a menu to the mai

21、n form. The p3epilog.pcl is the only one of these that is read after the main form has been created.Loading Custom .plbsTo install your own PCL Functions system wide: Put p3prolog.pcl and p3epilog.pcl in the p3_home directory, Then inside p3epilog.pcl execute:!library your_site.plbDUMPDUMP shows typ

22、e and contents of PCL variableSTRING example70 = DUMP displays the characteristics of a variable.DUMP example$# STRING example70 = DUMP displays the characteristics of a variable.Examples of DUMP:INTEGER number = 100DUMP number$#INTEGER number = 100INTEGER series(10) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10D

23、UMP series$#INTEGER series(10) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10Str_token Example:string input_string80 = /patran/patran3/bin/exe/p3/* pick out the fourth word in the command line*/STRING desired_output32desired_output = str_token (input_string, /, 4, TRUE)DUMP desired_output$# STRING desired_output32

24、 = exeStr_token Descriptionstr_token ( string, delim, num , compress )Function:Extract a token from a string.Input:stringSTRINGSource string from which to extract tokens.delimSTRINGSingle character delimiternumINTEGERItem number where one is the first pressLOGICALOptional flag that specifies ignorin

25、g of empty tokens caused by multiple delimiters. The default value of this flag is FALSE.Output:STRINGToken extracted from string. Leading and trailing blanks are stripped if the delimiter is not a blank.Built-ins for Exercise #2text_read_string ( chan, line, lenline )Function:Read a single record i

26、nto a string from a text I/O file.Input:chanINTEGERChannel from a previous call to text_open or zero to read from standard input (xterm window).Output:lineSTRINGLine read in from the text file.lenlineINTEGERLength of the line that was read in.INTEGERZero for success, minus one for end of file, else

27、error message code.Built-Ins for Exercise #2 (cont.)str_datatype ( string )Function:Attempt to decipher the type of representation in a string.Input:stringSTRINGString to decipher.Output:STRINGString representing datatype. Either INTEGER, REAL, LOGICAL, or STRING.Built-Ins for Exercise #2 (cont.)str

28、_to_integer ( string , stat )Function:Convert a string to an integer.Input:stringSTRINGString to convert to integer value.Output:statINTEGEROptional status, zero for success, or the position within the input string which contains the first invalid character.INTEGERInteger value from conversion. Usua

29、lly zero if the conversion fails.Built-Ins for Exercise #3str_length ( string )Function:Return the current length of a PCL string.Input:stringSTRINGThe string for which to return the length.Output:INTEGERThe current length of the string. Remember that PCL strings are variable length.Examples:string

30、line40integer xline = x = str_length( line ) dump x$# integer x = 1line = line / testingx = str_length( line )dump x$# INTEGER x = 8Built-Ins for Exercise #3 (cont.)file_exists ( filespec, options )Function:Check to see if a file exists.Input:filespecSTRINGFile to look up.optionsSTRINGOption flags o

31、f P or V.Path, VersionOutput:LOGICALTRUE if file exists. FALSE if file could not be found.Built-Ins for Exercise #3 (cont.)ui_read_logical ( prompt, hotread )Function:Display a form to the user requesting a yes/no response.Input:promptSTRINGPrompt to display in the form.hotreadLOGICALOptional and ig

32、nored.Output:LOGICALTrue if YES button, False otherwise.Examples:ok = ui_read_logical( Do you want to continue? )Built-Ins for Exercise #3 (cont.)file_delete ( filespec )Function:Delete an operating system file.Input:filespecSTRINGFile to delete. The path will not be searched for the file.Output:INT

33、EGERZero for success, else error message code.Built-Ins for Exercise #3 (cont.)utl_process_spawn ( command, wait )Function:Run a subprocess command. The spawned command es a process group leader. This allows all processes created by this spawned process to be killed via the abort button or UTL_PROCE

34、SS_KILL. Redirection cannot be used in subprocess commands entered via utl_process_spawn. If redirection is required for the subprocess it is mended that a bourne shell script be created which accepts the redirected input and output files as arguments and then issues the actual command of interest,

35、including the redirection. This bourne shell script is what should be input to the utl_process_spawn function in this case.Input:commandSTRINGCommand string to execute.waitLOGICALTrue to wait for completion before continuing. False to execute command asynchronously.Output:INTEGERIf WAIT is TRUE, then a return code is returned which needs to be checked by

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论