Index: trunk/ippTasks/fake.pro
===================================================================
--- trunk/ippTasks/fake.pro	(revision 18607)
+++ trunk/ippTasks/fake.pro	(revision 18787)
@@ -7,11 +7,14 @@
 
 book init fakePendingImfile
+book init fakePendingExp
 
 macro fake.status
   book listbook fakePendingImfile
+  book listbook fakePendingExp
 end
 
 macro fake.reset
   book init fakePendingImfile
+  book init fakePendingExp
 end
 
@@ -23,4 +26,10 @@
     active true
   end
+  task fake.exp.load
+    active true
+  end
+  task fake.exp.run
+    active true
+  end
 end
 
@@ -32,8 +41,15 @@
     active false
   end
+  task fake.exp.load
+    active false
+  end
+  task fake.exp.run
+    active false
+  end
 end
 
 # this variable will cycle through the known database names
-$fake_DB = 0
+$fakeImfile_DB = 0
+$fakeExp_DB = 0
 
 # select images ready for fake analysis
@@ -57,8 +73,8 @@
     else
       # save the DB name for the exit tasks
-      option $DB:$fake_DB
-      command faketool -pendingimfile -limit 20 -dbname $DB:$fake_DB
-      $fake_DB ++
-      if ($fake_DB >= $DB:n) set fake_DB = 0
+      option $DB:$fakeImfile_DB
+      command faketool -pendingimfile -limit 20 -dbname $DB:$fakeImfile_DB
+      $fakeImfile_DB ++
+      if ($fakeImfile_DB >= $DB:n) set fakeImfile_DB = 0
     end
   end
@@ -153,2 +169,119 @@
   end
 end
+
+
+
+
+# select exposures ready for fake analysis
+# new entries are added to fakePendingExp
+# skip already-present entries
+task	       fake.exp.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/fake.exp.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command faketool -pendingexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$fakeExp_DB
+      command faketool -pendingexp -limit 20 -dbname $DB:$fakeExp_DB
+      $fakeExp_DB ++
+      if ($fakeExp_DB >= $DB:n) set fakeExp_DB = 0
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout fakePendingExp -key fake_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook fakePendingExp
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup fakePendingExp
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the fake_exp.pl script on pending images
+task	       fake.exp.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages fakePendingExp -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new exposures in fakePendingExp (pantaskState == INIT)
+    book getpage fakePendingExp 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword fakePendingExp $pageName pantaskState RUN
+    book getword fakePendingExp $pageName camera -var CAMERA
+    book getword fakePendingExp $pageName exp_id -var EXP_ID
+    book getword fakePendingExp $pageName exp_tag -var EXP_TAG
+    book getword fakePendingExp $pageName fake_id -var FAKE_ID
+    book getword fakePendingExp $pageName workdir -var WORKDIR_TEMPLATE
+    book getword fakePendingExp $pageName dbname -var DBNAME
+    book getword fakePendingExp $pageName reduction -var REDUCTION
+
+    # specify choice of local or remote host based on camera and fake
+    set.host.for.camera $CAMERA FPA
+
+    # set the WORKDIR variable
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s/%s.fk.%s" $WORKDIR $EXP_TAG $EXP_TAG $FAKE_ID
+
+    stderr $LOGDIR/fake.exp.log
+    stderr $LOGDIR/fake.exp.log
+
+    $run = fake_exp.pl --exp_id $EXP_ID --fake_id $FAKE_ID --camera $CAMERA --outroot $outroot
+    if ("$REDUCTION" != "NULL")
+      $run = $run --reduction $REDUCTION
+    end
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit fakePendingExp $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword fakePendingExp $options:0 pantaskState TIMEOUT
+  end
+end
