File Coverage

blib/lib/Sim/OPT/Morph.pm
Criterion Covered Total %
statement 78 2474 3.1
branch 2 608 0.3
condition 0 120 0.0
subroutine 24 72 33.3
pod 0 49 0.0
total 104 3323 3.1


line stmt bran cond sub pod time code
1             package Sim::OPT::Morph;
2             # Copyright (C) 2008-2014 by Gian Luca Brunetti and Politecnico di Milano.
3             # This is the module Sim::OPT::Morph of Sim::OPT, a program for detailed metadesign managing parametric explorations through the ESP-r building performance simulation platform and performing optimization by block coordinate descent.
4             # This 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, version 2.
5              
6 1     1   11 use v5.14;
  1         2  
  1         38  
7 1     1   4 use Exporter;
  1         1  
  1         33  
8 1     1   4 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
  1         2  
  1         70  
9 1     1   5 use Math::Trig;
  1         1  
  1         193  
10 1     1   5 use Math::Round;
  1         1  
  1         45  
11 1     1   4 use List::Util qw[ min max reduce shuffle];
  1         1  
  1         57  
12 1     1   4 use List::MoreUtils qw(uniq);
  1         1  
  1         6  
13 1     1   336 use List::AllUtils qw(sum);
  1         2  
  1         40  
14 1     1   4 use Statistics::Basic qw(:all);
  1         1  
  1         6  
15 1     1   412 use Set::Intersection;
  1         2  
  1         75  
16 1     1   5 use List::Compare;
  1         2  
  1         15  
17 1     1   3 use IO::Tee;
  1         1  
  1         38  
18 1     1   4 use Data::Dumper;
  1         1  
  1         34  
19 1     1   3 use Sim::OPT;
  1         1  
  1         40  
20 1     1   377 use Sim::OPT::Sim;
  1         3  
  1         110  
21 1     1   8 use Sim::OPT::Retrieve;
  1         2  
  1         50  
22 1     1   4 use Sim::OPT::Report;
  1         2  
  1         34  
23 1     1   4 use Sim::OPT::Descend;
  1         1  
  1         29  
24 1     1   4 use Sim::OPT::Takechance;
  1         2  
  1         32  
25             #$Data::Dumper::Indent = 0;
26             #$Data::Dumper::Useqq = 1;
27             #$Data::Dumper::Terse = 1;
28 1     1   4 use Data::Dump qw(dump);
  1         1  
  1         34  
29 1     1   4 use feature 'say';
  1         1  
  1         63  
30              
31 1     1   4 no strict;
  1         65  
  1         28  
32 1     1   4 no warnings;
  1         1  
  1         30667  
33              
34             @ISA = qw(Exporter); # our @adamkISA = qw(Exporter);
35             #%EXPORT_TAGS = ( DEFAULT => [qw( &opt &prepare )]); # our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
36             #@EXPORT_OK = qw(); # our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
37              
38             @EXPORT = qw(
39             morph translate translate_surfaces_simple translate_surfaces rotate_surface translate_vertices shift_vertices rotate
40             rotatez make_generic_change reassign_construction change_thickness obs_modify bring_obstructions_back
41             recalculateish daylightcalc daylightcalc_other change_config checkfile change_climate recalculatenet apply_constraints
42             reshape_windows warp constrain_geometry read_geometry read_geo_constraints apply_geo_constraints vary_controls
43             calc_newctl checkfile constrain_controls read_controls read_control_constraints apply_loopcontrol_changes
44             apply_flowcontrol_changes constrain_obstructions read_obstructions read_obs_constraints apply_obs_constraints
45             vary_net read_net apply_node_changes
46             apply_component_changes constrain_net read_net_constraints propagate_constraints
47             ); # our @EXPORT = qw( );
48              
49             $VERSION = '0.40.11'; # our $VERSION = '';
50              
51              
52              
53             sub morph
54             {
55 0     0 0 0 my $swap = shift; #say $tee "swapINMORPH: " . dump($swap);
56 0         0 my %dat = %$swap;
57 0         0 my @instances = @{ $dat{instances} }; #say "scalar(\@instances): " . scalar(@instances);
  0         0  
58 0         0 my $countcase = $dat{countcase}; #say "dump(\$countcase): " . dump($countcase); # IT WILL BE SHADOWED. CUT ZZZ
59 0         0 my $countblock = $dat{countblock}; #say "dump(\$countblock): " . dump($countblock); # IT WILL BE SHADOWED. CUT ZZZ
60 0         0 my %dirfiles = %{ $dat{dirfiles} }; #say "dump(\%dirfiles): " . dump(%dirfiles);
  0         0  
61            
62 0         0 $configfile = $main::configfile; #say "dump(\$configfile): " . dump($configfile);
63 0         0 @sweeps = @main::sweeps; #say "dump(\@sweeps): " . dump(@sweeps);
64 0         0 @varinumbers = @main::varinumbers; #say "dump(\@varinumbers): " . dump(@varinumbers);
65 0         0 @mediumiters = @main::mediumiters;
66 0         0 @rootnames = @main::rootnames; #say "dump(\@rootnames): " . dump(@rootnames);
67 0         0 %vals = %main::vals; #say "dump(\%vals): " . dump(%vals);
68            
69 0         0 $mypath = $main::mypath; #say $tee "dumpINMORPH(\$mypath): " . dump($mypath);
70 0         0 $exeonfiles = $main::exeonfiles; #say $tee "dumpINMORPH(\$exeonfiles): " . dump($exeonfiles);
71 0         0 $generatechance = $main::generatechance;
72 0         0 $file = $main::file;
73 0         0 $preventsim = $main::preventsim;
74 0         0 $fileconfig = $main::fileconfig; #say $tee "dumpINMORPH(\$fileconfig): " . dump($fileconfig); # NOW GLOBAL. TO MAKE IT PRIVATE, FIX PASSING OF PARAMETERS IN CONTRAINTS PROPAGATION SECONDARY SUBROUTINES
75 0         0 $outfile = $main::outfile;
76 0         0 $toshell = $main::toshell;
77 0         0 $report = $main::report;
78 0         0 $simnetwork = $main::simnetwork;
79            
80 0         0 $tee = new IO::Tee(\*STDOUT, ">>$toshell"); # GLOBAL ZZZ
81            
82 0 0       0 open ( OUTFILE, ">>$outfile" ) or die "Can't open $outfile: $!";
83 0 0       0 open ( TOSHELL, ">>$toshell" ) or die "Can't open $toshell: $!";
84 0         0 say $tee "\n# Now in Sim::OPT::Morph.\n";
85            
86 0         0 %dowhat = %main::dowhat;
87              
88 0         0 @themereports = @main::themereports; #say "dumpINMORPH(\@themereports): " . dump(@themereports);
89 0         0 @simtitles = @main::simtitles; #say "dumpINMORPH(\@simtitles): " . dump(@simtitles);
90 0         0 @reporttitles = @main::reporttitles;
91 0         0 @simdata = @main::simdata;
92 0         0 @retrievedata = @main::retrievedata;
93 0         0 @keepcolumns = @main::keepcolumns;
94 0         0 @weights = @main::weights;
95 0         0 @weightsaim = @main::weightsaim;
96 0         0 @varthemes_report = @main::varthemes_report;
97 0         0 @varthemes_variations = @vmain::arthemes_variations;
98 0         0 @varthemes_steps = @main::varthemes_steps;
99 0         0 @rankdata = @main::rankdata; # CUT ZZZ
100 0         0 @rankcolumn = @main::rankcolumn;
101 0         0 @reporttempsdata = @main::reporttempsdata;
102 0         0 @reportcomfortdata = @main::reportcomfortdata;
103 0         0 @reportradiationenteringdata = @main::reportradiationenteringdata;
104 0         0 @report_loadsortemps = @main::report_loadsortemps;
105 0         0 @files_to_filter = @main::files_to_filter;
106 0         0 @filter_reports = @main::filter_reports;
107 0         0 @base_columns = @main::base_columns;
108 0         0 @maketabledata = @main::maketabledata;
109 0         0 @filter_columns = @main::filter_columns;
110            
111 0         0 my @simcases = @{ $dirfiles{simcases} }; #say "dump(\@simcases): " . dump(@simcases);
  0         0  
112 0         0 my @simstruct = @{ $dirfiles{simstruct} }; #say "dump(\@simstruct): " . dump(@simstruct);
  0         0  
113 0         0 my @morphcases = @{ $dirfiles{morphcases} };
  0         0  
114 0         0 my @morphstruct = @{ $dirfiles{morphstruct} };
  0         0  
115 0         0 my @retcases = @{ $dirfiles{retcases} };
  0         0  
116 0         0 my @retstruct = @{ $dirfiles{retstruct} };
  0         0  
117 0         0 my @repcases = @{ $dirfiles{repcases} };
  0         0  
118 0         0 my @repstruct = @{ $dirfiles{repstruct} };
  0         0  
119 0         0 my @mergecases = @{ $dirfiles{mergecases} };
  0         0  
120 0         0 my @mergestruct = @{ $dirfiles{mergestruct} };
  0         0  
121 0         0 my @descendcases = @{ $dirfiles{descendcases} };
  0         0  
122 0         0 my @descendstruct = @{ $dirfiles{descendstruct} };
  0         0  
123            
124 0         0 my $morphlist = $dirfiles{morphlist}; #say "dump(\$dat{morphlist}): " . dump($dat{morphlist});
125 0         0 my $morphblock = $dirfiles{morphblock};
126 0         0 my $simlist = $dirfiles{simlist}; #say "dump(\$simlist): " . dump($simlist);
127 0         0 my $simblock = $dirfiles{simblock};
128 0         0 my $retlist = $dirfiles{retlist};
129 0         0 my $retblock = $dirfiles{retblock};
130 0         0 my $replist = $dirfiles{replist};
131 0         0 my $repblock = $dirfiles{repblock};
132 0         0 my $descendlist = $dirfiles{descendlist};
133 0         0 my $descendblock = $dirfiles{descendblock};
134            
135             #my $getpars = shift;
136             #eval( $getpars );
137              
138             #if ( fileno (MORPHLIST)
139            
140 0         0 $countinstance = 1;
141 0         0 foreach my $instance (@instances)
142             {
143 0         0 my %d = %{$instance};
  0         0  
144 0         0 my $countcase = $d{countcase}; say $tee "#dump(\$countcase): " . dump($countcase);
  0         0  
145 0         0 my $countblock = $d{countblock}; say $tee "#dump(\$countblock): " . dump($countblock);
  0         0  
146 0         0 my @miditers = @{ $d{miditers} }; say $tee "#MORPH dump(\@miditers): " . dump(@miditers);
  0         0  
  0         0  
147 0         0 my @winneritems = @{ $d{winneritems} }; say $tee "#dumpIN( \@winneritems) " . dump(@winneritems);
  0         0  
  0         0  
148 0         0 my $countvar = $d{countvar}; say $tee "#dump(\$countvar): " . dump($countvar);
  0         0  
149 0         0 my $countstep = $d{countstep}; say $tee "#dump(\$countstep): " . dump($countstep);
  0         0  
150 0         0 my $to = $d{to}; #say $tee "dump(\$to): " . dump($to);
151 0         0 my $origin = $d{origin}; say $tee "#dump(\$origin): " . dump($origin);
  0         0  
152 0         0 my @uplift = @{ $d{uplift} }; say $tee "#dump(\@uplift): " . dump(@uplift);
  0         0  
  0         0  
153             #eval($getparshere);
154            
155 0         0 my $rootname = Sim::OPT::getrootname(\@rootnames, $countcase); say $tee "#dump(\$rootname): " . dump($rootname);
  0         0  
156 0         0 my @blockelts = Sim::OPT::getblockelts(\@sweeps, $countcase, $countblock); say $tee "#dumpIN( \@blockelts) " . dump(@blockelts);
  0         0  
157 0         0 my @blocks = Sim::OPT::getblocks(\@sweeps, $countcase); say $tee "#dumpIN( \@blocks) " . dump(@blocks);
  0         0  
158 0         0 my $toitem = Sim::OPT::getitem(\@winneritems, $countcase, $countblock); say $tee "#dump(\$toitem): " . dump($toitem);
  0         0  
159 0         0 my $from = Sim::OPT::getline($toitem); say $tee "#dumpIN(\$from): " . dump($from);
  0         0  
160 0         0 my %varnums = Sim::OPT::getcase(\@varinumbers, $countcase); say $tee "#dumpIN---(\%varnums): " . dump(%varnums);
  0         0  
161 0         0 my %mids = Sim::OPT::getcase(\@miditers, $countcase); say $tee "#dumpIN---(\%mids): " . dump(%mids);
  0         0  
162             #eval($getfly);
163            
164 0         0 my $stepsvar = Sim::OPT::getstepsvar($countvar, $countcase, \@varinumbers); #say $tee "#dump(\$stepsvar): " . dump($stepsvar);
165 0         0 my $varnumber = $countvar; #say $tee "#dump---(\$varnumber): " . dump($varnumber) . "\n\n"; # LEGACY VARIABLE
166            
167 0         0 my $countcaseplus1 = ( $countcase + 1);
168 0         0 my $countblockplus1 = ( $countblock + 1);
169            
170             #@totblockelts = (@totblockelts, @blockelts); # @blockelts
171             #@totblockelts = uniq(@totblockelts);
172             #@totblockelts = sort(@totblockelts);
173             #if ( $countvar == $#blockelts )
174             #{
175             # $$general_variables[0] = "n";
176             #} # THIS TELLS THAT IF THE SEARCH IS ENDING (LAST SUBSEARCH CYCLE) GENERATION OF CASES HAS TO BE TURNED OFF
177             ####### OLD. $stepsvar = ${ "varnums{$countvar}" . "$varnumber" };
178            
179 0         0 my @applytype = @{ $vals{$countvar}{applytype} }; #say "dump(\@applytype): " . dump(@applytype);
  0         0  
180 0         0 my $general_variables = $vals{$countvar}{general_variables}; #say "dump(\$general_variables): " . dump($general_variables);
181 0         0 my @generic_change = @{$vals{$countvar}{generic_change} };
  0         0  
182 0         0 my $rotate = $vals{$countvar}{rotate};
183 0         0 my $rotatez = $vals{$countvar}{rotatez};
184 0         0 my $translate = $vals{$countvar}{translate}; #say "dump(\$translate): " . dump($translate);
185 0         0 my $translate_surface_simple = $vals{$countvar}{translate_surface_simple};
186 0         0 my $translate_surface = $vals{$countvar}{translate_surface};
187 0         0 my $keep_obstructions = $vals{$countvar}{keep_obstructions};
188 0         0 my $shift_vertices = $vals{$countvar}{shift_vertices};
189 0         0 my $construction_reassignment = $vals{$countvar}{construction_reassignment};
190 0         0 my $thickness_change = $vals{$countvar}{thickness_change};
191 0         0 my $recalculateish = $vals{$countvar}{recalculateish};
192 0         0 my @recalculatenet = @{ $vals{$countvar}{recalculatenet} };
  0         0  
193 0         0 my $obs_modify = $vals{$countvar}{obs_modify};
194 0         0 my $netcomponentchange = $vals{$countvar}{netcomponentchange};
195 0         0 my $changecontrol = $vals{$countvar}{changecontrol};
196 0         0 my @apply_constraints = @{ $vals{$countvar}{apply_constraints} }; # NOW SUPERSEDED BY @constrain_geometry
  0         0  
197 0         0 my $rotate_surface = $vals{$countvar}{rotate_surface};
198 0         0 my @reshape_windows = @{ $vals{$countvar}{reshape_windows} };
  0         0  
199 0         0 my @apply_netconstraints = @{ $vals{$countvar}{apply_netconstraints} };
  0         0  
200 0         0 my @apply_windowconstraints = @{ $vals{$countvar}{apply_windowconstraints} };
  0         0  
201 0         0 my @translate_vertices = @{ $vals{$countvar}{translate_vertices} };
  0         0  
202 0         0 my $warp = $vals{$countvar}{warp};
203 0         0 my @daylightcalc = @{ $vals{$countvar}{daylightcalc} };
  0         0  
204 0         0 my @change_config = @{ $vals{$countvar}{change_config} };
  0         0  
205 0         0 my @constrain_geometry = @{ $vals{$countvar}{constrain_geometry} };
  0         0  
206 0         0 my @vary_controls = @{ $vals{$countvar}{vary_controls} };
  0         0  
207 0         0 my @constrain_controls = @{ $vals{$countvar}{constrain_controls} };
  0         0  
208 0         0 my @constrain_obstructions = @{ $vals{$countvar}{constrain_obstructions} };
  0         0  
209 0         0 my @get_obstructions = @{ $vals{$countvar}{get_obstructions} };
  0         0  
210 0         0 my $checkfile = $vals{$countvar}{checkfile};
211 0         0 my @vary_net = @{ $vals{$countvar}{vary_net} };
  0         0  
212 0         0 my @constrain_net = @{ $vals{$countvar}{constrain_net} };
  0         0  
213 0         0 my @propagate_constraints = @{ $vals{$countvar}{propagate_constraints} };
  0         0  
214 0         0 my @change_climate = @{ $vals{$countvar}{change_climate} };
  0         0  
215 0         0 my $skip = $vals{$countvar}{skip};
216 0         0 my $constrain = $vals{$countvar}{constrain};
217            
218 0         0 my ( @cases_to_sim, @files_to_convert );
219 0         0 my ( @obs, @node, @component, @loopcontrol, @flowcontrol ); # THINGS globsAL AS REGARDS TO COUNTER ZONE CYCLES
220 0         0 my ( @myobs, @mynode, @mycomponent, @myloopcontrol, @myflowcontrol); # THINGS LOCAL AS REGARDS TO COUNTER ZONE CYCLES
221 0         0 my ( @tempv, @tempobs, @tempnode, @tempcomponent, @temploopcontrol, @tempflowcontrol); # THINGS LOCAL AS REGARDS TO COUNTER ZONE CYCLES
222 0         0 my ( @v_, @doobs, @donode, @docomponent, @doloopcontrol, @doflowcontrol); # THINGS LOCAL AS REGARDS TO COUNTER ZONE CYCLES
223            
224 0         0 my $generate = $$general_variables[0];
225 0         0 my $sequencer = $$general_variables[1];
226 0         0 my $dffile = "df-$file.txt";
227            
228             #my $toshellmorph = "$toshell" . "-1morph.txt";
229             #my $outfilemorph = "$outfile" . "-1morph.txt";
230            
231             #open ( TOSHELL, ">>$toshellmorph" );
232             #open ( OUTFILE, ">>$outfilemorph" );
233            
234 0 0 0     0 if ( ( $countblock == 0 ) and ( $countstep == 1 ) )
235             {
236 0 0       0 if (not ( -e "$origin" ) )
237             {
238 0 0       0 if ($exeonfiles eq "y")
239             {
240 0         0 print `cp -R $mypath/$file $from`; #say "FROM: $from";
241             }
242 0         0 say TOSHELL "cp -R $mypath/$file $from\n";
243             }
244             }
245            
246             #if ( fileno (RETLIST) )
247             #if (not (-e $morphlist ) )
248             #{
249             # if ( $countblock == 0 )
250             # {
251 0         0 open ( MORPHLIST, ">>$morphlist"); # or die;
252             # }
253             # else
254             # {
255             # open ( MORPHLIST, ">>$morphlist"); # or die;
256             # }
257             #}
258            
259             #if ( fileno (MORPHBLOCK) )
260             #if (not (-e $morphblock ) )
261             #{
262             # if ( $countblock == 0 )
263             # {
264 0         0 open (MORPHBLOCK, ">>$morphblock");# or die;
265             # }
266             # else
267             # {
268             # open (MORPHBLOCK, ">>$morphblock");# or die;
269             # }
270             #}
271              
272 0         0 push ( @{ $morphstruct[$countcase][$countblock] }, $to );
  0         0  
273 0         0 print MORPHBLOCK "$to\n";
274 0 0       0 if ( not ( $to ~~ @morphcases ) )
275             {
276             #say "HERE2. MORPHCASES.";
277 0         0 push ( @morphcases, $to );
278 0         0 print MORPHLIST "$to\n";
279 0         0 say TOSHELL "from: $from, origin: $origin, to: $to";
280              
281             #my $from = "$case_to_sim";
282             #my $almost_to = $from;
283             #$almost_to =~ s/$varnumber-\d+/$varnumber-$countstep/ ;
284             #if ( ( $generate eq "n" )
285             # and ( ( $sequencer eq "y" ) or ( $sequencer eq "last" ) ) )
286             #{
287             # if ( $almost_to =~ m/§$/ ) { $to = "$almost_to" ; }
288             # else
289             # {
290             # #$to = "$case_to_sim$varnumber-$countstep§";
291             # $to = "$almost_to" . "§";
292             # }
293             #}
294             #elsif ( ( $generate eq "y" ) and ( $sequencer eq "n" ) )
295             #{
296             # if ( $almost_to =~ m/_$/ ) { $to = "$almost_to" ; }
297             # else
298             # {
299             # $to = "$case_to_sim$varnumber-$countstep" . "_";
300             # $to = "$almost_to" . "_";
301             # if ( $countstep == $stepsvar )
302             # {
303             # if ($exeonfiles eq "y") { print `chmod -R 777 $from\n`; }
304             # print TOSHELL "chmod -R 777 $from\n\n";
305             # }
306             # }
307             #}
308             #elsif ( ( $generate eq "y" ) and ( $sequencer eq "y" ) )
309             #{
310             # #$to = "$case_to_sim$varnumber-$countstep" . "£";
311             # $to = "$almost_to" . "£";
312             #}
313             #elsif ( ( $generate eq "y" ) and ( $sequencer eq "last" ) )
314             #{
315             # if ( $almost_to =~ m/£$/ ) { $to = "$almost_to" ; }
316             # else
317             # {
318             # #$to = "$case_to_sim$varnumber-$countstep" . "£";
319             # $to = "$almost_to" . "£";
320             # #if ( $countstep == $stepsvar )
321             # #{
322             # # if ($exeonfiles eq "y") { print `chmod -R 777 $from\n`; }
323             # # print TOSHELL "chmod -R 777 $from\n\n";
324             # #}
325             # }
326             #}
327             #elsif ( ( $generate eq "n" ) and ( $sequencer eq "n" ) )
328             #{
329             # $almost_to =~ s/[_|£]$// ;
330             # #$to = "$case_to_sim$varnumber-$countstep";
331             # $to = "$almost_to";
332             #}
333            
334 0 0 0     0 if
335             #(
336             #( $generate eq "y" )
337             #and ( $countstep == $stepsvar )
338             #and ( ( $sequencer eq "n" ) or ( $sequencer eq "last" ) )
339             #and ( ($skip ne "") and ($skipask ne "yes") )
340             #and
341             ( ( not (-e $to) ) and ( not ( eval $skip) ) )
342             #)
343             {
344             #say TOSHELL "HERE2A. MAIN. ";
345            
346 0 0       0 if ($exeonfiles eq "y")
347             {
348 0         0 print `cp -R $origin $to\n`;
349             }
350 0         0 print TOSHELL "cp -R $origin $to\n\n";
351             #say "HERE2B";
352            
353 0         0 $countop = 0; # "$countop" IS THE COUNTER OF THE OPEATIONS
354 0         0 foreach my $op (@applytype) # "$op" MEANS OPERATION
355             {
356              
357 0         0 my $modification_type = $applytype[$countop][0];
358 0 0 0     0 if ( ( $applytype[$countop][1] ne $applytype[$countop][2] ) and ( $modification_type ne "changeconfig" ) )
359             {
360 0 0       0 if ($exeonfiles eq "y")
361             {
362 0         0 print `cp -f $to/zones/$applytype[$countop][1] $to/zones/$applytype[$countop][2]\n`;
363             }
364 0         0 print TOSHELL "cp -f $to/zones/$applytype[$countop][1] $to/zones/$applytype[$countop][2]\n\n";
365 0 0       0 if ($exeonfiles eq "y")
366             {
367 0         0 print `cp -f $to/cfg/$applytype[$countop][1] $to/cfg/$applytype[$countop][2]\n`;
368             } # ORDINARILY, THIS PART CAN BE REMOVED
369 0         0 print TOSHELL "cp -f $to/cfg/$applytype[$countop][1] $to/cfg/$applytype[$countop][2]\n\n";
370             }# ORDINARILY, THIS PART CAN BE REMOVED
371 0 0 0     0 if ( ( $applytype[$countop][1] ne $applytype[$countop][2] ) and ( $modification_type eq "changeconfig" ) )
372             {
373 0 0       0 if ($exeonfiles eq "y")
374             {
375 0         0 print `cp -f $to/cfg/$applytype[$countop][1] $to/cfg/$applytype[$countop][2]\n`;
376             }
377 0         0 print TOSHELL "cp -f $to/cfg/$applytype[$countop][1] $to/cfg/$applytype[$countop][2]\n\n";
378             } # ORDINARILY, THIS PART CAN BE REMOVED
379              
380            
381 0         0 print `cd $to`;
382 0         0 print TOSHELL "cd $to\n\n";
383            
384 0 0 0     0 if ( ( $stepsvar > 1) and ( not ( eval $skip) ) )
385             {
386             sub dothings
387             { # THIS CONTAINS FUNCTIONS THAT APPLY CONSTRAINTS AND UPDATE CALCULATIONS.
388             #if ( $get_obstructions[$countop][0] eq "y" )
389             #{
390             # get_obstructions # THIS IS TO MEMORIZE OBSTRUCTIONS.
391             # # THEY WILL BE SAVED IN A TEMPORARY FILE.
392             # ($to, $fileconfig, $stepsvar, $countop,
393             # $countstep, $exeonfiles, \@applytype, \@get_obstructions, $configfile, $countvar, $fileconfig );
394             #}
395 0     0 0 0 my ( $whatdone ) = @_;
396 0 0 0     0 if ( ( $propagate_constraints[$countop] ) and ( not ( $whatdone eq "done_constraint_propagation" ) ) )
397             {
398 0         0 &propagate_constraints
399             ($to, $stepsvar, $countop,
400             $countstep, \@applytype, \@propagate_constraints, $countvar, $fileconfig );
401             }
402 0 0 0     0 if ( ( $constrain_geometry[$countop] ) and ( not ( $whatdone eq "done_geo_constraint" ) ) )
403             {
404 0         0 @v_ = constrain_geometry
405             ( $to, $stepsvar, $countop,
406             $countstep, \@applytype, \@constrain_geometry, $countvar, $fileconfig, \@v_ );
407             }
408 0 0 0     0 if ( ( $constrain_controls[$countop] ) and ( not ( $whatdone eq "done_constrol_constraint" ) ) )
409             {
410 0         0 &constrain_controls
411             ( $to, $stepsvar, $countop,
412             $countstep, \@applytype, \@constrain_controls, $countvar, $fileconfig );
413             }
414 0 0 0     0 if ( ( $constrain_net[$countop] ) and ( not ( $whatdone eq "done_net_constraint" ) ) )
415             {
416 0         0 &constrain_net( $to, $stepsvar, $countop,
417             $countstep, \@applytype, \@constrain_net, $to_do, $countvar, $fileconfig );
418             }
419 0 0 0     0 if ( ( $constrain_obstructions[$countop] ) and ( not ( $whatdone eq "done_obs_constraint" ) ) )
420             {
421 0         0 &constrain_obstructions
422             ( $to, $stepsvar, $countop,
423             $countstep, \@applytype, \@constrain_obstructions, $to_do, $countvar, $fileconfig );
424             }
425 0 0       0 if ( $$keep_obstructions[$countop] )
426             {
427 0         0 &bring_obstructions_back( $to, $stepsvar, $countop,
428             $countstep, \@applytype, $keep_obstructions, $countvar, $fileconfig );
429             }
430 0 0       0 if ( $apply_constraints[$countop] )
431             {
432 0         0 &apply_constraints
433             ( $to, $stepsvar, $countop,
434             $countstep, \@applytype, \@apply_constraints, $countvar, $fileconfig );
435             }
436 0 0       0 if ( $recalculatenet[$countop] )
437             {
438 0         0 &recalculatenet
439             ( $to, $stepsvar, $countop,
440             $countstep, \@applytype, \@recalculatenet, $countvar, $fileconfig );
441             }
442 0 0       0 if ( $recalculateish eq "y" )
443             {
444 0         0 &recalculateish
445             ( $to, $stepsvar, $countop,
446             $countstep, \@applytype, \@recalculateish, $countvar, $fileconfig );
447             }
448 0 0       0 if ( $daylightcalc[0] eq "y" )
449             {
450 0         0 &daylightcalc
451             ( $to, $stepsvar, $countop,
452             $countstep, \@applytype, $filedf, \@daylightcalc, $countvar, $fileconfig );
453             }
454             } # END SUB DOTHINGS
455              
456 0 0       0 if ( $modification_type eq "generic_change" )#
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
457             {
458 0         0 &make_generic_change
459             ($to, $stepsvar, $countop, $countstep,
460             \@applytype, $generic_change, $countvar, $fileconfig );
461 0         0 &dothings;
462             } #
463             elsif ( $modification_type eq "surface_translation_simple" )
464             {
465 0         0 &translate_surfaces_simple
466             ($to, $stepsvar, $countop, $countstep,
467             \@applytype, $translate_surface_simple, $countvar, $fileconfig );
468 0         0 &dothings;
469             }
470             elsif ( $modification_type eq "surface_translation" )
471             {
472 0         0 &translate_surfaces
473             ($to, $stepsvar, $countop, $countstep,
474             \@applytype, $translate_surface, $countvar, $fileconfig );
475 0         0 &dothings;
476             }
477             elsif ( $modification_type eq "surface_rotation" ) #
478             {
479 0         0 &rotate_surface
480             ($to, $stepsvar, $countop, $countstep,
481             \@applytype, $rotate_surface, $countvar, $fileconfig );
482 0         0 &dothings;
483             }
484             elsif ( $modification_type eq "vertices_shift" )
485             {
486 0         0 &shift_vertices
487             ($to, $stepsvar, $countop, $countstep,
488             \@applytype, $shift_vertices, $countvar, $fileconfig );
489 0         0 &dothings;
490             }
491             elsif ( $modification_type eq "vertex_translation" )
492             {
493 0         0 &translate_vertices
494             ($to, $stepsvar, $countop, $countstep,
495             \@applytype, \@translate_vertices, $countvar, $fileconfig );
496 0         0 &dothings;
497             }
498             elsif ( $modification_type eq "construction_reassignment" )
499             {
500 0         0 &reassign_construction
501             ($to, $stepsvar, $countop, $countstep,
502             \@applytype, $construction_reassignment, $countvar, $fileconfig );
503 0         0 &dothings;
504             }
505             elsif ( $modification_type eq "rotation" )
506             {
507 0         0 &rotate
508             ($to, $stepsvar, $countop, $countstep,
509             \@applytype, $rotate, $countvar, $fileconfig );
510 0         0 &dothings;
511             }
512             elsif ( $modification_type eq "translation" )
513             {
514 0         0 &translate
515             ($to, $stepsvar, $countop, $countstep,
516             \@applytype, $translate, $countvar, $fileconfig );
517 0         0 &dothings;
518             }
519             elsif ( $modification_type eq "thickness_change" )
520             {
521 0         0 &change_thickness
522             ($to, $stepsvar, $countop, $countstep,
523             \@applytype, $thickness_change, $countvar, $fileconfig );
524 0         0 &dothings;
525             }
526             elsif ( $modification_type eq "rotationz" )
527             {
528 0         0 &rotatez
529             ($to, $stepsvar, $countop, $countstep,
530             \@applytype, $rotatez, $countvar, $fileconfig );
531 0         0 &dothings;
532             }
533             elsif ( $modification_type eq "change_config" )
534             {
535 0         0 &change_config
536             ($to, $stepsvar, $countop, $countstep,
537             \@applytype, \@change_config, $countvar, $fileconfig );
538 0         0 &dothings;
539             }
540             elsif ( $modification_type eq "window_reshapement" )
541             {
542 0         0 &reshape_windows
543             ($to, $stepsvar, $countop, $countstep,
544             \@applytype, \@reshape_windows, $countvar, $fileconfig );
545 0         0 &dothings;
546             }
547             elsif ( $modification_type eq "obs_modification" ) # REWRITE FOR NEW GEO FILE?
548             {
549 0         0 &obs_modify
550             ($to, $stepsvar, $countop, $countstep,
551             \@applytype, $obs_modify, $countvar, $fileconfig );
552 0         0 &dothings;
553             }
554             elsif ( $modification_type eq "warping" )
555             {
556 0         0 &warp
557             ($to, $stepsvar, $countop, $countstep,
558             \@applytype, $warp, $countvar, $fileconfig );
559 0         0 &dothings;
560             }
561             elsif ( $modification_type eq "vary_controls" )
562             {
563 0         0 &vary_controls
564             ($to, $stepsvar, $countop, $countstep,
565             \@applytype, \@vary_controls, $countvar, $fileconfig );
566 0         0 &dothings;
567             }
568             elsif ( $modification_type eq "vary_net" )
569             {
570 0         0 &vary_net
571             ($to, $stepsvar, $countop, $countstep,
572             \@applytype, \@vary_net, $countvar, $fileconfig );
573 0         0 &dothings;
574             }
575             elsif ( $modification_type eq "change_climate" )
576             {
577 0         0 &change_climate
578             ($to, $stepsvar, $countop, $countstep,
579             \@applytype, \@change_climate, $countvar, $fileconfig );
580 0         0 &dothings;
581             }
582             elsif ( $modification_type eq "vary_controls" )
583             {
584 0         0 &dothings( "done_control_constraint" );
585             }
586             elsif ( $modification_type eq "constrain_geometry" )
587             {
588 0         0 &dothings( "done_geo_constraint" );
589             }
590             elsif ( $modification_type eq "vary_net" )
591             {
592 0         0 &dothings( "done_net_constraint" );
593             }
594             elsif ( $modification_type eq "constrain_obstructions" )
595             {
596 0         0 &dothings( "done_obs_constraint" );
597             }
598             elsif ( $modification_type eq "propagate_constraints" )
599             {
600 0         0 &dothings( "done_constraint_propagation" );
601             }
602             }
603 0         0 $countop++;
604 0         0 print `cd $mypath`;
605 0         0 print TOSHELL "cd $mypath\n\n";
606             }
607             }
608             #else
609             #{
610             # if ($exeonfiles eq "y") { print `cp -R $origin $to\n`; }
611             # print TOSHELL "cp -R $origin $to\n\n";
612             #}
613             #push(@morphed, $to);
614             }
615 0         0 close MORPHLIST;
616 0         0 close MORPHBLOCK;
617 0         0 $countinstance++;
618             }
619 0         0 close TOSHELL;
620 0         0 close OUTFILE;
621 0         0 return (\@morphcases, \@morphsruct);
622             } # END SUB morph
623              
624              
625             sub translate
626             {
627 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $translate, $countvar, $fileconfig ) = @_;
628 0         0 my @applytype = @$swap;
629 0         0 my $zone_letter = $applytype[$countop][3];
630            
631 0         0 say "Translating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
632 0         0 say TOSHELL "#Translating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
633              
634 0 0       0 if ( $stepsvar > 1 )
635             {
636 0         0 my $yes_or_no_translate_obstructions = "$$translate[$countop][0]";
637 0         0 my $yes_or_no_update_radiation = $$translate[$countop][1];
638 0         0 my $configfile = $$translate[$countop][3];
639 0 0       0 if ( $yes_or_no_update_radiation eq "y" )
640             {
641 0         0 $yes_or_no_update_radiation = "a";
642             }
643             else
644             {
645 0         0 $yes_or_no_update_radiation = "c";
646             }
647              
648 0         0 my @coordinates_for_movement = @{ $$translate[$countop][1] };
  0         0  
649 0         0 my $x_end = $coordinates_for_movement[0];
650 0         0 my $y_end = $coordinates_for_movement[1];
651 0         0 my $z_end = $coordinates_for_movement[2];
652 0         0 my $x_swingtranslate = ( 2 * $x_end );
653 0         0 my $y_swingtranslate = ( 2 * $y_end );
654 0         0 my $z_swingtranslate = ( 2 * $z_end );
655 0         0 my $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
656 0         0 my $x_movement = (- ( $x_end - ( $x_pace * ( $countstep - 1 ) ) ));
657 0         0 my $y_pace = ( $y_swingtranslate / ( $stepsvar - 1 ) );
658 0         0 my $y_movement = (- ( $y_end - ( $y_pace * ( $countstep - 1 ) ) ));
659 0         0 my $z_pace = ( $z_swingtranslate / ( $stepsvar - 1 ) );
660 0         0 my $z_movement = (- ( $z_end - ( $z_pace * ( $countstep - 1 ) ) ));
661              
662 0         0 my $printthis =
663             "prj -file $to/cfg/$fileconfig -mode script<
664              
665             m
666             c
667             a
668             $zone_letter
669             i
670             e
671             $x_movement $y_movement $z_movement
672             y
673             $yes_or_no_translate_obstructions
674             -
675             y
676             c
677             -
678             -
679             -
680             -
681             -
682             -
683             -
684             -
685             -
686             YYY
687             ";
688              
689 0 0       0 if ($exeonfiles eq "y")
690             {
691 0         0 print `$printthis`;
692             }
693 0         0 print TOSHELL
694             "#Translating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.\"
695             $printthis
696             ";
697             }
698             } # end sub translate
699              
700             my $countcycles_transl_surfs = 0;
701              
702              
703             sub translate_surfaces
704             {
705 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $translate_surface, $countvar, $fileconfig ) = @_;
706 0         0 say TOSHELL "got \$to : " . dump($to); say TOSHELL "got \$stepsvar : " . dump($stepsvar);
  0         0  
