Index: trunk/Ohana/src/relphot/Makefile
===================================================================
--- trunk/Ohana/src/relphot/Makefile	(revision 4796)
+++ trunk/Ohana/src/relphot/Makefile	(revision 4805)
@@ -41,5 +41,4 @@
 $(SRC)/plotstuff.$(ARCH).o	 \
 $(SRC)/misc.$(ARCH).o		 \
-$(SRC)/time.$(ARCH).o		 \
 $(SRC)/reload_catalogs.$(ARCH).o \
 $(SRC)/free_catalogs.$(ARCH).o   \
Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 4796)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 4805)
@@ -88,5 +88,5 @@
 
 int TimeSelect;
-unsigned int TSTART, TSTOP;
+time_t TSTART, TSTOP;
 
 # ifdef GRID_V1
@@ -98,115 +98,98 @@
 # endif
 
-/***** prototypes ****/
-int main (int argc, char **argv);
-Catalog *load_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion);
-GSCRegion *load_images (char *seed, int *nregion, GSCRegion *fullregion);
-GSCRegion *name_region (char *name, int *Nregions);
-GSCRegion *find_regions (Image *image, int Nimage, int *Nregions, GSCRegion *fullregion);
-GSCRegion *get_regions (double minRa, double maxRa, double minDec, double maxDec, int *Nregions);
-Image *find_images (GSCRegion *region, int Nregion, int *Nimages, int **LineNum);
-double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
-int edge_check (double *x1, double *y1, double *x2, double *y2);
-int corner_check (double *x1, double *y1, double *x2, double *y2);
-int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string);
-int bcatalog (Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion);
-int findMosaics (Catalog *catalog, int Ncatalog);
-int setMmos (Catalog *catalog, int Poor);
-int setMrel (Catalog *catalog, int Ncatalog);
-int setrefcode (Image *image, int Nimage); 
-int args (int argc, char **argv);
-short getMgrid (int meas, int cat);
-short getMcal (int meas, int cat);
-short getMmos (int meas, int cat);
-short getMrel (Catalog *catalog, int meas, int cat);
-void initGrid (int dX, int dY);
-void initGridBins (Catalog *catalog, int Ncatalog);
-void initMosaics (Image *image, int Nimage);
-void initMosaicGrid (Image *image, int Nimage);
-void initMosaicBins (Catalog *catalog, int Ncatalog);
-void initMrel (Catalog *catalog, int Ncatalog);
-void initialize (int argc, char **argv);
-void ConfigInit (int *argc, char **argv);
-void mark_images (Image *image, int Nimage, Image *timage, int Ntimage);
-void setMgrid (Catalog *catalog);
-void dumpGrid ();
-void initImages (Image *input, int N);
-void initImageBins (Catalog *catalog, int Ncatalog);
-void findImages (Catalog *catalog, int Ncatalog);
-void matchImage (Catalog *catalog, int meas, int cat);
-void matchMosaics (Catalog *catalog, int meas, int cat);
-void setMcal (Catalog *catalog, int Poor);
-void clean_images ();
-void clean_stars (Catalog *catalog, int Ncatalog);
-void reload_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion);
-void free_catalogs (Catalog *catalog, int Ncatalog);
-void set_ZP (double ZERO);
-char *GetPhotnamebyCode (PhotCodeData *photcodes, int code);
-StatType statsStarS (Catalog *catalog, int Ncatalog);
-StatType statsStarX (Catalog *catalog, int Ncatalog);
-StatType statsStarN (Catalog *catalog, int Ncatalog);
-StatType statsImageN (Catalog *catalog);
-StatType statsImageX (Catalog *catalog);
-StatType statsImageM (Catalog *catalog);
-void plot_scatter (Catalog *catalog, int Ncatalog);
-void plot_defaults (Graphdata *graphdata);
-void plot_list (Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *file);
-void plot_stars (Catalog *catalog, int Ncatalog);
-void plot_chisq (Catalog *catalog, int Ncatalog);
-void plot_star_coords (Catalog *catalog, int Ncatalog);
-void plot_grid (Catalog *catalog);
-void dump_grid (); 
-int *SelectRefMosaic (Mosaic **refmosaic, int *Nimage);
-Image *getimage (int N);
-void InterpolateGrid (float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords);
-void plot_mosaic_fields (Catalog *catalog);
-void plot_mosaics ();
-void plot_images ();
-void wimages ();
-void clean_mosaics ();
-void freeMosaicBins (int Ncatalog);
-void freeGridBins (int Ncatalog);
-void clean_measures (Catalog *catalog, int Ncatalog, int final);
-void global_stats (Catalog *catalog, int Ncatalog);
-StatType statsImagedM (Catalog *catalog);
-StatType statsMosaicdM (Catalog *catalog);
-StatType statsMosaicM (Catalog *catalog);
-StatType statsMosaicN (Catalog *catalog);
-StatType statsMosaicX (Catalog *catalog);
-Coords *getCoords (int meas, int cat);
-int setExclusions (Catalog *catalog, int Ncatalog);
-void freeImageBins (int Ncatalog);
-void sortA (double *X, int N);
-void sortB (double *X, double *Y, int N);
-void sortC (double *X, double *Y, double *F1, double *F2, int N);
-void sortD (double *X, double *Y, double *Z, int N);
-void initstats (char *mode);
-int liststats (double *value, double *dvalue, int N, StatType *stats);
-
-int dms_to_ddd (double *Value, char *string);
-int str_to_radec (double *ra, double *dec, char *str1, char *str2);
-int chk_time (char *line);
-double sec_to_jd (unsigned long second);
-unsigned long int jd_to_sec (double jd);
-char *sec_to_date (unsigned long second);
-unsigned long date_to_sec (char *date);
-  
-int str_to_time (char *line, unsigned int *second);
-int str_to_dtime (char *line, double *second);
-int Fseek (FILE *f, long offset, int whence);
-void GetConfig (char *config, char *field, char *format, int N, void *ptr);
-void skip_measurements (Catalog *catalog, int pass);
-Image *getimages (int *N);
-
-void setMrelFinal (Catalog *catalog);
-void skip_measurements (Catalog *catalog, int pass);
-GSCRegion *get_regions (double minRa, double maxRa, double minDec, double maxDec, int *Nregions);
-int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string);
-GSCRegion *find_regions (Image *image, int Nimage, int *Nregions, GSCRegion *fullregion);
-void getfullregion (Image *image, int Nimage, GSCRegion *fullregion);
-void setMcalFinal (Image *image, int Nimage);
-int gcatalog (Catalog *catalog, int FINAL);
-void write_coords (Header *header, Coords *coords);
-void wcatalog (Catalog *catalog);
-int setMrelOutput (Catalog *catalog, int Ncatalog, int mark);
-int setMcalOutput (Catalog *catalog, int Ncatalog);
+/*** relphot prototypes ***/
+void          ConfigInit          PROTO((int *argc, char **argv));
+int           Fseek               PROTO((FILE *f, long offset, int whence));
+void          GetConfig           PROTO((char *config, char *field, char *format, int N, void *ptr));
+char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
+void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
+int          *SelectRefMosaic     PROTO((Mosaic **refmosaic, int *Nimage));
+int           args                PROTO((int argc, char **argv));
+int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion));
+void          clean_images        PROTO(());
+void          clean_measures      PROTO((Catalog *catalog, int Ncatalog, int final));
+void          clean_mosaics       PROTO(());
+void          clean_stars         PROTO((Catalog *catalog, int Ncatalog));
+int           corner_check        PROTO((double *x1, double *y1, double *x2, double *y2));
+void          dumpGrid            PROTO(());
+void          dump_grid           PROTO(()); 
+int           edge_check          PROTO((double *x1, double *y1, double *x2, double *y2));
+void          findImages          PROTO((Catalog *catalog, int Ncatalog));
+int           findMosaics         PROTO((Catalog *catalog, int Ncatalog));
+Image        *find_images         PROTO((GSCRegion *region, int Nregion, int *Nimages, int **LineNum));
+GSCRegion    *find_regions        PROTO((Image *image, int Nimage, int *Nregions, GSCRegion *fullregion));
+void          freeGridBins        PROTO((int Ncatalog));
+void          freeImageBins       PROTO((int Ncatalog));
+void          freeMosaicBins      PROTO((int Ncatalog));
+void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
+int           gcatalog            PROTO((Catalog *catalog, int FINAL));
+Coords       *getCoords           PROTO((int meas, int cat));
+short         getMcal             PROTO((int meas, int cat));
+short         getMgrid            PROTO((int meas, int cat));
+short         getMmos             PROTO((int meas, int cat));
+short         getMrel             PROTO((Catalog *catalog, int meas, int cat));
+GSCRegion    *get_regions         PROTO((double minRa, double maxRa, double minDec, double maxDec, int *Nregions));
+void          getfullregion       PROTO((Image *image, int Nimage, GSCRegion *fullregion));
+Image        *getimage            PROTO((int N));
+Image        *getimages           PROTO((int *N));
+void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
+void          initGrid            PROTO((int dX, int dY));
+void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
+void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
+void          initImages          PROTO((Image *input, int N));
+void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
+void          initMosaicGrid      PROTO((Image *image, int Nimage));
+void          initMosaics         PROTO((Image *image, int Nimage));
+void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
+void          initialize          PROTO((int argc, char **argv));
+void          initstats           PROTO((char *mode));
+int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
+Catalog      *load_catalogs       PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
+GSCRegion    *load_images         PROTO((char *seed, int *nregion, GSCRegion *fullregion));
+int           main                PROTO((int argc, char **argv));
+void          mark_images         PROTO((Image *image, int Nimage, Image *timage, int Ntimage));
+void          matchImage          PROTO((Catalog *catalog, int meas, int cat));
+void          matchMosaics        PROTO((Catalog *catalog, int meas, int cat));
+GSCRegion    *name_region         PROTO((char *name, int *Nregions));
+double        opening_angle       PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
+void          plot_chisq          PROTO((Catalog *catalog, int Ncatalog));
+void          plot_defaults       PROTO((Graphdata *graphdata));
+void          plot_grid           PROTO((Catalog *catalog));
+void          plot_images         PROTO(());
+void          plot_list           PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *file));
+void          plot_mosaic_fields  PROTO((Catalog *catalog));
+void          plot_mosaics        PROTO(());
+void          plot_scatter        PROTO((Catalog *catalog, int Ncatalog));
+void          plot_star_coords    PROTO((Catalog *catalog, int Ncatalog));
+void          plot_stars          PROTO((Catalog *catalog, int Ncatalog));
+void          reload_catalogs     PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
+int           setExclusions       PROTO((Catalog *catalog, int Ncatalog));
+void          setMcal             PROTO((Catalog *catalog, int Poor));
+void          setMcalFinal        PROTO((Image *image, int Nimage));
+int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog));
+void          setMgrid            PROTO((Catalog *catalog));
+int           setMmos             PROTO((Catalog *catalog, int Poor));
+int           setMrel             PROTO((Catalog *catalog, int Ncatalog));
+void          setMrelFinal        PROTO((Catalog *catalog));
+int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, int mark));
+void          set_ZP              PROTO((double ZERO));
+int           setrefcode          PROTO((Image *image, int Nimage)); 
+void          skip_measurements   PROTO((Catalog *catalog, int pass));
+void          sortA               PROTO((double *X, int N));
+void          sortB               PROTO((double *X, double *Y, int N));
+void          sortC               PROTO((double *X, double *Y, double *F1, double *F2, int N));
+void          sortD               PROTO((double *X, double *Y, double *Z, int N));
+StatType      statsImageM         PROTO((Catalog *catalog));
+StatType      statsImageN         PROTO((Catalog *catalog));
+StatType      statsImageX         PROTO((Catalog *catalog));
+StatType      statsImagedM        PROTO((Catalog *catalog));
+StatType      statsMosaicM        PROTO((Catalog *catalog));
+StatType      statsMosaicN        PROTO((Catalog *catalog));
+StatType      statsMosaicX        PROTO((Catalog *catalog));
+StatType      statsMosaicdM       PROTO((Catalog *catalog));
+StatType      statsStarN          PROTO((Catalog *catalog, int Ncatalog));
+StatType      statsStarS          PROTO((Catalog *catalog, int Ncatalog));
+StatType      statsStarX          PROTO((Catalog *catalog, int Ncatalog));
+void          wcatalog            PROTO((Catalog *catalog));
+void          wimages             PROTO(());
+void          write_coords        PROTO((Header *header, Coords *coords));
Index: trunk/Ohana/src/relphot/src/get_regions.c
===================================================================
--- trunk/Ohana/src/relphot/src/get_regions.c	(revision 4796)
+++ trunk/Ohana/src/relphot/src/get_regions.c	(revision 4805)
@@ -166,43 +166,2 @@
   
 }
