Index: trunk/ippTasks/fake.pro
===================================================================
--- trunk/ippTasks/fake.pro	(revision 17359)
+++ trunk/ippTasks/fake.pro	(revision 17359)
@@ -0,0 +1,170 @@
+## fake.pro : globals and support macros : -*- sh -*-
+## this file contains the tasks for running the phase 0 stage
+## these tasks use the book fakePendingImfile
+
+# test for required global variables
+check.globals
+
+$LOGSUBDIR = $LOGDIR/fake
+exec mkdir -p $LOGSUBDIR
+
+book init fakePendingImfile
+
+macro fake.status
+  book listbook fakePendingImfile
+end
+
+macro fake.reset
+  book init fakePendingImfile
+end
+
+macro fake.on
+  task fake.imfile.load
+    active true
+  end
+  task fake.imfile.run
+    active true
+  end
+end
+
+macro fake.off
+  task fake.imfile.load
+    active false
+  end
+  task fake.imfile.run
+    active false
+  end
+end
+
+# this variable will cycle through the known database names
+$fake_DB = 0
+
+# select images ready for fake analysis
+# new entries are added to fakePendingImfile
+# skip already-present entries
+task	       fake.imfile.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/fake.imfile.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command faketool -pendingimfile -limit 20
+    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
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout fakePendingImfile -key fake_id:class_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook fakePendingImfile
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup fakePendingImfile
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+# run the fake_imfile.pl script on pending images
+task	       fake.imfile.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 60
+
+  task.exec
+    book npages fakePendingImfile -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new images in fakePendingImfile (pantaskState == INIT)
+    book getpage fakePendingImfile 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword fakePendingImfile $pageName pantaskState RUN
+    book getword fakePendingImfile $pageName camera -var CAMERA
+    book getword fakePendingImfile $pageName exp_id -var EXP_ID
+    book getword fakePendingImfile $pageName exp_tag -var EXP_TAG
+    book getword fakePendingImfile $pageName fake_id -var FAKE_ID
+    book getword fakePendingImfile $pageName workdir -var WORKDIR_TEMPLATE
+    book getword fakePendingImfile $pageName class_id -var CLASS_ID
+    book getword fakePendingImfile $pageName uri -var URI
+    book getword fakePendingImfile $pageName dbname -var DBNAME
+    book getword fakePendingImfile $pageName reduction -var REDUCTION
+
+    # specify choice of local or remote host based on camera and fake (class_id)
+    set.host.for.camera $CAMERA $CLASS_ID
+
+    # raw workdir examples:
+    # file://data/@HOST@.0/gpc1/20080130
+    # neb:///@HOST@-vol0/gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
+    set.workdir.by.camera $CAMERA $CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+    # out workdir examples:
+    # file://data/ipp004.0/gpc1/20080130
+    # neb:///ipp004-vol0/gpc1/20080130
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s/%s.fk.%s" $WORKDIR $EXP_TAG $EXP_TAG $FAKE_ID
+
+    ## generate output log based on filerule (convert the URI to a PATH)
+    $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
+    if ("$logfile" == "") 
+      echo "WARNING: logfile not defined in fake.pro:152"
+      break
+    end
+
+    stdout $logfile
+    stderr $logfile
+    dirname $logfile -var outpath
+    mkdir $outpath
+
+    $run = fake_imfile.pl --exp_id $EXP_ID --fake_id $FAKE_ID --class_id $CLASS_ID --exp_tag $EXP_TAG --uri $URI --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 fakePendingImfile $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword fakePendingImfile $options:0 pantaskState TIMEOUT
+  end
+end