707 0         0 say TOSHELL "got \$countop : " . dump($countop); say TOSHELL "got \$countstep : " . dump($countstep);
  0         0  
708 0         0 say TOSHELL "got \$swap : " . dump($swap); say TOSHELL "got \$translate_surface : " . dump($translate_surface);
  0         0  
709 0         0 say TOSHELL "got \$countvar : " . dump($countvar); say TOSHELL "got \$fileconfig : " . dump($fileconfig);
  0         0  
710            
711 0         0 my @applytype = @$swap; say TOSHELL "got \@applytype : " . dump(@applytype);
  0         0  
712 0         0 my $zone_letter = $applytype[$countop][3]; say TOSHELL "got \$zone_letter : " . dump($zone_letter);
  0         0  
713            
714 0         0 say "Translating surfaces for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
715              
716 0         0 my $transform_type = $$translate_surface[$countop][0]; say TOSHELL "got \$transform_type : " . dump($transform_type);
  0         0  
717 0         0 my @surfs_to_transl = @{ $translate_surface->[$countop][1] }; say TOSHELL "got \@surfs_to_transl : " . dump(@surfs_to_transl);
  0         0  
  0         0  
718 0         0 my @ends_movs = @{ $translate_surface->[$countop][2] }; say TOSHELL "got \@ends_movs : " . dump(@ends_movs); # end points of the movements.
  0         0  
  0         0  
719 0         0 my $yes_or_no_update_radiation = $$translate_surface[$countop][3]; say TOSHELL "got \$yes_or_no_update_radiation : " . dump($yes_or_no_update_radiation);
  0         0  
720 0         0 my @transform_coordinates = @{ $translate_surface->[$countop][4] }; say TOSHELL "got \@transform_coordinates : " . dump(@transform_coordinates);
  0         0  
  0         0  
721 0         0 my $countsurface = 0;
722 0         0 my ( $end_mov, $mov_surf, $pace, $movement, $surface_letter_constrainedarea, $movement_constrainedarea, $pace, $swing_surf, $movement );
723              
724 0         0 foreach my $surface_letter (@surfs_to_transl)
725 0         0 { say TOSHELL "got \$surface_letter : " . dump($surface_letter);
726 0         0 say TOSHELL "got \$stepsvar : " . dump($stepsvar);
727 0 0       0 if ( $stepsvar > 1 )
728             {
729 0         0 say TOSHELL "got \$transform_type : " . dump($transform_type);
730 0 0       0 if ($transform_type eq "a")
    0          
731             {
732 0         0 $end_mov = $ends_movs[$countsurface]; say TOSHELL "got \$end_mov : " . dump($end_mov); say TOSHELL "got \$countstep : " . dump($countstep);
  0         0  
  0         0  
733 0 0       0 if ( ref ( $end_mov ) )
734             {
735 0         0 my $min = $end_mov->[0]; say TOSHELL "FROM REF got \$min : " . dump($min);
  0         0  
736 0         0 my $max = $end_mov->[1]; say TOSHELL "FROM REF got \$max : " . dump($max);
  0         0  
737 0         0 $swing_surf = ( $max - $min ); say TOSHELL "FROM REF got \$swing_surf : " . dump($swing_surf);
  0         0  
738 0         0 $end_mov = ( $swing_surf / 2 ); say TOSHELL "FROM REF got \$end_mov : " . dump($end_mov);
  0         0  
739             }
740             else
741             {
742 0         0 $swing_surf = $end_mov * 2; say TOSHELL "got \$swing_surf : " . dump($swing_surf);
  0         0  
743             }
744            
745 0         0 $pace = ( $swing_surf / ( $stepsvar - 1 ) ); say TOSHELL "got \$pace : " . dump($pace);
  0         0  
746 0         0 say TOSHELL "got \$end_mov : " . dump($end_mov); say TOSHELL "got \$countstep : " . dump($countstep);
  0         0  
747 0         0 $movement = ( - ( ($end_mov) -( $pace * ( $countstep - 1 ) ) ) ); say TOSHELL "RESULT: got \$movement : " . dump($movement);
  0         0  
748            
749 0         0 my $printthis =
750             "prj -file $to/cfg/$fileconfig -mode script<
751              
752             m
753             c
754             a
755             $zone_letter
756             e
757             >
758             $surface_letter
759             $transform_type
760             $movement
761             y
762             -
763             -
764             y
765             c
766             -
767             -
768             -
769             -
770             -
771             -
772             -
773             -
774             YYY
775             ";
776 0 0       0 if ($exeonfiles eq "y")
777             {
778 0         0 print `$printthis`;
779             }
780 0         0 print TOSHELL "
781             #Translating surfaces for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance
782             $printthis";
783              
784 0         0 $countsurface++;
785 0         0 $countcycles_transl_surfs++;
786             }
787             elsif ($transform_type eq "b")
788             {
789 0         0 my @coordinates_for_movement = @{ $transform_coordinates[$countsurface] };
  0         0  
790 0         0 my $x_end = $coordinates_for_movement[0];
791 0         0 my $y_end = $coordinates_for_movement[1];
792 0         0 my $z_end = $coordinates_for_movement[2];
793 0         0 my $x_swingtranslate = ( 2 * $x_end );
794 0         0 my $y_swingtranslate = ( 2 * $y_end );
795 0         0 my $z_swingtranslate = ( 2 * $z_end );
796 0         0 my $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
797 0         0 my $x_movement = (- ( $x_end - ( $x_pace * ( $countstep - 1 ) ) ));
798 0         0 my $y_pace = ( $y_swingtranslate / ( $stepsvar - 1 ) );
799 0         0 my $y_movement = (- ( $y_end - ( $y_pace * ( $countstep - 1 ) ) ));
800 0         0 my $z_pace = ( $z_swingtranslate / ( $stepsvar - 1 ) );
801 0         0 my $z_movement = (- ( $z_end - ( $z_pace * ( $countstep - 1 ) ) ));
802              
803 0         0 my $printthis =
804             "prj -file $to/cfg/$fileconfig -mode script<
805              
806             m
807             c
808             a
809             $zone_letter
810             e
811             >
812             $surface_letter
813             $transform_type
814             $x_movement $y_movement $z_movement
815             y
816             -
817             -
818             y
819             c
820             -
821             -
822             -
823             -
824             -
825             -
826             -
827             -
828             YYY
829             ";
830              
831 0 0       0 if ($exeonfiles eq "y")
832             {
833 0         0 print `$printthis`;
834             }
835              
836 0         0 print TOSHELL "
837             #Translating surfaces for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance
838             $printthis";
839              
840 0         0 $countsurface++;
841 0         0 $countcycles_transl_surfs++;
842             }
843             }
844             }
845             } # END SUB translate_surfaces
846              
847              
848             sub rotate_surface
849             {
850 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $applytyperef, $rotate_surface, $countvar, $fileconfig ) = @_;
851            
852 0         0 my @applytype = @$applytyperef;
853 0         0 my $zone_letter = $applytype[$countop][3];
854            
855 0         0 say "Rotating surfaces for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
856            
857 0         0 my @surfs_to_rotate = @{ $rotate_surface->[$countop][0] };
  0         0  
858 0         0 my @vertices_numbers = @{ $rotate_surface->[$countop][1] };
  0         0  
859 0         0 my @swingrotations = @{ $rotate_surface->[$countop][2] };
  0         0  
860 0         0 my @yes_or_no_apply_to_others = @{ $rotate_surface->[$countop][3] };
  0         0  
861 0         0 my $configfile = $$rotate_surface[$countop][4];
862 0         0 my ( $swingrotate, $pacerotate, $rotation_degrees, $vertex_number, $yes_or_no_apply );
863              
864 0         0 my $countrotate = 0;
865 0         0 foreach my $surface_letter (@surfs_to_rotate)
866             {
867 0         0 $swingrotate = $swingrotations[$countrotate];
868              
869 0 0       0 if ( ref ( $swingrotate ) )
870             {
871 0         0 my $min = $end_mov_>[0];
872 0         0 my $max = $end_mov->[1];
873 0         0 $swingrotate = ( $max - $min );
874             }
875             else
876             {
877 0         0 $swingrotate = $end_mov * 2;
878             }
879              
880 0         0 $pacerotate = ( $swingrotate / ( $stepsvar - 1 ) );
881 0         0 $rotation_degrees = ( ( $swingrotate / 2 ) - ( $pacerotate * ( $countstep - 1 ) )) ;
882 0         0 $vertex_number = $vertices_numbers[$countrotate];
883 0         0 $yes_or_no_apply = $yes_or_no_apply_to_others[$countrotate];
884 0 0 0     0 if ( ( $swingrotate != 0 ) and ( $stepsvar > 1 ) and ( $yes_or_no_rotate_surfs eq "y" ) )
      0        
885             {
886 0         0 my $printthis =
887             "prj -file $to/cfg/$fileconfig -mode script<
888              
889             m
890             c
891             a
892             $zone_letter
893             e
894             >
895             $surface_letter
896             c
897             $vertex_number
898             $rotation_degrees
899             $yes_or_no_apply
900             -
901             -
902             y
903             c
904             -
905             -
906             -
907             -
908             -
909             -
910             -
911             -
912             YYY
913             ";
914 0 0       0 if ($exeonfiles eq "y")
915             {
916 0         0 print `$printthis`;
917             }
918              
919 0         0 print TOSHELL "
920             Rotating surfaces for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance
921             $printthis";
922             }
923 0         0 $countrotate++;
924             }
925             } # END SUB rotate_surface
926              
927              
928             sub translate_vertices # TO BE RE-TESTED.
929             {
930 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig) = @_;
931 0         0 my @applytype = @$swap;
932 0         0 my $zone_letter = $applytype[$countop][3];
933 0         0 my @translate_vertices = @$swap2;
934 0         0 say "Translating vertices for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
935 0         0 my @v;
936 0         0 my @verts_to_transl = @{ $translate_vertices[$countop][0] };
  0         0  
937 0         0 my @transform_coordinates = @{ $translate_vertices[$countop][1] };
  0         0  
938 0         0 my @sourcefiles = @{ $translate_vertices[$countop][2] };
  0         0  
939 0         0 my @longmenus = @{ $translate_vertices[$countop][3] };
  0         0  
940            
941 0         0 my $sourcefile = $sourcefiles[ $countops ];
942 0         0 my $longmenu = $longmenus[ $countops ];
943 0         0 my $sourceaddress = "$mypath/$file$sourcefile";
944            
945 0 0       0 open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourcefile 2: $!\n";
946 0         0 my @lines = ;
947 0         0 close SOURCEFILE;
948            
949 0         0 my $countlines = 0;
950 0         0 my $countvert = 0;
951              
952 0         0 my @vertex_letters;
953 0 0       0 if ($longmenu eq "y")
954             {
955 0         0 @vertex_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
956             "n", "o", "p", "0\nb\nq", "0\nb\nr", "0\nb\ns", "0\nb\nt", "0\nb\nu", "0\nb\nv",
957             "0\nb\nw", "0\nb\nx", "0\nb\ny", "0\nb\nz", "0\nb\na", "0\nb\nb","0\nb\nc","0\nb\nd",
958             "0\nb\ne","0\nb\n0\nb\nf","0\nb\n0\nb\ng","0\nb\n0\nb\nh","0\nb\n0\nb\ni",
959             "0\nb\n0\nb\nj","0\nb\n0\nb\nk","0\nb\n0\nb\nl","0\nb\n0\nb\nm","0\nb\n0\nb\nn",
960             "0\nb\n0\nb\no","0\nb\n0\nb\np","0\nb\n0\nb\nq","0\nb\n0\nb\nr","0\nb\n0\nb\ns",
961             "0\nb\n0\nb\nt");
962             }
963             else
964             {
965 0         0 @vertex_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
966             "n", "o", "p", "0\nq", "0\nr", "0\ns", "0\nt", "0\nu", "0\nv", "0\nw", "0\nx",
967             "0\ny", "0\nz", "0\na", "0\nb","0\n0\nc","0\n0\nd","0\n0\ne","0\n0\nf","0\n0\ng",
968             "0\n0\nh","0\n0\ni","0\n0\nj","0\n0\nk","0\n0\nl","0\n0\nm","0\n0\nn","0\n0\no",
969             "0\n0\np","0\n0\nq","0\n0\nr","0\n0\ns","0\n0\nt");
970             }
971              
972 0         0 foreach my $line (@lines)
973             {
974 0         0 $line =~ s/^\s+//;
975 0         0 my @rowelements = split(/\s+|,/, $line);
976 0 0       0 if ($rowelements[0] eq "*vertex" )
977             {
978 0 0       0 if ($countvert == 0)
979             {
980 0         0 push (@v, [ "vertices of $sourceaddress" ]);
981 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ], $vertexletters[$countvert] );
982             }
983              
984 0 0       0 if ($countvert > 0)
985             {
986 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3], $vertexletters[$countvert] ] );
987             }
988 0         0 $countvert++;
989             }
990 0         0 $countlines++;
991             }
992              
993 0         0 my $countvertex = 0;
994 0         0 foreach my $vertex_letter (@vertex_letters)
995             {
996 0         0 my ( $x_swingtranslate, $y_swingtranslate, $z_swingtranslate );
997 0         0 my @base_coordinates = @{ $transform_coordinates[ $countvertex ] };
  0         0  
998            
999 0         0 my $x_end = $base_coordinates[0];
1000 0 0       0 if ( ref ( $x_end ) )
1001             {
1002 0         0 my $min = $x_end->[0];
1003 0         0 my $max = $x_end->[1];
1004 0         0 $x_swingtranslate = ( $max - $min );
1005             }
1006             else
1007             {
1008 0         0 $x_swingtranslate = ( 2 * $x_end );
1009             }
1010              
1011 0         0 my $y_end = $base_coordinates[1];
1012 0 0       0 if ( ref ( $y_end ) )
1013             {
1014 0         0 my $min = $y_end->[0];
1015 0         0 my $max = $y_end->[1];
1016 0         0 $y_swingtranslate = ( $max - $min );
1017             }
1018             else
1019             {
1020 0         0 $y_swingtranslate = ( 2 * $y_end );
1021             }
1022            
1023 0         0 my $z_end = $base_coordinates[2];
1024 0 0       0 if ( ref ( $z_end ) )
1025             {
1026 0         0 my $min = $z_end->[0];
1027 0         0 my $max = $z_end->[1];
1028 0         0 $z_swingtranslate = ( $max - $min );
1029             }
1030             else
1031             {
1032 0         0 $z_swingtranslate = ( 2 * $z_end );
1033             }
1034            
1035 0         0 my $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
1036 0         0 my $x_movement = (- ( $x_end - ( $x_pace * ( $countstep - 1 ) ) ));
1037 0         0 my $y_pace = ( $y_swingtranslate / ( $stepsvar - 1 ) );
1038 0         0 my $y_movement = (- ( $y_end - ( $y_pace * ( $countstep - 1 ) ) ));
1039 0         0 my $z_pace = ( $z_swingtranslate / ( $stepsvar - 1 ) );
1040 0         0 my $z_movement = (- ( $z_end - ( $z_pace * ( $countstep - 1 ) ) ));
1041 0         0 my $printthis =
1042             "prj -file $to/cfg/$fileconfig -mode script<
1043              
1044             m
1045             c
1046             a
1047             $zone_letter
1048             d
1049             $vertex_letter
1050             $x_movement $y_movement $z_movement
1051             -
1052             y
1053             -
1054             y
1055             c
1056             -
1057             -
1058             -
1059             -
1060             -
1061             -
1062             -
1063             -
1064             -
1065             YYY
1066             ";
1067 0 0       0 if ($exeonfiles eq "y")
1068             {
1069 0         0 print `$printthis`;
1070             }
1071              
1072 0         0 print TOSHELL "
1073             #Translating vertices for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1074             $printthis";
1075 0         0 $countvertex++;
1076             }
1077 0         0 $countops++;
1078             } # END SUB translate_vertices
1079              
1080              
1081             sub shift_vertices
1082             {
1083 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $shift_vertices, $countvar, $fileconfig ) = @_;
1084            
1085 0         0 my @applytype = @$swap;
1086 0         0 my $zone_letter = $applytype[$countop][3];
1087            
1088 0         0 say "Shifting vertices for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1089              
1090 0         0 my ( $pace, $movement );
1091 0         0 my $movementtype = $$shift_vertices[$countop][0];
1092 0         0 my @pairs_of_vertices = @{ $$shift_vertices[$countop][1] };
  0         0  
1093 0         0 my @shift_swings = @{ $$shift_vertices[$countop][2] };
  0         0  
1094 0         0 my $yes_or_no_radiation_update = $$shift_vertices[$countop][3];
1095 0         0 my $configfile = $$shift_vertices[$countop][4];
1096            
1097 0 0       0 if ( $stepsvar > 1 )
1098             {
1099 0         0 my $countthis = 0;
1100 0 0       0 if ($movementtype eq "j")
    0          
1101             {
1102 0         0 foreach my $shift_swing (@shift_swings)
1103             {
1104            
1105 0 0       0 if ( ref ( $shift_swing ) )
1106             {
1107 0         0 my $min = $shift_swing->[0];
1108 0         0 my $max = $shift_swing->[1];
1109 0         0 $shift_swing = ( $max - $min );
1110             }
1111             else
1112             {
1113             ;
1114             }
1115            
1116 0         0 $pace = ( $shift_swing / ( $stepsvar - 1 ) );
1117 0         0 $movement_or_vertex = ( ( ($shift_swing) / 2 ) - ( $pace * ( $countstep - 1 ) ) );
1118 0         0 $vertex1 = $pairs_of_vertices[ 0 + ( 2 * $countthis ) ];
1119 0         0 $vertex2 = $pairs_of_vertices[ 1 + ( 2 * $countthis ) ];
1120            
1121 0         0 my $printthis =
1122             "prj -file $to/cfg/$fileconfig -mode script<
1123              
1124             m
1125             c
1126             a
1127             $zone_letter
1128             d
1129             ^
1130             $movementtype
1131             $vertex1
1132             $vertex2
1133             -
1134             $movement_or_vertex
1135             y
1136             -
1137             y
1138             -
1139             y
1140             -
1141             -
1142             -
1143             -
1144             -
1145             -
1146             -
1147             -
1148             YYY
1149             ";
1150 0 0       0 if ($exeonfiles eq "y")
1151             {
1152 0         0 print `$printthis`;
1153             }
1154 0         0 print TOSHELL "
1155             #Shifting vertices for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1156             $printthis";
1157              
1158 0         0 $countthis++;
1159             }
1160             }
1161             elsif ($movementtype eq "h")
1162             {
1163 0         0 foreach my $shift_swing (@shift_swings)
1164             {
1165 0         0 my $printthis =
1166             "prj -file $to/cfg/$fileconfig -mode script<
1167              
1168             m
1169             c
1170             a
1171             $zone_letter
1172             d
1173             ^
1174             $movementtype
1175             $vertex1
1176             $vertex2
1177             -
1178             $movement_or_vertex
1179             -
1180             y
1181             n
1182             n
1183             n
1184             -
1185             y
1186             -
1187             y
1188             -
1189             -
1190             -
1191             -
1192             -
1193             -
1194             -
1195             -
1196             YYY
1197             ";
1198 0 0       0 if ($exeonfiles eq "y")
1199             {
1200 0         0 print `$printthis`;
1201             }
1202 0         0 print TOSHELL "
1203             #Shifting vertices for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1204             $printthis";
1205             }
1206             }
1207             }
1208             } # END SUB shift_vertices
1209              
1210              
1211             sub rotate # generic zone rotation
1212             {
1213 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $rotate, $countvar, $fileconfig ) = @_;
1214            
1215 0         0 my @applytype = @$swap;
1216 0         0 my $zone_letter = $applytype[$countop][3];
1217            
1218 0         0 say "Rotating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1219              
1220 0         0 my $rotation_degrees;
1221 0         0 my $swingrotate = $$rotate[$countop][0];
1222            
1223 0 0       0 if ( ref ( $swingrotate ) )
1224             {
1225 0         0 my $min = $swingrotate->[0];
1226 0         0 my $max = $swingrotate->[1];
1227 0         0 $swingrotate = ( $max - $min );
1228             }
1229            
1230 0         0 my $yes_or_no_update_radiation = $$rotate[$countop][1];
1231 0         0 my $base_vertex = $$rotate[$countop][2];
1232 0         0 my $configfile = $$rotate[$countop][3];
1233 0         0 my $pacerotate;
1234 0         0 my $count_rotate = 0;
1235 0 0 0     0 if ( ( $swingrotate != 0 ) and ( $stepsvar > 1 ) )
1236             {
1237 0         0 $pacerotate = ( $swingrotate / ( $stepsvar - 1 ) );
1238 0         0 $rotation_degrees = ( ( $swingrotate / 2 ) - ( $pacerotate * ( $countstep - 1 ) ) );
1239              
1240 0         0 my $printthis =
1241             "prj -file $to/cfg/$fileconfig -mode script<
1242              
1243              
1244             m
1245             c
1246             a
1247             $zone_letter
1248             i
1249             b
1250             $rotation_degrees
1251             $base_vertex
1252             -
1253             $yes_or_no_rotate_obstructions
1254             -
1255             y
1256             c
1257             -
1258             y
1259             -
1260             -
1261             -
1262             -
1263             -
1264             -
1265             -
1266             -
1267             YYY
1268             ";
1269              
1270 0 0       0 if ($exeonfiles eq "y")
1271             {
1272 0         0 print `$printthis`;
1273             }
1274 0         0 print TOSHELL
1275             "
1276             #Rotating zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1277             $printthis
1278             ";
1279             }
1280             } # END SUB rotate
1281              
1282              
1283             sub rotatez # PUT THE ROTATION POINT AT POINT 0, 0, 0. I HAVE NOT YET MADE THE FUNCTION GENERIC ENOUGH.
1284             {
1285 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $rotatez, $countvar, $fileconfig ) = @_;
1286            
1287 0         0 my @applytype = @$swap;
1288 0         0 my $zone_letter = $applytype[$countop][3];
1289            
1290 0         0 say "Rotating zones on the vertical plane for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1291              
1292 0         0 my @centerpoints = @{$$rotatez[0]};
  0         0  
