Artifact 84ca816297ebe9c281b8c093fa9bec8fb06e99eeebfc462edf12e98c66d64139:


#! /bin/sh

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

# Bourne shell script: mtt
# This is the main shell script for MTT

# P.J.Gawthrop Oct 1989, Dec 1989, 1990, 1991, Oct 1993, Dec 1993, Jan 1994, Dec 95, Nov 1996.
# Copyright (c) P.J.Gawthrop, 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997,1998,1999
# Copyright (C) 2000 by Peter J. Gawthrop
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$
## Revision 1.417  2008/07/22 17:37:01  geraint
## Fixed case of MTT_EXAMPLES
##
## Revision 1.416  2006/09/27 13:03:20  geraint
## Fixed fr.view and enabled commands to directly build ??fr.m
##
## Revision 1.415  2006/02/09 23:58:24  geraint
## rtxi: builds but does not yet work.
##
## Revision 1.414  2005/11/18 17:23:19  geraint
## rtxi.
##
## Revision 1.413  2005/11/16 00:43:15  geraint
## rtxi
##
## Revision 1.412  2005/09/29 13:46:25  gawthrop
## Converts labg.fig -> ps/eps correctly (using fig2ps)
##
## Revision 1.411  2005/03/15 15:03:28  gawthrop
## Now works for Hierarchical systems
##
## Revision 1.410  2005/03/15 13:35:50  gawthrop
## Pretty abg figure in reports.
##
## Revision 1.409  2005/03/15 12:03:17  gawthrop
## New labg.fig rep - pretty LaTeX figures.
##
## Revision 1.408  2005/02/18 16:59:02  gawthrop
## Don't check files when using -s
##
## Revision 1.407  2005/02/17 18:36:38  geraint
## Removed a bash-ism: replaced [[ conditional ]] with [ conditional ]
##
## Revision 1.406  2005/01/06 15:36:06  geraint
## Tidied output of options.
##
## Revision 1.405  2005/01/06 12:47:53  geraint
## Fixed generation of sese.r with -make-sort option.
##
## Revision 1.404  2004/09/10 21:05:15  geraint
## Ensure that the system exists before proceeding.
## This should stop me from copying my home directory to MTT_work.
##
## Revision 1.403  2004/09/07 20:38:44  geraint
## Applies CRs before creating sese.make to avoid Circular dependencies.
##
## Revision 1.402  2004/09/03 08:35:27  geraint
## Copies Perl CRs to an mtt subdirectory (=> mtt:: workspace).
##
## Revision 1.401  2004/09/02 22:04:06  geraint
## Passes ${use_reduce} to mtt_make_sympar so that it can decide
## if to issue warnings about Reduce reserved words
##
## Revision 1.400  2004/08/31 01:29:48  geraint
## CRs are applied to sorted equation files during production.
##
## Revision 1.399  2004/08/29 16:09:49  geraint
## Added option -no-reduce
##
## Code sorting can now be used with Reduce (via sese.r) so that existing CRs
## work with sorted code (using -make-sort or -sort), or without by using
## -no-reduce; this option implies -make-sort.
##
## Revision 1.398  2004/08/29 14:39:23  geraint
## Added rule to create dae from sorted equations (sese) if sorting is requested.
##
## Revision 1.397  2004/08/29 13:17:30  geraint
## Added rules to use sae (sorted algebraic equations) instead
## of ae if sorted equations are being used.
##
## Converted temporary variable names to lowercase in sorted
## sympar.h to match code output from mtt_r2m.
##
## Revision 1.396  2004/08/29 02:59:30  geraint
## Added -make-sort option and rules to generate simulation using sesx and sesy.
##
## Revision 1.395  2004/08/28 23:48:06  geraint
## Removed dependency of ae.r on cse.r if -ae is not specified as an option.
## This prevents an implicit -A and thus removes a dependency on cse
## (and hence Reduce) for sorted systems.
##
## Revision 1.394  2004/08/28 22:14:12  geraint
## Removed -ibg option: now the default method.
##
## Revision 1.393  2004/08/26 16:20:17  geraint
## Creates postscript files of either dia or fig bond graphs.
##
## Revision 1.392  2004/08/26 12:50:12  geraint
## Replaced some implicit rules with explicit tests and patterns.
## Better than having make search through every possible implicit rule.
##
## Revision 1.391  2004/08/26 00:07:06  geraint
## Added rule to create cbg.dia.
##
## Revision 1.390  2004/08/13 09:49:13  geraint
## Only use one level of MTT_work to prevent MTT from repeatedly copying or creating the same files.
##
## Revision 1.389  2004/08/13 01:32:03  geraint
## Use ibg.m by default for both Xfig and Dia models.
##
## Revision 1.388  2004/08/11 08:18:07  geraint
## Ignores diy make files if the file ${rep}_rep.make.ignore exists, thus allowing user-defined makefiles to use the default MTT rules for languages which they do not override. See odes_rep.make and odeso_rep.make for an example of its use.
##
## Revision 1.387  2004/08/11 07:44:18  geraint
## Included cmp.m as a prerequisite for abg.m
##
## Revision 1.386  2004/08/05 00:02:57  geraint
## Uses lbl2cmp_txt2m.pl to generate _cmp.m.
##
## Revision 1.385  2004/08/02 20:25:47  geraint
## abg.m requires lbl.txt to allow units to be checked.
##
## Revision 1.384  2004/08/01 20:13:30  geraint
## ibg2abg transformation does not require lbl.txt (directly)
##
## Revision 1.383  2004/08/01 19:50:07  geraint
## Moved rules for ibg.m and abg.m so that -ibg can be used with dia models.
## Need to create cmp.m files before this combination will work.
##
## Revision 1.382  2003/09/23 20:53:49  geraint
## Updated version number (5.0).
##
## Revision 1.381  2003/08/10 18:56:55  gawthrop
## Explicitly generate eps files
##
## Revision 1.380  2003/08/06 14:44:51  gawthrop
## Don't include -q or -u in long file names via ${__ARGS}
##
## Revision 1.379  2003/08/06 10:33:42  gawthrop
## User now warned not to use -c which is unsupported.
##
## Revision 1.378  2003/08/04 09:15:09  gawthrop
## -ss switch reinstated
##
## Revision 1.377  2003/06/11 15:48:02  gawthrop
## Copies (aliased) subsystems first.
## Include switches in .ps file names.
##
## Revision 1.376  2003/05/09 09:46:35  gawthrop
## Fixed html output of figures
##
## Revision 1.375  2003/05/08 18:42:52  gawthrop
## Generate pdf from ps (using hyperref package for links etc)
##
## Revision 1.374  2003/04/17 20:57:27  geraint
## Added -sort option to allow direct generation of ode2odes.m using sese.m
## instead of ode/csex.
##
## "mtt -sort rc odeso view" works without Reduce installed!!!
##
## Revision 1.373  2003/04/17 20:07:32  geraint
## Added rule to create _sese.m
##
## Revision 1.372  2003/03/24 12:03:36  gawthrop
## Added -I switch to sese transformation
##
## Revision 1.371  2003/03/13 15:47:35  gawthrop
## Added sese rep.
##
## Revision 1.370  2003/02/11 20:04:08  geraint
## Reverted to line-by-line optimisation as default and added caution to
## description of -optg.
##
## Global optimisation has been observed to create assignments using
## uninitialised temporary variables.
##
## Revision 1.369  2003/02/06 20:28:40  geraint
## Added -ibg switch to aid testing during development of ibg2abg.m
##
## Revision 1.368  2002/12/12 17:18:41  geraint
## Fixed [ 647664 ] Namespace clash: LANG
## Prepended MTT_ to SYS, OPTS and LANG environment variables.
##
## Revision 1.367  2002/12/09 00:14:08  geraint
## Hierarchical dia and mixed dia/fig bond graphs now working.
##
## Revision 1.366  2002/12/06 21:56:21  geraint
## Cosmetic change: removed commented-out lines.
##
## Revision 1.365  2002/12/06 12:45:25  gawthrop
## Simplified rule for sub.sh: both fig and dia go via cmp.txt now.
##
## Revision 1.364  2002/12/03 23:28:44  geraint
## Added dependencies for bond graphs built with dia.
##
## Revision 1.363  2002/11/30 13:39:50  gawthrop
## Split abg2lbl_fig2txt into two parts:
##   abg2cmp_fig2txt
##   cmp2lbl_txt
## and incorporated into mtt
##
## Revision 1.362  2002/09/19 08:12:53  gawthrop
## Merged version after documentation update
##
## Revision 1.361  2002/09/16 08:08:00  geraint
## Merged changes from global-optimisation branch.
##
## Revision 1.360.2.3  2002/09/16 07:59:26  geraint
## Changed default optimisation to global.
##
## Revision 1.360.2.2  2002/09/04 10:44:59  geraint
## Added option to specify number of tmp variables declared (-ntmpvar <N>).
##
## Revision 1.360.2.1  2002/09/03 23:44:43  geraint
## adding global optimisation (-optg).
##
## Revision 1.360  2002/08/20 15:51:16  gawthrop
## Update to work with ident DIY rep
##
## Revision 1.359  2002/08/07 14:27:14  geraint
## Changes to make "-i dassl" work again.
##
## Revision 1.358  2002/08/07 11:04:40  geraint
## Now updates timestamp on lbl.txt after processing in make. This eliminates the delay where MTT spends a long period of time uselessly recursing through the model on subsequent passes if the label file is older than the bondgraph.
##
## Revision 1.357  2002/06/28 10:13:40  geraint
## Includes fix_c.r in ese2rdae and def2write_r to eliminate occurrances of x**y.
##
## Revision 1.356  2002/06/17 13:14:50  geraint
## Fixed some rules to reduce number of implicit rule searches.
##
## Revision 1.355  2002/06/10 23:18:44  geraint
## Adjusted cr.h comment delimiters to be C compliant.
##
## Revision 1.354  2002/06/10 10:43:19  gawthrop
## ode2odes now prerequisite for sim.m and ssim.m
##
## Revision 1.353  2002/05/28 18:08:38  geraint
## Fixed [ 547294 ] CRs are not sought from MTT_CRS.
##
## Revision 1.352  2002/05/24 11:04:10  geraint
## Removed unnecessary message about *.log file not existing when -D option is used.
##
## Revision 1.351  2002/05/23 17:08:20  geraint
## `mtt sys sfun zip` now produces an input block and an interface block for MTT models.
## Models can be embedded within larger Simulink models by the 2 ports.
## The user must edit 2 code blocks in <sys>_sfun_interface.c before compiling with mex.
##
## Revision 1.350  2002/05/21 08:45:36  gawthrop
## DIY reps: no longer skips rep if file exists already.
## Avoids problems in rep.txt when options change
##
## Revision 1.349  2002/05/20 10:29:59  gawthrop
## -oct now forces an m target language to be oct
## (if the rep is an the list: "ae input logic numpar simpar state")
##
## Revision 1.348  2002/05/20 08:50:12  geraint
## Cleans _sfun_ae.mexglx.
##
## Revision 1.347  2002/05/20 07:12:05  gawthrop
## Trying to get oct files generated with -oct
##
## Revision 1.346  2002/05/17 11:15:38  gawthrop
## Messages about copying when using -dr now only appear in verbose (-v) mode.
##
## Revision 1.345  2002/05/15 14:22:25  geraint
## Code for Simulink S-function target written direct to sfun.cc instead of
## calling .mexglx files. This eliminates the sfun dependency on Octave
## ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine
## (can't test this yet).
##
## added sfun.zip target to create source code to export.
##
## Revision 1.344  2002/05/11 01:14:17  geraint
## Fix for [ 553218 ] simpar.oct and simpar.m different.
## Translation added between ColumnVector in base .cc and Octave_map in .oct.
##
## Revision 1.343  2002/05/10 14:07:16  geraint
## Preserve .cc files.
##
## Revision 1.342  2002/05/10 13:24:58  geraint
## Added initial support for building Simulink S-functions.
## Rates do not update properly yet.
## Inertial switches do not work yet.
## Implicit integration not supported yet.
##
## build with: mtt -i euler MotorGenerator sfun mexglx.
##
## Revision 1.341  2002/05/09 15:40:22  gawthrop
## -dr touches copied files to redo timestamp
##
## Revision 1.340  2002/05/08 22:13:47  geraint
## Removed redundant path from mtt_*.cc targets in mexglx build line.
##
## Revision 1.339  2002/05/08 21:32:26  geraint
## Tidied up $1_ode2odes_*.* targets and renamed dummies as *.stamp.
##
## Revision 1.338  2002/05/08 16:03:32  geraint
## Added mex support for ode2odes: mtt sys ode2odes mexglx.
## This mex stuff seems to require octave2.1-headers.
##
## Revision 1.337  2002/05/08 14:51:03  geraint
## Moved matlab/octave data type conversion functions to a separate file.
##
## Revision 1.336  2002/05/07 23:50:34  geraint
## Preliminary support for Matlab dynamically linked shared objects:
## invoke with: mtt -cc sys rep mexglx
## ode2odes support is not yet included.
##
## Revision 1.335  2002/05/01 17:30:55  geraint
## Improved pre-processor directives to better accommodate future alternatives (matlab)
## if necessary.
##
## Revision 1.334  2002/05/01 14:10:22  gawthrop
## Added -dr foo (reads from dir foo) option
##
## Revision 1.333  2002/04/28 18:41:26  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.332  2002/04/26 23:19:00  geraint
## Fixed path to info files for "mtt info".
##
## Revision 1.331  2002/04/19 09:24:29  gawthrop
## 2 changes to ode2odes_out generation: only compiles the specified c
## file; outside the computation=c clause
##
## Revision 1.330  2002/04/17 10:03:12  geraint
## Marked .sg as a major representation.
##
## Revision 1.329  2002/04/16 14:58:00  gawthrop
## mtt copy does NOT now copy the CVS directory
## $directory --> ${directory}  (just to be tidy)
##
## Revision 1.328  2002/02/19 16:27:05  geraint
## Changes to make MTT work out of the box with Debian.
##
## Revision 1.327  2001/11/15 02:56:17  geraint
## Added DASSL as an option for solution of algebraic equations (-ae dassl).
## Requires octave-2.1.35.
##
## Revision 1.326  2001/10/26 01:01:47  geraint
## fixcc when rdae_is_dae (-cr).
##
## Revision 1.325  2001/10/11 03:15:55  geraint
## Fixed make dependencies for c++ simulation code
## - re-simulation no longer required for different output format.
##
## Revision 1.324  2001/10/05 23:39:43  geraint
## Made odes.dat2 .PRECIOUS to prevent deletion when simulation receives ^C.
##
## Revision 1.323  2001/08/08 02:14:59  geraint
## Rationalisation of solver code, beginning with algebraic solvers.
##
## Revision 1.322  2001/08/01 04:06:07  geraint
## Added -i dassl for -cc and -oct.
##
## Revision 1.321  2001/07/27 23:43:34  geraint
## Added -cc to usage options (required for use with xmtt).
##
## Revision 1.320  2001/07/27 23:38:38  geraint
## Changed comment below (# SUMMARY) - fixes xmtt.
##
## Revision 1.319  2001/07/27 23:29:10  geraint
## *** empty log message ***
##
## Revision 1.318  2001/07/24 04:17:30  gawthrop
## Removed all " from # SUMMARY lines - messes up xmtt
##
## Revision 1.317  2001/07/24 00:55:17  gawthrop
## Resolved clashes -- marked with ## >>>
##
## Revision 1.316  2001/07/22 19:24:03  geraint
## Multiple '-v' increases verbosity.
##
## Revision 1.315  2001/07/13 04:54:04  geraint
## Branch merge: numerical-algebraic-solution back to main.
##
## Revision 1.314  2001/07/13 04:19:03  gawthrop
## Now loads _subs.r with _cr.r file when using -cr option
##
## Revision 1.313  2001/06/13 14:53:59  gawthrop
## MTT now gas the double-colon option in the abg.fig file
## eg R:r:a^2+3*b
##
## Revision 1.312  2001/06/11 19:43:49  gawthrop
## MTT is now much more sophisticated in generating lbl files
## Labels can contain maths
## Repetative components are now broken
##
## Revision 1.311  2001/05/26 18:36:43  gawthrop
## Further modifications. Now works on rcPPP
##  -- next jobs:
##     add identification to ppp_nlin_sim
##     create real-time ppp_nlin_run
##
## Revision 1.310  2001/05/08 08:30:12  gawthrop
## Added line to reverse the x^y --> pow(x,y) in default  _simp file to
## prettyfy LaTeX
##
## Revision 1.309.2.3  2001/07/13 04:02:31  geraint
## Implemented numerical algebraic solution for _ode2odes.oct.
##
## Revision 1.309.2.2  2001/06/05 03:20:39  geraint
## added -ae option to select algebraic equation solution method.
##
## Revision 1.309.2.1  2001/05/04 04:07:24  geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.309  2001/04/28 03:15:03  geraint
## Fixed comment (interfered with "mtt help representations").
##
## Revision 1.308  2001/04/25 22:17:45  geraint
## Fixed icd.txt2 dependency.
##
## Revision 1.307  2001/04/15 21:15:41  geraint
## Added interface definition rep: _ICD.(txt|c|cc|m).
##
## Revision 1.305  2001/04/11 09:44:26  gawthrop
## Fixed cc and c problems to do with pow(x,y) and integers
## mtt/lib/reduce/fix_c.r is included in rdae2dae and cse2smx_lang for
## -c, -cc and -oct options
##
## Revision 1.304  2001/04/11 07:35:22  gawthrop
## Now uses system_cr.h in place of system.h in .c rep -
##   compatible with older code
##
## Revision 1.303  2001/04/10 12:54:50  gawthrop
## Minor fixes for sensitivity versions
##
## Revision 1.302  2001/04/06 05:24:30  geraint
## -stdin for .cc reps.
##
## Revision 1.301  2001/04/05 03:46:12  geraint
## Added mtt_prepend.sh, -p preserves time attribute of base file
## - eliminates error in dependencies due to update of ese.r by modpar.r.
##
## Revision 1.300  2001/04/04 10:06:49  gawthrop
## New ssim (sensitiveity simulation) rep
##
## Revision 1.299  2001/04/03 14:49:42  gawthrop
## Revised to incorporate new ssim (sensitivity simulation)
## representation (m only just now).
##
## Revision 1.298  2001/04/02 17:36:20  gawthrop
## Resolved $sys name clash when using -s
##
## Revision 1.297  2001/03/29 19:20:45  gawthrop
## Can now use c representations of crs when using -c option
##
## Revision 1.296  2001/03/27 01:07:34  geraint
## Improved determination of Octave version for ode2odes.exe creation.
## Removed FORCE check_update of .txts.
##
## Revision 1.295  2001/03/23 11:21:29  gawthrop
## Show -pdf oprion in help list
##
## Revision 1.294  2001/03/19 02:28:52  geraint
## Branch merge: merging-ode2odes-exe back to MAIN.
##
## Revision 1.293.2.8  2001/03/19 01:35:31  geraint
## Reverted forced update check to main branch form, ready for merge.
##
## Revision 1.293.2.7  2001/03/17 09:51:06  geraint
## Implemented Runge-Kutta IV fixed-step method (-i rk4).
##
## Revision 1.293.2.6  2001/03/03 06:50:38  geraint
## Added summary lines for ode2odes.
##
## Revision 1.293.2.5  2001/03/03 00:27:14  geraint
## Fixed ar options to work with GNU ar. Allow mtt to create dependencies for mtt_%.cc when making mtt_%.oct.
##
## Revision 1.293.2.4  2001/03/02 00:45:21  geraint
## Separated Euler and Implicit methods in .cc code and dependencies.
##
## Revision 1.293.2.3  2001/03/01 05:05:53  geraint
## Minor revisions.
##
## Revision 1.293.2.2  2001/02/23 03:53:53  geraint
## Minor revisions. (ode2odes.exe works on GNU/Linux and ~GNU/Irix)
##
## Revision 1.293.2.1  2001/02/22 06:41:40  geraint
## Initial merge of ode2odes.exe into main mtt.
## standalone_rep.make deleted: rules moved to mtt, variables to mttrc.
##
## Revision 1.293  2001/02/06 04:39:08  geraint
## Added _standalone.exe representation.
##
## Revision 1.292  2001/02/05 17:27:40  gawthrop
## Make sure _def.r exists before creating _state.txt
##
## Revision 1.291  2000/12/27 14:50:40  peterg
## This is the first CVS version (4.9).
## Commented out code now deleted
##
## Revision 1.290  2000/12/05 09:59:37  peterg
## Generates $1_cr.h - allows inclusion of c functions for crs
##
## Revision 1.289  2000/12/05 09:01:52  peterg
## Changed == to =
##
## Revision 1.288  2000/12/01 17:59:01  peterg
## Added .PRECIOUS: %.cc to hang on to cc files - thanks Geraint
##
## Revision 1.287  2000/12/01 16:04:24  peterg
## More partitioning achieved -- now needs the connections to be properly
## sorted in cbg2ese_r
##
## Revision 1.286  2000/12/01 14:18:44  peterg
## -partition now partially works up to cse.m
##   but need to think about indexing, struc files etc for subsystems.
##
## Revision 1.285  2000/11/27 11:51:21  peterg
## Fixed a few pdf /fig bugs
##
## Revision 1.284  2000/11/27 10:33:35  peterg
## -pdf option now coerces ps-->pdf
##
## Revision 1.283  2000/11/24 15:11:50  peterg
## -pdf switch for simple displays
##
## Revision 1.282  2000/11/24 14:53:53  peterg
## Added lagrange rep : lde.r and lde.tex
##
## Revision 1.281  2000/11/16 13:51:15  peterg
## Added units stuff
##
## Revision 1.280  2000/11/10 14:45:16  peterg
## Finished up changes to incorporate Geraint's cc stuff
##
## Revision 1.279  2000/11/08 09:51:52  peterg
## Started incorporating Geraints CC/oct conversions
##
## Revision 1.278  2000/11/07 16:39:21  peterg
## *** empty log message ***
##
## Revision 1.277  2000/10/17 09:54:07  peterg
## logic rep sorted out
##
## Revision 1.276  2000/10/15 09:30:31  peterg
## *** empty log message ***
##
## Revision 1.275  2000/10/12 18:38:47  peterg
## New method of sympar generation implemented - uses mtt_make_sympar
## Check/update of numpar.txt is forced.
##
## Revision 1.274  2000/10/12 15:11:54  peterg
## Added the update function for numpar only
##
## Revision 1.273  2000/10/10 21:00:27  peterg
## More changes for new code gneration
##
## Revision 1.272  2000/10/06 16:20:00  peterg
## added ode_write rule
##
## Revision 1.271  2000/10/03 12:14:25  peterg
## Version 4.8
##
## Revision 1.270  2000/10/03 12:13:51  peterg
## Corrected MTT_LIB paths
##
## Revision 1.269  2000/09/30 14:12:03  peterg
## Fixed bug with no-parameter systems - changed mtt_txt2m and mtt_m2p
##
## Revision 1.268  2000/09/27 16:15:55  peterg
## Now sh (as opposed to bash) compatible -  fixed dat22dat again
##
## Revision 1.267  2000/09/21 10:08:30  peterg
## Version 4.7.1 - bug in odes.dat representation fixed in dat22dat
##
## Revision 1.266  2000/09/19 07:47:38  peterg
## fig2dev back to eps - ps produces a4 style output.
##
## Revision 1.265  2000/09/19 07:45:28  peterg
## Version 4.7
##
## Revision 1.264  2000/09/15 08:37:27  peterg
## Fixed bug using -sub in cbg view
##
## Revision 1.263  2000/09/15 07:33:35  peterg
## Replace fig2dev language eps by ps to avoid version problem.
##
## Revision 1.262  2000/09/14 17:16:33  peterg
## Fixes some outstanding bugs:
##   perpendicular strokes in cbg.fig
##   proper display of hierachical cbg file (-sub and -viewlevel)
##
## Revision 1.261  2000/09/14 12:43:46  peterg
## view of ps s files now uses -sub and -viewlevel options
##
## Revision 1.260  2000/09/14 09:59:08  peterg
## Added -viewlevel switch
##
## Revision 1.259  2000/09/11 08:21:27  peterg
## Introduced MML - but for _tf rep only.
##
## Revision 1.258  2000/09/11 08:17:28  peterg
## Extended _simp.r to incude default switches
##
## Revision 1.257  2000/09/02 15:53:53  peterg
## Now does partitioning up to dae.view
##
## Revision 1.256  2000/09/02 14:24:06  peterg
## -sub switch introduced - works up to dae.r
##
## Revision 1.255  2000/08/30 11:43:04  peterg
## Put in the -opt switch for code optimisation
##
## Revision 1.254  2000/08/29 09:59:47  peterg
## Version 4.5 -- includes code optimisation using the "Scope" package in reduce
##
## Revision 1.253  2000/08/24 08:53:35  peterg
## New makesubs to create a .subs.r file with output switches to simplify output.
##
## Revision 1.252  2000/08/09 10:31:17  peterg
## Use -d option to find if its a book-style report
##
## Revision 1.251  2000/08/04 10:54:33  peterg
## Rationalised call to gcc using -lp2c to access p2c lib.
##
## Revision 1.250  2000/08/01 19:29:27  peterg
## Explcit zero of input in the simulations
##
## Revision 1.249  2000/08/01 12:28:02  peterg
## VERSION 4.4
##    euler now works
##    stepfactor applies to both int. algorithms
##
## Revision 1.248  2000/07/20 07:46:07  peterg
## Version 4.3
##
## Revision 1.247  2000/07/13 07:21:12  peterg
## Interface to Octave Control Systems Toolbox (OCST) - mtt2sys.m
##
## Revision 1.246  2000/05/21 18:00:11  peterg
## Make manual if not already done.
## Released 4.2 version
## (Train Durham -- Glasgow).
##
## Revision 1.245  2000/05/19 17:50:10  peterg
## Changes to state rep - now has parameter
##
## Revision 1.244  2000/05/19 14:19:46  peterg
## Added library path for representations
##
## Revision 1.243  2000/05/19 11:36:36  peterg
## Added logic rep.
##
## Revision 1.242  2000/05/18 20:12:02  peterg
## Version 4.2
##
## Revision 1.241  2000/05/16 11:42:14  peterg
## Addded /usr/lib/libp2c.a  to gcc
##
## Revision 1.240  2000/05/10 09:38:58  peterg
## Added Make to list of copied files.
##
## Revision 1.239  2000/04/11 18:08:33  peterg
## Fixed cse.tex bug
##
## Revision 1.238  2000/04/10 10:06:41  peterg
## Sorted out implicit rules for p2oct conversion
##
## Revision 1.237  2000/04/07 19:10:24  peterg
## New smxa and smxax reps
##
## Revision 1.236  2000/04/06 10:55:36  peterg
## Removed debug lines
##
## Revision 1.235  2000/04/06 10:52:53  peterg
## Replace $PWD with `pwd` for sh compatibility
##
## Revision 1.234  2000/04/04 16:14:08  peterg
## Sorted mtt help
##
## Revision 1.233  2000/03/16 10:16:11  peterg
## Clean no longer zaps the abg.m files
##
## Revision 1.232  2000/03/16 09:43:35  peterg
## Put in $mtt_switches in mtt comand line when creating _state.txt and
## _input.txt
##
## Revision 1.231  2000/03/15 21:24:23  peterg
## Version 4.1:
##   Fixed problems with -abg mode
##   Old-style SS lbl no longer supported
##
## Revision 1.230  2000/03/15 20:31:06  peterg
## Replaced lbl2cr by abg2cr_m2txt
##
## Revision 1.229  2000/03/15 19:39:40  peterg
## Replaced sub creation cmp2sub_m2sh by abg2sub_m2sh
##
## Revision 1.228  2000/03/07 10:54:14  peterg
## Added  $1_lbl.txt to sympar.txt
##
## Revision 1.227  2000/02/16 15:05:46  peterg
## Replaced spurious 8spaces by tab
##
## Revision 1.226  2000/02/10 18:51:31  peterg
## Included OFF exp; in subs.r default
##
## Revision 1.225  2000/02/10 15:03:10  peterg
## Put subs.r file into the m-code generation -- allows the off exp;
## switch for simpler expresions.
##
## Revision 1.224  2000/02/08 10:27:04  peterg
## Removed obselete .h stuff
##
## Revision 1.223  2000/02/08 09:55:00  peterg
## Added .oct language for ode
## -- octave loadable builtin
##
## Revision 1.222  1999/12/23 10:03:42  peterg
## Added $1_sympars.txt to numpar.m target
##
## Revision 1.221  1999/12/22 05:15:51  peterg
## Set to version 4.0.
##
## Revision 1.220  1999/12/17 03:17:57  peterg
## reps_made is now $1_reps_made - stops clash between two reps per directory
##
## Revision 1.219  1999/12/14 00:36:50  peterg
## Changed $source to $stdin and added to mtt_m2p arg list
##
## Revision 1.218  1999/12/03 00:04:50  peterg
## Version to eric.
## -stdin switch added
##
## Revision 1.217  1999/11/16 22:15:55  peterg
## Changed compcopy to test for abg, not lbl file
##
## Revision 1.216  1999/11/16 05:53:21  peterg
## Added sensitivity (-s) switch
##
## Revision 1.215  1999/11/15 22:45:31  peterg
## Reorganised integration method using -i switch
## Introduced -r (reset) switch
##
## Revision 1.214  1999/11/14 21:27:11  peterg
## *** empty log message ***
##
## Revision 1.213  1999/09/02 23:24:40  peterg
## Now explicitly generates executable _ode2odes.out file
## Which takes command line arguments
##
## Revision 1.212  1999/08/18 06:20:32  peterg
## Put -u back again .....
##
## Revision 1.211  1999/08/17 04:10:38  peterg
## Removed the -u switch from cp - it doesnt work on non GNU cps
##
## Revision 1.210  1999/08/02 12:52:12  peterg
## Removed redundant .p copying.
##
## Revision 1.209  1999/07/27 03:50:13  peterg
## Fixed odeo.p bug.
## Fixed compound object bug in fig.
##
## Revision 1.208  1999/07/20 23:43:05  peterg
## V 3.8 ( to Eric)
##
## Revision 1.207  1999/04/02 07:17:37  peterg
## Upped version to 3.6 -- the new implicit solver with switches
##
## Revision 1.206  1999/04/02 06:28:54  peterg
## New implicit method - solves numerical prob with ISW
##
## Revision 1.205  1999/03/15 23:27:43  peterg
## Modified generation of odes.dat2 data
##
## Revision 1.204  1999/03/15 05:53:33  peterg
## Put in user-defined representations
##
## Revision 1.203  1999/03/08 03:51:12  peterg
## Version 3.5 for Linux Red Hat 5.2 (Newcastle)
##
## Revision 1.202  1999/02/17 01:59:20  peterg
## Now handles html copy correctely (ie mv directory to ..)
## Fixed path probs with html
##
## Revision 1.201  1999/02/16 03:50:09  peterg
## Removed explicit _smx targets
##
## Revision 1.200  1998/12/03 17:11:03  peterg
## Added -dc (derivative causality) switch.
##
## Revision 1.199  1998/12/03 16:53:50  peterg
## Now completes causality using component, not bond, status.
##
## Revision 1.198  1998/11/20 16:12:30  peterg
## Now copies aliased systems BEFORE generating rgb etc.
##
## Revision 1.197  1998/11/20 09:00:45  peterg
## Number of changes to underlying tools
##
## Revision 1.196  1998/11/10 11:55:40  peterg
## Added $info_switch to abg2cbg invocation
##
## Revision 1.195  1998/10/28 13:58:57  peterg
## Added $1_sympars.txt prerequisite to _tf.m target
##
## Revision 1.194  1998/10/20 09:00:43  peterg
## Added a few summary lines - to help with xmtt
##
## Revision 1.193  1998/10/01 16:11:42  peterg
## Implicit integration now handles switches
##
## Revision 1.192  1998/09/29 20:09:46  peterg
## Fixed nyfr and nifr plotting bug
##
## Revision 1.191  1998/09/02 12:05:39  peterg
## Added INPUT to simpar
## Revision 1.190  1998/09/02 11:48:51  peterg
## VERSION 3.2 (Swansea)
## abg data structure now uses explicti port and subsystem lists so that
## processing is in predetermined order.
##
## Revision 1.189  1998/08/31 10:49:15  peterg
## Minor changes to -abg operation
##
## Revision 1.188  1998/08/27 08:33:21  peterg
## New reduce integration methods - euler/Implicit only
##
## Revision 1.187  1998/08/25 20:06:56  peterg
## New data structure for abg.m and cbg.m
##
## Revision 1.186  1998/08/18 10:49:05  peterg
## VERSION 3.1 release
##
## Revision 1.185  1998/08/18 09:21:14  peterg
## Removed "" from default simpar file.
##
## Revision 1.184  1998/08/18 09:08:26  peterg
## Now grabs components (specified in lbl file as alias) at the rbg stage
## - this makes sure that they are there when needed.
##
## Revision 1.183  1998/08/18 08:48:43  peterg
## Sorted out problem with ifeq ($REPTYPE,data) block - added else.
##
## Revision 1.182  1998/08/17 15:48:39  peterg
## Replaced SVD solver with LUD solver
##
## Revision 1.181  1998/08/15 13:45:28  peterg
## Added new integration methods in Pascal/c version
## Revised the various translations appropriately
##
## Revision 1.180  1998/08/12 14:15:13  peterg
## Implicit integration - c implemetation now included.
##
## Revision 1.179  1998/08/12 12:29:18  peterg
## Put back some of the args stuff -- needed for plots.
##
## Revision 1.178  1998/08/11 13:38:35  peterg
## Zapped the obsolete args stuff
##
## Revision 1.177  1998/07/30 17:32:44  peterg
## VERSION 3.0
##
## Revision 1.176  1998/07/27 20:25:15  peterg
## Sorted out new mtt_r2m
##
## Revision 1.175  1998/07/27 18:49:09  peterg
## Fixed the frequency stuff
##
## Revision 1.174  1998/07/27 07:10:10  peterg
## Removed dummy global stuff.
##
## Revision 1.173  1998/07/26 14:38:20  peterg
## *** empty log message ***
##
## Revision 1.172  1998/07/26 11:13:38  peterg
## Fixed name classes with globs - ide is that all @strong{MTT} variables
## start with @strong{MTT}
##
## Revision 1.171  1998/07/25 20:37:22  peterg
## Removes -s (switches) option -- they are now assumed to be present
## I still need to shift the old switch
##
## Revision 1.170  1998/07/25 19:16:22  peterg
## Sorted out sympar + switch variables - new sympars rep combines both
##
## Revision 1.169  1998/07/25 16:35:12  peterg
## Incorporated mtt_p2c (uses p2c)
##
## Revision 1.168  1998/07/25 09:44:25  peterg
## Uses Pascal as step on the way to c code -- MUCH nicer!
## State and input now use the simple default - no steady states
##
## Revision 1.167  1998/07/24 17:10:34  peterg
## *** empty log message ***
##
## Revision 1.166  1998/07/22 08:37:30  peterg
## Implicit integration now the default - for octave anyway.
##
## Revision 1.165  1998/07/19 16:00:22  peterg
## Added smx representation
##
## Revision 1.164  1998/07/17 19:45:58  peterg
## Component aliases implemented.
##
## Revision 1.163  1998/07/17 08:27:33  peterg
## Added find target
##
## Revision 1.162  1998/07/16 16:14:27  peterg
## Now stops if a transformation forces error.
##
## Revision 1.161  1998/07/08 11:21:32  peterg
## Added -I switch
##
## Revision 1.160  1998/07/04 11:38:51  peterg
## Version 3.0-- (Seascale)
##
## Revision 1.159  1998/07/04 11:37:43  peterg
## Aliases implemented for parameters + lots of associated goodies
## New-style lbl files - no more SS nonsense.
##
## Revision 1.158  1998/07/03 09:06:39  peterg
## Alias implemented for ports
##
## Revision 1.157  1998/07/01 10:22:11  peterg
## Moved tidy stuff to end of preamble -- needed to make muti-plot copy
## correctely
## Now copies ps file with arguments to WD
##
## Revision 1.156  1998/06/26 14:19:43  peterg
## Copy hidden files (eg .octaverc) in tidy mode
##
## Revision 1.155  1998/06/24 07:43:42  peterg
## Version 2.91 -- includes implicit integration (octave)
##
## Revision 1.154  1998/06/17 14:14:09  peterg
## Removed struc.txt prerequisite for simpar.txt - switch version
##
## Revision 1.153  1998/05/28 09:36:38  peterg
## --version and --versions switch
##
## Revision 1.152  1998/05/24 15:43:10  peterg
## Added symbolic solution of alg. equations (-A)
##
## Revision 1.151  1998/05/23 16:18:37  peterg
## ordinary differential equation.m files generated with the new ode2lang
## method.
##
## Revision 1.150  1998/05/19 19:47:37  peterg
## Updated the odesso representation to use simpar file.
##
## Revision 1.149  1998/05/14 15:16:13  peterg
## Sorted out Differential-Algebraic Equation simulation
## Added LSODE methode to ordinary differential equation simulation
##
## Revision 1.148  1998/05/12 14:42:07  peterg
## Added ese_tidy and new method for organising ese files -
## Each subsystem has an array of variables - effort, flow and state for
## each bond
##
## Revision 1.147  1998/04/15 18:41:47  peterg
## Fixed various probs with multiple systems in one directory
##
## Revision 1.146  1998/04/04 11:00:20  peterg
## Modified various parts to allow coercing directions at ports
##
## Revision 1.145  1998/04/03 11:17:44  peterg
## VERSION 2.9
##
## Revision 1.144  1998/03/27 13:32:25  peterg
## Removed sympar prerequisites from ss reps.
##
## Revision 1.143  1998/03/22 21:14:03  peterg
## Added obspar.r representation
## Help now case insensitive
##
## Revision 1.142  1998/03/20 15:09:26  peterg
## Changed order of prerequisites for _dae.r to put _rdae.r first.
##
## Revision 1.141  1998/03/11 10:45:19  peterg
## Added rclean - recursive clean
##
## Revision 1.140  1998/03/09 10:23:30  peterg
## PS view now runs as a background process.
##
## Revision 1.139  1998/03/07 16:04:23  peterg
## Added some more txt view reps: input, lbl, numpar, state
##
## Revision 1.138  1998/03/07 15:23:40  peterg
## Uses sort_sympar to uniquely produce the sympar list.
##
## Revision 1.137  1998/03/07 14:04:17  peterg
## dae creation split into 2 parts:
## 1. create a raw (ie without constitutive relationship) dae (rdae)
## 2. add the raw dae to the crs to get the dae.
## reduce has less work to do with this approach
##
## Revision 1.136  1998/03/04 16:34:19  peterg
## New local (_cr.r) and generic (.cr) CR structure.
## CR and lbl now have view mode.
## CRS in abg_tex.
##
## Revision 1.135  1998/02/25 22:09:48  peterg
## Added simpar representation.
##
## Revision 1.134  1998/02/25 15:28:34  peterg
## Added state.m rep.
##
## Revision 1.133  1998/02/24 22:35:33  peterg
## Added -p (preserve) switch to cp in tidy mode.
##
## Revision 1.132  1998/02/24 22:33:23  peterg
## new state reresentation included
##
## Revision 1.131  1998/02/23 16:21:21  peterg
## Just do model name in summary line of lbl file
##
## Revision 1.130  1998/02/19 13:40:24  peterg
## Removed prerequisit from sspar.r target.
##
## Revision 1.129  1998/02/12 08:18:42  peterg
## VERSION 2.8 (St. Annes)
##
## Revision 1.128  1998/02/12 07:48:04  peterg
## Tidy mode copies all files (containing .) to work dir -- this makes
## sure that files such a .c .constitutive relationship go across.
##
## Revision 1.127  1998/02/11 19:36:29  peterg
## Only displays one level of cbg file now.
##
## Revision 1.126  1998/02/11 19:26:03  peterg
## Added verbose (-v) mode.
##
## Revision 1.125  1998/02/11 11:36:28  peterg
## Updated version control mode - make it untidy.
## cp --> cp -u after tidy-mode .
##
## Revision 1.124  1998/02/10 13:03:36  peterg
## Now includes controller transfer function (ctf).
##
## Revision 1.123  1998/02/09 13:51:04  peterg
## Fixed directory string bug.
##
## Revision 1.122  1998/02/06 15:02:26  peterg
## New default sspar -- sets all states to zero.
##
## Revision 1.121  1998/02/06 14:36:51  peterg
## Report on copying back from MTT_work
##
## Revision 1.120  1998/02/05 16:06:53  peterg
## Removed debugging lines.
## Auto parts in books.
##
## Revision 1.119  1998/02/05 15:04:25  peterg
## Fixed problem with book in tidy mode.
##
## Revision 1.118  1998/02/05 12:00:11  peterg
## Tidy mode now default.
## It seems to work ok but not for book type documents.
##
## Revision 1.117  1998/02/04 16:50:50  peterg
## Introduced the tidy (-t and -T) options
##
## Revision 1.116  1998/02/04 11:00:04  peterg
## Added view of subsystems.
##
## Revision 1.115  1998/01/29 19:37:31  peterg
## Fixed spurious call to X server bug
##
## Revision 1.114  1998/01/23 13:38:07  peterg
## VERSION 2.7
##
## Revision 1.113  1998/01/23 13:27:13  peterg
## Added state-feedback control representations:
## smc,smo,ssk,ssl
##
## Revision 1.112  1998/01/21 09:24:46  peterg
## Removed 'touch $1_rep.txt' -- perhaps best to do this by hand if
## necessary. As it is, it cuased probs wene reediting the _rep.txt file.
##
## Revision 1.111  1998/01/16 14:56:59  peterg
## Argument now correctely recognised as a string beginning with -
## (rather than containing -)
##
# Revision 1.110  1998/01/06  13:59:30  peterg
# Added rename function.
#
# Revision 1.109  1998/01/06  09:20:02  peterg
# Made LATEX2HTML an environment variable.
#
# Revision 1.108  1997/12/19  08:48:55  peterg
# Lille modifications - bicausal algebraic loops supported
#
## Revision 1.107  1997/12/11 10:59:50  peterg
## This is version 2.6
##
# Revision 1.106  1997/12/11  10:59:07  peterg
# Added debug -D switch + echos directory when -d switch used.
#
# Revision 1.105  1997/12/11  09:04:47  peterg
# Reduced default rep.txt file to just abg.txt -- this is to document
# components which may not be causally complete
#
# Revision 1.104  1997/12/07  21:05:10  peterg
# Removed a debbugging echo
#
## Revision 1.103  1997/12/07 20:10:36  peterg
## Fixed bugs with reprots and distinguish between book, article and
## section reports.
##
## Revision 1.102  1997/12/07 12:14:43  peterg
## Hnadles book, article and section reports seperately
##
## Revision 1.101  1997/12/06 18:54:53  peterg
## Now tidies up after itself.
## Major modifications to do a rep on a directory -- creates a book with
## each example as a chapter.
##
## Revision 1.100  1997/12/06 12:14:39  peterg
## Put a conditional around the PS data rep to check for set arguments.
##
## Revision 1.99  1997/12/04 22:06:53  peterg
## Added view arguments for graph plotting
##
## Revision 1.98  1997/12/04 10:58:15  peterg
## Tidied up switches
##
## Revision 1.97  1997/12/04 10:44:33  peterg
## Changed $cc to $CC
##
## Revision 1.96  1997/12/04 10:40:26  peterg
## Added -p switch - print enviromment variables
##
## Revision 1.95  1997/12/04 10:05:02  peterg
## Compiler now symbolocic $cc
##
# Revision 1.94  1997/11/20  11:23:16  peterg
# Changed gcc to cc
#
## Revision 1.93  1997/09/18 16:57:28  peterg
## _sympar.txt now has a second column - the system type from whence the
## parameter (in the first column) came.
## Done on the train Glasgow-Warrington !
##
## Revision 1.92  1997/09/11 17:08:46  peterg
## Added spreadsheet version of odeso
##
## Revision 1.91  1997/09/11 08:21:08  peterg
## copy utility split into two:
## copy: copies examples (copies the entire directory)
## compcopy: (just used internally) copies components.
##
## Revision 1.90  1997/08/30 19:35:39  peterg
## Added date to mtt line
##
## Revision 1.89  1997/08/26 15:20:25  peterg
## Added explicit evaluation of report representations
## Version now 2.5++
##
## Revision 1.88  1997/08/25 07:51:47  peterg
## Version 2.5.
##
## Revision 1.87  1997/07/27 13:11:11  peterg
## Added path checking code -- mtt_check_vars
##
# Revision 1.86  1997/06/29  19:05:51  peterg
# Seascale changes -- mainly to new rep format.
#
## Revision 1.85  1997/06/27 12:14:49  peterg
## Upped version to 2.4++
##
# Revision 1.84  1997/06/13  14:08:23  peterg
# Changed default rep.txt
#
# Revision 1.83  1997/06/13  09:18:28  peterg
# Removed all params.m
#
# Revision 1.82  1997/06/13  08:59:03  peterg
# Set to version 2.4
#
## Revision 1.81  1997/05/22 10:11:04  peterg
## Fixed dat2gdat bug (with parameters)
##
## Revision 1.80  1997/05/22 07:38:27  peterg
## Added command line info to .doc files (makedoc)
##
## Revision 1.79  1997/05/19 16:44:12  peterg
## Many changes to get rep.html mode working properly.
##
# Revision 1.78  1997/05/19  13:17:50  peterg
# Explicit inclusion of mtt.sty in .doc files -- latex2html prefers this
#
# Revision 1.77  1997/05/19  11:29:37  peterg
# Added desc.tex and abg.tex descriptions.
#
# Revision 1.76  1997/05/15  09:43:46  peterg
# New version of _input.txt for -s option
#
# Revision 1.75  1997/05/15  09:15:54  peterg
# Included switch.c in dependancy list for _input.c (when -s switch set)
#
# Revision 1.74  1997/05/13  16:58:02  peterg
# Added -s switch to get mtt to search for (Bond Graph) switches
#
## Revision 1.73  1997/05/09 09:18:45  peterg
## Put ./ in front of a.out (again)
##
# Revision 1.72  1997/05/06  13:54:21  peterg
# Changed gcc arguments for the ode simulation -- all files now included
# in the _odes.c file
#
# Revision 1.71  1997/05/03  15:50:18  peterg
# c functions not included in gcc arg list -- they are now included in
# the main prog.
#
# Revision 1.70  1997/05/03  14:17:13  peterg
# Now copies c utilities (eg dsvdcmp.c) from $MTTPATH/trans/c.
#
# Revision 1.69  1997/05/03  13:58:35  peterg
# Implicit integration for sm representation added.
#
# Revision 1.68  1997/05/01  08:39:20  peterg
# params.c and params.m not used any more.
# _numpar.txt is the common base from which _numpar.c and numpar.m is
# generated.
#
# Revision 1.67  1997/04/23  07:26:49  peterg
# Added -o switch -- ode and dae are the same
# Added switches to default menu
#
# Revision 1.66  1997/04/16  09:46:01  peterg
# More informative copy message
#
# Revision 1.65  1997/04/15  15:16:12  peterg
# Added structure (_struc) files.
# Fixed prob with dvi2ps conversion -- removed .doc extension.
#
# Revision 1.64  1997/04/09  09:26:44  peterg
# Added crcopy feature to pull crs from library -- similar to copy
# feature.
#
# Revision 1.63  1997/03/22  17:09:11  peterg
# Fixed bug in recursive cr.txt generation.
# Fixed bug in recursive sympar.txt generation.
#
# Revision 1.62  1997/03/20  17:48:50  peterg
# Better _input.c file default.
#
# Revision 1.61  1997/03/20  16:53:01  peterg
# Generates c files using include statements.
#
# Revision 1.60  1997/03/20  10:25:41  peterg
# Generates a compehensive default params file.
#
# Revision 1.59  1997/03/19  10:14:04  peterg
# Now produces a stripped acausal bond graph.
#
# Revision 1.58  1997/03/18  17:58:12  peterg
# Generates label files containing all variables in fig file.
# Generates sympar file for all levels in system.
# Generates txt version of sympar file.
#
# Revision 1.57  1997/03/10  09:24:58  peterg
# a.out now deleted in the clean operation
#
# Revision 1.56  1997/03/05  08:24:09  peterg
# Delete a.out after it has run.
#
# Revision 1.55  1997/02/24  19:31:10  peterg
# Removed numpar.m requirement from .m files
#
## Revision 1.54  1997/02/09 20:33:13  peterg
## Replaced a.out with ./a.out
##
## Revision 1.53  1997/02/09 20:30:04  peterg
## Copied from tweedledum.
##
# Revision 1.54  1997/02/07  13:33:03  peterg
# Added ; to _input.c file - bug fix.
#
# Revision 1.53  1997/02/07  13:25:04  peterg
# Version 2.3
#
# Revision 1.52  1997/01/21  22:55:59  peterg
# Minor bug fixes
#
## Revision 1.51  1997/01/21 13:16:40  peterg
## Included transformations to language c for:
## ode
## params
## numpar
##
## Revision 1.50  1996/12/21 19:46:52  peterg
## Set to 2.2++
## Changed \* --> \\* in rbg_fig2m.awk
##
## Revision 1.49  1996/12/19 19:55:22  peterg
## Version 2.2 -- Linux.
##
## Revision 1.48  1996/12/07 21:33:52  peterg
## Changed _input file to give unit step on ALL inputs
##
## Revision 1.47  1996/12/07 20:50:16  peterg
## *** empty log message ***
##
## Revision 1.46  1996/12/05 10:48:51  peterg
## Put sympar in clean list.
## sympar now sucks in params.r file
##
## Revision 1.45  1996/12/05 10:41:39  peterg
## Saved many changes over past 2 weeks.
##
# Revision 1.44  1996/11/12  16:04:25  peterg
# Really VERSION 2.1
#
# Revision 1.43  1996/11/12  08:52:57  peterg
# Fixed bug in test arg to if - missing "".
#
# Revision 1.42  1996/11/11  17:23:03  peterg
# Added numpar.m requirement to all .m targets
#
## Revision 1.41  1996/11/11 17:18:32  peterg
## VERSION 2.1
##
## Revision 1.40  1996/11/09 21:17:38  peterg
## Fixed bug with copying at level 0.
##
## Revision 1.39  1996/11/09 20:22:54  peterg
## VERSION 2.0
##
## Revision 1.38  1996/11/09 20:17:34  peterg
## Fixed bug with null ARGS argument
## Put in new lib paths.
##
## Revision 1.37  1996/11/09 18:47:46  peterg
## Added new copy command (using find).
## More documaentation stuff.
##
# Revision 1.36  1996/11/03  21:19:02  peterg
# Recursice generation of Constitutive Relationship files.
#
## Revision 1.35  1996/11/02 10:19:19  peterg
## Constitutive Relationship generation from lbl file
##
## Revision 1.34  1996/11/01 13:34:35  peterg
## -q (quiet) switch added
##
## Revision 1.33  1996/11/01 12:34:45  peterg
## Added browser - mtt_help
##
## Revision 1.32  1996/10/31 20:48:41  peterg
## Revised html generation.
## Stopped deletion of rep.txt file.
##
# Revision 1.31  1996/10/20  19:23:54  peterg
# Automatic generation of sub-system abg.m files.
#
## Revision 1.30  1996/10/01 14:08:05  peterg
## Replaced $() by ``
## Replaced make with gmake
##
# Revision 1.29  1996/10/01  11:04:05  peter
# Changed name of html document.
#
## Revision 1.28  1996/09/13 18:44:11  peter
## Added params dependencies.
##
## Revision 1.27  1996/09/12 19:24:56  peter
## New numpar/params setup.
##
## Revision 1.26  1996/09/10 17:04:47  peter
## Added impulse response (ir) representation.
##
## Revision 1.25  1996/08/30 20:03:45  peter
## Removed dependencies from vc
##
## Revision 1.24  1996/08/30 18:37:17  peter
## inor changes.
##
## Revision 1.23  1996/08/30 11:10:37  peter
## More files in clean up.
##
## Revision 1.22  1996/08/30 10:07:51  peter
## Removed impicit creation of abg.fig file.
##
## Revision 1.21  1996/08/22 12:19:51  peter
## Added various document viewers.
##
## Revision 1.20  1996/08/20 08:24:53  peter
## Now with version control.
##
## Revision 1.19  1996/08/19 15:33:22  peter
## Included new state matric (sm) rep.
## Generate step response (sr) from sm.
##
## Revision 1.18  1996/08/19 13:30:54  peter
## New CLEAN target.
##
## Revision 1.17  1996/08/19 06:48:14  peter
## Explicit figure editing.
##
## Revision 1.16  1996/08/18 19:58:36  peter
## Report generation included.
##
## Revision 1.15  1996/08/18 12:01:01  peter
## Unified format of time responses.
##
## Revision 1.14  1996/08/16 14:52:24  peter
## Added two alternative view options - dview and pview.
##
## Revision 1.13  1996/08/16 08:24:31  peter
## Correctly chooses how to make a ps file using $REPTYPE.
##
## Revision 1.12  1996/08/15 16:47:47  peter
## DAE solution (experimental) included.
##
## Revision 1.11  1996/08/15 11:55:30  peter
## Checks for changed argument.
## Handles frequency response.
##
## Revision 1.10  1996/08/15 07:44:24  peter
## Now handles generic transformations using %.
##
## Revision 1.9  1996/08/14 09:16:08  peter
## Step response now goes through  m, dat and gdat conversions
##
## Revision 1.8  1996/08/12 20:19:52  peter
## Arguments now passed via $1_args.m file
##
## Revision 1.7  1996/08/11 19:49:27  peter
## Parameter passing (via $4) added.
##
## Revision 1.6  1996/08/11 10:40:56  peter
## Added new numpar stuff.
## Added step response.
##
## Revision 1.5  1996/08/10 14:13:47  peter
## Added impulse and frequency response stuff.
##
## Revision 1.4  1996/08/10 09:19:48  peter
## Put in help, info and warranty stuff.
##
## Revision 1.3  1996/08/09 15:13:13  peter
## Generic viewing of any representation via ps files implemented.
##
## Revision 1.2  1996/08/05 19:50:55  peter
## Put in fig.fig target.
##
## Revision 1.1  1996/08/04 17:29:42  peter
## Initial revision
##
###############################################################

