MidgardTimestamp *midgard_timestamp_new_from_iso8601(const gchar *iso_date)
{
	MidgardTimestamp *mt = midgard_timestamp_new();

	caltime_scan(iso_date, mt);

	return mt;
}
Beispiel #2
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;
}
GValue *midgard_timestamp_new_value_from_iso8601(const gchar *iso_date)
{
	GValue *tval = g_new0(GValue, 1);
	g_value_init(tval, MGD_TYPE_TIMESTAMP);

	MidgardTimestamp *mt = (MidgardTimestamp *) g_value_get_boxed(tval);

	if (caltime_scan(iso_date, mt) > 0) {
		
		midgard_timestamp_set(mt);
	
	} else {
		
		__timestamp_reset(tval);
	}

	return tval;
}
Beispiel #4
0
int main(int argc, char **argv)
{
  miniseed_file_t *mseed;
  wav_file_t *wav;
  int32_t frame[16];
  uint64_t frames = 0;
  struct caltime ct;
  struct taia start_time;

  if (argc < 4) {
    fprintf(stderr, "Usage: %s <start time> <infile.wav> <outfile.seed>\n", argv[0]);
    return -1;
  }

  if (!(caltime_scan(argv[1], &ct))) {
    fprintf(stderr, "Malformed start time.\n");
    return -1;
  }
  caltime_tai(&ct, &start_time.sec);
  start_time.nano = 0;
  start_time.atto = 0;

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

  if (!(mseed = miniseed_file_create(argv[3]))) {
    fprintf(stderr, "Invalid file: %s.\n", argv[3]);
    return -1;
  }
  miniseed_file_set_sample_rate(mseed, wav->header.sample_rate);
  miniseed_file_set_start_time(mseed, &start_time);

  while (wav_file_read_int_frame(wav, frame) >= 0) {
    miniseed_file_write_int_frame(mseed, frame);
    ++frames;
  }

  wav_file_close(wav);
  miniseed_file_close(mseed);

  return 0;
}
static void midgard_timestamp_transform_from_string(const GValue *src, GValue *dst) 
{
	g_return_if_fail(G_VALUE_HOLDS_STRING(src) &&
			G_VALUE_HOLDS(dst, MGD_TYPE_TIMESTAMP));

	const gchar *time = g_value_get_string(src);
	g_return_if_fail(time != NULL);

        MidgardTimestamp *mt = (MidgardTimestamp *) g_value_get_boxed(dst);

	if(mt == NULL) {
		
		mt = midgard_timestamp_new();
		g_value_take_boxed(dst, mt);
	}	

	gint rv = caltime_scan(time, mt);

	if (rv != 0)
		g_warning ("Failed to transform given datetime string (%s) to MidgardTimestamp", time);
}
Beispiel #6
0
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);
}