1293 0         0 my $centerpointsx = $centerpoints[0];
1294 0         0 my $centerpointsy = $centerpoints[1];
1295 0         0 my $centerpointsz = $centerpoints[2];
1296 0         0 my $plane_of_rotation = "$$rotatez[1]";
1297 0         0 my $infile = "$to/zones/$applytype[$countop][2]";
1298 0         0 my $infile2 = "$to/cfg/$applytype[$countop][2]";
1299 0         0 my $outfilemorph = "erase";
1300 0         0 my $outfile2 = "$to/zones/$applytype[$countop][2]eraseobtained";
1301 0 0       0 open(INFILE, "$infile") or die "Can't open infile $infile: $!\n";
1302 0 0       0 open($_outfile_2, ">>$outfile2") or die "Can't open outfile2 $outfile2: $!\n";
1303 0         0 my @lines = ;
1304 0         0 close(INFILE);
1305 0         0 my $countline = 0;
1306 0         0 my $countcases = 0;
1307 0         0 my @vertices;
1308 0         0 my $swingrotate = $$rotatez[2];
1309 0         0 my $alreadyrotation = $$rotatez[3];
1310 0         0 my $rotatexy = $$rotatez[4];
1311 0         0 my $swingrotatexy = $$rotatez[5];
1312            
1313 0 0       0 if ( ref ( $swingrotate ) )
1314             {
1315 0         0 my $min = $swingrotate->[0];
1316 0         0 my $max = $swingrotate->[1];
1317 0         0 $swingrotatexy = ( $max - $min );
1318             }
1319             else { ; }
1320            
1321 0 0       0 if ( ref ( $swingrotate ) )
1322             {
1323 0         0 my $min = $swingrotate->[0];
1324 0         0 my $max = $swingrotate->[1];
1325 0         0 $swingrotatexy = ( $max - $min );
1326             }
1327             else { ; }
1328            
1329 0         0 my ( $pacerotate, $linenew, $linenew2 );
1330 0         0 my $count_rotate = 0;
1331 0         0 my ( @rowprovv, @rowprovv2, @row, @row2 );
1332 0 0       0 if ( $stepsvar > 1 )
1333             {
1334 0         0 foreach my $line (@lines)
1335             {#
1336             {
1337 0         0 $linenew = $line;
  0         0  
1338 0         0 $linenew =~ s/\:\s/\:/g ;
1339 0         0 @rowprovv = split(/\s+/, $linenew);
1340 0         0 $rowprovv[0] =~ s/\:\,/\:/g ;
1341 0         0 @row = split(/\,/, $rowprovv[0]);
1342 0 0       0 if ($row[0] eq "*vertex")
1343 0         0 { push (@vertices, [$row[1], $row[2], $row[3]] ) }
1344             }
1345 0         0 $countline = $countline +1;
1346             }
1347              
1348 0         0 foreach $vertex (@vertices)
1349             {
1350 0         0 print $_outfile_ "vanilla ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";
  0         0  
  0         0  
  0         0  
1351             }
1352 0         0 foreach $vertex (@vertices)
1353             {
1354 0         0 ${$vertex}[0] = (${$vertex}[0] - $centerpointsx);
  0         0  
  0         0  
1355 0         0 ${$vertex}[0] = sprintf("%.5f", ${$vertex}[0]);
  0         0  
  0         0  
1356 0         0 ${$vertex}[1] = (${$vertex}[1] - $centerpointsy);
  0         0  
  0         0  
1357 0         0 ${$vertex}[1] = sprintf("%.5f", ${$vertex}[1]);
  0         0  
  0         0  
1358 0         0 ${$vertex}[2] = (${$vertex}[2] - $centerpointsz);
  0         0  
  0         0  
1359 0         0 ${$vertex}[2] = sprintf("%.5f", ${$vertex}[2]);
  0         0  
  0         0  
1360 0         0 print $_outfile_ "aftersum ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";
  0         0  
  0         0  
  0         0  
1361             }
1362              
1363 0         0 my $anglealready = deg2rad(-$alreadyrotation);
1364 0         0 foreach $vertex (@vertices)
1365             {
1366 0         0 my $x_new = cos($anglealready)*${$vertex}[0] - sin($anglealready)*${$vertex}[1];
  0         0  
  0         0  
1367 0         0 my $y_new = sin($anglealready)*${$vertex}[0] + cos($anglealready)*${$vertex}[1];
  0         0  
  0         0  
1368 0         0 ${$vertex}[0] = $x_new; ${$vertex}[0] = sprintf("%.5f", ${$vertex}[0]);
  0         0  
  0         0  
  0         0  
  0         0  
1369 0         0 ${$vertex}[1] = $y_new; ${$vertex}[1] = sprintf("%.5f", ${$vertex}[1]);
  0         0  
  0         0  
  0         0  
  0         0  
1370 0         0 print $_outfile_ "afterfirstrotation ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";
  0         0  
  0         0  
  0         0  
1371             }
1372              
1373 0         0 $pacerotate = ( $swingrotate / ( $stepsvar - 1) );
1374 0         0 $rotation_degrees = - ( ($swingrotate / 2) - ($pacerotate * ($countstep -1) ) );
1375 0         0 my $angle = deg2rad($rotation_degrees);
1376 0         0 foreach $vertex (@vertices)
1377             {
1378 0         0 my $y_new = cos($angle)*${$vertex}[1] - sin($angle)*${$vertex}[2];
  0         0  
  0         0  
1379 0         0 my $z_new = sin($angle)*${$vertex}[1] + cos($angle)*${$vertex}[2];
  0         0  
  0         0  
1380 0         0 ${$vertex}[1] = $y_new; ${$vertex}[1] = sprintf("%.5f", ${$vertex}[1]);
  0         0  
  0         0  
  0         0  
  0         0  
1381 0         0 ${$vertex}[2] = $z_new; ${$vertex}[2] = sprintf("%.5f", ${$vertex}[2]);
  0         0  
  0         0  
  0         0  
  0         0  
1382 0         0 ${$vertex}[0] = sprintf("%.5f", ${$vertex}[0]);
  0         0  
  0         0  
1383 0         0 print $_outfile_ "aftersincos ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";
  0         0  
  0         0  
  0         0  
1384             }
1385              
1386 0         0 my $angleback = deg2rad($alreadyrotation);
1387 0         0 foreach $vertex (@vertices)
1388             {
1389 0         0 my $x_new = cos($angleback)*${$vertex}[0] - sin($angleback)*${$vertex}[1];
  0         0  
  0         0  
1390 0         0 my $y_new = sin($angleback)*${$vertex}[0] + cos($angleback)*${$vertex}[1];
  0         0  
  0         0  
1391 0         0 ${$vertex}[0] = $x_new; ${$vertex}[0] = sprintf("%.5f", ${$vertex}[0]);
  0         0  
  0         0  
  0         0  
  0         0  
1392 0         0 ${$vertex}[1] = $y_new; ${$vertex}[1] = sprintf("%.5f", ${$vertex}[1]);
  0         0  
  0         0  
  0         0  
  0         0  
1393 0         0 print $_outfile_ "afterrotationback ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";ctl type
  0         0  
  0         0  
  0         0  
  0         0  
1394             }
1395              
1396 0         0 foreach $vertex (@vertices)
1397             {
1398 0         0 ${$vertex}[0] = ${$vertex}[0] + $centerpointsx; ${$vertex}[0] = sprintf("%.5f", ${$vertex}[0]);
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
1399 0         0 ${$vertex}[1] = ${$vertex}[1] + $centerpointsy; ${$vertex}[1] = sprintf("%.5f", ${$vertex}[1]);
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
1400 0         0 ${$vertex}[2] = ${$vertex}[2] + $centerpointsz; ${$vertex}[2] = sprintf("%.5f", ${$vertex}[2]);
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
1401 0         0 print $_outfile_ "after final substraction ${$vertex}[0], ${$vertex}[1], ${$vertex}[2]\n";
  0         0  
  0         0  
  0         0  
1402             }
1403              
1404 0         0 my $countwrite = -1;
1405 0         0 my $countwriteand1;
1406 0         0 foreach $line (@lines)
1407             {#
1408              
1409 0         0 $linenew2 = $line;
1410 0         0 $linenew2 =~ s/\:\s/\:/g ;
1411 0         0 my @rowprovv2 = split(/\s+/, $linenew2);
1412 0         0 $rowprovv2[0] =~ s/\:\,/\:/g ;
1413 0         0 @row2 = split(/\,/, $rowprovv2[0]);
1414 0         0 $countwriteright = ($countwrite - 5);
1415 0         0 $countwriteand1 = ($countwrite + 1);
1416 0 0       0 if ($row2[0] eq "*vertex")
1417             {
1418 0 0       0 if ( $countwrite == - 1) { $countwrite = 0 }
  0         0  
1419 0         0 print $_outfile_2
1420 0         0 "*vertex"."\,"."${$vertices[$countwrite]}[0]"."\,"."${$vertices[$countwrite]}[1]"."\,"."${$vertices[$countwrite]}[2]"." # "."$countwriteand1\n";
  0         0  
  0         0  
1421             }
1422             else
1423             {
1424 0         0 print $_outfile_2 "$line";
1425             }
1426 0 0       0 if ( $countwrite > ( - 1 ) ) { $countwrite++; }
  0         0  
1427             }
1428              
1429 0         0 close($_outfile_);
1430 0 0       0 if ($exeonfiles eq "y") { print `chmod 777 $infile`; }
  0         0  
1431 0         0 print TOSHELL "chmod -R 777 $infile\n";
1432 0 0       0 if ($exeonfiles eq "y") { print `chmod 777 $infile2`; }
  0         0  
1433 0         0 print TOSHELL "chmod -R 777 $infile2\n";
1434 0 0       0 if ($exeonfiles eq "y") { print `rm $infile`; }
  0         0  
1435 0         0 print TOSHELL "rm $infile\n";
1436 0 0       0 if ($exeonfiles eq "y") { print `chmod 777 $outfile2`; }
  0         0  
1437 0         0 print TOSHELL "chmod 777 $outfile2\n";
1438 0 0       0 if ($exeonfiles eq "y") { print `cp $outfile2 $infile`; }
  0         0  
1439 0         0 print TOSHELL "cp $outfile2 $infile\n";
1440 0 0       0 if ($exeonfiles eq "y") { print `cp $outfile2 $infile2`; }
  0         0  
1441 0         0 print TOSHELL "cp $outfile2 $infile2\n";
1442             }
1443             } # END SUB rotatez
1444              
1445              
1446             sub reassign_construction
1447             {
1448 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $construction_reassignment, $countvar, $fileconfig ) = @_;
1449            
1450 0         0 my @applytype = @$swap;
1451 0         0 my $zone_letter = $applytype[$countop][3];
1452            
1453 0         0 say "Reassign construction solutions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1454              
1455 0         0 my @surfaces_to_reassign = @{ $construction_reassignment->[$countop][0] };
  0         0  
1456 0         0 my @constructions_to_choose = @{ $construction_reassignment->[$countop][1] };
  0         0  
1457 0         0 my $configfile = $$construction_reassignment[$countop][2];
1458 0         0 my $surface_letter;
1459 0         0 my $count = 0;
1460 0         0 my @reassign_constructions;
1461              
1462 0         0 foreach $surface_to_reassign (@surfaces_to_reassign)
1463             {
1464 0         0 $construction_to_choose = $constructions_to_choose[$count][$countstep];
1465            
1466 0         0 my $printthis =
1467             "prj -file $to/cfg/$fileconfig -mode script<
1468              
1469             m
1470             c
1471             a
1472             $zone_letter
1473             f
1474             $surface_to_reassign
1475             e
1476             n
1477             y
1478             $construction_to_choose
1479             -
1480             -
1481             -
1482             -
1483             y
1484             y
1485             -
1486             -
1487             -
1488             -
1489             -
1490             -
1491             -
1492             -
1493             YYY
1494             ";
1495 0 0       0 if ($exeonfiles eq "y")
1496             {
1497 0         0 print `$printthis`;
1498             }
1499              
1500 0         0 print TOSHELL "
1501             #Reassign construction solutions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1502             $printthis";
1503 0         0 $count++;
1504             }
1505              
1506             } # END SUB reassign_construction
1507              
1508            
1509             sub change_thickness
1510             {
1511 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $thickness_change, $countvar, $fileconfig ) = @_;
1512 0         0 my @applytype = @$swap;
1513 0         0 my $zone_letter = $applytype[$countop][3];
1514            
1515 0         0 say "Changing thicknesses in construction layer for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1516              
1517 0         0 my @entries_to_change = @{ $$thickness_change[$countop][0] };
  0         0  
1518 0         0 my @groups_of_strata_to_change = @{ $$thickness_change[$countop][1] };
  0         0  
1519 0         0 my @groups_of_couples_of_min_max_values = @{ $$thickness_change[$countop][2] };
  0         0  
