Overview
Comment:Replaces defunct abg2lbl_fig2txt
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 4f90b9967b2ea16b2df6719b2e06bdd457861b7eb87c6f85645579b995ec9280
User & Date: gawthrop@users.sourceforge.net on 2002-12-01 14:54:52
Other Links: branch diff | manifest | tags
Context
2002-12-03
08:51:22
Wrappers for trans/dia2abg.pl. check-in: f3b17d5450 user: geraint@users.sourceforge.net tags: origin/master, trunk
2002-12-01
14:54:52
Replaces defunct abg2lbl_fig2txt check-in: 4f90b9967b user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2002-11-30
13:39:50
Split abg2lbl_fig2txt into two parts:
abg2cmp_fig2txt
cmp2lbl_txt
and incorporated into mtt
check-in: 3155072938 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/bin/trans/abg2cmp_fig2txt version [cb66a7f672].

































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#! /bin/sh

### abg2cmp_fig2txt
##  Creates list of components contained in _abg.fig
## Copyright (C) 2002 by Peter J. Gawthrop

  ###################################### 
  ##### Model Transformation Tools #####
  ######################################
  
  ###############################################################
  ## Version control history
  ###############################################################
  ## $Log$
  ##
  ###############################################################

system=$1
infile=${system}_abg.fig
outfile=${system}_cmp.txt

echo Creating ${outfile}

## Find names of all components
grep -v '\[[0-9]*:[0-9]*\]' ${infile}  |\
gawk '/:/ {print $NF}'  | \
sed 's/\\001//' | \
sort -u> ${outfile}

## Create cmp.txt files beneath this one
##mtt -q -u -l 1 ${system} sub sh # Create the list of subsystems
##sh ${system}_sub.sh "abg2cmp_fig2txt " " " # Create the comp files

Added mttroot/mtt/bin/trans/cmp2lbl_txt version [9e70f59481].



























































































































































































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#!/bin/sh

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

# Bourne shell script: cmp2lbl_txt
#
# Component list to skeleton lable file
# Hacked from (now redundent) abg2lbl_txt

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
##
## Old log from abg2lbl_fig2txt
## Revision 1.28  2002/10/30 00:04:22  gawthrop
## Added AEf and AFe to list
##
## Revision 1.27  2002/05/10 09:08:55  gawthrop
## Added EMTF and INTF
## Fixed bug in writing out component headings
##
## Revision 1.26  2002/04/28 18:41:26  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.25  2001/10/15 14:27:00  gawthrop
## Now handles [1:N] style port labels
##
## Revision 1.24  2001/08/02 03:24:48  geraint
## Replaced mtt_version.sh with mtt_banner.sh - I think this was the intent.
##
## Revision 1.23  2001/07/26 04:08:35  gawthrop
## Removed lines deleting _type.sh and cbg.m
##  -- how did they get there ??
##
## Revision 1.22  2001/07/08 03:28:11  gawthrop
## Fixed a bug: abg2sympar_m2txt neads a _lbl.txt file when using
## "usinglabel" option
##
## Revision 1.21  2001/07/06 00:46:50  gawthrop
## Added -cr option -- forces cr to be loaded before the ese.r file
## This avoids causality problems when using multi-port Rs to represent
## arbitary equations
##
## Revision 1.20  2001/07/04 05:19:57  gawthrop
## Added RT & CT to list
##
## Revision 1.19  2001/07/03 23:51:10  gawthrop
## Now puts outline #Summary and #Description lines at top of lbl file
##
## Revision 1.18  2001/06/13 18:24:10  gawthrop
## Made "lin" default in place of "none"
## Still needs arg and cr alias clashes to be sorted ....
##
## Revision 1.17  2001/06/13 10:41:06  gawthrop
## Further changes towards aouto creation of lbl files.
## Prettified lbl files
##
## Revision 1.16  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.15  2001/06/11 16:53:49  gawthrop
## Now uses abg2sympar_m2txt to get the arguments
##
## Revision 1.14  2001/06/11 15:06:58  gawthrop
## Now handles user-defined components
##
## Revision 1.13  2001/06/04 08:13:37  gawthrop
## Various changes to support PPP
##
## Revision 1.12  2001/05/08 15:18:10  gawthrop
## Added trig and hyperbolic functions to argument exclusion list
##
## Revision 1.11  2000/09/19 11:14:30  peterg
## Now writes the first component type header correctely
##
## Revision 1.10  2000/01/26 10:11:10  peterg
## Added I component
##
## Revision 1.9  1999/11/10 00:47:08  peterg
## Replaced ifs by a table of cr/arg information
##
## Revision 1.8  1999/11/09 22:32:41  peterg
## Under RCS ready for using arrays to contaain defaults.
##
## Revision 1.7  1998/07/04 10:37:21  peterg
## Major revision to include:
## 	aliases
## 	new Style
## 	prettyfied
##
## Revision 1.6  1998/03/05 10:09:47  peterg
## Corrected bug in writing "other" components
##
## Revision 1.5  1998/03/02 09:26:18  peterg
## Now does default CR and args for the basic components only
## SS,I,R,C,GY,TF
## C now has a default of effort input.
##
## Revision 1.4  1998/02/23 16:20:33  peterg
## Summary line just contains the model name
##
## Revision 1.3  1997/05/09 14:21:35  peterg
## Default to flow,component_name
##
# Revision 1.2  1997/03/19  12:08:01  peterg
# No longer writes out non-unique names - now done in rbg_fig2m
#
# Revision 1.1  1997/03/18  13:55:01  peterg
# Initial revision
#
###############################################################


