File mttroot/mtt/bin/trans/abg2sympar_m2txt artifact f1c08a0b7a part of check-in 37b5fb06f3


#! /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" with $1 $2 $3

# Separation characters
SEPS='^=*;+/()-'
# Replace by ,
REPS='[,*]'

SystemName=$2
UseLabelFile=$3

if [ -n "$UseLabelFile" ]; then ## Take input from lbl.txt
     strip_comments < $1_lbl.txt  | tr $SEPS $REPS |\
     gawk '{printf("%s %s \"%s\",\n",$1,$2,$3)}' > mtt_stripped_file
else ## Take input from _abg.m
     cat $1_abg.m | grep "arg =" | tr $SEPS $REPS > mtt_stripped_file
fi

rm -f mtt_error
# This is the main transformation using gawk
cat mtt_stripped_file | \
gawk '
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 = "[%|#][PAR|VAR]";
  not_an_arg = "effort flow state internal external zero unknown\
                mtt_e mtt_f\
		sqrt exp log sign sin asin cos acos tan atan \
		sin asin cos acos tan atan \
		sinh asinh cosh acosh tanh atanh \
                none abs";
  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);
    if (length(args)>0)
      printf("%s\t%s\n", args,system_name)
##  }
}' system_name=$SystemName |\
grep -v '^\$' | mtt_strip_args | sort -u > mtt_stripped_args


## Now get the explicit declarations
if [ -n "$UseLabelFile" ]; then ## Take input from lbl.txt
    ext=_lbl.txt
else
    ext=_abg.m
fi

strip_pars.sh $1${ext} $1 |  sort -u > mtt_explicit_args

## And write sorted list
cat  mtt_explicit_args mtt_stripped_args 




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