## TEST ## 'awk' PROGRAM NAME: feinp_nas2freeform_elinfo_awkprogTESTcbeam_cbar ## ## in $FEDIR/scripts ## where FEDIR=/apps/nns_com/fea ## ######################################################################## ## PURPOSE: FOR TESTING OF REFORMATTING OF CBEAM/CBAR RECORDS ## into a 'generic, free-format'. ## ## ** This awk-program READs an MSC/NASTRAN input file and ## ** EXTRACTs various ELEMENT records (CBEAM & CBAR -- ## ** for test) into an output file. ## ## See the statements/section-starts like ## if ($0 ~ "^CBEAM" || $0 ~ "^cbeam") ## 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 cid g1 g2 g3 ... ## where elname is an element name like CBEAM ## eid = element-id (an integer) ## cid = 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: ## - CBEAM/CBAR ######################################################################## ## MAINTENANCE HISTORY: ## Written by: B.Montandon O06 16Aug2000 'nasinp2freeform_elTESTcbeam_cbar' ## 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_elTESTcbeam_cbar' ## into this awkprog file. ######################################################################## ## SAMPLE INPUT FOR TESTING: ## $ 1 2 3 4 5 6 7 ## $ 345678901234567890123456789012345678901234567890123456789012345678901234567890 ## GRID ## $ ## CBEAM,37,37,114,115,0.0,1.0,0.0 ## CBEAM 38 38 115 116 0.0 0.0 1.0 ## CBEAM* 39 39 116 117 + ## + 1.0 0.0 0.0 ## CBEAM 40 40 115 116 1 ## CBEAM* 41 41 116 117 + ## + 2 BEGIN { printf ("# ELEMENT RECS FROM NASTRAN INPUT %-65s\n",FILE_IN); printf ("# \n"); printf ("# For each input ELEMENT record,\n"); printf ("# a single *free-form* record is written, of the form\n"); printf ("# elname eid pid g1 g2 g3 ...\n"); printf ("# where elname = element name like CBEAM\n"); printf ("# eid = element-id, integer\n"); printf ("# pid = property id (usually), integer\n"); printf ("# gi-s are ids of grid/node points, integers.\n"); printf ("# \n"); ## i is a GRID rec counter; j is an element rec counter. i=0; j=0; DEBUG=DE_BUG } { ############################################################################## ## *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" 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 } ########################################################################### ## **CBEAM/CBAR** RECORD PROCESSING LOGIC: ########################################################################### ## LOOK FOR *CBEAM* or *CBAR* IN THE FIRST FIELD. ## INCREMENT THE ELEMENT-REC COUNT, j. ########################################################################### if ($0 ~ "^CBEAM" || $0 ~ "^cbeam" || \ $0 ~ "^CBAR" || $0 ~ "^cbar") {j++ ####################################################### ## CBEAM/BAR **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) PRINT THE CHANGED *FREE-FORMAT* ELEMENT REC. ## SAMPLE: CBEAM,37,37,114,115,0.0,1.0,0.0 ## ASSUMPTION: ALL THE NEEDED DATA IS IN ONE REC. ####################################################### if (RECfmt=="free") { # gsub(/,,/,",0,") gsub(/,,/,",dummy,") gsub(/,/," ") print $0 ## *FOR TESTING* -- show the changed rec, to be written: if (DEBUG==1) { print "DEBUG - FREE-FORMAT REC WRITTEN. RECfmt="RECfmt" j="j } next } ######################################################### ## END OF CBEAM/BAR **FREE RECORD FORMAT** WRITE SECTION ######################################################### ########################################################### ## CBEAM/BAR **SHORT-FIELD-FORMAT** RECORD-PROCESSING SECTION ########################################################### ## 1) GET FIELDS 1,2,3,4,5,6 OF THE NASTRAN ## *SHORT-FIELD-FORMAT* CBEAM/BAR REC. ## [THE 4th,5th FIELDS are 2 grid ids --- AND ## if the 7th FIELD IS BLANK, THE 6th FIELD is a GRID ID, ## ELSE ## THE 6th,7th,8th FIELDS are xyz coords of orientation vec. ## ## SAMPLE: ## $ 1 2 3 4 5 6 7 ## $2345678901234567890123456789012345678901234567890123456789012345678901234567890 ## $ ## CBEAM 38 38 115 116 0.0 0.0 1.0 ## ## 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) if (f5==" ") f5="dummy" f6=substr($0,41,8) if (f6==" ") f6="dummy" f7=substr($0,49,8) if (f7 == " ") { printf ("%s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6) f8=" " } else { f8=substr($0,57,8) if (f8==" ") f8="dummy" printf ("%s %s %s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6,f7,f8) } ## *FOR TESTING* -- show the just-captured *CBEAM/BAR* data: if (DEBUG==1) { print "DEBUG - SHORT FIELD REC WRITTEN. DECOMPOSITION:" print " Fmt="RECfmt" j=element-count="j print " f1=elname="f1" f2=elid="f2" f3=propid="f3 print " f4=g1="f4" f5=g2="f5 print " f6="f6" f7="f7" f8="f8 } next } ############################################################ ## END OF CBEAM/BAR **SHORT-FIELD-FORMAT** WRITE SECTION ############################################################ ############################################################ ## CBEAM/BAR **LONG-FIELD FORMAT** RECORD-PROCESSING SECTION ############################################################ ## 1) GET FIELDS 1,2,3,4,5,6 OF THE NASTRAN ## *LONG-FIELD-FORMAT* CBEAM/BAR REC. ## [THE 4th,5th FIELDS are 2 grid ids --- AND ## if the 7th FIELD IS BLANK, THE 6th FIELD is a GRID ID, ## ELSE ## THE 6th,7th,8th FIELDS are xyz coords of orientation vec. ## ## SAMPLE: ## $ 1 2 3 4 5 6 7 ## $2345678901234567890123456789012345678901234567890123456789012345678901234567890 ## $ ## CBEAM 39 39 116 117 + ## + 1.0 0.0 0.0 ## ## 2) PRINT THE CAPTURED FIELDS, SPACE-SEPARATED, in one rec. ########################################################### if (RECfmt=="long") { f1=substr($0,1,8) f2=substr($0,9,16) if (f2==" ") f2="dummy" f3=substr($0,25,16) if (f3==" ") f3="dummy" f4=substr($0,41,16) if (f4==" ") f4="dummy" f5=substr($0,57,16) if (f5==" ") f5="dummy" getline ## *FOR TESTING* -- show the just-captured ELEMENT data: if (DEBUG==1) { print "DEBUG - LONG-FIELD CONTINUE REC READ. REC:" print $0 } f6=substr($0,9,16) if (f6==" ") f6="dummy" f7=substr($0,25,16) if (f7==" ") { printf ("%s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6) f8=" " } else { f8=substr($0,41,16) if (f8==" ") f8="dummy" printf ("%s %s %s %s %s %s %s %s\n",f1,f2,f3,f4,f5,f6,f7,f8) } ## *FOR TESTING* -- show the just-captured ELEMENT data: if (DEBUG==1) { print "DEBUG - LONG-FIELD REC WRITTEN. DECOMPOSITION:" print " Fmt="RECfmt" j=element-count="j print " f1=elname="f1" f2=elid="f2" f3=propid="f3 print " f4=g1="f4" f5=g2="f5 print " f6="f6" f7="f7" f8="f8 } next } ###################################################### ## END OF **LONG-FIELD RECORD FORMAT** WRITE SECTION ###################################################### } ######################################################################### ## END OF **CBEAM/BAR** RECORD PROCESSING LOGIC. ######################################################################### } END { printf ("# Created via $FEDIR/scripts/nasinp2freeform_elinfo\n") printf ("# or via $HOME/Dscrtest/test_nasinp2freeform_cbeam_cbar\n") printf ("# Total number of GRID recs encountered: %12d\n",i) printf ("# Total number of ELEMENT recs put in this file: %12d\n",j) }