Index: trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl	(revision 17604)
+++ trunk/ippScripts/scripts/ipp_serial_inject_mosaic.pl	(revision 17622)
@@ -23,22 +23,24 @@
 use Pod::Usage qw( pod2usage );
 
-my ($camera,			# Camera used
-    $telescope,			# Telescope used
-    $dbname,			# Database name
-    $workdir,			# Working directory
-    $path,			# Path to data
+my ($camera,                    # Camera used
+    $telescope,                 # Telescope used
+    $tess_id,                   # Tessellation identifier
+    $dbname,                    # Database name
+    $workdir,                   # Working directory
+    $path,                      # Path to data
     );
 GetOptions(
-	   'camera|c=s'    => \$camera,
-	   'telescope|t=s' => \$telescope,
-	   'workdir=s'     => \$workdir,
-	   'path=s'        => \$path,
-	   'dbname=s'      => \$dbname,
+           'camera|c=s'    => \$camera,
+           'telescope|t=s' => \$telescope,
+           'workdir=s'     => \$workdir,
+           'tess_id=s'     => \$tess_id,
+           'path=s'        => \$path,
+           'dbname=s'      => \$dbname,
 ) or pod2usage( 2 );
 
 pod2usage(
-	  -msg => "Required options: --camera --telescope --workdir --path --dbname",
-	  -exitval => 3,
-	  ) unless defined $camera
+          -msg => "Required options: --camera --telescope --workdir --path --dbname",
+          -exitval => 3,
+          ) unless defined $camera
     and defined $telescope
     and defined $workdir
@@ -57,12 +59,12 @@
 
 # Inject new data into the database
-my @classes;			# Names of the classes
-my @files;			# What to add to the filename for each class
+my @classes;                    # Names of the classes
+my @files;                      # What to add to the filename for each class
 my $imfiles;
-my $add_dir;			# Add directory name to get file name?
+my $add_dir;                    # Add directory name to get file name?
 if ($camera eq "MEGACAM") {
     for (my $i = 0; $i < 36; $i++) {
-	push @classes, sprintf("ccd%02d", $i);
-	push @files, sprintf(".ccd%02d", $i);
+        push @classes, sprintf("ccd%02d", $i);
+        push @files, sprintf(".ccd%02d", $i);
     }
 } elsif ($camera eq "MCSHORT") {
@@ -74,5 +76,5 @@
 } elsif ($camera eq "TC3") {
     @classes = ( 'CCID58-1-06b2', 'CCID45-1-14A', 'CCID45-1-11A', 'CCID45-1-22A',
-		 'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' );
+                 'CCID45-1-04C', 'CCID45-1-13A', 'CCID45-1-05A', 'CCID45-1-19A' );
     @files = ( '00', '01', '10', '11', '20', '21', '30', '31' );
     $add_dir = 1;
