int main(void)
{
    int f,res,b[300],ji;
    char a[300][20],c[20];
    while(scanf("%s",&a[0])!=EOF)
    {
        strcpy(c,a[0]);
        res=pan(a[0]);
        ji=1;
        for(ji=1;0==res;ji++)
        {
            b[ji]=tod(a[ji-1]);
            fan(a[ji-1]);
            b[ji]=b[ji]+tod(a[ji-1]);
            tos(b[ji],a[ji]);
            res=pan(a[ji]);
        }
        printf("%d\n",ji-1);
        printf("%s",c);
        for(f=1;f<ji;f++)
        {
            printf("--->");
            printf("%s",a[f]);
        }
        printf("\n");
    }
return 0;
}
Exemple #2
0
void Clocker::end() {
    if(getrusage(RUSAGE_SELF,&r_usageEnd)!=0)
        cerr << "Error " << errno << " on Clocker::end()" << endl;
    gettimeofday(&stop, NULL);
    usageEnd = clock();
    tod(&since);
    tod(stop,&now);
}
Exemple #3
0
int main()
{
    double h, t, d;
    double x, y;
    char a, b;
    while (scanf("%c %lf %c %lf\r\n", &a, &x, &b, &y) && a != 'E')
    {
        h = t = d = MAX;

        if (a == 'T')
            t = x;
        else if (a == 'D')
            d = x;
        else
            h = x;

        if (b == 'T')
            t = y;
        else if (b == 'D')
            d = y;
        else
            h = y;

        if (h == MAX)
            h = toh(t, d);
        else if (t == MAX)
            t = tot(d, h);
        else
            d = tod(t, h);
        printf("T %.1f D %.1f H %.1f\r\n", t, d, h);
    }
}
Exemple #4
0
/* external function definitions */
int 
timerproc(void)
{
  struct node *hp = &timers;
  struct timeval *now = tod();
  struct node *np;
  int didwork = 0;

  while ((np = hp->f) != hp) {
    struct timer *tp = TIMERAT(np);
    struct timeval *tvp = &(tp->expire);

    if (tvcmp(now, tvp) >= 0) {
      void (*func) () = tp->func;
      void *arg = tp->arg;

      timerclr(tp);
      if (func != (void (*) ()) (0))
	(*func) (arg);
    } else {
      break;
    }
    didwork = 1;
  }

  return didwork;
}
Exemple #5
0
	jd_t gregorian_to_jd(year_t year, month_t month, day_t day, hour_t hour, minute_t minute, second_t second) {
		long long a = (14 - month) / 12;
		long long y = year + 4800 - a;
		long long m = month + 12 * a - 3;
		jd_t ymd = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045 - 0.5;
		jd_t hms = tod(hour, minute, second);
		return ymd + hms;
	}