set_oct() {
## Sets ${m} to oct if such a rep is supported
    m=m
    supported_reps="ae input logic numpar simpar state"
    for supported_rep in ${supported_reps}; do
	if [ "${rep}" = "${supported_rep}" ]; then
          m=oct	    
	fi
    done
}

#Check $MTTPATH has been set
mtt_check_var "$MTTPATH" "MTTPATH"

#Version
version='5.0'

# MTT recursion level is zero unless explicitly set
level=0

#Computation mode is octave by default
computation=octave

#By default, Reduce is used if available
if [ -n "$SYMBOLIC" ]; then
    use_reduce='yes'
else
    use_reduce='no'
fi

#By default, the dae and ode representations are different
dae_is_ode=0

#By default, the ode and cse reps are different
ode_is_cse=0

# By default, don't look for BG switches
switches=0

#By default, don't print the environment variables
print='';

# By default, make it tidy
tidy=tidy;

# Default not verbose
verbose=' -s'
verbosity=0

# Default integration method
integration_method=implicit;

# Default algebraic equation solver
algebraic_solver=noAlgebraicSolver;

# Default no info
info_switch=''

# Default use m, not oct files
m='m';

# Default use ps files
ps=ps
eps=eps
psview=$PSVIEW

# Default declare 500 temporary variables
num_tmp_var=500

