## TEST ## 'awk' PROGRAM NAME: feinp_nas2freeform_elinfo_awkprogTESTrbe2 ## ## in $FEDIR/scripts ## where FEDIR=/apps/nns_com/fea ## ######################################################################## ## PURPOSE: FOR TESTING OF REFORMATTING OF *RBE2* RECORDS ## into a 'generic, free-format'. ## ## ** This awk-program to READs an MSC/NASTRAN input file and ## ** EXTRACTs RBE2 ELEMENT record formats into an output file. ## ## **NOTE: Makes multiple 'CROD-RBE2' recs for eventual representation, ## in an STL file, like 'CROD' elements. ## ## See the statements/section-starts like ## if ($0 ~ "^RBE2" || $0 ~ "^rbe2") ## in this awk program to see the supported elements --- and ## how the NASTRAN records are read and parsed. ## ## The input ELEMENT records can be in MSC ## - free-form format ## - short-field format ## or - long-field format (with continuation record). ## ## For each input ELEMENT record, a single 'free-form' record is written ## which is generally of the form ## elname eid pid g1 g2 g3 ... ## where elname is an element name like CBEAM ## eid = element-id (an integer) ## pid = property id, usually (an integer) ## gi's are ids of grid/node points (integers). ## ######################################################################## ## CALLED BY: TEST SCRIPT 'feinp_nas2stl_nogui_TESTawkprogs' ## in $FEDIR/scripts. ## To prepare for incorporation into ## 'feinp_nas2freeform_elinfo_awkprog' ## which is called in 'feinp_nas2stl_bygui' ## ## which is a "NASTRAN-to-STL" file creation utility. ## ## The 'generic' ELEMENT-info output file is used as input in ## 'feinp_nas2stl_bygui'. See that script for more info. ## ######################################################################## ## INPUT: 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. ######################################################################## ## SUPPORTED ELEMENT RECORD TYPES BELOW: ## - RBE2 ######################################################################## ## MAINTENANCE HISTORY: ## Written by: B.Montandon O06 24Aug2000 'nasinp2freeform_elTESTrbe2' ## test script+awkprog was created ## based on 'nasinp2stl_awkprog' ## and 'nasinp2stl_bygui' ## in $FEDIR/scripts ## Updated by: B.Montandon O06 13Sep2000 Extracted awkprog from ## 'nasinp2freeform_elTESTrbe2' ## into this awkprog file. ######################################################################## ## SAMPLE INPUT FOR TESTING: ## $ 1 2 3 4 5 6 7 ## $ 345678901234567890123456789012345678901234567890123456789012345678901234567890 ## GRID 101 5 0.0 0.0 0.0 5 345 ## GRID 102 6 0.0 0.0 0.0 6 345 ## GRID 103 -238.147420. ## $ ## $ EID G0 DOFs G1 G2 G3 G4 G5 ## $ G6 G7 ... ## $ ## RBE2 100 103 126 101 102 ## $ ## RBE2 5005 1405 12345 651 652 653 654 655 +RB41 ## +RB41 727 728 ## $ ## RBE2,1005,1405,12345,651,652 ## $ ## RBE2,5005,1405,12345,651,652,653,654,655,+RB41 ## +RB41,727,728,729,621,622,623,624,625,+RB42 ## +RB42,702,703,704,705,777,778,779,626,+RB43 ## +RB43,627,628,629,630,677,678,679,680,+RB44 ## +RB44,752,753,754 ## $ BEGIN { printf ("# ELEMENT RECS FROM NASTRAN INPUT %-65s\n",FILE_IN); printf ("# \n"); printf ("# For each input RBE2 ELEMENT record,\n"); printf ("# one or more *free-form* record(s) are written, of the form\n"); printf ("# elname eid dummy g0 gi \n"); printf ("# where elname = element name = CROD-RBE2\n"); printf ("# eid = element-id, integer\n"); printf ("# dummy is in place of typical item in the 3rd field\n"); printf ("# --- pid = property id (usually), integer\n"); printf ("# gi is id (integer) of a grid/node points exracted.\n"); printf ("# the RBE2 rec or one of its continuations.\n"); printf ("# \n"); DEBUG=DE_BUG; i=0; jrbe2=0; jrodrbe2=0 ## i is a GRID rec counter. ## jrbe2 is an element in-rec counter. ## jrodrbe2 is an element out-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 A *GRID* REC. ############################################################################## FIELD1=substr($0,1,8) FLD1CAPS=toupper(FIELD1) if (FLD1CAPS ~ "GRID") {i++; next} ############################################################################## ## DETERMINE THE RECORD FORMAT OF THE INCOMING REC. ############################################################################## RECfmt="free" IXCOMMA=index($0,",") if (IXCOMMA==0) RECfmt="short" ############################################################################## ## NOTE: LONG-FORMAT MAY ONLY BE AN ISSUE WITH GRID RECS, not element recs. ############################################################################## ## We do not try to deal with LONG-FORMAT RBE2 RECS. ############################################################################## # if (RECfmt=="short") # { # IXSTAR=index(FIELD1,"*") # if (IXSTAR!=0) RECfmt="long" # } ## *FOR TESTING* -- show the just-captured RECfmt: if (DEBUG==1) { print "**************************************" print "DEBUG - nonGRID,nonCOMMENT RECORD READ:" print " Fmt="RECfmt" FIELD1="FIELD1" IXCOMMA="IXCOMMA" IXSTAR="IXSTAR print " Rec=" print $0 } ########################################################################### ## **RBE2** RECORD PROCESSING LOGIC: ########################################################################### ## LOOK FOR *RBE2* IN THE FIRST FIELD. ## INCREMENT THE ELEMENT-REC COUNT, j. ########################################################################### if ($0 ~ "^RBE2" || $0 ~ "^rbe2") {jrbe2++ ####################################################### ## *RBE2* **FREE FORMAT** RECORD-PROCESSING SECTION ####################################################### ## 1) REPLACE ADJACENT COMMAS IN ELEMENT REC ## BY TWO COMMAS SEPARATED BY A DUMMY STRING --- ## 2) REPLACE EACH COMMA IN THE *FREE-FORMAT* ## ELEMENT REC BY A BLANK. ## 3) THEN, GET FIELDS 1,2,3,4,5 OF THE NASTRAN ## *FREE-FORMAT* *RBE2* REC. ## ## THE 3rd & 5th FIELDS are 2 grid ids --- G0 & G1. ## ## We write a pseudo 'CROD-RBE2' rec with this data -- ## in the CROD format: CROD-RBE2,eid,pid,g1,g2 ## with g1,g2=f3,f5. ## ## If the 6th FIELD IS BLANK, we are done. If not, ## THE 6th FIELD is a GRID ID. Write another 'CROD-RBE2', ## with g1,g2=f3,f6. ## ## If the 7th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 8th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 9th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 10th FIELD IS NOT BLANK, 'getline' the next rec ## write another 'CROD-RBE2' with f2. ## If the 3rd FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 4th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 5th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 6th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 7th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 8th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 9th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 10th FIELD IS NOT BLANK, 'getline' the next rec ## write another 'CROD-RBE2' with f2. ## If the 3rd FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 4th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## etc. etc. ## ## We will keep a counter and stop after 100 continuations, to ## avoid a loop --- which we deem more important than getting ## all the RBE2s, at this time. ## SAMPLES: ## $ ## $ EID G0 DOFs G1 G2 G3 G4 G5 ## $ G6 G7 ... ## $ ## RBE2,1005,1405,12345,651,652 ## $ ## RBE2,5005,1405,12345,651,652,653,654,655,+RB41 ## +RB41,727,728,729,621,622,623,624,625,+RB42 ## ## NOTE: THE NEEDED DATA MAY BE IN CONTINUATION RECS. ####################################################### if (RECfmt=="free") { # gsub(/,,/,",0,") gsub(/,,/,",dummy,") gsub(/,/," ") f1=$1 f2=$2 # if (f2==" ") f2="dummy" f3=$3 # if (f3==" ") f3="dummy" f4=$4 # if (f4==" ") f4="dummy" f5=$5 eid=f2; g0=f3 printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f5) jrodrbe2++ f6=$6 # if (f6=="") { next } ## FAILS IF NO FIELD6 ? if (6<=NF) { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f6) jrodrbe2++ f7=$7 if (f7=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f7) jrodrbe2++ f8=$8 if (f8=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f8) jrodrbe2++ f9=$9 if (f9=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f9) jrodrbe2++ f10=$10 if (f10=="") { next } contin_cnt=0 getcont: getline contin_cnt=contin_cnt+1 if (contin_cnt>1000) { next } ## *FOR TESTING* -- show the just-captured ELEMENT data: if (DEBUG==1) { print "DEBUG - SHORT-FIELD CONTINUE REC READ. REC:" print $0 } f2=$2 printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f2) jrodrbe2++ f3=$3 # if (f3=="") { next } ## FAILS IF NO FIELD6 ? if (3<=NF) { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f3) jrodrbe2++ f4=$4 if (f4=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f4) jrodrbe2++ f5=$5 if (f5=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f5) jrodrbe2++ f6=$6 if (f6=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f6) jrodrbe2++ f7=$7 if (f7=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f7) jrodrbe2++ f8=$8 if (f8=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f8) jrodrbe2++ f9=$9 if (f9=="") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f9) jrodrbe2++ f10=$10 if (f10=="") { next } goto getcont next } ######################################################### ## END OF *RBE2* **FREE RECORD FORMAT** WRITE SECTION ######################################################### ########################################################### ## *RBE2* **SHORT-FIELD-FORMAT** RECORD-PROCESSING SECTION ########################################################### ## 1) FIRST, GET FIELDS 1,2,3,4,5 OF THE NASTRAN ## *SHORT-FIELD-FORMAT* *RBE2* REC. ## ## THE 3rd & 5th FIELDS are 2 grid ids --- G0 & G1. ## ## We write a pseudo 'CROD-RBE2' rec with this data -- ## in the CROD format: CROD-RBE2,eid,pid,g1,g2 ## with g1,g2=f3,f5. ## ## If the 6th FIELD IS BLANK, we are done. If not, ## THE 6th FIELD is a GRID ID. Write another 'CROD-RBE2', ## with g1,g2=f3,f6. ## ## If the 7th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 8th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 9th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 10th FIELD IS NOT BLANK, 'getline' the next rec ## write another 'CROD-RBE2' with f2. ## If the 3rd FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 4th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 5th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 6th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 7th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 8th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 9th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 10th FIELD IS NOT BLANK, 'getline' the next rec ## write another 'CROD-RBE2' with f2. ## If the 3rd FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## If the 4th FIELD IS NOT BLANK, write another 'CROD-RBE2'. ## etc. etc. ## ## We will keep a counter and stop after 100 continuations, to ## avoid a loop --- which we deem more important than getting ## all the RBE2s, at this time. ## ## SAMPLE: ## $ 1 2 3 4 5 6 7 ## $2345678901234567890123456789012345678901234567890123456789012345678901234567890 ## $ ## $ EID G0 DOFs G1 G2 G3 G4 G5 ## $ G6 G7 ... ## $ f2 f3 f4 f5 f6 f7 f8 f9 ## $ ## RBE2 100 103 126 101 102 ## $ ## RBE2 5005 1405 12345 651 652 653 654 655 +RB41 ## +RB41 727 728 ## ## 2) PRINT THE CAPTURED FIELDS, SPACE-SEPARATED, in one rec. ########################################################### if (RECfmt=="short") { f1=substr($0,1,8) f2=substr($0,9,8) # if (f2==" ") f2="dummy" f3=substr($0,17,8) # if (f3==" ") f3="dummy" f4=substr($0,25,8) if (f4==" ") f4="dummy" f5=substr($0,33,8) eid=f2; g0=f3 printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f5) jrodrbe2++ f6=substr($0,41,8) if (f6==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f6) jrodrbe2++ f7=substr($0,49,8) if (f7 == " ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f7) jrodrbe2++ f8=substr($0,57,8) if (f8==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f8) jrodrbe2++ f9=substr($0,75,8) if (f9==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f9) jrodrbe2++ f10=substr($0,73,8) if (f10==" ") { next } contin_cnt=0 getcont: getline contin_cnt=contin_cnt+1 if (contin_cnt>1000) { next } ## *FOR TESTING* -- show the just-captured ELEMENT data: if (DEBUG==1) { print "DEBUG - SHORT-FIELD CONTINUE REC READ. REC:" print $0 } f2=substr($0,9,8) # if (f2==" ") f2="dummy" printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f2) jrodrbe2++ f3=substr($0,17,8) if (f3==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f3) jrodrbe2++ f4=substr($0,25,8) if (f4==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f4) jrodrbe2++ f5=substr($0,33,8) if (f5==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f5) jrodrbe2++ f6=substr($0,41,8) if (f6==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f6) jrodrbe2++ f7=substr($0,49,8) if (f7 == " ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f7) jrodrbe2++ f8=substr($0,57,8) if (f8==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f8) jrodrbe2++ f9=substr($0,75,8) if (f9==" ") { next } printf ("CROD-RBE2 %s PID %s %s\n",eid,g0,f9) jrodrbe2++ f10=substr($0,73,8) if (f10==" ") { next } goto getcont next } ############################################################ ## END OF *RBE2* **SHORT-FIELD-FORMAT** WRITE SECTION ############################################################ } ######################################################################### ## END OF **RBE2** RECORD PROCESSING LOGIC. ######################################################################### } END { printf ("# Created via $FEDIR/scripts/nasinp2freeform_elTESTrbe2\n") printf ("# Total number of GRID recs encountered: %12d\n",i) printf ("# Total number of RBE2 ELEMENT recs read: %12d\n",jrbe2) printf ("# Total number of CROD-RBE2 ELEMENT recs output: %12d\n",jrodrbe2) }' > $OUTFILE ## FOR PRODUCTION (all print to OUTFILE): # $FILEIN > $OUTFILE ## OPTION FOR TESTING (all print to stdout): # $FILEIN ## FOR TESTING: ## set - ######################################################################### ## FOR TESTING, ## SHOW the free-from GRID-info file -- via 'nedit' in read-only mode. ######################################################################### # if test "$DEBUGIN" = "1" # then nedit -read $OUTFILE & # fi