@@ -85,12 +87,12 @@
 } elsif ($camera eq "GPC1") {
     for (my $i = 0; $i < 8; $i++) {
-	for (my $j = 0; $j < 8; $j++) {
-	    if (($i == 0 or $i == 7) and ($j == 0 or $j == 7)) {
-		# Excluding corner chips
-		next;
-	    }
-	    push @classes, "XY$i$j";
-	    push @files, "$i$j";
-	}
+        for (my $j = 0; $j < 8; $j++) {
+            if (($i == 0 or $i == 7) and ($j == 0 or $j == 7)) {
+                # Excluding corner chips
+                next;
+            }
+            push @classes, "XY$i$j";
+            push @files, "$i$j";
+        }
     }
     $add_dir = 1;
@@ -100,54 +102,54 @@
 
 foreach my $exp_name ( @ARGV ) {
-    my $command = "$pxinject -newExp -tmp_exp_name $exp_name -tmp_inst $camera -tmp_telescope $telescope -workdir $workdir"; # Command to run
+    my $command = "$pxinject -newExp -tmp_exp_name $exp_name -tmp_inst $camera -tmp_telescope $telescope -workdir $workdir -tess_id $tess_id"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run( command => $command, verbose => 1 );
+        run( command => $command, verbose => 1 );
     die "Unable to inject $exp_name: $error_code\n" if not $success;
-    
+
     my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag
-    my $exp_id = $line[2];	# The exposure tag
+    my $exp_id = $line[2];      # The exposure tag
     for (my $i = 0; $i < scalar @classes; $i++) {
-	my $class_id = $classes[$i];
-	my $file_id = $files[$i];
-	my $filename = $exp_name . $file_id . '.fits';
-	$filename = caturi( $exp_name, $filename ) if defined $add_dir;
-	$filename = caturi( $path, $filename );
+        my $class_id = $classes[$i];
+        my $file_id = $files[$i];
+        my $filename = $exp_name . $file_id . '.fits';
+        $filename = caturi( $exp_name, $filename ) if defined $add_dir;
+        $filename = caturi( $path, $filename );
 
-	die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
+        die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
 
-	$filename = $ipprc->convert_filename_relative( $filename );
-	my $command = "$pxinject -newImfile -exp_id $exp_id -tmp_class_id $class_id -uri $filename"; # Command to run
-	$command .= " -dbname $dbname" if defined ($dbname);
+        $filename = $ipprc->convert_filename_relative( $filename );
+        my $command = "$pxinject -newImfile -exp_id $exp_id -tmp_class_id $class_id -uri $filename"; # Command to run
+        $command .= " -dbname $dbname" if defined ($dbname);
 
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run( command => $command, verbose => 1 );
-	die "Unable to inject $exp_name $class_id: $error_code\n" if not $success;
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run( command => $command, verbose => 1 );
+        die "Unable to inject $exp_name $class_id: $error_code\n" if not $success;
     }
 
     if (scalar @classes == 0) {
-	my $filename = $exp_name . '.fits';
-	$filename = caturi( $exp_name, $filename ) if defined $add_dir;
-	$filename = caturi( $path, $filename );
+        my $filename = $exp_name . '.fits';
+        $filename = caturi( $exp_name, $filename ) if defined $add_dir;
+        $filename = caturi( $path, $filename );
 
-	die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
+        die "Unable to find file $filename" unless -f $ipprc->file_resolve( $filename );
 
-	$filename = $ipprc->convert_filename_relative( $filename );
-	my $command = "$pxinject -newImfile -exp_id $exp_id -tmp_class_id fpa -uri $filename"; # Command to run
-	$command .= " -dbname $dbname" if defined ($dbname);
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run( command => $command, verbose => 1 );
-	die "Unable to inject $exp_name imfile: $error_code\n" if not $success;
+        $filename = $ipprc->convert_filename_relative( $filename );
+        my $command = "$pxinject -newImfile -exp_id $exp_id -tmp_class_id fpa -uri $filename"; # Command to run
+        $command .= " -dbname $dbname" if defined ($dbname);
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run( command => $command, verbose => 1 );
+        die "Unable to inject $exp_name imfile: $error_code\n" if not $success;
     }
 
     # Update the exposure to run
     {
-	my $command = "$pxinject -updatenewExp -exp_id $exp_id -state run"; # Command to run
-	$command .= " -dbname $dbname" if defined ($dbname);
+        my $command = "$pxinject -updatenewExp -exp_id $exp_id -state run"; # Command to run
+        $command .= " -dbname $dbname" if defined ($dbname);
 
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run( command => $command, verbose => 1 );
-	die "Unable to activate $exp_name: $error_code\n" if not $success;
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run( command => $command, verbose => 1 );
+        die "Unable to activate $exp_name: $error_code\n" if not $success;
     }
 
Index: trunk/ippScripts/scripts/ipp_simulation_data.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_simulation_data.pl	(revision 17604)
+++ trunk/ippScripts/scripts/ipp_simulation_data.pl	(revision 17622)
@@ -13,36 +13,38 @@
 use Pod::Usage qw( pod2usage );
 use PS::IPP::Config qw(
-		       $PS_EXIT_SUCCESS
-		       $PS_EXIT_UNKNOWN_ERROR
-		       $PS_EXIT_SYS_ERROR
-		       $PS_EXIT_CONFIG_ERROR
-		       $PS_EXIT_PROG_ERROR
-		       $PS_EXIT_DATA_ERROR
-		       $PS_EXIT_TIMEOUT_ERROR
-		       caturi
-		       );
+                       $PS_EXIT_SUCCESS
+                       $PS_EXIT_UNKNOWN_ERROR
+                       $PS_EXIT_SYS_ERROR
+                       $PS_EXIT_CONFIG_ERROR
+                       $PS_EXIT_PROG_ERROR
+                       $PS_EXIT_DATA_ERROR
+                       $PS_EXIT_TIMEOUT_ERROR
+                       caturi
+                       );
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
 
-my ($name,			# Base name for output images
-    $camera,			# Name of camera to use
-    $telescope,			# Telescope name
-    $dbname,			# Database name
-    $path,			# Path to data
-    $workdir,			# Working directory for data
-    $no_cal,			# Don't produce calibration files
-    $no_update			# Don't update the database
+my ($name,                      # Base name for output images
+    $camera,                    # Name of camera to use
+    $telescope,                 # Telescope name
+    $tess_id,                   # Tessellation identifier
+    $dbname,                    # Database name
+    $path,                      # Path to data
+    $workdir,                   # Working directory for data
+    $no_cal,                    # Don't produce calibration files
+    $no_update                  # Don't update the database
     );
 
 GetOptions(
-	   'name=s'        => \$name,
-	   'camera=s'      => \$camera,
-	   'telescope=s'   => \$telescope,
-	   'dbname=s'      => \$dbname,
-	   'path=s'        => \$path,
-	   'workdir=s'     => \$workdir,
-	   'no-cal'        => \$no_cal,
-	   'no-update'     => \$no_update,
-	   ) or pod2usage( 2 );
+           'name=s'        => \$name,
+           'camera=s'      => \$camera,
+           'telescope=s'   => \$telescope,
+           'tess_id=s'     => \$tess_id,
+           'dbname=s'      => \$dbname,
+           'path=s'        => \$path,
+           'workdir=s'     => \$workdir,
+           'no-cal'        => \$no_cal,
+           'no-update'     => \$no_update,
+           ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
@@ -50,6 +52,6 @@
 pod2usage(
           -msg => "Required options: --name --path --camera --telescope --dbname",
-	    -exitval => 3,
-	  ) unless
+            -exitval => 3,
+          ) unless
     defined $name and
     defined $path and
@@ -67,7 +69,7 @@
     or (warn "Can't find ipp_serial_inject_mosaic.pl" and $missing_tools = 1);
 
-if ($missing_tools) { 
+if ($missing_tools) {
     warn ("Can't find required tools");
-    exit($PS_EXIT_CONFIG_ERROR); 
+    exit($PS_EXIT_CONFIG_ERROR);
 }
 
@@ -76,42 +78,42 @@
 # Dark exposure times
 use constant DARK => [ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
-		       300, 300, 300, 300, 300, 300, 300, 300, 300, 300 ];
+                       300, 300, 300, 300, 300, 300, 300, 300, 300, 300 ];
 # Flat-field image characteristics
 use constant FLAT => [
-		      {
-			  filter => 'r',
-			  exptime => [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 1, 2, 5, 10, 20, 20, 20, 20, 20 ],
-		      },
-		      {
-			  filter => 'i',
-			  exptime => [ 20, 20, 20, 20, 20 ],
-		      }
-		      ];
+                      {
+                          filter => 'r',
+                          exptime => [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 1, 2, 5, 10, 20, 20, 20, 20, 20 ],
+                      },
+                      {
+                          filter => 'i',
+                          exptime => [ 20, 20, 20, 20, 20 ],
+                      }
+                      ];
 # Object image characteristics
 use constant OBJECT => [
-			{
-			    filter => 'r',
-			    exptime => [ 5, 10, 10, 10, 10, 10, 240 ],
-			    seeing => [ 0.8, 0.4, 0.6, 0.8, 1.2, 1.5, 0.7 ],
-			    ra => 150.119167,
-			    dec => 2.205833,
-			    pa => 0,
-			    zp => 25.15,
-			    sky => 20.86,
-			    dither => 40,
-			},
-			{
-			    filter => 'i',
-			    exptime => [ 5, 30, 30, 30, 30, 30, 240 ],
-			    seeing => [ 0.8, 0.4, 0.6, 0.8, 1.2, 1.5, 0.7 ],
-			    ra => 150.119167,
-			    dec => 2.205833,
-			    pa => 0,
-			    zp => 25.00,
-			    sky => 20.15,
-			    dither => 40,
-			},
-			];
-use constant SCALE => 0.2;	# Plate scale
+                        {
+                            filter => 'r',
+                            exptime => [ 5, 10, 10, 10, 10, 10, 240 ],
+                            seeing => [ 0.8, 0.4, 0.6, 0.8, 1.2, 1.5, 0.7 ],
+                            ra => 150.119167,
+                            dec => 2.205833,
+                            pa => 0,
+                            zp => 25.15,
+                            sky => 20.86,
+                            dither => 40,
+                        },
+                        {
+                            filter => 'i',
+                            exptime => [ 5, 30, 30, 30, 30, 30, 240 ],
+                            seeing => [ 0.8, 0.4, 0.6, 0.8, 1.2, 1.5, 0.7 ],
+                            ra => 150.119167,
+                            dec => 2.205833,
+                            pa => 0,
+                            zp => 25.00,
+                            sky => 20.15,
+                            dither => 40,
+                        },
+                        ];
+use constant SCALE => 0.2;      # Plate scale
 
 #############################################################################################################
