內(nèi)容案例msc.patran courses課程_第1頁
內(nèi)容案例msc.patran courses課程_第2頁
內(nèi)容案例msc.patran courses課程_第3頁
內(nèi)容案例msc.patran courses課程_第4頁
內(nèi)容案例msc.patran courses課程_第5頁
已閱讀5頁,還剩27頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論