Index: /trunk/Ohana/src/opihi/cmd.astro/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 40375)
+++ /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 40376)
@@ -82,4 +82,5 @@
 $(SRC)/wcs.$(ARCH).o         \
 $(SRC)/imsub.$(ARCH).o		   \
+$(SRC)/jdtolst.$(ARCH).o		   \
 $(SRC)/imfit.$(ARCH).o		   \
 $(SRC)/imfit-fgauss.$(ARCH).o	   \
Index: /trunk/Ohana/src/opihi/cmd.astro/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 40375)
+++ /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 40376)
@@ -33,4 +33,5 @@
 int imfit                   PROTO((int, char **));
 int imsub                   PROTO((int, char **));
+int jdtolst                 PROTO((int, char **));
 int medianmap               PROTO((int, char **));
 int galsectors              PROTO((int, char **));
@@ -103,4 +104,5 @@
   {1, "imfit",       imfit,        "fit function"},
   {1, "imsub",       imsub,        "subtract function"},
+  {1, "jdtolst",     jdtolst,      "JD to LST conversion"},
   {1, "medianmap",   medianmap,    "small median image"},
   {1, "mkgauss",     mkgauss,      "generate a 2-D gaussian centered in image"},
Index: /trunk/Ohana/src/opihi/cmd.astro/jdtolst.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/jdtolst.c	(revision 40376)
+++ /trunk/Ohana/src/opihi/cmd.astro/jdtolst.c	(revision 40376)
@@ -0,0 +1,90 @@
+# include "astro.h"
+
+int jdtolst (int argc, char **argv) {
+
+  int N;
+  Vector *jdvec, *outvec;
+
+  int VERBOSE = FALSE;
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  char *OutputName = NULL;
+  if ((N = get_argument (argc, argv, "-output"))) {
+    remove_argument (N, &argc, argv);
+    OutputName = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (argc != 2) goto syntax;
+
+  char *long_str = get_variable ("LONGITUDE");
+  if (!long_str) {
+    gprint (GP_ERR, "please define $LONGITUDE\n");
+    FREE (OutputName);
+    return FALSE;
+  }
+  double longitude = atof (long_str);
+  if (VERBOSE) gprint (GP_ERR, "using longitude of %f\n", longitude);
+  free (long_str);
+
+  if (ISNUM(argv[1][0])) {
+
+    char *endptr;
+    double jd = strtod (argv[1], &endptr);
+    if (endptr == argv[1]) {
+      gprint (GP_ERR, "error interpretting %s as a number\n", argv[1]);
+      FREE (OutputName);
+      return FALSE;
+    }
+
+    double lst = ohana_lst (jd, longitude);
+
+    if (OutputName) {
+      set_variable (OutputName, lst);
+      FREE (OutputName);
+      return (TRUE);
+    }
+    
+    gprint (GP_ERR, "lst: %f\n", lst);
+    return (TRUE);
+  }
+
+  if (!OutputName) {
+    gprint (GP_ERR, " if (JD) is a vector, -output must be supplied\n");
+    return FALSE;
+  }
+
+  if ((jdvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) {
+    FREE (OutputName);
+    return FALSE;
+  }
+
+  if (jdvec->type != OPIHI_FLT) {
+    gprint (GP_ERR, " (JD) must be of type FLOAT\n");
+    FREE (OutputName);
+    return FALSE;
+  }
+
+  if ((outvec = SelectVector (OutputName, ANYVECTOR, TRUE)) == NULL) {
+    FREE (OutputName);
+    return FALSE;
+  }
+
+  ResetVector (outvec, OPIHI_FLT, jdvec[0].Nelements);
+
+  for (int i = 0; i < jdvec[0].Nelements; i++) {
+    double lst = ohana_lst (jdvec->elements.Flt[i], longitude);
+    outvec->elements.Flt[i] = lst;
+  }
+  FREE (OutputName);
+  return TRUE;
+
+ syntax:
+  gprint (GP_ERR, "USAGE: jdtolst (JD) [-output name]\n");
+  gprint (GP_ERR, "  (JD) may be a number or a vector.\n");
+  gprint (GP_ERR, "  if (JD) is a vector, (output) must be supplied and is used as the name of the output vector \n");
+  return (FALSE);
+}
Index: /trunk/Ohana/src/opihi/cmd.data/nnet.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/nnet.c	(revision 40375)
+++ /trunk/Ohana/src/opihi/cmd.data/nnet.c	(revision 40376)
@@ -9,5 +9,5 @@
   {1, "get",      nnet_get,      "get nnet node values"},
   {1, "read",     nnet_read,     "read nnet values from a file"},
-// {1, "write",    nnet_write,    "write nnet values to a file"},
+  {1, "write",    nnet_write,    "write nnet values to a file"},
   {1, "train",    nnet_train,    "train nnet on a set of data"},
   {1, "apply",    nnet_apply,    "apply nnet to a set of data"},
@@ -27,4 +27,5 @@
     gprint (GP_ERR, "    nnet get    (nnet) [weights] [biases] ... [weights] [biases] : get nnet weights (images) and biases (vectors)\n");
     gprint (GP_ERR, "    nnet read   (nnet) (filename) : set nnet weights and biases using a data file\n");
+    gprint (GP_ERR, "    nnet write  (nnet) (filename) : save nnet weights and biases to a data file\n");
     gprint (GP_ERR, "    nnet train  (nnet) [input] [input] ... [output] [output] ... : train nnet on data from a set of vectors\n");
     gprint (GP_ERR, "    nnet apply  (nnet) [input] [input] ... [output] [output] ... : apply nnet to input data and generate output\n");
Index: /trunk/Ohana/src/opihi/cmd.data/nnet_commands.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/nnet_commands.c	(revision 40375)
+++ /trunk/Ohana/src/opihi/cmd.data/nnet_commands.c	(revision 40376)
@@ -258,4 +258,55 @@
 }
 
+int nnet_write (int argc, char **argv) {
+
+  if (argc < 3) {
+    gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n");
+    return FALSE;
+  }
+
+  Nnet *nnet = FindNnet (argv[1]);
+  if (nnet == NULL) {
+    gprint (GP_ERR, "nnet %s not found, create it first\n", argv[1]);
+    return FALSE;
+  }
+
+  // open the file and read the number of layers
+  FILE *f = fopen (argv[2], "w");
+  if (f == NULL) {
+    gprint (GP_ERR, "USAGE: nnet write (nnet) (filename) : save nnet weights and biases to a file\n");
+    gprint (GP_ERR, "file %s could not be opened\n", argv[2]);
+    return FALSE;
+  }
+
+  // write the number of layers
+  // NLAYER 3
+  fprintf (f, "NLAYER %d\n", nnet->Nlayer);
+
+  // write the number of nodes for each layer
+  // LAYERS 2 4 2
+  fprintf (f, "LAYERS");
+  for (int i = 0; i < nnet->Nlayer; i++) {
+    fprintf (f, " %d", nnet->Nnodes[i]);
+  }
+  fprintf (f, "\n");
+
+  // read the weights and biases from the data file
+  for (int L = 1; L < nnet[0].Nlayer; L++) {
+    
+    fprintf (f, "LAYER %d NX %d NY %d\n", L - 1, nnet->Nnodes[L-1], nnet->Nnodes[L]);
+
+    for (int j = 0; j < nnet->Nnodes[L]; j++) {
+      for (int i = 0; i < nnet->Nnodes[L-1]; i++) {
+	int k = i + j*nnet[0].Nnodes[L-1];
+	fprintf (f, "%f ", nnet[0].weight[L][k]);
+      }
+      fprintf (f, "%f\n", nnet[0].biases[L][j]);
+    }
+  }
+  fclose (f);
+
+  return TRUE;
+}
+
 int nnet_get (int argc, char **argv) {
 
Index: /trunk/Ohana/src/opihi/cmd.data/test/nnet.sh
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/test/nnet.sh	(revision 40375)
+++ /trunk/Ohana/src/opihi/cmd.data/test/nnet.sh	(revision 40376)
@@ -1,2 +1,48 @@
+
+macro test.io
+
+  nnet create t1 2 3 2
+  
+  # biases:
+  vlist v1 -0.2 0.0 0.2
+  vlist v2 -0.3 0.3
+
+  # weights
+  mcreate m1 2 3
+  m1[0][0] =  0.2
+  m1[1][0] = -0.2
+  m1[0][1] = -0.6
+  m1[1][1] =  0.5
+  m1[0][2] = -0.2
+  m1[1][2] =  0.2
+
+  mcreate m2 3 2
+  m2[0][0] = -0.6
+  m2[1][0] = -0.4
+  m2[2][0] = -0.5
+
+  m2[0][1] = -0.2
+  m2[1][1] = -0.5
+  m2[2][1] =  0.1
+
+  # set weights and biases
+  nnet set t1 m1 v1 m2 v2
+
+  nnet write t1 test.nnet.dat
+  nnet read t2 test.nnet.dat
+
+  nnet get t2 M1 V1 M2 V2
+
+  set dM1 = M1 - m1
+  set dM2 = M2 - m2
+  set dV1 = V1 - v1
+  set dV2 = V2 - v2
+
+  stat dM1
+  stat dM2
+ 
+  vstat dV1
+  vstat dV2
+end
 
 macro test.python
Index: /trunk/Ohana/src/opihi/include/data.h
===================================================================
--- /trunk/Ohana/src/opihi/include/data.h	(revision 40375)
+++ /trunk/Ohana/src/opihi/include/data.h	(revision 40376)
@@ -278,4 +278,5 @@
 int nnet_get (int argc, char **argv);
 int nnet_read (int argc, char **argv);
+int nnet_write (int argc, char **argv);
 int nnet_print (int argc, char **argv);
 