@@ -120,18 +122,19 @@
 
 my $counter = 0;
+my $tessellation = (defined $tess_id) ? "--tess_id $tess_id" : ""; # Additional switch for tessellation
 
 # Generate bias images
 for (my $i = 0; $i < BIAS; $i++) {
-    my $basename;		# Output base filename
+    my $basename;               # Output base filename
     ( $basename, $counter ) = filename( $name, $counter );
     my $filename = caturi( $path, $basename );
     unless ($no_cal) {
-	run( command => "$ppSim -camera $camera -type BIAS $filename",
-	     verbose => 1 ) or die "Unable to run ppSim";
-	unless ($no_update) {
-	    run( command => "$inject --camera $camera --telescope $telescope --path $path " .
-		 "--workdir $workdir --dbname $dbname $basename",
-		 verbose => 1 ) or die "Unable to inject file.";
-	}
+        run( command => "$ppSim -camera $camera -type BIAS $filename",
+             verbose => 1 ) or die "Unable to run ppSim";
+        unless ($no_update) {
+            run( command => "$inject --camera $camera --telescope $telescope --path $path " .
+                 "$tessellation --workdir $workdir --dbname $dbname $basename",
+                 verbose => 1 ) or die "Unable to inject file.";
+        }
     }
 }
@@ -139,15 +142,15 @@
 # Generate dark images
 foreach my $exptime ( @{DARK()} ) {
-    my $basename;		# Output base filename
+    my $basename;               # Output base filename
     ( $basename, $counter ) = filename( $name, $counter );
     my $filename = caturi( $path, $basename );
     unless ($no_cal) {
-	run ( command => "$ppSim -camera $camera -type DARK -exptime $exptime $filename",
-	      verbose => 1 ) or die "Unable to run ppSim";
-	unless ($no_update) {
-	    run( command => "$inject --camera $camera --telescope $telescope --path $path " .
-		 "--workdir $workdir --dbname $dbname $basename",
-		 verbose => 1 ) or die "Unable to inject file.";
-	}
+        run ( command => "$ppSim -camera $camera -type DARK -exptime $exptime $filename",
+              verbose => 1 ) or die "Unable to run ppSim";
+        unless ($no_update) {
+            run( command => "$inject --camera $camera --telescope $telescope --path $path " .
+                 "$tessellation --workdir $workdir --dbname $dbname $basename",
+                 verbose => 1 ) or die "Unable to inject file.";
+        }
     }
 }