# Default no equation sorting
do_sort=''
sort_method=''

#Initialise list of switches
mtt_switches='';

#Initialise read dirs
read_dirs=''

#Look for a command line argument
while [ -n "`echo $1 | grep '^-'`" ]; do
  case $1 in
	-q )
                mtt_switches="$mtt_switches $1";
		quiet=quiet;;  
	-r )
                mtt_switches="$mtt_switches $1";
		reset=reset;;  

	-p )
                mtt_switches="$mtt_switches $1";
		print='-p';;
	-c )
	        echo "-c is obsolete. Please use -cc instead"
                fixcc='-fixcc'
                mtt_switches="$mtt_switches $1";
                matrix_smxa="-matrix";
		computation=c ;;
	-cc )
                fixcc='-fixcc'
                mtt_switches="$mtt_switches $1";
                matrix_smxa="-matrix";
		computation=cc ;;
	-cr )
                mtt_switches="$mtt_switches $1";
		rdae_is_dae=1 ;
                cr_first='-cr';;
	-o )
                mtt_switches="$mtt_switches $1";
		dae_is_ode=1 ;;
	-nocr )
                mtt_switches="$mtt_switches $1";
		rdae_is_dae=1 ;;
	-no-reduce )
                mtt_switches="$mtt_switches $1";
                use_reduce='no';
                do_sort='-sort';
                sort_method='make';
                rdae_is_dae=1 ;
                cr_first='-cr';
                Solve='';
                num_tmp_var=0 ;
                integration_method="euler" ;;
	-i )
                mtt_switches="$mtt_switches $1";
                shift;
                case $1 in
		    dassl)
			integration_method=dassl;
			mtt_switches="$mtt_switches dassl";
			;;
		    euler)
			integration_method=euler;
                        mtt_switches="$mtt_switches euler";
			;;
		    implicit)
			integration_method=implicit;
                        mtt_switches="$mtt_switches implicit";
			;;
		    rk4)
			integration_method=rk4;
			mtt_switches="$mtt_switches rk4";
			;;
		    *)
			echo $1 is an unknown integration method - use dassl, euler, rk4 or implicit;
                        exit;;
		esac;;
	-ae )
                mtt_switches="$mtt_switches $1";
		case $2 in
		    dassl)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=Dassl_Solver;
			shift;
			;;
		    fsolve | hybrd)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=Hybrd_Solver;
			shift;
			;;
		    hooke)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=HJ_Solver;
			shift;
			;;
		    reduce)
			mtt_switches="$mtt_switches $2";
			algebraic_solver=Reduce_Solver;			
			Solve='-A';
			shift;
			;;
		    *)
			echo $1 is an unknown solver - use hybrd, hooke or reduce;
			exit;;
	        esac;;
	-s )
                sensitivity_switch='-s';
                mtt_switches="$mtt_switches $1";
		sensitivity=sensitivity ;;
	-make-sort )
		mtt_switches="$mtt_switches $1";
		do_sort='-sort';
		sort_method="make";
		num_tmp_var=0 ;;
	-sort )
                mtt_switches="$mtt_switches $1";
		do_sort='-sort';
		sort_method="seqn";
		integration_method="sorted_euler";;
	-ss )
                mtt_switches="$mtt_switches $1";
		steadystate_computation=yes ;;
	-d )
		directory=$2; cd $directory; shift ;;
	-dc )
		mtt_switches="$mtt_switches $1";
		causality_switch='-derivative' ;;
	-S )
		directory=$2;  shift;;
	-D )
                mtt_switches="$mtt_switches $1";
		debug=debug ;;
	-v )
                mtt_switches="$mtt_switches $1";
		info_switch='-I';
                Verbose='verbose';
		verbosity=`expr $verbosity + 1`;
		if [ $verbosity -ge 1 ]; then verbose=' -w '; fi;
		if [ $verbosity -ge 2 ]; then set -x; fi;
		if [ $verbosity -ge 3 ]; then verbose_make=' -d '; fi;
		;;
	-I )
                mtt_switches="$mtt_switches $1";
		info_switch='-I' ;;
	-t )
		tidy=tidy ;;
	-trace )
                mtt_switches="$mtt_switches $1";
		trace='-n' ;;
	-T )
		tidy=tidy;
                verytidy=verytidy ;;
	-u )
		tidy=untidy ;
                mtt_switches="$mtt_switches $1";
                ;;
	-l )
                mtt_switches="$mtt_switches $1 $2";
		level=$2; shift ;;
	-A )
                mtt_switches="$mtt_switches $1";
                Solve='-A';;
	-abg )
                mtt_switches="$mtt_switches $1";
                start_at_abg='yes';;
	-stdin )
                mtt_switches="$mtt_switches $1";
                stdin=stdin;;
	-sub )  mtt_switches="$mtt_switches $1 $2";
                sub='-sub'; 
                subsystem="_"$2;
                shift;;
	-oct )
                fixcc='-fixcc'
                mtt_switches="$mtt_switches $1";
                using_oct=yes;
                ;;
	-opt | -optl )
		mtt_switches="$mtt_switches $1";
                optimise='-optimise_local';;
	-optg )
		mtt_switches="$mtt_switches $1";
                optimise='-optimise_global';;
        -ntmpvar )
		num_tmp_var=$2;
		mtt_switches="$mtt_switches $1 $2";
		shift;;
	-partition ) mtt_switches="$mtt_switches $1";
                     partition='-partition';
                ;;
	-pdf )   mtt_switches="$mtt_switches $1";
                 ## ps=pdf; 
                 ## eps=pdf;
                 ## pdf='-pdf';
                 psview=$PDFVIEW;
                ;;
	-dr )   mtt_switches="$mtt_switches $1"; shift
                mtt_switches="$mtt_switches $1"; read_dir=$1
	        if [ -d "${read_dir}" ]; then
		    read_dirs="${read_dirs} ${read_dir}"
		else
		    echo "${read_dir} does not exist - ignoring"
		fi
                ;;
	-nas )  no_alpha_sort="no_alpha_sort";
                mtt_switches="$mtt_switches $1";
                ;;
	-viewlevel )  mtt_switches="$mtt_switches $1 $2";
                      viewlevel=$2;
                      shift;;
        --version)                
                  echo 'MTT version' $version; exit;;
        --versions)                
                mtt_versions; exit;;
	*)
		echo "$1 is an invalid argument - ignoring" ;;
  esac
  shift
