Index: trunk/ippTasks/survey.pro
===================================================================
--- trunk/ippTasks/survey.pro	(revision 34824)
+++ trunk/ippTasks/survey.pro	(revision 34828)
@@ -17,4 +17,5 @@
  book create SURVEY_PUBLISH
  book create SURVEY_STATICSKYSINGLE 
+ book create SURVEY_SKYCAL
  $haveSurveyBooks = TRUE
 end
@@ -31,4 +32,5 @@
 $SURVEY_WARP_BG_DB = 0
 $SURVEY_PUBLISH_DB = 0
+$SURVEY_SKYCAL_DB = 0
 $SURVEY_STATICSKYSINGLE_DB = 0
 $SURVEY_EXEC = 120
@@ -73,4 +75,7 @@
     active true
   end  
+  task survey.skycal
+    active true
+  end
 end
 
@@ -110,4 +115,7 @@
   end
   task survey.staticskysingle
+    active false
+  end
+  task survey.skycal
     active false
   end
@@ -464,4 +472,32 @@
   book delpage SURVEY_STATICSKYSINGLE $1
 end
+
+macro survey.add.skycal
+  if ($0 != 3)
+    echo "USAGE: survey.add.skycal (label) (dist_group)"
+    break
+  end
+  book newpage SURVEY_SKYCAL $1
+  book setword SURVEY_SKYCAL $1 LABEL $1
+  book setword SURVEY_SKYCAL $1 DIST_GROUP $2
+  book setword SURVEY_SKYCAL $1 STATE PENDING
+end
+
+macro survey.del.skycal
+  if ($0 != 2)
+    echo "USAGE: survey.del.skycal (label)"
+    break
+  end
+  book delpage SURVEY_SKYCAL $1
+end
+
+macro survey.show.skycal
+  if ($0 != 1)
+    echo "USAGE: survey.show.skyacl"
+    break
+  end
+  book listbook SURVEY_SKYCAL
+end
+
 
 task survey.diff
@@ -1453,2 +1489,74 @@
 end
 
+# Survey task for Skycal stage
+
+task survey.skycal
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  stdout $LOGDIR/survey.skycal.log
+  stderr $LOGDIR/survey.skycal.log
+
+  task.exec
+    book npages SURVEY_SKYCAL -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_SKYCAL 0 -var label -key STATE NEW
+    if ("$label" == "NULL")
+      # All labels have been done --- reset
+#      echo "Resetting labels"
+      for i 0 $N
+        book getpage SURVEY_SKYCAL $i -var label
+	book setword SURVEY_SKYCAL $label STATE NEW
+      end
+      book getpage SURVEY_SKYCAL 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_SKYCAL_DB ++
+      if ($SURVEY_SKYCAL_DB >= $DB:n) set SURVEY_SKYCAL_DB = 0
+    end
+
+    book setword SURVEY_SKYCAL $label STATE DONE
+    book getword SURVEY_SKYCAL $label DIST_GROUP -var dist_group
+
+    # note: currently skycal uses the staticskyRun workdir 
+
+    $run = staticskytool -defineskycalrun -select_label $label -set_dist_group $dist_group
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run -dbname $DB:$SURVEY_SKYCAL_DB
+      option $DB:$SURVEY_SKYCAL_DB
+    end
+    
+    # echo $run
+    command $run
+  end
+
+  # success
+  task.exit    0
+#    echo "Success"
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