@@ -157,16 +160,16 @@
     my $filter = $set->{filter}; # Name of filter
     foreach my $exptime ( @{$set->{exptime}} ) {
-	my $basename;		# Output base filename
-	( $basename, $counter ) = filename( $name, $counter );
-	my $filename = caturi( $path, $basename );
-	unless ($no_cal) {
-	    run( command => "$ppSim -camera $camera -type FLAT -filter $filter -exptime $exptime $filename",
-		 verbose => 1 ) or die "Unable to run ppSim";
-	    unless ($no_update) {
-		run( command => "$inject --camera $camera --telescope $telescope --path $path " .
-		     "--workdir $workdir --dbname $dbname $basename",
-		     verbose => 1 ) or die "Unable to inject file.";
-	    }
-	}
+        my $basename;           # Output base filename
+        ( $basename, $counter ) = filename( $name, $counter );
+        my $filename = caturi( $path, $basename );
+        unless ($no_cal) {
+            run( command => "$ppSim -camera $camera -type FLAT -filter $filter -exptime $exptime $filename",
+                 verbose => 1 ) or die "Unable to run ppSim";
+            unless ($no_update) {
+                run( command => "$inject --camera $camera --telescope $telescope --path $path " .
+                     "$tessellation --workdir $workdir --dbname $dbname $basename",
+                     verbose => 1 ) or die "Unable to inject file.";
+            }
+        }
     }
 }
