## ## 'awk' PROGRAM NAME: feinp_nas2freeform_nodeinfo_awkprog ## ## in $FEDIR/scripts ## where FEDIR=/apps/nns_com/fea ## ######################################################################## ## PURPOSE: This 'awk' program is called in script ## ## $FEDIR/scripts/feinp_nas2stl_bygui ## ## ** to READ an MSC/NASTRAN input file and ## ** EXTRACT GRID RECORDS into an a 'generic, free-format' output file ## ** of node info (mainly, node-ID and x,y,z-coords). ## ** --- ONE record (no continuation rec) for each node-ID. ## ## i.e. REFORMATS NASTRAN GRID RECORDS --- ## into 'generic, free-format' single records ## with data fields in each generic record space-separated. ## ## A SPECIAL FEATURE: ## Changes NASTRAN-acceptable numbers like .8254-16 to .8254E-16 ## ##------------------------------- ## INFO ON 'feinp_nas2stl_bygui': ## ## 'feinp_nas2stl_bygui' is a "NASTRAN-to-STL" file creation utility meant ## to support viewing of 1D elements as well as 2D and 3D. ## ## The 'generic' GRID-geom-info output file from this awk-prog, ## 'feinp_nas2freeform_nodeinfo_awkprog', is used as input in a ## genericFE-to-STL awk program, 'feinp_generic2stl_awkprog'. ## ## See the 'feinp_nas2stl_bygui' script for more info. ## It includes a description of the script/awk-prog call hierarchy. ## ######################################################################## ## BASIC PROCESSING: ## See the awk program, below, to see how the ## NASTRAN GRID records are read and parsed. A brief summary: ## ## The input GRID records can be in MSC ## - free-form format ## - short-field format ## or - long-field format (with continuation record). ## ## The format type is determined. Then ... ## ## For each 'logical' GRID record, a single 'free-form' record, with ## space(s) for field separators, is written --- of the form ## GRID nid cid x y z ## where nid = node-id ## cid = coordsys id ## x,y,z are x,y,z coords of the grid/node point. ## ######################################################################## ## CALLED BY: 'feinp_nas2stl_bygui' in $FEDIR/scripts, ## ## and 'feinp_nas2stl_nogui_TESTawkprogs' in $FEDIR/scripts, ## ## in an awk statement. ######################################################################## ## SIMILAR SCRIPTS/AWK-PROGS to 'feinp_nas2freeform_nodeinfo_awkprog': ## ## There is a very similar script & in-line awk-prog ## 'simtec_nasinp2freeform_nodeinfo' ## that translates NASTRAN GRID records to 'generic, free-format' ## FE-node data. ## ## 'simtec_nasinp2freeform_nodeinfo' is called by ## 'simtec_nas_tria_quad2stl_bygui' (2D-elements-only-TO-STL) ## and 'simtec_nas_tetra_penta_hexa2stl_bygui' (3D-elements-only-TO-STL). ## ##----------------- ## If improvements are made to 'simtec_nasinp2freeform_nodeinfo' ## they should probably also be made to this awk-prog, ## 'feinp_nas2freeform_nodeinfo_awkprog' --- and vice versa. ## ## These two NASTRAN-GRID-to-generic-recs scripts/awk-progs are kept ## separate --- to help avoid one utility being crippled by a bug ## introduced in ## 1) re-organizing the scripts & awk-progs ## or ## 2) handling NASTRAN grid(=node) records for the other utility. ## ######################################################################## ## INPUT: a NASTRAN input filename ## OUTPUT: stdout ######################################################################## ## TEST FILES: Test NASTRAN files with various elements are ## in directory /apps/nns_com/fea/demos_nas2stl. ## Some of these NASTRAN input files are from ## /apps/msc/msc70/msc70/nast/demo ## and /apps/msc/msc70/msc70/nast/tpl. ## Others may be from NNS NASTRAN users. ######################################################################## ## MAINTENANCE HISTORY: ## Written by: B.Montandon O06 12Sep2000 Based on the in-line awk-prog ## in 'feinp_nas2freeform_nodeinfo' ## in $FEDIR/scripts ## Updated by: B.Montandon O06 12Sep2000 ######################################################################## BEGIN { printf ("# GRID info FROM NASTRAN INPUT %-65s\n",FILE_IN); printf ("# \n"); printf ("# For each input GRID record,\n"); printf ("# a single 'free-form' record is written, of the form\n"); printf ("# GRID nid cid x y z\n"); printf ("# where 'GRID' is a string (actually, 'GRID*' in long-field recs)\n"); printf ("# nid = node-id\n"); printf ("# cid = coordsys id\n"); printf ("# x,y,z are x,y,z coords of the grid/node point.\n"); printf ("# and these 6 fields are space-separated.\n"); printf ("# \n"); DEBUG=DE_BUG; i=0; ## i is a GRID rec counter } { ####################################################################### ## *SKIP* THIS REC IF IT IS A *COMMENT* REC. ####################################################################### # if (substr($0,1,1)=="$") { next } COL1=substr($0,1,1) if (COL1=="$") { next } ####################################################################### ## SKIP THIS REC IF IT IS NOT A GRID REC. ####################################################################### FIELD1=substr($0,1,8) FIELD1=toupper(FIELD1) if ( FIELD1 !~ "GRID" ) next # if ($0 !~ "^GRID" && $0 !~ "^grid") next ####################################################################### ## DETERMINE THE RECORD FORMAT OF THE GRID REC. ####################################################################### RECfmt="free" IXCOMMA=index($0,",") if (IXCOMMA==0) RECfmt="short" if (RECfmt=="short") { IXSTAR=index(FIELD1,"*") if (IXSTAR!=0) RECfmt="long" } ## *FOR TESTING* -- show the just-captured RECfmt: if (DEBUG==1) { print "#DEBUG" print "#DEBUG - RECORD READ:" print "#DEBUG - RECfmt="RECfmt" FIELD1:"FIELD1" IXCOMMA:"IXCOMMA" IXSTAR:"IXSTAR print "#DEBUG - REC-IN=" print "#DEBUG - "$0 print "#DEBUG" } ####################################################################### ## **FREE FORMAT** RECORD-PROCESSING SECTION ####################################################################### if (RECfmt == "free") { i++ ######################################################## ## REPLACE ADJACENT COMMAS IN NASTRAN GRID REC ## BY TWO COMMAS SEPARATED BY A DUMMY STRING --- ## I.E. IN *FREE-FORMAT* RECS REPLACE SUCCESSIVE COMMAS ## BY SOMETHING. Typically the 3rd field (coord-id) ## is missing, i.e. defaulted to zero. ######################################################## # gsub(/,,/,",0,") gsub(/,,/,",dummy,") ######################################################## ## REPLACE EACH COMMA IN THE NASTRAN *FREE-FORMAT* GRID ## REC BY A BLANK. ######################################################## gsub(/,/," ") ######################################################## ## PRINT THE CHANGED *FREE-FORMAT* GRID REC. ######################################################## print $0 ## *FOR TESTING* -- show the number of the GRID record written: if (DEBUG==1) { print "#DEBUG" print "#DEBUG - FREE-FORMAT REC WRITTEN (above): Fmt="RECfmt" i="i print "#DEBUG" } ########################################################### ## END OF **FREE RECORD FORMAT** SECTION ########################################################### next } ########################################################################## ## **SHORT-FIELD-FORMAT** RECORD-PROCESSING SECTION ########################################################################## if (RECfmt == "short") { i++ ######################################################## ## GET FIELDS 1,2,3,4,5,6 OF THE NASTRAN ## *SHORT-FIELD-FORMAT* GRID REC. ## FIELDS 4,5,6 contain the x,y,z coords. ######################################################## f1=substr($0,1,8) f2=substr($0,9,8) if (f2==" ") f2="0" f3=substr($0,17,8) if (f3==" ") f3="0" f4=substr($0,25,8) if (f4==" ") f4="0" f4=refmt_number(f4) f5=substr($0,33,8) if (f5==" ") f5="0" f5=refmt_number(f5) f6=substr($0,41,8) if (f6==" ") f6="0" f6=refmt_number(f6) ######################################################## ## PRINT THE FIRST 6 FIELDS OF THE *SHORT-FIELD-FORMAT* ## GRID REC, separated by a blank. ######################################################## printf ("%s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6) ## *FOR TESTING* -- show the just-captured *GRID* data: if (DEBUG==1) { print "#DEBUG" print "#DEBUG - SHORT FIELD REC WRITTEN (above). DECOMPOSITION:" print "#DEBUG - RECfmt="RECfmt" i=grid-count="i print "#DEBUG - f1=field1="f1" f2=gridid="f2" f3=coordsys-id="f3 print "#DEBUG - f4=x="f4" f5=y="f5" f6=z="f6 print "#DEBUG" } ############################################################################## ## END OF **SHORT-FIELD RECORD FORMAT** SECTION ############################################################################## next } ############################################################################## ## **LONG-FIELD FORMAT** RECORD-PROCESSING SECTION ############################################################################## if (RECfmt == "long") { i++ ######################################################## ## GET FIELDS 1,2,3,4,5,6 OF THE NASTRAN ## *LONG-FIELD-FORMAT* GRID REC. ######################################################## f1=substr($0,1,8) f2=substr($0,9,16) if (f2==" ") f2="0" f3=substr($0,25,16) if (f3==" ") f3="0" f4=substr($0,41,16) if (f4==" ") f4="0" f4=refmt_number(f4) f5=substr($0,57,16) if (f5==" ") f5="0" f5=refmt_number(f5) getline ## *FOR TESTING* -- show the just-captured ELEMENT data: if (DEBUG==1) { print "#DEBUG - LONG-FIELD CONTINUE REC READ." print "#DEBUG - REC-IN=" print "#DEBUG - "$0 print "#DEBUG" } f6=substr($0,9,16) if (f6==" ") f6="0" f6=refmt_number(f6) ######################################################## ## PRINT THE FIRST 6 FIELDS OF THE *LONG-FIELD-FORMAT* ## GRID REC, separated by a blank. ######################################################## printf ("%s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6) ## *FOR TESTING* -- show the just-captured *GRID* data: if (DEBUG==1) { print "#DEBUG - LONG-FIELD REC WRITTEN (above). DECOMPOSITION:" print "#DEBUG - RECfmt="RECfmt" i="i print "#DEBUG - f1=field1="f1" f2=gridid="f2" f3=coordsys-id="f3 print "#DEBUG - f4=x="f4" f5=y="f5" f6=z="f6 print "#DEBUG" } ####################################################################### ## END OF **LONG-FIELD RECORD FORMAT** SECTION ####################################################################### next } ############################################################################## ## SAMPLE FIELD COUNT CHECK TO USE ABOVE. ## SHOULD NOT NEED THIS BECAUSE BLANK/DEFAULTED FIELDS ARE SET TO ZERO. ############################################################################## ## EXIT, WITH MSG TO OUTFILE, IF A GRID REC HAS LESS THAN 6 FIELDS. # if (NF<6) # \{ print "*ERROR: There must be at least 6 fields in GRID recs:" # print "*ERROR: *GRID*, two integers, and 3 x,y,z coordinates." # exit # \} ############################################################################## } END { printf ("#\n") printf ("# Created via $FEDIR/scripts/feinp_nas2freeform_nodeinfo\n") printf ("# Total number of GRID recs in this file: %12d\n",i) } ## START OF function *refmt_number* ## NOTE: This function works whether the number is short-field format ## or long-field, i.e. 8 bytes or 16 bytes. function refmt_number(NUMIN, holdnum,len) { ## FOR TESTING: # lenNUM=length(NUMIN) holdnum=NUMIN ######################################################## ## REMOVE ALL SPACES. ######################################################## gsub(" ","",holdnum) lennum=length(holdnum) ## FOR TESTING: # print "REMOVE SPACES: NUMIN=|"NUMIN"| lenNUM="lenNUM" holdnum=|"holdnum"| lennum="lennum ######################################################## ## REMOVE LEADING SPACES. ######################################################## # while (0=0) { # char1=substr(holdnum,1,1) # if (char1==" ") {holdnum=substr(holdnum,2) # } else {continue} # } ######################################################## ## REPLACE A MINUS SIGN after the 1st char of the number ## by 'E' and the minus sign. ######################################################## IXMINUS=index(holdnum,"-") if (IXMINUS>1) holdnum=substr(holdnum,1,IXMINUS-1)"E"substr(holdnum,IXMINUS,lennum) ## FOR TESTING: # print "E-REFORMAT: NUMIN=|"NUMIN"| holdnum=|"holdnum"| len="lennum return holdnum } ## END OF awk program