Index: /trunk/Ohana/src/opihi/pantasks/JobOps.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 3139)
+++ /trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 3140)
@@ -70,5 +70,5 @@
 }
 
-/* return job with given name */
+/* return job with given ID */
 Job *FindJob (int JobID) {
 
@@ -161,5 +161,6 @@
 }
 
-/* this needs to: 1) distinguish local from controller jobs
+/* this needs to: 
+   1) distinguish local from controller jobs
    2) fork the local jobs in the background
    3) send the controller jobs to the controller */
Index: /trunk/Ohana/src/opihi/pantasks/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 3139)
+++ /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 3140)
@@ -26,5 +26,5 @@
 
 sched = \
-$(SDIR)/schedule.$(ARCH).o \
+$(SDIR)/run.$(ARCH).o \
 $(SDIR)/task.$(ARCH).o \
 $(SDIR)/task_command.$(ARCH).o \
Index: /trunk/Ohana/src/opihi/pantasks/TaskOps.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/TaskOps.c	(revision 3139)
+++ /trunk/Ohana/src/opihi/pantasks/TaskOps.c	(revision 3140)
@@ -141,2 +141,16 @@
 }
 
+double GetTaskTimer (struct timeval start) {
+
+  double dtime;
+  struct timeval now;
+  
+  gettimeofday (&now, (void *) NULL);
+  dtime = DTIME (now, start);
+  
+  return (dtime);
+}
+
+void SetTaskTimer (struct timeval *timer) {
+  gettimeofday (timer, (void *) NULL);
+}
Index: /trunk/Ohana/src/opihi/pantasks/init.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/init.c	(revision 3139)
+++ /trunk/Ohana/src/opihi/pantasks/init.c	(revision 3140)
@@ -7,5 +7,5 @@
 int task_command    PROTO((int, char **));
 int task_periods    PROTO((int, char **));
-int schedule        PROTO((int, char **));
+int run             PROTO((int, char **));
 
 static Command cmds[] = {  
@@ -16,5 +16,5 @@
   {"command",   task_command, "define executed command for a task"},
   {"periods",   task_periods, "define time scales for a task"},
-  {"schedule",  schedule,     "schedule the tasks"},
+  {"run",       run,          "run the scheduler"},
 }; 
 
Index: /trunk/Ohana/src/opihi/pantasks/run.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/run.c	(revision 3140)
+++ /trunk/Ohana/src/opihi/pantasks/run.c	(revision 3140)
@@ -0,0 +1,121 @@
+# include "basic.h"
+# include "scheduler.h"
+
+int run (int argc, char **argv) {
+
+  Job *job;
+  Task *task;
+  Macro *macro;
+  int i, found, status;
+  int Ntest;
+
+  if (argc != 1) {
+    fprintf (stderr, "USAGE: run\n");
+    return (FALSE);
+  }
+
+  /* start the clock for all tasks */
+  while ((task = NextTask ()) != NULL) {
+    gettimeofday (&task[0].last, (void *) NULL);
+  }
+
+  Ntest = 0;
+
+  /* loop forever, checking for completed jobs and ready tasks */
+  while (1) {
+    if (Ntest > 5) { 
+      ListJobs ();
+      Ntest = 0;
+    }
+    usleep (10000);
+    Ntest ++;
+
+    /** test all tasks: ready to test? ready to run? **/
+    while ((task = NextTask ()) != NULL) {
+
+      /* ready to test? : check exec period */
+      if (GetTaskTimer(task[0].last) < task[0].exec_period) continue;
+
+      SetCurrentTask (task[0].name);
+      fprintf (stderr, "trying task %s\n", task[0].name);
+
+      /* ready to run? : run task.exec macro */
+      if (task[0].exec != NULL) {
+	status = exec_loop (task[0].exec);
+	if (!status) continue;
+      }
+
+      /* is task valid?  check state of task.(argc, argv) */
+      /*** ADD CODE HERE ***/
+
+      /* construct job from task */
+      job = CreateJob (task);
+
+      /* execute job - XXX add status test */
+      SubmitJob (job);
+
+      /* reset timer on task (don't do this if Create/Submit fails)*/
+      gettimeofday (&task[0].last, (void *) NULL);
+    }
+
+    /** test all jobs: ready to test?  finished? **/
+    while ((job = NextJob ()) != NULL) {
+
+      /* check for timeout */
+      if (GetTaskTimer(job[0].start) >= job[0].task.timeout_period) {
+	fprintf (stderr, "timeout on %s\n", job[0].task.name);
+	/* run task.timeout macro, if it exists */
+	if (job[0].task.timeout != NULL) {
+	  exec_loop (job[0].task.timeout);
+	}
+	DeleteJob (job);
+	continue;
+      }
+
+      /* check poll period (ready to run again?) */
+      if (GetTaskTimer(job[0].last) < job[0].task.poll_period) continue;
+
+      /* check current status */
+      status = CheckJob (job);
+      switch (status) {
+	case JOB_BUSY:
+	  fprintf (stderr, "job %s (%d) busy\n", job[0].task.name, job[0].JobID);
+	  break;
+
+	case JOB_CRASH:
+	  fprintf (stderr, "job %s (%d) crash\n", job[0].task.name, job[0].JobID);
+	  /* run task.crash macro, if it exists */
+	  if (job[0].task.crash != NULL) {
+	    exec_loop (job[0].task.crash);
+	  }
+	  DeleteJob (job);
+	  continue;
+	  break;
+
+	case JOB_EXIT:
+	  fprintf (stderr, "job %s (%d) exit\n", job[0].task.name, job[0].JobID);
+	  /* run corresponding task.exit macro, if it exists */
+	  macro = job[0].task.def;
+	  for (i = 0; i < job[0].task.Nexit; i++) {
+	    if (job[0].exit_status == atoi(job[0].task.exit[i][0].name)) {
+	      macro = job[0].task.exit[i];
+	      break;
+	    }
+	  }
+	  if (macro != NULL) exec_loop (macro);
+	  DeleteJob (job);
+	  continue;
+	  break;
+
+	default:
+	  fprintf (stderr, "unknown exit status\n");
+	  /** do something more useful here ?? **/
+	  break;
+      }
+
+      /* reset polling clock */
+      SetTaskTimer (&job[0].last);
+    }
+  }
+  return (TRUE);
+}
Index: unk/Ohana/src/opihi/pantasks/sched.txt
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/sched.txt	(revision 3139)
+++ 	(revision )
@@ -1,52 +1,0 @@
-
-scheduler commands:
-
-task (taskname)
- - define a new task
- - loads task-related commands from list / readline
- - commands are parsed on load
- - end with end (like if / for)
-
-task.exit (value)
- - define a new task macro for this exit condition
-   (value) may be an exit status (number)
-   (value) may be 'timeout'
-   (value) may be 'crash' ?
- - commands are parsed on execution (not on definition)
-
-task.exec
- - define a task macro for exec condition
- - commands are parsed on execution (not on definition)
-
-command (args) (args)
- - defines command associated with task
- - may be in task or in task.macro (exit/exec)
-   (in task, command line is static; in task.macro, command line is expanded for each instance)
-
-host (machine)
- - defines preferred host
- - may be in task or in task.macro (exit/exec)
-   (in task, value is static; in task.macro, value is defined for each instance)
-
-stderr (file / variable)
- - defines destination for stderr capture from task
- - written to destination at end of execution?
-
-stdout (file / variable)
- - defines destination for stdout capture from task
- - written to destination at end of execution?
-
-periods -poll 1
-periods -exec 30
-periods -timeout 2
- - defines relevant time-scale for the task
-
-schedule
- - runs the scheduler loop, executing the various tasks
-
-scheduler functions:
-
-InitTasks ();
-FindTask ();
-CreateTask ();
-
Index: unk/Ohana/src/opihi/pantasks/schedule.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/schedule.c	(revision 3139)
+++ 	(revision )
@@ -1,134 +1,0 @@
-# include "basic.h"
-# include "scheduler.h"
-
-int schedule (int argc, char **argv) {
-
-  Job *job;
-  Task *task;
-  Macro *macro;
-  struct timeval now;
-  double dtime;
-  int i, found, status;
-  int Ntest;
-
-  if (argc != 1) {
-    fprintf (stderr, "USAGE: schedule\n");
-    return (FALSE);
-  }
-
-  /*
-  task = NextTask ();
-  CreateJob (task);
-  CreateJob (task);
-  job = NextJob ();
-  DeleteJob (job);
-  CreateJob (task);
-  return (FALSE);
-  */
-
-  /* start the clock for all tasks */
-  while ((task = NextTask ()) != NULL) {
-    gettimeofday (&task[0].last, (void *) NULL);
-  }
-
-  Ntest = 0;
-
-  while (1) {
-    if (Ntest > 5) { 
-      ListJobs ();
-      Ntest = 0;
-    }
-    usleep (10000);
-    Ntest ++;
-
-    /** test all tasks **/
-    while ((task = NextTask ()) != NULL) {
-
-      /* check exec period (ready to run again?) */
-      gettimeofday (&now, (void *) NULL);
-      dtime = DTIME (now, task[0].last);
-      if (dtime < task[0].exec_period) continue;
-
-      SetCurrentTask (task[0].name);
-      fprintf (stderr, "trying task %s\n", task[0].name);
-
-      /* run task.exec macro */
-      if (task[0].exec != NULL) {
-	status = exec_loop (task[0].exec);
-	if (!status) continue;
-      }
-
-      /* is task valid ?(argc, argv) */
-
-      /* construct job from task */
-      job = CreateJob (task);
-
-      /* execute job */
-      SubmitJob (job);
-
-      /* reset timer on task (don't do this if Create/Submit fails)*/
-      gettimeofday (&task[0].last, (void *) NULL);
-
-    }
-
-    /** test all jobs **/
-    while ((job = NextJob ()) != NULL) {
-
-      /* check poll period (ready to run again?) */
-      gettimeofday (&now, (void *) NULL);
-
-      dtime = DTIME (now, job[0].last);
-      if (dtime >= job[0].task.poll_period) {
-	/* check current status */
-	status = CheckJob (job);
-	switch (status) {
-	case JOB_BUSY:
-	  fprintf (stderr, "job %s (%d) busy\n", job[0].task.name, job[0].JobID);
-	  break;
-
-	case JOB_CRASH:
-	  fprintf (stderr, "job %s (%d) crash\n", job[0].task.name, job[0].JobID);
-	  if (job[0].task.crash != NULL) {
-	    exec_loop (job[0].task.crash);
-	  }
-	  DeleteJob (job);
-	  continue;
-	  break;
-
-	case JOB_EXIT:
-	  fprintf (stderr, "job %s (%d) exit\n", job[0].task.name, job[0].JobID);
-	  /* look for corresponding exit macro */
-	  macro = job[0].task.def;
-	  for (i = 0; i < job[0].task.Nexit; i++) {
-	    if (job[0].exit_status == atoi(job[0].task.exit[i][0].name)) {
-	      macro = job[0].task.exit[i];
-	      break;
-	    }
-	  }
-	  if (macro != NULL) exec_loop (macro);
-	  DeleteJob (job);
-	  continue;
-	  break;
-
-	default:
-	  fprintf (stderr, "unknown exit status\n");
-	  break;
-	}
-	job[0].last = now;
-      }
-
-      dtime = DTIME (now, job[0].start);
-      if (dtime >= job[0].task.timeout_period) {
-	fprintf (stderr, "timeout on %s\n", job[0].task.name);
-	if (job[0].task.timeout != NULL) {
-	  exec_loop (job[0].task.timeout);
-	}
-	DeleteJob (job);
-	continue;
-      }
-    }
-  }
-
-  return (TRUE);
-
-}
Index: unk/Ohana/src/opihi/pantasks/schinit.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/schinit.c	(revision 3139)
+++ 	(revision )
@@ -1,76 +1,0 @@
-# include "opihi.h"
-
-# define opihi_name "MANA"
-# define opihi_prompt "mana: "
-# define opihi_description "an image manipulation tool\n"
-# define opihi_history ".mana"
-# define opihi_rcfile ".manarc"
-
-void InitBasic ();
-
-void welcome () {
-  fprintf (stderr, "\n");
-  fprintf (stderr, "Welcome to %s - %s\n\n", opihi_name, opihi_description);
-}
-
-/* program-dependent initialization */
-void initialize (int argc, char **argv) {
-  
-  FILE *f;
-
-  auto_break = TRUE;
-
-  Nlists = 0;
-  ALLOCATE (lists, List, 1); 
-
-  /* init functions required by libraries */
-  /* -libopihi */
-  InitCommands ();
-  InitMacros ();
-  InitBuffers ();
-  InitVectors ();
-  InitVariables ();
-
-  /* -libdisplay */
-  InitGraph ();
-  InitImage ();
-
-  /* load the commands used by this implementation */
-  InitBasic ();
-  InitData ();
-  InitAstro ();
-  InitOutfile ();
-
-  rl_readline_name = opihi_name;
-  rl_attempted_completion_function = command_completer;
-
-  set_str_variable ("HISTORY", opihi_history);
-  set_str_variable ("PROMPT", opihi_prompt);
-  set_str_variable ("RCFILE", opihi_rcfile);
-
-  /* here we open the history file for append.  it this fails, we
-     won't be able to write to it, warn the user.  otherwise, this
-     creates the file readline will write to, if it did not exist */  
-
-  /* check history file */
-  /* rewrite with fstat or stat */
-  f = fopen (opihi_history, "a");
-  if (f == NULL) /* no current history file here */
-    fprintf (stderr, "can't save history.\n");
-  else
-    fclose (f);
-  
-  stifle_history (200);
-  read_history (opihi_history);
-
-  signal (SIGINT, SIG_IGN);
-  return;
-}
-
-/* add program-dependent exit functions here */
-void cleanup () {
-  /* -libdisplay
-  QuitImage ();
-  QuitGraph (); */
-  return;
-}
