Skip to content

Instantly share code, notes, and snippets.

@tailriver
Created January 9, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tailriver/6c4aab0cf0c4e995dc99 to your computer and use it in GitHub Desktop.
Save tailriver/6c4aab0cf0c4e995dc99 to your computer and use it in GitHub Desktop.
Remove *parameter from Abaqus input file
#!/usr/bin/env perl
use strict;
use warnings;
if (@ARGV != 1) {
warn "$0 input_with_parameter.inp > output_without_parameter.inp\n";
exit 1;
}
my $context = "";
my %symbols;
open my $fh, '<:utf8', $ARGV[0] or die $!;
while (<$fh>) {
if (/^\*(\w+)/) {
$context = $1;
}
s/\R$//;
if ($context eq "parameter") {
next unless /=/;
s/^ +//;
s/ +$//;
my($lhs, $rhs) = split / *= */;
while (my ($k, $v) = each %symbols) {
$rhs =~ s/\b$k\b/$v/g;
}
my $value = eval $rhs;
die "eval error: `$rhs`: $@\n" if $@;
$symbols{$lhs} = $value;
} else {
s/<(\w+)>/$symbols{$1}/g;
print $_, "\n";
}
}
close $fh;
=pod
for my $k (sort keys %symbols) {
print "** $k = $symbols{$k}\n";
}
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment