Index: /trunk/PS-IPP-Config/lib/PS/IPP/Operations.pm
===================================================================
--- /trunk/PS-IPP-Config/lib/PS/IPP/Operations.pm	(revision 15645)
+++ /trunk/PS-IPP-Config/lib/PS/IPP/Operations.pm	(revision 15645)
@@ -0,0 +1,77 @@
+# Copyright (c) 2007  Paul Price
+#
+# $Id: Operations.pm,v 1.1 2007-11-17 02:35:59 price Exp $
+
+package PS::IPP::Operations;
+
+use strict;
+use warnings FATAL => qw( all );
+
+our $VERSION = '0.01';
+
+use Carp qw( carp );
+use IPC::Cmd 0.36 qw( can_run run );
+
+# Allow exporting of function
+use base qw( Exporter );
+our @EXPORT_OK = qw( generate_skycells );
+
+#$::RD_TRACE = 1;
+#$::RD_HINT = 1;
+#use Data::Dumper;
+
+# Extract skycells to images
+sub generate_skycells {
+    my $ipprc = shift;		# Configuration object
+    my $tess_ids = shift;	# List of tessellation ids
+    my $skycell_ids = shift;	# List of skycell ids
+    my $workdir = shift;	# Working directory
+
+    if (scalar @$tess_ids != scalar @$skycell_ids) {
+	carp "Lengths of tess_id and skycell_id don't match";
+	return 0;
+    }
+
+    my $dvoImageExtract = can_run('dvoImageExtract') or die "Can't find dvoImageExtract";
+
+    my $tessellations = $ipprc->tessellations() or
+	(carp "Can't get list of tessellations." and return 0); # Hash of defined tessellations
+
+    for (my $i = 0; $i < scalar @$tess_ids; $i++) {
+	my $tess_id = $$tess_ids[$i]; # Tessellation identifier
+	my $skycell_id = $$skycell_ids[$i]; # Skycell identifier
+
+	### Because DVO doesn't use psModules, it doesn't understand Nebulous --- check
+	my $scheme = file_scheme($$tessellations{$tess_id}); # The scheme, e.g., file, path, neb
+	if (defined $scheme and lc($scheme) eq 'neb') {
+	    carp "Tessellation $tess_id refers to a Nebulous path: $$tessellations{$tess_id}";
+	    return 0;
+	}
+
+	my $tess_dir = $ipprc->convert_filename_absolute( $$tessellations{$tess_id} ); # Catdir for DVO
+	my $skyDir = caturi($workdir, "tess_" . $tess_id, "sky_" . $skycell_id ); # Directory for output
+
+	# Extract the skycell to an image
+	my $skyFile = $ipprc->file_prepare( $skycell_id, $skyDir );
+	unless ($ipprc->file_exists( $skyFile )) {
+	    my $skyFileResolved = $ipprc->file_create( $skyFile ); # Resolved filename, for Nebulous
+	    my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $skyFileResolved";
+	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+		run(command => $command, verbose => 1);
+	    unless ($success) {
+		carp "Unable to perform dvoImageExtract for $tess_id $skycell_id";
+		return 0;
+	    }
+	}
+    }
+}
+
+
+
+
+
+
+1;
+
+__END__;
+