Exemple #6
0
string Clocker::readReset() {
    ostringstream str;
    end();
    double diff = getTimediff();
    double timeUsed = getUsage() / 1E6;
    str << ":: " << tod(&now) << " :: " << setfill('0') << setprecision(6) << setw(10) << diff << " sec elapsed; "
    << setfill(' ') << setprecision(4) << timeUsed << " cpu sec used" ;
    begin();
    return str.str();
}
Exemple #7
0
/* external function definitions */
void 
dapselect(void)
{
  static char fnc[] = "dapselect";
  struct timeval timeout;
  struct timeval *tvpnext;
  struct timeval *tvp;
  int rc;

  /* copy enable flags over able flags */
  fdscopy(fds_r, fds_ra);
  fdscopy(fds_w, fds_wa);
  fdscopy(fds_x, fds_xa);

  /* set up timeout */
  if (dapZeroTimeout) {
    tvp = &timeout;
    tvp->tv_sec = tvp->tv_usec = (long) (0);
  } else if ((tvpnext = timernext()) == (struct timeval *) (0)) {
#ifdef _AIX
    /* TK - AIX has a problem with this. Wait until next year. */
    tvp = &timeout;
    tvp->tv_sec = (366 * 24 * 60 * 60) + 2;
    tvp->tv_usec = (long) (0);
#else
    tvp = (struct timeval *) (0);
#endif
  } else {
    tvp = &timeout;
    (void) tvdiff(tvpnext, tod(), tvp);
    if (tvp->tv_sec < 0) {
      tvp->tv_sec = tvp->tv_usec = (long) (0);
    }
    if (tvp->tv_sec > tv_select_max.tv_sec) {
      tvp = &tv_select_max;
    }
  }

  if (((rc = select(fds_size, fds_ra, fds_wa, fds_xa, tvp)) < 0)
      && (errno != EINTR)) {
    Warn("%t %s(): error: select(): %m\n", fnc);
  }
  if (rc <= 0) {
    fdszero(fds_ra);
    fdszero(fds_wa);
    fdszero(fds_xa);
  }
  return;
}
Exemple #8
0
	jd_t hebrew_to_jd(year_t year, month_t month, day_t day, hour_t hour, minute_t minute, second_t second) {

		jd_t ymd = HEBREW_EPOCH + delay_of_week(year) + delay_adjacent_year(year) + day + 1;
		
		if (month < 7) {
			for (month_t m = 7; m <= hebrew_months_in_year(year); ++m)
				ymd += hebrew_days_in_month(year, m);
			for (month_t m = 1; m <= month - 1; ++m)
				ymd += hebrew_days_in_month(year, m);
		}
		else {
			for (month_t m = 7; m <= month - 1; ++m)
				ymd += hebrew_days_in_month(year, m);
		}

		jd_t hms = tod(hour, minute, second);
		if (hms >= 0.5) --hms;
		return ymd + hms; 
	}
Exemple #9
0
static void processFile(const boost::filesystem::path &path, int hrsOffset, result_t &results)
{
    std::string fn = path.string();
    std::time_t t = boost::filesystem::last_write_time(path);

    boost::posix_time::ptime lwt = boost::posix_time::from_time_t(t);
    lwt = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(lwt);
    lwt += boost::posix_time::time_duration(hrsOffset, 0, 0, 0);

    StatusReport statusReport(fn);

    std::ifstream in(fn.c_str());
    Json json;
    while (!in.eof())
    {
        char c;
        in.get(c);
        json.nextChar(c);
    }

    map_t::const_iterator itor = json.getMap().find("eventlog");
    if (itor != json.getMap().end())
    {
        std::vector<std::string> v;
        json.getArray(itor->second, v);
        if (v.size() > 1) 
        {   // more than just labels
            std::vector<std::string> labels;
            json.getArray(v[0], labels);
            std::map<int, int> colMap;
            for (int j = 0; j < (int)NUM_COLUMNS; j++)
            {
                std::string l; l += '"'; l += Columns[j]; l += '"';
                for (int k = 0; k < labels.size(); k++)
                {
                    if (labels[k] == l)
                        colMap[j] = k;
                }
            }
            if (colMap.size() == (int)NUM_COLUMNS)
            {   // every column we expect appears?
                for (int i = 1; i < v.size(); i++)
                {
                    std::vector<std::string> vals;
                    json.getArray(v[i], vals);
                    if (vals.size() == labels.size())
                    {   // this record has an entry for every label?
                        boost::posix_time::time_duration todFile = lwt.time_of_day();
                        int todHors = todFile.hours();
                        int todMins = todFile.minutes();
                        int hrs = atoi(vals[colMap[HOUR]].c_str());
                        int min = atoi(vals[colMap[MINUTE]].c_str());
                        boost::posix_time::time_duration tod(hrs, min, 0, 0), delta;
                        delta = tod - todFile;
                        const int minMin = 2;
                        if (delta.total_seconds() > (minMin * 60)) // assume rolled over midnight
                            delta -= boost::posix_time::time_duration(24,0,0,0);
                        long ts = delta.total_seconds();
                        const int maxMin = 120;
                        if ((ts > (minMin * 60)) || (ts < (maxMin * -60)))
                        {
                            std::ostringstream oss;
                            oss << "Time label (" << hrs << ':' << min << ") not in window " << maxMin << "min before file stamp ("
                                << todHors << ':' << todMins << ") ts=" << ts;    
                            statusReport.report(oss.str());
                            continue;
                        }
                        boost::posix_time::ptime tstamp = lwt + delta;
                        results[tstamp] = Event(vals[colMap[RELAY]].c_str(), 
                            vals[colMap[TEMPERATURE]].c_str(),
                            vals[colMap[TARGET_TEMPERATURE]].c_str(), 
                            vals[colMap[HUMIDITY]].c_str(),
                            path.filename().string());
                    }
                }
            }
        }
    }
    else statusReport.report("No eventlog in json");
}
	static boost::posix_time::ptime ToBoostPtime(const Time &t)
	{
	  boost::gregorian::date d(t.m_year, t.m_month, t.m_day);
	  boost::posix_time::time_duration tod(t.m_hour, t.m_minute, t.m_second, static_cast<boost::posix_time::time_duration::fractional_seconds_type>(t.m_fraction_of_second * pow(10.0, boost::posix_time::time_duration::num_fractional_digits())));
	  return boost::posix_time::ptime(d, tod);
	}
