#! /bin/sh

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

# Bourne shell script: struc_txt2m

# Structure file - txt to m conversion
# P.J.Gawthrop April 1997
# Copyright (c) P.J.Gawthrop, 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.4  2002/04/28 18:55:03  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.3  2001/10/15 14:20:27  gawthrop
## Now handles the cases where ny or nx or nu are zero
##
## Revision 1.2  2001/03/19 02:28:52  geraint
## Branch merge: merging-ode2odes-exe back to MAIN.
##
## Revision 1.1.2.1  2001/03/06 03:52:15  geraint
## Put back struc_txt2m - required by mtt2sys.
##
###############################################################



# Inform user
echo "Creating $1_struc.m"

rm -f mtt_error

#Write some file headers
echo "function [input_name,output_name,state_name] = $1_struc" > $1_struc.m
echo "%% Usage: [input_name,output_name,state_name] = $1_struc" >> $1_struc.m
echo "%% Structure file ($1_struc.m)" >> $1_struc.m
echo "%% Generated by MTT at `date`" >> $1_struc.m

cat  >> $1_struc.m <<EOF

## Default to null strings
 input_name = "";
 output_name = "";
 state_name  = "";
EOF



# This is the main transformation using awk
gawk '
function header(what){
  print what "_name = [";
}

function footer(what){
  print "];";
}

BEGIN{
Which="";
apostrophe = "\047";
}
{
  if ($1!=Which) {
    if (Which!="") footer(Which);
    header($1);
  }
  print  apostrophe $4 "_" $3 apostrophe;
  Which = $1;
}
END{
  footer(Which)
}
'  SYSTEM=$1  < $1_struc.txt >> $1_struc.m 2>mtt_error.txt

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