# P.J.Gawthrop March 1997
# Copyright (c) P.J.Gawthrop, 1997
# Copyright (C) 2002 by Peter J. Gawthrop

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

if [ -n "$sensitivity" ]; then
    sys="-s ${system}"
    sensitivity_switch=" -s "
else
    sys=${system}
fi

# Remove unwanted files
rm -f abg2lbl_fig2txt.log
rm -f $infofile
rm -f mtt_junk*

## Create lbl files beneath this one
mtt -q -u -l 1 ${sys} sub sh # Create the list
sh $1_sub.sh "echo mtt -q -l 1 ${sensitivity_switch}" " lbl txt" | sh

if [ -f "$1_lbl.txt" ]; then
  ##echo "$1_lbl.txt exists in `pwd` - no action taken"
  exit
##else 
  ##echo "$1_lbl.txt dosn not exist in `pwd` "
fi

#Inform user
if [ -n "$sensitivity" ]; then
    echo "Creating ${outfile} (sensitivity version)"
else
    echo "Creating ${outfile}"
fi

write_header()

{
cat<<EOF
#SUMMARY ${system}
#DESCRIPTION Detailed description here

## System ${system}, representation lbl, language txt
## File ${system}_lbl.txt
## Generated by MTT on `date`

EOF
cat $MTT_DOC/mtt_banner.sh


}

write_blurb()
{
cat <<EOF

## Each line should be of one of the following forms:
##	     a comment (ie starting with #)
##	     component-name	cr_name	arg1,arg2,..argn
##	     blank

## ---- Component labels ----
EOF
}

create_lbl_body()
{


#Write out the outline lbl file
grep -v  '\[[0-9]*\]'  $1_cmp.txt | \
gawk --field-separator ':' '
 BEGIN {
    OldComponent="None";
    default_cr = "lin";
 }
 { 
  Component = $1;
  Name = $2;
  Arg = $3;

##Aliases
  if (Component == "SS") {
    port_alias[++j] = Name;
  }
  else {
    alias[++i] = Name;
    if (length(sensitivity)>0) {
      s_arg = sprintf("%ss",Name);
      alias[++i] = s_arg;
      s_arg = sprintf(";%s",s_arg);
      Component_type = Component;
      Component = substr(Component,2);
      lin = "slin"
    }
   else {
      Component_type = Component;
      lin = "lin";
    }
  
 }

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

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

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

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

    cr["INTF"] = lin;  arg["INTF"]  = "";

    cr["CS"] = "lin";  arg["CS"]  = sprintf("effort,%s;%s_x0%s", Name, Name, s_arg);
    cr["IS"] = "lin";  arg["IS"]  = sprintf("flow,%s;%s_x0%s", Name, Name, s_arg);
    cr["INTFS"] = "lin";  arg["INTFS"]  = sprintf("%s_x0%s", Name, s_arg);

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

    ##cr["EMTF"] = sprintf("%s", Name);  arg["EMTF"]  = sprintf("l%s",  s_arg);
    cr["EMTF"] = "lin";  arg["EMTF"]  = sprintf("flow,%s%s", Name, s_arg);

    cr["AE"] = "lin";  arg["AE"]  = sprintf("%s%s", Name, s_arg);
    cr["AF"] = "lin";  arg["AF"]  = sprintf("%s%s", Name, s_arg);
    cr["AEf"] = "lin";  arg["AEf"]  = sprintf("%s%s", Name, s_arg);
    cr["AFe"] = "lin";  arg["AFe"]  = sprintf("%s%s", Name, s_arg);

    cr["CDx"] = "lin";  arg["CDx"]  = sprintf("%s%s", Name, s_arg);


    cr["FMR"] = lin;  arg["FMR"]  = sprintf("effort,%s%s", Name, s_arg);

    cr["RS"] = lin;  arg["RS"]  = sprintf("flow,%s%s", Name, s_arg);
    cr["RT"] = lin;  arg["RT"]  = sprintf("flow,%s%s", Name, s_arg);
    cr["CT"] = lin;  arg["CT"]  = sprintf("effort,%s%s", Name, s_arg);

    ## Put in the explicit arguments
    if (length(Arg)>0) {
      arg[Component] = Arg;
      if (match(Arg,"=")>0) # Its an equation type cr
        cr[Component] = "cr"
      else # assume a linear cr
        cr[Component] = "lin";
    }

  ## Print component header 
  if (Component != OldComponent) print "\n## Component type", Component_type

  ## Print Component
    printf("\t%s\t", Name);
    if (Component in cr)
      printf("%s\t\t", cr[Component])
    else 
      printf("%s\t\t", default_cr);

   if (Component in arg)
      printf("%s\t\t\n", arg[Component])
    else {
	print "lbl2args_txt2out", Component_type | "/bin/sh"; close("/bin/sh")
    }

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

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

create_arg_aliases()
{
cat <<EOF

## Argument aliases
EOF
abg2sympar_m2txt ${system} ${system} use_label_file |\
gawk '{printf("#ALIAS\t$%i\t%s\n", ++i, $1)}'
}

## Main 

create_lbl_body $1> $1_lbl.txt
create_arg_aliases > mtt_args.txt # using $1_lbl.txt
mv $1_lbl.txt mtt_junk_lbl.txt

write_header            > ${outfile}
cat mtt_junk_alias.txt >> ${outfile}
cat mtt_args.txt       >> ${outfile}
write_blurb            >> ${outfile}
cat mtt_junk_lbl.txt   >> ${outfile}
## Put a blank line at end
cat >> ${outfile} <<EOF

EOF
## Clean up
rm -f mtt_junk*






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