File mttroot/mtt/bin/trans/abg2lbl_fig2txt artifact f9d0cf4b05 part of check-in 644f6421a6


#! /bin/sh

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

# Bourne shell script: abg2lbl_fig2txt
#
# Acausal bond graph to causal bond graph: mfile format

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.10  2000/01/26 10:11:10  peterg
## Added I component
##
## Revision 1.9  1999/11/10 00:47:08  peterg
## Replaced ifs by a table of cr/arg information
##
## Revision 1.8  1999/11/09 22:32:41  peterg
## Under RCS ready for using arrays to contaain defaults.
##
## Revision 1.7  1998/07/04 10:37:21  peterg
## Major revision to include:
## 	aliases
## 	new Style
## 	prettyfied
##
## Revision 1.6  1998/03/05 10:09:47  peterg
## Corrected bug in writing "other" components
##
## Revision 1.5  1998/03/02 09:26:18  peterg
## Now does default CR and args for the basic components only
## SS,I,R,C,GY,TF
## C now has a default of effort input.
##
## Revision 1.4  1998/02/23 16:20:33  peterg
## Summary line just contains the model name
##
## Revision 1.3  1997/05/09 14:21:35  peterg
## Default to flow,component_name
##
# Revision 1.2  1997/03/19  12:08:01  peterg
# No longer writes out non-unique names - now done in rbg_fig2m
#
# Revision 1.1  1997/03/18  13:55:01  peterg
# Initial revision
#
###############################################################


# P.J.Gawthrop March 1997
# Copyright (c) P.J.Gawthrop, 1997

infofile='mtt_info.txt'
typefile="$1_type.sh"
sensitivity=$2;

# Remove the old log file
rm -f abg2lbl_fig2txt.log
rm -f $1_cbg.m
rm -f $typefile
rm -f $infofile
rm -f mtt_junk*

#Inform user


if [ -n "$sensitivity" ]; then
    echo "Creating $1_lbl.txt (sensitivity version)"
else
    echo "Creating $1_lbl.txt"
fi

	( \
	echo "%% Label file for system $1 ($1_lbl.txt)"; \
	echo "%SUMMARY $1"; \
	echo "%DESCRIPTION "; \
	cat $MTTPATH/trans/m/rcs_header.txt; \
        )>mtt_junk_top.txt

	( \
	echo; \
	echo "%% Each line should be of one of the following forms:"; \
	echo "%	     a comment (ie starting with %)"; \
	echo "%	     component-name	cr_name	arg1,arg2,..argn"; \
	echo "%	     blank"; \
	echo; \
	echo "% ---- Component labels ----"; \
        )> mtt_junk_blurb.txt

awk '/:/ {print $NF}' $1_abg.fig | \
sed 's/\\001//' | \
sort | \
tee $1_raw_list | \
sort -u> $1_unique_raw_list

#Write out non-unique names
#echo 'Non-unique names (if any):'
#diff $1_unique_raw_list  $1_raw_list | grep '>' | sed 's/>/	/'

#Write out the outline lbl file
grep -v  '\[[0-9]*\]'  $1_unique_raw_list | \
awk --field-separator ':' '
 BEGIN {
    OldComponent="None";
 }
 { 
  Component = $1;
  ##Aliases
  if (Component == "SS") {
    port_alias[++j] = $2;
  }
  else {
    alias[++i] = $2;
    if (length(sensitivity)>0) {
      s_arg = sprintf("%ss",$2);
      alias[++i] = s_arg;
      s_arg = sprintf(";%s",s_arg);
      Component = substr(Component,2);
    }
 }

    ## Table of components
    cr["SS"] = "SS";  arg["SS"] = "external,external";

    cr["Se"] = "SS";  arg["Se"] = sprintf("external%s", s_arg);
    cr["Sf"] = "SS";  arg["Sf"] = sprintf("external%s", s_arg);

    cr["De"] = "SS";  arg["De"] = "external";
    cr["Df"] = "SS";  arg["Df"] = "external";

    cr["R"] = "lin";  arg["R"]  = sprintf("flow,%s%s", $2, s_arg);
    cr["C"] = "lin";  arg["C"]  = sprintf("effort,%s%s", $2, s_arg);
    cr["I"] = "lin";  arg["I"]  = sprintf("flow,%s%s", $2, s_arg);

    cr["CS"] = "lin";  arg["CS"]  = sprintf("effort,%s;x_0%s", $2, s_arg);
    cr["IS"] = "lin";  arg["IS"]  = sprintf("flow,%s;x_0%s", $2, s_arg);

    cr["TF"] = "lin";  arg["TF"]  = sprintf("flow,%s%s", $2, s_arg);
    cr["GY"] = "lin";  arg["GY"]  = sprintf("flow,%s%s", $2, s_arg);

    cr["AE"] = "lin";  arg["AE"]  = sprintf("%s%s", $2, s_arg);
    cr["AF"] = "lin";  arg["AF"]  = sprintf("%s%s", $2, s_arg);

  ## Heading
  if (Component !~ OldComponent) print "\n% Component type", Component

  ## Component
    print  "\t" $2 "\t" cr[Component] "\t\t" arg[Component];
    OldComponent=Component;
  }
  END{
    print "\n% Port aliases" >> "mtt_junk_alias.txt";
    for (k=1;k<=j;k++){
      if (port_alias[k] ~ "\\["){ # Only do ports
        port_name = substr(port_alias[k],2,length(port_alias[k])-2);
        if (length(sensitivity)==0)
          print "%ALIAS\t" port_name "\t" port_name >> "mtt_junk_alias.txt";
        else
          print "%ALIAS\t" port_name "\t" port_name "_1," port_name "_2" >> "mtt_junk_alias.txt";
      }
    }

    print "\n% Argument aliases" >> "mtt_junk_alias.txt";
    for (k=1;k<=i;k++){
      print "%ALIAS\t\$" k "\t" alias[k] >> "mtt_junk_alias.txt";
    }
 }' sensitivity=$sensitivity > mtt_junk_body.txt

cat mtt_junk_top.txt mtt_junk_alias.txt mtt_junk_blurb.txt mtt_junk_body.txt > $1_lbl.txt











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