done

## Create switches string for adding to file names.
  MTT_SWITCHES=`echo ${mtt_switches} | sed 's/ //g' | sed 's/^-u-q//'`

#Print header if not in quiet (-q) mode.
if [ "$quiet" != "quiet" ]; then
  echo
  echo 'MTT (Model Transformation Tools) version' $version
  echo '($Date$)'
  echo 'This is free software with ABSOLUTELY NO WARRANTY.'
  echo 'Type `mtt warranty'\' 'for details.'
  echo
  # Print current directory if in -d mode
  if [ -n "$directory" ]; then
    echo Using directory $directory
    echo
  fi
fi

#Print what's going on if in verbose mode
if [ -n "$Verbose" ]; then
    echo  Starting  mtt  $mtt_switches  $1 $2 $3 $4 at level $level 
    echo  "        " current wd `pwd`
fi

#Check the principle paths
mtt_check_vars $print

# Exit if just printing paths
if [ "$print" != "" ]; then
  exit
fi

if [ -z "$1" ]; then
  if [ -z "$print" ]; then
      cat <<EOF
Usage:
	mtt help		-- mtt on-line help
	mtt find component	-- find location of a compound component
	mtt info		-- info-based manual
	mtt info topic
	mtt hinfo		-- hypertext manual
	mtt manual		-- pdf manual
	mtt warranty
	mtt clean		-- cleans up intermediate files
	mtt rclean		-- recursively cleans up intermediate files
	mtt Clean		-- cleans up all generated files
	mtt <system_name> clean
	mtt copy <system_name> <path_name>
	mtt rename <old_name> <new_name>
	mtt <system_name> <representation> vc 
	mtt <system_name> <representation> <language>
	mtt <system_name> <representation> <language> <parameters>

Options:
	-A		solve algebraic equations symbolically
	-abg		start at abg.m representation
	-ae <method>	algebraic equation solver: reduce|hybrd|dassl|hooke
	-cc		C++ code generation
	-cr		use cr before resolving equations
	-D		debug -- leave log files etc
	-d <dir>	use directory <dir>
	-dc		maximise derivative (not integral) causality
	-dr <dir>	use files contained in <dir>
	-I		prints more information
	-i <method>	integration method: implicit|euler|rk4|dassl
        -nas            no alphabetic sort (of components)
	-o		ode is same as dae
	-oct		use oct files in place of m files where appropriate
	-opt		optimise code generation (equivalent to -optl)
	-optl		locally optimise code generation (line-by-line)
	-ntmpvar <N>	declare <N> temporary variables (default=$num_tmp_var)
	-p		print environment variables
	-partition	partition hierachical system
	-pdf		generate pdf in place of ps
	-q		quiet mode -- suppress MTT banner
	-r		reset time stamp on representation
	-s		generate sensitivity BG (use mtt -s sSys rep lang)
	-ss		use steady-state info to initialise simulations
	-stdin		read input data from standard input for  simulations
	-sub <subsys>	operate on subsystem <subsys>
	-t		tidy mode (default)
	-trace		just indicate what mtt will do - but do not do it
	-u		untidy mode (leaves files in current dir)
	-v		verbose mode (multiple uses increment the verbosity)
	--version	print version and exit
	--versions	print version of mtt and components and exit
	-viewlevel <N>	view <N> levels of hierachy

Experimental options:
	-optg		globally optimise code generation (full vector)
	-make-sort	use sorted equations (sese, generated by make)
	-no-reduce	try not to use symbolic algebra
	-sort		use sorted equations (sese, generated by seqn)

Deprecated options:
	-c		c-code generation

EOF
    exit
  fi
fi


if [ "$1" = "info" ]  && [ "$3" = "" ]; then
  (cd $MTT_DOC ; make --silent mtt.info)
  echo "Invoking info in xterm"
  xterm -e info -f $MTT_DOC/mtt.info $2
  exit
fi

if [ "$1" = "help" ]; then
  mtt_help $2 $3
  exit
fi

if [ "$1" = "hinfo" ] && [$2 = ""]; then
   mtt_check_var "$HTMLVIEW" HTMLVIEW
  (cd $MTT_DOC/; make --silent mtt.html) 
   echo Invoking $HTMLVIEW
   (cd $MTT_DOC; $HTMLVIEW file://$MTT_DOC/mtt.html)&
   exit
fi

if [ "$1" = "manual" ] && [$2 = ""]; then
  mtt_check_var "$PDFVIEW" PDFVIEW
  (cd $MTT_DOC/; make --silent mtt.pdf) 
  echo Invoking $PDFVIEW 
  $PDFVIEW  $MTT_DOC/mtt.pdf &
  exit
fi

if [ $1 = "find" ]&& [$3 = ""]; then
    mtt_find $MTT_COMPONENTS $2
    find_status=$?
  if [ $find_status = "1" ]; then
    echo Component $2 not found - is MTT_COMPONENTS set correctly?
  fi
    exit $find_status
fi

if [ "$1" = "warranty" ] && [$2 = ""]; then
  cat << EOF
Copyright (C) 1989, 1990, 1991, 1992, 1993, 
              1994, 1995, 1996, 1997, 1998, 1999 Peter J. Gawthrop
This is free software with ABSOLUTELY NO WARRANTY.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

EOF
  exit
fi

# Start at abg representation
if [ -n "$start_at_abg" ]; then
  if [ -f "$1_abg.m" ]; then
    if [ "$quiet" != "quiet" ]; then
        echo Starting from $1_abg.m
    fi
  else
    echo $1_abg.m does not exist
    exit
  fi
fi

# Clean up 
if [ "$1" = "clean" ]; then
  echo Removing intermediate files in `pwd`
  rm -fr MTT_work
  exit
fi

# Recursively clean up
if [ "$1" = "rclean" ]; then
  echo 'Removing intermediate files recursively'
  dir2paths '.' | gawk '{print "mtt -q -d " $1 " clean " $2}' | sh
  exit
fi

# The big clean up
if [ "$1" = "Clean" ] && [ "$2" = "" ]; then
  echo 'Removing all generated files for all systems'
  rm -f *.log  mtt_info.txt warning.txt
  rm -f *_abg.ps *_args.*  *_cr.txt *_abg.tex
  rm -f *_sabg.fig *_sabg.ps *_head.fig *_bnd.fig 
  rm -f *_labg.fig *_lcbg.fig
  rm -f *_sympar.r *_sympar.c *_sympar.h *_sympar.txt? *_sympar.tex
  rm -f *_rbg.* *_cmp.* *_fig.fig *_*cbg.* *_ese.* *_def.* *_alias.*
  rm -f *_sub.* *_type.sh
  rm -f *_dae*.* *_cse.* *_ode.*
  rm -f *_obs.* *_rfe.* *_ss.*
  rm -f *_dm.* *_csm.*  *_tf.* *_sr*.* *_ir*.* *_*fr.*
  rm -f *_numpar.c *_input.m *_input.c *_switch.c *_switch.txt
  rm -f *_sm.* *_can.*
  rm -f *_struc.* *_sympar.txt *_sympar.c *_sympar.h *_sympar.m
  rm -f *_odes.c *_odes.dat *_odes.gdat *_odes.m *_odes.ps *_odes.sg
  rm -f *_odeso.dat *_odeso.gdat *_odeso.sdat *_odeso.m *_odeso.ps
  rm -f *_*.doc *_*.idx *_*.ind *_*.ilg *_*.dvi *_*.aux *_*.lof *_*.toc
  rm -f *_rep.tex
  rm -f  *_unique_raw_list *_raw_list
  rm -f mtt_error.txt mtt_info.txt *_ode2odes.out 
  rm -f *_*_write.r *_simpar.m *_simpar.p
  rm -f *_cseo.oct *_input.oct *_simpar.oct *_smxax.oct
  rm -f *_csex.oct *_numpar.oct *_smxa.oct *_state.oct 
  rm -f *_ode.oct *_odeo.oct
  rm -f *_cseo.mexglx *_input.mexglx *_simpar.mexglx *_smxax.mexglx
  rm -f *_csex.mexglx *_numpar.mexglx *_smxa.mexglx *_state.mexglx 
  rm -f *_ode.mexglx *_odeo.mexglx
  rm -f *_sfun.mexglx *_sfun_*.mexglx
  rm -f *_cseo.cc *_input.cc *_simpar.cc *_smxax.cc
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
  rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m
  rm -f *_ae.r *_ae.m *_ae.cc *_ae.oct
  rm -f *_sese.r *_sese.m
  rm -f *_sese.make *_sesx.* *_sesy.* _sae.*
  rm -fR *_rep MTT_work
  exit
fi

# Clean up named system
if [ "$2" = "Clean" ] && [ "$3" = "" ]; then
  echo 'Removing all generated files for system ' $1
  rm -f *.log  mtt_info.txt warning.txt
  rm -f $1_abg.ps $1_args.*  $1_cr.txt $1_abg.tex
  rm -f $1_sabg.fig $1_sabg.ps $1_head.fig $1_bnd.fig 
  rm -f $1_labg.fig $1_lcbg.fig
  rm -f $1_sympar.r $1_sympar.c $1_sympar.h $1_sympar.txt? $1_sympar.tex
  rm -f $1_rbg.* $1_cmp.* $1_fig.fig $1*_*cbg.* $1*_ese.* $1_def.* $1_alias.*
  rm -f $1_sub.* $1_type.sh
  rm -f $1_dae*.* $1_cse.* $1_ode.*  $1_obs.* $1_rfe.* $1_ss.*
  rm -f $1_dm.* $1_csm.* $1_tf.* $1_sr*.* $1_ir*.* $1_*fr.*
  rm -f  $1_numpar.m $1_numpar.c $1_input.m $1_input.c $1_switch.c $1_switch.txt
  rm -f $1_sm*.* $1_can.*
  rm -f $1_struc.* $1_sympar.txt $1_sympar.c $1_sympar.h $1_sympar.m
  rm -f $1_odes.c $1_odes.dat $1_odes.gdat $1_odes.sdat $1_odes.m $1_odes.ps $1_odes.sg
  rm -f $1_odeso.dat $1_odeso.gdat $1_odeso.m $1_odeso.ps
  rm -f $1_*.doc $1_*.idx $1_*.ind $1_*.ilg $1_*.dvi $1_*.aux $1_*.lof $1_*.toc
  rm -f $1_rep.tex
  rm -f $1_unique_raw_list $1_raw_list
  rm -f mtt_error.txt mtt_info.txt $1_ode2odes.out 
  rm -f $1_*_write.r $1_simpar.m $1_simpar.p
  rm -f $1_cseo.oct $1_input.oct $1_simpar.oct $1_smxax.oct
  rm -f $1_csex.oct $1_numpar.oct $1_smxa.oct $1_state.oct 
  rm -f $1_ode.oct $1_odeo.oct
  rm -f $1_cseo.mexglx $1_input.mexglx $1_simpar.mexglx $1_smxax.mexglx
  rm -f $1_csex.mexglx $1_numpar.mexglx $1_smxa.mexglx $1_state.mexglx 
  rm -f $1_ode.mexglx $1_odeo.mexglx
  rm -f $1_sfun.mexglx $1_sfun_*.mexglx
  rm -f $1_cseo.cc $1_input.cc $1_simpar.cc $1_smxax.cc
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r
  rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m
  rm -f $1_ae.r $1_ae.m $1_ae.cc $1_ae.oct
  rm -f $1_sese.r $1_sese.m
  rm -f $1_sese.make $1_sesx.* $1_sesy.* $1_sae.*
  rm -fR $1_rep MTT_work
  exit
fi

if [ "$2" = "rep" ]; then
     documenttype=article
      # See if we are making a book -- ie representation rep on a directory
     isMTT_work=`pwd | grep 'MTT_work'`
      if [ -n "$isMTT_work" ]; then
	dotdot='../'
      fi  

     #isdirectory=`file $dotdot$1 | gawk '{print $2}' | grep directory`
     if [ -d "$dotdot$1" ]; then
	documenttype=book
     fi
else
     documenttype=section
fi

case $2 in
    nyfr)
	NyquistStyle='True'
	;;
    nifr)
	NyquistStyle='True'
	;;
    *)
esac

#SUMMARY abg*	acausal bond graph (fig)
#SUMMARY abg*	acausal bond graph (dia)
#SUMMARY abg*	acausal bond graph (ps)
#SUMMARY abg*	acausal bond graph (view)
# Invoke explicit requests for modification
if [ "$2" = "abg" ] && [ "$3" = "fig" ]; then
  mtt_check_var "$FIG" FIG
  echo Editing $1_$2.$3
  ($FIG $1_$2.$3; cp $1_abg.fig $1_$1_abg.fig) &
  exit
fi

# Rename a system
if [ "$1" = "rename" ]; then
  mtt_rename_all $2 $3
  exit
fi

# Copy systems from the example library
if [ "$1" = "copy" ]; then
   #set up source and destination dirs
    source=$3
    if [ -z "$source" ]; then
      source=$MTT_EXAMPLES
    fi
    destination=$4
    if [ -z "${destination}" ]; then
      destination=$2
    fi      
# check that its not here already
  file_exists=`ls ${destination}/$2_abg.fig 2> /dev/null`
  if [ -n "$file_exists" ]; then
    if [ "$quiet" != "quiet" ]; then    
      echo System $2 exists already - no action taken
    fi
  else
    source=$3
    if [ -z "$source" ]; then
      source=$MTT_EXAMPLES
    fi
    destination=$4
    if [ -z "${destination}" ]; then
      destination=$2
    fi    
echo Copying system $2 from $source into directory ${destination}
    find $source -name "$2" -exec cp -fr {} . \;
    rm -rf ${destination}/CVS
  fi
  exit
fi

