/[ascend]/trunk/ascend4/bin/convertoutput.pl
ViewVC logotype

Contents of /trunk/ascend4/bin/convertoutput.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (17 years, 2 months ago) by aw0a
File MIME type: text/x-perl
File size: 3563 byte(s)
Setting up web subdirectory in repository
1 #!/usr/local/bin/perl
2
3 # This program opens a file called lookup and uses
4 # it to convert the gams output with substitute
5 # variables into gams output with real variables.
6 # The command line for this program is as follows:
7 # convertoutput <filename> <simulation_name>
8 #
9 # $Revision: 1.2 $
10 # $Author: ballan $
11 # $Date: 1997/07/05 14:12:08 $
12 #
13
14 $filename = shift(@ARGV);
15 $sim = shift(@ARGV);
16
17 # split the list filename into the base and its extension
18 ($base,$extension) = split(/\./,$filename);
19
20 # concatenate the base with the extension .con
21 $outfile = $base."\.con";
22
23 open(OUTPUT, ">$outfile");
24 open(INPUT, "$filename");
25
26 # need to open the look-up table for the variables
27
28 # concatenate the base the the extensions .gms and .lk
29 # this is the format of the lookup file name as set in
30 # ascend2gms.pl
31 $lookup = $base."\.gms\.lk";
32
33
34 while (<INPUT>) {
35
36 # set some switches so you know where you are in the file you are parsing
37 if (/^.*VAR /){
38 $convert = 1;
39 $display = 0;
40 }else{
41 $convert = 0;
42 }
43
44 if (/^.*VARIABLE /){
45 $convert = 0;
46 $display = 1;
47 }else{
48 $display = 0;
49 }
50
51 # if we are in the variables section
52 if($convert == 1){
53
54 # the lines being read are of the form
55 # ---- VAR x 0 .5 1 .23
56 # these lines are split and the parts are saved in the appropriate variables
57 ($spacer, $type, $dummy, $lower, $level, $upper, $marginal) = split(' ', $_);
58
59 if($dummy == Z1) {
60 # since z1 is the actual variable, don't change it
61 $actual = $dummy;
62 }
63
64 $outerlinenum = 0;
65
66 # concatenate the dummy variable with a return
67 $dummy = $dummy."\n";
68
69 # open the lookup table
70 open(TABLE, "$lookup");
71 while (<TABLE>) {
72 $outerlinenum = $outerlinenum + 1;
73 $innerlinenum = 0;
74
75 # count the number of lines in the lookup table until we find the dummy variable
76 if(/^$dummy/i){
77 # open the lookup table again and go to the line number before the dummy variable
78 open(TABLE, "$lookup");
79 while(<TABLE>) {
80 $innerlinenum = $innerlinenum + 1;
81 if($innerlinenum == $outerlinenum - 1){
82
83 # set the actual variable to that at the corresponding line
84 $actual = $_;
85 }
86 }
87 }
88 }
89
90 # remove the return character from the variable
91 chop($actual);
92
93 # format the output so it is easy to read
94 format OUTPUT =
95 @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>>
96 $actual,$lower,$level,$upper,$marginal
97 .
98 write OUTPUT;
99 }elsif($display == 1){
100 ($type, $dummyplusextension, $equalsign, $level) = split(' ', $_);
101 $outerlinenum = 0;
102 ($dummy,$extension) = split(/\./,$dummyplusextension);
103 $dummy = $dummy."\n";
104 open(TABLE, "$lookup");
105 while (<TABLE>) {
106 $outerlinenum = $outerlinenum + 1;
107 $innerlinenum = 0;
108 if(/^$dummy/i){
109 open(TABLE, "$lookup");
110 while(<TABLE>) {
111 $innerlinenum = $innerlinenum + 1;
112 if($innerlinenum == $outerlinenum - 1){
113 $actual = $_;
114 }
115 }
116 }
117 }
118 chop($actual);
119 # with the format of the output, you can directly cut and paste into the script window
120 # this currently assumes that your simulation was called t1
121 print OUTPUT "ASSIGN {",$sim,".",$actual,"}"," ",$level,";\n";
122 }else{
123 print OUTPUT $_;
124 }
125 }
126

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22