Exemple #11
0
int
main(int argc, char* argv[])
{
#ifdef CH_MPI
  MPI_Init(&argc, &argv);
#endif

  int err =0;

  if ( verbose )
    pout() << indent2 << "Beginning " << pgmname << " ..." << std::endl ;

#ifdef CH_TICKS
  int m0, m1;
  unsigned long long int t0, t1, t2, seconds0, seconds1;
  tod(seconds0, m0);
  t0=ch_ticks();
  t1=0;
  for (int i=0; i<32*16384; i++)
    {
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
      ch_ticks();
    }
  t2=ch_ticks();
  tod(seconds1, m1);
  if ( verbose )
    {
      pout()<<"t0 t2:"<<t0<<" "<<t2<<"\n";
      pout()<<"seconds "<<seconds0<<" "<<seconds1<<"\n";
      pout()<<"micro   "<<m0<<" "<<m1<<"\n";
    }
  t1=t2-t0;

  if ( verbose )
    {
      int micro = (seconds1-seconds0)*1000000 + (m1-m0);
      pout()<<"ticks: "<<t1<<" microseconds: "<<micro<<std::endl;

      double resolution = ((double)(micro*1000)/t1);
      pout()<<"tick resolution="<<resolution<<" nanoseconds"<<std::endl;
      t0=t1;
      t0/=32*32*16384;
      pout()<<"ticks per ch_ticks call: "<<t0<<std::endl;
    }

#else
  pout()<<"clock.cpp (and CH_TIME* macros) need a ch_ticks function"<<std::endl;
  err = 1;
#endif

  if ( verbose )
    {
      if (err == 0)
        {
          pout() << indent << "clock tick test passed." << std::endl;
        }
      else
        {
          pout() << indent << "clock tick test  FAILED!!! "<<err<<std::endl;
        }
    }

#ifdef CH_MPI
  MPI_Finalize();
#endif

  return err;
}
Exemple #12
0
	jd_t julian_to_jd(year_t year, month_t month, day_t day, hour_t hour, minute_t minute, second_t second) {
		return julian_to_jd(year, month, day) + tod(hour, minute, second);
	}