# Copy components from the library
if [ "$1" = "compcopy" ]; then

   #Pull out the base name (we may have a library as well)
   name=`basename $2`

   #set up source and destination dirs
    source=$3
    if [ -z "$source" ]; then
      source=$MTT_COMPONENTS
    fi
    destination=$4
    if [ -z "${destination}" ]; then
      destination='.'
    fi   

  # check that its not here already
  file_exists=`ls ${destination}/"$name"_abg.fig 2> /dev/null`
  if [ -n "$file_exists" ]; then
    if [ "$quiet" != "quiet" ]; then    
      echo Component $name exists already - no action taken
    fi
  else
    if [ $source = "." ]; then
      cp -u *_*.* ${destination}
    else
      comp_path=`mtt_find $source $2 path_only`
      n_found=`echo $comp_path | wc | gawk '{print $2}'`

      if [ "$n_found" = "1" ]; then
         echo Copying $2 from $comp_path to ${destination}
         cp $comp_path/*_*.* ${destination}
         exit 0
      elif [ "$n_found" = "0" ]; then
	if [ "$quiet" != "quiet" ]; then    
           echo Component $2 not found - is MTT_COMPONENTS set correctly?
        fi
         exit 1
      elif [ "$n_found" > "1" ]; then
         echo "Multiple versions of $2 found (see below) - use a more explicit alias"
         mtt -q find $2
         exit 2
      fi
    fi
  fi
  exit
fi

# Copy CRs from the library
if [ "$1" = "crcopy" ]; then
  # check that its not here already (or a _cr.r version)
  file_exists=`ls $2.cr $2_cr.r 2> /dev/null`
  if [ -n "$file_exists" ]; then
    if [ "$quiet" != "quiet" ]; then    
      echo $2.cr or $2_cr.r exists already - no action taken
    fi
  else
    path_name=$3
    if [ -z "$path_name" ]; then
	path_name=""
	for path in `echo $MTT_CRS | sed 's/:/ /g'`; do
	    path_name="$path_name $path/r"
	done
    fi
    echo Copying CR $2 to here from $3
    find $path_name -name "$2.cr" -exec cp {} . \;
  fi
  exit
fi


# Version control
VC=''

if [ "$3" = "vc" ]; then
  tidy=untidy;
  if [ -n "$4" ]; then
    log_message=$4
  else
    log_message="No Message"
  fi
  case $2 in
	abg )
		VC='ok'
		VCext='fig' ;;
	lbl )
		VC='ok'
		VCext='txt' ;;
	desc )
		VC='ok'
		VCext='tex' ;;
	simp )
		VC='ok'
		VCext='r' ;;
	rep )
		VC='ok'
		VCext='txt' ;;
	numpar )
		VC='ok'
		VCext='txt' ;;
	input )
		VC='ok'
		VCext='txt' ;;
	state )
		VC='ok'
		VCext='txt' ;;
	odes )
		VC='ok'
		VCext='h' ;;
	sspar )
		VC='ok'
		VCext='r' ;;
	*)
		echo Version control is not appropriate for representation $2
		exit  ;;
  esac
fi

# Classify the representation - needed for conversion route to postscript
PLOTTYPE='single';
case $2 in
	abg )
		REPTYPE='bg' ;;
	labg )
		REPTYPE='lbg' ;;
	sabg )
		REPTYPE='bg' ;;
	cbg )
		REPTYPE='bg' ;;
	input )
		REPTYPE='txt' ;;
	numpar )
		REPTYPE='txt' ;;
	state )
		REPTYPE='txt' ;;
	simpar )
		REPTYPE='txt' ;;
	obspar )
		REPTYPE='txt' ;;
	odes)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	odeso)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	sms)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	smso)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	odess)
		REPTYPE='data' ;;
	odesso)
		REPTYPE='data' ;;
	daes)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	daeso)
		REPTYPE='data'; PLOTTYPE='multiple' ;;
	ir)
		REPTYPE='data' ;;
	iro)
		REPTYPE='data' ;;
	sr)
		REPTYPE='data' ;;
	sro)
		REPTYPE='data' ;;
	fr)
		REPTYPE='data' ;;
	lmfr)
		REPTYPE='data' ;;
	lpfr)
		REPTYPE='data' ;;
	nyfr)
		REPTYPE='data' ;;
	nifr)
		REPTYPE='data' ;;
	*)
		REPTYPE='tex' ;;
esac


## Set up the main arguments
sys=$1
rep=$2
lang=$3

## Make ps pdf if -pdf set
if [ "$lang" = "ps" ]; then
  lang=$ps
fi


# Create some strings
Subsystem=$1$subsystem;

Subsystem_=$Subsystem"_"
Subsystem_ese=$Subsystem"_ese"
Subsystem_def=$Subsystem"_def"
Subsystem_rdae=$Subsystem"_rdae"
Subsystem_dae=$Subsystem"_dae"
Subsystem_subs=$Subsystem"_subs"
Subsystem_cr=$Subsystem"_cr"
Subsystem_cbg=$Subsystem"_cbg"


## Create the make target name
if [ -z "${using_oct}" ]; then
  target=${sys}_${rep}.${lang}    
else
  set_oct;
  if [ "${lang}" = "m" ]; then
    target=${sys}_${rep}.${m}
  else
    target=${sys}_${rep}.${lang}
  fi
fi 

##echo $target
##target=${sys}_${rep}.${lang}

## Arguments
ARGS=$4; _ARGS=-$4; __ARGS=`echo $_ARGS | tr ',' '-'`
__ARGS="${MTT_SWITCHES}${__ARGS}"
__ARGS=`echo ${__ARGS} | sed -e 's/-q//g' -e 's/-u//g'`

# Save up the argument list in a file; but only if argument has changed
#DIFF doesn't like empty files - so put a blank if empty
#if [ -z "$ARGS" ]; then
#  ARGS=' ';
#  _ARGS='';
#fi

#cat > $1_args.new <<EOF
#$ARGS
##EOF

#DIFF=`diff -bq $1_args.m $1_args.new 2>/dev/null`

#if [ -n "$DIFF" ]; then
#  mv $1_args.new $1_args.m
#fi

## If in MTT_work, then copy from -dr read dirs
this_dir=`basename $PWD`
if [ "${this_dir}" = "MTT_work" ]; then
  # Copy from read dirs to MTT_work
  for dir in ${read_dirs}; do
     if [ -n "$Verbose" ]; then
       echo Copying ${dir}/*
       cp --force ${dir}/* .
     else
       cp --force ${dir}/* . 2> /dev/null
     fi
    read_files=`echo ${dir}/*`
    for read_file in ${read_files}; do
     read_file_name=`basename ${read_file}`
     touch ${read_file_name}
    done
   done
fi

# Tidy mode - operate in the directory MTT-work
if [ "$tidy" = "tidy" ] && [ "$level" = "0" ]; then
    # make sure that a system exists in this directory
    if [ "${sys}_${rep}.${lang}" != "${sys}_abg.dia" ] && [ "${sys}_${rep}.${lang}" != "${sys}_abg.fig" ]; then
	nabgs=`ls ${sys}_abg.* 2>/dev/null | wc -l`
	if [ $nabgs -eq 0 ]&&[ -z "$sensitivity" ]; then
	    echo "MTT Error: System $sys does not exist"
	    exit -1;
	fi
    fi
   mkdir -p MTT_work
   valid_files=`ls | grep -v '^MTT'`
   ##cp -p -u  Makefile Make *.* .* MTT_work  2>/dev/null
   cp -p -u -R ${valid_files} MTT_work  2>/dev/null

   # Go to MTT_work
   cd MTT_work

   if [ -f ".octaverc" ]; then
     touch .octaverc
   else
     echo Copying .octaverc 
     cp $MTT_LIB/octave/.octaverc .
   fi

   if [ -f "useful-functions.hh" ]; then
     touch useful-functions.hh
   else
     echo Copying useful-functions.hh
     cp $MTT_CC/include/useful-functions.hh .
   fi

   if [ -z "$directory" ]; then
     Directory=''
   else
     Directory=$directory/MTT_work
   fi

     mtt -u -q  $mtt_switches -S "$Directory"  $1 $2 $3 $4
     mtt_status=$?

   # Exit on failure
   if [ "$mtt_status" != "0" ]; then
     echo Exiting MTT with error $mtt_status
     exit 1
   fi

  # Copy back from working directory
   if [ "$3" != "view" ] && [ "$3" != "hview" ] && [ -z "$reset" ]; then
      if [ "$3" = "html" ]; then
	  echo Moving $1_$2
          mv $1_$2 ..
      else
        if [ "$PLOTTYPE" = "multiple" -a -f $1_$2__ARGS.$ps ]; then
          echo Copying  $1_$2$__ARGS.$ps
          cp  $1_$2$__ARGS.$ps ..
        else
	    if [ -f $1$subsystem"_"$2.$lang ]; then
		echo Copying  $1$subsystem"_"$2.$lang
		cp  -p -u $1$subsystem"_"$2.$lang ..
	    fi
        fi
      fi
    fi

   # Remove the MTT_work directory if very tidy
   if [ "$verytidy" = "verytidy" ]; then
    echo Removing all working files
    rm -rf ../MTT_work
  fi
exit
fi 

# User defined representations
## Copy from library if not already here

## .make versions
if [ -f "$MTT_REP/$2_rep.make" ]; then
  if [ -f "$2_rep.make" ]; then
    echo Using $2_rep.make
  else
    echo Copying $2_rep.make from $MTT_REP
    cp $MTT_REP/$2_rep.make .
  fi
fi

if [ -f "$2_rep.make" ]; then
   if [ -n "$4" ]; then
      filename=$1_$2-$4.$3
   else
      filename=$1_$2.$3
   fi

   #if [ -f "$filename" ]; then
   #   echo $filename exists
   #else
   if [ ! -f "$2_rep.make.ignore" ]; then
       if [ -n "$Verbose" ]; then
	   echo make -s -f $2_rep.make "MTT_SYS=$1" "MTT_LANG=$3" "MTT_ARG=$4" "MTT_OPTS=$mtt_switches" 
       fi
       make -s -f $2_rep.make "MTT_SYS=$1" "MTT_LANG=$3" "MTT_ARG=$4" "MTT_OPTS=$mtt_switches"
       if [ -n "$4" ]; then
	   echo Copying  $1_$2$__ARGS.$ps
	   cp  $1_$2$__ARGS.$ps ..
       fi
   #fi
       exit
   fi
fi

## Check for pre version 4.0 integration method specification.
if [ $level = "0" ]; then
  if [ -f "$1_simpar.txt" ]; then
    method_line=`grep -i METHOD  $1_simpar.txt`
    if [ -n "`echo $method_line | grep -i euler`" ]; then
      echo Obsolete $1_simpar.txt contains: $method_line
      echo "    please use mtt -i euler in future"
      mtt_switches="$mtt_switches -i euler";
    elif [ -n "`echo $method_line | grep -i implicit`" ]; then
      echo Obsolete $1_simpar.txt contains: $method_line
      echo "    please use mtt -i implicit in future"
      mtt_switches="$mtt_switches -i implicit";
    fi
  fi
fi

if [ -n "$reset" ]; then
  if [ -f "$1_$2.$3" ]; then
    echo Resetting time stamp on $1_$2.$3
    touch $1_$2.$3
  else
    echo $1_$2.$3 does not exist - no action taken
  fi
  exit;    
fi


if [ -n "$sensitivity" ]; then
  sys_s=`echo $1 | cut -c 2-`
  sys_abg=${sys_s}_abg
fi

## Check octave version
case `$MATRIX --version | gawk -F\. '{print $2}'` in
    0) define_octave_dev="";;			# stable 
    1) define_octave_dev="-DOCTAVE_DEV";;	# development
    *) define_octave_dev="-DOCTAVE_DEV";;
esac

################################
# This is the main mtt programme
################################

#echo Target is $target, Subsystem is $Subsystem, options are $mtt_switches
##<<<<<<< mtt
##$MAKE  -S ${trace} ${verbose}  -f  -  ${target} << EOF
##=======
##$MAKE -S $verbose $verbose_make -f  -  $target << EOF
##>>>>>>> 1.316
$MAKE -S ${trace} $verbose $verbose_make -f  -  $target << EOF

# Cancel implicit rules I don't want
%.dvi: %.tex

# MTT implicit rules
## .oct files
$1_%.oct:  $1_%.cc $1_def.h $1_sympar.h $1_cr.h
	echo Creating $1_\$*.oct; $MKOCTFILE ${MTT_CXXINCS} -DCODEGENTARGET=OCTAVEDLD $1_\$*.cc

## pdf files from ps (new version)
$1_%.pdf:  $1_%.ps
	echo Creating $1_\$*.pdf; ps2pdf  $1_\$*.ps $1_\$*.pdf

## eps from ps (NB ps files are actually eps anyway)
$1_%.eps:  $1_%.ps
	echo Creating $1_\$*.eps; cp  $1_\$*.ps $1_\$*.eps

.PRECIOUS: mtt_%.oct
.PRECIOUS: $1_%.oct
mtt_%.oct: mtt_%.cc
	echo Compiling \$<
	${MKOCTFILE} ${MTT_CXXINCS} -DCODEGENTARGET=OCTAVEDLD $define_octave_dev \$<

## .mex files
$1_%.mexglx: $1_%.cc $1_def.h $1_sympar.h $1_cr.h mtt_kpathsea.cc mtt_matlab_octave.cc mtt_matlab_octave.hh
	echo Creating $1_\$*.mexglx
	${MTT_CXX} -shared -o $1_\$*.mexglx $1_\$*.cc \
	${MTT_MATLAB_FLAGS} -DCODEGENTARGET=MATLABMEX \
	${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} mtt_kpathsea.cc mtt_matlab_octave.cc

## .cc files
.PRECIOUS: %.cc # Don't let mtt delete them
.PRECIOUS: $1_%.cc # Don't let mtt delete them
$1_%.cc:  $1_%.m
	mtt_m2cc.sh  $1 \$* cc cat 

mtt_%.cc:: ${MTT_LIB}/cc/mtt_%.cc
	cp ${MTT_LIB}/cc/mtt_\$*.cc mtt_\$*.cc

mtt_%.hh:: ${MTT_LIB}/cc/mtt_%.hh
	cp ${MTT_LIB}/cc/mtt_\$*.hh mtt_\$*.hh

## .o files
.PRECIOUS: $1_%.o
$1_%.o: $1_%.cc $1_def.h $1_sympar.h $1_cr.h
	echo Compiling $1_\$*.cc
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $< -DCODEGENTARGET=STANDALONE

.PRECIOUS: mtt_%.o
mtt_%.o: mtt_%.cc
	echo Compiling mtt_\$*.cc
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $< -DCODEGENTARGET=STANDALONE $define_octave_dev

# Copy aliased subsystems
$1_aliased_subsystems_copied: 
	lbl2component $1 | sh || exit 1 # Grab specified components now
	touch $1_aliased_subsystems_copied

# Generates code to write reduce code
$1_ode_write.r: $1_def.m
	def2write_r  $1 $2 $computation

ifeq ("$sensitivity","sensitivity")
ifeq ("$level","0")
$1_abg.fig: $sys_abg.fig
	abg2sensitivity_fig $sys_s
else # Either find the sensitivity model or fetch the model and create sensitivity model
$1_abg.fig:
	mtt -q -u $mtt_switches compcopy $1 || abg2sensitivity_fig $sys_s
endif
endif

ifneq ("$sensitivity","sensitivity")
ifneq ("$level","0")
# If level>0, try and get subsystem files; creating if necessary
ifneq ("\$(wildcard $1_abg.dia)","$1_abg.dia")
$1_abg.fig:
	mtt -q -u $mtt_switches compcopy $1
else
$1_abg.fig:
endif
endif
endif

# Create an arg file if it doesn't exist
$1_args.m:
	touch $1_args.m

#Create list of components
ifeq ("\$(wildcard $1_abg.dia)","$1_abg.dia")
$1_cmp.txt: $1_abg.dia
	abg2cmp_dia2txt $1
else
$1_cmp.txt: $1_abg.fig
	abg2cmp_fig2txt $1
endif

#Create skeleton files (with titles) if not already there
#SUMMARY lbl*	label file (txt)
#SUMMARY lbl	label file (txt)
#SUMMARY lbl*	label file (view)
#SUMMARY lbl	label file (view)
#SUMMARY lbl*	label file (tex)
#SUMMARY lbl	label file (tex)
$1_lbl.txt: $1_cmp.txt
	cmp2lbl_txt $1 $sensitivity
	touch $1_lbl.txt

$1_lbl.tex: $1_lbl.txt
	lbl_txt2tex $1

#SUMMARY alias  name aliases for each subsystem (txt)
$1_alias.txt: $1_lbl.txt
	lbl2alias_txt2txt $1

#SUMMARY modpar  name modulated parameters for each subsystem (txt)
$1_modpar.txt: $1_lbl.txt
	lbl2modpar_txt $1

#SUMMARY modpar  name modulated parameters for each subsystem (r)
$1_modpar.r: $1_modpar.txt $1_struc.txt
	modpar_txt2r $1

#SUMMARY alias  name aliases for each subsystem (m)
$1_alias.m: $1_alias.txt
	alias_txt2m $1

##SUMMARY icd	interface definition for system (c)
##SUMMARY icd	interface definition for system (cc)
##SUMMARY icd	interface definition for system (m)
##SUMMARY icd	interface definition for system (txt)

$1_ICD.c: $1_ICD.txt
	ICD_txt2lang.sh $1 c

$1_ICD.cc: $1_ICD.txt
	ICD_txt2lang.sh $1 cc

$1_ICD.m: $1_ICD.txt
	ICD_txt2lang.sh $1 m

$1_ICD.txt: $1_icd.txt2
	icd2ICD_txt22txt.sh $1

$1_icd.txt2: $1_ese.r
	touch $1_icd.txt2

#SUMMARY icd	interface definitions for each subsystem (m)
$1_icd.m: $1_icd.txt
	icd_txt2m.sh $1

#SUMMARY icd	interface definitions for each subsystem (txt)
$1_icd.txt: $1_lbl.txt
	lbl2icd_txt2txt.sh $1

#SUMMARY cr	constitutive relationship for each subsystem (txt)
$1_cr.txt: $1_abg.m $1_sub.sh
	abg2cr_m2txt $1

	if [ "$level" = "0" ]; then \
	  mv $1_cr.txt MTT_cr.txt; \
	else \
	  cat $1_cr.txt >> MTT_cr.txt; \
	fi

	sh $1_sub.sh "rm -f " '_cr.txt' # Remove the txt.cr files
	sh $1_sub.sh "mtt $mtt_switches -q -u -l $level+1 " ' cr txt' #Create new ones

	if [ "$level" = "0" ]; then \
	  sort -u MTT_cr.txt> $1_cr.txt; \
	fi

#SUMMARY cr	constitutive relationship for each subsystem (r)
$1_cr.r: $1_cr.txt
	cr_txt2r $1

#SUMMARY cr	constitutive relationship header (c)
$1_cr.h: 
	echo Creating $1_cr.h
	echo "/* CR headers for system $1 */" > $1_cr.h

# Cheat a bit and use the top level cr file for the subsystem as well
ifneq ($sub,)
$Subsystem_cr.r: $1_cr.r
	echo Creating $Subsystem_cr.r "(copying $1_cr.r)"
	cp $1_cr.r $Subsystem_cr.r
endif
#SUMMARY cr	constitutive relationship for each subsystem (tex)
#SUMMARY cr	constitutive relationship for each subsystem (view)
$1_cr.tex: $1_cr.r
	txt2tex $1 cr r

#SUMMARY sympar	symbolic parameters (txt)
#SUMMARY sympar*	symbolic parameters (view)
$1_sympar.txt: $1_type.sh $1_abg.m $1_aliased.txt
	mtt_make_sympar $1 ${use_reduce}

#SUMMARY sympar	symbolic parameters (r)
$1_sympar.r: $1_sympar.txt
	sympar_txt2r $1
$1_sympar.m: $1_sympar.txt
	sympar_txt2m $1
ifneq ($sort_method,make)
$1_sympar.h: $1_sympar.txt
	sympar_txt2h.sh $1 $num_tmp_var
else
$1_sympar.h: $1_sympar.txt $1_sese.make
	sympar_txt2h.sh $1 $num_tmp_var
	declaration="static double" \
	make -f $1_sese.make declare_tmpvars |\
	tr [A-Z] [a-z] >> \$@
endif

#SUMMARY sympar	symbolic parameters (c)
# txt to c sympar conversion
$1_sympar.c: $1_sympar.txt
	sympar_txt2c $1

#SUMMARY sympar	symbolic parameters (tex)
# txt to tex (LaTeX) sympar conversion
$1_sympar.tex: $1_sympar.txt
	sympar_txt2tex $1

#SUMMARY logic	Dynamic switch logic (tex)
#SUMMARY logic	Dynamic switch logic (view)
$1_logic.tex: $1_logic.txt
	txt2tex $1 logic txt


#SUMMARY switch	Dynamic switch information (txt)
$1_switch.txt: $1_struc.txt
	struc2switch_txt $1
#$1_switchopen.m: $1_switch.txt $1_sympars.txt $1_logic.txt
#	switch_txt2m $1

#SUMMARY sympars sympar + dynamic switch information (txt)
$1_sympars.txt: $1_sympar.txt $1_switch.txt
	   echo Creating $1_sympars.txt
	   cat $1_sympar.txt $1_switch.txt > $1_sympars.txt

