void qt_MJD::value_Entered_CB () { MJD newval; if (newval.Construct (value.text().ascii()) < 0) { if (MJD::verbose) std::cerr << "qt_MJD:: invalid mjd:" << value.text() << std::endl; newval = valset; } setMJD (newval); }
MJD dsp::Mark4File::decode_date(uint64_t from) { char *timecode = new char[8*channels]; // 8 bytes per channel MJD date; MJD current; utc_t utcdate; utc_t tmpdate; // Special lookup table, see documentation for Mark4 formaters. // 0=0, 1=1.25, 2=2.5, 3=3.75, 4=NA, 5=5.0, 6=6.25, 7=7.5, 8=8.75, 9=NA //Required for Mark4 standard format float time_code_table[] = {0,1.25,2.5,3.75,0.0,5.0,6.25,7.50,8.75,0.0}; current.Construct(time(NULL)); uint64_t inital_pos = lseek(fd, 0, SEEK_CUR); uint64_t next_sync = find_sync(fd, from); // Read the 8 bytes after the SYNC - and handle them as per modes lseek(fd,next_sync+4*channels,SEEK_SET); read(fd, timecode, 8*channels); int stepsize = channels/8; int julian = 0; int year = 0; int day = 0; int hour = 0; int minute = 0; double second = 0.0; char tmp[4]; switch(mode) { case VLBA: // Date format for VLBA = JJJSSSSS.ssss // JJJ tmp[0] = timecode[0*stepsize]; tmp[1] = timecode[1*stepsize]; tmp[2] = timecode[2*stepsize]; tmp[3] = timecode[3*stepsize]; julian += decode_bcd(tmp)*100; tmp[0] = timecode[4*stepsize]; tmp[1] = timecode[5*stepsize]; tmp[2] = timecode[6*stepsize]; tmp[3] = timecode[7*stepsize]; julian += decode_bcd(tmp)*10; tmp[0] = timecode[8*stepsize]; tmp[1] = timecode[9*stepsize]; tmp[2] = timecode[10*stepsize]; tmp[3] = timecode[11*stepsize]; julian += decode_bcd(tmp)*1; //SSSSS tmp[0] = timecode[12*stepsize]; tmp[1] = timecode[13*stepsize]; tmp[2] = timecode[14*stepsize]; tmp[3] = timecode[15*stepsize]; second += decode_bcd(tmp)*10000.0; tmp[0] = timecode[16*stepsize]; tmp[1] = timecode[17*stepsize]; tmp[2] = timecode[18*stepsize]; tmp[3] = timecode[19*stepsize]; second += decode_bcd(tmp)*1000.0; tmp[0] = timecode[20*stepsize]; tmp[1] = timecode[21*stepsize]; tmp[2] = timecode[22*stepsize]; tmp[3] = timecode[23*stepsize]; second += decode_bcd(tmp)*100.0; tmp[0] = timecode[24*stepsize]; tmp[1] = timecode[25*stepsize]; tmp[2] = timecode[26*stepsize]; tmp[3] = timecode[27*stepsize]; second += decode_bcd(tmp)*10.0; tmp[0] = timecode[28*stepsize]; tmp[1] = timecode[29*stepsize]; tmp[2] = timecode[30*stepsize]; tmp[3] = timecode[31*stepsize]; second += decode_bcd(tmp)*1.0; //.ssss tmp[0] = timecode[32*stepsize]; tmp[1] = timecode[33*stepsize]; tmp[2] = timecode[34*stepsize]; tmp[3] = timecode[35*stepsize]; second += decode_bcd(tmp)*0.1; tmp[0] = timecode[36*stepsize]; tmp[1] = timecode[37*stepsize]; tmp[2] = timecode[38*stepsize]; tmp[3] = timecode[39*stepsize]; second += decode_bcd(tmp)*0.01; tmp[0] = timecode[40*stepsize]; tmp[1] = timecode[41*stepsize]; tmp[2] = timecode[42*stepsize]; tmp[3] = timecode[43*stepsize]; second += decode_bcd(tmp)*0.001; tmp[0] = timecode[44*stepsize]; tmp[1] = timecode[45*stepsize]; tmp[2] = timecode[46*stepsize]; tmp[3] = timecode[47*stepsize]; second += decode_bcd(tmp)*0.0001; if(int(current.in_days())%1000 >= julian){ // 2 most significant digits of 5 digit julian are correct julian += ( int(current.in_days())/1000)*1000; } else{ julian += ( int(current.in_days())/1000 -1 )*1000; } date = MJD(julian,int(second), (second-int(second))); break; case Standard: // Date format for VLBA = YDDDHHMMSS.sss // Y tmp[0] = timecode[0*stepsize]; tmp[1] = timecode[1*stepsize]; tmp[2] = timecode[2*stepsize]; tmp[3] = timecode[3*stepsize]; year = decode_bcd(tmp); // DDD tmp[0] = timecode[4*stepsize]; tmp[1] = timecode[5*stepsize]; tmp[2] = timecode[6*stepsize]; tmp[3] = timecode[7*stepsize]; day += decode_bcd(tmp)*100; tmp[0] = timecode[8*stepsize]; tmp[1] = timecode[9*stepsize]; tmp[2] = timecode[10*stepsize]; tmp[3] = timecode[11*stepsize]; day += decode_bcd(tmp)*10; tmp[0] = timecode[12*stepsize]; tmp[1] = timecode[13*stepsize]; tmp[2] = timecode[14*stepsize]; tmp[3] = timecode[15*stepsize]; day += decode_bcd(tmp)*1; // HH tmp[0] = timecode[16*stepsize]; tmp[1] = timecode[17*stepsize]; tmp[2] = timecode[18*stepsize]; tmp[3] = timecode[19*stepsize]; hour += decode_bcd(tmp)*10; tmp[0] = timecode[20*stepsize]; tmp[1] = timecode[21*stepsize]; tmp[2] = timecode[22*stepsize]; tmp[3] = timecode[23*stepsize]; hour += decode_bcd(tmp)*1; // MM tmp[0] = timecode[24*stepsize]; tmp[1] = timecode[25*stepsize]; tmp[2] = timecode[26*stepsize]; tmp[3] = timecode[27*stepsize]; minute += decode_bcd(tmp)*10; tmp[0] = timecode[28*stepsize]; tmp[1] = timecode[29*stepsize]; tmp[2] = timecode[30*stepsize]; tmp[3] = timecode[31*stepsize]; minute += decode_bcd(tmp)*1; // SS tmp[0] = timecode[32*stepsize]; tmp[1] = timecode[33*stepsize]; tmp[2] = timecode[34*stepsize]; tmp[3] = timecode[35*stepsize]; second += decode_bcd(tmp)*10.0; tmp[0] = timecode[36*stepsize]; tmp[1] = timecode[37*stepsize]; tmp[2] = timecode[38*stepsize]; tmp[3] = timecode[39*stepsize]; second += decode_bcd(tmp)*1.0; // .sss tmp[0] = timecode[40*stepsize]; tmp[1] = timecode[41*stepsize]; tmp[2] = timecode[42*stepsize]; tmp[3] = timecode[43*stepsize]; second += decode_bcd(tmp)*0.1; tmp[0] = timecode[44*stepsize]; tmp[1] = timecode[45*stepsize]; tmp[2] = timecode[46*stepsize]; tmp[3] = timecode[47*stepsize]; second += decode_bcd(tmp)*0.01; tmp[0] = timecode[48*stepsize]; tmp[1] = timecode[49*stepsize]; tmp[2] = timecode[50*stepsize]; tmp[3] = timecode[51*stepsize]; second += time_code_table[decode_bcd(tmp)]*0.001; current.UTC(&tmpdate,0); if(tmpdate.tm_year%10 >= year){ year += int(tmpdate.tm_year/10)*10; }else{ year += int((tmpdate.tm_year/10)-1)*10; } utcdate.tm_year = year; utcdate.tm_yday = day; utcdate.tm_hour = hour; utcdate.tm_min = minute; utcdate.tm_sec = int(second); date = MJD(utcdate); date += second-int(second); // add fractions of seconds. break; default: cerr << "Unknown mode - " << mode << endl; } // cerr << "SEEK_CUR: " << lseek(fd,0,SEEK_CUR); // lseek(fd,next_sync-8*channels,SEEK_SET); // position of decoded time. // cerr << "\t" << lseek(fd,0,SEEK_CUR)/channels << endl; lseek(fd,inital_pos,SEEK_SET); // restored original file pointer return date; }