-
-/**********/
-int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string) {
-  
-  int flag_d0, flag_d1, flag_h0, flag_h1;
-  double tmp;
-  
-  *d0 = *h0 = *d1 = *h1 = 0;
-
-  flag_h0 = dparse (h0, 1, string);
-  flag_h1 = dparse (h1, 4, string);
-  flag_d0 = dparse (d0, 7, string);
-  flag_d1 = dparse (d1, 9, string);
-  *h0 *= flag_h0;
-  *h1 *= flag_h1;
-  *d0 *= flag_d0;
-  *d1 *= flag_d1;
-
-  dparse (&tmp, 2, string);
-  *h0 += tmp/60.0;
-  dparse (&tmp, 3, string);
-  *h0 += tmp/3600.0;
-  
-  dparse (&tmp, 5, string);
-  *h1 += tmp/60.0;
-  dparse (&tmp, 6, string);
-  *h1 += tmp/3600.0;
-  
-  dparse (&tmp, 8, string);
-  *d0 += tmp/60.0;
-
-  dparse (&tmp, 10, string);
-  *d1 += tmp/60.0;
-
-  *h0 *= 15*flag_h0;
-  *h1 *= 15*flag_h1;
-  *d0 *= flag_d0;
-  *d1 *= flag_d1;
-
-  return (TRUE);
-}
Index: trunk/Ohana/src/relphot/src/misc.c
===================================================================
--- trunk/Ohana/src/relphot/src/misc.c	(revision 4796)
+++ trunk/Ohana/src/relphot/src/misc.c	(revision 4805)
@@ -182,2 +182,20 @@
 }
 
