示例#1
0
文件: nowutc.c 项目: KatsOide/SAD
int main()
{
  if (leapsecs_init() == -1) {
    fprintf(stderr,"utcnow: fatal: unable to init leapsecs\n");
    exit(111);
  }
    
  taia_now(&now);
  x[taia_fmtfrac(x,&now)] = 0;

  taia_tai(&now,&sec);
  caltime_utc(&ct,&sec,(int *) 0,(int *) 0);

  printf("%ld-%02d-%02d %02d:%02d:%02d.%s\n"
    ,ct.date.year
    ,ct.date.month
    ,ct.date.day
    ,ct.hour
    ,ct.minute
    ,ct.second
    ,x
    );

  exit(0);
}
示例#2
0
int httpdate(stralloc *sa,struct tai *t)
{
  struct caltime ct;
  int i;

  caltime_utc(&ct,t,&i,(int *) 0);

  if (i < 0) i = 0;
  if (i > 6) i = 6;
  if (!stralloc_copys(sa,weekday[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.day,2)) return 0;
  i = ct.date.month - 1;
  if (i < 0) i = 0;
  if (i > 11) i = 11;
  if (!stralloc_cats(sa,month[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.year,0)) return 0;
  if (!stralloc_cats(sa," ")) return 0;
  if (!stralloc_catuint0(sa,ct.hour,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.minute,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.second,2)) return 0;
  if (!stralloc_cats(sa," GMT")) return 0;

  return 1;
}
示例#3
0
static void
cal_ftm(ftm *ftm, int required)
{ int missing = ftm->flags^required;

  if ( missing )			/* we need something, so we always */
  { struct caltime ct;			/* need the stamp */
    struct tai tai;

    ct.date.year  = ftm->tm.tm_year+1900;
    ct.date.month = ftm->tm.tm_mon+1;
    ct.date.day   = ftm->tm.tm_mday;
    ct.hour       = ftm->tm.tm_hour;
    ct.minute     = ftm->tm.tm_min;
    ct.second     = ftm->tm.tm_sec;
    ct.offset     = -ftm->utcoff / 60;	/* TBD: make libtai speak seconds */

    caltime_tai(&ct, &tai);
    ftm->stamp  = (double)((int64_t)tai.x - TAI_UTC_OFFSET);
    ftm->stamp -= (double)ct.second;
    ftm->stamp += ftm->sec;
    ftm->flags |= HAS_STAMP;

    if ( missing & HAS_WYDAY )
    { caltime_utc(&ct, &tai, &ftm->tm.tm_wday, &ftm->tm.tm_yday);
      ftm->flags |= HAS_WYDAY;
    }
  }
}
示例#4
0
int main() {
  caltime_t ct;
  tai_t t = TAI_INIT;
  int wday = 0;
  int yday = 0;
  
  t.sec = 0;
  
  if (!caltime_scan(&ct, "2009-01-01 01:01:01 +0000"))
    return 1;
    
  caltime_utc(&ct, &t, &wday, &yday);
  
  if ((wday == 0) || (yday == 0))
    return 1;
    
  return 0;
}
示例#5
0
文件: check.c 项目: fohr/libtai
main()
{
  struct tai t;
  struct tai t2;
  struct caltime ct;
  struct caltime ct2;
  int weekday;
  int yearday;
  int i;
  double packerr;

  if (leapsecs_init() == -1)
    printf("unable to init leapsecs\n");

  while (fgets(line,sizeof line,stdin))
    if (!caltime_scan(line,&ct))
      printf("unable to parse\n");
    else {
      caltime_tai(&ct,&t);
      caltime_utc(&ct2,&t,&weekday,&yearday);
      tai_pack(x,&t);
      tai_unpack(x,&t2);
      tai_sub(&t2,&t2,&t);
      packerr = tai_approx(&t2);
      for (i = 0;i < TAI_PACK;++i)
        printf("%2.2x",(unsigned long) (unsigned char) x[i]);
      if (packerr)
        printf(" packerr=%f",packerr);
      printf(" %03d  %s",yearday,dayname[weekday]);
      if (caltime_fmt((char *) 0,&ct2) + 1 < sizeof out) {
        out[caltime_fmt(out,&ct2)] = 0;
        printf(" %s",out);
      }
      printf("\n");
    }
  return(0);
}
示例#6
0
文件: converter.c 项目: stoni/libtai
int main(int argc, char** argv)
{
	const char* cmd;
	uint64_t tai;
	const char* iso;

	if (argc < 3) {
		usage();
		return(1);
	}

	cmd = argv[1];

	if (strcmp(cmd, "taiToIso") == 0) {
		struct caltime ct;
		struct tai t;
		char buf[128];
		int len;
		tai = _strtoui64(argv[2], NULL, 10);
		t.x = tai;
		caltime_utc(&ct, &t, 0, 0);
		len = caltime_fmt(buf, &ct);
		buf[len] = '\0';
		printf("ISO: %s\n", buf);
	}
	else if (strcmp(cmd, "isoToTai") == 0) {
		iso = argv[2];
	}
	else {
		usage();
		return(1);
	}



	return(0);
}
示例#7
0
int main(int argc, char **argv)
{
  kumy_file_t *kumy;
  miniseed_file_t *mseed[KUMY_FILE_CHANNELS];
  int32_t frame[KUMY_FILE_CHANNELS];
  uint64_t frames, l, frames_per_file, frames_total, frame_count = 0;
  int i;
  char oname[1024], folder[1024];
  uint32_t sample_rate, seconds_per_file;
  int percent = 0, old_percent = -1;
  int compression = 1, show_progress = 1;
  char *infile = 0;

  struct taia start_time; /* 1871 */
  struct taia stop_time;  /* 1951 */
  struct taia sync_time;  /* 2031 */
  struct taia skew_time;  /* 2111 */

  struct caltime ct;
  struct taia tt, dt;

  program = argv[0];
  parse_options(&argc, &argv, OPTIONS(
    FLAG('n', "no-compression", compression, 0),
    FLAG('q', "quiet", show_progress, 0),
    FLAG_CALLBACK('h', "help", usage)
  ));

  if (argc < 2) {
    usage(0, 0, 0);
  }

  infile = argv[1];
  if (!(kumy = kumy_file_open(infile))) {
    fprintf(stderr, "Invalid file: %s.\n", infile);
    return -1;
  }

  parse_text_date(&start_time, kumy->text_header[0].content + 1871);
  parse_text_date(&stop_time,  kumy->text_header[0].content + 1951);
  parse_text_date(&sync_time,  kumy->text_header[0].content + 2031);
  parse_text_date(&skew_time,  kumy->text_header[0].content + 2111);

  sample_rate = 1000000 / kumy->binary_header[0].sample_interval;

  if (sample_rate <= 250) {
    seconds_per_file = 86400;
  } else if (sample_rate <= 500) {
    seconds_per_file = 43200;
  } else if (sample_rate <= 1000) {
    seconds_per_file = 21600;
  } else if (sample_rate <= 2000) {
    seconds_per_file = 10800;
  } else {
    seconds_per_file = 5400;
  }

  frames_per_file = sample_rate * seconds_per_file;
  frames_total = kumy->binary_header[0].num_samples;

  caltime_utc(&ct, &start_time.sec, 0, 0);
  ct.hour = 0;
  ct.minute = 0;
  ct.second = 0;
  caltime_tai(&ct, &tt.sec);
  tt.nano = tt.atto = 0;

  while (!taia_less(&start_time, &tt)) {
    tt.sec.x += seconds_per_file;
  }

  taia_sub(&dt, &tt, &start_time);
  frames = taia_approx(&dt) / seconds_per_file * frames_per_file;

  l = last('.', infile);
  if (l == -1 || l >= sizeof(folder)) return -1;

  /* Create folder. */
  copy(folder, l, infile);
  folder[l] = 0;
  mkdir_p(folder);

  for (i = 0; i < KUMY_FILE_CHANNELS; ++i) {
    caltime_utc(&ct, &start_time.sec, 0, 0);
    snprintf(oname, sizeof(oname), "%s/%lld.%02lld.%02lld.%02lld.%02lld.%02lld.%s.seed",
      folder, (long long)ct.date.year, (long long)ct.date.month, (long long)ct.date.day, (long long)ct.hour, (long long)ct.minute, (long long)ct.second, channel_names[i]);

    if (!(mseed[i] = miniseed_file_create((char*)oname))) {
      fprintf(stderr, "Invalid file: %s.\n", oname);
      return -1;
    }
    miniseed_file_set_sample_rate(mseed[i], sample_rate);
    miniseed_file_set_start_time(mseed[i], &start_time);
    miniseed_file_set_info(mseed[i], "OBS", "DE", channel_names[i], "K");
    miniseed_file_set_compression(mseed[i], compression);
  }

  while (kumy_file_read_int_frame(kumy, frame) >= 0) {
    if (frames == 0) {
      /* Create new files.*/
      for (i = 0; i < KUMY_FILE_CHANNELS; ++i) {
        miniseed_file_close(mseed[i]);
        caltime_utc(&ct, &tt.sec, 0, 0);
        snprintf(oname, sizeof(oname), "%s/%lld.%02lld.%02lld.%02lld.%02lld.%02lld.%s.seed",
          folder, (long long)ct.date.year, (long long)ct.date.month, (long long)ct.date.day, (long long)ct.hour, (long long)ct.minute, (long long)ct.second, channel_names[i]);
        if (!(mseed[i] = miniseed_file_create((char*)oname))) {
          fprintf(stderr, "Invalid file: %s.\n", oname);
          return -1;
        }
        miniseed_file_set_sample_rate(mseed[i], sample_rate);
        miniseed_file_set_start_time(mseed[i], &tt);
        miniseed_file_set_info(mseed[i], "OBS", "DE", channel_names[i], "K");
        miniseed_file_set_compression(mseed[i], compression);
      }
      frames = frames_per_file;
      tt.sec.x += seconds_per_file;
    }

    for (i = 0; i < KUMY_FILE_CHANNELS; ++i) {
      miniseed_file_write_int_frame(mseed[i], frame + i);
    }
    if (show_progress && frame_count % 10000 == 0) {
      percent = 100 * frame_count / frames_total;
      if (percent != old_percent) {
        progress(percent, 0);
        old_percent = percent;
      }
    }
    --frames;
    ++frame_count;
  }
  if (show_progress) progress(100, 1);

  kumy_file_close(kumy);
  for (i = 0; i < KUMY_FILE_CHANNELS; ++i) {
    miniseed_file_close(mseed[i]);
  }

  return 0;
}