Index: /trunk/Ohana/src/opihi/cmd.data/lookup.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/lookup.c	(revision 7951)
+++ /trunk/Ohana/src/opihi/cmd.data/lookup.c	(revision 7952)
@@ -3,8 +3,7 @@
 int lookup (int argc, char **argv) {
   
-  int i, Nbins, bin, N, Normalize;
-  float start, end, delta;
-  float *V, *K, *O, *NV;
-  Vector *val, *key, *out;
+  int i, j;
+  float *ip, *op, *xp, *yp;
+  Vector *in, *out, *xv, *yv;
 
   if (argc != 5) {
Index: /trunk/Ohana/src/opihi/doc/pantasks.txt
===================================================================
--- /trunk/Ohana/src/opihi/doc/pantasks.txt	(revision 7951)
+++ /trunk/Ohana/src/opihi/doc/pantasks.txt	(revision 7952)
@@ -1,7 +1,12 @@
+
+- todo:
+
+  - create the processing threads:
+    - check tasks
+    - check jobs
+    - check controller  
+    - load inputs
 
 - additional issues:
-
-  - missing dependency for shell.h?
-  - should not return an error message in client if command is not found
   - server input needs to place files for input on a stack which is 
     actually loaded by the RunScheduler loop
@@ -10,39 +15,7 @@
     be running multicommand, but it probably does not hurt.
     (the client is not allowed to send ';' to the server)
-  - the multicommand needs to be available in the 'for' and other loops
-    this probably means unifying the client and non-client forms.  
-    how does multiclient get the value of the server?  I tend to use
-    globals for things like that, which is probably not the best 
-    practice.  is the client form of the tool generic? are there other
-    circumstances which would use a client/server beyond pantasks?
-    maybe pcontrol?  
 
-    the two pieces of information which need to be carried to the
-    multicommand and command functions in client/server mode are the 
-    server socket and the verbosity of the error messages.  these could
-    be defined on startup with globals and an init function of some sort.
+  - pantasks input: this passes an 'input' command to the server, which
+    performs the input in a different thread.  is this the same thread
+    as the scheduler loop?  another option within the scheduler loop?
 
-I need to do some serious work on the output messages in order 
-to support the client/server interactions.  In client/server mode,
-all of the output messages to be sent back to the client need to be
-saved in a buffer and then pushed back to the client after the command
-is executed.  Currently, I can select only the output file pointer.
-this is not sufficient.  I need to supply a function which will write to 
-an internal buffer until a 'dump' function is called, or something
-equivalent.  
-
-in client/server mode, the commands issues by the client (except as noted 
-below) all return immediately.  The output produced by those commands
-is saved by the server until the command is finished, then the
-resulting buffered data is pushed back to the client.  There a few
-commands which behave a bit differently.  these commands are in the
-background thread of the scheduler.  the resulting output is sent to
-the logger device of the scheduler rather than back to any specific
-client.  should there be a way for the client(s) to examine the
-scheduler output? 
-
-- pantasks input: this passes an 'input' command to the server, which
-  performs the input in a different thread.  is this the same thread
-  as the scheduler loop?  another option within the scheduler loop?
-
-- run
Index: /trunk/Ohana/src/opihi/include/pantasks.h
===================================================================
--- /trunk/Ohana/src/opihi/include/pantasks.h	(revision 7951)
+++ /trunk/Ohana/src/opihi/include/pantasks.h	(revision 7952)
@@ -213,2 +213,25 @@
 int gprintf (char *format, ...);
 */
+
+// functions related to the server threads
+void CheckTasksSetState (int state);
+int CheckTasksGetState ();
+void CheckTasksThread ();
+void CheckJobsSetState (int state);
+int CheckJobsGetState ();
+void CheckJobsThread ();
+void CheckControllerSetState (int state);
+int CheckControllerGetState ();
+void CheckControllerThread ();
+void CheckInputsSetState (int state);
+int CheckInputsGetState ();
+void CheckInputsThread ();
+
+// functions related to the queue of input files
+void InitInputs ();
+void AddNewInput (char *input);
+int DeleteInput (char *input);
+void CheckInputs ();
+
+void SerialThreadLock ();
+void SerialThreadUnlock ();
Index: /trunk/Ohana/src/opihi/pantasks/InputQueue.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/InputQueue.c	(revision 7952)
+++ /trunk/Ohana/src/opihi/pantasks/InputQueue.c	(revision 7952)
@@ -0,0 +1,80 @@
+# include "pantasks.h"
+# define DEBUG 1
+
+static int Ninputs = 0;
+static int NINPUTS = 0;
+static char **inputs;
+
+void InitInputs () {
+
+  Ninputs = 0;
+  NINPUTS = 10;
+  ALLOCATE (inputs, char *, NINPUTS);
+}
+
+/* add this input to the inputs table */
+void AddNewInput (char *input) {
+
+  SerialThreadLock ();
+  if (DEBUG) gprint (GP_LOG, "adding a new input (%s)\n", input);
+  inputs[Ninputs] = input;
+  Ninputs ++;
+  if (Ninputs >= NINPUTS - 1) {
+    NINPUTS += 10;
+    REALLOCATE (inputs, char *, NINPUTS);
+  }
+  if (DEBUG) gprint (GP_LOG, "done new input (%s)\n", input);
+  SerialThreadUnlock ();
+}
+
+/* remove this input from the inputs table */
+int DeleteInput (char *input) {
+
+  int i, j;
+
+  if (DEBUG) gprint (GP_LOG, "deleting an input (%s)\n", input);
+  for (i = 0; i < Ninputs; i++) {
+    if (inputs[i] == input) {
+      free (inputs[i]);
+      for (j = i; j < Ninputs - 1; j++) {
+	inputs[j] = inputs[j+1];
+      }
+      Ninputs --;
+      if ((Ninputs > 10) && (Ninputs / 2 < NINPUTS)) {
+	NINPUTS = Ninputs + 10;
+	REALLOCATE (inputs, char *, NINPUTS);
+      }
+      if (DEBUG) gprint (GP_LOG, "deleted an input\n");
+      return TRUE;
+    }
+  }
+  // did not find the input
+  return FALSE;
+}
+
+/* if any inputs are pending, run one */
+void CheckInputs () {
+
+  int Nbytes, status;
+  char *input, *line, *outline, tmp;
+
+  if (Ninputs < 1) return;
+
+  input = inputs[0];
+  if (DEBUG) gprint (GP_LOG, "got an input (%s)\n", input);
+  
+  Nbytes = snprintf (&tmp, 0, "input %s", input);
+  fprintf (stderr, "string len %d\n", Nbytes);
+
+  ALLOCATE (line, char, Nbytes + 1);
+  fprintf (stderr, "allocated line\n");
+
+  snprintf (line, Nbytes + 1, "input %s", input);
+  
+  fprintf (stderr, "running command %s\n", line);
+
+  status = command (line, &outline, TRUE);
+  free (outline);
+  
+  DeleteInput (input);
+}
Index: /trunk/Ohana/src/opihi/pantasks/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 7951)
+++ /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 7952)
@@ -74,4 +74,8 @@
 server = \
 $(SDIR)/pantasks_server.$(ARCH).o \