+/* fseek with timeout - 0.5 sec */
+int Fseek (FILE *f, long offset, int whence) {
+
+  int status;
+
+  status = fseek (f, offset, whence);
+  if (status == -1) {
+    int k;
+    /* fprintf (stderr, "problem seeking position: %d\n", errno); */
+    for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
+    if (status == -1) {
+      /* fprintf (stderr, "ERROR: serious problem seeking position: %d\n", errno); */
+      /* clear lock at this point? */
+      return (0);
+    }
+  }
+  return (1);
+}
Index: trunk/Ohana/src/relphot/src/time.c
===================================================================
--- trunk/Ohana/src/relphot/src/time.c	(revision 4796)
+++ trunk/Ohana/src/relphot/src/time.c	(revision 4805)
@@ -1,3 +1,5 @@
 # include "relphot.h"
+
+enum {TIME_NONE, TIME_DATE, TIME_DAYS, TIME_HOURS, TIME_MINUTES, TIME_SECONDS, TIME_JD, TIME_MJD};
 
 /***** convert [-]00:00:00 to 0.0000 ****/
@@ -86,11 +88,4 @@
 }
 
-# define FORMAT_DAYS    1
-# define FORMAT_HOURS   2
-# define FORMAT_MINUTES 3
-# define FORMAT_SECONDS 4
-# define FORMAT_JD      5
-# define FORMAT_DATE    6
-
 /**********/
 int chk_time (char *line) {
@@ -102,22 +97,24 @@
   p1 = line;
   tmp = strtod (p1, &p2);
+  mode = TIME_DATE;
   if (p2 == p1 + strlen (p1) - 1) {
     if (*p2 == 'd') {
-      mode = FORMAT_DAYS;
+      mode = TIME_DAYS;
     }
     if (*p2 == 'h') {
-      mode = FORMAT_HOURS;
+      mode = TIME_HOURS;
     }
     if (*p2 == 'm') {
-      mode = FORMAT_MINUTES;
+      mode = TIME_MINUTES;
     }
     if (*p2 == 's') {
-      mode = FORMAT_SECONDS;
+      mode = TIME_SECONDS;
     }
     if (*p2 == 'j') {
-      mode = FORMAT_JD;
-    }
-  } else { 
-    mode = FORMAT_DATE;
+      mode = TIME_JD;
+    }
+    if (*p2 == 'J') {
+      mode = TIME_MJD;
+    }
   }
   return (mode);