@@ -175,29 +178,29 @@
 foreach my $set ( @{OBJECT()} ) {
     my $filter = $set->{filter}; # Name of filter
-    my $ra0 = $set->{ra};	# Base Right Ascension (deg)
-    my $dec0 = $set->{dec};	# Base Declination (deg)
-    my $pa = $set->{pa};	# Position angle (deg)
-    my $zp = $set->{zp};	# Zero point
-    my $scale = SCALE();	# Plate scale (arcsec/pix)
-    my $sky = 10**( -0.4 * ( $set->{sky} - $zp ) ) * $scale**2;	# Sky background (counts/s)
-    my $dither = $set->{dither} / 3600;	# Dither size (deg)
+    my $ra0 = $set->{ra};       # Base Right Ascension (deg)
+    my $dec0 = $set->{dec};     # Base Declination (deg)
+    my $pa = $set->{pa};        # Position angle (deg)
+    my $zp = $set->{zp};        # Zero point
+    my $scale = SCALE();        # Plate scale (arcsec/pix)
+    my $sky = 10**( -0.4 * ( $set->{sky} - $zp ) ) * $scale**2; # Sky background (counts/s)
+    my $dither = $set->{dither} / 3600; # Dither size (deg)
 
     for (my $i = 0; $i < scalar @{$set->{exptime}}; $i++) {
-	my $exptime = ${$set->{exptime}}[$i]; # Exposure time
-	my $seeing = ${$set->{seeing}}[$i]; # Seeing (pix)
-	my $ra = $ra0 + (2*rand() - 1) * $dither * cos(deg2rad($dec0)); # RA with dither
-	my $dec = $dec0 + (2*rand() - 1) * $dither; # Dec with dither
-
-	my $basename;		# Output base filename
-	( $basename, $counter ) = filename( $name, $counter );
-	my $filename = caturi( $path, $basename );
-	run( command => "$ppSim -camera $camera -type OBJECT -filter $filter -exptime $exptime " .
-	     "-skyrate $sky -ra $ra -dec $dec -pa $pa -scale $scale -zp $zp -seeing $seeing $filename",
-	     verbose => 1 ) or die "Unable to run ppSim";
-	unless ($no_update) {
-	    run( command => "$inject --camera $camera --telescope $telescope --path $path " .
-		 "--workdir $workdir --dbname $dbname $basename",
-		 verbose => 1 ) or die "Unable to inject file.";
-	}
+        my $exptime = ${$set->{exptime}}[$i]; # Exposure time
+        my $seeing = ${$set->{seeing}}[$i]; # Seeing (pix)
+        my $ra = $ra0 + (2*rand() - 1) * $dither * cos(deg2rad($dec0)); # RA with dither
+        my $dec = $dec0 + (2*rand() - 1) * $dither; # Dec with dither
+
+        my $basename;           # Output base filename
+        ( $basename, $counter ) = filename( $name, $counter );
+        my $filename = caturi( $path, $basename );
+        run( command => "$ppSim -camera $camera -type OBJECT -filter $filter -exptime $exptime " .
+             "-skyrate $sky -ra $ra -dec $dec -pa $pa -scale $scale -zp $zp -seeing $seeing $filename",
+             verbose => 1 ) or die "Unable to run ppSim";
+        unless ($no_update) {
+            run( command => "$inject --camera $camera --telescope $telescope --path $path " .
+                 "$tessellation --workdir $workdir --dbname $dbname $basename",
+                 verbose => 1 ) or die "Unable to inject file.";
+        }
     }
 }
@@ -210,7 +213,7 @@
 sub filename
 {
-    my $base = shift;		# Base name
-    my $num = shift;		# Number
-    my $workdir = shift;	# Working directory
+    my $base = shift;           # Base name
+    my $num = shift;            # Number
+    my $workdir = shift;        # Working directory
     my $name = sprintf("$base%04d", $num);
     $num++;
