I was trying to create a simple 2D planetary simulator, and I was making it write the resultant data to a file. Well, the incrementing doesn't seem to be working, and I assume this may have to do with the problem. Only one line of data is written to the file.

Code:#!usr/bin/perl #2D Planetary Gravity Simulator #version 1.0 use Math::Trig; use Fcntl; print "Input some parameters to create a simulation.\n"; #parameters print "Star mass (M sol): "; my $starMass = <STDIN>; chomp $starMass; print "Planet mass (M earth): "; my $planetMass = <STDIN>; chomp $planetMass; print "Moon mass (M luna): "; my $moonMass = <STDIN>; chomp $moonMass; print "Planet location x (AU): "; my $planetLocX = <STDIN>; chomp $planetLocX; print "Planet location Y (AU): "; my $planetLocY = <STDIN>; chomp $planetLocY; print "Planet velocity (m/s): "; my $planetVel = <STDIN>; chomp $planetVel; print "Planet theta (deg): "; my $planetTheta = <STDIN>; chomp $planetTheta; print "Moon location x (Mm): "; my $moonLocX = <STDIN>; chomp $moonLocX; print "Moon location Y (Mm): "; my $moonLocY = <STDIN>; chomp $moonLocY; print "Moon velocity (m/s): "; my $moonVel = <STDIN>; chomp $moonVel; print "Moon theta (deg): "; my $moonTheta = <STDIN>; chomp $moonTheta; print "Timestep (h): "; my $timestep = <STDIN>; chomp $timestep; print "Iterations: "; my $iter = <STDIN>; chomp $iter; my $starLocX = 0; my $starLocY = 0; my $starTheta = 0.001; my $starVel = 0; my $count = $iter; #multiply distances my $planetLocX = $planetLocX*149598000; my $planetLocY = $planetLocY*149598000; my $moonLocX = $moonLocX*1000000; my $moonLocY = $moonLocY*1000000; #file output print "Type the filepath you want to save to: "; my $FILEPATH = <STDIN>; chomp $FILEPATH; sysopen(TEXT, $FILEPATH, O_CREAT|O_RDWR); printf TEXT "StarX StarY PlanetX PlanetY MoonX MoonY"; close (TEXT); #calculate for($i = $iter; $i > 0; $i--) { #COUNTER my $counter = 0; $counter++; #PLANET-STAR CALCULATIONS #force magnitude my $g = 6.67*10**(1/11); my $kgMassStar = $starMass*(1.9889*10**30); my $kgMassPlan = $planetMass*(5.9742*10**24); my $theta = atan($planetLocY/$planetLocX); my $sine = sin($theta); my $distance = ($planetLocY/$sine); my $F = $g*(($kgMassStar*$kgMassPlan)/$distance); #acceleration magnitude my $planetAcceleration = ($F/$kgMassPlan); my $starAcceleration = ($F/$kgMassStar); my $starAccTheta = $theta; #result my $planetAccTheta = $theta+180; #result my $planetDeltaLoc = $planetAcceleration*($timestep*3600); #result my $starDeltaLoc = $starAcceleration*($timestep*3600); #result #PLANET-MOON CALCULATIONS #force magnitude my $kgMassMoon = $moonMass*(7.36*10**22); my $theta = atan($moonLocY-$planetLocY/$moonLocX-$planetLocX); my $sine = sin($theta); my $distance = ($moonLocY/$sine); my $F = $g*(($kgMassPlan*$kgMassMoon)/$distance); #acceleration magnitude $planetAcceleration = ($F/$kgMassPlan); $moonAcceleration = ($F/$kgMassMoon); $planetAccTheta2 = $theta; #result $moonAccTheta = $theta+180; #result $planetDeltaLoc2 = $planetAcceleration*($timestep*3600); #result $moonDeltaLoc = $moonAcceleration*($timestep*3600); #result #STAR-MOON CALCULATIONS #force my $theta = atan($moonLocY/$moonLocX); my $sine = sin($theta); my $distance = ($moonLocY/$sine); my $F = $g*(($kgMassStar*$kgMassPlan)/$distance); #acceleration magnitude $starAcceleration = ($F/$kgMassStar); $moonAcceleration = ($F/$kgMassMoon); $starAccTheta2 = $theta; #result $moonAccTheta2 = $theta+180; #result $moonDeltaLoc2 = $moonAcceleration*($timestep*3600); #result $starDeltaLoc2 = $starAcceleration*($timestep*3600); #result #VECTOR ADDITION #convert polar to cartesian #planet star my $sine = sin($planetAccTheta); my $psVelY = ($planetDeltaLoc*$sine); my $tan = tan($planetAccTheta); my $psVelX = ($psVelY/$tan); #planet moon my $sine = sin($planetAccTheta2); my $pmVelY = ($planetDeltaLoc2*$sine); my $tan = tan($planetAccTheta2); my $pmVelX = ($pmVelY/$tan); #star planet my $sine = sin($starAccTheta); my $spVelY = ($starDeltaLoc*$sine); my $tan = tan($starAccTheta); my $spVelX = ($spVelY/$tan); #star moon my $sine = sin($starAccTheta2); my $smVelY = ($starDeltaLoc2*$sine); my $tan = tan($starAccTheta2); my $smVelX = ($smVelY/$tan); #moon planet my $sine = sin($moonAccTheta); my $mpVelY = ($moonDeltaLoc*$sine); my $tan = tan($moonAccTheta); my $mpVelX = ($mpVelY/$tan); #moon star my $sine = sin($moonAccTheta2); my $msVelY = ($moonDeltaLoc2*$sine); my $tan = tan($moonAccTheta2); my $msVelX = ($msVelY/$tan); #planet velocity my $sine = sin($planetTheta); my $pVelY = ($planetVel*$sine); my $tan = tan($planetTheta); my $pVelX = ($pVelY/$tan); #moon velocity my $sine = sin($moonTheta); my $mVelY = ($planetVel*$sine); my $tan = tan($moonTheta); my $mVelX = ($mVelY/$tan); #star velocity my $sine = sin($starTheta); my $sVelY = ($starVe*$sine); my $tan = tan($starTheta); my $sVelX = ($sVelY/$tan); #add cartesian vectors #planet my $pFinalX = ($psVelX+$pmVelX+$pVelX); my $pFinalY = ($psVelY+$pmVelY+$pVelY); #moon my $mFinalX = ($msVelX+$mpVelX+$mVelX); my $mFinalY = ($msVelY+$mpVelY+$mVelY); #star my $sFinalX = ($spVelX+$smVelX+$sVelX); my $sFinalY = ($spVelY+$smVelY+$sVelY); #convert cartesian to polar #planet my $planetTheta = atan($pFinalY/$pFinalX); my $planetVel = sqrt(($pFinalX)**2+($pFinalY)**2); #moon my $moonTheta = atan($mFinalY/$mFinalX); my $moonVel = sqrt(($mFinalX)**2+($mFinalY)**2); #star my $starTheta = atan($sFinalY/$sFinalX); my $starVel = sqrt(($sFinalX)**2+($sFinalY)**2); #ADD VELOCITIES TO CREATE NEW LOCATION #planet my $planetLocX = $planetLocX+$pFinalX; my $planetLocY = $planetLocY+$pFinalY; #moon my $moonLocX = $moonLocX+$mFinalX; my $moonLocY = $moonLocY+$mFinalY; #star my $starLocX = $starLocX+$sFinalX; my $starLocY = $starLocY+$sFinalY; #WRITE TO FILE sysopen(TEXT, $FILEPATH, O_RDWR); printf TEXT "$starLocX $starLocY $planetLocX $planetLocY $moonLocX $moonLocY"; close (TEXT); #COUNTER PRINT print "Iteration $counter of $iter complete.\n"; } print "\nYour simulation is done!"; sleep 10;