1520 0         0 my $configfile = $$thickness_change[$countop][3];
1521 0         0 my $thiscount = 0;
1522 0         0 my ( $entry_to_change, $countstrata, $stratum_to_change, $min, $max, $change_stratum, $enter_change_entry, $swing, $pace, $thickness );
1523 0         0 my ( @strata_to_change, @min_max_values , @change_strata, @change_entries, @change_entries_with_thicknesses );
1524              
1525 0 0       0 if ( $stepsvar > 1 )
1526             {
1527 0         0 foreach $entry_to_change (@entries_to_change)
1528             {
1529 0         0 @strata_to_change = @{ $groups_of_strata_to_change[$thiscount] };
  0         0  
1530 0         0 $countstrata = 0;
1531 0         0 foreach $stratum_to_change (@strata_to_change)
1532             {
1533 0         0 @min_max_values = @{ $groups_of_couples_of_min_max_values[$thiscount][$countstrata] };
  0         0  
1534 0         0 $min = $min_max_values[0];
1535 0         0 $max = $min_max_values[1];
1536 0         0 $swing = $max - $min;
1537 0         0 $pace = ( $swing / ( $stepsvar - 1 ) );
1538 0         0 $thickness = $min + ( $pace * ( $countstep - 1 ) );
1539              
1540 0         0 my $printthis =
1541             "prj -file $to/cfg/$fileconfig -mode script<
1542             b
1543             e
1544             a
1545             $entry_to_change
1546             $stratum_to_change
1547             n
1548             $thickness
1549             -
1550             -
1551             y
1552             y
1553             -
1554             y
1555             y
1556             -
1557             -
1558             -
1559             -
1560             -
1561             YYY
1562             ";
1563 0 0       0 if ($exeonfiles eq "y")
1564             {
1565 0         0 print `$printthis`;
1566             }
1567 0         0 print TOSHELL "
1568             #Changing thicknesses in construction layer for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1569             $printthis";
1570 0         0 $countstrata++;
1571             }
1572 0         0 $thiscount++;
1573             }
1574 0         0 $" = " ";
1575 0 0       0 if ($exeonfiles eq "y") { print `$enter_esp$go_to_construction_database@change_entries_with_thicknesses$exit_construction_database_and_esp`; }
  0         0  
1576 0         0 print TOSHELL "$enter_esp$go_to_construction_database@change_entries_with_thicknesses$exit_construction_database_and_esp\n";
1577             }
1578             } # END sub change_thickness
1579              
1580              
1581             sub readgeofile
1582             { # THIS READS A GEO FILE TO GET THE DATA OF THE REQUESTED OBSTRUCTIONS
1583 0     0 0 0 my $geofile = $_[0]; #say "geofile: $geofile";
1584 0 0       0 open (GEOFILE, "$geofile") or die;
1585 0         0 my @lines = ;
1586 0         0 close GEOFILE;
1587              
1588 0         0 foreach my $line (@lines)
1589             {
1590 0         0 my @elts = split(/\s+|,/, $line); #say "elts: " . dump(@elts);
1591             #*obs,3.000,-1.500,6.000,0.010,1.500,3.000,0.000,1.00,left3,wall27 # block 3
1592 0 0       0 if ($elts[0] eq "\*obs")
1593             {
1594 0         0 push ( @obsdata, [ @elts ] );
1595             }
1596             }
1597 0         0 return ( @obsdata );
1598             }
1599              
1600              
1601             sub obs_modify
1602             {
1603 0 0   0 0 0 if ( $stepsvar > 1 )
1604             {
1605 0         0 my ( $to, $stepsvar, $countop, $countstep, $swap, $obs_modify, $countvar, $fileconfig ) = @_;
1606 0         0 my @applytype = @$swap;
1607 0         0 my $zone_letter = $applytype[$countop][3];
1608 0         0 say "Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
1609              
1610 0         0 my @obs_letters = @{ $$obs_modify[$countop][0] };
  0         0  
1611 0         0 my $modification_type = $$obs_modify[$countop][1];
1612 0         0 my @values = @{ $$obs_modify[$countop][2] };
  0         0  
1613 0         0 my @base = @{ $$obs_modify[$countop][3] };
  0         0  
1614 0         0 my $configfile = $$obs_modify[$countop][4];
1615 0         0 my $xz_resolution = $$obs_modify[$countop][5];
1616 0         0 my $countobs = 0;
1617 0         0 my ( $x_end, $y_end, $z_end, $x_base, $y_base, $z_base, $end_value, $base_value, $x_swingtranslate,
1618             $y_swingtranslate, $z_swingtranslate, $x_pace, $x_value, $y_pace, $y_value, $z_pace, $z_value );
1619 0 0 0     0 if ( ($modification_type eq "a") or ($modification_type eq "b"))
1620             {
1621 0         0 $x_end = $values[0];
1622 0 0       0 if ( ref ( $x_end ) )
1623             {
1624 0         0 my $min = $x_end->[0];
1625 0         0 my $max = $x_end->[1];
1626 0         0 $x_swingtranslate = ( $max - $min );
1627             }
1628             else
1629             {
1630 0         0 $x_swingtranslate = ( 2 * $x_end );
1631             }
1632 0         0 $x_base = $base[0];
1633            
1634 0         0 $y_end = $values[1];
1635 0 0       0 if ( ref ( $y_end ) )
1636             {
1637 0         0 my $min = $y_end->[0];
1638 0         0 my $max = $y_end->[1];
1639 0         0 $y_swingtranslate = ( $max - $min );
1640             }
1641             else
1642             {
1643 0         0 $y_swingtranslate = ( 2 * $y_end );
1644             }
1645 0         0 $y_base = $base[1];
1646            
1647 0         0 $z_end = $values[2];
1648 0 0       0 if ( ref ( $z_end ) )
1649             {
1650 0         0 my $min = $z_end->[0];
1651 0         0 my $max = $z_end->[1];
1652 0         0 $z_swingtranslate = ( $max - $min );
1653             }
1654             else
1655             {
1656 0         0 $z_swingtranslate = ( 2 * $z_end );
1657             }
1658 0         0 $z_base = $base[2];
1659              
1660 0         0 $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
1661 0         0 $x_value = ($x_base + ( $x_end - ( $x_pace * ( $countstep - 1 ) ) ));
1662 0         0 $y_pace = ( $y_swingtranslate / ( $stepsvar - 1 ) );
1663 0         0 $y_value = ($y_base + ( $y_end - ( $y_pace * ( $countstep - 1 ) ) ));
1664 0         0 $z_pace = ( $z_swingtranslate / ( $stepsvar - 1 ) );
1665 0         0 $z_value = ($z_base + ( $z_end - ( $z_pace * ( $countstep - 1 ) ) ));
1666              
1667 0         0 my $printthis =
1668             "prj -file $to/cfg/$fileconfig -mode script<
1669              
1670             m
1671             c
1672             a
1673             $zone_letter
1674             h
1675             a
1676             $obs_letter
1677             $modification_type
1678             a
1679             $x_value $y_value $z_value
1680             -
1681             -
1682             c
1683             -
1684             c
1685             -
1686             -
1687             -
1688             -
1689             -
1690             -
1691             -
1692             -
1693             YYY
1694             ";
1695 0         0 foreach my $obs_letter (@obs_letters)
1696             {
1697 0 0       0 if ($exeonfiles eq "y")
1698             {
1699 0         0 print `$printthis`;
1700             }
1701 0         0 print TOSHELL "
1702             #Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1703             $printthis";
1704 0         0 $countobs++;
1705             }
1706             }
1707              
1708 0 0 0     0 if ( ($modification_type eq "c") or ($modification_type eq "d"))
1709             {
1710 0         0 $x_end = $values[0];
1711            
1712 0 0       0 if ( ref ( $x_end ) )
1713             {
1714 0         0 my $min = $x_end->[0];
1715 0         0 my $max = $x_end->[1];
1716 0         0 $x_swingtranslate = ( $max - $min );
1717             }
1718             else
1719             {
1720 0         0 $x_swingtranslate = ( 2 * $x_end );
1721             }
1722            
1723 0         0 $x_base = $base[0];
1724 0         0 $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
1725 0         0 $x_value = ($x_base + ( $x_end - ( $x_pace * ( $countstep - 1 ) ) ));
1726              
1727 0         0 foreach my $obs_letter (@obs_letters)
1728             {
1729 0         0 my $printthis =
1730             "prj -file $to/cfg/$fileconfig -mode script<
1731              
1732             m
1733             c
1734             a
1735             $zone_letter
1736             h
1737             a
1738             $obs_letter
1739             $modification_type
1740             $x_value
1741             -
1742             -
1743             c
1744             -
1745             c
1746             -
1747             -
1748             -
1749             -
1750             -
1751             -
1752             -
1753             -
1754             YYY
1755             ";
1756 0 0       0 if ($exeonfiles eq "y")
1757             {
1758 0         0 print `$printthis`;
1759             }
1760 0         0 print TOSHELL "
1761             #Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1762             $printthis";
1763 0         0 $countobs++;
1764             }
1765             }
1766              
1767 0 0       0 if ($modification_type eq "g")
1768             {
1769 0         0 foreach my $obs_letter (@obs_letters)
1770             {
1771 0         0 my $count = 0;
1772 0         0 foreach my $x_value (@values)
1773             {
1774 0 0       0 if ($count < $stepsvar)
1775             {
1776 0         0 my $printthis =
1777             "prj -file $to/cfg/$fileconfig -mode script<
1778              
1779             m
1780             c
1781             a
1782             $zone_letter
1783             h
1784             a
1785             $obs_letter
1786             $modification_type
1787             $x_value
1788             -
1789             -
1790             -
1791             -
1792             -
1793             -
1794             -
1795             -
1796             -
1797             -
1798             -
1799             -
1800             -
1801             -
1802             YYY
1803             ";
1804 0 0       0 if ($exeonfiles eq "y")
1805             {
1806 0         0 print `$printthis`;
1807             }
1808 0         0 print TOSHELL "
1809             Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1810             $printthis";
1811 0         0 $countobs++;
1812 0         0 $count++;
1813             }
1814             }
1815             }
1816             }
1817              
1818 0 0       0 if ($modification_type eq "h")
1819             {
1820 0         0 $x_end = $values[0];
1821 0         0 $x_base = $base[0];
1822            
1823 0 0       0 if ( ref ( $x_end ) )
1824             {
1825 0         0 my $min = $x_end->[0];
1826 0         0 my $max = $x_end->[1];
1827 0         0 $x_end = ( $max - $min );
1828             }
1829             else
1830             {
1831             ;
1832             }
1833            
1834 0         0 $x_swingtranslate = ( $x_base - $x_end );
1835 0         0 $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
1836 0         0 $x_value = ($x_base - ( $x_pace * ( $countstep - 1 ) ));
1837              
1838 0         0 foreach my $obs_letter (@obs_letters)
1839             {
1840 0         0 my $printthis =
1841             "prj -file $to/cfg/$fileconfig -mode script<
1842              
1843             m
1844             c
1845             a
1846             $zone_letter
1847             h
1848             a
1849             $obs_letter
1850             $modification_type
1851             $x_value
1852             -
1853             -
1854             -
1855             -
1856             -
1857             -
1858             -
1859             -
1860             -
1861             -
1862             -
1863             -
1864             -
1865             -
1866             YYY
1867             ";
1868 0 0       0 if ($exeonfiles eq "y")
1869             {
1870 0         0 print `$printthis`;
1871             }
1872 0         0 print TOSHELL $printthis;
1873 0         0 $countobs++;
1874             }
1875             }
1876              
1877 0 0       0 if ($modification_type eq "t")
1878             {
1879 0         0 my $modification_type = "~";
1880 0         0 my $what_todo = $base[0];
1881 0         0 $x_end = $values[0];
1882 0         0 $y_end = $values[1];
1883 0         0 $z_end = $values[2];
1884            
1885 0 0       0 if ( ref ( $x_end ) )
1886             {
1887 0         0 my $min = $x_end->[0];
1888 0         0 my $max = $x_end->[1];
1889 0         0 $x_swingtranslate = ( $max - $min );
1890             }
1891             else
1892             {
1893 0         0 $x_swingtranslate = ( 2 * $x_end );;
1894             }
1895            
1896 0 0       0 if ( ref ( $y_end ) )
1897             {
1898 0         0 my $min = $y_end->[0];
1899 0         0 my $max = $y_end->[1];
1900 0         0 $y_swingtranslate = ( $max - $min );
1901             }
1902             else
1903             {
1904 0         0 $y_swingtranslate = ( 2 * $y_end );;
1905             }
1906            
1907 0 0       0 if ( ref ( $z_end ) )
1908             {
1909 0         0 my $min = $z_end->[0];
1910 0         0 my $max = $z_end->[1];
1911 0         0 $z_swingtranslate = ( $max - $min );
1912             }
1913             else
1914             {
1915 0         0 $z_swingtranslate = ( 2 * $z_end );;
1916             }
1917            
1918 0         0 $x_pace = ( $x_swingtranslate / ( $stepsvar - 1 ) );
1919 0         0 $x_value = ( $x_end - ( $x_pace * ( $countstep - 1 ) ) );
1920 0         0 $y_pace = ( $y_swingtranslate / ( $stepsvar - 1 ) );
1921 0         0 $y_value = ( $y_end - ( $y_pace * ( $countstep - 1 ) ) );
1922 0         0 $z_pace = ( $z_swingtranslate / ( $stepsvar - 1 ) );
1923 0         0 $z_value = ( $z_end - ( $z_pace * ( $countstep - 1 ) ) );
1924              
1925 0         0 foreach my $obs_letter (@obs_letters)
1926             {
1927 0         0 my $printthis =
1928             "prj -file $to/cfg/$fileconfig -mode script<
1929              
1930             m
1931             c
1932             a
1933             $zone_letter
1934             h
1935             a
1936             $modification_type
1937             $what_todo
1938             $obs_letter
1939             -
1940             $x_value $y_value $z_value
1941             -
1942             c
1943             -
1944             c
1945             -
1946             -
1947             -
1948             -
1949             -
1950             -
1951             -
1952             -
1953             YYY
1954             ";
1955 0 0       0 if ($exeonfiles eq "y")
1956             {
1957 0         0 print `$printthis`;
1958             }
1959 0         0 print TOSHELL "
1960             Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1961             $printthis";
1962 0         0 $countobs++;
1963             }
1964             }
1965              
1966             #NOW THE XZ GRID RESOLUTION WILL BE PUT TO THE SPECIFIED VALUE
1967 0         0 my $printthis = #THIS IS WHAT HAPPEN INSIDE SUB KEEP_SOME_OBSTRUCTIONS
1968             "prj -file $to/cfg/$fileconfig -mode script<
1969              
1970              
1971             m
1972             c
1973             a
1974             $zone_letter
1975             h
1976             a
1977             a
1978             $xz_resolution
1979             -
1980             c
1981             -
1982             c
1983             -
1984             -
1985             -
1986             -
1987             -
1988             -
1989             -
1990             YYY
1991             ";
1992 0 0       0 if ($exeonfiles eq "y")
1993             {
1994 0         0 print `$printthis`;
1995             }
1996 0         0 print TOSHELL "
1997             Modifying obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
1998             $printthis";
1999             }
2000             } # END SUB obs_modify.
2001              
2002              
2003             sub bring_obstructions_back
2004             {
2005 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $keep_obstructions, $countvar, $fileconfig ) = @_;
2006 0         0 my @applytype = @$swap;
2007 0         0 my $geofile = $applytype[$countop][1];
2008 0         0 my $zone_letter = $applytype[$countop][3];
2009 0         0 my $ref = $$keep_obstructions[$countop];
2010 0         0 my %keepobs = %$ref;
2011 0         0 my $what = $keepobs{what};
2012 0         0 my $tempname = $keepobs{tempname};
2013 0         0 my $obsnumbersref = $keepobs{obsnumbers};
2014 0         0 my @obsnumbers = @$obsnumbersref;
2015            
2016 0         0 say "Keeping some obstructions in positions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2017              
2018 0 0       0 if ( $what eq "read" )
2019             {
2020 0         0 `cp -f $geofile $tempname`;
2021             }
2022            
2023 0 0       0 if ( $what eq "write" )
2024             {
2025 0 0       0 open (GEOFILE, "$geofile") or die;
2026 0         0 my @geolines = ;
2027 0         0 close GEOFILE;
2028 0         0 `mv -f $geofile $geofile.tmp `;
2029            
2030 0         0 open (TEMPFILE, "$tempname");
2031 0         0 my @templines = ;
2032 0         0 close TEMPFILE;
2033            
2034 0         0 my ( @tempobs );
2035              
2036 0         0 foreach my $line (@templines)
2037             {
2038 0         0 my @elts = split(/\s+|,/, $line); #say "elts: " . dump(@elts);
2039             #*obs,3.000,-1.500,6.000,0.010,1.500,3.000,0.000,1.00,left3,wall27 # block 3
2040 0 0 0     0 if ( ( $elts[0] eq "\*obs" ) and ( $elts[13] ~~ @obsnumbers ) )
2041             {
2042 0         0 push ( @tempobs, $line );
2043             }
2044             }
2045            
2046 0 0       0 open ( GEOFILE, ">$geofile" ) or die;
2047 0         0 my $countline = 0;
2048 0         0 foreach my $line ( @geolines )
2049             {
2050 0         0 my @elts = split(/\s+|,/, $line); #say "elts: " . dump(@elts);
2051            
2052 0 0 0     0 if ( ( $elts[0] eq "\*obs" ) and ( $elts[13] ~~ @obsnumbers ) )
2053             {
2054 0         0 print GEOFILE $templines[ $countline ];
2055             }
2056             else
2057             {
2058 0         0 print GEOFILE $line;
2059             }
2060 0         0 $countline++,
2061             }
2062 0         0 close GEOFILE;
2063             }
2064             } # END SUB bring_obstructions_back
2065              
2066              
2067             sub recalculateish
2068             {
2069 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $countvar, $fileconfig ) = @_;
2070            
2071 0         0 my @applytype = @$swap;
2072            
2073 0         0 say "Updating the insolation calculations for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2074              
2075 0         0 my $zone_letter = $applytype[$countop][3];
2076              
2077 0         0 my $printthis =
2078             "prj -file $to/cfg/$fileconfig -mode script<
2079              
2080             m
2081             c
2082             f
2083             *
2084             a
2085             a
2086             -
2087             -
2088             -
2089             -
2090             -
2091             -
2092             YYY
2093             ";
2094 0 0       0 if ($exeonfiles eq "y")
2095             {
2096 0         0 print `$printthis`;
2097             }
2098              
2099 0         0 print TOSHELL "
2100             #Updating the insolation calculations for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2101             $printthis";
2102             } #END SUB RECALCULATEISH
2103            
2104              
2105             sub ifempty
2106             {
2107 0     0 0 0 my ( $dir, $d ) = @_;
2108 0 0       0 opendir($d, $dir) or die;
2109 0 0       0 return ( scalar( grep{ $_ ne "." and $_ ne ".." } readdir($d)) == 0 );
  0         0  
2110             }
2111              
2112            
2113             sub daylightcalc # IT WORKS ONLY IF THE "RAD" DIRECTORY IS EMPTY
2114             {
2115 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $filedf, $swap2, $countvar, $fileconfig ) = @_;
2116            
2117 0         0 my @applytype = @$swap;
2118 0         0 my $zone_letter = $applytype[$countop][3];
2119 0         0 my @daylightcalc = @$swap2;
2120            
2121 0         0 say "Performing daylight calculations through Radiance for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2122              
2123 0         0 my $zone = $daylightcalc[0];
2124 0         0 my $surface = $daylightcalc[1];
2125 0         0 my $where = $daylightcalc[2];
2126 0         0 my $edge = $daylightcalc[3];
2127 0         0 my $distance = $daylightcalc[4];
2128 0         0 my $density = $daylightcalc[5];
2129 0         0 my $accuracy = $daylightcalc[6];
2130 0         0 my $filedf = $daylightcalc[7];
2131 0         0 my $pathdf = "$to/rad/$filedf";
2132 0         0 my $printthis;
2133            
2134 0 0       0 if ( not ( ifempty ( "$to/rad/" ) ) )
2135             {
2136 0         0 $printthis =
2137             "
2138             cd $to/cfg/
2139             e2r -file $to/cfg/$fileconfig -mode script<
2140             a
2141              
2142             d
2143              
2144             g
2145             -
2146             e
2147             d
2148              
2149              
2150              
2151             y
2152             -
2153             g
2154             y
2155             $zone
2156             -
2157             $surface
2158             $distance
2159             $where
2160             $edge
2161             -
2162             $density
2163              
2164             i
2165             $accuracy
2166             y
2167             a
2168             a
2169             -
2170             -
2171             YYY
2172             \n\n
2173             cd $mypath
2174             ";
2175             }
2176            
2177 0 0       0 if ( ifempty ( "$to/rad/" ) )
2178             {
2179 0         0 $printthis =
2180             "
2181             cd $to/cfg/
2182             e2r -file $to/cfg/$fileconfig -mode script<
2183              
2184             a
2185              
2186             a
2187             d
2188             $zone
2189             -
2190             $surface
2191             $distance
2192             $where
2193             $edge
2194             -
2195             $density
2196             y
2197             $accuracy
2198             a
2199             -
2200             -
2201             -
2202             -
2203             -
2204             YYY
2205             \n\n
2206             cd $mypath
2207             ";
2208             }
2209            
2210 0 0       0 if ($exeonfiles eq "y")
2211             {
2212 0         0 print `$printthis`;
2213             }
2214              
2215 0         0 print TOSHELL "
2216             #Performing daylight calculations through Radiance for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2217             $printthis";
2218              
2219 0 0       0 open( RADFILE, $pathdf) or die "Can't open $pathdf: $!\n";
2220 0         0 my @linesrad = ;
2221 0         0 close RADFILE;
2222 0         0 my @dfs;
2223             my $dfaverage;
2224 0         0 my $sum = 0;
2225 0         0 foreach my $linerad (@linesrad)
2226             {
2227 0         0 $linerad =~ s/^\s+//;
2228 0         0 my @rowelements = split(/\s+|,/, $linerad);
2229 0         0 push (@dfs, $rowelements[-1]);
2230             }
2231 0         0 foreach my $df (@dfs)
2232             {
2233 0         0 $sum = ($sum + $df);
2234             }
2235 0         0 $dfaverage = ( $sum / scalar(@dfs) );
2236              
2237 0 0       0 open( DFFILE, ">>$dffile" ) or die "Can't open $dffile: $!";
2238 0         0 print DFFILE "$dfaverage\n";
2239 0         0 close DFFILE;
2240              
2241             } # END SUB daylightcalc
2242              
2243              
2244            
2245             sub change_config
2246             {
2247 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
2248            
2249 0         0 my @applytype = @$swap;
2250 0         0 my $zone_letter = $applytype[$countop][3];
2251 0         0 my @change_config = @$swap2;
2252            
2253 0         0 say "Substituting a configuration file for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2254              
2255 0         0 my @change_conf = @{$change_config[$countezone]};
  0         0  
2256 0         0 my @original_configfiles = @{$change_conf[0]};
  0         0  
2257 0         0 my @new_configfiles = @{$change_conf[1]};
  0         0  
2258 0         0 my $countconfig = 0;
2259 0         0 my $original_configfile = $original_configfiles[$countstep-1];
2260 0         0 my $new_configfile = $new_configfiles[$countstep-1];
2261 0 0       0 if ( $new_configfile ne $original_configfile )
2262             {
2263 0 0       0 if ($exeonfiles eq "y") { print `cp -f $to/$new_configfile $to/$original_configfile\n`; }
  0         0  
2264 0         0 print TOSHELL "cp -f $to/$new_configfile $to/$original_configfile\n";
2265             }
2266 0         0 $countconfig++;
2267             } # END SUB copy_config
2268              
2269              
2270             sub checkfile # THIS CHECKS IF A SOURCE FILE MUST BE SUBSTITUTED BY ANOTHER ONE.
2271             {
2272 0     0 0 0 my ( $sourceaddress, $targetaddress ) = @_;
2273              
2274 0 0 0     0 unless ( ($sourceaddress eq "" ) or ( $targetaddress eq "" ))
2275             {
2276 0         0 print $_outfile_ "TARGETFILE IN FUNCTION: $targetaddress\n";
2277 0 0       0 if ( $sourceaddress ne $targetaddress )
2278             {
2279 0 0       0 if ($exeonfiles eq "y")
2280             {
2281 0         0 print
2282             `cp -f $sourceaddress $targetaddress\n`;
2283             }
2284 0         0 print TOSHELL
2285             "cp -f $sourceaddress $targetaddress\n\n";
2286             }
2287             }
2288             } # END SUB checkfile
2289              
2290              
2291             sub change_climate ### THIS SIMPLE SCRIPT HAS TO BE DEBUGGED. WHY DOES IT BLOCK ITSELF IF PRINTED TO THE SHELL?
2292             { # THIS FUNCTION CHANGES THE CLIMATE FILES.
2293 0     0 0 0 my $to = shift;
2294 0         0 my $stepsvar = shift;
2295 0         0 my $countop = shift;
2296 0         0 my $countstep = shift;
2297 0         0 my $swap = shift;
2298 0         0 my @applytype = @$swap;
2299 0         0 my $zone_letter = $applytype[$countop][3];
2300 0         0 my $change_climate = shift;
2301 0         0 my $countvar = shift;
2302 0         0 my $fileconfig = shift;
2303            
2304 0         0 say "Substituting climate database for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2305              
2306 0         0 my @climates = @{$change_climate[$countop]};
  0         0  
2307 0         0 my $climate = $climates[$countstep-1];
2308 0 0       0 open ( FILECONFIG, $fileconfig ) or die;
2309 0         0 print TOSHELL "opening $fileconfig for reading\n";
2310 0         0 my @lines = ;
2311 0         0 my ( $oldfile, $climatefolder );
2312 0         0 foreach my $line ( @lines )
2313             {
2314 0 0       0 if ( $line =~ /^\*clm/ )
2315             {
2316 0         0 my @row = split ( /\s+/ , $line );
2317 0         0 $climatefile = $row[1]
2318             }
2319 0         0 ( $climatefolder, $oldfile ) = /(.+\/)(\w+)/ ;
2320 0         0 $line =~ s/$oldfile$/$climate/;
2321            
2322 0         0 my $tempfileconfig = $fileconfig . ".temp";
2323 0 0       0 open ( TEMPFILECONFIG, ">$tempfileconfig" ) or die;
2324 0         0 print TOSHELL "opening $tempfileconfig for printing\n";
2325 0         0 print TEMPFILECONFIG $line;
2326             }
2327 0         0 close FILECONFIG;
2328 0         0 close TEMPFILECONFIG;
2329 0         0 `cp -R -f $tempfileconfig $fileconfig\n`;
2330 0         0 print TOSHELL "cp -R -f $tempfileconfig $fileconfig\n";
2331              
2332 0         0 print TOSHELL "
2333             #Substituting a configuration file with climate updated for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2334             $printthis";
2335             }
2336              
2337            
2338             sub recalculatenet # THIS FUNCTION HAS BEEN OUTDATED BY THOSE FOR CONSTRAINING THE NETS, BELOW, BUT WORKS AND IS SIMPLER
2339             {
2340 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
2341            
2342 0         0 my @applytype = @$swap;
2343 0         0 my $zone_letter = $applytype[$countop][3];
2344 0         0 my @recalculatenet = @$swap2;
2345            
2346 0         0 say "Adequating the ventilation network for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2347            
2348 0         0 my $filenet = $recalculatenet[0];
2349 0         0 my $infilenet = "$mypath/$file/nets/$filenet";
2350 0         0 my @nodezone_data_tot = @{$recalculatenet[1]}; ################
  0         0  
2351 0         0 my @nodesdata_tot = @{$recalculatenet[2]}; ###############
  0         0  
2352 0         0 my $geosourcefilesref = $recalculatenet[3]; ###################
2353 0         0 my $configaddress = $recalculatenet[4]; # FILE FOR PROPAGATION OF CONSTRAINTS
2354 0         0 my $y_or_n_reassign_cp = $recalculatenet[5];
2355 0         0 my $y_or_n_detect_obs = $recalculatenet[6];
2356 0         0 my @crackwidths = @{$recalculatenet[8]};
  0         0  
2357            
2358 0         0 my @geosourcefiles = @$geosourcefilesref; ##################
2359            
2360 0         0 my ( @geos, @genobs, @genobspoints );
2361            
2362 0         0 my $countgeo = 0;
2363 0         0 foreach my $nodezone_dataref ( @nodezone_data_tot )
2364             {
2365            
2366 0         0 my ( @obstaclesdata, @differences, @ratios );
2367 0         0 my $countlines = 0;
2368 0         0 my $countnode = 0;
2369 0         0 my $geosourcefile = $geosourcefiles->[ $countgeo ];
2370 0         0 my $sourceaddress = "$to$geosourcefile";
2371 0 0       0 open( SOURCEFILE, $sourceaddress ) or die "Can't open $geosourcefile 2: $!\n";
2372 0         0 my @linesgeo = ;
2373 0         0 close SOURCEFILE;
2374 0         0 my $countvert = 0;
2375 0         0 my $countobs = 0;
2376 0         0 my ( $zone, $line, $xlenght, $ylenght, $truedistance, $heightdifference );
2377 0         0 my ( @rowelements, @node, @component, @v, @obs, @obspoints, @obstructionpoint );
2378            
2379 0         0 foreach my $line (@linesgeo)
2380             {
2381 0         0 $line =~ s/^\s+//;
2382              
2383 0         0 my @rowelements = split(/\s+|,/, $line);
2384 0 0       0 if ($rowelements[0] eq "*vertex" )
    0          
2385             {
2386 0 0       0 if ($countvert == 0)
2387             {
2388 0         0 push (@v, [ "vertices_of_$sourceaddress" ]);
2389 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2390             }
2391              
2392 0 0       0 if ($countvert > 0)
2393             {
2394 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2395             }
2396 0         0 $countvert++;
2397             }
2398             elsif ($rowelements[0] eq "*obs" )
2399             {
2400 0         0 push (@obs, [ $rowelements[1], $rowelements[2], $rowelements[3], $rowelements[4],
2401             $rowelements[5], $rowelements[6], $rowelements[7], $rowelements[8], $rowelements[9], $rowelements[10] ] );
2402 0         0 $countobs++;
2403             }
2404 0         0 $countlines++;
2405             }
2406              
2407             #if ( $y_or_n_detect_obs eq "y") ### THIS HAS YET TO BE DONE AND WORK.
2408             #{
2409             # foreach my $ob (@obs)
2410             # {
2411             # push (@obspoints , [ $$ob[0], $$ob[1],$$ob[5] ] );
2412             # push (@obspoints , [ ($$ob[0] + ( $$ob[3] / 2) ), ( $$ob[1] + ( $$ob[4] / 2 ) ) , $$ob[5] ] );
2413             # push (@obspoints , [ ($$ob[0] + $$ob[3]), ( $$ob[1] + $$ob[4] ) , $$ob[5] ] );
2414             # }
2415             #}
2416             #else
2417             #{
2418 0         0 @obspoints = @{$recalculatenet[7]};
  0         0  
2419             #}
2420 0         0 push ( @geos, [ @v ] );
2421 0         0 push ( @genobs, [ @obs ] );
2422 0         0 push ( @genobspoints, [ @genobs ] );
2423 0         0 $countgeo++;
2424             }
2425            
2426 0         0 my ( @winpoints, @windowpoints, @windimsfront, @windimseast, @windimsback, @windimswest, @windsims, @windareas, @jointlenghts );
2427 0         0 my ( $jointfront, $jointeast, $jointback, $jointwest, $windimxfront, $windimyfront,
2428             $windimxback, $windimyback, $windimxeast, $windimyeast, $windimxwest, $windimywest );
2429              
2430 0 0       0 if ($constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
2431             # FOR PROPAGATION OF CONSTRAINTS
2432              
2433 0 0       0 if ($y_or_n_reassign_cp == "y")
2434             {
2435 0         0 eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS
2436             # IS EVALUATED, AND HERE BELOW CONSTRAINTS ARE PROPAGATED.
2437             # vertices CAN BE CALLED BY NAME with $geo[ $zonenumber ][ ]
2438             # x, y or z CAN BE CALLED WITH THE NUMBERS 0, 1 or 2: EXAMPLE: $genobs[ $zonenumber ][ $vertexnumber ][ 0, 1 or 2 ]
2439             # ZONENUMBER DERIVES FROM $countop.
2440             # OBSTRUCTION CAN BE CALLED WITH $genobs[ $zonenumber ][ $obstruction_number ]
2441             # REMEMBER TO ASSIGN THE $height IN THE CONFIGURATION FILE.
2442             # UNLESS, ESP-r WILL ASSIGN THAT FOR YOU AND THIS IS NOT ALWAYS WHAT YOU WANT.
2443             }
2444              
2445              
2446 0 0       0 open( INFILENET, $infilenet ) or die "Can't open $infilenet 2: $!\n";
2447 0         0 my @linesnet = ;
2448 0         0 close INFILENET;
2449              
2450 0         0 my @letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
2451             "t", "u", "v", "w", "x", "y", "z");
2452            
2453 0         0 my $countnode = 0;
2454 0         0 my ( $interfaceletter, $calcpressurecoefficient, $nodetype, $nodeletter, $mode );
2455 0         0 my $countlines = 0;
2456 0         0 my $countopening = 0;
2457 0         0 my $countcrack = 0;
2458 0         0 my $countthing = 0;
2459 0         0 my $countjoint = 0;
2460 0         0 foreach my $line (@linesnet)
2461             {
2462 0         0 $line =~ s/^\s+//;
2463 0         0 @rowelements = split(/\s+/, $line);
2464              
2465 0 0       0 if ($rowelements[0] eq "Node") { $mode = "nodemode"; }
  0         0  
2466 0 0       0 if ($rowelements[0] eq "Component") { $mode = "componentmode"; }
  0         0  
2467 0 0 0     0 if ( ( $mode eq "nodemode" ) and ($countlines > 1) and ($countlines < (2 + scalar(@nodesdata) ) ) )
      0        
2468             {
2469 0         0 $countnode = ($countlines - 2);
2470 0         0 $zone = $nodesdata[$countnode][0];
2471 0         0 $interfaceletter = $nodesdata[$countnode][1];
2472 0         0 $calcpressurecoefficient = $nodesdata[$countnode][2];
2473 0         0 $nodetype = $rowelements[2];
2474 0         0 $nodeletter = $letters[$countnode];
2475              
2476 0 0       0 if ( $nodetype eq "0")
    0          
2477             {
2478 0         0 my $printthis =
2479             "prj -file $to/cfg/$fileconfig -mode script<
2480              
2481              
2482             m
2483             e
2484             c
2485              
2486             n
2487             c
2488             $nodeletter
2489              
2490             a
2491             a
2492             y
2493             $zone
2494              
2495             $height
2496             a
2497              
2498             -
2499             -
2500             y
2501              
2502             y
2503             -
2504             -
2505             -
2506             -
2507             -
2508             -
2509             -
2510             -
2511             YYY
2512             ";
2513 0 0       0 if ($exeonfiles eq "y")
2514             {
2515 0         0 print `$printthis`;
2516             }
2517              
2518 0         0 print TOSHELL "
2519             #Adequating the ventilation network for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2520             $printthis";
2521 0         0 $countnode++;
2522             }
2523             elsif ( $nodetype eq "3")
2524             {
2525 0 0       0 if ($y_or_n_reassign_cp == "y")
2526             {
2527 0         0 my $printthis =
2528             "prj -file $to/cfg/$fileconfig -mode script<
2529              
2530              
2531             m
2532             e
2533             c
2534              
2535             n
2536             c
2537             $nodeletter
2538              
2539             a
2540             e
2541             $zone
2542             $interfaceletter
2543             $calcpressurecoefficient
2544             y
2545              
2546             $height
2547             -
2548             -
2549             y
2550              
2551             y
2552             -
2553             -
2554             -
2555             -
2556             -
2557             -
2558             -
2559             -
2560             YYY
2561             ";
2562 0 0       0 if ($exeonfiles eq "y")
2563             {
2564 0         0 print `printthis`;
2565             }
2566              
2567 0         0 print TOSHELL "
2568             #Adequating the ventilation network for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2569             $printthis";
2570 0         0 $countnode++;
2571             }
2572             }
2573             }
2574              
2575 0         0 my @node_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
2576             "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
2577 0 0 0     0 if ( ($mode eq "componentmode") and ( $line =~ "opening"))
    0 0        
2578             {
2579 0         0 my $printthis =
2580             "prj -file $to/cfg/$fileconfig -mode script<
2581              
2582              
2583             m
2584             e
2585             c
2586              
2587             n
2588             d
2589             $node_letters[$countthing]
2590              
2591             k
2592             -
2593             $windareas[$countopening]
2594             -
2595             -
2596             y
2597              
2598             y
2599             -
2600             -
2601             -
2602             -
2603             -
2604             -
2605             -
2606             YYY
2607             ";
2608 0 0       0 if ($exeonfiles eq "y")
2609             {
2610 0         0 print `$printthis`;
2611             }
2612              
2613 0         0 print TOSHELL "
2614             #Adequating the ventilation network for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2615             $printthis";
2616              
2617 0         0 $countopening++;
2618 0         0 $countthing++;
2619             }
2620             elsif ( ($mode eq "componentmode") and ( $line =~ "crack "))
2621             {
2622 0         0 MY $printthis =
2623             "prj -file $to/cfg/$fileconfig -mode script<
2624              
2625              
2626             m
2627             e
2628             c
2629              
2630             n
2631             d
2632             $node_letters[$countthing]
2633              
2634             l
2635             -
2636             $crackwidths[$countjoint] $jointlenghts[$countjoint]
2637             -
2638             -
2639             y
2640              
2641             y
2642             -
2643             -
2644             -
2645             -
2646             -
2647             -
2648             -
2649             YYY
2650             ";
2651 0 0       0 if ($exeonfiles eq "y")
2652             {
2653 0         0 print `$printthis`;
2654             }
2655              
2656 0         0 print TOSHELL $printthis;
2657              
2658 0         0 $countcrack++;
2659 0         0 $countthing++;
2660 0         0 $countjoint++;
2661             }
2662 0         0 $countlines++;
2663             }
2664             } # END SUB recalculatenet
2665              
2666              
2667              
2668             sub apply_constraints
2669             {
2670 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
2671            
2672 0         0 my @applytype = @$swap;
2673 0         0 my $zone_letter = $applytype[$countop][3];
2674 0         0 my @apply_constraints = @$swap2;
2675              
2676 0         0 my ( $value_reshape, $ybasewall, $ybasewindow );
2677 0         0 my @v;
2678            
2679 0         0 say "Propagating geometry constraints for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2680              
2681 0         0 foreach my $group_operations ( @apply_constraints )
2682             {
2683 0         0 my @group = @{$group_operations};
  0         0  
2684              
2685 0         0 my @sourcefiles = @{$group[0]};
  0         0  
2686 0         0 my @targetfiles = @{$group[1]};
  0         0  
2687 0         0 my @configfiles = @{$group[2]};
  0         0  
2688 0         0 my @basevalues = @{$group[3]};
  0         0  
2689 0         0 my @swingvalues = @{$group[4]};
  0         0  
2690 0         0 my @work_values = @{$group[5]};
  0         0  
2691 0         0 my $longmenu = $group[6];
2692 0         0 my ( $basevalue, $targetfile, $configfile, $swingvalue, $sourceaddress, $targetaddress, $configaddress );
2693 0         0 my $countops = 0;
2694              
2695 0         0 foreach $sourcefile ( @sourcefiles )
2696             {
2697 0         0 $basevalue = $basevalues[$countops];
2698 0         0 $sourcefile = $sourcefiles[$countops];
2699 0         0 $targetfile = $targetfiles[$countops];
2700 0         0 $configfile = $configfiles[$countops];
2701 0         0 $swingvalue = $swingvalues[$countops];
2702 0         0 $sourceaddress = "$to$sourcefile";
2703 0         0 $targetaddress = "$to$targetfile";
2704 0         0 $configaddress = "$to/opts/$configfile";
2705 0         0 $longmenu = $longmenus[$countops];
2706 0         0 checkfile($sourceaddress, $targetaddress);
2707            
2708 0 0       0 if ( ref ( $swingvalue ) )
2709             {
2710 0         0 my $min = $swingvalue->[0];
2711 0         0 my $max = $swingvalue->[1];
2712 0         0 $swingvalue = ( $max - $min );
2713             }
2714             else
2715             {
2716             ;
2717             }
2718            
2719              
2720 0 0       0 open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourcefile 2: $!\n";
2721 0         0 my @lines = ;
2722 0         0 close SOURCEFILE;
2723 0         0 my $countlines = 0;
2724 0         0 my $countvert = 0;
2725 0         0 foreach my $line (@lines)
2726             {
2727 0         0 $line =~ s/^\s+//;
2728 0         0 my @rowelements = split(/\s+|,/, $line);
2729 0 0       0 if ($rowelements[0] eq "*vertex" )
2730             {
2731 0 0       0 if ($countvert == 0)
2732             {
2733 0         0 push (@v, [ "vertices of $sourceaddress" ]);
2734 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2735             }
2736              
2737 0 0       0 if ($countvert > 0)
2738             {
2739 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2740             }
2741 0         0 $countvert++;
2742             }
2743 0         0 $countlines++;
2744             }
2745              
2746 0         0 my @vertexletters;
2747 0 0       0 if ($longmenu eq "y")
2748             {
2749 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
2750             "o", "p", "0\nb\nq", "0\nb\nr", "0\nb\ns", "0\nb\nt", "0\nb\nu", "0\nb\nv", "0\nb\nw",
2751             "0\nb\nx", "0\nb\ny", "0\nb\nz", "0\nb\na", "0\nb\nb","0\nb\nc","0\nb\nd","0\nb\ne",
2752             "0\nb\n0\nb\nf","0\nb\n0\nb\ng","0\nb\n0\nb\nh","0\nb\n0\nb\ni","0\nb\n0\nb\nj",
2753             "0\nb\n0\nb\nk","0\nb\n0\nb\nl","0\nb\n0\nb\nm","0\nb\n0\nb\nn","0\nb\n0\nb\no",
2754             "0\nb\n0\nb\np","0\nb\n0\nb\nq","0\nb\n0\nb\nr","0\nb\n0\nb\ns","0\nb\n0\nb\nt");
2755             }
2756             else
2757             {
2758 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
2759             "n", "o", "p", "0\nq", "0\nr", "0\ns", "0\nt", "0\nu", "0\nv", "0\nw", "0\nx",
2760             "0\ny", "0\nz", "0\na", "0\nb","0\n0\nc","0\n0\nd","0\n0\ne","0\n0\nf","0\n0\ng",
2761             "0\n0\nh","0\n0\ni","0\n0\nj","0\n0\nk","0\n0\nl","0\n0\nm","0\n0\nn","0\n0\no",
2762             "0\n0\np","0\n0\nq","0\n0\nr","0\n0\ns","0\n0\nt");
2763             }
2764              
2765 0 0       0 if ($constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
2766             # FOR PROPAGATION OF CONSTRAINTS
2767              
2768 0 0       0 if (-e $configaddress)
2769             {
2770 0         0 eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS
2771             # IS EVALUATED, AND HERE BELOW CONSTRAINTS ARE PROPAGATED.
2772              
2773 0 0       0 if ($constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
2774             # FOR PROPAGATION OF CONSTRAINTS
2775              
2776              
2777 0         0 my $countvertex = 0;
2778 0         0 foreach (@v)
2779             {
2780 0 0       0 if ($countvertex > 0)
2781             {
2782 0         0 my $vertexletter = $vertexletters[$countvertex-1];
2783 0 0       0 if ($vertexletter ~~ @work_values)
2784             {
2785 0         0 my $printthis =
2786             "prj -file $to/cfg/$fileconfig -mode script<
2787              
2788             m
2789             c
2790             a
2791             $zone_letter
2792             d
2793             $vertexletter
2794             $v[$countvertex][0] $v[$countvertex][1] $v[$countvertex][2]
2795             -
2796             y
2797             -
2798             y
2799             c
2800             -
2801             -
2802             -
2803             -
2804             -
2805             -
2806             -
2807             -
2808             -
2809             YYY
2810             ";
2811 0 0       0 if ($exeonfiles eq "y")
2812             {
2813 0         0 print `$printthis`;
2814             }
2815              
2816 0         0 print TOSHELL "
2817             #Propagating geometry constraints for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2818             $printthis";
2819             }
2820             }
2821 0         0 $countvertex++;
2822             }
2823             }
2824 0         0 $countops++;
2825             }
2826             }
2827             } # END SUB apply_constraints
2828              
2829              
2830              
2831             sub reshape_windows # IT APPLIES CONSTRAINTS
2832             {
2833 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
2834            
2835 0         0 my @applytype = @$swap;
2836 0         0 my $zone_letter = $applytype[$countop][3];
2837 0         0 my @reshape_windows = @$swap2;
2838            
2839 0         0 say "Reshaping windows for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
2840              
2841 0         0 my ( @work_letters, @v );
2842              
2843 0         0 foreach my $group_operations ( @{$reshape_windows[$countop]} )
  0         0  
2844             {
2845 0         0 my @group = @{$group_operations};
  0         0  
2846 0         0 my @sourcefiles = @{$group[0]};
  0         0  
2847 0         0 my @targetfiles = @{$group[1]};
  0         0  
2848 0         0 my @configfiles = @{$group[2]};
  0         0  
2849 0         0 my @basevalues = @{$group[3]};
  0         0  
2850 0         0 my @swingvalues = @{$group[4]};
  0         0  
2851 0         0 my @work_letters = @{$group[5]};
  0         0  
2852 0         0 my @longmenus = @{$group[6]};
  0         0  
2853              
2854 0         0 my $countops = 0;
2855 0         0 foreach $sourcefile ( @sourcefiles )
2856             {
2857 0         0 my $basevalue = $basevalues[$countops];
2858 0         0 my $sourcefile = $sourcefiles[$countops];
2859 0         0 my $targetfile = $targetfiles[$countops];
2860 0         0 my $configfile = $configfiles[$countops];
2861 0         0 my $swingvalue = $swingvalues[$countops];
2862 0         0 my $longmenu = $longmenus[$countops];
2863 0         0 my $sourceaddress = "$to$sourcefile";
2864 0         0 my $targetaddress = "$to$targetfile";
2865 0         0 my $configaddress = "$to/opts/$configfile";
2866 0         0 my $totalswing;
2867 0 0       0 unless ( ref ( $swingvalue ) )
2868             {
2869 0         0 $totalswing = ( 2 * $swingvalue );
2870             }
2871            
2872 0 0       0 if ( ref ( $swingvalue ) )
2873             {
2874 0         0 my $min = $swingvalue->[0];
2875 0         0 my $max = $swingvalue->[1];
2876 0         0 $totalswing = ( $max - $min );
2877             }
2878            
2879 0         0 my $pace = ( $totalswing / ( $stepsvar - 1 ) );
2880 0         0 checkfile($sourceaddress, $targetaddress);
2881            
2882 0 0       0 open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourcefile 2: $!\n";
2883 0         0 my @lines = ;
2884 0         0 close SOURCEFILE;
2885              
2886 0         0 my $countlines = 0;
2887 0         0 my $countvert = 0;
2888 0         0 foreach my $line (@lines)
2889             {
2890 0         0 $line =~ s/^\s+//;
2891              
2892 0         0 my @rowelements = split(/\s+|,/, $line);
2893 0 0       0 if ($rowelements[0] eq "*vertex" )
2894             {
2895 0 0       0 if ($countvert == 0)
2896             {
2897 0         0 push (@v, [ "vertices of $sourceaddress", [], [] ]);
2898 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2899             }
2900              
2901 0 0       0 if ($countvert > 0)
2902             {
2903 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
2904             }
2905              
2906 0         0 $countvert++;
2907             }
2908 0         0 $countlines++;
2909             }
2910              
2911 0         0 my @vertexletters;
2912 0 0       0 if ($longmenu eq "y")
2913             {
2914 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
2915             "n", "o", "p", "0\nb\nq", "0\nb\nr", "0\nb\ns", "0\nb\nt", "0\nb\nu", "0\nb\nv",
2916             "0\nb\nw", "0\nb\nx", "0\nb\ny", "0\nb\nz", "0\nb\na", "0\nb\nb","0\nb\nc","0\nb\nd",
2917             "0\nb\ne","0\nb\n0\nb\nf","0\nb\n0\nb\ng","0\nb\n0\nb\nh","0\nb\n0\nb\ni",
2918             "0\nb\n0\nb\nj","0\nb\n0\nb\nk","0\nb\n0\nb\nl","0\nb\n0\nb\nm","0\nb\n0\nb\nn",
2919             "0\nb\n0\nb\no","0\nb\n0\nb\np","0\nb\n0\nb\nq","0\nb\n0\nb\nr","0\nb\n0\nb\ns",
2920             "0\nb\n0\nb\nt");
2921             }
2922             else
2923             {
2924 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
2925             "n", "o", "p", "0\nq", "0\nr", "0\ns", "0\nt", "0\nu", "0\nv", "0\nw", "0\nx",
2926             "0\ny", "0\nz", "0\na", "0\nb","0\n0\nc","0\n0\nd","0\n0\ne","0\n0\nf","0\n0\ng",
2927             "0\n0\nh","0\n0\ni","0\n0\nj","0\n0\nk","0\n0\nl","0\n0\nm","0\n0\nn","0\n0\no",
2928             "0\n0\np","0\n0\nq","0\n0\nr","0\n0\ns","0\n0\nt");
2929             }
2930              
2931 0         0 $value_reshape_window = ( ( $basevalue - $swingvalue) + ( $pace * ( $countstep - 1 )) );
2932              
2933 0 0       0 if (-e $configaddress)
2934             {
2935              
2936 0         0 eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS
2937             # IS EVALUATED, AND HERE BELOW CONSTRAINTS ARE PROPAGATED.
2938              
2939 0 0       0 if (-e $constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
2940             # FOR PROPAGATION OF CONSTRAINTS
2941              
2942 0         0 my $countvertex = 0;
2943              
2944 0         0 foreach (@v)
2945             {
2946 0 0       0 if ($countvertex > 0)
2947             {
2948 0         0 my $vertexletter = $vertexletters[$countvertex];
2949 0 0       0 if ($vertexletter ~~ @work_letters)
2950             {
2951 0         0 my $printthis =
2952             "prj -file $to/cfg/$fileconfig -mode script<
2953              
2954             m
2955             c
2956             a
2957             $zone_letter
2958             d
2959             $vertexletter
2960             $v[$countvertex+1][0] $v[$countvertex+1][1] $v[$countvertex+1][2]
2961             -
2962             y
2963             -
2964             y
2965             c
2966             -
2967             -
2968             -
2969             -
2970             -
2971             -
2972             -
2973             -
2974             -
2975             YYY
2976             ";
2977 0 0       0 if ($exeonfiles eq "y")
2978             {
2979 0         0 print `$printthis`;
2980             }
2981              
2982 0         0 print TOSHELL "
2983             #Reshaping windows for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
2984             $printthis";
2985             }
2986             }
2987 0         0 $countvertex++;
2988             }
2989             }
2990 0         0 $countops++;
2991             }
2992              
2993             }
2994             } # END SUB reshape_windows
2995              
2996              
2997             sub warp #
2998             {
2999 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $warp, $countvar, $fileconfig ) = @_;
3000            
3001 0         0 my @applytype = @$swap;
3002 0         0 my $zone_letter = $applytype[$countop][3];
3003            
3004 0         0 say "Warping zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
3005              
3006 0         0 my @surfs_to_warp = @{ $warp->[$countop][0] };
  0         0  
