Index: trunk/Ohana/doc/www/html/IPP-subsystems/psched/chip.host
===================================================================
--- trunk/Ohana/doc/www/html/IPP-subsystems/psched/chip.host	(revision 4813)
+++ trunk/Ohana/doc/www/html/IPP-subsystems/psched/chip.host	(revision 4813)
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+
+if (@ARGV != 1) { die "USAGE: chip.host (chip)\n"; }
+
+$chip = $ARGV[0];
+
+if ($chip eq "ccd00") {
+    print "po04\n";
+    exit 0;
+}
+if ($chip eq "ccd01") {
+    print "po01\n";
+    exit 0;
+}
+if ($chip eq "ccd02") {
+    print "po02\n";
+    exit 0;
+}
+if ($chip eq "ccd03") {
+    print "po03\n";
+    exit 0;
+}
+print "anyhost\n";
Index: trunk/Ohana/doc/www/html/IPP-subsystems/psched/copy.image
===================================================================
--- trunk/Ohana/doc/www/html/IPP-subsystems/psched/copy.image	(revision 4813)
+++ trunk/Ohana/doc/www/html/IPP-subsystems/psched/copy.image	(revision 4813)
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+if (@ARGV != 2) { die "USAGE: copy.image (filename) (chip)\n"; }
+
+$filename = $ARGV[0];
+$chip     = $ARGV[1];
+
+@word = split ("/", $filename);
+$base = $word[-1];
+$output = "/data/alala/swtests/psched/$base";
+
+open (FILE, ">$output");
+$host = `hostname`;
+printf FILE "chip $chip $host\n";
+close (FILE);
+
+printf STDOUT "$filename $chip\n";
+
+exit 0;
Index: trunk/Ohana/doc/www/html/IPP-subsystems/psched/new.images
===================================================================
--- trunk/Ohana/doc/www/html/IPP-subsystems/psched/new.images	(revision 4813)
+++ trunk/Ohana/doc/www/html/IPP-subsystems/psched/new.images	(revision 4813)
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+# a dummy script to simulate data arriving from OTIS
+
+# read lines 'new.list', send to 'raw.list'
+
+open (FILE, "new.last");
+@list = <FILE>;
+close (FILE);
+($Nend) = split (" ", $list[0]);
+# print "Nend: $Nend\n";
+
+open (FILE, "new.list");
+@list = <FILE>;
+close (FILE);
+
+$Nend += 5;
+for ($i = 0; $i < $Nend; $i++) {
+    ($name, $chip, $state) = split (" ", $list[$i]);
+    if ($state ne "new") { next; }
+    print "$list[$i]";
+}
+
+open (FILE, ">new.last");
+print FILE "$Nend\n";
+close (FILE);
Index: trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.htm
===================================================================
--- trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.htm	(revision 4813)
+++ trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.htm	(revision 4813)
@@ -0,0 +1,138 @@
+
+Below is an example script for psched which demonstrates the
+scheduling system. This parallel-copying script implements the
+Pan-STARRS image copying system, which requests images from the summit
+and copies them to the appropriate computer.  The first task in the
+script queries an external system for new image names with the
+function <tt>new.images</tt>.  In the case of Pan-STARRS, this would
+be a request from OTIS, the observatory controlling system.  The
+second task initiates the individual image copies, with separate CCDs
+being copied to separate computers.  This script uses the concept of
+having specific machines assigned to specific CCDs (as Pan-STARRS
+intends to operate). The association is determined by calling the
+external function <tt>chip.host</tt>, providing the identifier of the
+chip in question.  This returns an appropriate host.  The
+<tt>copy.image</tt> function copies the file and also sends a message
+to the summit system to inform it that the image has been successfully
+copied.
+
+<p>
+You may download just the <a href="pcopy.pro">pcopy.pro</a> script for
+a copy free of HTML code.  Also available are the dummy scripts <a
+href="new.images">new.images</a>, <a href="copy.image">copy.image</a>,
+and <a href="chip.host">chip.host</a>.
+
+<hr>
+
+<pre>
+verbose on
+queueinit newImages
+exec echo 0 > new.last
+exec cp -f raw.list new.list
+
+controller host add po01
+controller host add po02
+controller host add po03
+controller host add po04
+
+# identify the images ready for copy 
+# new entries are added to queue newImages
+# need to compare the new list with the ones already being processed
+task	       new.images
+  command      new.images
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 5
+
+  # success
+  task.exit    0
+    local i j Nstdout Nimages
+    # compare output with new.image queue
+    # keep only new entries
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush newImages -uniq -key 0 "$line"
+    end
+  end
+
+  # locked list
+  task.exit    1
+    echo       "new.images: exec failure"
+    $new.image.failure ++
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "new.images: unknown exit status: $EXIT"
+    $new.image.failure ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "new.images: timeout"
+    $new.image.failure ++
+  end
+end
+
+# copy new images, sending job to desired host
+task	       copy.images
+  periods      -poll 0.2
+  periods      -exec 1
+  periods      -timeout 5
+
+  task.exec
+    queuesize  newImages -var N
+    if ($N == 0) break
+    # if ($network == 0) break
+    # if ($filesystem == 1) break
+    
+    queuepop newImages -var line
+    list tmp -split $line
+    $filename   = $tmp:0
+    $chip       = $tmp:1
+    $state      = $tmp:2
+    if ($state == new) 
+      # copy this image
+      queuepush newImages -replace -key 0 "$filename $chip run"
+    else
+      # ignore this image
+      queuepush newImages -replace -key 0 "$filename $chip $state"
+      break
+    end
+    # echo $chip
+    $host = `chip.host $chip`
+    # echo $host
+    host $host
+    # echo "starting copy for $filename on $host..."
+    command copy.image $filename $chip
+  end
+
+  # can I have access to argc,argv?
+
+  # success
+  task.exit    0
+    echo "done copy..."
+    queuepop stdout -var line
+    list tmp -split $line
+    $filename   = $tmp:0
+    $chip       = $tmp:1
+    exec mark.image $filename
+    queuepush newImages -replace -key 0 "$filename $chip copy"
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "new.images: unknown exit status: $EXIT"
+    $new.image.failure ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "new.images: timeout"
+    $new.image.failure ++
+  end
+end
+<pre>
Index: trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.pro
===================================================================
--- trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.pro	(revision 4813)
+++ trunk/Ohana/doc/www/html/IPP-subsystems/psched/pcopy.pro	(revision 4813)
@@ -0,0 +1,111 @@
+
+verbose on
+queueinit newImages
+exec echo 0 > new.last
+exec cp -f raw.list new.list
+
+controller host add po01
+controller host add po02
+controller host add po03
+controller host add po04
+
+# identify the images ready for copy 
+# new entries are added to queue newImages
+# need to compare the new list with the ones already being processed
+task	       new.images
+  command      new.images
+  host         local
+
+  periods      -poll 1
+  periods      -exec 5
+  periods      -timeout 5
+
+  # success
+  task.exit    0
+    local i j Nstdout Nimages
+    # compare output with new.image queue
+    # keep only new entries
+    queuesize stdout -var Nstdout
+    for i 0 $Nstdout
+      queuepop stdout -var line
+      queuepush newImages -uniq -key 0 "$line"
+    end
+  end
+
+  # locked list
+  task.exit    1
+    echo       "new.images: exec failure"
+    $new.image.failure ++
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "new.images: unknown exit status: $EXIT"
+    $new.image.failure ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "new.images: timeout"
+    $new.image.failure ++
+  end
+end
+
+# copy new images, sending job to desired host
+task	       copy.images
+  periods      -poll 0.2
+  periods      -exec 1
+  periods      -timeout 5
+
+  task.exec
+    queuesize  newImages -var N
+    if ($N == 0) break
+    # if ($network == 0) break
+    # if ($filesystem == 1) break
+    
+    queuepop newImages -var line
+    list tmp -split $line
+    $filename   = $tmp:0
+    $chip       = $tmp:1
+    $state      = $tmp:2
+    if ($state == new) 
+      # copy this image
+      queuepush newImages -replace -key 0 "$filename $chip run"
+    else
+      # ignore this image
+      queuepush newImages -replace -key 0 "$filename $chip $state"
+      break
+    end
+    # echo $chip
+    $host = `chip.host $chip`
+    # echo $host
+    host $host
+    # echo "starting copy for $filename on $host..."
+    command copy.image $filename $chip
+  end
+
+  # can I have access to argc,argv?
+
+  # success
+  task.exit    0
+    echo "done copy..."
+    queuepop stdout -var line
+    list tmp -split $line
+    $filename   = $tmp:0
+    $chip       = $tmp:1
+    exec mark.image $filename
+    queuepush newImages -replace -key 0 "$filename $chip copy"
+  end
+
+  # default exit status
+  task.exit    default
+    echo       "new.images: unknown exit status: $EXIT"
+    $new.image.failure ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    echo       "new.images: timeout"
+    $new.image.failure ++
+  end
+end
