File mttroot/mtt/bin/trans/abg2sympar_m2txt artifact daf0665c64 part of check-in 9d9d8be442


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: abg2sympar_m2txt

# Label file to symbolic parameters conversion
# Copyright (C) 2000 by Peter J. Gawthrop


# Inform user
echo "Creating $1_sympar.txt"

rm -f mtt_error
# Separation characters
SEPS=';+*/()-'
# Replace by ,
REPS=',,,,,,,'

# This is the main transformation using gawk
tr $SEPS $REPS <  $1_abg.m | \
awk '
function exact_match(name1, name2) {
  return ((match(name1,name2)>0)&&(length(name1)==length(name2)))
}

function matches(names, name) {
  n_matches = split(names,match_name);
  matched = 0;
  for (i_matches = 1; i_matches <= n_matches; i_matches++) {
    if ( exact_match(name,match_name[i_matches]) ) {
      matched = 1;
      break;
    }
  }
  return matched;
}

BEGIN {
  var = "[%|#]VAR";
  not_an_arg = "effort flow state internal external zero unknown";
  arg_line = "arg = ";
}
{
  ## Explicit VAR declarations
  if (match($1,var)>0) print $2 "\t" system_name;

   ## Implicit declarations from the arg list
  if (match($1,"arg")>0) {
    args=substr($3,2,length($3)-3);
    N=split(args, arg, ",");
    for (i=1;i<=N;i++){
      if ( (length(arg[i])>0)&&(matches(not_an_arg,arg[i])==0)&&(match(arg[i],"^[0-9]+[.]*")==0) ){
        print arg[i] "\t" system_name;
      }
    }
  }
}' system_name=$1 |\
grep -v '^\$' |\
sort -u > $1_sympar.txt 2>mtt_error.txt

# Now invoke the standard error handling.
mtt_error mtt_error.txt





MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]