+$(SDIR)/server_threads.$(ARCH).o \
+$(SDIR)/server_run.$(ARCH).o \
+$(SDIR)/server_load.$(ARCH).o \
+$(SDIR)/InputQueue.$(ARCH).o \
 $(SDIR)/ListenClients.$(ARCH).o \
 $(SDIR)/CheckPassword.$(ARCH).o
Index: /trunk/Ohana/src/opihi/pantasks/pantasks_server.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 7951)
+++ /trunk/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 7952)
@@ -16,5 +16,9 @@
 int main (int argc, char **argv) {
   
-  pthread_t thread;
+  pthread_t clientsThread;
+  pthread_t tasksThread;
+  pthread_t jobsThread;
+  pthread_t inputsThread;
+  pthread_t controllerThread;
   int InitSocket, BindSocket;
   SockAddress Address;
@@ -32,4 +36,5 @@
   
   gprintInit ();  // each thread needs to init the printing system
+  InitInputs ();
 
   signal (SIGPIPE, gotsignal);
@@ -38,14 +43,12 @@
   signal (SIGINT, SIG_DFL);
 
-  // startup (&argc, argv);
-
-  /* set up mechanisms for sharing data between the threads */
-  // init_data_handling ();
+  startup (&argc, argv);
 
   /* start up the background threads here */
-  pthread_create (&thread, NULL, &ListenClients, NULL);
-
-  // pthread_create (&thread, NULL, &RunScheduler, NULL);
-  // pthread_create (&thread, NULL, &RunController, NULL);
+  pthread_create (&clientsThread,    NULL, &ListenClients,    	   NULL);
+  pthread_create (&tasksThread,      NULL, &CheckTasksThread, 	   NULL);
+  pthread_create (&jobsThread,       NULL, &CheckJobsThread,  	   NULL);
+  pthread_create (&controllerThread, NULL, &CheckControllerThread, NULL);
+  pthread_create (&inputsThread,     NULL, &CheckInputsThread,     NULL);
 
   /* in this loop, we listen for incoming connections, validate, and
Index: /trunk/Ohana/src/opihi/pantasks/server.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/server.c	(revision 7951)
+++ /trunk/Ohana/src/opihi/pantasks/server.c	(revision 7952)
@@ -4,4 +4,7 @@
 int quit            PROTO((int, char **));
 int input      	    PROTO((int, char **));
+int server_load	    PROTO((int, char **));
+int server_run	    PROTO((int, char **));
+int server_stop	    PROTO((int, char **));
 int cd              PROTO((int, char **));
 int pwd        	    PROTO((int, char **));
@@ -14,4 +17,7 @@
   {"quit",   quit,   "shutdown server"},
   {"input",  input,  "load input file on server"},
+  {"load",   server_load, "load input file on server"},
+  {"run",    server_run,  "run scheduler"},
+  {"stop",   server_stop, "stop scheduler"},
   {"cd",     cd,     "set local directory"},
   {"pwd",    pwd,    "check local directory"},
Index: /trunk/Ohana/src/opihi/pantasks/server_load.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/server_load.c	(revision 7952)
+++ /trunk/Ohana/src/opihi/pantasks/server_load.c	(revision 7952)
@@ -0,0 +1,18 @@
+# include "pantasks.h"
+
+int server_load (int argc, char **argv) {
+
+  char *input;
+
+  if (argc != 2) {
+    gprint (GP_ERR, "USAGE: server load (file)\n");
+    return (FALSE);
+  }
+
+  // the allocated input string is eventually freed 
+  // by the InputQueue system
+  input = strcreate (argv[1]);
+  AddNewInput (input);
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/pantasks/server_run.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/server_run.c	(revision 7952)
+++ /trunk/Ohana/src/opihi/pantasks/server_run.c	(revision 7952)
@@ -0,0 +1,23 @@
+# include "pantasks.h"
+
+int server_run (int argc, char **argv) {
+
+  if (argc != 1) {
+    gprint (GP_ERR, "USAGE: server run\n");
+    return (FALSE);
+  }
+
+  CheckTasksSetState (TRUE);
+  return (TRUE);
+}
+
+int server_stop (int argc, char **argv) {
+
+  if (argc != 1) {
+    gprint (GP_ERR, "USAGE: server stop\n");
+    return (FALSE);
+  }
+
+  CheckTasksSetState (FALSE);
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/pantasks/server_threads.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/server_threads.c	(revision 7952)
+++ /trunk/Ohana/src/opihi/pantasks/server_threads.c	(revision 7952)
@@ -0,0 +1,138 @@
+# include "pantasks.h"
+
+/* this mutex is used by the serialized threads */
+
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void SerialThreadLock () {
+    pthread_mutex_lock (&mutex);
+}
+
+void SerialThreadUnlock () {
+    pthread_mutex_unlock (&mutex);
+}
+
+/** things related to CheckTasks **/
+
+static int CheckTasksRun = FALSE;
+
+void CheckTasksSetState (int state) {
+  CheckTasksRun = state;
+}
+int CheckTasksGetState () {
+  return (CheckTasksRun);
+}
+
+void CheckTasksThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckTasksRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckTasks ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "T");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckJobs **/
+
+static int CheckJobsRun = FALSE;
+
+void CheckJobsSetState (int state) {
+  CheckJobsRun = state;
+}
+int CheckJobsGetState () {
+  return (CheckJobsRun);
+}
+
+void CheckJobsThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckJobsRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckJobs ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "J");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckController **/
+
+static int CheckControllerRun = FALSE;
+
+void CheckControllerSetState (int state) {
+  CheckControllerRun = state;
+}
+int CheckControllerGetState () {
+  return (CheckControllerRun);
+}
+
+void CheckControllerThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckControllerRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckController ();
+    CheckControllerOutput ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "C");
+    usleep (250000);
+  }
+}
+
+/** things related to CheckInputs **/
+
+static int CheckInputsRun = TRUE;
+
+void CheckInputsSetState (int state) {
+  CheckInputsRun = state;
+}
+int CheckInputsGetState () {
+  return (CheckInputsRun);
+}
+
+void CheckInputsThread () {
+
+  gprintInit ();  // each thread needs to init the printing system
+  while (1) {
+
+    // check for thread suspend
+    if (!CheckInputsRun) {
+      usleep (500000);
+      continue;
+    }
+
+    // one run of the task checker
+    SerialThreadLock ();
+    CheckInputs ();
+    SerialThreadUnlock ();
+    fprintf (stderr, "I");
+    usleep (250000);
+  }
+}
Index: /trunk/Ohana/src/opihi/pantasks/status.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/status.c	(revision 7951)
+++ /trunk/Ohana/src/opihi/pantasks/status.c	(revision 7952)
@@ -9,5 +9,15 @@
     gprint (GP_LOG, " Scheduler is running\n");
   }
-  if (CheckControllerStatus ()) {
+  if (CheckControllerStatus()) {
+    gprint (GP_LOG, " Controller is running\n");
+  } else {
+    gprint (GP_LOG, " Controller is stopped\n");
+  }
+  if (CheckTasksGetState()) {
+    gprint (GP_LOG, " Scheduler is running\n");
+  } else {
+    gprint (GP_LOG, " Scheduler is stopped\n");
+  }
+  if (CheckControllerGetState()) {
     gprint (GP_LOG, " Controller is running\n");
   } else {