Exemple #13
0
string& Clocker::tod(string* data) {
    timeval tv;
    gettimeofday(&tv, NULL);
    return tod(tv,data);
}
Exemple #14
0
string& Clocker::tod() {
    return tod(&now);
}
Exemple #15
0
A pString_Connection::syncReadLoop(struct timeval *pgameover)
{
  A result=(A)0, dataobj;
  int rc;
  struct timeval timeleft, *tvp;
  
  ipcWarn(wrnlvl(), "%t pString_Connection::syncReadLoop\n");
  /* make arguments for select() */
  Syncfds.fdszero(Syncfds.r());
  Syncfds.fdszero(Syncfds.ra());
  LOCALCHANENBL(Syncfds.r(),readChannel());
  
  if (pgameover != (struct timeval *)0) 
  {
    tvp=&timeleft;
    tvdiff(pgameover,tod(),tvp);
    if (0>tvp->tv_sec) tvp->tv_sec=tvp->tv_usec=0;
  } else tvp=NULL;
  
  for(;;) 
  {
    Syncfds.fdscopy(Syncfds.r(),Syncfds.ra());

    if (((rc = select(Syncfds.size(), Syncfds.ra(), NULL, NULL, tvp)) < 0)) 
    {
      if (EINTR==errno)
	syncFillError("interrupt","select() received an interrupt");
      else
	syncFillError("select", 
		      "select() returned error code %d.  errno=%d",
		      rc, errno);
      break;
    }
    
    if (rc) 
    {
      if (Syncfds.fdsisset(Syncfds.ra(), fd()))
      {
	rc=syncDoRead(&dataobj);
	if (0<rc) result=dataobj;
	if (rc) break;
      }
      else {
	syncFillError("fdsisset","unexpected event broke select()");
	break;
      }
    }
    
    /* check for timeout and reset timeleft */
    if (NULL != tvp) 
    {
      tvdiff(pgameover,tod(),tvp);
      if (0>tvp->tv_sec) tvp->tv_sec=tvp->tv_usec=0;
      if (0==tvp->tv_sec && 0==tvp->tv_usec) 
      {
	syncFillError("timeout","Syncread loop timed out");
	break;
      }
    }
    
  } /* end for(;;) loop */
  
  return result;
}  
Exemple #16
0
static void filltwh(SCAN *scan, XSCAN *xscan, int rec)
{
    int i, swapped = 0;
    float *next;
    float *twh;
    double fact;
	
	int CheckDataSize(int);
	
    twh = (float *)itwh;
    
    fact = twh[57];
    if (fact == 0.0) fact = 1.0;
    
    scan->ScanNo = itwh[0];
    scan->NChannel = (int)(twh[55+rec]/fact + 0.5);
    xscan->NChannel = (int)(twh[55+rec]/fact + 0.5);
    scan->Day   = itwh[28];
    scan->Month = itwh[27];
#ifdef DEBUG
    printf("NChannel=%d\n", xscan->NChannel);
    printf("ScanNo=%d\n", scan->ScanNo);
    printf("fact=%f\n", fact);
#endif

    if (scan->NChannel <= 0 || scan->ScanNo < 0 ||
        scan->Day < 0 || scan->Day > 31 ||
        scan->Month < 0 || scan->Month > 12) {
        swap_twh();
        fact = twh[57];
        if (fact == 0.0) fact = 1.0;
        scan->ScanNo = itwh[0];
        scan->NChannel = (int)(twh[55+rec]/fact + 0.5);
        scan->Day   = itwh[28];
        scan->Month = itwh[27];
#ifdef DEBUG
        printf("Swapped NChannel=%d\n", scan->NChannel);
        printf("        ScanNo=%d\n", scan->ScanNo);
        printf("        fact=%f\n", fact);
#endif
        if (scan->NChannel <= 0 || scan->ScanNo < 0 ||
            scan->Day < 0 || scan->Day > 31 ||
            scan->Month < 0 || scan->Month > 12) return;
        swapped = 1;
    }
    	
	if (CheckDataSize(scan->NChannel) < scan->NChannel) {
	    return;
	}
	
    scan->Year = itwh[29];
    if (scan->Year < 1900) scan->Year += 1900;
    hms(twh[12]/fact, &scan->UTHour, &scan->UTMin, &scan->UTSec);
    hms(twh[11]/fact, &scan->STHour, &scan->STMin, &scan->STSec);
    scan->ObsMode = itwh[30];
    scan->CSystem = 0;
    strncpy(scan->Name, (char *)(itwh+12), 12);
    scan->Name[11] = '\0';
    strncpy(scan->Project, (char *)(itwh+8), 4);
    strncpy(scan->Molecule, (char *)(itwh+260), 18);
    scan->Molecule[17] = '\0';
    scan->JulDate = (int)(twh[9]/fact + 0.5);
    scan->LMapOff = twh[90]/fact;
    scan->BMapOff = twh[91]/fact;
    scan->AzMapOff = twh[88]/fact;
    scan->ElMapOff = twh[89]/fact;
    scan->StepX = twh[140]/fact;
    scan->StepY = twh[141]/fact;
    scan->PosAngle = twh[142]/fact;
    scan->Equinox = twh[24]/fact;
    scan->Tsys = twh[45+rec]/fact;
    scan->Tcal = twh[41+rec]/fact;
    scan->IntTime = twh[47+rec]/fact;
    scan->AirTemp = twh[77]/fact;
    scan->Pressure = twh[78]/fact;
    scan->Humidity = twh[79]/fact;
    scan->VSource = (double)twh[49+rec]/fact;
    scan->VelRes = (double)twh[51+rec]/fact;
    scan->Bandwidth = (double)twh[53+rec]/fact;
    scan->FreqRes = scan->Bandwidth/scan->NChannel;
    next = twh+150;
    if (rec) next += (int)(twh[55]/fact + 0.5);
    for (i=0; i<scan->NChannel; i++) {
        if (swapped) swap((char *)next, sizeof(float));
        scan->c[i] = (*next++)/fact;
    }
    scan->Longitude = tod(itwh[42],itwh[43],itwh[44],swapped)/fact;
    scan->Latitude = tod(itwh[45],itwh[46],itwh[47],swapped)/fact;
    scan->Azimuth = tod(itwh[164],itwh[165],itwh[166],swapped)/fact;
    scan->Elevation = tod(itwh[167],itwh[168],itwh[169],swapped)/fact;
    scan->RestFreq = tod(itwh[70+3*rec],itwh[71+3*rec],itwh[72+3*rec],swapped)/fact;
    scan->SkyFreq = tod(itwh[76+3*rec],itwh[77+3*rec],itwh[78+3*rec],swapped)/fact;
}
Exemple #17
0
time_t
parsetime(int argc, char **argv)
{
/* Do the argument parsing, die if necessary, and return the time the job
 * should be run.
 */
    time_t nowtimer, runtimer;
    struct tm nowtime, runtime;
    int hr = 0;
    /* this MUST be initialized to zero for midnight/noon/teatime */

    nowtimer = time(NULL);
    nowtime = *localtime(&nowtimer);

    runtime = nowtime;
    runtime.tm_sec = 0;
    runtime.tm_isdst = 0;

    if (argc <= optind)
	usage();

    init_scanner(argc-optind, argv+optind);

    switch (token()) {
    case NOW:	
	    if (scc < 1) {
		return nowtimer;
	    }
	    /* now is optional prefix for PLUS tree */
	    expect(PLUS);
    case PLUS:
	    plus(&runtime);
	    break;

    case NUMBER:
	    tod(&runtime);
	    month(&runtime);
	    break;

	    /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised
	     * hr to zero up above, then fall into this case in such a
	     * way so we add +12 +4 hours to it for teatime, +12 hours
	     * to it for noon, and nothing at all for midnight, then
	     * set our runtime to that hour before leaping into the
	     * month scanner
	     */
    case TEATIME:
	    hr += 4;
    case NOON:
	    hr += 12;
    case MIDNIGHT:
	    if (runtime.tm_hour >= hr) {
		runtime.tm_mday++;
		runtime.tm_wday++;
	    }
	    runtime.tm_hour = hr;
	    runtime.tm_min = 0;
	    token();
	    /* FALLTHROUGH to month setting */
    default:
	    month(&runtime);
	    break;
    } /* ugly case statement */
    expect(EOF);

    /* convert back to time_t
     */
    runtime.tm_isdst = -1;
    runtimer = mktime(&runtime);

    if (runtimer < 0)
	panic("garbled time");

    if (nowtimer > runtimer)
	panic("trying to travel back in time");

    return runtimer;
} /* parsetime */
Exemple #18
0
	jd_t islamic_to_jd(year_t year, month_t month, day_t day, hour_t hour, minute_t minute, second_t second) {
		jd_t time = tod(hour, minute, second);
		if (time >= 0.5) { time -= 1; }
		return islamic_to_jd(year, month, day) + time;
	}
