######################################
##### Model Transformation Tools #####
######################################
# gawk script: lbl2sympar.awk
# Label file to symbolic parameters conversion
# P.J.Gawthrop August 1996
# Copyright (c) P.J.Gawthrop, 1996.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
###############################################################
function exact_match(name1, name2) {
return ((match(name1,name2)>0)&&(length(name1)==length(name2)))
}
function matches(name, names) {
n = split(names,match_name);
matched = 0;
for (i = 1; i <= n; i++) {
if ( exact_match(name,match_name[i]) ) {
matched = 1;
break;
}
}
return matched;
}
BEGIN {
comment = "%";
arg_delimiter = ",";
not_an_arg = "effort flow internal external zero";
numeric = "[0-9]";
symbol_count = 0;
symbols = "";
}
{
if ( (match($1,comment)==0) && (NF>=3) ) {
args = $3;
n_args = split(args,arg,arg_delimiter);
for (i = 1; i <= n_args; i++) {
first_char = substr(arg[i],1,1);
if ( (matches(not_an_arg,arg[i])==0) \
&& (match(first_char,numeric)==0) \
&& (length(arg[i])>0) \
&& (matches(symbols,arg[i]) ==0) ) {
symbol_count++;
symbols = sprintf("%s %s", symbols, arg[i]);
}
}
}
}
END {
# print the _sympar file
printf("%% Symbolic parameter file - generated by MTT\n\n");
printf("MTTNVar := %1.0f;\n", symbol_count);
if (symbol_count>0) {
printf("MATRIX MTTVar(MTTNVar,1);\n");
split(symbols,symbol);
for (i = 1; i <= symbol_count; i++) {
printf("MTTVar(%1.0f,1) := %s;\n", i, symbol[i]);
}
}
}