* {********************************************************************* File: intfc/general/elfres.cm This is an example of extracting data from a large result file (over three megabytes) using the general file interface of the shell. A result file of a general purpuse finite element simulation programme Elfen is used for the demonstration. The same data is extracted as in the example "../elfen/res.cm". So it is possible to compare the general file interface with the built-in interface for reading data from Elfen's rsult files. On some computers the example using the general file interface runs even a bit faster than the example using the specialized interface for Elfen's result files. This is because when we use the general interface we can teke into account some facts about the specific result file which can not used in the built-in interface because this would spoil for the generality of the interface (e.g. the interface would be useful for mechanical analyses but not for thermal). This example can give a feeling how time consuming exchanging data through files can be if the user can not influence which data is written to the files, so that the data is not written selectively and therefore the interfacing files are very large. If there is a possibility to select which data is output by a simulation programme it should defenitely be used. However, in some cases it is not so bad even if we can not select the data which is output to files because the analysis still takes much longer time as exchanging data through these large files. If this is not the case, a possibility of selected data output should be added, or, which is even better if it is possible, a direct exchange of data between the shell and the simulation programme should be provided. If none of these possibilities are yet available, the general file interface operating on non-selectively written files is still appliable to at least estimate the applicability of the shell in a combination with a given simulation programme. Author: Igor Gresovnik, July 1998 ************************************************************************} setfile{outfile elfres.ct} setfile{infile ../elfen/prestr.res} setvector{incpos 10} *{Vector of increment data positions} setvectorcomponents{incpos 0} *{First we find the positions of increments:} ={numincs:0} while{(![fileoperror[0]]) [ fskipstring{"INCREMENT NUMBER"} if {(![fileoperror[0]]) [ ={numincs:numincs+1} freadnumber{incnum} fnextline{} setvector{ incpos {$incnum : ${getfpos[]} } } write{"Position of "$incnum ". increment: " ${getfpos[]} ".\n"} fwrite{"Position of "$incnum ". increment: " ${getfpos[]} ".\n"} if {(incnum!=numincs) [ write{"\n\nWarning: the "$numincs ". increment has serial number "$incnum".\n\n"} fwrite{"\n\nWarning: the "$numincs ". increment has serial number "$incnum".\n\n"} ]} ]} ]} ={numincs:incnum} *{The last component of the vector incpos will be the file length:} setvector{incpos {${numincs+1}:${getflength[]}} } write{"\nFile length: "${getvector["incpos",incnum+1]}" bytes."\n\n\n} fwrite{"\nFile length: "${getvector["incpos",incnum+1]}" bytes."\n\n\n} *{ ************************ NODAL DISPLACEMENTS: ****************************** } fsetpos{${getvector["incpos",3]}} *{From the beginning of data for increment 3, we search for the displacement field:} fskipstring{"NODAL DISPLACEMENTS FOR INCREMENT"} freadnumber{incnum} if {(incnum!=3) [ write{"\n\nError: Nodal displacements field does not exist for increment 3.\n\n"} fwrite{"\n\nError: Nodal displacements field does not exist for increment 3.\n\n"} ] else [ *{We have found the sttring which indicates the nodal displacements field, now we want to determine the actual beginning of the field:} fnextline{} fnextline{} fskipblanks{} fnextline{} fnextline{} fmarkpos{beginfield} *{Now we also determine the length of data for one node. Since the data for nodes is sorted by node numbers and the data is formatted so that every record for individual node has the same length, we can use this information for calculating where a specific record is positioned:} fnextline{secondline} ={recordlength:1+secondline-beginfield} write{"Nodal displacement; increment 3, node 38, component y: " } fwrite{"Nodal displacement; increment 3, node 38, component y: " } *{We go to the beginning of line which belong to the appropriate node; we calculate this position from the position of the beginning of the field of nodal displacements and the record length: } fsetpos{ ${beginfield+(38-1)*recordlength} } *{We skip node number and x coordinate:} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} *{We extract other nodal displacements the same way:} write{"Nodal displacement; increment 3, node 1, component x: " } fwrite{"Nodal displacement; increment 3, node 1, component x: " } fsetpos{ ${beginfield+(1-1)*recordlength} } *{Here we only skip the coordinate number:} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal displacement; increment 3, node 915, component y: " } fwrite{"Nodal displacement; increment 3, node 915, component y: " } fsetpos{ ${beginfield+(915-1)*recordlength} } fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} ]} *{ ************************ NODAL REACTIONS: ****************************** } fsetpos{${getvector["incpos",4]}} *{From the beginning of data for increment 4, we search for the reactions field:} fskipstring{"NODAL REACTIONS FOR INCREMENT"} freadnumber{incnum} if {(incnum!=4) [ write{"\n\nError: Nodal reactions field does not exist for increment 4.\n\n"} fwrite{"\n\nError: Nodal reactions field does not exist for increment 4.\n\n"} ] else [ *{Now we want to determine the actual beginning of the field:} fnextline{} fnextline{} fskipblanks{} fnextline{} fnextline{} fmarkpos{beginfield} *{Since we don't have this type of data for all nodes, we can not simply calculate the record positions. We must search for node numbers instead:} write{\n} fwrite{\n} write{"Nodal reaction; increment 4, node 32, component y: " } fwrite{"Nodal reaction; increment 4, node 32, component y: " } *{We search for node number:} fsetpos{$beginfield} fskipstring{" 23 "} fskipnumber{} *{We skip the x component} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal reaction; increment 4, node 23, component y: " } fwrite{"Nodal reaction; increment 4, node 23, component y: " } fsetpos{$beginfield} fskipstring{" 32 "} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} ]} *{ ************************ CONTACT NODAL FORCES: ****************************** } fsetpos{${getvector["incpos",4]}} *{From the beginning of data for increment 4, we search for the contact nodal forces field:} fskipstring{"CONTACT NODAL FORCES (GLOBLE) FOR INCREMENT"} freadnumber{incnum} if {(incnum!=4) [ write{"\n\nError: Contact nodal forces field does not exist for increment 4.\n\n"} fwrite{"\n\nError: Contact nodal forces field does not exist for increment 4.\n\n"} ] else [ *{Now we must find the right slideline surface:} ={end:0} clearfileoperrors{} while{(![end]) [ fskipstring{"SLIDELINE SURFACE NUMBER ="} freadnumber{num} if {(num==3 || fileoperror[0]) [ ={end:1} ]} ]} if {(fileoperror[0]) [ write{"\n\nError: Data for nodal forces on slideline 3 don't exist for increment 4.\n\n"} fwrite{"\n\nError: Data for nodal forces on slideline 3 don't exist for increment 4.\n\n"} ] else [ *{We found the data for increment 4, slideline 3, now we determine the actual beginning of the field and extract the information we need: } fnextline{} fnextline{} fskipblanks{} fnextline{} fnextline{} fmarkpos{beginfield} write{\n} fwrite{\n} *{Since we don't have this type of data for all nodes, we can not simply calculate the record positions. We must search for node numbers instead:} write{"Nodal contact force; increment 4, slideline 3, node 23, component y: " } fwrite{"Nodal contact force; increment 4, slideline 3, node 23, component y: " } fsetpos{$beginfield} fskipstring{" 23 "} *{We skip the flag and the x component:} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal contact force; increment 4, slideline 3, node 210, component y: " } fwrite{"Nodal contact force; increment 4, slideline 3, node 210, component y: " } fsetpos{$beginfield} fskipstring{" 210 "} *{We skip the flag and the x component:} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal contact force; increment 4, slideline 3, node 211, component y: " } fwrite{"Nodal contact force; increment 4, slideline 3, node 211, component y: " } fsetpos{$beginfield} fskipstring{" 211 "} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal contact force; increment 4, slideline 3, node 212, component y: " } fwrite{"Nodal contact force; increment 4, slideline 3, node 212, component y: " } fsetpos{$beginfield} fskipstring{" 212 "} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} write{"Nodal contact force; increment 4, slideline 3, node 213, component y: " } fwrite{"Nodal contact force; increment 4, slideline 3, node 213, component y: " } fsetpos{$beginfield} fskipstring{" 213 "} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} ]} ]} *{ ************************ NODAL STRESSES: ****************************** } fsetpos{${getvector["incpos",4]}} *{From the beginning of data for increment 4, we search for the element nodal stresses field:} fskipstring{"ELEMENT NODAL STRESSES FOR INCREMENT"} freadnumber{incnum} if {(incnum!=4) [ write{"\n\nError: Nodal stress field does not exist for increment 4.\n\n"} fwrite{"\n\nError: Nodal stress field does not exist for increment 4.\n\n"} ] else [ *{Now we determine the actual beginning of the field and extract the information we need: } fnextline{} fnextline{} fskipblanks{} fmarkpos{beginfield} write{\n} fwrite{\n} *{In order to extract nodal stresses, we must find all element stresses for a specific node:} clearfileoperrors{} ={stress:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element stresses of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 1" "ELFEN SUCCESSFULLY COMPLETED"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRS-YY ="} freadnumber{x} ={stress:stress+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element stresses:} ={stress:stress/num} write{\n} fwrite{\n} write{"Nodal stress; increment 4, node 1, component yy: " } fwrite{"Nodal stress; increment 4, node 1, component yy: " } write{$ stress "."\n} fwrite{$ stress "."\n} ]} *{We will now read stresses for another increment, so we repeat similar procedure as above:} fsetpos{${getvector["incpos",3]}} *{From the beginning of data for increment 3, we search for the element nodal stresses field:} fskipstring{"ELEMENT NODAL STRESSES FOR INCREMENT"} freadnumber{incnum} if {(incnum!=3) [ write{"\n\nError: Nodal stress field does not exist for increment 3.\n\n"} fwrite{"\n\nError: Nodal stress field does not exist for increment 3.\n\n"} ] else [ *{Now we determine the actual beginning of the field and extract the information we need: } fnextline{} fnextline{} fskipblanks{} fmarkpos{beginfield} write{\n} fwrite{\n} *{In order to extract nodal stresses, we must find all element stresses for a specific node:} clearfileoperrors{} ={stress:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element stresses of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 142" "SLIDELINE ASSIGNMENTS DATA"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRS-XY ="} freadnumber{x} ={stress:stress+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element stresses:} ={stress:stress/num} write{\n} fwrite{\n} write{"Nodal stress; increment 3, node 142, component xy: " } fwrite{"Nodal stress; increment 3, node 142, component xy: " } write{$ stress "."\n} fwrite{$ stress "."\n} *{We extract stress for another node:} clearfileoperrors{} ={stress:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element stresses of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 143" "SLIDELINE ASSIGNMENTS DATA"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRS-XX ="} freadnumber{x} ={stress:stress+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element stresses:} ={stress:stress/num} write{\n} fwrite{\n} write{"Nodal stress; increment 3, node 143, component xx: " } fwrite{"Nodal stress; increment 3, node 143, component xx: " } write{$ stress "."\n} fwrite{$ stress "."\n} *{We extract stress for another node:} clearfileoperrors{} ={stress:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element stresses of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 144" "SLIDELINE ASSIGNMENTS DATA"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRS-XY ="} freadnumber{x} ={stress:stress+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element stresses:} ={stress:stress/num} write{\n} fwrite{\n} write{"Nodal stress; increment 3, node 144, component xy: " } fwrite{"Nodal stress; increment 3, node 144, component xy: " } write{$ stress "."\n} fwrite{$ stress "."\n} ]} *{ ************************ NODAL STRAINS: ****************************** } fsetpos{${getvector["incpos",4]}} *{From the beginning of data for increment 3, we search for the element nodal strain field:} fskipstring{"ELEMENT NODAL STRAINS FOR INCREMENT"} freadnumber{incnum} if {(incnum!=4) [ write{"\n\nError: Nodal strain field does not exist for increment 4.\n\n"} fwrite{"\n\nError: Nodal strain field does not exist for increment 4.\n\n"} ] else [ *{Now we determine the actual beginning of the field and extract the information we need: } fnextline{} fnextline{} fskipblanks{} fmarkpos{beginfield} write{\n} fwrite{\n} *{In order to extract nodal strains, we must find all element strains for a specific node:} clearfileoperrors{} ={strain:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element strains of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 1" "STRESSES FOR INCREMENT"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRN-YY ="} freadnumber{x} ={strain:strain+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element strains:} ={strain:strain/num} write{\n} fwrite{\n} write{"Nodal strain; increment 4, node 1, component yy: " } fwrite{"Nodal strain; increment 4, node 1, component yy: " } write{$ strain"."\n} fwrite{$ strain"."\n} *{We extract strain for another node:} clearfileoperrors{} ={strain:0} ={num:0} ={end:0} fsetpos{$beginfield} while{(![end]) [ *{We search for element strains of the node of interest:} fmultskipstring{{"GLOBAL NODAL POINT = 143" "STRESSES FOR INCREMENT"} which} if {(which!=1) [ ={end:1} ] else [ fskipstring{"STRN-XY ="} freadnumber{x} ={strain:strain+x} ={num:num+1} ]} ]} *{To obtain the correct result, we must calculate an average of element strains:} ={strain:strain/num} write{\n} fwrite{\n} write{"Nodal strain; increment 4, node 143, component xy: " } fwrite{"Nodal strain; increment 4, node 143, component xy: " } write{$ strain"."\n} fwrite{$ strain"."\n} ]} *{ ************************ NODE COORDINATES: ****************************** } fsetpos{1} *{From the beginning of the result file, we search for the node coordinates field:} fskipstring{" NODE COORDINATES"} if {(fileoperror[]) [ write{"\n\nError: Node coordinates field does not exist.\n\n"} fwrite{"\n\nError: Node coordinates field does not exist.\n\n"} ] else [ *{We have found the sttring which indicates the node coordinates field, now we want to determine the actual beginning of the field:} fnextline{} fnextline{} fskipblanks{} fnextline{} fnextline{} fmarkpos{beginfield} *{Now we also determine the length of data for one node. Since the data for nodes is sorted by node numbers and the data is formatted so that every record for individual node has the same length, we can use this information for calculating where a specific record is positioned:} fnextline{secondline} ={recordlength:1+secondline-beginfield} write{\n} fwrite{\n} write{"Node coordinate; node 1, component x: " } fwrite{"Node coordinate; node 1, component x: " } *{We go to the beginning of line which belong to the appropriate node; we calculate this position from the position of the beginning of the node coordinates field and the record length: } fsetpos{ ${beginfield+(1-1)*recordlength} } *{We skip the node number:} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} *{We extract the next coordinate:} write{\n} fwrite{\n} write{"Node coordinate; node 863, component x: " } fwrite{"Node coordinate; node 863, component x: " } *{We go to the beginning of line which belong to the appropriate node; we calculate this position from the position of the beginning of the node coordinates field and the record length: } fsetpos{ ${beginfield+(863-1)*recordlength} } *{We skip the node number:} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} *{We extract the next coordinate:} write{\n} fwrite{\n} write{"Node coordinate; node 914, component y: " } fwrite{"Node coordinate; node 914, component y: " } *{We go to the beginning of line which belong to the appropriate node; we calculate this position from the position of the beginning of the node coordinates field and the record length: } fsetpos{ ${beginfield+(914-1)*recordlength} } *{We skip the node number and the x component:} fskipnumber{} fskipnumber{} freadnumber{x} write{$ x "."\n} fwrite{$ x "."\n} ]}