Differences From Artifact [9dabba8c1b]:

To Artifact [2aec5bf1c2]:


9
10
11
12
13
14
15





16
17
18
19
20
21
22
# Acausal bond graph to causal bond graph: mfile format

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$





## 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







>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Acausal bond graph to causal bond graph: mfile format

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## 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
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

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

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



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


## Create lbl files beneath this one
mtt -q -u -l 1 $1 sub sh # Create the list
sh $1_sub.sh "abg2lbl_fig2txt "

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 $1_lbl.txt (sensitivity version)"
else
    echo "Creating $1_lbl.txt"
fi


	( \



	echo "%% Label file for system $1 ($1_lbl.txt)"; \

	echo "%SUMMARY $1"; \
	echo "%DESCRIPTION "; \

	cat $MTTPATH/trans/m/rcs_header.txt; \

        )>mtt_junk_top.txt


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


        )> mtt_junk_blurb.txt


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

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

#Write out the outline lbl file
grep -v  '\[[0-9]*\]'  $1_unique_raw_list | \
awk --field-separator ':' '
 BEGIN {
    OldComponent="None";
 }
 { 
  Component = $1;
  Name = $2;
  name = Name;
  gsub(/[()-+*/]/,"",name); # Remove maths

##Aliases
  if (Component == "SS") {
    port_alias[++j] = Name;
  }
  else {
    alias[++i] = Name;







>
>







<














|

|


>
|
>
>
>
|
>
|
<
>
|
>
|
>
|
|
|
|
|
|
|
|
|
>
>
|
>
|



















|
<







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

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

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

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


## Create lbl files beneath this one
mtt -q -u -l 1 $1 sub sh # Create the list
sh $1_sub.sh "abg2lbl_fig2txt "

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
## System ${system}, representation lbl, language txt
## File ${system}_lbl.txt
## Generated by MTT on `date`


EOF
cat $MTT_DOC/mtt_version.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()
{
awk '/:/ {print $NF}' $1_abg.fig | \
sed 's/\\001//' | \
sort | \
tee $1_raw_list | \
sort -u> $1_unique_raw_list

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

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


##Aliases
  if (Component == "SS") {
    port_alias[++j] = Name;
  }
  else {
    alias[++i] = Name;
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
    cr["AF"] = "lin";  arg["AF"]  = sprintf("%s%s", Name, s_arg);

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


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










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

  ## Component
    printf("\t%s\t", name);
    if (Component in cr)
      printf("%s\t\t", cr[Component])
    else 
      printf("none\t\t");

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

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

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


## Create argument aliases

cat > mtt_junk_arg_alias.txt<<EOF

# Argument aliases
EOF

abg2sympar_m2txt $1 "" use_label_file |\
 awk '{printf("#ALIAS $%i %s\n", ++i, $1)}' >> mtt_junk_arg_alias.txt

mv  $1_lbl.txt mtt_junk_body.txt



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



















>
>
>
>
>
>
>

>

|


|














|




|

|







|
|

|
>
|

|



|
|
|
>

>
|
>
>
>
>
>
>
>
>
>



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
    cr["AF"] = "lin";  arg["AF"]  = sprintf("%s%s", Name, s_arg);

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


    cr["RS"] = lin;  arg["RS"]  = sprintf("flow,%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";

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

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

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

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

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

create_args()
{
cat <<EOF

## Argument aliases
EOF

abg2sympar_m2txt $1 "" use_label_file |\
 awk '{printf("#ALIAS\t$%i\t%s\n", ++i, $1)}'
}

## Main 

create_lbl_body $1> mtt_junk_lbl.txt

write_header            > ${outfile}
cat mtt_junk_alias.txt >> ${outfile}
create_args mtt_junk   >> ${outfile}
write_blurb            >> ${outfile}
cat mtt_junk_lbl.txt   >> ${outfile}

## Clean up
rm -f mtt_junk*





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