@@ -125,8 +122,11 @@
 
 /**********/
-int str_to_time (char *line, unsigned int *second) {
-  
+int str_to_time (char *line, time_t *second) {
+  
+  char *tmpline;
+  struct tm *gmt;
   struct timeval now;
   double jd;
+  time_t tsec;
 
   if (!strcasecmp (line, "NOW")) {
@@ -136,8 +136,18 @@
   }
     
-  if (!strcasecmp (line, "TODAY")) {
+  if (!strncasecmp (line, "TODAY", 5)) {
     gettimeofday (&now, (struct timezone *) NULL);
-    *second = 86400 * ((int)(now.tv_sec / 86400));
-    return (TRUE);
+    if (line[5]) { /* line has extra data (ie, hh:mm:ss) */
+      tsec = now.tv_sec;
+      ALLOCATE (tmpline, char, 64);
+      gmt   = gmtime (&tsec);
+      sprintf (tmpline, "%04d/%02d/%02d,%s", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, &line[6]);
+      *second = date_to_sec (tmpline);
+      free (tmpline);
+      return (TRUE);
+    } else {
+      *second = 86400 * ((int)(now.tv_sec / 86400));
+      return (TRUE); 
+    }
   }
     
@@ -145,26 +155,31 @@
   case 0:
     return (FALSE);
-  case FORMAT_DAYS:
+  case TIME_DATE:
+    *second = date_to_sec (line);
+    return (TRUE);
+  case TIME_DAYS:
     *second = strtod (line, 0) * 86400.0;
     return (TRUE);
-  case FORMAT_HOURS:
+  case TIME_HOURS:
     *second = strtod (line, 0) * 3600.0;
     return (TRUE);
-  case FORMAT_MINUTES:
+  case TIME_MINUTES:
     *second = strtod (line, 0) * 60.0;
     return (TRUE);
-  case FORMAT_SECONDS:
+  case TIME_SECONDS:
     *second = strtod (line, 0);
     return (TRUE);
-  case FORMAT_JD:
+  case TIME_JD:
     jd = strtod (line, 0);
     *second = jd_to_sec (jd);
     return (TRUE);
-  case FORMAT_DATE:
-    *second = date_to_sec (line);
+  case TIME_MJD:
+    jd = strtod (line, 0);
+    *second = mjd_to_sec (jd);
     return (TRUE);
   }
   return (FALSE);
 }
+
 
 /**********/
@@ -173,17 +188,18 @@
   switch (chk_time (line)) {
   case 0:
-  case FORMAT_JD:
-  case FORMAT_DATE:
+  case TIME_JD:
+  case TIME_MJD:
+  case TIME_DATE:
     return (FALSE);
-  case FORMAT_DAYS:
+  case TIME_DAYS:
     *second = strtod (line, 0) * 86400.0;
     return (TRUE);
-  case FORMAT_HOURS:
+  case TIME_HOURS:
     *second = strtod (line, 0) * 3600.0;
     return (TRUE);
-  case FORMAT_MINUTES:
+  case TIME_MINUTES:
     *second = strtod (line, 0) * 60.0;
     return (TRUE);
-  case FORMAT_SECONDS:
+  case TIME_SECONDS:
     *second = strtod (line, 0);
     return (TRUE);
@@ -193,5 +209,5 @@
 
 /**********/
-double sec_to_jd (unsigned long second) {
+double sec_to_jd (time_t second) {
 
   double jd;
@@ -202,7 +218,7 @@
 
 /**********/
-unsigned long int jd_to_sec (double jd) {
-
-  unsigned long int second;
+time_t jd_to_sec (double jd) {
+
+  time_t second;
 
   second = (jd - 2440587.5)*86400;
@@ -211,5 +227,23 @@
 
 /**********/
-char *sec_to_date (unsigned long second) {
+double sec_to_mjd (time_t second) {
+
+  double mjd;
+  
+  mjd = second/86400.0 + 40587.0;
+  return (mjd);
+}
+
+/**********/
+time_t mjd_to_sec (double mjd) {
+
+  time_t second;
+
+  second = (mjd - 40587.0)*86400;
+  return (second);
+}
+
+/**********/
+char *sec_to_date (time_t second) {
   
   struct tm *gmt;
@@ -218,5 +252,5 @@
   ALLOCATE (line, char, 64);
   gmt   = gmtime (&second);
-  sprintf (line, "%4d/%02d/%02d,%02d:%02d:%02d", 1900+gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
+  sprintf (line, "%04d/%02d/%02d,%02d:%02d:%02d", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
   return (line);
 
@@ -224,7 +258,7 @@
 
 /***** date in format yyyy/mm/dd,hh:mm:ss *****/
-unsigned long date_to_sec (char *date) {
-  
-  unsigned long second;
+time_t date_to_sec (char *date) {
+  
+  time_t second;
   double tmp, jd;
   struct tm now;
@@ -283,31 +317,75 @@
 }
 
+/***** short date in format yymmdd *****/
+time_t short_date_to_sec (char *date) {
+  
+  time_t second;
+  double jd;
+  struct tm now;
+  
+  bzero (&now, sizeof(now));
+
+  sscanf (date, "%2d%2d%2d", &now.tm_year, &now.tm_mon, &now.tm_mday);
+
+  if (now.tm_year >   51) now.tm_year +=   0;
+  if (now.tm_year <   50) now.tm_year += 100;
+  now.tm_mon --; /* tm_mon runs from 0 - 11 */
+
+  jd = now.tm_mday - 32075 + (int)(1461*(1900 + now.tm_year + 4800 + (int)(((now.tm_mon+1)-14)/12))/4)
+    + (int)(367*((now.tm_mon+1) - 2 - (int)(((now.tm_mon+1) - 14)/12)*12)/12)
+    - (int)(3*(int)((1900 + now.tm_year + 4900 + (int)(((now.tm_mon+1) - 14)/12))/100)/4) - 0.5;
+  
+  second = (jd - 2440587.5)*86400 + 3600.0*now.tm_hour + now.tm_min*60.0 + now.tm_sec;
+
+  return (second);
+}
+
+/**********/
+int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string) {
+  
+  int flag_d0, flag_d1, flag_h0, flag_h1;
+  double tmp;
+  
+  *d0 = *h0 = *d1 = *h1 = 0;
+
+  flag_h0 = dparse (h0, 1, string);
+  flag_h1 = dparse (h1, 4, string);
+  flag_d0 = dparse (d0, 7, string);
+  flag_d1 = dparse (d1, 9, string);
+  *h0 *= flag_h0;
+  *h1 *= flag_h1;
+  *d0 *= flag_d0;
+  *d1 *= flag_d1;
+
+  dparse (&tmp, 2, string);
+  *h0 += tmp/60.0;
+  dparse (&tmp, 3, string);
+  *h0 += tmp/3600.0;
+  
+  dparse (&tmp, 5, string);
+  *h1 += tmp/60.0;
+  dparse (&tmp, 6, string);
+  *h1 += tmp/3600.0;
+  
+  dparse (&tmp, 8, string);
+  *d0 += tmp/60.0;
+
+  dparse (&tmp, 10, string);
+  *d1 += tmp/60.0;
+
+  *h0 *= 15*flag_h0;
+  *h1 *= 15*flag_h1;
+  *d0 *= flag_d0;
+  *d1 *= flag_d1;
+
+  return (TRUE);
+}
 
 /* times may be in forms as:
-   20040200450s (N seconds since 1970.0)
+ * 20040200450s (N seconds since 1970.0)
    2440900.232j (julian date)
-   99/02/23,03:22:18 (date string)
-   (separators may be anything except space, +, -)
-   99:02:15:12:23:30
-   99:02:15:12h23m30s
-   */
-
-
-/* fseek with timeout - 0.5 sec */
-int Fseek (FILE *f, long offset, int whence) {
-
-  int status;
-
-  status = fseek (f, offset, whence);
-  if (status == -1) {
-    int k;
-    /* fprintf (stderr, "problem seeking position: %d\n", errno); */
-    for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
-    if (status == -1) {
-      /* fprintf (stderr, "ERROR: serious problem seeking position: %d\n", errno); */
-      /* clear lock at this point? */
-      return (0);
-    }
-  }
-  return (1);
-}
+ * 99/02/23,03:22:18 (date string)
+ * (separators may be anything except space, +, -)
+ * 99:02:15:12:23:30
+ * 99:02:15:12h23m30s
+ */