#SUMMARY simp	simplification information (r)
$1_simp.r:
	echo Creating $1_simp.r
	( \
	echo "%% Reduce commands to simplify output for system $1 ($1_simp.r)"; \
	cat $MTTPATH/trans/m/rcs_header.txt; \
	    echo 'ON ALLFAC; %Multiplicative factors'; \
	    echo 'OFF DIV; %Polynomial division'; \
	    echo 'OFF FACTOR; %Factorise polynomials'; \
	    echo 'OFF LIST; %Each term on a new line'; \
	    echo 'FOR ALL x,y LET pow(x,y) = x^y; %Readable pow function'; \
	echo 'END;'; \
	)> $1_simp.r

#SUMMARY subs  algebraic substitution (r)
$Subsystem_subs.r: 
	mtt $mtt_switches -q -u $1 sympar txt; 
	makesubs $Subsystem;

#SUMMARY obspar  GPC observability function parameters (r)
$1_obspar.r:
	echo Creating $1_obspar.r
	( \
	echo "%% Reduce  GPC observability function parameters for system $1 ($1_obspar.r)"; \
	cat $MTTPATH/trans/m/rcs_header.txt; \
	echo 'MTTGPCNy := 5;'; \
	echo 'MTTGPCNu := 0;'; \
	echo 'Matrix MTTdU(5,1);'; \
	echo 'MTTdU(1,1) := MTTdU1;'; \
	echo 'MTTdU(2,1) := MTTdU2;'; \
	echo 'MTTdU(3,1) := MTTdU3;'; \
	echo 'MTTdU(4,1) := MTTdU4;'; \
	echo 'MTTdU(5,1) := MTTdU5;'; \
	echo 'Matrix MTTUU(1,5);'; \
	echo 'MTTUU(1,1) := MTTu1;'; \
	echo 'MTTUU(1,2) := MTTu11;'; \
	echo 'MTTUU(1,3) := MTTu12;'; \
	echo 'MTTUU(1,4) := MTTu13;'; \
	echo 'MTTUU(1,5) := MTTu14;'; \
	echo 'END;'; \
	)> $1_obspar.r

#SUMMARY simpar	simulation information (txt)
$1_simpar.txt:
	echo Creating $1_simpar.txt
	( \
	echo '# -*-octave-*- Put Emacs into octave-mode'; \
	echo "# Simulation parameters for system $1 ($1_simpar.txt)"; \
	echo "# Generated by MTT on" `date`.; \
	cat $MTTPATH/trans/rcs_header.sh; \
	echo ;\
	echo 'FIRST        = 0.0;       # First time in simulation output'; \
	echo 'DT          = 0.1;        # Print interval'; \
	echo 'LAST        = 10.0;       # Last time in simulation'; \
	echo 'STEPFACTOR  = 1;          # Integration steps per print interval'; \
	echo 'WMIN        = -1;         # Minimum frequency = 10^WMIN'; \
	echo 'WMAX        = 2;          # Maximum frequency = 10^WMAX'; \
	echo 'WSTEPS      = 100;        # Number of frequency steps'; \
	echo 'INPUT       = 1;          # Index of the input'; \
	)> $1_simpar.txt

#SUMMARY simpar	simulation information (m)
$1_simpar.m: $1_simpar.txt $1_def.r $1_sympar.txt
	mtt_txt2m $1 simpar


#SUMMARY numpar	numerical parameter declaration -- default (txt) 
$1_numpar.txt : $1_sympar.txt $1_def.r
ifeq ($target,$1_numpar.txt)
	mtt_update $1 numpar update
else
	mtt_update $1 numpar
endif

#SUMMARY state	numerical state declaration  -- default (txt)
ifeq ($steadystate_computation,yes)
$1_state.txt : $1_struc.txt $1_sympar.txt $1_def.r $1_ss.r
else
$1_state.txt : $1_struc.txt $1_sympar.txt $1_def.r
endif

ifeq ($target,$1_state.txt)
	mtt_update $1 state update
else
	mtt_update $1 state
endif

#SUMMARY input	numerical state declaration  -- default (txt)
$1_input.txt : $1_struc.txt $1_sympar.txt
ifeq ($target,$1_input.txt)
	mtt_update $1 input update
else
	mtt_update $1 input
endif

#SUMMARY logic	Dynamic switch logic (txt)
$1_logic.txt : $1_def.r $1_struc.txt $1_sympar.txt
ifeq ($target,$1_logic.txt)
	mtt_update $1 logic update
else
	mtt_update $1 logic
endif

# Dummy target
FORCE:

ifeq ($use_reduce,yes)
$1_ode2odes_common_%.stamp: $1_ae.% $1_input.% $1_logic.% $1_numpar.% $1_simpar.% $1_state.%
	touch \$@
$1_ode2odes_common.o: $1_ae.o $1_input.o $1_logic.o $1_numpar.o $1_simpar.o $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
else
$1_ode2odes_common_%.stamp: $1_sae.% $1_input.% $1_logic.% $1_numpar.% $1_simpar.% $1_state.%
	touch \$@
$1_ode2odes_common.o: $1_sae.o $1_input.o $1_logic.o $1_numpar.o $1_simpar.o $1_state.o
	@echo "Creating $1_ode2odes_common.o"
	ar -cr \$@ \$^
endif

ifeq ($use_reduce,yes)
$1_ode2odes_euler_%.stamp $1_ode2odes_rk4_%.stamp: $1_ode.% $1_odeo.%
	touch \$@
$1_ode2odes_euler.o $1_ode2odes_rk4.o: $1_ode.o $1_odeo.o mtt_euler.o
	@echo "Creating \$@"
	ar -cr \$@ \$^
else
$1_ode2odes_euler_%.stamp $1_ode2odes_rk4_%.stamp: $1_sesx.% $1_sesy.%
	touch \$@
$1_ode2odes_euler.o $1_ode2odes_rk4.o: $1_sesx.o $1_sesy.o mtt_euler.o
	@echo "Creating \$@"
	ar -cr \$@ \$^
endif

ifeq ($use_reduce,yes)
$1_ode2odes_implicit_%.stamp: $1_cseo.% $1_csex.% $1_smxa.% $1_smxax.%
	touch \$@
$1_ode2odes_implicit.o: $1_cseo.o $1_csex.o $1_smxa.o $1_smxax.o mtt_implicit.o
	@echo "Creating $1_ode2odes_implicit.o"
	ar -cr \$@ \$^
endif				# no alternative

ifeq ($use_reduce,yes)
$1_ode2odes_dassl_oct.stamp: $1_ode.oct $1_odeo.oct mtt_dassl.oct
	touch \$@
$1_ode2odes_dassl_o.stamp: $1_ode.o $1_odeo.o mtt_dassl.o
	touch \$@
$1_ode2odes_dassl_%.stamp: $1_ode.% $1_odeo.%
	touch \$@
$1_ode2odes_dassl.o: $1_ode.o $1_odeo.o mtt_dassl.o
	@echo "Creating \$@"
	ar -cr \$@ \$^
else
$1_ode2odes_dassl_oct.stamp: $1_sesx.oct $1_sesy.oct mtt_dassl.oct
	touch \$@
$1_ode2odes_dassl_o.stamp: $1_sesx.o $1_sesy.o mtt_dassl.o
	touch \$@
$1_ode2odes_dassl_%.stamp: $1_sesx.% $1_sesy.%
	touch \$@
$1_ode2odes_dassl.o: $1_sesx.o $1_sesy.o mtt_dassl.o
	@echo "Creating \$@"
	ar -cr \$@ \$^
endif

$1_ode2odes_${algebraic_solver}.cc:	mtt_Solver.cc mtt_AlgebraicSolver.cc mtt_${algebraic_solver}.hh mtt_${algebraic_solver}.cc

$1_ode2odes_${algebraic_solver}.o:	mtt_Solver.o  mtt_AlgebraicSolver.o  mtt_${algebraic_solver}.o
	@echo "Creating $1_ode2odes_${algebraic_solver}.o"
	ar -cr \$@ \$^

#SUMMARY numpar	numerical parameter declaration (m) 
$1_numpar.m:  $1_numpar.txt $1_sympars.txt
	mtt_txt2m $1 numpar

#SUMMARY numpar	numerical parameter declaration (c) 
#SUMMARY numpar	numerical parameter declaration (view) 
$1_numpar.c:  $1_numpar.txt $1_sympar.c
	txt2c $1 numpar



#SUMMARY logic	logic input declaration (m) 
$1_logic.m:  $1_logic.txt $1_switch.txt
	mtt_txt2m $1 logic

#SUMMARY state	state declaration  -- default (txt)
#$1_state.txt: 
#	mtt $mtt_switches $1 struc txt; 
#	mtt $mtt_switches $1 ss r; 
#	struc2state_txt2txt $1

#SUMMARY state	state declaration (m) 
$1_state.m:  $1_state.txt $1_sympars.txt
	mtt_txt2m $1 state

#SUMMARY desc Verbal description of system (tex)
$1_desc.tex:
	makedesc $1


#SUMMARY params	symbolic parameter setting (r)
 $1_params.r: 
	echo Creating $1_params.r
	( \
	echo "%% Parameter file for system $1 ($1_params.r)"; \
	echo "%% This file provides symbolic parameters for simplification";\
	cat $MTTPATH/trans/m/rcs_header.txt; \
	echo 'END;'; \
	)> $1_params.r


#SUMMARY sspar	steady-state definition (r)
$1_sspar.r: 
	struc2sspar_txt2r $1

#SUMMARY sspar	steady-state parameters (tex)
#SUMMARY sspar	steady-state parameters (view)
$1_sspar.tex: $1_sspar.r
	txt2tex $1 sspar r

#SUMMARY rep*	report (txt)
#SUMMARY rep	report (tex)
#SUMMARY rep*	report (view)
#SUMMARY rep*	report (html)


ifeq ($documenttype,book)
$1_rep.txt:
	dir2rep $1 $dotdot;
else
$1_rep.txt:
	makerep_txt $1;
endif

#SUMMARY rbg	raw bond graph (m)
#Raw bond graph: fig file to mfile
$1_rbg.m: $1_abg.fig  $1_lbl.txt
	rbg_fig2m $1 $no_alpha_sort

$1_cmp.m: $1_lbl.txt $1_cmp.txt
	lbl2cmp_txt2m.pl --sys=$1 --$debug

$1_fig.fig: $1_rbg.m

#SUMMARY sabg	stripped acausal bond graph (fig)
#SUMMARY sabg	stripped acausal bond graph (ps)
#SUMMARY sabg	stripped acausal bond graph (view)
$1_sabg.fig: $1_rbg.m

#SUMMARY labg	latex-ready acausal bond graph (fig)
$1_labg.fig: $1_rbg.m
$1_labg.tex: $1_labg.fig
	fig2dev -L pstex_t -p $1_labg.eps $1_labg.fig $1_labg.tex
	fig2dev -L pstex $1_labg.fig $1_labg.eps
	cp -v $1_labg.eps ..

#Subsystem creation commands
#SUMMARY sub Executable subsystem list (sh)
ifeq ($start_at_abg,yes)
$1_sub.sh: $1_abg.m
	abg2sub_m2sh $1
else
$1_sub.sh: $1_cmp.txt $1_aliased_subsystems_copied
	cmp2sub_txt2sh $1
endif

#SUMMARY sub LaTeX subsystem list (tex)
#SUMMARY sub subsystem list (ps)
#SUMMARY sub subsystem list (view)
$1_sub.tex: $1_sub.sh
ifeq ($documenttype,section)
	sub_sh2tex $1
else
	sub_sh2tex -l $1
endif

#SUMMARY abg	acausal bond graph (m)
#Raw bond graph to acausal bond graph: mfile

ifneq ($start_at_abg,yes)
$1_abg.m: $1_ibg.m $1_cmp.m $1_lbl.txt $1_alias.m $1_sub.sh $1_icd.m
	@echo "Creating \$@"
	(sh $1_sub.sh "mtt $mtt_switches -q -u -l $level+1 " ' abg m null  || exit 1') || exit 1
	ibg2abg_m $info_switch $1
endif

ifeq ("\$(wildcard $1_abg.dia)","$1_abg.dia")
$1_ibg.m: $1_abg.dia $1_alias.m
	abg2ibg_dia2m $1
else
$1_ibg.m: $1_abg.fig $1_rbg.m
	@echo "Creating \$@"
	rbg2ibg_m $info_switch $1
endif

$1_connections.dat: $1_abg.m
	abg2connections_m2dat $1

#SUMMARY cbg*	causal bond graph (m)
#Acausal bond graph to causal bond graph: mfile
$1_cbg.m: $1_abg.m
	abg2cbg_m  $info_switch $causality_switch $1

$1_type.sh: $1_cbg.m
	touch $1_type.sh

#SUMMARY cbg*	causal bond graph (fig)
#SUMMARY cbg*	causal bond graph (dia)
#SUMMARY cbg*	causal bond graph (ps)
#SUMMARY cbg*	causal bond graph (view)
#Causal bond graph: mfile to fig conversion
$1_cbg.fig: $1_cbg.m  $1_fig.fig $1_type.sh
	sh $1_type.sh 'echo cbg_m2fig ' ' ' ' ' | sh

$1_cbg.dia: $1_cbg.m
	@sh $1_type.sh 'cbg_m2dia ' ' ' ' '

#SUMMARY ese	elementary system equations (r)
#SUMMARY def	definitions - system orders etc. (r)
#SUMMARY def	definitions - system orders etc. (m)
#SUMMARY def	definitions - system orders etc. (h)
#SUMMARY struc*	structure - list of inputs, outputs and states (txt)
#SUMMARY struc	structure - list of inputs, outputs and states (tex)
#SUMMARY struc*	structure - list of inputs, outputs and states (view)
#Elementary system equations + definitions
${sys}_ese.r: ${sys}_cbg.m
	   cbg2ese_m2r $partition $info_switch $Subsystem; #ese_tidy $1

ifeq ($sort_method,seqn)
${sys}_sese.m: ${sys}_def.r ${sys}_sese.r ${sys}_sympar.txt
	echo Creating \$@
	mtt_r2m ${sys} sese m
${sys}_sese.r: ${sys}_cbg.m ${sys}_struc.m
	echo Creating \$@
	cbg2sese_m2r $info_switch $Subsystem
endif

ifeq ($sort_method,make)
${sys}_sesx.m: ${sys}_def.r ${sys}_sesx.r ${sys}_sympar.txt
	echo Creating \$@
	mtt_r2m ${sys} sesx m
${sys}_sesy.m: ${sys}_def.r ${sys}_sesy.r ${sys}_sympar.txt
	echo Creating \$@
	mtt_r2m ${sys} sesy m
${sys}_sae.m: ${sys}_def.r ${sys}_sae.r ${sys}_sympar.txt
	echo Creating \$@
	mtt_r2m ${sys} sae m

${sys}_sese.r: ${sys}_sese.make
	echo Creating \$@
	make -f \$< MTTdX MTTy > \$@
	echo 'END;' >> \$@
${sys}_sesx.r: ${sys}_sese.make
	echo Creating \$@
	make -f \$< MTTdX > \$@
${sys}_sesy.r: ${sys}_sese.make
	echo Creating \$@
	make -f \$< MTTy  > \$@
${sys}_sae.r: ${sys}_sese.make
	echo Creating \$@
	make -f \$< MTTyz > \$@

${sys}_sese.make: ${sys}_ese.txt
	echo Creating \$@
	ese_txt2make.pl --sys=${sys} --infile=${sys}_ese.txt --outfile=\$@ --$debug

${sys}_ese.txt: ${sys}_ese.r ${sys}_cr.txt perl_crs.stamp
	echo Creating \$@
	ese_r2txt.pl < \$< |\
	apply_crs ${sys} > \$@