Exemple #19
0
/******************************************************************************
* Function: main
*
* Description:
*    Connect to a remote time-of-day service and write the remote host's TOD to
*    stdout.
*
* Parameters:
*    The usual argc & argv parameters to a main() program.
*
* Return Value:
*    This function always returns zero.
******************************************************************************/
int main( int   argc,
          char *argv[ ] )
{
   const char   *host     = DFLT_HOST;
   int           opt;
   int           sckt;
   unsigned int  scopeId  = if_nametoindex( DFLT_SCOPE_ID );
   const char   *service  = DFLT_SERVICE;

   init_performance();

   /*
   ** Determine the program name (w/o directory prefix).
   */
   pgmName = (const char*) strrchr( argv[ 0 ], '/' );
   pgmName = pgmName == NULL  ?  argv[ 0 ]  :  pgmName+1;
   /*
   ** Process command line options.
   */
   opterr = 0;   /* Turns off "invalid option" error messages. */
   while ( ( opt = getopt( argc, argv, VALIDOPTS ) ) != -1 )
   {
      switch ( opt )
      {
         case 's':   /* Scope identifier (IPv6 kluge). */
         {
            scopeId = if_nametoindex( optarg );
            if ( scopeId == 0 )
            {
               fprintf( stderr,
                        "%s: Unknown network interface (%s).\n",
                        pgmName,
                        optarg );
               USAGE;
            }
            break;
         }
         case 'v':   /* Verbose mode. */
         {
            verbose = true;
            break;
         }
         default:
         {
            USAGE;
         }
      }  /* End SWITCH on command option. */
   } /* End WHILE processing command options. */
   /*
   ** Process command arguments.  At the end of the above loop, optind is the
   ** index of the first NON-option argv element.
   */
   switch ( argc - optind )
   {
      case 2:   /* Both host & service are specified on the command line. */
      {
          service = argv[ optind + 1 ];
          /***** Fall through *****/
      }
      case 1:   /* Host is specified on the command line. */
      {
          host = argv[ optind ];
          /***** Fall through *****/
      }
      case 0:   /* Use default host & service. */
      {
          break;
      }
      default:
      {
         USAGE;
      }
   }  /* End SWITCH on number of command arguments. */
   /*
   ** Open a connection to the indicated host/service.
   **
   ** Note that if all three of the following conditions are met, then the
   ** scope identifier remains unresolved at this point.
   **    1) The default network interface is unknown for some reason.
   **    2) The -s option was not used on the command line.
   **    3) An IPv6 "scoped address" was not specified for the hostname on the
   **       command line.
   ** If the above three conditions are met, then only an IPv4 socket can be
   ** opened (connect(2) fails without the scope ID properly set for IPv6
   ** sockets).
   */
   if ( ( sckt = openSckt( host,
                           service,
                           scopeId ) ) == INVALID_DESC )
   {
      fprintf( stderr,
               "%s: Sorry... a connection could not be established.\n",
               pgmName );
      exit( 1 );
   }
   /*
   ** Get the remote time-of-day.
   */
   tod( sckt );
   /*
   ** Close the connection and terminate.
   */
   (void) SYSCALL( "close",
                   __LINE__,
                   close( sckt ) );
   return 0;
}  /* End main() */