Hi, I'm trying to get my perl script to write out an input file for building simulation software. It calculates the vertices of a 1x1x0.01m block in space based on the azimuth and tilt angle and writes it to a file.
I've provided a shortened version of my code.
I have two arrays:
1: azimuth angle of a PV panel
2: tilt angle of a PV panel
Code:
@azimuth = (-180, -165, -150, -135, -120, -105, -90, -75, -60, -45, -30, -15, 0);
@tilt = (0, 15, 30, 40, 45, 50, 55, 60, 75, 90);
my code runs if I use an array with only one element, for example:
Code:
$azimuth[$i] = -135;
$tilt[$f] = 45;
I would like it to enter the first loop (so $azimuth[0] = 180), then run the second loop multiple times ($tilt[$f] = 0, $tilt[$f] = 15, $tilt[$f] = 30, etc...). Then I want it to move to $azimuth[1] and do the same thing.
Code:
#! /usr/bin/perl -w
#use strict;
use Math::Trig;# ':pi';
use File::Copy;
# set incrementers i and f for azimuth and tilt arrays respectively
$i = 0;
$f = 0;
$pi = atan2(1,1) * 4;;
$pip2 = $pi/2;
#define azimuthal angles (phi) in degrees
$azimuthd[$i] = -135;
$azimuth[$i] = deg2rad($azimuthd[$i]);
# define tilt angle (alpha) in degrees
$tiltd[$f] = 45;
$tilt[$f] = deg2rad($tiltd[$f]);
while($i < 1){ # azimuth loop - all tilt angles for each azimuth
if($f < 1){ # tilt loop
if ((-$pip2 > $azimuth[$i]) && ($azimuth[$i] > -$pi)) {
$bprojc = $bc * cos($tilt[$f]);
$projcx = $bprojc * (cos($pi + $azimuth[$i]));
$projcy = $bprojc * (sin($pi + $azimuth[$i]));
$cz = $bc * ((sin($tilt[$f])));
$c[0] = $bx - ($projcx);
$c[1] = $by + ($projcy);
$c[2] = $cz;
}
open(GEO, '>../zones/hal.geo'); # overwrite simulation input file
printf GEO "# geometry of hal defined in: ../zones/hal.geo\n";
printf GEO "GEN hal hal describes a 1m2 pv panel # type, name, descr\n";
printf GEO " 8 6 ".sprintf("%.3f", $azimuth[$i])." # vertices, surfaces, rotation angle\n";
printf GEO "# X co-ord, Y co-ord, Z co-ord\n";
printf GEO " ".sprintf("%.5f", $c[0])."";
printf GEO " ".sprintf("%.5f", $c[1])."";
printf GEO " ".sprintf("%.5f", $c[2])." # vert 2\n";
close (GEO); # close simulation input file
system('bps.pl'); # run simulation
copy "OUT.csv", "Ottawa_$azimuthd[$i]_$tiltd[$f].csv"; # copy results file
$f++; # increment tilt index n w/out changing azimuth angle
} # end of tilt if loop
$i++; # increment the azimuth angle once all the tilt angles have been run
} # end of for loop for the azimuth angle i.e., every tilt angle has been run for each azimuth angle.
I've been experimenting with while, if, for, foreach loops with no luck. I'm trying to convert from degree (@azimuthd) inputs to radians (@azimuth) for the calculations and I don't believe that I'm doing that correctly either. @azimuthd was being defined correctly but @azimuth only contains the first element of @azimuthd. I tried the following but it seemed to only read in the first element:
Code:
@azimuth = deg2rad(@azimuthd);
I know that once its run the tilt loop $f should be reset for the next azimuth angle otherwise it won't pass the conditions but I'm really not sure how to go about it.
Any input will be greatly appreciated, I hope I clearly laid out my problem.