perl_crs.stamp:
	echo Copying CRs from ${MTT_LIB}/cr/perl
	mkdir -p mtt
	cp ${MTT_LIB}/cr/perl/*.pm mtt/
	touch \$@
endif

$1_def.r: $1_ese.r
	touch $1_def.r
$1_struc.txt: $1_ese.r
	touch $1_struc.txt
$1_aliased.txt: $1_ese.r
	touch $1_aliased.txt
$1_struc.tex: $1_struc.txt
	struc_txt2tex $1
$1_struc.m: $1_struc.txt 
	struc_txt2m $1
$1_def.m: $1_def.r
	def_r2m $1; matlab_tidy $1_def.m;
$1_def.h: $1_def.m $1_sympar.txt
	def_m2h.sh $1

#SUMMARY rdae	raw differential-algebraic equations (r)
#SUMMARY dae	differential-algebraic equations (r)
#SUMMARY dae*	differential-algebraic equations (m)
#SUMMARY dae	differential-algebraic equations (tex)
#SUMMARY dae*	differential-algebraic equations (view)
#SUMMARY dae	differential-algebraic equations (ps)
#Differential-algebraic equations

ifeq ($do_sort,)
${sys}_rdae.r: ${sys}_ese.r ${sys}_def.r $1_modpar.r ${Subsystem}_cr.r ${Subsystem}_subs.r
else
${sys}_rdae.r: ${sys}_sese.r ${sys}_def.r $1_modpar.r ${Subsystem}_cr.r ${Subsystem}_subs.r
endif
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} rdae r
endif
	mtt_prepend.sh -p $1_modpar.r $1_ese.r # Add modulated parameters to start
	ese2rdae_r ${cr_first} ${fixcc} ${do_sort} ${Subsystem}
	tidy ${Subsystem}_rdae.r

${sys}_dae.r: ${Subsystem}_rdae.r ${Subsystem}_def.r ${Subsystem}_subs.r ${Subsystem}_cr.r
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} dae r
endif
ifeq ($rdae_is_dae,1)
	echo Copying $1_rdae.r to $1_dae.r
	cp $1_rdae.r  $1_dae.r
else
	rdae2dae_r ${fixcc} ${Subsystem}; tidy ${Subsystem}_dae.r
endif

$1_dae.m: $1_def.r $1_dae.r  $1_sympars.txt
	dae_r2m $1; matlab_tidy $1_dae.m; matlab_tidy $1_daeo.m
$1_dae.c: $1_def.r $1_dae.r  $1_sympar.r
	dae_r2c $1; c_tidy $1_dae.c
$1_dae.tex: $1_dae.r $1_simp.r
	dae_r2tex $partition $1; latex_tidy $1_dae.tex

#SUMMARY ae	algebraic equations - unknown inputs (r)
#SUMMARY ae	algebraic equations - unknown inputs (m)
#SUMMARY ae	algebraic equations - unknown inputs (cc)

ifeq ($algebraic_solver,noAlgebraicSolver)
$1_ae.r:
else
$1_ae.r: $1_cse.r
endif
	touch \$@

$1_ae.m: $1_ae.r
	mtt_r2m $1 ae

#SUMMARY cse	constrained-state equations (r)
#SUMMARY cse*	constrained-state equations (m)
#SUMMARY cse*	constrained-state equations (oct)
#SUMMARY cse	constrained-state equations (tex)
#SUMMARY cse*	constrained-state equations (view)
#SUMMARY cse	constrained-state equations (ps)
#Constrained-state equations
${sys}_cse.r: ${Subsystem}_dae.r ${Subsystem}_dae.r ${Subsystem}_def.r ${Subsystem}_subs.r 
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} cse r
endif
	dae2cse_r $fixcc $optimise $Solve ${Subsystem}; tidy ${Subsystem}_cse.r #$1_subs.r
$1_csex.r: $1_cse.r
	touch $1_csex.r
$1_cseo.r: $1_cse.r
	touch $1_cseo.r

#$1_cse.m: $1_def.r $1_cse.r $1_sympar.r  $1_subs.r 
#	cse_r2m $1; matlab_tidy $1_cse.m
${sys}_cse.m: ${Subsystem}_def.r ${Subsystem}_cse.r ${sys}_sympars.txt
ifneq ($partition,)
	echo Doing subsystems
	mtt_cp_subrep ${sys} sympars txt
	mtt_make_subsystems  ${sys} cse m
endif
	mtt_r2m ${Subsystem} cse;#  matlab_tidy $1_cse.m; matlab_tidy $1_cseo.m; 

${sys}_cseo.m: ${Subsystem}_def.r ${Subsystem}_cseo.r ${sys}_sympars.txt
ifneq ($partition,)
	echo Doing subsystems
	mtt_cp_subrep ${sys} sympars txt
	mtt_make_subsystems  ${sys} cseo m
endif
	mtt_r2m ${Subsystem} cseo

${sys}_csex.m: ${Subsystem}_def.r ${Subsystem}_csex.r ${sys}_sympars.txt
ifneq ($partition,)
	echo Doing subsystems
	mtt_cp_subrep ${sys} sympars txt
	mtt_make_subsystems  ${sys} csex m
endif
	mtt_r2m ${Subsystem} csex

$1_cse.tex: $1_cse.r  $1_sympar.r $1_simp.r
	cse_r2tex $1 $2; latex_tidy $1_cse.tex


#SUMMARY scse	sensitivity constrained-state equations (r)
#SUMMARY scse	sensitivity constrained-state equations (tex)
#SUMMARY scse	sensitivity constrained-state equations (ps)

$1_scse.r: $1_cse.r $1_def.r 
	cse2scse_r  $1 "$4"; tidy $1_scse.r

#$1_cse.m: $1_def.r $1_cse.r $1_sympar.r  $1_subs.r 
#	cse_r2m $1; matlab_tidy $1_cse.m
$1_scse.m: $1_def.m $1_scse.r $1_sympars.txt
	mtt_r2m $optimise  -parameters $1 scse;  
	matlab_tidy $1_scse.m; matlab_tidy $1_scseo.m; 

$1_scse.tex: $1_scse.r  $1_sympar.r $1_simp.r
	cse_r2tex $1 $2; latex_tidy $1_scse.tex


#SUMMARY ode	ordinary differential equations (r)
#SUMMARY ode*	ordinary differential equations (m)
#SUMMARY ode	ordinary differential equations (c)
#SUMMARY ode	ordinary differential equations (tex)
#SUMMARY ode*	ordinary differential equations (view)
#SUMMARY ode	ordinary differential equations (ps)
#SUMMARY ode	ordinary differential equations (oct)
#Ordinary differential equations

ifeq ($dae_is_ode,1)
$1_ode.r: $1_dae.r
	echo Copying $1_dae.r to $1_ode.r
	cp $1_dae.r  $1_ode.r
else
$1_ode.r: $1_cse.r $1_cseo.r $1_def.r $1_sympar.r $1_subs.r
	cse2ode_r $optimise $1; tidy $1_ode.r
endif

$1_odeo.r: $1_ode.r
	touch $1_odeo.r

$1_ode.m: $1_def.r $1_ode.r
	mtt_r2m $optimise -parameters $1 ode m; #  matlab_tidy $1_ode.m
$1_odeo.m: $1_def.r $1_odeo.r
	mtt_r2m $1 odeo m

$1_odea.m: $1_ode.m
	touch $1_odea.m

$1_ode.tex: $1_ode.r  $1_sympar.r $1_simp.r
	ode_r2tex $1; latex_tidy $1_ode.tex


$1_lde.r: $1_dae.r
	dae2lde_r $optimise $1; tidy $1_lde.r

$1_lde.tex: $1_lde.r  $1_sympar.r $1_simp.r
	lde_r2tex $1; latex_tidy $1_lde.tex

# The main simulation programme
ifeq ($integration_method,implicit)
$1_ode2odes.m : $1_def.r $1_sympars.txt \
                $1_smxa.m $1_smxax.m\
                $1_simpar.m $1_numpar.m $1_state.m $1_input.m \
                $1_csex.m $1_cseo.m  $1_logic.m
ifeq ($using_oct,yes)
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method $algebraic_solver $sort_method
endif
endif
ifneq ($integration_method,implicit)
ifeq ($sort_method,seqn)
$1_ode2odes.m : $1_def.r $1_sympars.txt\
		$1_simpar.m $1_numpar.m $1_state.m $1_input.m \
		$1_sese.m $1_logic.m
else
ifeq ($use_reduce,no)
$1_ode2odes.m : $1_def.r $1_sympars.txt\
		$1_simpar.m $1_numpar.m $1_state.m $1_input.m \
		$1_sesx.m $1_sesy.m $1_logic.m
else
$1_ode2odes.m : $1_def.r $1_sympars.txt\
		$1_simpar.m $1_numpar.m $1_state.m $1_input.m \
		$1_ode.m $1_odeo.m  $1_logic.m
endif
endif
ifeq ($using_oct,yes)
	echo "*** Warning: Shouldn't be here! Creating dummy $1_ode2odes.m"
	touch $1_ode2odes.m # Create a dummy which wont' be used
	mtt $mtt_switches -q -u $1 ode2odes oct
else
	make_ode2odes $1 m $integration_method $algebraic_solver $sort_method
endif
endif

#SUMMARY ode2odes Simulation function (m)
#SUMMARY ode2odes Simulation function (cc)
#SUMMARY ode2odes Simulation function (oct)
#SUMMARY ode2odes_rtxi Simulation function (o)
#SUMMARY ode2odes Simulation function (exe)
$1_ode2odes.exe: $1_def.h $1_sympar.h\
		 $1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o mtt_kpathsea.o
	echo Creating $1_ode2odes.exe
	${MTT_CXX} ${MTT_CXXFLAGS} -o $1_ode2odes.exe\
	$1_ode2odes.o $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o mtt_kpathsea.o\
	${MTT_LDFLAGS} ${MTT_CXXLIBS}

$1_ode2odes.o: $1_ode2odes.cc $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o
	echo Creating $1_ode2odes.o
	${MTT_CXX} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $1_ode2odes.cc -DCODEGENTARGET=STANDALONE

$1_ode2odes.oct: $1_ode2odes.cc $1_ode2odes_common_oct.stamp $1_ode2odes_${integration_method}_oct.stamp $1_ode2odes_${algebraic_solver}.o
	touch $1_ode2odes.m
	echo Creating $1_ode2odes.oct
	$MKOCTFILE ${MTT_CXXINCS} -DCODEGENTARGET=OCTAVEDLD $1_ode2odes.cc mtt_${algebraic_solver}.cc mtt_Solver.cc mtt_AlgebraicSolver.cc

$1_ode2odes.mexglx: $1_ode2odes.cc $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o
	touch $1_ode2odes.m
	echo Creating $1_ode2odes.mexglx
	${MTT_CXX} -DCODEGENTARGET=MATLABMEX -o $1_ode2odes.mexglx $1_ode2odes.cc \
	$1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o \
	${MTT_MATLAB_FLAGS} ${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} \
	${MTT_LIB}/cc/mtt_kpathsea.cc ${MTT_LIB}/cc/mtt_matlab_octave.cc

$1_ode2odes.cc: $1_def.r $1_sympars.txt\
		$1_ode2odes_common_m.stamp $1_ode2odes_common_cc.stamp\
		$1_ode2odes_${integration_method}_m.stamp $1_ode2odes_${integration_method}_cc.stamp\
		mtt_Solver.cc mtt_AlgebraicSolver.cc mtt_${algebraic_solver}.cc mtt_${algebraic_solver}.hh
	touch $1_ode2odes.m
	make_ode2odes $1 cc $integration_method $algebraic_solver $sort_method

#SUMMARY rtxi real time module (cc)
#SUMMARY rtxi real time module (so)
$1_ode2odes_rtxi.lo: $1_ode2odes.cc $1_ode2odes_common.o $1_ode2odes_${integration_method}.o $1_ode2odes_${algebraic_solver}.o \
		    $1_rtxi.cc $1_rtxi.h
	@echo "Creating \$@"
	${MTT_RTXI_CXXCOMPILE} ${MTT_RTXI_CXXFLAGS} ${MTT_CXXFLAGS} ${MTT_CXXINCS} -c $1_ode2odes.cc -DCODEGENTARGET=RTXI -o \$@
	@echo compilation complete

$1_rtxi.so: $1_rtxi.cc $1_ode2odes_rtxi.lo $1_rtxi.h
	@echo Compiling module
	${MTT_RTXI_CXXCOMPILE} ${MTT_RTXI_CXXFLAGS} -c $1_rtxi.cc -o $1_rtxi.lo
	@echo Compilation complete
	${MTT_RTXI_CXXLINK} ${MTT_RTXI_LIBS} ${MTT_RTXI_LDFLAGS} ${MTT_CXXLIBS} -rpath ${MTT_RTXI_RPATH}$1 -o $1_rtxi.la $1_rtxi.lo $1_ode2odes_rtxi.lo
	@echo Module created

$1_rtxi.install: $1_rtxi.so
	@echo Installing module in ${MTT_RTXI_RPATH}$1)
	${MTT_RTXI_LIBTOOL} --mode=install cp $1_rtxi.la ${MTT_RTXI_RPATH}$1

$1_rtxi.cc: $1_struc.txt $1_sympar.txt
	echo Creating \$@
	sympar2rtxi_txt2cc $1

$1_rtxi.h: $1_sympar.txt
	echo Creating \$@
	sympar2rtxi_txt2h $1



#Conversion of m to p to c
#SUMMARY ode	ordinary differential equations (c)
#SUMMARY ode	ordinary differential equations (p)
#SUMMARY state	state declaration (c) 
#SUMMARY state	state declaration (p) 
$1_simpar.p : $1_def.r $1_simpar.m
	mtt_m2p $1_simpar.m
$1_numpar.p : $1_def.r $1_numpar.m
	mtt_m2p $1_numpar.m
$1_state.p : $1_def.r $1_state.m
	mtt_m2p $1_state.m

#SUMMARY input	numerical input declaration (m) 
ifeq ($stdin,stdin)
$1_input.m : $1_def.r
	make_stdin $1 m
$1_input.p : $1_def.r
	make_stdin $1 p
$1_input.cc:
	make_stdin $1 cc
else
$1_input.m:  $1_input.txt $1_sympars.txt
	mtt_txt2m $1 input
$1_input.p : $1_def.r $1_input.m
	mtt_m2p $1_input.m
endif

$1_ode.p : $1_def.r $1_ode.m
	mtt_m2p $1_ode.m
$1_odeo.p : $1_def.r $1_odeo.m
	mtt_m2p $1_odeo.m
$1_csex.p : $1_def.r $1_cse.m
	mtt_m2p $1_csex.m
$1_cseo.p : $1_def.r $1_cseo.m
	mtt_m2p $1_cseo.m
$1_smx.p : $1_def.r $1_smx.m
	mtt_m2p $1_smx.m
$1_smxa.p : $1_def.r $1_smxa.m
	mtt_m2p $1_smxa.m
$1_smxax.p : $1_def.r $1_smxax.m
	mtt_m2p $1_smxax.m
$1_logic.p : $1_def.r $1_logic.m
	mtt_m2p $1_logic.m

ifeq ($integration_method,implicit)
$1_ode2odes.p : $1_ode2odes.m $1_def.r $1_smxa.p $1_smxax.p\
		$1_simpar.p $1_numpar.p $1_state.p $1_input.p \
		$1_csex.p $1_cseo.p  $1_logic.p
	mtt_m2p $1_ode2odes.m $integration_method $stdin
endif
ifneq ($integration_method,implicit)
$1_ode2odes.p : $1_ode2odes.m $1_def.r\
		$1_simpar.p $1_numpar.p $1_state.p $1_input.p \
		$1_ode.p $1_odeo.p  $1_logic.p
	mtt_m2p $1_ode2odes.m $integration_method $stdin
endif

$1_ode2odes.c: $1_ode2odes.p 
	mtt_p2c $info_switch $1 ode2odes

##SUMMARY sim Octave simulation function (m)

#ifeq ($computation,octave)
#$1_sim.m: $1_def.r $1_sympar.txt $1_cse.m $1_cseo.m $1_smxa.m $1_smxax.m $1_numpar.m $1_state.m
	mtt_make_sim $1 $integration_method $computation 
#endif

#ifeq ($computation,c)
#$1_sim.m: $1_def.r $1_sympar.txt $1_ode2odes.out $1_numpar.m $1_state.m
#	mtt_make_sim $1 $integration_method $computation 
#endif

#SUMMARY ssim Octave sensitivity simulation function (m)
$1_ssim.m: $1_def.r $1_ode2odes.${m}
	make_ssim $1 m

#SUMMARY sim Octave simulation function (m)
$1_sim.m: $1_def.r $1_ode2odes.${m}
	make_sim $1 m

#SUMMARY obs	observer equations for CGPC (r)
#SUMMARY obs*	observer equations for CGPC (m)
#SUMMARY obs	observer equations for CGPC (tex)
#SUMMARY obs*	observer equations for CGPC (view)
#SUMMARY obs	observer equations for CGPC (ps)
#Observer functions for GPC
$1_obs.r: $1_ode.r $1_def.r $1_obspar.r $1_subs.r
	ode2obs_r $1; tidy $1_obs.r
$1_obs.m: $1_def.r $1_sympars.txt $1_obs.r $1_obspar.r $1_numpar.m
	mtt_r2m $optimise  -parameters $1 obs
$1_obs.tex: $1_obs.r  $1_sympar.r $1_simp.r
	obs_r2tex $1; latex_tidy $1_obs.tex


#SUMMARY rfe	robot-form equations (r)
#SUMMARY rfe	robot-form equations (tex)
#SUMMARY rfe*	robot-form equations (view)
#SUMMARY rfe	robot-form equations (ps)
#Robot-form equations
$1_rfe.r: $1_cse.r $1_csm.r $1_def.r $1_sympar.r
	cse2rfe_r $1; tidy $1_rfe.r
$1_rfe.tex: $1_rfe.r  $1_sympar.r  $1_simp.r
	rfe_r2tex $1; latex_tidy $1_rfe.tex

#SUMMARY ss	steady-state equations (r)
#SUMMARY ss*	steady-state equations (m)
#SUMMARY ss	steady-state equations (tex)
#SUMMARY ss*	steady-state equations (view)
#SUMMARY ss	steady-state equations (ps)
#Steady-states
$1_ss.r: $1_def.r $1_sspar.r $1_cr.r $1_ode.r
	sspar2ss_r $1; tidy $1_ss.r
$1_ss.m: $1_def.r  $1_ss.r  $1_numpar.m
	ss_r2m $1; matlab_tidy $1_ss.m
$1_ss.tex: $1_def.r $1_ss.r $1_simp.r
	ss_r2tex $1; latex_tidy $1_ss.tex 


#SUMMARY dm	descriptor matrices (r)
#SUMMARY dm*	descriptor matrices (m)
#SUMMARY dm	descriptor matrices (tex)
#SUMMARY dm*	descriptor matrices (view)
#SUMMARY dm	descriptor matrices (ps)
#Linearised system: descriptor matrices
$1_dm.r: $1_dae.r $1_def.r $1_cr.r  $1_ss.r $1_sympar.r
	dae2dm_r $1; tidy $1_dm.r
$1_dm.m: $1_def.r $1_dm.r $1_sympars.txt
		mtt_r2m $optimise -parameters $1 dm
$1_dm.tex: $1_dm.r $1_sympar.r $1_simp.r 
	dm_r2tex $1; latex_tidy $1_dm.tex



#SUMMARY csm	constrained-state matrices (r)
#SUMMARY csm	constrained-state matrices (m)
#SUMMARY csm	constrained-state matrices (tex)
#SUMMARY csm	constrained-state matrices (view)
#SUMMARY csm    constrained-state matrices (ps)
#Linearised system: constrained-state matrices
$1_csm.r: $1_cse.r $1_def.r $1_cr.r $1_sspar.r
	cse2csm_r $1 csm; tidy $1_csm.r
$1_csm.m: $1_def.r $1_csm.r $1_sympars.txt
		mtt_r2m $optimise  -parameters $1 csm;  matlab_tidy $1_csm.m
$1_csm.tex: $1_csm.r  $1_sympar.r $1_simp.r
	csm_r2tex $1 csm; latex_tidy $1_csm.tex
#SUMMARY scsm	sensitivity constrained-state matrices (r)
#SUMMARY scsm	sensitivity constrained-state matrices (m)
#SUMMARY scsm	sensitivity constrained-state matrices (tex)
#SUMMARY scsm	sensitivity constrained-state matrices (view)
#SUMMARY scsm	sensitivity constrained-state matrices (ps)
#Linearised system: sensitivity constrained-state matrices
$1_scsm.r: $1_scse.r $1_def.r $1_cr.r $1_sympar.r $1_sspar.r
	cse2csm_r $1 scsm; tidy $1_scsm.r
$1_scsm.m: $1_def.r $1_scsm.r $1_sympars.txt
		csm_r2m $1 scsm;  matlab_tidy $1_scsm.m
$1_scsm.tex: $1_scsm.r  $1_sympar.r $1_simp.r
	csm_r2tex $1 scsm; latex_tidy $1_scsm.tex

#SUMMARY sm	state matrices (r)
#SUMMARY sm*	state matrices (m)
#SUMMARY sm	state matrices (icad)
#SUMMARY sm	state matrices (tex)
#SUMMARY sm	state matrices (c)
#SUMMARY sm*	state matrices (view)
#SUMMARY sm	state matrices (ps)
#Linearised system: state matrices
$1_sm.r: $1_csm.r $1_def.r $1_cr.r $1_ss.r $1_sympar.r
	csm2sm_r $optimise $1 sm; tidy $1_sm.r
$1_sm.m: $1_def.r $1_sm.r $1_sympars.txt 
		mtt_r2m $optimise  -parameters $1 sm
$1_sm.icad:  $1_sm.m $1_numpar.m
		sm_m2icad $1
$1_sm.c: $1_def.r $1_sm.r $1_sympar.c
		sm_r2c $1
$1_sm.tex: $1_sm.r  $1_sympar.r $1_simp.r
	sm_r2tex $1 sm; latex_tidy $1_sm.tex

#SUMMARY ssm	sensitivity state matrices (r)
#SUMMARY ssm	sensitivity state matrices (icad)
#SUMMARY ssm	sensitivity state matrices (tex)
#SUMMARY ssm	sensitivity state matrices (c)
#SUMMARY ssm	sensitivity state matrices (ps)
#Linearised system: sensitivity state matrices
$1_ssm.r: $1_scsm.r $1_def.r $1_cr.r $1_ss.r $1_sympar.r
	csm2sm_r $optimise $1 ssm; tidy $1_ssm.r
$1_ssm.m: $1_def.r $1_ssm.r $1_sympars.txt 
		mtt_r2m $optimise -parameters $1 ssm
$1_ssm.tex: $1_ssm.r  $1_sympar.r $1_simp.r
	sm_r2tex $1 ssm; latex_tidy $1_ssm.tex

#SUMMARY smx	state matrices with variable state x (r)
#SUMMARY smx	state matrices with variable state x (m)
#SUMMARY smxx	Sparse computation of Ax (m)
#SUMMARY smxtx	Sparse computation of ATx (m)
$1_smx.r: $1_def.r $1_def.m $1_ode.r $1_subs.r
		ode2smx_lang $1 r; tidy $1_smx.r

$1_smx.m: $1_def.r $1_def.m $1_cse.r $1_sympars.txt $1_subs.r
		cse2smx_lang $fixcc $optimise -parameters $1 smx m

$1_smxa.m: $1_def.r $1_def.m $1_cse.r  $1_sympars.txt $1_subs.r
		cse2smx_lang $fixcc $optimise -parameters $matrix_smxa $1 smxa m

$1_smxax.m: $1_def.r $1_def.m $1_cse.r $1_sympars.txt $1_subs.r
		cse2smx_lang $fixcc $optimise -parameters $1 smxax m

#SUMMARY smc	controller form state matrices etc. - siso only (r)
#SUMMARY smc	controller form state matrices etc. - siso only (tex)
#SUMMARY smc*	controller form state matrices etc. - siso only (m)
#SUMMARY smc*	controller form state matrices etc. - siso only (view)
#SUMMARY smc	controller form state matrices etc. - siso only (ps)
#Linearised system: controller form state matrices etc.
$1_smc.r: $1_sm.r $1_def.r $1_tf.r 
	sm2smc_r $1; tidy $1_smc.r
$1_smc.tex: $1_smc.r  $1_simp.r
	smc_r2tex $1; latex_tidy $1_smc.tex
$1_smc.m: $1_def.r $1_smc.r $1_numpar.m
		smc_r2m $1;  matlab_tidy $1_smc.m

#SUMMARY smo	observer form state matrices etc. - siso only (r)
#SUMMARY smo	observer form state matrices etc. - siso only (tex)
#SUMMARY smo*	observer form state matrices etc. - siso only (m)
#SUMMARY smo*	observer form state matrices etc. - siso only (view)
#SUMMARY smo	observer form state matrices etc. - siso only (ps)
#Linearised system: observer form state matrices etc.
$1_smo.r: $1_sm.r $1_def.r $1_tf.r 
	sm2smo_r $1; tidy $1_smo.r
$1_smo.tex: $1_smo.r  $1_simp.r
	smo_r2tex $1; latex_tidy $1_smo.tex
$1_smo.m: $1_def.r $1_smo.r $1_numpar.m
		smo_r2m $1;  matlab_tidy $1_smo.m

#SUMMARY ssk	State-space controller gain - siso only (r)
#SUMMARY ssk	State-space controller gain - siso only (tex)
#SUMMARY ssk*	State-space controller gain - siso only (m)
#SUMMARY ssk*	State-space controller gain - siso only (view)
#SUMMARY ssk	State-space controller gain - siso only (ps)
#Linearised system: State-space controller gain
$1_ssk.r: $1_def.r $1_smc.r 
	smc2ssk_r $1; tidy $1_ssk.r
$1_ssk.tex: $1_ssk.r  $1_simp.r
	ssk_r2tex $1; latex_tidy $1_ssk.tex
$1_ssk.m: $1_def.r $1_ssk.r $1_numpar.m
		ssk_r2m $1;  matlab_tidy $1_ssk.m

#SUMMARY ssl	State-space observer gain - siso only (r)
#SUMMARY ssl	State-space observer gain - siso only (tex)
#SUMMARY ssl*	State-space observer gain - siso only (m)
#SUMMARY ssl*	State-space observer gain - siso only (view)
#SUMMARY ssl	State-space observer gain - siso only (ps)
#Linearised system: State-space observer gain
$1_ssl.r: $1_def.r $1_smo.r 
	smo2ssl_r $1; tidy $1_ssl.r
$1_ssl.tex: $1_ssl.r  $1_simp.r
	ssl_r2tex $1; latex_tidy $1_ssl.tex
$1_ssl.m: $1_def.r $1_ssl.r $1_numpar.m
		ssl_r2m $1;  matlab_tidy $1_ssl.m

#SUMMARY tf	transfer function (r)
#SUMMARY tf*	transfer function (m)
#SUMMARY tf	transfer function (tex)
#SUMMARY tf*	transfer function (view)
#SUMMARY tf	transfer function (ps)
#Linearised system: transfer function
$1_tf.r: $1_dm.r $1_sympar.r 
	dm2tf_r $1; tidy $1_tf.r
$1_tf.m: $1_def.r $1_sympars.txt $1_tf.r 
	tf_r2m $1; matlab_tidy $1_tf.m
$1_tf.tex: $1_def.r $1_tf.r $1_sympar.r $1_simp.r
	tf_r2tex $1; latex_tidy $1_tf.tex

#SUMMARY pkim	partialyy-known system identification matrix (r)
#SUMMARY pkim	partialyy-known system identification matrix (tex)
#SUMMARY pkim	partialyy-known system identification matrix (view)
#SUMMARY pkim	partialyy-known system identification matrix (ps)
$1_pkim.r: $1_tf.r $1_sympar.r 
	tf2pkim_r $1; tidy $1_pkim.r
$1_pkim.tex: $1_def.r $1_pkim.r $1_simp.r
	pkim_r2tex $1; latex_tidy $1_pkim.tex

#SUMMARY ctf    controller transfer function (r)
#SUMMARY ctf	controller transfer function (m)
#SUMMARY ctf	controller transfer function (tex)
#SUMMARY ctf	controller transfer function (view)
#SUMMARY ctf	controller transfer function (ps)
#Linearised system: transfer function
$1_ctf.r: $1_dm.r $1_ssk.r  $1_ssl.r   $1_sm.r  
	ssk2ctf_r $1; tidy $1_ctf.r
$1_ctf.m: $1_def.r $1_ctf.r 
	ctf_r2m $1; matlab_tidy $1_ctf.m
$1_ctf.tex: $1_def.r $1_ctf.r $1_sympar.r $1_simp.r
	ctf_r2tex $1; latex_tidy $1_ctf.tex

#SUMMARY ir	impulse response - state (m)
#SUMMARY ir	impulse response - state (dat)
#SUMMARY ir	impulse response - state (ps)
#SUMMARY ir	impulse response - state (view)

#SUMMARY iro	impulse response - output (m)
#SUMMARY iro	impulse response - output (dat)
#SUMMARY iro	impulse response - output (ps)
#SUMMARY iro	impulse response - output (view)

#SUMMARY sr	step response - state (m)
#SUMMARY sr	step response - state (dat)
#SUMMARY sr	step response - state (ps)
#SUMMARY sr	step response - state (view)

#SUMMARY sro*	step response - output (m)
#SUMMARY sro	step response - output (dat)
#SUMMARY sro	step response - output (ps)
#SUMMARY sro*	step response - output (view)

#SUMMARY odes	ode solution - state (m)
#SUMMARY odes*	ode solution - state (dat)
#SUMMARY odes*  ode solution - state & output for SciGraphica (sg)
#SUMMARY odes*	ode solution - state (ps)
#SUMMARY odes*	ode solution - state (view)

#SUMMARY sms	ode (in state matrix form) solution - state & output (c)

#SUMMARY odeso	ode solution - output (m)
#SUMMARY odeso*	ode solution - output (dat)
#SUMMARY odeso*	ode solution - output for spreadsheet (sdat) 
#SUMMARY odeso	ode solution - output (ps)
#SUMMARY odeso*	ode solution - output (view)

#SUMMARY daes   dae solution - state (m)
#SUMMARY daes	dae solution - state (dat)
#SUMMARY daes	dae solution - state (ps)
#SUMMARY daes	dae solution - state (view)

#SUMMARY daeso  dae solution - output (m)
#SUMMARY daeso	dae solution - output (dat)
#SUMMARY daeso	dae solution - output (ps)
#SUMMARY daeso	dae solution - output (view)

#Time responses
$1_ir.m: $1_sm.m $1_numpar.m $1_def.m $1_simpar.m
	sm2ir_m $1 '$ARGS'
$1_iro.m: $1_ir.m
	touch $1_iro.m
$1_ir.dat: $1_ir.m
	m2dat $1_ir
$1_iro.dat: $1_iro.m
	m2dat $1_iro
$1_sr.m: $1_sm.m $1_numpar.m $1_simpar.m $1_def.m
	sm2sr_m $1 
$1_sr.dat: $1_sr.m
	m2dat $1_sr
$1_sro.m: $1_sr.m
	touch $1_sro.m$
$1_sro.dat: $1_sro.m
	m2dat $1_sro
1_odes.c: $1_ode.c $1_def.r $1_sympar.r
	ode2odes_r2c $1 
$1_sms.c: $1_sm.c $1_def.r $1_sympar.r
	sm2sms_r2c $1

.PRECIOUS: $1_odes.dat2
ifeq ($computation,octave)
ifeq ($using_oct,yes)
$1_odes.dat2: $1_ode2odes.oct
	time octave_ode2odes $1
else
$1_odes.dat2: $1_ode2odes.m
	time octave_ode2odes $1
endif
endif

$1_ode2odes.out: $1_ode2odes.c $1_cr.h
	echo Creating $1_odes.out by compiling $1_ode2odes.c 
	$CC $1_ode2odes.c -lp2c -lm -o $1_ode2odes.out

ifeq ($computation,c)
$1_odes.dat2: $1_ode2odes.out
	echo Creating $1_odes.dat2 using c version
	    time ./$1_ode2odes.out>$1_odes.dat2
endif

ifeq ($computation,cc)
$1_sim.exe: $1_ese.r 
	mtt $mtt_switches -q $1 sim exe

$1_odes.dat2: $1_ode2odes.exe 
	echo Creating $1_odes.dat2 using cc version $ARGS
	    time ./$1_ode2odes.exe $ARGS >$1_odes.dat2
endif


#$1_odeso.m: $1_odes.m
#	touch $1_odeso.m
#$1_smso.m: $1_sms.m
#	touch $1_smso.m
#$1_daes.m: $1_dae.m $1_numpar.m  $1_def.m $1_input.m $1_simpar.m
#	dae2daes_m $1 '$ARGS'
#$1_daeso.m: $1_daes.m
#	touch $1_daeso.m


#Conversion of data files from dat to sdat format
$1_odeso.sdat: $1_odeso.dat $1_struc.txt
	odeso_dat2sdat $1

$1_odes.sdat: $1_odes.dat $1_struc.txt
	odes_dat2sdat $1

#Conversion of data to SciGraphica
$1_odes.sg: $1_struc.m $1_odes.dat2
	echo Creating $1_odes.sg
	dat22sg.sh $1

#SUMMARY odess	ode numerical steady-states - states (m)
#SUMMARY odess	ode numerical steady-states - states (dat)
#SUMMARY odess	ode numerical steady-states - states (ps)
#SUMMARY odess	ode numerical steady-states - states (view)

#SUMMARY odesso	ode numerical steady-states - outputs (m)
#SUMMARY odesso	ode numerical steady-states - outputs (dat)
#SUMMARY odesso	ode numerical steady-states - outputs (ps)
#SUMMARY odesso	ode numerical steady-states - outputs (view)

#Numerical steady states
$1_odess.dat2: $1_ode.m $1_odeo.m $1_numpar.m  $1_input.m $1_simpar.m
	ode2odess_m2dat2 $1 
#$1_odess.m: $1_ode.m $1_odeo.m $1_numpar.m  $1_input.m $1_simpar.m
#	ode2odess_m $1 
#$1_odesso.m: $1_odess.m
#	touch $1_odesso.m


#SUMMARY fr	frequency response (m)
#SUMMARY fr	frequency response (dat)
#SUMMARY fr	frequency response (ps)
#SUMMARY fr	frequency response (view)

#SUMMARY lmfr	loglog modulus frequency response (m)
#SUMMARY lmfr	loglog modulus frequency response (dat)
#SUMMARY lmfr	loglog modulus frequency response (ps)
#SUMMARY lmfr*	loglog modulus frequency response (view)

#SUMMARY lpfr	semilog phase frequency response (m)
#SUMMARY lpfr	semilog phase frequency response (dat)
#SUMMARY lpfr	semilog phase frequency response (ps)
#SUMMARY lpfr*	semilog phase frequency response (view)

#SUMMARY nyfr	Nyquist style frequency response (m)
#SUMMARY nyfr	Nyquist style frequency response (dat)
#SUMMARY nyfr	Nyquist style frequency response (ps)
#SUMMARY nyfr	Nyquist style frequency response (view)

#SUMMARY nifr	Nichols style frequency response (m)
#SUMMARY nifr	Nichols style frequency response (dat)
#SUMMARY nifr	Nichols style frequency response (ps)
#SUMMARY nifr	Nichols style frequency response (view)


#Frequency responses
$1_fr.m: $1_dm.m $1_numpar.m $1_def.m $1_simpar.m
	dm2fr_m $1 
$1_lmfr.m $1_lpfr.m $1_nyfr.m $1_nifr.m: $1_fr.m

$1_fr.dat: $1_fr.m
	m2dat $1_fr
$1_lmfr.dat: $1_lmfr.m
	m2dat $1_lmfr
$1_lpfr.dat: $1_lpfr.m
	m2dat $1_lpfr
$1_nyfr.dat: $1_nyfr.m
	m2dat $1_nyfr
$1_nifr.dat: $1_nifr.m
	m2dat $1_nifr


ifeq ($REPTYPE,txt)
#Generic conversion of txt files to tex files
$1_$2.tex: $1_$2.txt
	txt2tex $1 $2 txt
 endif

#Conversion of dat2 files  to dat format
$1_odeso.dat: $1_odes.dat2 $1_def.r
	echo Creating $1_odeso.dat
	dat22dat $1 ode so
$1_odes.dat: $1_odes.dat2 $1_def.r
	echo Creating $1_odes.dat
	dat22dat $1 ode s
$1_odesso.dat: $1_odess.dat2 $1_def.r
	echo Creating $1_odesso.dat
	dat22dat $1 odes so
$1_odess.dat: $1_odess.dat2 $1_def.r
	echo Creating $1_odess.dat
	dat22dat $1 odes s

#Generic conversion of data files from dat to (gplot) gdat format 
$1_$2.gdat: $1_$2.dat $1_struc.txt  $1_args.m
	dat2gdat $1 $2 "$ARGS" "$NyquistStyle"

## Conversion of gdat to fig files
ifeq ($REPTYPE,data)
$1_$2.fig: $1_$2.gdat
	gdat2fig $1_$2

ifneq ($ARGS,) ## Multiple plots
	echo Creating $1_$2$__ARGS.fig
	mv $1_$2.fig $1_$2$__ARGS.fig
	rm -f $1_$2.gdat
endif

## Conversion of gdat fig files to ps/pdf
ifeq ($ARGS,) # single plot
$1_$2.$ps : $1_$2.fig
	echo Creating $1_$2.$ps
	fig2dev -L$eps $1_$2.fig > $1_$2.$ps
else ## Multiple plots
$1_$2.$ps : $1_$2.fig
	mtt -q -r $1 $2 dat $4
	echo Creating $1_$2$__ARGS.$ps
	fig2dev -L$eps $1_$2$__ARGS.fig > $1_$2$__ARGS.$ps
endif

endif


#Generic conversion of Latex to latex document
mtt.sty:
	echo Copying mtt.sty to here
	cp $MTTPATH/trans/mtt.sty .
$1_$2.doc: $1_$2.tex
	makedoc "$mtt_switches" "$1" "$2" "$3" "$4" "$documenttype" "$ps"


#Create PostScript version of dia and fig files
ifeq ($REPTYPE,bg)
ifeq ("\$(wildcard $1_abg.dia)","$1_abg.dia")
$1_$2.$ps : $1_$2.dia
else
$1_$2.$ps : $1_$2.fig
endif
	echo Creating $1_$2.$ps
	bg2eps $1 $2 $ps $eps
endif

ifeq ($REPTYPE,lbg)
$1_$2.$ps : $1_$2.fig
	labg_fig2ps $1_$2
endif

ifeq ($REPTYPE,tex)
#Generic conversion of LaTeX doc to dvi or pdf
$1_$2.$ps: $1_$2.doc
	doc2$ps $1_$2 "$documenttype"
endif


ifeq ($REPTYPE,tex)
#Create html version of dvi file
$1_$2.html: $1_$2.doc
	echo Creating $1_$2/$1_$2.html
	$LATEX2HTML $1_$2.doc>latex2html.log 2>latex2html.log
endif

#Default view
ifeq ($REPTYPE,bg)
$1_$2.view : $Subsystem_$2.pview
endif

ifeq ($REPTYPE,data)
$1_$2.view: $1_$2.$ps
ifeq ($ARGS,) # single plot
	echo Creating view of $1_$2 - $ps file
	$psview $1_$2.$ps&
else
	echo Creating view of $1_$2$__ARGS - $ps file
	$psview $1_$2$__ARGS.$ps&
endif
endif

ifeq ($REPTYPE,tex)
$1_$2.view : $1_$2.pview
endif

ifeq ($REPTYPE,txt)
$1_$2.view : $1_$2.tview
endif

# Hypertext view
$1_$2.hview: $1_$2.html
	$HTMLVIEW $1_$2/$1_$2.html&

#View a ps file
$Subsystem_$2.pview: $1_$2.$ps
	echo Creating view of $Subsystem_$2 - $ps file
	mtt_multi $psview $Subsystem $2 $ps $viewlevel  | sh 

#View a gdat file
$1_$2.dview: $1_$2.gdat
	echo Creating view of $1_$2
	gdat2view $1_$2 '$ARGS'&

#View a tex file
$1_$2.tview: $1_$2.dvi
	echo Creating view of $1_$2
	$DVIVIEW $1_$2.dvi&

#Report generation
$1_rep.make: $1_rep.txt
	rep_txt2make $1 "$mtt_switches"

$1_reps_made:
	rep_txt2sh $1 "$mtt_switches";  touch $1_reps_made

$1_rep.tex: $1_rep.txt $1_reps_made
	rep_txt2tex $1 "$documenttype" "$directory" "$mtt_switches";

#SUMMARY abg Acausal bond graph report (tex)
$1_abg.tex: $1_sub.sh $1_labg.tex
	sh $1_sub.sh "mtt -q " " labg tex"
	abg2tex $pdf ${sensitivity_switch} $1

#SUMMARY tf Transfer function (mml)
$1_$2.mml: $1_$2.r
	mtt_r2mml $1 $2


# Version control system - uses RCS
RCS:
	echo Creating RCS
	mkdir RCS
$1_$2.vc: RCS 
	echo Version control on $1_$2.$VCext with message: $log_message
	ci -m"$log_message" -I $1_$2.$VCext </dev/tty  ; co -l $1_$2.$VCext 

EOF
# Remember the exit status of make
make_status=$?

# Tidy up.
# echo Removing log files and other garbage
  rm -f  *_unique_raw_list *_raw_list
  rm -f mtt_error.txt mtt_info.txt 
  rm -f  mtt_info.txt warning.txt
#  rm -f *_*.idx *_*.ind *_*.ilg  *_*.lof *_*.toc

# Remove logs if not debugging
if [ "$debug" != "debug" ]; then
  rm -f *.log
else
  echo Debugging - log files retained in LOGFILES  
  mkdir -p LOGFILES
  mv -f *.log LOGFILES 2> /dev/null
fi

#Print what's going on if in verbose mode
if [ -n "$Verbose" ]; then
    echo Finishing mtt  $mtt_switches  $1 $2 $3 $4 at level $level
fi

if [ "$make_status" != "0" ]; then
    echo Exiting MTT with error $make_status
    exit 1
fi


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