#! /usr/bin/perl # ParseElemsNodes.pl - split the elements and nodes created by ls-prepost2 into # two separate files (elems.dyn and nodes.dyn) # # USAGE:./ParseElemsNodes.pl < PrePostFile # # Mark Palmeri 08/27/07 # Department of Biomedical Engineering # Pratt School of Engineering # Duke University use strict; use warnings; use POSIX; my $z = 0; my $y = 0; my $x = 0; my $rem = 0; my $temp1 = 100; my $temp2 = 10; # check to make sure that you aren't going to clobber a # pre-existing file if(-e 'elems.dyn') {die "elems.dyn already exists" } if(-e 'nodes.dyn') {die "nodes.dyn already exists" } # open file handles for the element and node files open(ELEMFILE,'> elems.dyn'); open(NODEFILE,'> nodes.dyn'); # print the header for each file print ELEMFILE "*ELEMENT_SOLID\n"; print NODEFILE "*NODE\n"; while(<>) { # remove the EOL characters from each line chomp; # split up each line into columns delimited by spaces my @fields = split(' ',$_); # split the field entries using commas in the output file my $printout = join ",", @fields; # node entries will have 4 entries per line, while element # entries will have 10 entries per line if( ($#fields + 1) == 4) { print NODEFILE "$printout\n"; } elsif( ($#fields + 1) == 10) { $z = ceil($fields[0] / $temp1); $rem = $fields[0] - $z; # y coordinate. $y = ceil($rem / $temp2); $rem = $rem - $y; # x coordinate. $x = $rem; # Inclusion is 33 && $x<8 && $y>3 && $y<8){ print ELEMFILE "$fields[0],2,$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9]\n"; } else { print ELEMFILE "$printout\n"; } print ELEMFILE "$printout\n"; } } # print to footer for each file print ELEMFILE "*END\n"; print NODEFILE "*END\n"; # close the file handles close(ELEMFILE); close(NODEFILE);