#!/usr/bin/perl


 
      	     my @guessloop   = (-1000,1000,1);
	     my $deltaphi    = 0.0;
	     my $scpotential = 7;
	     my @spacecraft  = (1,2,3,4);
	     my $output	     = "cdf";
	     my $override    = "no";
	     my $sum	     = "BL1L2T";
	     my $qtmc	     = " -C/home/jgeach/qtmc_kdevelop/qtmc_v1.0.6";
	     my $datato      = " -D/home/jgeach/tmp";
	     my $calibration = $qtmc."/cal";
	     
	     my @s = (2002,75,14,0,0);

	     my $start = create_ddd_time_string(@s);
	     my $end = start_time_plus_4h_ddd(@s);	     
	    
  	     my $mysum;
	     $output = " -O".$output;
	     $start = " -S".$start;
	     $end = " -E".$end;
	     $deltaphi = " -U".$deltaphi;
	     $scpotential = " -V".$scpotential;
	     $override = " -o".$override;
	     
	     my $sc = 1;

	     	$mysum = " -M".$sc.$sum;
		exec("QTMC $start $end $calibration $datato $mysum $output $deltaphi $scpotential");	     

	     #subs
	     
	     sub create_ddd_time_string {     
	     				return sprintf("%d-%03dZ%02d:%02d:%02d.000",$_[0],$_[1],$_[2],$_[3],$_[4]);
	     			        };
	     
	     sub create_dd_time_string {     
	     				return sprintf("%d-%02d-%02dZ%02d:%02d:%02d.000",$_[0],$_[1],$_[2],$_[3],$_[4],$_[5]);
	     			       };
	     
	     sub start_time_plus_4h_ddd {
					 my $y = $_[0];
					 my $d = $_[1];
					 my $h = $_[2];
					 my $m = $_[3];
					 my $s = $_[4];
					 
					 if($h==23){$h = 3; if($d<366){$d += 1}else{ $d = 1; $y += 1} }
					 else{$h += 4};
 
					 return sprintf("%d-%03dZ%02d:%02d:%02d.000",$y,$d,$h,$m,$s);
	     			        };
	   
	    
	     

	     
	     
	     
	     
	     
