IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 16, 2005, 6:41:16 PM (21 years ago)
Author:
eugene
Message:

cleaning include files, merging time/coord functions in libohana

Location:
trunk/Ohana/src/relphot
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/relphot/Makefile

    r2833 r4805  
    4141$(SRC)/plotstuff.$(ARCH).o       \
    4242$(SRC)/misc.$(ARCH).o            \
    43 $(SRC)/time.$(ARCH).o            \
    4443$(SRC)/reload_catalogs.$(ARCH).o \
    4544$(SRC)/free_catalogs.$(ARCH).o   \
  • trunk/Ohana/src/relphot/include/relphot.h

    r4796 r4805  
    8888
    8989int TimeSelect;
    90 unsigned int TSTART, TSTOP;
     90time_t TSTART, TSTOP;
    9191
    9292# ifdef GRID_V1
     
    9898# endif
    9999
    100 /***** prototypes ****/
    101 int main (int argc, char **argv);
    102 Catalog *load_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion);
    103 GSCRegion *load_images (char *seed, int *nregion, GSCRegion *fullregion);
    104 GSCRegion *name_region (char *name, int *Nregions);
    105 GSCRegion *find_regions (Image *image, int Nimage, int *Nregions, GSCRegion *fullregion);
    106 GSCRegion *get_regions (double minRa, double maxRa, double minDec, double maxDec, int *Nregions);
    107 Image *find_images (GSCRegion *region, int Nregion, int *Nimages, int **LineNum);
    108 double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
    109 int edge_check (double *x1, double *y1, double *x2, double *y2);
    110 int corner_check (double *x1, double *y1, double *x2, double *y2);
    111 int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string);
    112 int bcatalog (Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion);
    113 int findMosaics (Catalog *catalog, int Ncatalog);
    114 int setMmos (Catalog *catalog, int Poor);
    115 int setMrel (Catalog *catalog, int Ncatalog);
    116 int setrefcode (Image *image, int Nimage);
    117 int args (int argc, char **argv);
    118 short getMgrid (int meas, int cat);
    119 short getMcal (int meas, int cat);
    120 short getMmos (int meas, int cat);
    121 short getMrel (Catalog *catalog, int meas, int cat);
    122 void initGrid (int dX, int dY);
    123 void initGridBins (Catalog *catalog, int Ncatalog);
    124 void initMosaics (Image *image, int Nimage);
    125 void initMosaicGrid (Image *image, int Nimage);
    126 void initMosaicBins (Catalog *catalog, int Ncatalog);
    127 void initMrel (Catalog *catalog, int Ncatalog);
    128 void initialize (int argc, char **argv);
    129 void ConfigInit (int *argc, char **argv);
    130 void mark_images (Image *image, int Nimage, Image *timage, int Ntimage);
    131 void setMgrid (Catalog *catalog);
    132 void dumpGrid ();
    133 void initImages (Image *input, int N);
    134 void initImageBins (Catalog *catalog, int Ncatalog);
    135 void findImages (Catalog *catalog, int Ncatalog);
    136 void matchImage (Catalog *catalog, int meas, int cat);
    137 void matchMosaics (Catalog *catalog, int meas, int cat);
    138 void setMcal (Catalog *catalog, int Poor);
    139 void clean_images ();
    140 void clean_stars (Catalog *catalog, int Ncatalog);
    141 void reload_catalogs (GSCRegion *region, int Nregion, GSCRegion *fullregion);
    142 void free_catalogs (Catalog *catalog, int Ncatalog);
    143 void set_ZP (double ZERO);
    144 char *GetPhotnamebyCode (PhotCodeData *photcodes, int code);
    145 StatType statsStarS (Catalog *catalog, int Ncatalog);
    146 StatType statsStarX (Catalog *catalog, int Ncatalog);
    147 StatType statsStarN (Catalog *catalog, int Ncatalog);
    148 StatType statsImageN (Catalog *catalog);
    149 StatType statsImageX (Catalog *catalog);
    150 StatType statsImageM (Catalog *catalog);
    151 void plot_scatter (Catalog *catalog, int Ncatalog);
    152 void plot_defaults (Graphdata *graphdata);
    153 void plot_list (Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *file);
    154 void plot_stars (Catalog *catalog, int Ncatalog);
    155 void plot_chisq (Catalog *catalog, int Ncatalog);
    156 void plot_star_coords (Catalog *catalog, int Ncatalog);
    157 void plot_grid (Catalog *catalog);
    158 void dump_grid ();
    159 int *SelectRefMosaic (Mosaic **refmosaic, int *Nimage);
    160 Image *getimage (int N);
    161 void InterpolateGrid (float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords);
    162 void plot_mosaic_fields (Catalog *catalog);
    163 void plot_mosaics ();
    164 void plot_images ();
    165 void wimages ();
    166 void clean_mosaics ();
    167 void freeMosaicBins (int Ncatalog);
    168 void freeGridBins (int Ncatalog);
    169 void clean_measures (Catalog *catalog, int Ncatalog, int final);
    170 void global_stats (Catalog *catalog, int Ncatalog);
    171 StatType statsImagedM (Catalog *catalog);
    172 StatType statsMosaicdM (Catalog *catalog);
    173 StatType statsMosaicM (Catalog *catalog);
    174 StatType statsMosaicN (Catalog *catalog);
    175 StatType statsMosaicX (Catalog *catalog);
    176 Coords *getCoords (int meas, int cat);
    177 int setExclusions (Catalog *catalog, int Ncatalog);
    178 void freeImageBins (int Ncatalog);
    179 void sortA (double *X, int N);
    180 void sortB (double *X, double *Y, int N);
    181 void sortC (double *X, double *Y, double *F1, double *F2, int N);
    182 void sortD (double *X, double *Y, double *Z, int N);
    183 void initstats (char *mode);
    184 int liststats (double *value, double *dvalue, int N, StatType *stats);
    185 
    186 int dms_to_ddd (double *Value, char *string);
    187 int str_to_radec (double *ra, double *dec, char *str1, char *str2);
    188 int chk_time (char *line);
    189 double sec_to_jd (unsigned long second);
    190 unsigned long int jd_to_sec (double jd);
    191 char *sec_to_date (unsigned long second);
    192 unsigned long date_to_sec (char *date);
    193  
    194 int str_to_time (char *line, unsigned int *second);
    195 int str_to_dtime (char *line, double *second);
    196 int Fseek (FILE *f, long offset, int whence);
    197 void GetConfig (char *config, char *field, char *format, int N, void *ptr);
    198 void skip_measurements (Catalog *catalog, int pass);
    199 Image *getimages (int *N);
    200 
    201 void setMrelFinal (Catalog *catalog);
    202 void skip_measurements (Catalog *catalog, int pass);
    203 GSCRegion *get_regions (double minRa, double maxRa, double minDec, double maxDec, int *Nregions);
    204 int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string);
    205 GSCRegion *find_regions (Image *image, int Nimage, int *Nregions, GSCRegion *fullregion);
    206 void getfullregion (Image *image, int Nimage, GSCRegion *fullregion);
    207 void setMcalFinal (Image *image, int Nimage);
    208 int gcatalog (Catalog *catalog, int FINAL);
    209 void write_coords (Header *header, Coords *coords);
    210 void wcatalog (Catalog *catalog);
    211 int setMrelOutput (Catalog *catalog, int Ncatalog, int mark);
    212 int setMcalOutput (Catalog *catalog, int Ncatalog);
     100/*** relphot prototypes ***/
     101void          ConfigInit          PROTO((int *argc, char **argv));
     102int           Fseek               PROTO((FILE *f, long offset, int whence));
     103void          GetConfig           PROTO((char *config, char *field, char *format, int N, void *ptr));
     104char         *GetPhotnamebyCode   PROTO((PhotCodeData *photcodes, int code));
     105void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
     106int          *SelectRefMosaic     PROTO((Mosaic **refmosaic, int *Nimage));
     107int           args                PROTO((int argc, char **argv));
     108int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog, GSCRegion *fullregion));
     109void          clean_images        PROTO(());
     110void          clean_measures      PROTO((Catalog *catalog, int Ncatalog, int final));
     111void          clean_mosaics       PROTO(());
     112void          clean_stars         PROTO((Catalog *catalog, int Ncatalog));
     113int           corner_check        PROTO((double *x1, double *y1, double *x2, double *y2));
     114void          dumpGrid            PROTO(());
     115void          dump_grid           PROTO(());
     116int           edge_check          PROTO((double *x1, double *y1, double *x2, double *y2));
     117void          findImages          PROTO((Catalog *catalog, int Ncatalog));
     118int           findMosaics         PROTO((Catalog *catalog, int Ncatalog));
     119Image        *find_images         PROTO((GSCRegion *region, int Nregion, int *Nimages, int **LineNum));
     120GSCRegion    *find_regions        PROTO((Image *image, int Nimage, int *Nregions, GSCRegion *fullregion));
     121void          freeGridBins        PROTO((int Ncatalog));
     122void          freeImageBins       PROTO((int Ncatalog));
     123void          freeMosaicBins      PROTO((int Ncatalog));
     124void          free_catalogs       PROTO((Catalog *catalog, int Ncatalog));
     125int           gcatalog            PROTO((Catalog *catalog, int FINAL));
     126Coords       *getCoords           PROTO((int meas, int cat));
     127short         getMcal             PROTO((int meas, int cat));
     128short         getMgrid            PROTO((int meas, int cat));
     129short         getMmos             PROTO((int meas, int cat));
     130short         getMrel             PROTO((Catalog *catalog, int meas, int cat));
     131GSCRegion    *get_regions         PROTO((double minRa, double maxRa, double minDec, double maxDec, int *Nregions));
     132void          getfullregion       PROTO((Image *image, int Nimage, GSCRegion *fullregion));
     133Image        *getimage            PROTO((int N));
     134Image        *getimages           PROTO((int *N));
     135void          global_stats        PROTO((Catalog *catalog, int Ncatalog));
     136void          initGrid            PROTO((int dX, int dY));
     137void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
     138void          initImageBins       PROTO((Catalog *catalog, int Ncatalog));
     139void          initImages          PROTO((Image *input, int N));
     140void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
     141void          initMosaicGrid      PROTO((Image *image, int Nimage));
     142void          initMosaics         PROTO((Image *image, int Nimage));
     143void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
     144void          initialize          PROTO((int argc, char **argv));
     145void          initstats           PROTO((char *mode));
     146int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
     147Catalog      *load_catalogs       PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
     148GSCRegion    *load_images         PROTO((char *seed, int *nregion, GSCRegion *fullregion));
     149int           main                PROTO((int argc, char **argv));
     150void          mark_images         PROTO((Image *image, int Nimage, Image *timage, int Ntimage));
     151void          matchImage          PROTO((Catalog *catalog, int meas, int cat));
     152void          matchMosaics        PROTO((Catalog *catalog, int meas, int cat));
     153GSCRegion    *name_region         PROTO((char *name, int *Nregions));
     154double        opening_angle       PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
     155void          plot_chisq          PROTO((Catalog *catalog, int Ncatalog));
     156void          plot_defaults       PROTO((Graphdata *graphdata));
     157void          plot_grid           PROTO((Catalog *catalog));
     158void          plot_images         PROTO(());
     159void          plot_list           PROTO((Graphdata *graphdata, double *xlist, double *ylist, int N, char *label, char *file));
     160void          plot_mosaic_fields  PROTO((Catalog *catalog));
     161void          plot_mosaics        PROTO(());
     162void          plot_scatter        PROTO((Catalog *catalog, int Ncatalog));
     163void          plot_star_coords    PROTO((Catalog *catalog, int Ncatalog));
     164void          plot_stars          PROTO((Catalog *catalog, int Ncatalog));
     165void          reload_catalogs     PROTO((GSCRegion *region, int Nregion, GSCRegion *fullregion));
     166int           setExclusions       PROTO((Catalog *catalog, int Ncatalog));
     167void          setMcal             PROTO((Catalog *catalog, int Poor));
     168void          setMcalFinal        PROTO((Image *image, int Nimage));
     169int           setMcalOutput       PROTO((Catalog *catalog, int Ncatalog));
     170void          setMgrid            PROTO((Catalog *catalog));
     171int           setMmos             PROTO((Catalog *catalog, int Poor));
     172int           setMrel             PROTO((Catalog *catalog, int Ncatalog));
     173void          setMrelFinal        PROTO((Catalog *catalog));
     174int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, int mark));
     175void          set_ZP              PROTO((double ZERO));
     176int           setrefcode          PROTO((Image *image, int Nimage));
     177void          skip_measurements   PROTO((Catalog *catalog, int pass));
     178void          sortA               PROTO((double *X, int N));
     179void          sortB               PROTO((double *X, double *Y, int N));
     180void          sortC               PROTO((double *X, double *Y, double *F1, double *F2, int N));
     181void          sortD               PROTO((double *X, double *Y, double *Z, int N));
     182StatType      statsImageM         PROTO((Catalog *catalog));
     183StatType      statsImageN         PROTO((Catalog *catalog));
     184StatType      statsImageX         PROTO((Catalog *catalog));
     185StatType      statsImagedM        PROTO((Catalog *catalog));
     186StatType      statsMosaicM        PROTO((Catalog *catalog));
     187StatType      statsMosaicN        PROTO((Catalog *catalog));
     188StatType      statsMosaicX        PROTO((Catalog *catalog));
     189StatType      statsMosaicdM       PROTO((Catalog *catalog));
     190StatType      statsStarN          PROTO((Catalog *catalog, int Ncatalog));
     191StatType      statsStarS          PROTO((Catalog *catalog, int Ncatalog));
     192StatType      statsStarX          PROTO((Catalog *catalog, int Ncatalog));
     193void          wcatalog            PROTO((Catalog *catalog));
     194void          wimages             PROTO(());
     195void          write_coords        PROTO((Header *header, Coords *coords));
  • trunk/Ohana/src/relphot/src/get_regions.c

    r4796 r4805  
    166166 
    167167}
    168 
    169 /**********/
    170 int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string) {
    171  
    172   int flag_d0, flag_d1, flag_h0, flag_h1;
    173   double tmp;
    174  
    175   *d0 = *h0 = *d1 = *h1 = 0;
    176 
    177   flag_h0 = dparse (h0, 1, string);
    178   flag_h1 = dparse (h1, 4, string);
    179   flag_d0 = dparse (d0, 7, string);
    180   flag_d1 = dparse (d1, 9, string);
    181   *h0 *= flag_h0;
    182   *h1 *= flag_h1;
    183   *d0 *= flag_d0;
    184   *d1 *= flag_d1;
    185 
    186   dparse (&tmp, 2, string);
    187   *h0 += tmp/60.0;
    188   dparse (&tmp, 3, string);
    189   *h0 += tmp/3600.0;
    190  
    191   dparse (&tmp, 5, string);
    192   *h1 += tmp/60.0;
    193   dparse (&tmp, 6, string);
    194   *h1 += tmp/3600.0;
    195  
    196   dparse (&tmp, 8, string);
    197   *d0 += tmp/60.0;
    198 
    199   dparse (&tmp, 10, string);
    200   *d1 += tmp/60.0;
    201 
    202   *h0 *= 15*flag_h0;
    203   *h1 *= 15*flag_h1;
    204   *d0 *= flag_d0;
    205   *d1 *= flag_d1;
    206 
    207   return (TRUE);
    208 }
  • trunk/Ohana/src/relphot/src/misc.c

    r4796 r4805  
    182182}
    183183
     184/* fseek with timeout - 0.5 sec */
     185int Fseek (FILE *f, long offset, int whence) {
     186
     187  int status;
     188
     189  status = fseek (f, offset, whence);
     190  if (status == -1) {
     191    int k;
     192    /* fprintf (stderr, "problem seeking position: %d\n", errno); */
     193    for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
     194    if (status == -1) {
     195      /* fprintf (stderr, "ERROR: serious problem seeking position: %d\n", errno); */
     196      /* clear lock at this point? */
     197      return (0);
     198    }
     199  }
     200  return (1);
     201}
  • trunk/Ohana/src/relphot/src/time.c

    r4796 r4805  
    11# include "relphot.h"
     2
     3enum {TIME_NONE, TIME_DATE, TIME_DAYS, TIME_HOURS, TIME_MINUTES, TIME_SECONDS, TIME_JD, TIME_MJD};
    24
    35/***** convert [-]00:00:00 to 0.0000 ****/
     
    8688}
    8789
    88 # define FORMAT_DAYS    1
    89 # define FORMAT_HOURS   2
    90 # define FORMAT_MINUTES 3
    91 # define FORMAT_SECONDS 4
    92 # define FORMAT_JD      5
    93 # define FORMAT_DATE    6
    94 
    9590/**********/
    9691int chk_time (char *line) {
     
    10297  p1 = line;
    10398  tmp = strtod (p1, &p2);
     99  mode = TIME_DATE;
    104100  if (p2 == p1 + strlen (p1) - 1) {
    105101    if (*p2 == 'd') {
    106       mode = FORMAT_DAYS;
     102      mode = TIME_DAYS;
    107103    }
    108104    if (*p2 == 'h') {
    109       mode = FORMAT_HOURS;
     105      mode = TIME_HOURS;
    110106    }
    111107    if (*p2 == 'm') {
    112       mode = FORMAT_MINUTES;
     108      mode = TIME_MINUTES;
    113109    }
    114110    if (*p2 == 's') {
    115       mode = FORMAT_SECONDS;
     111      mode = TIME_SECONDS;
    116112    }
    117113    if (*p2 == 'j') {
    118       mode = FORMAT_JD;
    119     }
    120   } else {
    121     mode = FORMAT_DATE;
     114      mode = TIME_JD;
     115    }
     116    if (*p2 == 'J') {
     117      mode = TIME_MJD;
     118    }
    122119  }
    123120  return (mode);
     
    125122
    126123/**********/
    127 int str_to_time (char *line, unsigned int *second) {
    128  
     124int str_to_time (char *line, time_t *second) {
     125 
     126  char *tmpline;
     127  struct tm *gmt;
    129128  struct timeval now;
    130129  double jd;
     130  time_t tsec;
    131131
    132132  if (!strcasecmp (line, "NOW")) {
     
    136136  }
    137137   
    138   if (!strcasecmp (line, "TODAY")) {
     138  if (!strncasecmp (line, "TODAY", 5)) {
    139139    gettimeofday (&now, (struct timezone *) NULL);
    140     *second = 86400 * ((int)(now.tv_sec / 86400));
    141     return (TRUE);
     140    if (line[5]) { /* line has extra data (ie, hh:mm:ss) */
     141      tsec = now.tv_sec;
     142      ALLOCATE (tmpline, char, 64);
     143      gmt   = gmtime (&tsec);
     144      sprintf (tmpline, "%04d/%02d/%02d,%s", 1900 + gmt[0].tm_year, gmt[0].tm_mon+1, gmt[0].tm_mday, &line[6]);
     145      *second = date_to_sec (tmpline);
     146      free (tmpline);
     147      return (TRUE);
     148    } else {
     149      *second = 86400 * ((int)(now.tv_sec / 86400));
     150      return (TRUE);
     151    }
    142152  }
    143153   
     
    145155  case 0:
    146156    return (FALSE);
    147   case FORMAT_DAYS:
     157  case TIME_DATE:
     158    *second = date_to_sec (line);
     159    return (TRUE);
     160  case TIME_DAYS:
    148161    *second = strtod (line, 0) * 86400.0;
    149162    return (TRUE);
    150   case FORMAT_HOURS:
     163  case TIME_HOURS:
    151164    *second = strtod (line, 0) * 3600.0;
    152165    return (TRUE);
    153   case FORMAT_MINUTES:
     166  case TIME_MINUTES:
    154167    *second = strtod (line, 0) * 60.0;
    155168    return (TRUE);
    156   case FORMAT_SECONDS:
     169  case TIME_SECONDS:
    157170    *second = strtod (line, 0);
    158171    return (TRUE);
    159   case FORMAT_JD:
     172  case TIME_JD:
    160173    jd = strtod (line, 0);
    161174    *second = jd_to_sec (jd);
    162175    return (TRUE);
    163   case FORMAT_DATE:
    164     *second = date_to_sec (line);
     176  case TIME_MJD:
     177    jd = strtod (line, 0);
     178    *second = mjd_to_sec (jd);
    165179    return (TRUE);
    166180  }
    167181  return (FALSE);
    168182}
     183
    169184
    170185/**********/
     
    173188  switch (chk_time (line)) {
    174189  case 0:
    175   case FORMAT_JD:
    176   case FORMAT_DATE:
     190  case TIME_JD:
     191  case TIME_MJD:
     192  case TIME_DATE:
    177193    return (FALSE);
    178   case FORMAT_DAYS:
     194  case TIME_DAYS:
    179195    *second = strtod (line, 0) * 86400.0;
    180196    return (TRUE);
    181   case FORMAT_HOURS:
     197  case TIME_HOURS:
    182198    *second = strtod (line, 0) * 3600.0;
    183199    return (TRUE);
    184   case FORMAT_MINUTES:
     200  case TIME_MINUTES:
    185201    *second = strtod (line, 0) * 60.0;
    186202    return (TRUE);
    187   case FORMAT_SECONDS:
     203  case TIME_SECONDS:
    188204    *second = strtod (line, 0);
    189205    return (TRUE);
     
    193209
    194210/**********/
    195 double sec_to_jd (unsigned long second) {
     211double sec_to_jd (time_t second) {
    196212
    197213  double jd;
     
    202218
    203219/**********/
    204 unsigned long int jd_to_sec (double jd) {
    205 
    206   unsigned long int second;
     220time_t jd_to_sec (double jd) {
     221
     222  time_t second;
    207223
    208224  second = (jd - 2440587.5)*86400;
     
    211227
    212228/**********/
    213 char *sec_to_date (unsigned long second) {
     229double sec_to_mjd (time_t second) {
     230
     231  double mjd;
     232 
     233  mjd = second/86400.0 + 40587.0;
     234  return (mjd);
     235}
     236
     237/**********/
     238time_t mjd_to_sec (double mjd) {
     239
     240  time_t second;
     241
     242  second = (mjd - 40587.0)*86400;
     243  return (second);
     244}
     245
     246/**********/
     247char *sec_to_date (time_t second) {
    214248 
    215249  struct tm *gmt;
     
    218252  ALLOCATE (line, char, 64);
    219253  gmt   = gmtime (&second);
    220   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);
     254  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);
    221255  return (line);
    222256
     
    224258
    225259/***** date in format yyyy/mm/dd,hh:mm:ss *****/
    226 unsigned long date_to_sec (char *date) {
    227  
    228   unsigned long second;
     260time_t date_to_sec (char *date) {
     261 
     262  time_t second;
    229263  double tmp, jd;
    230264  struct tm now;
     
    283317}
    284318
     319/***** short date in format yymmdd *****/
     320time_t short_date_to_sec (char *date) {
     321 
     322  time_t second;
     323  double jd;
     324  struct tm now;
     325 
     326  bzero (&now, sizeof(now));
     327
     328  sscanf (date, "%2d%2d%2d", &now.tm_year, &now.tm_mon, &now.tm_mday);
     329
     330  if (now.tm_year >   51) now.tm_year +=   0;
     331  if (now.tm_year <   50) now.tm_year += 100;
     332  now.tm_mon --; /* tm_mon runs from 0 - 11 */
     333
     334  jd = now.tm_mday - 32075 + (int)(1461*(1900 + now.tm_year + 4800 + (int)(((now.tm_mon+1)-14)/12))/4)
     335    + (int)(367*((now.tm_mon+1) - 2 - (int)(((now.tm_mon+1) - 14)/12)*12)/12)
     336    - (int)(3*(int)((1900 + now.tm_year + 4900 + (int)(((now.tm_mon+1) - 14)/12))/100)/4) - 0.5;
     337 
     338  second = (jd - 2440587.5)*86400 + 3600.0*now.tm_hour + now.tm_min*60.0 + now.tm_sec;
     339
     340  return (second);
     341}
     342
     343/**********/
     344int hms_to_deg (double *h0, double *h1, double *d0, double *d1, char *string) {
     345 
     346  int flag_d0, flag_d1, flag_h0, flag_h1;
     347  double tmp;
     348 
     349  *d0 = *h0 = *d1 = *h1 = 0;
     350
     351  flag_h0 = dparse (h0, 1, string);
     352  flag_h1 = dparse (h1, 4, string);
     353  flag_d0 = dparse (d0, 7, string);
     354  flag_d1 = dparse (d1, 9, string);
     355  *h0 *= flag_h0;
     356  *h1 *= flag_h1;
     357  *d0 *= flag_d0;
     358  *d1 *= flag_d1;
     359
     360  dparse (&tmp, 2, string);
     361  *h0 += tmp/60.0;
     362  dparse (&tmp, 3, string);
     363  *h0 += tmp/3600.0;
     364 
     365  dparse (&tmp, 5, string);
     366  *h1 += tmp/60.0;
     367  dparse (&tmp, 6, string);
     368  *h1 += tmp/3600.0;
     369 
     370  dparse (&tmp, 8, string);
     371  *d0 += tmp/60.0;
     372
     373  dparse (&tmp, 10, string);
     374  *d1 += tmp/60.0;
     375
     376  *h0 *= 15*flag_h0;
     377  *h1 *= 15*flag_h1;
     378  *d0 *= flag_d0;
     379  *d1 *= flag_d1;
     380
     381  return (TRUE);
     382}
    285383
    286384/* times may be in forms as:
    287    20040200450s (N seconds since 1970.0)
     385 * 20040200450s (N seconds since 1970.0)
    288386   2440900.232j (julian date)
    289    99/02/23,03:22:18 (date string)
    290    (separators may be anything except space, +, -)
    291    99:02:15:12:23:30
    292    99:02:15:12h23m30s
    293    */
    294 
    295 
    296 /* fseek with timeout - 0.5 sec */
    297 int Fseek (FILE *f, long offset, int whence) {
    298 
    299   int status;
    300 
    301   status = fseek (f, offset, whence);
    302   if (status == -1) {
    303     int k;
    304     /* fprintf (stderr, "problem seeking position: %d\n", errno); */
    305     for (k = 0; (k < 10) && ((status = fseek (f, 0, SEEK_SET)) == -1); k++) usleep (50000);
    306     if (status == -1) {
    307       /* fprintf (stderr, "ERROR: serious problem seeking position: %d\n", errno); */
    308       /* clear lock at this point? */
    309       return (0);
    310     }
    311   }
    312   return (1);
    313 }
     387 * 99/02/23,03:22:18 (date string)
     388 * (separators may be anything except space, +, -)
     389 * 99:02:15:12:23:30
     390 * 99:02:15:12h23m30s
     391 */
Note: See TracChangeset for help on using the changeset viewer.