3007 0         0 my @vertices_numbers = @{ $warp->[$countop][1] };
  0         0  
3008 0         0 my @swingrotations = @{ $warp->[$countop][2] };
  0         0  
3009 0         0 my @yes_or_no_apply_to_others = @{ $warp->[$countop][3] };
  0         0  
3010 0         0 my $configfilename = $$warp[$countop][4];
3011 0         0 my $configfile = $to."/opts/".$configfilename;
3012 0         0 my @pairs_of_vertices = @{ $warp->[$countop][5] }; # @pairs_of_vertices defining axes
  0         0  
3013 0         0 my @windows_to_reallign = @{ $warp->[$countop][6] };
  0         0  
3014 0         0 my $sourcefilename = $$warp[$countop][7];
3015 0         0 my $sourcefile = $to.$sourcefilename;
3016 0         0 my $longmenu = $$warp[$countop][8];
3017 0         0 my $countrotate = 0;
3018 0         0 foreach my $surface_letter (@surfs_to_warp)
3019             {
3020 0         0 $swingrotate = $swingrotations[$countrotate];
3021            
3022 0 0       0 if ( ref ( $swingrotate ) )
3023             {
3024 0         0 my $min = $swingrotate->[0];
3025 0         0 my $max = $swingrotate->[1];
3026 0         0 $swingrotate = ( $max - $min );
3027             }
3028            
3029 0         0 $pacerotate = ( $swingrotate / ( $stepsvar - 1 ) );
3030 0         0 $rotation_degrees = ( ( $swingrotate / 2 ) - ( $pacerotate * ( $countstep - 1 ) )) ;
3031 0         0 $vertex_number = $vertices_numbers[$countrotate];
3032 0         0 $yes_or_no_apply = $yes_or_no_apply_to_others[$countrotate];
3033 0 0 0     0 if ( ( $swingrotate != 0 ) and ( $stepsvar > 1 ) and ( $yes_or_no_warp eq "y" ) )
      0        
3034             {
3035 0         0 my $printthis =
3036             "prj -file $to/cfg/$fileconfig -mode script<
3037              
3038             m
3039             c
3040             a
3041             $zone_letter
3042             e
3043             >
3044             $surface_letter
3045             c
3046             $vertex_number
3047             $rotation_degrees
3048             $yes_or_no_apply
3049             -
3050             -
3051             y
3052             c
3053             -
3054             -
3055             -
3056             -
3057             -
3058             -
3059             -
3060             -
3061             YYY
3062             ";
3063 0 0       0 if ($exeonfiles eq "y")
3064             {
3065 0         0 print `$printthis`;
3066             }
3067 0         0 print TOSHELL "
3068             #Warping zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
3069             $printthis";
3070             }
3071 0         0 $countrotate++;
3072             }
3073              
3074             # THIS SECTION READS THE CONFIG FILE FOR DIMENSIONS
3075 0 0       0 open( SOURCEFILE, $sourcefile ) or die "Can't open $sourcefile: $!\n";
3076 0         0 my @lines = ;
3077 0         0 close SOURCEFILE;
3078 0         0 my $countlines = 0;
3079 0         0 my $countvert = 0;
3080 0         0 foreach my $line (@lines)
3081             {
3082 0         0 $line =~ s/^\s+//;
3083            
3084 0         0 my @rowelements = split(/\s+|,/, $line);
3085 0 0       0 if ($rowelements[0] eq "*vertex" )
3086             {
3087 0 0       0 if ($countvert == 0)
3088             {
3089 0         0 push (@v, [ "vertices of $sourceaddress" ]);
3090 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
3091             }
3092              
3093 0 0       0 if ($countvert > 0)
3094             {
3095 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
3096             }
3097 0         0 $countvert++;
3098             }
3099 0         0 $countlines++;
3100             }
3101              
3102              
3103 0         0 my @vertexletters;
3104 0 0       0 if ($longmenu eq "y")
3105             {
3106 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
3107             "o", "p", "0\nb\nq", "0\nb\nr", "0\nb\ns", "0\nb\nt", "0\nb\nu", "0\nb\nv", "0\nb\nw",
3108             "0\nb\nx", "0\nb\ny", "0\nb\nz", "0\nb\na", "0\nb\nb","0\nb\nc","0\nb\nd","0\nb\ne",
3109             "0\nb\n0\nb\nf","0\nb\n0\nb\ng","0\nb\n0\nb\nh","0\nb\n0\nb\ni","0\nb\n0\nb\nj",
3110             "0\nb\n0\nb\nk","0\nb\n0\nb\nl","0\nb\n0\nb\nm","0\nb\n0\nb\nn","0\nb\n0\nb\no",
3111             "0\nb\n0\nb\np","0\nb\n0\nb\nq","0\nb\n0\nb\nr","0\nb\n0\nb\ns","0\nb\n0\nb\nt");
3112             }
3113             else
3114             {
3115 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
3116             "o", "p", "0\nq", "0\nr", "0\ns", "0\nt", "0\nu", "0\nv", "0\nw", "0\nx", "0\ny",
3117             "0\nz", "0\na", "0\nb","0\n0\nc","0\n0\nd","0\n0\ne","0\n0\nf","0\n0\ng","0\n0\nh",
3118             "0\n0\ni","0\n0\nj","0\n0\nk","0\n0\nl","0\n0\nm","0\n0\nn","0\n0\no","0\n0\np",
3119             "0\n0\nq","0\n0\nr","0\n0\ns","0\n0\nt");
3120             }
3121              
3122              
3123 0 0       0 if (-e $configfile)
3124             {
3125 0         0 eval `cat $configfile`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS IS EVALUATED
3126             # AND PROPAGATED.
3127              
3128 0 0       0 if (-e $constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
3129             # FOR PROPAGATION OF CONSTRAINTS
3130              
3131             }
3132             # THIS SECTION SHIFTS THE VERTEX TO LET THE BASE SURFACE AREA UNCHANGED AFTER THE WARPING.
3133              
3134 0         0 my $countthis = 0;
3135 0         0 $number_of_moves = ( (scalar(@pairs_of_vertices)) /2 ) ;
3136 0         0 foreach my $pair_of_vertices (@pairs_of_vertices)
3137             {
3138 0 0       0 if ($countthis < $number_of_moves)
3139             {
3140 0         0 $vertex1 = $pairs_of_vertices[ 0 + ( 2 * $countthis ) ];
3141 0         0 $vertex2 = $pairs_of_vertices[ 1 + ( 2 * $countthis ) ];
3142              
3143 0         0 my $printthis =
3144             "prj -file $to/cfg/$fileconfig -mode script<
3145              
3146             m
3147             c
3148             a
3149             $zone_letter
3150             d
3151             ^
3152             j
3153             $vertex1
3154             $vertex2
3155             -
3156             $addedlength
3157             y
3158             -
3159             y
3160             -
3161             y
3162             -
3163             -
3164             -
3165             -
3166             -
3167             -
3168             -
3169             -
3170             YYY
3171             ";
3172 0 0       0 if ($exeonfiles eq "y")
3173             {
3174 0         0 print `$printthis`;
3175             }
3176 0         0 print TOSHELL "
3177             #Warping zones for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.
3178             $printthis";
3179             }
3180 0         0 $countthis++;
3181             }
3182             } # END SUB warp
3183              
3184              
3185             ##############################################################################
3186             # BEGINNING OF THE SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING GEOMETRY
3187             sub constrain_geometry # IT APPLIES CONSTRAINTS TO ZONE GEOMETRY
3188             {
3189             # IT CONSTRAINS GEOMETRY FILES. IT HAS TO BE CALLED FROM THE MAIN FILE WITH:
3190             # constrain_geometry($to, $fileconfig, $stepsvar, $countop, $countstep, $exeonfiles, \@applytype, \@constrain_geometry);
3191             # constrain_geometry($to, $fileconfig, $stepsvar, $countop,
3192             # $countstep, $exeonfiles, \@applytype, \@constrain_geometry, $to_do);
3193 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $applytyperef, $constrain_geometryref, $to_do, $countvar, $fileconfig, $v_ref ) = @_;
3194            
3195 0         0 my @applytype = @$applytyperef;
3196 0         0 my $zone_letter = $applytype[$countop][3];
3197 0         0 my @constrain_geometry = @$constrain_geometryref;
3198 0         0 my @v_ = @$v_ref;
3199            
3200 0         0 say "Propagating constraints on geometry for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
3201              
3202 0         0 foreach my $elm (@constrain_geometry)
3203             {
3204 0         0 my @group = @{$elm};
  0         0  
3205 0         0 my $sourcefile = $group[0];
3206 0         0 my $targetfile = $group[1];
3207 0         0 my $configfile = $group[2];
3208 0         0 my @work_letters = @{$group[3]};
  0         0  
3209 0         0 my $longmenus = $group[4];
3210 0         0 my @swings__ = @{ $group[5] };
  0         0  
3211 0         0 my $askop = $group[6];
3212 0 0       0 unless ( $askop ) { $askop = 0; }
  0         0  
3213            
3214 0         0 my $sourceaddress = "$to$sourcefile";
3215 0         0 my $targetaddress = "$to$targetfile";
3216 0         0 my $configaddress = "$to$configfile";
3217            
3218 0         0 my ( @v, @vertexletters, @work_items, @swings, @paces );
3219            
3220 0         0 foreach ( @swings__ )
3221             {
3222 0 0       0 if ( ref ( $_ ) )
3223             {
3224 0         0 $_ = ( $_->[0] - $_->[1] );
3225             }
3226             else
3227             {
3228 0         0 $_ = ( $_ * 2 );
3229             }
3230 0         0 push ( @swings, $_ );
3231             }
3232            
3233 0         0 foreach ( @swings )
3234             {
3235 0         0 my $pace = ( $_ / ( $stepsvar - 1 ) );
3236 0         0 push ( @paces, $pace );
3237             }
3238              
3239 0 0       0 if ($longmenu eq "y")
3240             {
3241 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
3242             "o", "p", "0\nb\nq", "0\nb\nr", "0\nb\ns", "0\nb\nt", "0\nb\nu", "0\nb\nv", "0\nb\nw",
3243             "0\nb\nx", "0\nb\ny", "0\nb\nz", "0\nb\na", "0\nb\nb","0\nb\nc","0\nb\nd","0\nb\ne",
3244             "0\nb\n0\nb\nf","0\nb\n0\nb\ng","0\nb\n0\nb\nh","0\nb\n0\nb\ni","0\nb\n0\nb\nj",
3245             "0\nb\n0\nb\nk","0\nb\n0\nb\nl","0\nb\n0\nb\nm","0\nb\n0\nb\nn","0\nb\n0\nb\no",
3246             "0\nb\n0\nb\np","0\nb\n0\nb\nq","0\nb\n0\nb\nr","0\nb\n0\nb\ns","0\nb\n0\nb\nt");
3247             }
3248             else
3249             {
3250 0         0 @vertexletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
3251             "n", "o", "p", "0\nq", "0\nr", "0\ns", "0\nt", "0\nu", "0\nv", "0\nw", "0\nx",
3252             "0\ny", "0\nz", "0\na", "0\nb","0\n0\nc","0\n0\nd","0\n0\ne","0\n0\nf","0\n0\ng",
3253             "0\n0\nh","0\n0\ni","0\n0\nj","0\n0\nk","0\n0\nl","0\n0\nm","0\n0\nn","0\n0\no",
3254             "0\n0\np","0\n0\nq","0\n0\nr","0\n0\ns","0\n0\nt");
3255             }
3256            
3257 0 0       0 unless ($to_do eq "justwrite")
3258             {
3259 0         0 checkfile($sourceaddress, $targetaddress);
3260 0         0 @v = read_geometry( $sourceaddress );
3261 0         0 @v_ = read_geo_constraints( $to, $fileconfig, $stepsvar, $countop, $countstep, $configaddress, \@v, $countvar, \@swings, \@paces, \@v_ );
3262             }
3263              
3264 0 0       0 unless ($to_do eq "justread")
3265             {
3266 0         0 apply_geo_constraints( \@v_, \@vertexletters, \@work_letters, $exeonfiles, $zone_letter, $askop );
3267             } # print $_outfile_ "\@v: " . Dumper(@v) . "\n\n";
3268             }
3269             } # END SUB constrain_geometry
3270              
3271              
3272             sub read_geometry # THIS READS GEOMETRY FILES TO GET THE VERTICES.
3273             {
3274 0     0 0 0 my ( $sourceaddress ) = @_;
3275            
3276 0 0       0 open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourcefile 2: $!\n";
3277 0         0 my @lines = ;
3278 0         0 close SOURCEFILE;
3279              
3280 0         0 my $countlines = 0;
3281 0         0 my $countvert = 0;
3282 0         0 foreach my $line (@lines)
3283             {
3284 0         0 $line =~ s/^\s+//;
3285              
3286 0         0 my @rowelements = split(/\s+|,/, $line);
3287 0 0       0 if ($rowelements[0] eq "*vertex" )
3288             {
3289 0         0 push (@v, [ $rowelements[1], $rowelements[2], $rowelements[3] ] );
3290 0         0 $countvert++;
3291             }
3292 0         0 $countlines++;
3293             }
3294 0         0 return( @v );
3295             } # END SUB read_geometry
3296              
3297              
3298             sub read_geo_constraints # THIS READ GEOMETRY CONSTRAINTS.
3299             {
3300             # THIS MAKES THE vertices IN THE GEOMETRY FILES AVAILABLE TO THE USER FOR MANIPULATION, IN THE FOLLOWING FORM:
3301             # $v_[$countop][$number][$x], $v_[$countop][$number][$y], $v_[$countop][$number][$z].
3302             # EXAMPLE: $v_[0][4][$x] = 1. OR: @v_[0][4][$x] = @v_[0][4][$y]. OR: @v_[1][4][$x] = @v_[0][3][$z].
3303             # $countops number mutations in series. The $countop that is actuated is always the last, the one which is active.
3304             # So it is more safe to read everything that may be needed before giving instruction to activate propagation of constraints.
3305             # PROPAGATION OF CONSTRAINTS ALLOWS TO IMPOSE EQUALITY CONSTRAINTS TO THE SPECIED VARIABLES.
3306             # THE FOLLOWING VARIABLES ARE ALSO ALWAYS AVAILABLE:
3307             # $stepsvar, WHICH TELLS THE PROGRAM HOW MANY ITERATION STEPS IT HAS TO DO IN THE CURRENT MORPHING PHASE.
3308             # $countop, WHICH TELLS THE PROGRAM WHAT OPERATION IS BEING EXECUTED IN THE CHAIN OF OPERATIONS
3309             # $countstep, WHICH TELLS THE PROGRAM WHAT THE CURRENT ITERATION STEP IS.
3310             # $countvar, WHICH TELLS THE PROGRAM WHAT NUMBER OF DESIGN PARAMETER THE PROGRAM IS WORKING AT.
3311 0     0 0 0 my ( $to, $fileconfig, $stepsvar, $countop, $countstep, $configaddress, $vref, $countvar, $swingsref, $pacesref, $v_ref ) = @_;
3312            
3313 0         0 my @myv = @$vref;
3314 0         0 my @swings = @$swingsref;
3315 0         0 my @paces = @$pacesref;
3316 0         0 my @v_ = @v_ref;
3317              
3318 0         0 my $x = 0;
3319 0         0 my $y = 1;
3320 0         0 my $z = 2;
3321 0         0 unshift (@myv, [ "vertices of $sourceaddress. \$countop: $countop ", [], [] ]);
3322              
3323 0 0       0 if (-e $configaddress)
3324             {
3325 0         0 push ( @v_, [ @myv ]); #
3326 0         0 eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS IS EVALUATED.
3327              
3328 0 0       0 if ( -e $constrain ) { eval ( $constrain ); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0         0  
3329             # FOR PROPAGATION OF CONSTRAINTS
3330 0         0 shift ( @{ $v_[$countop]} ); #
  0         0  
3331             }
3332 0         0 return ( @v_ );
3333             } # END SUB read_geo_constraints
3334              
3335              
3336             sub apply_geo_constraints
3337             {
3338 0     0 0 0 my ( $v_ref, $vertexlettersref, $work_lettersref, $exeonfiles, $zone_letter, $askop ) = @_;
3339            
3340 0         0 my @v_ = @$v_ref;
3341 0         0 my @vertexletters = @$vertexlettersref;
3342 0         0 my @work_letters = @$work_lettersref;
3343 0         0 my @v = @{ $v_[ $askop ] };
  0         0  
3344              
3345 0         0 my $countvertex = 0;
3346 0         0 foreach my $v (@v)
3347             {
3348 0         0 my $vertexletter = $vertexletters[$countvertex];
3349            
3350 0 0 0     0 if ( (@work_letters eq "") or ($vertexletter ~~ @work_letters) )
3351             {
3352 0         0 my $printthis =
3353             "prj -file $to/cfg/$fileconfig -mode script<
3354              
3355             m
3356             c
3357             a
3358             $zone_letter
3359             d
3360             $vertexletter
3361             $v[$countvertex+1][0] $v[$countvertex+1][1] $v[$countvertex+1][2]
3362             -
3363             y
3364             -
3365             y
3366             c
3367             -
3368             -
3369             -
3370             -
3371             -
3372             -
3373             -
3374             -
3375             -
3376             YYY
3377             ";
3378 0 0       0 if ($exeonfiles eq "y")
3379             {
3380 0         0 print `$printthis`;
3381             }
3382              
3383 0         0 print TOSHELL $printthis;
3384             }
3385 0         0 $countvertex++;
3386             }
3387              
3388             } # END SUB apply_geo_constraints
3389             # END OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING GEOMETRY
3390             ##############################################################################
3391              
3392              
3393             ##############################################################################
3394             # BEGINNING OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING CONTROLS
3395             sub vary_controls
3396             { # IT IS CALLED FROM THE MAIN FILE
3397 0     0 0 0 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
3398            
3399 0         0 my @applytype = @$swap;
3400 0         0 my $zone_letter = $applytype[$countop][3];
3401 0         0 my @vary_controls = @$swap2;
3402            
3403 0         0 say "Propagating constraints on controls for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
3404              
3405 0         0 my ( $semaphore_zone, $semaphore_dataloop, $semaphore_massflow, $semaphore_setpoint, $doline );
3406 0         0 my $count_controlmass = -1;
3407 0         0 my $countline = 0;
3408 0         0 my @letters = ("e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "z"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
3409 0         0 my @period_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
3410 0         0 my $loop_hour = 2; # NOTE: THE FOLLOWING VARIABLE NAMES ARE SHADOWED IN THE FOREACH LOOP BELOW,
3411             # BUT ARE THE ONES USED IN THE OPT CONSTRAINTS FILES.
3412 0         0 my $max_heating_power = 3;
3413 0         0 my $min_heating_power = 4;
3414 0         0 my $max_cooling_power = 5,
3415             my $min_cooling_power = 6;
3416 0         0 my $heating_setpoint = 7;
3417 0         0 my $cooling_setpoint = 8;
3418 0         0 my $flow_hour = 2;
3419 0         0 my $flow_setpoint = 3;
3420 0         0 my $flow_onoff = 4;
3421 0         0 my $flow_fraction = 5;
3422 0         0 my $loop_letter;
3423             my $loopcontrol_letter;
3424              
3425 0         0 my @group = @{$vary_controls[$countop]};
  0         0  
3426 0         0 my $sourcefile = $group[0];
3427 0         0 my $targetfile = $group[1];
3428 0         0 my $configfile = $group[2];
3429 0         0 my @buildbulk = @{$group[3]};
  0         0  
3430 0         0 my @flowbulk = @{$group[4]};
  0         0  
3431            
3432 0         0 my $countbuild = 0;
3433 0         0 my $countflow = 0;
3434              
3435 0         0 my $countcontrol = 0;
3436 0         0 my $sourceaddress = "$to$sourcefile";
3437 0         0 my $targetaddress = "$to$targetfile";
3438 0         0 my $configaddress = "$to$configfile";
3439              
3440             #@loopcontrol; # DON'T PUT "my" HERE.
3441             #@flowcontrol; # DON'T PUT "my" HERE.
3442             #@new_loopcontrols; # DON'T PUT "my" HERE.
3443             #@new_flowcontrols; # DON'T PUT "my" HERE.
3444 0         0 my ( @groupzone_letters, @zone_period_letters, @flow_letters, @fileloopbulk, @fileflowbulk );
3445              
3446 0         0 checkfile($sourceaddress, $targetaddress);
3447              
3448 0 0       0 if ($countstep == 1)
3449             {
3450 0         0 read_controls($sourceaddress, $targetaddress, \@letters, \@period_letters);
3451             }
3452              
3453              
3454             sub calc_newctl
3455             { # TO BE CALLED WITH: calc_newcontrols($to, $fileconfig, $stepsvar, $countop, $countstep, \@buildbulk, \@flowbulk, \@loopcontrol, \@flowcontrol);
3456             # THIS COMPUTES CHANGES TO BE MADE TO CONTROLS BEFORE PROPAGATION OF CONSTRAINTS
3457 1     1 0 2 my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $swap3, $swap4, $countvar, $fileconfig ) = @_;
3458            
3459 1         23 my @buildbulk = @$swap;
3460 1         2 my @flowbulk = @$swap2;
3461 1         2 my @loopcontrol = @$swap3;
3462 1         2 my @flowcontrol = @$swap4;
3463              
3464 1         2 my ( @new_loop_hours, @new_max_heating_powers, @new_min_heating_powers, @new_max_cooling_powers, @new_min_cooling_powers, @new_heating_setpoints,
3465             @new_cooling_setpoints, @new_flow_hours, @new_flow_setpoints, @new_flow_onoffs, @new_flow_fractions );
3466              
3467             # HERE THE MODIFICATIONS TO BE EXECUTED ON EACH PARAMETERS ARE CALCULATED.
3468 1 50       7 if ($stepsvar == 0) {$stepsvar = 1;}
  1         3  
3469 1 50       5 if ($stepsvar > 1)
3470             {
3471 0           foreach $each_buildbulk (@buildbulk)
3472             {
3473 0           my @askloop = @{$each_buildbulk};
  0            
3474 0           my $new_loop_letter = $askloop[0];
3475 0           my $new_loopcontrol_letter = $askloop[1];
3476 0           my $swing_loop_hour = $askloop[2];
3477 0           my $swing_max_heating_power = $askloop[3];
3478 0           my $swing_min_heating_power = $askloop[4];
3479 0           my $swing_max_cooling_power = $askloop[5];
3480 0           my $swing_min_cooling_power = $askloop[6];
3481 0           my $swing_heating_setpoint = $askloop[7];
3482 0           my $swing_cooling_setpoint = $askloop[8];
3483              
3484 0           my $countloop = 0; #IT IS FOR THE FOLLOWING FOREACH. LEAVE IT ATTACHED TO IT.
3485 0           foreach $each_loop (@loopcontrol) # THIS DISTRIBUTES THIS NESTED DATA STRUCTURES IN A FLAT MODE TO PAIR THE INPUT FILE, USER DEFINED ONE.
3486             {
3487 0           my $countcontrol = 0;
3488 0           @thisloop = @{$each_loop};
  0            
3489             # my $letterfile = $letters[$countloop];
3490 0           foreach $lp (@thisloop)
3491             {
3492 0           my @control = @{$lp};
  0            
3493             # my $letterfilecontrol = $period_letters[$countcontrol];
3494 0           $loop_letter = $loopcontrol[$countloop][$countcontrol][0];
3495 0           $loopcontrol_letter = $loopcontrol[$countloop][$countcontrol][1];
3496 0 0 0       if ( ( $new_loop_letter eq $loop_letter ) and ($new_loopcontrol_letter eq $loopcontrol_letter ) )
3497             {
3498             # print $_outfile_ "YES!: \n\n\n";
3499 0           $loop_hour__ = $loopcontrol[$countloop][$countcontrol][$loop_hour];
3500 0           $max_heating_power__ = $loopcontrol[$countloop][$countcontrol][$max_heating_power];
3501 0           $min_heating_power__ = $loopcontrol[$countloop][$countcontrol][$min_heating_power];
3502 0           $max_cooling_power__ = $loopcontrol[$countloop][$countcontrol][$max_cooling_power];
3503 0           $min_cooling_power__ = $loopcontrol[$countloop][$countcontrol][$min_cooling_power];
3504 0           $heating_setpoint__ = $loopcontrol[$countloop][$countcontrol][$heating_setpoint];
3505 0           $cooling_setpoint__ = $loopcontrol[$countloop][$countcontrol][$cooling_setpoint];
3506             }
3507 0           $countcontrol++;
3508             }
3509 0           $countloop++;
3510             }
3511              
3512 0           my $pace_loop_hour = ( $swing_loop_hour / ($stepsvar - 1) );
3513 0           my $floorvalue_loop_hour = ($loop_hour__ - ($swing_loop_hour / 2) );
3514 0           my $new_loop_hour = $floorvalue_loop_hour + ($countstep * $pace_loop_hour);
3515              
3516 0           my $pace_max_heating_power = ( $swing_max_heating_power / ($stepsvar - 1) );
3517 0           my $floorvalue_max_heating_power = ($max_heating_power__ - ($swing_max_heating_power / 2) );
3518 0           my $new_max_heating_power = $floorvalue_max_heating_power + ($countstep * $pace_max_heating_power);
3519              
3520 0           my $pace_min_heating_power = ( $swing_min_heating_power / ($stepsvar - 1) );
3521 0           my $floorvalue_min_heating_power = ($min_heating_power__ - ($swing_min_heating_power / 2) );
3522 0           my $new_min_heating_power = $floorvalue_min_heating_power + ($countstep * $pace_min_heating_power);
3523              
3524 0           my $pace_max_cooling_power = ( $swing_max_cooling_power / ($stepsvar - 1) );
3525 0           my $floorvalue_max_cooling_power = ($max_cooling_power__ - ($swing_max_cooling_power / 2) );
3526 0           my $new_max_cooling_power = $floorvalue_max_cooling_power + ($countstep * $pace_max_cooling_power);
3527              
3528 0           my $pace_min_cooling_power = ( $swing_min_cooling_power / ($stepsvar - 1) );
3529 0           my $floorvalue_min_cooling_power = ($min_cooling_power__ - ($swing_min_cooling_power / 2) );
3530 0           my $new_min_cooling_power = $floorvalue_min_cooling_power + ($countstep * $pace_min_cooling_power);
3531              
3532 0           my $pace_heating_setpoint = ( $swing_heating_setpoint / ($stepsvar - 1) );
3533 0           my $floorvalue_heating_setpoint = ($heating_setpoint__ - ($swing_heating_setpoint / 2) );
3534 0           my $new_heating_setpoint = $floorvalue_heating_setpoint + ($countstep * $pace_heating_setpoint);
3535              
3536 0           my $pace_cooling_setpoint = ( $swing_cooling_setpoint / ($stepsvar - 1) );
3537 0           my $floorvalue_cooling_setpoint = ($cooling_setpoint__ - ($swing_cooling_setpoint / 2) );
3538 0           my $new_cooling_setpoint = $floorvalue_cooling_setpoint + ($countstep * $pace_cooling_setpoint);
3539              
3540 0           $new_loop_hour = sprintf("%.2f", $new_loop_hour);
3541 0           $new_max_heating_power = sprintf("%.2f", $new_max_heating_power);
3542 0           $new_min_heating_power = sprintf("%.2f", $new_min_heating_power);
3543 0           $new_max_cooling_power = sprintf("%.2f", $new_max_cooling_power);
3544 0           $new_min_cooling_power = sprintf("%.2f", $new_min_cooling_power);
3545 0           $new_heating_setpoint = sprintf("%.2f", $new_heating_setpoint);
3546 0           $new_cooling_setpoint = sprintf("%.2f", $new_cooling_setpoint);
3547              
3548 0           push(@new_loopcontrols,
3549             [ $new_loop_letter, $new_loopcontrol_letter, $new_loop_hour,
3550             $new_max_heating_power, $new_min_heating_power, $new_max_cooling_power,
3551             $new_min_cooling_power, $new_heating_setpoint, $new_cooling_setpoint ] );
3552             }
3553              
3554 0           my $countflow = 0;
3555              
3556 0           foreach my $elm (@flowbulk)
3557             {
3558 0           my @askflow = @{$elm};
  0            
3559 0           my $new_flow_letter = $askflow[0];
3560 0           my $new_flowcontrol_letter = $askflow[1];
3561 0           my $swing_flow_hour = $askflow[2];
3562 0           my $swing_flow_setpoint = $askflow[3];
3563 0           my $swing_flow_onoff = $askflow[4];
3564 0 0         if ( $swing_flow_onoff eq "ON") { $swing_flow_onoff = 1; }
  0 0          
3565 0           elsif ( $swing_flow_onoff eq "OFF") { $swing_flow_onoff = -1; }
3566 0           my $swing_flow_fraction = $askflow[5];
3567              
3568 0           my $countflow = 0; # IT IS FOR THE FOLLOWING FOREACH. LEAVE IT ATTACHED TO IT.
3569 0           foreach $each_flow (@flowcontrol) # THIS DISTRIBUTES THOSE NESTED DATA STRUCTURES IN A FLAT MODE TO PAIR THE INPUT FILE, USER DEFINED ONE.
3570             {
3571 0           my $countcontrol = 0;
3572 0           @thisflow = @{$each_flow};
  0            
3573             # my $letterfile = $letters[$countflow];
3574 0           foreach $elm (@thisflow)
3575             {
3576 0           my @control = @{$elm};
  0            
3577             # my $letterfilecontrol = $period_letters[$countcontrol];
3578 0           $flow_letter = $flowcontrol[$countflow][$countcontrol][0];
3579 0           $flowcontrol_letter = $flowcontrol[$countflow][$countcontrol][1];
3580 0 0 0       if ( ( $new_flow_letter eq $flow_letter ) and ($new_flowcontrol_letter eq $flowcontrol_letter ) )
3581             {
3582 0           $flow_hour__ = $flowcontrol[$countflow][$countcontrol][$flow_hour];
3583 0           $flow_setpoint__ = $flowcontrol[$countflow][$countcontrol][$flow_setpoint];
3584 0           $flow_onoff__ = $flowcontrol[$countflow][$countcontrol][$flow_onoff];
3585 0 0         if ( $flow_onoff__ eq "ON") { $flow_onoff__ = 1; }
  0 0          
3586 0           elsif ( $flow_onoff__ eq "OFF") { $flow_onoff__ = -1; }
3587 0           $flow_fraction__ = $flowcontrol[$countflow][$countcontrol][$flow_fraction];
3588             }
3589 0           $countcontrol++;
3590             }
3591 0           $countflow++;
3592             }
3593            
3594 0           my $pace_flow_hour = ( $swing_flow_hour / ($stepsvar - 1) );
3595 0           my $floorvalue_flow_hour = ($flow_hour__ - ($swing_flow_hour / 2) );
3596 0           my $new_flow_hour = $floorvalue_flow_hour + ($countstep * $pace_flow_hour);
3597              
3598 0           my $pace_flow_setpoint = ( $swing_flow_setpoint / ($stepsvar - 1) );
3599 0           my $floorvalue_flow_setpoint = ($flow_setpoint__ - ($swing_flow_setpoint / 2) );
3600 0           my $new_flow_setpoint = $floorvalue_flow_setpoint + ($countstep * $pace_flow_setpoint);
3601              
3602 0           my $pace_flow_onoff = ( $swing_flow_onoff / ($stepsvar - 1) );
3603 0           my $floorvalue_flow_onoff = ($flow_onoff__ - ($swing_flow_onoff / 2) );
3604 0           my $new_flow_onoff = $floorvalue_flow_onoff + ($countstep * $pace_flow_onoff);
3605              
3606 0           my $pace_flow_fraction = ( $swing_flow_fraction / ($stepsvar - 1) );
3607 0           my $floorvalue_flow_fraction = ($flow_fraction__ - ($swing_flow_fraction / 2) );
3608 0           my $new_flow_fraction = $floorvalue_flow_fraction + ($countstep * $pace_flow_fraction);
3609              
3610 0           $new_flow_hour = sprintf("%.2f", $new_flow_hour);
3611 0           $new_flow_setpoint = sprintf("%.2f", $new_flow_setpoint);
3612 0           $new_flow_onoff = sprintf("%.2f", $new_flow_onoff);
3613 0           $new_flow_fraction = sprintf("%.2f", $new_flow_fraction);
3614              
3615 0           push(@new_flowcontrols,
3616             [ $new_flow_letter, $new_flowcontrol_letter, $new_flow_hour, $new_flow_setpoint, $new_flow_onoff, $new_flow_fraction ] );
3617             }
3618             # HERE THE MODIFICATIONS TO BE EXECUTED ON EACH PARAMETERS ARE APPLIED TO THE MODELS THROUGH ESP-r.
3619             # FIRST, HERE THEY ARE APPLIED TO THE ZONE CONTROLS, THEN TO THE FLOW CONTROLS
3620             }
3621             } # END SUB calc_newcontrols
3622              
3623 0         0 print $_outfile_ "\@new_loopcontrols: " . Dumper(@new_loopcontrols) . "\n\n";
3624              
3625 0         0 apply_loopcontrol_changes(\@new_loopcontrols);
3626 0         0 apply_flowcontrol_changes(\@new_flowcontrols);
3627              
3628             } # END SUB vary_controls.
3629              
3630              
3631             calc_newctl($to, $stepsvar, $countop, $countstep, \@buildbulk,
3632             \@flowbulk, \@loopcontrol, \@flowcontrol, $countvar, $fileconfig );
3633              
3634              
3635             sub constrain_controls
3636             { # IT READS CONTROL USER-IMPOSED CONSTRAINTS
3637 0     0 0   my ( $to, $filecon, $countop, $countstep, $swap, $swap2, $to_do, $countvar, $fileconfig ) = @_;
3638            
3639 0           my $zone_letter = $applytype[$countop][3];
3640 0           my @applytype = @$swap;
3641 0           my @constrain_controls = @$swap2;
3642              
3643 0           my $elm = $constrain_controls[$countop];
3644 0           my @group = @{$elm};
  0            
3645 0           my $sourcefile = $group[0];
3646 0           my $targetfile = $group[1];
3647 0           my $configfile = $group[2];
3648 0           my @sentletters = @{ $group[3] };
  0            
3649 0           my @sentperiod_letters = @{ $group[4] };
  0            
3650            
3651 0           my $sourceaddress = "$to$sourcefile";
3652 0           my $targetaddress = "$to$targetfile";
3653 0           my $configaddress = "$to$configfile";
3654             #@loopcontrol; @flowcontrol; @new_loopcontrols; @new_flowcontrols; # DON'T PUT "my" HERE. THEY ARE globsAL!!!
3655 0           my ( $semaphore_zone, $semaphore_dataloop, $semaphore_massflow, $semaphore_setpoint, $doline );
3656 0           my $count_controlmass = -1;
3657 0           my $countline = 0;
3658            
3659 0           my @letters;
3660 0 0         if (@sentletters) { @letters = @sentletters; }
  0            
3661             else
3662             {
3663 0           @letters = ("e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "z"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
3664             }
3665            
3666 0           my @period_letters;
3667 0 0         if (@sentperiod_letters) { @period_letters = @sentperiod_letters; }
  0            
3668             else
3669             {
3670 0           @period_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
3671             }
3672            
3673 0           my $loop_hour = 2; # NOTE: THE FOLLOWING VARIABLE NAMES ARE SHADOWED IN THE FOREACH LOOP BELOW,
3674             # BUT ARE THE ONES USED IN THE OPT CONSTRAINTS FILES.
3675 0           my $max_heating_power = 3;
3676 0           my $min_heating_power = 4;
3677 0           my $max_cooling_power = 5,
3678             my $min_cooling_power = 6;
3679 0           my $heating_setpoint = 7;
3680 0           my $cooling_setpoint = 8;
3681 0           my $flow_hour = 2;
3682 0           my $flow_setpoint = 3;
3683 0           my $flow_onoff = 4;
3684 0           my $flow_fraction = 5;
3685 0           my ( $loop_letter, $loopcontrol_letter );
3686 0           my $countbuild = 0;
3687 0           my $countflow = 0;
3688 0           my $countcontrol = 0;
3689              
3690 0           my ( @groupzone_letters, @zone_period_letters, @flow_letters, @fileloopbulk, @fileflowbulk );
3691              
3692 0 0         unless ($to_do eq "justwrite")
3693             {
3694 0 0         if ($countstep == 1)
3695             {
3696 0           print $_outfile_ "THIS\n";
3697 0           checkfile($sourceaddress, $targetaddress);
3698 0           read_controls($sourceaddress, $targetaddress, \@letters, \@period_letters);
3699 0           read_control_constraints($to, $stepsvar,
3700             $countop, $countstep, $configaddress, \@loopcontrol, \@flowcontrol, \@temploopcontrol, \@tempflowcontrol, $countvar, $fileconfig );
3701             }
3702             }
3703              
3704 0 0         unless ($to_do eq "justread")
3705             {
3706 0           print $_outfile_ "THAT\n";
3707 0           apply_loopcontrol_changes( \@new_loopcontrol, \@temploopcontrol);
3708 0           apply_flowcontrol_changes(\@new_flowcontrol, \@tempflowcontrol);
3709             }
3710              
3711             } # END SUB constrain_controls.
3712              
3713              
3714             sub read_controls
3715             { # TO BE CALLED WITH: read_controls($sourceaddress, $targetaddress, \@letters, \@period_letters);
3716             # THIS MAKES THE CONTROL CONFIGURATION FILE BE READ AND THE NEEDED VALUES ACQUIRED.
3717             # NOTICE THAT CURRENTLY ONLY THE "basic control law" IS SUPPORTED.
3718              
3719 0     0 0   my ( $sourceaddress, $targetaddress, $swap, $swap2, $countvar ) = @_;
3720            
3721 0           my @letters = @$swap;
3722 0           my @period_letters = @$swap2;
3723              
3724 0 0         open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourceaddress: $!\n";
3725 0           my @lines = ;
3726 0           close SOURCEFILE;
3727 0           my $countlines = 0;
3728 0           my $countloop = -1;
3729 0           my $countflow = -1;
3730 0           my $countflowcontrol = -1;
3731 0           my ( $countloopcontrol, $semaphore_building, $semaphore_loop, $loop_hour, $semaphore_loopcontrol, $semaphore_massflow,
3732             $flow_hour, $semaphore_flow, $semaphore_flowcontrol, $loop_letter, $loopcontrol_letter, $flow_letter, $flowcontrol_letter );
3733              
3734 0           foreach my $line (@lines)
3735             {
3736 0 0         if ( $line =~ /Control function/ )
3737             {
3738 0           $semaphore_loop = "yes";
3739 0           $countloopcontrol = -1;
3740 0           $countloop++;
3741 0           $loop_letter = $letters[$countloop];
3742             }
3743 0 0         if ( ($line =~ /ctl type, law/ ) )
3744             {
3745 0           $countloopcontrol++;
3746 0           my @row = split(/\s+/, $line);
3747 0           $loop_hour = $row[3];
3748 0           $semaphore_loopcontrol = "yes";
3749 0           $loopcontrol_letter = $period_letters[$countloopcontrol];
3750             }
3751              
3752 0 0 0       if ( ($semaphore_loop eq "yes") and ($semaphore_loopcontrol eq "yes") and ($line =~ /No. of data items/ ) )
      0        
3753             {
3754 0           $doline = $countlines + 1;
3755             }
3756              
3757 0 0 0       if ( ($semaphore_loop eq "yes" ) and ($semaphore_loopcontrol eq "yes") and ($countlines == $doline) )
      0        
3758             {
3759 0           my @row = split(/\s+/, $line);
3760 0           my $max_heating_power = $row[1];
3761 0           my $min_heating_power = $row[2];
3762 0           my $max_cooling_power = $row[3];
3763 0           my $min_cooling_power = $row[4];
3764 0           my $heating_setpoint = $row[5];
3765 0           my $cooling_setpoint = $row[6];
3766              
3767 0           push(@{$loopcontrol[$countloop][$countloopcontrol]},
  0            
3768             $loop_letter, $loopcontrol_letter, $loop_hour,
3769             $max_heating_power, $min_heating_power, $max_cooling_power,
3770             $min_cooling_power, $heating_setpoint, $cooling_setpoint );
3771              
3772 0           $semaphore_loopcontrol = "no";
3773 0           $doline = "";
3774             }
3775              
3776 0 0         if ($line =~ /Control mass/ )
3777             {
3778 0           $semaphore_flow = "yes";
3779 0           $countflowcontrol = -1;
3780 0           $countflow++;
3781 0           $flow_letter = $letters[$countflow];
3782             }
3783 0 0         if ( ($line =~ /ctl type \(/ ) )
3784             {
3785 0           $countflowcontrol++;
3786 0           my @row = split(/\s+/, $line);
3787 0           $flow_hour = $row[3];
3788 0           $semaphore_flowcontrol = "yes";
3789 0           $flowcontrol_letter = $period_letters[$countflowcontrol];
3790             }
3791              
3792 0 0 0       if ( ($semaphore_flow eq "yes") and ($semaphore_flowcontrol eq "yes") and ($line =~ /No. of data items/ ) )
      0        
3793             {
3794 0           $doline = $countlines + 1;
3795             }
3796              
3797 0 0 0       if ( ($semaphore_flow eq "yes" ) and ($semaphore_flowcontrol eq "yes") and ($countlines == $doline) )
      0        
3798             {
3799 0           my @row = split(/\s+/, $line);
3800 0           my $flow_setpoint = $row[1];
3801 0           my $flow_onoff = $row[2];
3802 0           my $flow_fraction = $row[3];
3803 0           push(@{$flowcontrol[$countflow][$countflowcontrol]},
  0            
3804             $flow_letter, $flowcontrol_letter, $flow_hour, $flow_setpoint, $flow_onoff, $flow_fraction);
3805 0           $semaphore_flowcontrol = "no";
3806 0           $doline = "";
3807             }
3808 0           $countlines++;
3809             }
3810             } # END SUB read_controls.
3811              
3812              
3813             sub read_control_constraints
3814             {
3815             # #!/usr/bin/perl
3816             # THIS FILE CAN CONTAIN USER-IMPOSED CONSTRAINTS FOR CONTROLS TO BE READ BY OPT.
3817             # THE FOLLOWING VALUES CAN BE ADDRESSED IN THE OPT CONSTRAINTS CONFIGURATION FILE,
3818             # SET BY THE PRESENT FUNCTION:
3819             # 1) $loopcontrol[$countop][$countloop][$countloopcontrol][$loop_hour]
3820             # Where $countloop and $countloopcontrol has to be set to a specified number in the OPT file for constraints.
3821             # 2) $loopcontrol[$countop][$countloop][$countloopcontrol][$max_heating_power] # Same as above.
3822             # 3) $loopcontrol[$countop][$countloop][$countloopcontrol][$min_heating_power] # Same as above.
3823             # 4) $loopcontrol[$countop][$countloop][$countloopcontrol][$max_cooling_power] # Same as above.
3824             # 5) $loopcontrol[$countop][$countloop][$countloopcontrol][$min_cooling_power] # Same as above.
3825             # 6) $loopcontrol[$countop][$countloop][$countloopcontrol][heating_setpoint] # Same as above.
3826             # 7) $loopcontrol[$countop][$countloop][$countloopcontrol][cooling_setpoint] # Same as above.
3827             # 8) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_hour]
3828             # Where $countflow and $countflowcontrol has to be set to a specified number in the OPT file for constraints.
3829             # 9) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_setpoint] # Same as above.
3830             # 10) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_onoff] # Same as above.
3831             # 11) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_fraction] # Same as above.
3832             # EXAMPLE : $flowcontrol[0][1][2][$flow_fraction] = 0.7
3833             # OTHER EXAMPLE: $flowcontrol[2][1][2][$flow_fraction] = $flowcontrol[0][2][1][$flow_fraction]
3834             # The $countop that is actuated is always the last, the one which is active.
3835             # It would have therefore no sense writing $flowcontrol[1][1][2][$flow_fraction] = $flowcontrol[3][2][1][$flow_fraction].
3836             # Differentent $countops can be referred to the same zone. Different $countops just number mutations in series.
3837             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS
3838             # AND THE STEPS THE MODEL HAS TO FOLLOW.
3839             # THIS ALLOWS TO IMPOSE EQUALITY CONSTRAINTS TO THESE VARIABLES,
3840             # WHICH COULD ALSO BE COMBINED WITH THE FOLLOWING ONES:
3841             # $stepsvar, WHICH TELLS THE PROGRAM HOW MANY ITERATION STEPS IT HAS TO DO IN THE CURRENT MORPHING PHASE.
3842             # $countop, WHICH TELLS THE PROGRAM WHAT OPERATION IS BEING EXECUTED IN THE CHAIN OF OPERATIONS
3843             # THAT MAY BE EXECUTES AT EACH MORPHING PHASE. EACH $countop WILL CONTAIN ONE OR MORE ITERATION STEPS.
3844             # TYPICALLY, IT WILL BE USED FOR A ZONE, BUT NOTHING PREVENTS THAT SEVERAL OF THEM CHAINED ONE AFTER
3845             # THE OTHER ARE APPLIED TO THE SAME ZONE.
3846             # $countstep, WHICH TELLS THE PROGRAM WHAT THE CURRENT ITERATION STEP IS.
3847             # $countvar, WHICH TELLS THE PROGRAM WHAT NUMBER OF DESIGN PARAMETER THE PROGRAM IS WORKING AT.
3848            
3849 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $swap3, $swap4, $countvar, $fileconfig ) = @_;
3850            
3851 0           @loopcontrol = @$swap;
3852 0           @flowcontrol = @$swap2;
3853 0           @temploopcontrol = @$swap3;
3854 0           @tempflowcontrol = @$swap4;
3855              
3856 0 0         if (-e $configaddress) # TEST THIS, DDD
3857             { # THIS APPLIES CONSTRAINST, THE FLATTEN THE HIERARCHICAL STRUCTURE OF THE RESULTS,
3858             # TO BE PREPARED THEN FOR BEING APPLIED TO CHANGE PROCEDURES. IT HAS TO BE TESTED.
3859 0           push (@loopcontrol, [@myloopcontrol]); #
3860 0           push (@flowcontrol, [@myflowcontrol]); #
3861              
3862 0           eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS
3863             # IS EVALUATED, AND HERE BELOW CONSTRAINTS ARE PROPAGATED.
3864              
3865 0 0         if (-e $constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0            
3866             # FOR PROPAGATION OF CONSTRAINTS
3867              
3868 0           @doloopcontrol = @{$loopcontrol[$#loopcontrol]}; #
  0            
3869 0           @doflowcontrol = @{$flowcontrol[$#flowcontrol]}; #
  0            
3870              
3871 0           shift (@doloopcontrol);
3872 0           shift (@doflowcontrol);
3873              
3874             sub flatten_loopcontrol_constraints
3875             {
3876 0     0 0   my @looptemp = @doloopcontrol;
3877 0           @new_loopcontrol = "";
3878 0           foreach my $elm (@looptemp)
3879             {
3880 0           my @loop = @{$elm};
  0            
3881 0           foreach my $elm (@loop)
3882             {
3883 0           my @loop = @{$elm};
  0            
3884 0           push (@new_loopcontrol, [@loop]);
3885             }
3886             }
3887             }
3888 0           flatten_loopcontrol_constraints;
3889              
3890             sub flatten_flowcontrol_constraints
3891             {
3892 0     0 0   my @flowtemp = @doflowcontrol;
3893 0           @new_flowcontrol = "";
3894 0           foreach my $elm (@flowtemp)
3895             {
3896 0           my @flow = @{$elm};
  0            
3897 0           foreach my $elm (@flow)
3898             {
3899 0           my @loop = @{$elm};
  0            
3900 0           push (@new_flowcontrol, [@flow]);
3901             }
3902             }
3903             }
3904 0           flatten_flowcontrol_constraints;
3905              
3906 0           shift @new_loopcontrol;
3907 0           shift @new_flowcontrol;
3908             }
3909             } # END SUB read_control_constraints
3910              
3911              
3912             sub apply_loopcontrol_changes
3913             { # TO BE CALLED WITH: apply_loopcontrol_changes($exeonfiles, \@new_loopcontrol);
3914             # THIS APPLIES CHANGES TO LOOPS IN CONTROLS (ZONES)
3915 0     0 0   my ( $swap, $swap2, $countvar ) = @_;
3916            
3917 0           my @new_loop_ctls = @$swap;
3918 0           my @temploopcontrol = @$swap2;
3919            
3920 0           my $countloop = 0;
3921              
3922 0           foreach my $elm (@new_loop_ctls)
3923             {
3924 0           my @loop = @{$elm};
  0            
3925 0           $new_loop_letter = $loop[0];
3926 0           $new_loopcontrol_letter = $loop[1];
3927 0           $new_loop_hour = $loop[2];
3928 0           $new_max_heating_power = $loop[3];
3929 0           $new_min_heating_power = $loop[4];
3930 0           $new_max_cooling_power = $loop[5];
3931 0           $new_min_cooling_power = $loop[6];
3932 0           $new_heating_setpoint = $loop[7];
3933 0           $new_cooling_setpoint = $loop[8];
3934 0 0         unless ( @{$new_loop_ctls[$countloop]} ~~ @{$temploopcontrol[$countloop]} )
  0            
  0            
3935             {
3936 0           my $printthis =
3937             "prj -file $to/cfg/$fileconfig -mode script<
3938              
3939             m
3940             j
3941              
3942             $new_loop_letter
3943             c
3944             $new_loopcontrol_letter
3945             1
3946             $new_loop_hour
3947             b
3948             $new_max_heating_power
3949             c
3950             $new_min_heating_power
3951             d
3952             $new_max_cooling_power
3953             e
3954             $new_min_cooling_power
3955             f
3956             $new_heating_setpoint
3957             g
3958             $new_cooling_setpoint
3959             -
3960             y
3961             -
3962             -
3963             -
3964             n
3965             d
3966              
3967             -
3968             y
3969             y
3970             -
3971             -
3972             YYY
3973             ";
3974 0 0         if ($exeonfiles eq "y")
3975             {
3976 0           print `$printthis`;
3977             }
3978 0           print TOSHELL $printthis;
3979             }
3980 0           $countloop++;
3981             }
3982             } # END SUB apply_loopcontrol_changes();
3983              
3984              
3985             sub apply_flowcontrol_changes
3986             { # THIS HAS TO BE CALLED WITH: apply_flowcontrol_changes($exeonfiles, \@new_flowcontrols);
3987             # # THIS APPLIES CHANGES TO NETS IN CONTROLS
3988 0     0 0   my ( $swap, $swap2, $countvar ) = @_;
3989            
3990 0           my $countflow = 0;
3991 0           my @new_flowcontrols = @$swap;
3992 0           my @tempflowcontrol = @$swap2;
3993              
3994 0           foreach my $elm (@new_flowcontrols)
3995             {
3996 0           my @flow = @{$elm};
  0            
3997 0           $flow_letter = $flow[0];
3998 0           $flowcontrol_letter = $flow[1];
3999 0           $new_flow_hour = $flow[2];
4000 0           $new_flow_setpoint = $flow[3];
4001 0           $new_flow_onoff = $flow[4];
4002 0           $new_flow_fraction = $flow[5];
4003 0 0         unless ( @{$new_flowcontrols[$countflow]} ~~ @{$tempflowcontrol[$countflow]} )
  0            
  0            
4004             {
4005 0           my $printthis =
4006             "prj -file $to/cfg/$fileconfig -mode script<
4007              
4008             m
4009             l
4010              
4011             $flow_letter
4012             c
4013             $flowcontrol_letter
4014             a
4015             $new_flow_hour
4016             $new_flow_setpoint $new_flow_onoff $new_flow_fraction
4017             -
4018             -
4019             -
4020             y
4021             y
4022             -
4023             -
4024             YYY
4025             ";
4026 0 0         if ($exeonfiles eq "y") # if ($exeonfiles eq "y")
4027             {
4028 0           print `$printthis`;
4029             }
4030              
4031 0           print TOSHELL $printthis;
4032             }
4033 0           $countflow++;
4034             }
4035             } # END SUB apply_flowcontrol_changes;
4036             # END OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING CONTROLS
4037             ##############################################################################
4038              
4039              
4040             ##############################################################################
4041             # BEGINNING OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING OBSTRUCTIONS
4042             sub constrain_obstructions # IT APPLIES CONSTRAINTS TO OBSTRUCTIONS
4043             {
4044             # THIS CONSTRAINS OBSTRUCTION FILES. IT HAS TO BE CALLED FROM THE MAIN FILE WITH:
4045             # constrain_obstruction($to, $fileconfig, $stepsvar, $countop, $countstep, $exeonfiles, \@applytype, \@constrain_obstructions);
4046 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $to_do, $countvar, $fileconfig ) = @_;
4047            
4048 0           my @applytype = @$swap;
4049 0           my $zone_letter = $applytype[$countop][3];
4050 0           my @constrain_obstructions = @$swap2;
4051            
4052 0           say "Propagating constraints on obstructions for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
4053              
4054 0           my @work_letters;
4055             #@obs; # globsAL!
4056              
4057 0           foreach my $elm (@constrain_obstructions)
4058             {
4059 0           my @group = @{$elm};
  0            
4060 0           my $zone_letter = $group[0];
4061 0           my $sourcefile = $group[1];
4062 0           my $targetfile = $group[2];
4063 0           my $configfile_ = $group[3];
4064 0           my $sourceaddress = "$to$sourcefile";
4065 0           my $targetaddress = "$to$targetfile";
4066 0           my $configaddress = "$to$configfile";
4067 0           my @work_letters = @{$group[4]};
  0            
4068 0           my $actonmaterials = $group[5];
4069 0           my @sentobs_letters = @{$group[6]};
  0            
4070            
4071 0 0         unless ($to_do eq "justwrite")
4072             {
4073 0           checkfile($sourceaddress, $targetaddress);
4074 0           read_obstructions($to, $sourceaddress, $targetaddress, $configaddress, \@work_letters, $actonmaterials, $countvar, \@sentobs_letters);
4075 0           read_obs_constraints($to, $stepsvar, $countop, $countstep, $configaddress, $actonmaterials, \@tempobs, $countvar, $fileconfig ); # IT WORKS ON THE VARIABLE @obs, WHICH IS globsAL.
4076             }
4077              
4078 0 0         unless ($to_do eq "justread")
4079             {
4080 0           apply_obs_constraints(\@doobs, \@obs_letters, \@work_letters, $zone_letter, $actonmaterials, \@tempobs);
4081             }
4082             }
4083             } # END SUB constrain_obstructions
4084              
4085              
4086             sub read_obstructions
4087             {
4088             # THIS READS GEOMETRY FILES. # IT HAS TO BE CALLED WITH:
4089             # read_obstructions($to, $sourcefile, $targetfile, $configfiles, \@work_letters, $actonmaterials, $countvar);
4090 0     0 0   my ( $to, $sourceaddress, $targetaddress, $configaddress, $swap, $actonmaterials, $countvar, $swap2 ) = @_;
4091            
4092 0           my @obs_letters;
4093            
4094 0           my @work_letters = @$swap;
4095 0           my @sentobs_letters = @$swap2;
4096            
4097 0 0         open( SOURCEFILE, $sourceaddress) or die "Can't open $sourceaddress: $!\n";
4098 0           my @lines = ;
4099 0           close SOURCEFILE;
4100              
4101 0           my $count = 0;
4102 0           foreach my $line (@lines)
4103             {
4104             #$line =~ s/^\s+//;
4105 0 0         if ( $line =~ m/\*obs/ )
4106             {
4107 0 0         unless ( $line =~ m/\*obs =/ )
4108             {
4109 0           $count++;
4110             }
4111             }
4112             }
4113            
4114 0 0         if (@sentobs_letters)
4115             {
4116 0           @obs_letters = @sentobs_letters;
4117             }
4118             else
4119             {
4120 0 0         if ( $count > 21 )
4121             {
4122 0           @obs_letters = ("e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
4123             "o", "0\nb\nf", "0\nb\ng", "0\nb\nh", "0\nb\ni", "0\nb\nj", "0\nb\nk", "0\nb\nm",
4124             "0\nb\nn", "0\nb\no", "0\nb\n0\nb\nf","0\nb\n0\nb\ng",
4125             "0\nb\n0\nb\nh","0\nb\n0\nb\ni","0\nb\n0\nb\nj","0\nb\n0\nb\nk","0\nb\n0\nb\nl",
4126             "0\nb\n0\nb\nm","0\nb\n0\nb\nn","0\nb\n0\nb\no","0\nb\n0\nb\n0\nb\nf",
4127             "0\nb\n0\nb\n0\nb\ng","0\nb\n0\nb\n0\nb\nh","0\nb\n0\nb\n0\nb\ni","0\nb\n0\nb\n0\nb\nj",
4128             "0\nb\n0\nb\n0\nb\nk","0\nb\n0\nb\n0\nb\nl","0\nb\n0\nb\n0\nb\nm","0\nb\n0\nb\n0\nb\nn",
4129             "0\nb\n0\nb\n0\nb\no");
4130             }
4131             else
4132             {
4133 0           @obs_letters = ("e", "f", "g", "h", "i", "j", "k", "l", "m",
4134             "n", "o", "0\nf", "0\ng", "0\nh", "0\ni", "0\nj", "0\nk", "0\nl",
4135             "0\nm", "0\nn", "0\no");
4136             }
4137             }
4138              
4139 0           my $count = 0;
4140 0           foreach my $line (@lines)
4141             {
4142 0 0         if ( $line =~ m/\*obs/ )
4143             {
4144 0 0         unless ( $line =~ m/\*obs =/ )
4145             {
4146             #$line =~ s/^\s+//;
4147 0           my @rowelements = split(/,/, $line);
4148 0           push (@obs, [ $rowelements[1], $rowelements[2], $rowelements[3],
4149             $rowelements[4], $rowelements[5], $rowelements[6],
4150             $rowelements[7], $rowelements[8], $rowelements[9],
4151             $rowelements[10], $rowelements[11], $rowelements[12], $obs_letters[$count] ] );
4152 0           $count++;
4153             }
4154             }
4155             }
4156             } # END SUB read_obstructions
4157              
4158              
4159             sub read_obs_constraints
4160             {
4161             # THE VARIABLE @obs REGARDS OBSTRUCTION USER-IMPOSED CONSTRAINTS
4162             # THIS CONSTRAINT CONFIGURATION FILE MAKES AVAILABLE TO THE USER THE FOLLOWING VARIABLES:
4163             # $obs[$countop][$obs_number][$x], $obs[$countop][$obs_number][$y], $obs[$countop][$obs_number][$y]
4164             # $obs[$countop][$obs_number][$width], $obs[$countop][$obs_number][$depth], $obs[$countop][$obs_number][$height]
4165             # $obs[$countop][$obs_number][$z_rotation], $obs[$countop][$obs_number][$y_rotation],
4166             # $obs[$countop][$obs_number][$tilt], $obs[$countop][$obs_number][$opacity], $obs[$countop][$obs_number][$material],
4167             # EXAMPLE: $obs[0][2][$x] = 2. THIS MEANS: AT COUNTERZONE 0, COORDINATE x OF OBSTRUCTION HAS TO BE SET TO 2.
4168             # OTHER EXAMPLE: $obs[0][2][$x] = $obs[2][2][$y].
4169             # The $countop that is actuated is always the last, the one which is active.
4170             # There would be therefore no sense in writing $obs[0][4][$x] = $obs[1][2][$y].
4171             # Differentent $countops can be referred to the same zone. Different $countops just number mutations in series.
4172             # NOTE THAT THE MATERIAL TO BE SPECIFIED IS A MATERIAL LETTER, BETWEEN QUOTES. EXAMPLE: $obs[1][$material] = "a".
4173             # $tilt IS PRESENTLY UNUSED.
4174             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS
4175             # AND THE STEPS THE MODEL HAVE TO FOLLOW.
4176             # THIS ALLOWS TO IMPOSE EQUALITY CONSTRAINTS TO THESE VARIABLES,
4177             # WHICH COULD ALSO BE COMBINED WITH THE FOLLOWING ONES:
4178             # $stepsvar, WHICH TELLS THE PROGRAM HOW MANY ITERATION STEPS IT HAS TO DO IN THE CURRENT MORPHING PHASE.
4179             # $countop, WHICH TELLS THE PROGRAM WHAT OPERATION IS BEING EXECUTED IN THE CHAIN OF OPERATIONS
4180             # THAT MAY BE EXECUTES AT EACH MORPHING PHASE. EACH $countop WILL CONTAIN ONE OR MORE ITERATION STEPS.
4181             # TYPICALLY, IT WILL BE USED FOR A ZONE, BUT NOTHING PREVENTS THAT SEVERAL OF THEM CHAINED ONE AFTER
4182             # THE OTHER ARE APPLIED TO THE SAME ZONE.
4183             # $countstep, WHICH TELLS THE PROGRAM WHAT THE CURRENT ITERATION STEP IS.
4184             # $countvar, WHICH TELLS THE PROGRAM WHAT NUMBER OF DESIGN PARAMETER THE PROGRAM IS WORKING AT.
4185 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $configaddress, $actonmaterials, $swap, $countvar, $fileconfig ) = @_;
4186            
4187 0           @tempobs = @$swap;
4188              
4189 0           my $obs_letter = 13;
4190 0           my $x = 1;
4191 0           my $y = 2;
4192 0           my $z = 3;
4193 0           my $width = 4;
4194 0           my $depth = 5;
4195 0           my $height = 6;
4196 0           my $z_rotation = 7;
4197 0           my $y_rotation = 8;
4198 0           my $tilt = 9; # UNUSED
4199 0           my $opacity = 10;
4200 0           my $name = 11; # NOT TO BE CHANGED
4201 0           my $material = 12;
4202 0 0         if (-e $configaddress)
4203             {
4204 0           unshift (@obs, []);
4205 0           push (@obs, [@myobs]); #
4206 0           eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS IS EVALUATED.
4207              
4208 0 0         if (-e $constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0            
4209             # FOR PROPAGATION OF CONSTRAINTS
4210              
4211 0           @doobs = @{$obs[$#obs]}; #
  0            
4212 0           shift @doobs;
4213             }
4214             } # END SUB read_geo_constraints
4215              
4216              
4217             sub apply_obs_constraints
4218             {
4219             # IT APPLY USER-IMPOSED CONSTRAINTS TO A GEOMETRY FILES VIA SHELL
4220             # IT HAS TO BE CALLED WITH:
4221             # apply_geo_constraints(\@obs, \@obsletters, \@work_letters, \$exeonfiles, \$zone_letter, $actonmaterials);
4222 0     0 0   my ( $swap, $swap2, $swap3, $zone_letter, $actonmaterials, $swap4, $countvar ) = @_;
4223            
4224 0           my @obs = @$swap;
4225 0           my @obs_letters = @$swap2;
4226 0           my @work_letters = @$swap3;
4227 0           my @tempobs = @$swap4;
4228            
4229              
4230 0           my $countobs = 0;
4231 0           print $_outfile_ "OBS_LETTERS IN APPLY" . Dumper(@obs_letters) . "\n\n";
4232 0           foreach my $ob (@obs)
4233             {
4234 0           my $obs_letter = $obs_letters[$countobs];
4235 0 0 0       if ( ( @work_letters eq "") or ($obs_letter ~~ @work_letters))
4236             {
4237 0           my @obstr = @{$ob};
  0            
4238 0           my $x = $obstr[0];
4239 0           my $y = $obstr[1];
4240 0           my $z = $obstr[2];
4241 0           my $width = $obs[3];
4242 0           my $depth = $obs[4];
4243 0           my $height = $obs[5];
4244 0           my $z_rotation = $obs[6];
4245 0           my $y_rotation = $obs[7];
4246 0           my $tilt = $obs[8];
4247 0           my $opacity = $obs[9];
4248 0           my $name = $obs[10];
4249 0           my $material = $obs[11];
4250 0 0         unless
4251             (
4252 0           ( @{$obs[$countobs]} ~~ @{$tempobs[$countobs]} )
  0            
4253             )
4254             {
4255 0           my $printthis =
4256             "prj -file $to/cfg/$fileconfig -mode script<
4257              
4258             m
4259             c
4260             a
4261             $zone_letter
4262             h
4263             a
4264             $obs_letter
4265             a
4266             a
4267             $x $y $z
4268             b
4269             $width $depth $height
4270             c
4271             $z_rotation
4272             d
4273             $y_rotation
4274             e # HERE THE DATUM IS STILL UNUSED. WHEN IT WILL, A LINE MUST BE ADDED WITH THE VARIABLE $tilt.
4275             h
4276             $opacity
4277             -
4278             -
4279             c
4280             -
4281             c
4282             -
4283             -
4284             -
4285             -
4286             YYY
4287             ";
4288 0 0         if ($exeonfiles eq "y")
4289             {
4290 0           print `$printthis`;
4291             }
4292              
4293 0           print TOSHELL $printthis;
4294             }
4295              
4296 0           my $obs_letter = $obs_letters[$countobs];
4297 0 0         if ($obs_letter ~~ @work_letters)
4298             {
4299 0 0         if ($actonmaterials eq "y")
4300             {
4301 0           my $printthis =
4302             "prj -file $to/cfg/$fileconfig -mode script<
4303              
4304             m
4305             c
4306             a
4307             $zone_letter
4308             h
4309             a
4310             $obs_letter
4311             g
4312             $material
4313             -
4314             -
4315             -
4316             c
4317             -
4318             c
4319             -
4320             -
4321             -
4322             -
4323             YYY
4324             ";
4325 0 0         if ($exeonfiles eq "y")
4326             {
4327 0           print `$printthis`;
4328             }
4329              
4330 0           print TOSHELL $printthis;
4331             }
4332             }
4333             }
4334 0           $countobs++;
4335             }
4336             } # END SUB apply_obs_constraints
4337             ##############################################################################
4338             # END OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING OBSTRUCTIONS
4339              
4340              
4341             ##############################################################################
4342             # BEGINNING OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING THE MASS-FLOW NETWORKS
4343             sub vary_net
4344             { # IT IS CALLED FROM THE MAIN FILE
4345 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $countvar, $fileconfig ) = @_;
4346            
4347 0           my @applytype = @$swap;
4348 0           my $zone_letter = $applytype[$countop][3];
4349 0           my @vary_net = @$swap2;
4350            
4351 0           say "Propagating constraints on networks for case " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
4352              
4353 0           my $activezone = $applytype[$countop][3];
4354 0           my ($semaphore_node, $semaphore_component, $node_letter);
4355 0           my $count_component = -1;
4356 0           my $countline = 0;
4357 0           my @node_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
4358 0           my @component_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
4359             # NOTE: THE FOLLOWING VARIABLE NAMES ARE SHADOWED IN THE FOREACH LOOP BELOW,
4360             # BUT ARE THE ONES USED IN THE OPT CONSTRAINTS FILES.
4361              
4362 0           my @group = @{$vary_net[$countop]};
  0            
4363 0           my $sourcefile = $group[0];
4364 0           my $targetfile = $group[1];
4365 0           my $configfile = $group[2];
4366 0           my @nodebulk = @{$group[3]};
  0            
4367 0           my @componentbulk = @{$group[4]};
  0            
4368 0           my $countnode = 0;
4369 0           my $countcomponent = 0;
4370              
4371 0           my $sourceaddress = "$to$sourcefile";
4372 0           my $targetaddress = "$to$targetfile";
4373 0           my $configaddress = "$to$configfile";
4374              
4375             #@node; @component; # PLURAL. DON'T PUT "my" HERE!
4376             #@new_nodes; @new_components; # DON'T PUT "my" HERE.
4377              
4378 0           my @flow_letters;
4379              
4380 0           checkfile($sourceaddress, $targetaddress);
4381              
4382 0 0         if ($countstep == 1)
4383             {
4384 0           read_net($sourceaddress, $targetaddress, \@node_letters, \@component_letters);
4385             }
4386              
4387             sub calc_newnet
4388             { # TO BE CALLED WITH: calc_newnet($to, $fileconfig, $stepsvar, $countop, $countstep, \@nodebulk, \@componentbulk, \@node_, \@component);
4389             # THIS COMPUTES CHANGES TO BE MADE TO CONTROLS BEFORE PROPAGATION OF CONSTRAINTS
4390 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $swap3, $swap4, $countvar, $fileconfig ) = @_;
4391            
4392 0           my @nodebulk = @$swap;
4393 0           my @componentbulk = @$swap2;
4394 0           my @node = @$swap3; # PLURAL
4395 0           my @component = @$swap4; # PLURAL
4396            
4397 0           my ( @new_volumes_or_surfaces, @node_heights_or_cps, @new_azimuths, @boundary_heights );
4398              
4399             # HERE THE MODIFICATIONS TO BE EXECUTED ON EACH PARAMETERS ARE CALCULATED.
4400 0 0         if ($stepsvar == 0) {$stepsvar = 1;}
  0            
4401 0 0         if ($stepsvar > 1)
4402             {
4403 0           foreach $each_nodebulk (@nodebulk)
4404             {
4405 0           my @asknode = @{$each_nodebulk};
  0            
4406 0           my $new_node_letter = $asknode[0];
4407 0           my $new_fluid = $asknode[1];
4408 0           my $new_type = $asknode[2];
4409 0           my $new_zone = $activezone;
4410 0           my $swing_height = $asknode[3];
4411 0           my $swing_data_2 = $asknode[4];
4412 0           my $new_surface = $asknode[5];
4413 0           my @askcp = @{$asknode[6]};
  0            
4414 0           my ($height__, $data_2__, $data_1__, $new_cp);
4415 0           my $countnode = 0; #IT IS FOR THE FOLLOWING FOREACH. LEAVE IT ATTACHED TO IT.
4416 0           foreach $each_node (@node)
4417             {
4418 0           @node_ = @{$each_node};
  0            
4419 0           my $node_letter = $node_[0];
4420 0 0         if ( $new_node_letter eq $node_letter )
4421             {
4422 0           $height__ = $node_[3];
4423 0           $data_2__ = $node_[4];
4424 0           $data_1__ = $node_[5];
4425 0           $new_cp = $askcp[$countstep-1];
4426             }
4427 0           $countnode++;
4428             }
4429 0           my $height = ( $swing_height / ($stepsvar - 1) );
4430 0           my $floorvalue_height = ($height__ - ($swing_height / 2) );
4431 0           my $new_height = $floorvalue_height + ($countstep * $pace_height);
4432 0           $new_height = sprintf("%.3f", $height);
4433 0 0         if ($swing_height == 0) { $new_height = ""; }
  0            
4434              
4435 0           my $pace_data_2 = ( $swing_data_2 / ($stepsvar - 1) );
4436 0           my $floorvalue_data_2 = ($data_2__ - ($swing_data_2 / 2) );
4437 0           my $new_data_2 = $floorvalue_data_2 + ($countstep * $pace_data_2);
4438 0           $new_data_2 = sprintf("%.3f", $new_data_2);
4439 0 0         if ($swing_data_2 == 0) { $new_data_2 = ""; }
  0            
4440              
4441 0           my $pace_data_1 = ( $swing_data_1 / ($stepsvar - 1) ); # UNUSED
4442 0           my $floorvalue_data_1 = ($data_1__ - ($swing_data_1 / 2) );
4443 0           my $new_data_1 = $floorvalue_data_1 + ($countstep * $pace_data_1);
4444 0           $new_data_1 = sprintf("%.3f", $new_data_1);
4445 0 0         if ($swing_data_1 == 0) { $new_data_1 = ""; }
  0            
4446              
4447 0           push(@new_nodes,
4448             [ $new_node_letter, $new_fluid, $new_type, $new_zone, $new_height, $new_data_2, $new_surface, $new_cp ] );
4449             }
4450              
4451 0           foreach $each_componentbulk (@componentbulk)
4452             {
4453 0           my @askcomponent = @{$each_componentbulk};
  0            
4454 0           my $new_component_letter = $askcomponent[0];
4455              
4456 0           my $new_type = $askcomponent[1];
4457 0           my $swing_data_1 = $askcomponent[2];
4458 0           my $swing_data_2 = $askcomponent[3];
4459 0           my $swing_data_3 = $askcomponent[4];
4460 0           my $swing_data_4 = $askcomponent[5];
4461 0           my $component_letter;
4462 0           my $countcomponent = 0; #IT IS FOR THE FOLLOWING FOREACH.
4463 0           my ($new_type, $data_1__, $data_2__, $data_3__, $data_4__ );
4464 0           foreach $each_component (@component) # PLURAL
4465             {
4466 0           @component_ = @{$each_component};
  0            
4467 0           $component_letter = $component_letters[$countcomponent];
4468 0 0         if ( $new_component_letter eq $component_letter )
4469             {
4470 0           $new_component_letter = $component_[0];
4471 0           $new_fluid = $component_[1];
4472 0           $new_type = $component_[2];
4473 0           $data_1__ = $component_[3];
4474 0           $data_2__ = $component_[4];
4475 0           $data_3__ = $component_[5];
4476 0           $data_4__ = $component_[6];
4477             }
4478 0           $countcomponent++;
4479             }
4480              
4481 0           my $pace_data_1 = ( $swing_data_1 / ($stepsvar - 1) );
4482 0           my $floorvalue_data_1 = ($data_1__ - ($swing_data_1 / 2) );
4483 0           my $new_data_1 = $floorvalue_data_1 + ($countstep * $pace_data_1);
4484 0 0         if ($swing_data_1 == 0) { $new_data_1 = ""; }
  0            
4485              
4486 0           my $pace_data_2 = ( $swing_data_2 / ($stepsvar - 1) );
4487 0           my $floorvalue_data_2 = ($data_2__ - ($swing_data_2 / 2) );
4488 0           my $new_data_2 = $floorvalue_data_2 + ($countstep * $pace_data_2);
4489 0 0         if ($swing_data_2 == 0) { $new_data_2 = ""; }
  0            
4490              
4491 0           my $pace_data_3 = ( $swing_data_3 / ($stepsvar - 1) );
4492 0           my $floorvalue_data_3 = ($data_3__ - ($swing_data_3 / 2) );
4493 0           my $new_data_3 = $floorvalue_data_3 + ($countstep * $pace_data_3 );
4494 0 0         if ($swing_data_3 == 0) { $new_data_3 = ""; }
  0            
4495              
4496 0           my $pace_data_4 = ( $swing_data_4 / ($stepsvar - 1) );
4497 0           my $floorvalue_data_4 = ($data_4__ - ($swing_data_4 / 2) );
4498 0           my $new_data_4 = $floorvalue_data_4 + ($countstep * $pace_data_4 );
4499 0 0         if ($swing_data_4 == 0) { $new_data_4 = ""; }
  0            
4500              
4501 0           $new_data_1 = sprintf("%.3f", $new_data_1);
4502 0           $new_data_2 = sprintf("%.3f", $new_data_2);
4503 0           $new_data_3 = sprintf("%.3f", $new_data_3);
4504 0           $new_data_4 = sprintf("%.3f", $new_data_4);
4505 0           $new_data_4 = sprintf("%.3f", $new_data_4);
4506              
4507 0           push(@new_components, [ $new_component_letter, $new_fluid, $new_type, $new_data_1, $new_data_2, $new_data_3, $new_data_4 ] );
4508             }
4509             }
4510             } # END SUB calc_newnet
4511              
4512 0           calc_newnet($to, $stepsvar, $countop, $countstep, \@nodebulk, \@componentbulk, \@node, \@component, $countvar, $fileconfig ); # PLURAL
4513              
4514 0           apply_node_changes(\@new_nodes);
4515 0           apply_component_changes(\@new_components);
4516              
4517             } # END SUB vary_net.
4518              
4519              
4520             sub read_net
4521             {
4522 0     0 0   my ( $sourceaddress, $targetaddress, $swap, $swap2, $countvar ) = @_;
4523            
4524             # checkfile($sourceaddress, $targetaddress); # THIS HAS TO BE _FIXED!_
4525 0           my @node_letters = @$swap;
4526 0           my @component_letters = @$swap2;
4527              
4528 0 0         open( SOURCEFILE, $sourceaddress ) or die "Can't open $sourcefile : $!\n";
4529 0           my @lines = ;
4530 0           close SOURCEFILE;
4531 0           my $countlines = 0;
4532 0           my $countnode = -1;
4533 0           my $countcomponent = -1;
4534 0           my $countcomp = 0;
4535 0           my $semaphore_node = "no";
4536 0           my $semaphore_component = "no";
4537 0           my $semaphore_connection = "no";
4538 0           my ($component_letter, $type, $data_1, $data_2, $data_3, $data_4);
4539 0           foreach my $line (@lines)
4540             {
4541 0 0         if ( $line =~ m/Fld. Type/ )
4542             {
4543 0           $semaphore_node = "yes";
4544             }
4545 0 0         if ( $semaphore_node eq "yes" )
4546             {
4547 0           $countnode++;
4548             }
4549 0 0         if ( $line =~ m/Type C\+ L\+/ )
4550             {
4551 0           $semaphore_component = "yes";
4552 0           $semaphore_node = "no";
4553             }
4554              
4555              
4556              
4557 0 0 0       if ( ($semaphore_node eq "yes") and ( $semaphore_component eq "no" ) and ( $countnode >= 0))
      0        
4558             {
4559 0           $line =~ s/^\s+//;
4560 0           my @row = split(/\s+/, $line);
4561 0           my $node_letter = $node_letters[$countnode];
4562 0           my $fluid = $row[1];
4563 0           my $type = $row[2];
4564 0           my $height = $row[3];
4565 0           my $data_2 = $row[6]; # volume or azimuth
4566 0           my $data_1 = $row[5]; #surface
4567 0           push(@node, [ $node_letter, $fluid, $type, $height, $data_2, $data_1 ] ); # PLURAL
4568             }
4569              
4570 0 0         if ( $semaphore_component eq "yes" )
4571             {
4572 0           $countcomponent++;
4573             }
4574              
4575 0 0         if ( $line =~ m/\+Node/ )
4576             {
4577 0           $semaphore_connection = "yes";
4578 0           $semaphore_component = "no";
4579 0           $semaphore_node = "no";
4580             }
4581              
4582 0 0 0       if ( ($semaphore_component eq "yes") and ( $semaphore_connection eq "no" ) and ( $countcomponent > 0))
      0        
4583             {
4584 0           $line =~ s/^\s+//;
4585 0           my @row = split(/\s+/, $line);
4586 0 0         if ($countcomponent % 2 == 1) # $number is odd
4587             {
4588 0           $component_letter = $component_letters[$countcomp];
4589 0           $fluid = $row[0];
4590 0           $type = $row[1];
4591 0 0         if ($type eq "110") { $type = "k";}
  0            
4592 0 0         if ($type eq "120") { $type = "l";}
  0            
4593 0 0         if ($type eq "130") { $type = "m";}
  0            
4594 0           $countcomp++;
4595             }
4596             else # $number is even
4597             {
4598 0           $data_1 = $row[1];
4599 0           $data_2 = $row[2];
4600 0           $data_3 = $row[3];
4601 0           $data_4 = $row[4];
4602 0           push( @component, [ $component_letter, $fluid, $type, $data_1, $data_2, $data_3, $data_4 ] ); # PLURAL
4603             }
4604              
4605             }
4606              
4607 0           $countlines++;
4608             }
4609             } # END SUB read_controls.
4610              
4611              
4612             sub apply_node_changes
4613             { # TO BE CALLED WITH: apply_node_changes($exeonfiles, \@new_nodes);
4614             # THIS APPLIES CHANGES TO NODES IN NETS
4615 0     0 0   my ( $swap, $swap2, $countvar ) = @_;
4616            
4617 0           my @new_nodes = @$swap;
4618 0           my @tempnodes = @$swap2;
4619              
4620 0           my $countnode = 0;
4621 0           foreach my $elm (@new_nodes)
4622             {
4623 0           my @node_ = @{$elm};
  0            
4624 0           my $new_node_letter = $node_[0];
4625 0           my $new_fluid = $node_[1];
4626 0           my $new_type = $node_[2];
4627 0           my $new_zone = $node_[3];
4628 0           my $new_height = $node_[4];
4629 0           my $new_data_2 = $node_[5];
4630 0           my $new_surface = $node_[6];
4631 0           my $new_cp = $node_[7];
4632              
4633 0 0         unless ( @{$new_nodes[$countnode]} ~~ @{$tempnodes[$countnode]} )
  0            
  0            
4634             {
4635 0 0         if ($new_type eq "a" ) # IF NODES ARE INTERNAL
4636             {
4637 0           my $printthis =
4638             "prj -file $to/cfg/$fileconfig -mode script<
4639              
4640             m
4641             e
4642             c
4643              
4644             n
4645             c
4646             $new_node_letter
4647              
4648             $new_fluid
4649             $new_type
4650             y
4651             $new_zone
4652             $new_data_2
4653             $new_height
4654             a
4655              
4656             -
4657             -
4658             y
4659              
4660             y
4661             -
4662             -
4663             YYY
4664             ";
4665 0 0         if ($exeonfiles eq "y")
4666             {
4667 0           print `$printthis`;
4668             }
4669 0           print TOSHELL $printthis;
4670             }
4671              
4672 0 0         if ($new_type eq "e" ) # IF NODES ARE BOUNDARY ONES, WIND-INDUCED
4673             {
4674 0           my $printthis =
4675             "prj -file $to/cfg/$fileconfig -mode script<
4676              
4677             m
4678             e
4679             c
4680              
4681             n
4682             c
4683             $new_node_letter
4684              
4685             $new_fluid
4686             $new_type
4687             $new_zone
4688             $new_surface
4689             $new_cp
4690             y
4691             $new_data_2
4692             $new_height
4693             -
4694             -
4695             y
4696              
4697             y
4698             -
4699             -
4700             YYY
4701             ";
4702 0 0         if ($exeonfiles eq "y")
4703             {
4704 0           print `$printthis`;
4705             }
4706 0           print TOSHELL $printthis;
4707             }
4708             }
4709 0           $countnode++;
4710             }
4711             } # END SUB apply_node_changes;
4712              
4713              
4714             sub apply_component_changes
4715             { # TO BE CALLED WITH: apply_component_changes($exeonfiles, \@new_components);
4716             # THIS APPLIES CHANGES TO COMPONENTS IN NETS
4717 0     0 0   my ( $swap, $swap2, $countvar ) = @_;
4718            
4719 0           my @new_components = @$swap; # [ $new_component_letter, $new_type, $new_data_1, $new_data_2, $new_data_3, $new_data_4 ]
4720 0           my @tempcomponents = @$swap2;
4721              
4722 0           my $countcomponent = 0;
4723 0           foreach my $elm (@new_components)
4724             {
4725 0           my @component_ = @{$elm};
  0            
4726 0           my $new_component_letter = $component_[0];
4727 0           my $new_fluid = $component_[1];
4728 0           my $new_type = $component_[2];
4729 0           my $new_data_1 = $component_[3];
4730 0           my $new_data_2 = $component_[4];
4731 0           my $new_data_3 = $component_[5];
4732 0           my $new_data_4 = $component_[6];
4733              
4734 0 0         unless
4735 0           ( @{$new_components[$countcomponents]} ~~ @{$tempcomponents[$countcomponents]} )
  0            
4736             {
4737 0 0         if ($new_type eq "k" ) # IF THE COMPONENT IS A GENERIC OPENING
4738             {
4739 0           my $printthis =
4740             "prj -file $to/cfg/$fileconfig -mode script<
4741              
4742             m
4743             e
4744             c
4745              
4746             n
4747             d
4748             $new_component_letter
4749             $new_fluid
4750             $new_type
4751             -
4752             $new_data_1
4753             -
4754             -
4755             y
4756              
4757             y
4758             -
4759             -
4760             YYY
4761             ";
4762 0 0         if ($exeonfiles eq "y")
4763             {
4764 0           print `$printthis`;
4765             }
4766 0           print TOSHELL $printthis;
4767             }
4768              
4769 0 0         if ($new_type eq "l" ) # IF THE COMPONENT IS A CRACK
4770             {
4771 0           my $printthis =
4772             "prj -file $to/cfg/$fileconfig -mode script<
4773              
4774             m
4775             e
4776             c
4777              
4778             n
4779             d
4780             $new_component_letter
4781             $new_fluid
4782             $new_type
4783             -
4784             $new_data_1 $new_data_2
4785             -
4786             -
4787             y
4788              
4789             y
4790             -
4791             -
4792             YYY
4793             ";
4794 0 0         if ($exeonfiles eq "y")
4795             {
4796 0           print `$printthis`;
4797             }
4798 0           print TOSHELL $printthis;
4799             }
4800              
4801 0 0         if ($new_type eq "m" ) # IF THE COMPONENT IS A DOOR
4802             {
4803 0           my $printthis =
4804             "prj -file $to/cfg/$fileconfig -mode script<
4805              
4806             m
4807             e
4808             c
4809              
4810             n
4811             d
4812             $new_component_letter
4813             $new_fluid
4814             $new_type
4815             -
4816             $new_data_1 $new_data_2 $new_data_3 $new_data_4
4817             -
4818             -
4819             y
4820              
4821             y
4822             -
4823             -
4824             YYY
4825             ";
4826 0 0         if ($exeonfiles eq "y")
4827             {
4828 0           print `$printthis`;
4829             }
4830 0           print TOSHELL "$printthis";
4831             }
4832             }
4833 0           $countcomponent++;
4834             }
4835             } # END SUB apply_component_changes;
4836              
4837              
4838             sub constrain_net
4839             { # IT ALLOWS TO MANIPULATE USER-IMPOSED CONSTRAINTS REGARDING NETS
4840 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $swap2, $to_do, $countvar, $fileconfig ) = @_;
4841            
4842 0           my @applytype = @$swap;
4843 0           my $zone_letter = $applytype[$countop][3];
4844 0           my @constrain_net = @$swap2;
4845              
4846 0           my $elm = $constrain_net[$countop];
4847 0           my @group = @{$elm};
  0            
4848 0           my $sourcefile = $group[0];
4849 0           my $targetfile = $group[1];
4850 0           my $configfile = $group[2];
4851 0           my @nodebulk = @{$group[3]};
  0            
4852 0           my @componentbulk = @{$group[4]};
  0            
4853 0           my $sourceaddress = "$to$sourcefile";
4854 0           my $targetaddress = "$to$targetfile";
4855 0           my $configaddress = "$to$configfile";
4856              
4857 0           my $node = 0;
4858 0           my $fluid = 1;
4859 0           my $type = 2;
4860 0           my $height = 3;
4861 0           my $volume = 4;
4862 0           my $volume = 4;
4863 0           my $azimuth = 4;
4864 0           my $component = 0;
4865 0           my $area = 3;
4866 0           my $width = 4;
4867 0           my $length = 5;
4868 0           my $door_width = 4;
4869 0           my $door_height = 5;
4870 0           my $door_nodeheight = 6;
4871 0           my $door_discharge = 7;
4872              
4873 0           my $activezone = $applytype[$countop][3];
4874 0           my ($semaphore_node, $semaphore_component, $node_letter);
4875 0           my $count_component = -1;
4876 0           my $countline = 0;
4877 0           my @node_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
4878 0           my @component_letters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s"); # CHECK IF THE LAST LETTERS ARE CORRECT, ZZZ
4879 0           my $countnode = 0;
4880 0           my $countcomponent = 0;
4881              
4882             #@node; @component; # PLURAL! DON'T PUT "MY" HERE. globsAL.
4883             #@new_nodes; @new_components; # DON'T PUT "my" HERE. THEY ARE globsAL!!!
4884              
4885 0 0         unless ($to_do eq "justwrite")
4886             {
4887 0           checkfile($sourceaddress, $targetaddress);
4888 0 0         if ($countstep == 1)
4889             {
4890 0           read_net($sourceaddress, $targetaddress, \@node_letters, \@component_letters);
4891 0           read_net_constraints
4892             ($to, $stepsvar, $countop, $countstep, $configaddress, \@node, \@component, \@tempnode, \@tempcomponent, $countvar, $fileconfig ); # PLURAL
4893             }
4894             }
4895              
4896 0 0         unless ($to_do eq "justread")
4897             {
4898 0           apply_node_changes(\@donode, \@tempnode); #PLURAL
4899 0           apply_component_changes(\@docomponent, \@tempcomponent);
4900             }
4901             } # END SUB constrain_net.
4902              
4903              
4904             sub read_net_constraints
4905             {
4906 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $configaddress, $swap, $swap2, $swap3, $swap4, $countvar, $fileconfig ) = @_;
4907            
4908 0           @node = @$swap; # PLURAL
4909 0           @component = @$swap2;
4910 0           @tempnode = @$swap3;
4911 0           @tempcomponent = @$swap4;
4912              
4913 0           unshift (@node, []); # PLURAL
4914 0           unshift (@component, []);
4915 0 0         if (-e $configaddress) # TEST THIS
4916             { # THIS APPLIES CONSTRAINST, THE FLATTEN THE HIERARCHICAL STRUCTURE OF THE RESULTS,
4917             # TO BE PREPARED THEN FOR BEING APPLIED TO CHANGE PROCEDURES. IT IS TO BE TESTED.
4918              
4919 0           push (@node, [@mynode]); #
4920 0           push (@component, [@mycomponent]); #
4921              
4922 0           eval `cat $configaddress`; # HERE AN EXTERNAL FILE FOR PROPAGATION OF CONSTRAINTS
4923             # IS EVALUATED, AND HERE BELOW CONSTRAINTS ARE PROPAGATED.
4924             # THIS FILE CAN CONTAIN USER-IMPOSED CONSTRAINTS FOR MASS-FLOW NETWORKS TO BE READ BY OPT.
4925             # IT MAKES AVAILABLE VARIABLES REGARDING THE SETTING OF NODES IN A NETWORK.
4926             # CURRENTLY: INTERNAL UNKNOWN AIR NODES AND BOUNDARY WIND-CONCERNED NODES.
4927             # IT MAKES AVAILABLE VARIABLES REGARDING COMPONENTS
4928             # CURRENTLY: WINDOWS, CRACKS, DOORS.
4929             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS.
4930             # SPECIFICALLY, THE FOLLOWING VARIABLES WHICH REGARD BOTH INTERNAL AND BOUNDARY NODES.
4931             # NOTE THAT "node_number" IS THE NUMBER OF THE NODE IN THE ".afn" ESP-r FILE.
4932             # $node[$countop][node_number][$node]. # EXAMPLE: $node[0][3][$node]. THIS IS THE LETTER OF THE THIRD NODE,
4933             # AT THE FIRST CONTERZONE (NUMBERING STARTS FROM 0)
4934             # $node[$countop][node_number][$type]
4935             # $node[$countop][node_number][$height]. # EXAMPLE: $node[0][3][$node]. THIS IS THE HEIGHT OF THE 3RD NODE AT THE FIRST COUNTERZONE
4936             # THEN IT MAKES AVAILABLE THE FOLLOWING VARIABLES REGARDING NODES:
4937             # $node[$countop][node_number][$volume] # REGARDING INTERNAL NODES
4938             # $node[$countop][node_number][$azimut] # REGARDING BOUNDARY NODES
4939             # THEN IT MAKE AVAILABLE THE FOLLOWING VARIABLES REGARDING COMPONENTS:
4940             # $node[$countop][node_number][$area] # REGARDING SIMPLE OPENINGS
4941             # $node[$countop][node_number][$width] # REGARDING CRACKS
4942             # $node[$countop][node_number][$length] # REGARDING CRACKS
4943             # $node[$countop][node_number][$door_width] # REGARDING DOORS
4944             # $node[$countop][node_number][$door_height] # REGARDING DOORS
4945             # $node[$countop][node_number][$door_nodeheight] # REGARDING DOORS
4946             # $node[$countop][node_number][$door_discharge] # REGARDING DOORS (DISCHARGE FACTOR)
4947             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS
4948             # AND THE STEPS THE MODEL HAVE TO FOLLOW.
4949             # THIS ALLOWS TO IMPOSE EQUALITY CONSTRAINTS TO THESE VARIABLES,
4950             # WHICH COULD ALSO BE COMBINED WITH THE FOLLOWING VARIABLES
4951             # $stepsvar, WHICH TELLS THE PROGRAM HOW MANY ITERATION STEPS IT HAS TO DO IN THE CURRENT MORPHING PHASE.
4952             # $countop, WHICH TELLS THE PROGRAM WHAT OPERATION IS BEING EXECUTED IN THE CHAIN OF OPERATIONS
4953             # THAT MAY BE EXECUTES AT EACH MORPHING PHASE. EACH $countop WILL CONTAIN ONE OR MORE ITERATION STEPS.
4954             # TYPICALLY, IT WILL BE USED FOR A ZONE, BUT NOTHING PREVENTS THAT SEVERAL OF THEM CHAINED ONE AFTER
4955             # THE OTHER ARE APPLIED TO THE SAME ZONE.
4956             # $countstep, WHICH TELLS THE PROGRAM WHAT THE CURRENT ITERATION STEP IS.
4957             # $countvar, WHICH TELLS THE PROGRAM WHAT NUMBER OF DESIGN PARAMETER THE PROGRAM IS WORKING AT.
4958             # The $countop that is actuated is always the last, the one which is active.
4959             # It would have therefore no sense writing $node[0][3][$node] = $node[1][3][$node].
4960             # Differentent $countops can be referred to the same zone. Different $countops just number mutations in series.
4961              
4962 0 0         if (-e $constrain) { eval ($constrain); } # HERE THE INSTRUCTION WRITTEN IN THE OPT CONFIGURATION FILE CAN BE SPEFICIED
  0            
4963             # FOR PROPAGATION OF CONSTRAINTS
4964              
4965 0           @donode = @{$node[$#node]}; #
  0            
4966 0           @docomponent = @{$component[$#component]}; #
  0            
4967              
4968 0           shift (@donode);
4969 0           shift (@docomponent);
4970             }
4971             } # END SUB read_net_constraints
4972             ##############################################################################
4973             # END OF SECTION DEDICATED TO FUNCTIONS FOR CONSTRAINING MASS-FLOW NETWORKS
4974              
4975              
4976              
4977             ##############################################################################
4978             # BEGINNING OF SECTION DEDICATED TO GENERIC FUNCTIONS FOR PROPAGATING CONSTRAINTS
4979             sub propagate_constraints
4980             {
4981             # THIS FUNCTION ALLOWS TO MANIPULATE COMPOUND USER-IMPOSED CONSTRAINTS.
4982             # IT COMPOUNDS ALL FOUR PRINCIPAL PROPAGATION TYPES. THAT MEANS THAT ONE COULD DO
4983             # ANY TYPE OF THE AVAILABLE PROPAGATIONS JUST USING THIS FUNCTION.
4984             # IT MAKES AVAILABLE TO THE USER THE FOLLOWING VARIABLES FOR MANIPULATION.
4985              
4986             # REGARDING GEOMETRY:
4987             # $v[$countop][$number][$x], $v[$countop][$number][$y], $v[$countop][$number][$z]. EXAMPLE: $v[0][4][$x] = 1.
4988             # OR: @v[0][4][$x] = @v[0][4][$y]. OR EVEN: @v[1][4][$x] = @v[0][3][$z].
4989              
4990             # REGARDING OBSTRUCTIONS:
4991             # $obs[$countop][$obs_number][$x], $obs[$countop][$obs_number][$y], $obs[$countop][$obs_number][$y]
4992             # $obs[$countop][$obs_number][$width], $obs[$countop][$obs_number][$depth], $obs[$countop][$obs_number][$height]
4993             # $obs[$countop][$obs_number][$z_rotation], $obs[$countop][$obs_number][$y_rotation],
4994             # $obs[$countop][$obs_number][$tilt], $obs[$countop][$obs_number][$opacity], $obs[$countop][$obs_number][$material],
4995             # EXAMPLE: $obs[0][2][$x] = 2. THIS MEANS: AT COUNTERZONE 0, COORDINATE x OF OBSTRUCTION HAS TO BE SET TO 2.
4996             # OTHER EXAMPLE: $obs[0][2][$x] = $obs[2][2][$y].
4997             # NOTE THAT THE MATERIAL TO BE SPECIFIED IS A MATERIAL LETTER, BETWEEN QUOTES! EXAMPLE: $obs[1][$material] = "a".
4998             # $tilt IS PRESENTLY UNUSED.
4999              
5000             # REGARDING MASS-FLOW NETWORKS:
5001             # @node and @component.
5002             # CURRENTLY: INTERNAL UNKNOWN AIR NODES AND BOUNDARY WIND-CONCERNED NODES.
5003             # IT MAKES AVAILABLE VARIABLES REGARDING COMPONENTS
5004             # CURRENTLY: WINDOWS, CRACKS, DOORS.
5005             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS.
5006             # SPECIFICALLY, THE FOLLOWING VARIABLES WHICH REGARD BOTH INTERNAL AND BOUNDARY NODES.
5007             # NOTE THAT "node_number" IS THE NUMBER OF THE NODE IN THE ".afn" ESP-r FILE.
5008             # 1) $loopcontrol[$countop][$countloop][$countloopcontrol][$loop_hour]
5009             # Where $countloop and $countloopcontrol has to be set to a specified number in the OPT file for constraints.
5010             # 2) $loopcontrol[$countop][$countloop][$countloopcontrol][$max_heating_power] # Same as above.
5011             # 3) $loopcontrol[$countop][$countloop][$countloopcontrol][$min_heating_power] # Same as above.
5012             # 4) $loopcontrol[$countop][$countloop][$countloopcontrol][$max_cooling_power] # Same as above.
5013             # 5) $loopcontrol[$countop][$countloop][$countloopcontrol][$min_cooling_power] # Same as above.
5014             # 6) $loopcontrol[$countop][$countloop][$countloopcontrol][heating_setpoint] # Same as above.
5015             # 7) $loopcontrol[$countop][$countloop][$countloopcontrol][cooling_setpoint] # Same as above.
5016             # 8) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_hour]
5017             # Where $countflow and $countflowcontrol has to be set to a specified number in the OPT file for constraints.
5018             # 9) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_setpoint] # Same as above.
5019             # 10) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_onoff] # Same as above.
5020             # 11) $flowcontrol[$countop][$countflow][$countflowcontrol][$flow_fraction] # Same as above.
5021             # EXAMPLE : $flowcontrol[0][1][2][$flow_fraction] = 0.7
5022             # OTHER EXAMPLE: $flowcontrol[2][1][2][$flow_fraction] = $flowcontrol[0][2][1][$flow_fraction]
5023              
5024             # REGARDING CONTROLS:
5025             # IT MAKES AVAILABLE VARIABLES REGARDING COMPONENTS
5026             # CURRENTLY: WINDOWS, CRACKS, DOORS.
5027             # ALSO, THIS MAKES AVAILABLE TO THE USER INFORMATIONS ABOUT THE MORPHING STEP OF THE MODELS.
5028             # SPECIFICALLY, THE FOLLOWING VARIABLES WHICH REGARD BOTH INTERNAL AND BOUNDARY NODES.
5029             # NOTE THAT "node_number" IS THE NUMBER OF THE NODE IN THE ".afn" ESP-r FILE.
5030             # $node[$countop][node_number][$node]. # EXAMPLE: $node[0][3][$node]. THIS IS THE LETTER OF THE THIRD NODE,
5031             # AT THE FIRST CONTERZONE (NUMBERING STARTS FROM 0)
5032             # $node[$countop][node_number][$type]
5033             # $node[$countop][node_number][$height]. # EXAMPLE: $node[0][3][$node]. THIS IS THE HEIGHT OF THE 3RD NODE AT THE FIRST COUNTERZONE
5034             # THEN IT MAKES AVAILABLE THE FOLLOWING VARIABLES REGARDING NODES:
5035             # $node[$countop][node_number][$volume] # REGARDING INTERNAL NODES
5036             # $node[$countop][node_number][$azimut] # REGARDING BOUNDARY NODES
5037             # THEN IT MAKE AVAILABLE THE FOLLOWING VARIABLES REGARDING COMPONENTS:
5038             # $node[$countop][node_number][$area] # REGARDING SIMPLE OPENINGS
5039             # $node[$countop][node_number][$width] # REGARDING CRACKS
5040             # $node[$countop][node_number][$length] # REGARDING CRACKS
5041             # $node[$countop][node_number][$door_width] # REGARDING DOORS
5042             # $node[$countop][node_number][$door_height] # REGARDING DOORS
5043             # $node[$countop][node_number][$door_nodeheight] # REGARDING DOORS
5044             # $node[$countop][node_number][$door_discharge] # REGARDING DOORS (DISCHARGE FACTOR)
5045              
5046             # ALSO, THIS KIND OF FILE MAKES INFORMATION AVAILABLE ABOUT
5047             # THE MORPHING STEP OF THE MODELS AND THE STEPS THE MODEL HAVE TO FOLLOW.
5048             # THIS ALLOWS TO IMPOSE EQUALITY CONSTRAINTS TO THESE VARIABLES,
5049             # WHICH COULD ALSO BE COMBINED WITH THE FOLLOWING ONES:
5050             # $stepsvar, WHICH TELLS THE PROGRAM HOW MANY ITERATION STEPS IT HAS TO DO IN THE CURRENT MORPHING PHASE.
5051             # $countop, WHICH TELLS THE PROGRAM WHAT OPERATION IS BEING EXECUTED IN THE CHAIN OF OPERATIONS
5052             # THAT MAY BE EXECUTES AT EACH MORPHING PHASE. EACH $countop WILL CONTAIN ONE OR MORE ITERATION STEPS.
5053             # TYPICALLY, IT WILL BE USED FOR A ZONE, BUT NOTHING PREVENTS THAT SEVERAL OF THEM CHAINED ONE AFTER
5054             # THE OTHER ARE APPLIED TO THE SAME ZONE.
5055             # $countstep, WHICH TELLS THE PROGRAM WHAT THE CURRENT ITERATION STEP IS.
5056             # $countvar, WHICH TELLS THE PROGRAM WHAT NUMBER OF DESIGN PARAMETER THE PROGRAM IS WORKING AT.
5057              
5058             # The $countop that is actuated is always the last, the one which is active.
5059             # Differentent $countops can be referred to the same zone. Different $countops just number mutations in series.
5060             # So referral to different time steps when needed has to be explicitly specified in the files in which the criteria
5061             # for propagation of constraints are written.
5062              
5063 0     0 0   my ( $to, $stepsvar, $countop, $countstep, $swap, $justread, $justwrite, $swap2, $countvar, $fileconfig ) = @_;
5064            
5065 0           my @applytype = @$swap;
5066 0           my $zone_letter = $applytype[$countop][3];
5067 0           my @propagate_constraints = @$swap2;
5068            
5069 0           say "Propagating constraints on multiple databases " . ($countcase + 1) . ", block " . ($countblock + 1) . ", parameter $countvar at iteration $countstep. Instance $countinstance.";
5070              
5071 0           my $zone = $applytype[$countop][3];
5072 0           my $count = 0;
5073 0           my @group = @{$propagate_constraints[$countop]};
  0            
5074 0           foreach my $elm (@group)
5075             {
5076 0 0         if ($count > 0)
5077             {
5078 0           my @items = @{$elm};
  0            
5079 0           my $what_to_do = $items[0];
5080 0           my $sourcefile = $items[1];
5081 0           my $targetfile = $items[2];
5082 0           my $configfile = $items[3];
5083 0           my $askop = $items[6];
5084 0 0         if ($what_to_do eq "read_geo")
    0          
    0          
    0          
    0          
    0          
    0          
    0          
5085             {
5086 0           $to_do = "justread";
5087 0           my @vertex_letters = @{$items[4]};
  0            
5088 0           my $long_menus = $items[5];
5089 0           my @constrain_geometry = ( [ $zone, $sourcefile, $targetfile, $configfile , \@vertex_letters, $long_menus ] );
5090 0           constrain_geometry( $to, $fileconfig, $stepsvar, $countop, $countstep,
5091             $exeonfiles, \@applytype, \@constrain_geometry, $to_do, $countvar, $fileconfig );
5092              
5093             }
5094             elsif ($what_to_do eq "read_obs")
5095             {
5096 0           $to_do = "justread";
5097 0           my @obs_letters = @{$items[4]};
  0            
5098 0           my $act_on_materials = $items[5];
5099 0           my @constrain_obstructions = ( [ $applytype[$countop][3], $sourcefile, $targetfile, $configfile , \@obs_letters, $act_on_materials ] );
5100 0           constrain_obstructions( $to, $stepsvar, $countop,
5101             $countstep, \@applytype, \@constrain_obstructions, $to_do, $countvar, $fileconfig );
5102             }
5103             elsif ($what_to_do eq "read_ctl")
5104             {
5105 0           $to_do = "justread";
5106 0           my @constrain_controls = ( [ $zone, $sourcefile, $targetfile, $configfile ] );
5107 0           constrain_controls( $to, $stepsvar, $countop,
5108             $countstep, \@applytype, \@constrain_controls, $to_do, $countvar, $fileconfig );
5109             }
5110             elsif ($what_to_do eq "read_net")
5111             {
5112 0           $to_do = "justread";
5113 0           my @surfaces = @{$items[4]};
  0            
5114 0           my @cps = @{$items[5]};
  0            
5115 0           my @constrain_net = ( [ $zone, $sourcefile, $targetfile, $configfile , \@surfaces, \@cps ] );
5116 0           constrain_net( $to, $stepsvar, $countop,
5117             $countstep, \@applytype, \@constrain_net, $to_do, $countvar, $fileconfig );
5118             }
5119              
5120             elsif ($what_to_do eq "write_geo")
5121             {
5122 0           $to_do = "justwrite";
5123 0           my @vertex_letters = @{$items[4]};
  0            
5124 0           my $long_menus = $items[5];
5125 0           my @constrain_geometry = ( [ $zone, $sourcefile, $targetfile, $configfile , \@vertex_letters, $long_menus, $askop ] );
5126 0           constrain_geometry( $to, $stepsvar, $countop,
5127             $countstep, \@applytype, \@constrain_geometry, $to_do, $countvar, $fileconfig );
5128             }
5129             elsif ($what_to_do eq "write_obs")
5130             {
5131 0           $to_do = "justwrite";
5132 0           my @obs_letters = @{$items[4]};
  0            
5133 0           my $act_on_materials = $items[5];
5134 0           my @constrain_obstructions = ( [ $zone, $sourcefile, $targetfile, $configfile , \@obs_letters, $act_on_materials] );
5135 0           constrain_obstructions( $to, $stepsvar, $countop,
5136             $countstep, \@applytype, \@constrain_obstructions, $to_do, $countvar, $fileconfig );
5137             }
5138             elsif ($what_to_do eq "write_ctl")
5139             {
5140 0           $to_do = "justwrite";
5141 0           my @constrain_controls = ( [ $zone, $sourcefile, $targetfile, $configfile ] );
5142 0           constrain_controls( $to, $stepsvar, $countop,
5143             $countstep, \@applytype, \@constrain_controls, $to_do, $countvar, $fileconfig );
5144             }
5145             elsif ($what_to_do eq "write_net")
5146             {
5147 0           $to_do = "justwrite";
5148 0           my @surfaces = @{$items[4]};
  0            
5149 0           my @cps = @{$items[5]};
  0            
5150 0           my @constrain_net = ( [ $zone, $sourcefile, $targetfile, $configfile , \@surfaces, \@cps ] );
5151 0           constrain_net( $to, $stepsvar, $countop,
5152             $countstep, \@applytype, \@constrain_net, $to_do, $countvar, $fileconfig );
5153             }
5154             }
5155 0           $count++;
5156             }
5157             }
5158             ###########################################################################
5159             # END OF SECTION DEDICATED TO GENERIC FUNCTIONS FOR PROPAGATING CONSTRAINTS
5160              
5161             1;