#! /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$
###############################################################
# 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 "%% Structure file ($1_struc.m)" >> $1_struc.m
echo "%% Generated by MTT at `date`" >> $1_struc.m
# This is the main transformation using awk
awk '
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