SaErrorT show_dat(Domain_t *domain, hpi_ui_print_cb_t proc) { SaHpiAlarmT alarm; SaErrorT rv = SA_OK; char buf[SHOW_BUF_SZ]; char time[256]; int ind; alarm.AlarmId = SAHPI_FIRST_ENTRY; while (rv == SA_OK) { rv = saHpiAlarmGetNext(domain->sessionId, SAHPI_ALL_SEVERITIES, FALSE, &alarm); if (rv != SA_OK) break; snprintf(buf, SHOW_BUF_SZ, "(%d) ", alarm.AlarmId); time2str(alarm.Timestamp, time, 256); strcat(buf, time); strcat(buf, " "); strcat(buf, oh_lookup_severity(alarm.Severity)); if (alarm.Acknowledged) strcat(buf, " a "); else strcat(buf, " - "); strcat(buf, oh_lookup_statuscondtype(alarm.AlarmCond.Type)); ind = strlen(buf); if (alarm.AlarmCond.Type == SAHPI_STATUS_COND_TYPE_SENSOR) { snprintf(buf + ind, SHOW_BUF_SZ - ind, " %d/%d 0x%x", alarm.AlarmCond.ResourceId, alarm.AlarmCond.SensorNum, alarm.AlarmCond.EventState); } else if (alarm.AlarmCond.Type == SAHPI_STATUS_COND_TYPE_OEM) { snprintf(buf + ind, SHOW_BUF_SZ - ind, " OEM = %d", alarm.AlarmCond.Mid); break; }; strcat(buf, "\n"); if (proc(buf) != 0) return(-1); }; if (rv == SA_ERR_HPI_NOT_PRESENT) { proc("No alarms in DAT.\n"); return(SA_OK); }; return(rv); }
void CschedulerDlg::OnBnClickedAdd() { // TODO: Add your control notification handler code here COleDateTime temptime,temphours; CString strtime; int nitem; nitem=m_list.GetItemCount(); if(nitem>=KS_MAX_ITIMES) return; if(m_pData[nitem]==0) m_pData[nitem] = new ITEMDATA; m_pData[nitem]->index=nitem; m_now.GetTime(temptime); m_hours.GetTime(temphours); temptime=temptime+temphours; //show time on list strtime=time2str(&temptime); //luu time m_pData[nitem]->time=strtime; m_list.InsertItem(nitem,strtime); CString tempstr; //get the note GetDlgItemText(IDC_FARM,tempstr); m_pData[nitem]->note=tempstr; //save note m_list.SetItem(nitem,1,LVIF_TEXT ,tempstr,0,LVIF_STATE,0,0); //get the content GetDlgItemText(IDC_COMMENT,tempstr); m_pData[nitem]->comment=tempstr; //save comment m_list.SetItem(nitem,2,LVIF_TEXT ,tempstr,0,LVIF_STATE,0,0); //set item data m_list.SetItemData(nitem,(DWORD_PTR)m_pData[nitem]); }
/* validation of combined solutions ------------------------------------------*/ static int valcomb(const sol_t *solf, const sol_t *solb) { double dr[3],var[3]; int i; char tstr[32]; trace(3,"valcomb :\n"); /* compare forward and backward solution */ for (i=0;i<3;i++) { dr[i]=solf->rr[i]-solb->rr[i]; var[i]=solf->qr[i]+solb->qr[i]; } for (i=0;i<3;i++) { if (dr[i]*dr[i]<=16.0*var[i]) continue; /* ok if in 4-sigma */ time2str(solf->time,tstr,2); trace(2,"degrade fix to float: %s dr=%.3f %.3f %.3f std=%.3f %.3f %.3f\n", tstr+11,dr[0],dr[1],dr[2],SQRT(var[0]),SQRT(var[1]),SQRT(var[2])); return 0; } return 1; }
void CschedulerDlg::OnBnClickedEditBtn() { // TODO: Add your control notification handler code here ITEMDATA* pEditItemData; COleDateTime temptime,temphours; CString strtime; CString tempstr; int nitem; //get select item nitem=m_list.GetNextItem(-1,LVIS_FOCUSED|LVIS_SELECTED); pEditItemData=(ITEMDATA*)m_list.GetItemData(nitem); if(nitem ==-1) return; //now + remain time m_now.GetTime(temptime); m_hours.GetTime(temphours); temptime=temptime+temphours; //strtime=temptime.Format(_T("%d %H:%M")); strtime=time2str(&temptime); //edit item data pEditItemData->time=strtime; m_list.SetItemText(nitem,0,strtime); GetDlgItemText(IDC_FARM,tempstr); //edit item data pEditItemData->note=tempstr; m_list.SetItemText(nitem,1,tempstr); GetDlgItemText(IDC_COMMENT,tempstr); //edit item data pEditItemData->comment=tempstr; m_list.SetItemText(nitem,2,tempstr); }
static krb5_error_code entry2string_int (krb5_context context, krb5_storage *sp, hdb_entry *ent) { char *p; size_t i; krb5_error_code ret; /* --- principal */ ret = krb5_unparse_name(context, ent->principal, &p); if(ret) return ret; append_string(context, sp, "%s ", p); free(p); /* --- kvno */ append_string(context, sp, "%d", ent->kvno); /* --- keys */ for(i = 0; i < ent->keys.len; i++){ /* --- mkvno, keytype */ if(ent->keys.val[i].mkvno) append_string(context, sp, ":%d:%d:", *ent->keys.val[i].mkvno, ent->keys.val[i].key.keytype); else append_string(context, sp, "::%d:", ent->keys.val[i].key.keytype); /* --- keydata */ append_hex(context, sp, &ent->keys.val[i].key.keyvalue); append_string(context, sp, ":"); /* --- salt */ if(ent->keys.val[i].salt){ append_string(context, sp, "%u/", ent->keys.val[i].salt->type); append_hex(context, sp, &ent->keys.val[i].salt->salt); }else append_string(context, sp, "-"); } append_string(context, sp, " "); /* --- created by */ append_event(context, sp, &ent->created_by); /* --- modified by */ append_event(context, sp, ent->modified_by); /* --- valid start */ if(ent->valid_start) append_string(context, sp, "%s ", time2str(*ent->valid_start)); else append_string(context, sp, "- "); /* --- valid end */ if(ent->valid_end) append_string(context, sp, "%s ", time2str(*ent->valid_end)); else append_string(context, sp, "- "); /* --- password ends */ if(ent->pw_end) append_string(context, sp, "%s ", time2str(*ent->pw_end)); else append_string(context, sp, "- "); /* --- max life */ if(ent->max_life) append_string(context, sp, "%d ", *ent->max_life); else append_string(context, sp, "- "); /* --- max renewable life */ if(ent->max_renew) append_string(context, sp, "%d ", *ent->max_renew); else append_string(context, sp, "- "); /* --- flags */ append_string(context, sp, "%d ", HDBFlags2int(ent->flags)); /* --- generation number */ if(ent->generation) { append_string(context, sp, "%s:%d:%d ", time2str(ent->generation->time), ent->generation->usec, ent->generation->gen); } else append_string(context, sp, "- "); /* --- extensions */ if(ent->extensions && ent->extensions->len > 0) { for(i = 0; i < ent->extensions->len; i++) { void *d; size_t size, sz = 0; ASN1_MALLOC_ENCODE(HDB_extension, d, size, &ent->extensions->val[i], &sz, ret); if (ret) { krb5_clear_error_message(context); return ret; } if(size != sz) krb5_abortx(context, "internal asn.1 encoder error"); if (hex_encode(d, size, &p) < 0) { free(d); krb5_set_error_message(context, ENOMEM, "malloc: out of memory"); return ENOMEM; } free(d); append_string(context, sp, "%s%s", p, ent->extensions->len - 1 != i ? ":" : ""); free(p); } } else append_string(context, sp, "-"); return 0; }
static void printkeyinfo (const dki_t *dkp, const char *oldpath) { time_t currtime; if ( dkp == NULL ) /* print headline */ { if ( headerflag ) { tc_attr (stdout, TC_BOLD, 1); printf ("%-33.33s %5s %3s %3.3s %-7s", "Keyname", "Tag", "Typ", "Status", "Algorit"); if ( timeflag ) printf (" %-20s", "Generation Time"); if ( exptimeflag ) printf (" %-20s", "Expiration Time"); if ( ageflag ) printf (" %16s", "Age"); if ( lifetimeflag ) printf (" %4s", "LfTm"); tc_attr (stdout, TC_BOLD, 0); putchar ('\n'); } return; } time (&currtime); /* TODO: use next line if dname is dynamically allocated */ /* if ( pathflag && dkp->dname && strcmp (oldpath, dkp->dname) != 0 ) */ if ( pathflag && strcmp (oldpath, dkp->dname) != 0 ) printf ("%s/\n", dkp->dname); if ( (kskflag && dki_isksk (dkp)) || (zskflag && !dki_isksk (dkp)) ) { int color; if ( ljustflag ) printf ("%-33.33s ", dkp->name); else printf ("%33.33s ", dkp->name); printf ("%05d ", dkp->tag); printf ("%3s ", dki_isksk (dkp) ? "KSK" : "ZSK"); if ( dkp->status == DKI_ACT ) color = TC_GREEN; else if ( dkp->status == DKI_PUB ) color = TC_BLUE; else if ( dkp->status == DKI_DEP ) color = TC_RED; else color = TC_BLACK; tc_attr (stdout, color, 1); printf ("%-3.3s ", dki_statusstr (dkp) ); tc_attr (stdout, color, 0); printf ("%-7s", dki_algo2sstr(dkp->algo)); if ( currtime < dkp->time + dkp->lifetime ) color = TC_GREEN; else color = TC_BOLD|TC_RED; tc_attr (stdout, color, 1); if ( timeflag ) printf (" %-20s", time2str (dkp->gentime ? dkp->gentime: dkp->time, 's')); if ( exptimeflag ) printf (" %-20s", time2str (dkp->exptime, 's')); if ( ageflag ) printf (" %16s", age2str (dki_age (dkp, currtime))); if ( lifetimeflag && dkp->lifetime ) { if ( dkp->status == 'a' ) printf ("%c", (currtime < dkp->time + dkp->lifetime) ? '<' : '!'); else putchar (' '); printf ("%hdd", dki_lifetimedays (dkp)); } tc_attr (stdout, color, 0); putchar ('\n'); } }
void CGroupsDlg::BindGroup(int nCur, bool bEdit) { m_CurSel = nCur; if (nCur < 0 || !bEdit) { m_listDevices.EnableWindow(FALSE); m_editName.EnableWindow(FALSE); m_editDesc.EnableWindow(FALSE); m_editCreateTime.EnableWindow(FALSE); m_dtValid.EnableWindow(FALSE); m_chkValid.EnableWindow(FALSE); m_chkValid.SetCheck(0); } else { m_listDevices.EnableWindow(TRUE); m_editName.EnableWindow(TRUE); m_editDesc.EnableWindow(TRUE); m_editCreateTime.EnableWindow(FALSE); m_dtValid.EnableWindow(TRUE); m_chkValid.EnableWindow(TRUE); m_chkValid.SetCheck(0); } if (nCur < 0) return; GroupInfo& info = m_Groups[nCur]; m_editName.SetWindowText(info.Name); m_editDesc.SetWindowText(info.Desc); m_editCreateTime.SetWindowText(time2str(&info.CreateTime).c_str()); CTime valid(info.ValidTime); m_dtValid.SetTime(&valid); if (info.ValidTime != 0) { m_dtValid.EnableWindow(bEdit ? TRUE : FALSE); m_chkValid.SetCheck(1); } else { m_dtValid.EnableWindow(FALSE); m_chkValid.SetCheck(0); } memset(m_GroupDevices, 0, sizeof(int) * 2048); int num = 0; if (info.Index > 0) num = m_pAccApi->ListGroupDevices(info.Index, m_GroupDevices, 2048); else m_listDevices.EnableWindow(FALSE); for (int i = 0; i < m_listDevices.GetItemCount(); ++i) { BOOL check = FALSE; for (int j = 0; j < num; ++j) { if (m_Devs[i].Index == m_GroupDevices[j]) { check = TRUE; break; } } m_listDevices.SetCheck(i, check); m_listDevices.SetItemData(i, check); } m_GroupDeviceCount = num; }
int main() { /** Setup test environ */ setupTestTree(); std::vector<int16_t> v201501, v201502, v201503; /** (1420070400) NO_DATA (1420074000) 75 (1420077600) NO_DATA (1422748800) */ for (int i = 0; i < 267840; ++i) { if (i < 360 || i > 720) v201501.push_back(-32768); else v201501.push_back(75); } for (int i = 0; i < 241920; ++i) { if (i > 720 && i < 1080) v201502.push_back(-32768); else v201502.push_back(85); } for (int i = 0; i < 267840; ++i) { if (i < 360) v201503.push_back(-32768); else v201503.push_back(95); //v201503.push_back(-32768); } createSzCacheFile("TestA/TestB/TestC/201501.szc", v201501); createSzCacheFile("TestA/TestB/TestC/201502.szc", v201502); createSzCacheFile("TestA/TestB/TestC/201503.szc", v201503); /** Test */ SzCache szc("./",2); /** availableRange() */ SzCache::SzRange szr = szc.availableRange(); std::cout << "SzCache::availableRange(): (" << szr.first << "," << szr.second << ")\n"; std::cout << "= ( " << time2str(szr.first) << " , " << time2str(szr.second) << " )\n"; std::cout << "\n"; SzCache::SzTime t1(1420070400 ); SzCache::SzTime t2(1420070400 + 3600); SzCache::SzTime t3(1420070400 + 3600 + 3600); SzCache::SzTime t4(1420070400 + 2678400); SzCache::SzTime t5(1420070400 + 2678400 + 3600 + 3600); SzCache::SzTime t6(1420070400 + 2678400 + 3600 + 3600 + 3600); SzCache::SzTime t7(1420070400 + 2678400 + 2419200); SzCache::SzTime t8(1420070400 + 2678400 + 2419200 + 3600); SzCache::SzPath szp1("TestA/TestB/TestC"); try { SzCache::SzSearchResult ssr = szc.searchInPlace(t1,szp1); std::cout << "SzCache::searchInPlace("<<t1<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t2,szp1); std::cout << "SzCache::searchInPlace("<<t2<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t2) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t2-10,szp1); std::cout << "SzCache::searchInPlace("<<t2-10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t3,szp1); std::cout << "SzCache::searchInPlace("<<t3<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t3) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t3+10,szp1); std::cout << "SzCache::searchInPlace("<<t3+10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t4,szp1); std::cout << "SzCache::searchInPlace("<<t4<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t4) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t5,szp1); std::cout << "SzCache::searchInPlace("<<t5<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t5) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t5+10,szp1); std::cout << "SzCache::searchInPlace("<<t5+10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t6,szp1); std::cout << "SzCache::searchInPlace("<<t6<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t6) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t6-10,szp1); std::cout << "SzCache::searchInPlace("<<t6-10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t7,szp1); std::cout << "SzCache::searchInPlace("<<t7<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t8,szp1); std::cout << "SzCache::searchInPlace("<<t8<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t8) throw std::logic_error("Assertion failed!"); ssr = szc.searchInPlace(t8-10,szp1); std::cout << "SzCache::searchInPlace("<<t8-10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchRight(t2-50,t3,szp1); std::cout << "SzCache::searcRight("<<t2-50<<","<<t3<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t2) throw std::logic_error("Assertion failed!"); ssr = szc.searchRight(t2+50,t4,szp1); std::cout << "SzCache::searcRight("<<t2+50<<","<<t4<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != (t2+50)) throw std::logic_error("Assertion failed!"); ssr = szc.searchRight(t3+10,t3+50,szp1); std::cout << "SzCache::searcRight("<<t3+10<<","<<t3+50<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchRight(t4-100,t5,szp1); std::cout << "SzCache::searcRight("<<t4-100<<","<<t5<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != t4) throw std::logic_error("Assertion failed!"); ssr = szc.searchLeft(t7+100,t6,szp1); std::cout << "SzCache::searchLeft("<<t7+100<<","<<t6<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != (t7-10)) throw std::logic_error("Assertion failed!"); ssr = szc.searchLeft(t6+100,t5,szp1); std::cout << "SzCache::searchLeft("<<t6+100<<","<<t5<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != (t6+100)) throw std::logic_error("Assertion failed!"); ssr = szc.searchLeft(t3+100,t3+10,szp1); std::cout << "SzCache::searchLeft("<<t3+100<<","<<t3+10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); ssr = szc.searchLeft(t3+100,t3+10,szp1); std::cout << "SzCache::searchLeft("<<t3+100<<","<<t3+10<<","<<szp1<<"):\n" << "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n"; if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!"); std::vector<int16_t> vals; SzCache::SzTime wtime = szc.writeData(vals, t2-50, t2+50, szp1); while( wtime < t2+50 ) wtime = szc.writeData(vals, wtime, t2+50, szp1); std::cout << "writeData(" << t2-50 << "," << t2+50 << "):\n"; for (unsigned int i = 0; i < vals.size(); i++) { std::cout << vals[i] << std::endl; if ((i < 5) && (vals[i] != SzCache::cSzCacheNoData)) throw std::logic_error("Assertion failed!"); if ((i > 5) && (vals[i] != 75)) throw std::logic_error("Assertion failed!"); } std::cout << std::endl; vals.clear(); wtime = szc.writeData(vals, t4-50, t4+50, szp1); while( wtime < t4+50 ) wtime = szc.writeData(vals, wtime, t4+50, szp1); std::cout << "writeData(" << t4-50 << "," << t4+50 << "):\n"; for (unsigned int i = 0; i < vals.size(); i++) { std::cout << vals[i] << std::endl; if ((i < 5) && (vals[i] != SzCache::cSzCacheNoData)) throw std::logic_error("Assertion failed!"); if ((i > 5) && (vals[i] != 85)) throw std::logic_error("Assertion failed!"); } std::cout << std::endl; vals.clear(); wtime = szc.writeData(vals, t7-50, t7+50, szp1); while( wtime < t7+50 ) wtime = szc.writeData(vals, wtime, t7+50, szp1); std::cout << "writeData(" << t7-50 << "," << t7+50 << "):\n"; for (unsigned int i = 0; i < vals.size(); i++) { std::cout << vals[i] << std::endl; if ((i < 5) && (vals[i] != 85)) throw std::logic_error("Assertion failed!"); if ((i > 5) && (vals[i] != SzCache::cSzCacheNoData)) throw std::logic_error("Assertion failed!"); } std::cout << std::endl; vals.clear(); } catch (std::logic_error& le) { removeSzCacheFile("TestA/TestB/TestC/201501.szc"); removeSzCacheFile("TestA/TestB/TestC/201502.szc"); removeSzCacheFile("TestA/TestB/TestC/201503.szc"); removeTestTree(); std::cout << "Assertion has failed!" << std::endl; return -1; } std::cout << "All assertions valid: Test PASSED" << std::endl; /** Remove test environ */ removeSzCacheFile("TestA/TestB/TestC/201501.szc"); removeSzCacheFile("TestA/TestB/TestC/201502.szc"); removeSzCacheFile("TestA/TestB/TestC/201503.szc"); removeTestTree(); return 0; }
SaErrorT show_event_log(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid, int show_short, hpi_ui_print_cb_t proc) { SaErrorT rv = SA_OK; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEventLogInfoT info; SaHpiEventLogEntryIdT entryid; SaHpiEventLogEntryIdT nextentryid; SaHpiEventLogEntryIdT preventryid; SaHpiEventLogEntryT sel; SaHpiRdrT rdr; char buf[1024]; char date[30], date1[30]; rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiRptEntryGet error = %s\n", oh_lookup_error(rv)); proc(buf); return rv; }; if (rptentry.ResourceId == resourceid) { if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG) break; else { proc("ERROR: The designated resource hasn't SEL.\n"); return rv; } }; rptentryid = nextrptentryid; } if (rptentryid == SAHPI_LAST_ENTRY) { snprintf(buf, 1024, "ERROR: no resource for resourceId = %d\n", resourceid); proc(buf); return rv; } rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiEventLogInfoGet error = %s\n", oh_lookup_error(rv)); proc(buf); return -1; } snprintf(buf, 1024, "EventLog: entries = %d, size = %d, enabled = %d\n", info.Entries, info.Size, info.Enabled); proc(buf); time2str(info.UpdateTimestamp, date, 30); time2str(info.CurrentTime, date1, 30); snprintf(buf, 1024, "UpdateTime = %s CurrentTime = %s Overflow = %d\n", date, date1, info.OverflowFlag); proc(buf); if (info.Entries != 0){ entryid = SAHPI_OLDEST_ENTRY; while (entryid != SAHPI_NO_MORE_ENTRIES) { rv = saHpiEventLogEntryGet(sessionid, resourceid, entryid, &preventryid, &nextentryid, &sel, &rdr, NULL); if (rv != SA_OK) { snprintf(buf, 1024, "ERROR: saHpiEventLogEntryGet error = %s\n", oh_lookup_error(rv)); proc(buf); return -1; }; if (show_short) show_short_event(&(sel.Event)); else oh_print_eventlogentry(&sel, 1); preventryid = entryid; entryid = nextentryid; } } else { snprintf(buf, 1024, "SEL is empty\n"); proc(buf); }; return SA_OK; }
int msaReportWebLineAjaxSubmit(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead) { ltDbCursor *tempCursor; LT_DBROW tempRow; ltDbHeadPtr dbPtr; ltTablePtr tablePtr; char sqlBuf[1024]; char caSdate[32],caEdate[32],caSdate1[32],caSdate2[32]; char *reportname=NULL; char *email=NULL; char *lt_page_content=NULL; char *work=NULL; char caTempDir[256]; char responseDir[256]; char caLabel[256]; char strdayflow[32]; char htmlpage[256]; unsigned long long lMaxBytes=1; unsigned long tmpDir=0; unsigned long fileName=0; long lTime,lTime1,lTime2; int iFd=-1; int srvindex,step; step=0; memset(htmlpage,0,sizeof(htmlpage)); memset(caLabel,0,sizeof(caLabel)); memset(caTempDir,0,sizeof(caTempDir)); memset(responseDir,0,sizeof(responseDir)); char *dbUser; char *dbPass; char *dbName; dbName=_ltPubInfo->_dbname; dbUser=_ltPubInfo->_dbuser; dbPass=_ltPubInfo->_dbpass; G_DbCon=ltDbConnect(dbUser,dbPass,dbName); if(G_DbCon==NULL) { return 0; } if(ltMsgGetVar_s(ltMsgPk,"sdate")) { sprintf(caSdate,"%s",ltMsgGetVar_s(ltMsgPk,"sdate")); } else { sprintf(caSdate,"%s",""); } if(ltMsgGetVar_s(ltMsgPk,"edate")) { sprintf(caEdate,"%s",ltMsgGetVar_s(ltMsgPk,"edate")); } else { sprintf(caEdate,"%s",""); } if(ltMsgGetVar_s(ltMsgPk,"reportname")) { reportname=ltMsgGetVar_s(ltMsgPk,"reportname"); } if(ltMsgGetVar_s(ltMsgPk,"email")) { email=ltMsgGetVar_s(ltMsgPk,"email"); } if(ltMsgGetVar_s(ltMsgPk,"step")) { step=atoi(ltMsgGetVar_s(ltMsgPk,"step")); } if(ltMsgGetVar_s(ltMsgPk,"work")) { work=ltMsgGetVar_s(ltMsgPk,"work"); } if(ltMsgGetVar_s(ltMsgPk,"filedir")) { fileName=atoll(ltMsgGetVar_s(ltMsgPk,"filedir")); } if(fileName==0) { tmpDir=ltStrGetId(); sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_webreport,tmpDir); sprintf(responseDir,"%lu",tmpDir); printf("caTempDir:%s\n",caTempDir); if(ltFileIsExist(caTempDir)!=1) { if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) { ltMsgPk->msgpktype=1; lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0"); ltMsgFree(ltMsgPk); return 0; } } } else { sprintf(caTempDir,"%s%s/%lu/",_datacenterdir,_webreport,fileName); sprintf(responseDir,"%lu",fileName); } lTime = time(0); if(!ltStrIsSpaces(caSdate)) { lTime1 = nasCvtLongTime(caSdate,"00:00:00"); } else { lTime1 = 0; } if(!ltStrIsSpaces(caEdate)) { lTime2 = nasCvtLongTime(caEdate,"23:59:59"); } else { lTime2 = 0; } if(lTime1 == 0) { lTime1 = lTime; } if(lTime2 == 0) { lTime2 = lTime; } if(lTime1 > lTime) { lTime1 = lTime; } if(lTime2>lTime) { lTime2=lTime; } char sDate[64],sTime[64]; char caFile1[256]; char caCmd[256]; int fdwrite=0; nasTimeGetDate(caSdate1,lTime); nasCvtStime(time(0),sDate,sTime); sprintf(caFile1,"%sinfo.ini",caTempDir); fdwrite = open(caFile1, O_APPEND | O_WRONLY | O_CREAT, 0644); if(fdwrite == (-1)) { ltMsgPk->msgpktype=1; lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"0"); ltMsgFree(ltMsgPk); return 0; } sprintf(caCmd,"date=%s_%s\n",sDate,sTime); write(fdwrite,caCmd,strlen(caCmd)); sprintf(caCmd,"reportname=%s\n",reportname); write(fdwrite,caCmd,strlen(caCmd)); close(fdwrite); sprintf(caLabel,"/bin/echo '1' > %sproccess.ini",caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/right-top-d.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/right-top.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/banner.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/up-1.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/up-2.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); sprintf(caLabel,"/bin/cp %s%s/up-3.jpg %s",_msahtmldir,_weblineplt,caTempDir); system(caLabel); ltMsgPk->msgpktype=1; lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,responseDir); nasTimeGetDate(caSdate1,lTime1); nasTimeGetDate(caSdate2,lTime2); if(step==1) { //网址分类排序 sprintf(sqlBuf,"select urlsort,sum(bytes) as abyte from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by urlsort order by abyte desc ",caSdate1,caSdate2,work); } else if(step==2) { //网址流量排序 sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msauserhttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by abyte asc",caSdate1,caSdate2,work); } else if(step==3) { //top30流量人员网址访问 sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msauserhttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by abyte asc limit %d offset 0",caSdate1,caSdate2,work,30); } else if(step==4) { //网址访问次数排序 sprintf(sqlBuf,"select host,sum(bytes) as abyte,sum(lcount) as acount,sum(ctime) as ctime from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by host order by acount desc",caSdate1,caSdate2,work); } else if(step==5) { //网址分类访问次数排序 sprintf(sqlBuf,"select urlsort,sum(bytes) as abyte,sum(lcount) as acount from msahttpreport where sdate>='%s' and sdate<='%s' and workflag=%s group by urlsort order by acount desc ",caSdate1,caSdate2,work); } printf("sql:%s\n",sqlBuf); tempCursor = ltDbOpenCursor(G_DbCon,sqlBuf); if(tempCursor == NULL) { sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","数据库错误,无法生成报告",caTempDir); system(caLabel); ltMsgFree(ltMsgPk); return 0; } srvindex=1; lMaxBytes=1; dbPtr=lt_dbinit(); lt_db_htmlpage(dbPtr,"utf-8"); tablePtr=lt_dbput_table(dbPtr,"list"); tempRow= ltDbFetchRow(tempCursor); while(tempRow!=NULL) { if(step==1) { if(atoll(tempRow[1])>1024000) { sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00); } else { sprintf(strdayflow,"%0.3fKB",atoll(tempRow[1])/1024.00); } lt_dbput_recordvars(tablePtr,2, "urlsort",LT_TYPE_STRING,_ltPubInfo->ltService[atol(tempRow[0])].srvName, "lbyte",LT_TYPE_STRING,strdayflow ); printf("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"); } else if(step==2) { if(atoll(tempRow[1])>1024000) { sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00); } else { sprintf(strdayflow,"%0.3fKB",atoll(tempRow[1])/1024.00); } lt_dbput_recordvars(tablePtr,2, "host",LT_TYPE_STRING,tempRow[0], "lbyte",LT_TYPE_STRING,strdayflow ); } else if(step==3) { if(atoll(tempRow[1])>1024000) { sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00); } else { sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00); } // if(lMaxBytes<atoll(tempRow[1])){ // lMaxBytes=atoll(tempRow[1]); // } lt_dbput_recordvars(tablePtr,4, "host",LT_TYPE_STRING,tempRow[0], "srvljflow",LT_TYPE_STRING,strdayflow, "srvlcount",LT_TYPE_STRING,tempRow[2], "srvljtime",LT_TYPE_STRING,time2str(atoi(tempRow[3])) ); } else if(step==4) { if(atoll(tempRow[1])>1024000) { sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00); } else { sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00); } if(lMaxBytes<atoll(tempRow[1])) { lMaxBytes=atoll(tempRow[1]); } lt_dbput_recordvars(tablePtr,4, "host",LT_TYPE_STRING,tempRow[0], "srvljflow",LT_TYPE_STRING,strdayflow, "srvlcount",LT_TYPE_STRING,tempRow[2], "srvljtime",LT_TYPE_STRING,time2str(atoi(tempRow[3])) ); } else if(step==5) { if(atoll(tempRow[1])>1024000) { sprintf(strdayflow,"%0.3fM",atoll(tempRow[1])/1024000.00); } else { sprintf(strdayflow,"%0.3fK",atoll(tempRow[1])/1024.00); } if(lMaxBytes<atoll(tempRow[1])) { lMaxBytes=atoll(tempRow[1]); } lt_dbput_recordvars(tablePtr,3, "sorname",LT_TYPE_STRING,_ltPubInfo->ltService[atol(tempRow[0])].srvName, "srvljflow",LT_TYPE_STRING,strdayflow, "srvlcount",LT_TYPE_STRING,tempRow[2] ); } if(step==1) { srvindex++; } tempRow=ltDbFetchRow(tempCursor);//移动光标 } ltDbCloseCursor(tempCursor); // if(step==1){//画图 // close(iFd); // sprintf(caLabel,"%s/Scripts/onlinesrv-bar.pl %sdata.ini %ssrvreport.gif %llu ",_msahtmldir,caTempDir,caTempDir,lMaxBytes); //柱状 饼图:onlinesrv1.pl // system(caLabel); // lt_dbput_rootvars(dbPtr,1,"piechart","srvreport.gif" ); // } lt_dbput_rootvars(dbPtr,3,"reportname",reportname,"bdate",caSdate1,"edate",caSdate2); sprintf(htmlpage,"%s%s/webflow%d.htm",_msahtmldir,_weblineplt,step); printf("%s\n",htmlpage); lt_page_content=ltPltFileParse(htmlpage,dbPtr->doc,0); if(lt_page_content==NULL) { printf("11111111111111111111111111\n"); sprintf(caLabel,"/bin/echo '%s' > %serrmsg.ini","无报告数据,无法生成报告",caTempDir); system(caLabel);/*建立目录和正在处理标志*/ ltMsgFree(ltMsgPk); lt_dbfree(dbPtr); return 0; } else { printf("22222222222222222222222222\n"); lt_page_content=strstr(lt_page_content,"<!DOCTYPE"); if(step==1) { sprintf(caLabel,"%sindex.htm",caTempDir); } else { sprintf(caLabel,"%spage%d.htm",caTempDir,step); } iFd = open(caLabel,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); if(iFd >0) { write(iFd,lt_page_content,strlen(lt_page_content)); } close(iFd); } if(step==5) { sprintf(caLabel,"%s/Scripts/html2mail %s index.htm %sindex.mht report %s",_msahtmldir,caTempDir,caTempDir,email); system(caLabel); } chdir(caTempDir); system("rm -f report.tgz"); system("tar -cvzf report.tgz *"); sprintf(caLabel,"/bin/rm %sproccess.ini",caTempDir); system(caLabel); sprintf(caLabel,"/bin/rm %serrmsg.ini",caTempDir); system(caLabel); ltMsgFree(ltMsgPk); lt_dbfree(dbPtr); return 0; }
void get_table_time_stamp(MockClient &client, const uint64_t major_version) { int64_t time_stamp = 0; int err = client.get_table_time_stamp(major_version, time_stamp, timeout); fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err); if (OB_SUCCESS == err) { fprintf(stdout, "major_version=%lu time_stamp=%ld %s\n", major_version, time_stamp, time2str(time_stamp)); } }
/* raim fde (failure detection and exclution) -------------------------------*/ static int raim_fde(const obsd_t *obs, int n, const double *rs, const double *dts, const double *vare, const int *svh, const nav_t *nav, const prcopt_t *opt, sol_t *sol, double *azel, int *vsat, double *resp, char *msg) { obsd_t *obs_e; sol_t sol_e={{0}}; char tstr[32],name[16],msg_e[128]; double *rs_e,*dts_e,*vare_e,*azel_e,*resp_e,rms_e,rms=100.0; int i,j,k,nvsat,stat=0,*svh_e,*vsat_e,sat=0; trace(3,"raim_fde: %s n=%2d\n",time_str(obs[0].time,0),n); if (!(obs_e=(obsd_t *)malloc(sizeof(obsd_t)*n))) return 0; rs_e = mat(6,n); dts_e = mat(2,n); vare_e=mat(1,n); azel_e=zeros(2,n); svh_e=imat(1,n); vsat_e=imat(1,n); resp_e=mat(1,n); for (i=0;i<n;i++) { /* satellite exclution */ for (j=k=0;j<n;j++) { if (j==i) continue; obs_e[k]=obs[j]; matcpy(rs_e +6*k,rs +6*j,6,1); matcpy(dts_e+2*k,dts+2*j,2,1); vare_e[k]=vare[j]; svh_e[k++]=svh[j]; } /* estimate receiver position without a satellite */ if (!estpos(obs_e,n-1,rs_e,dts_e,vare_e,svh_e,nav,opt,&sol_e,azel_e, vsat_e,resp_e,msg_e)) { trace(3,"raim_fde: exsat=%2d (%s)\n",obs[i].sat,msg); continue; } for (j=nvsat=0,rms_e=0.0;j<n-1;j++) { if (!vsat_e[j]) continue; rms_e+=SQR(resp_e[j]); nvsat++; } if (nvsat<5) { trace(3,"raim_fde: exsat=%2d lack of satellites nvsat=%2d\n", obs[i].sat,nvsat); continue; } rms_e=sqrt(rms_e/nvsat); trace(3,"raim_fde: exsat=%2d rms=%8.3f\n",obs[i].sat,rms_e); if (rms_e>rms) continue; /* save result */ for (j=k=0;j<n;j++) { if (j==i) continue; matcpy(azel+2*j,azel_e+2*k,2,1); vsat[j]=vsat_e[k]; resp[j]=resp_e[k++]; } stat=1; *sol=sol_e; sat=obs[i].sat; rms=rms_e; vsat[i]=0; strcpy(msg,msg_e); } if (stat) { time2str(obs[0].time,tstr,2); satno2id(sat,name); trace(2,"%s: %s excluded by raim\n",tstr+11,name); } free(obs_e); free(rs_e ); free(dts_e ); free(vare_e); free(azel_e); free(svh_e); free(vsat_e); free(resp_e); return stat; }
/* set approx position -------------------------------------------------------*/ static void setapppos(strfile_t *str, rnxopt_t *opt) { prcopt_t prcopt=prcopt_default; sol_t sol={{0}}; char msg[128]; prcopt.navsys=opt->navsys; /* point positioning with last obs data */ #ifdef WAAS_STUDY if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL, NULL,msg)) { #else if (!pntpos(str->obs->data,str->obs->n,str->nav,&prcopt,&sol,NULL,NULL, msg)) { #endif trace(2,"point position error (%s)\n",msg); return; } matcpy(opt->apppos,sol.rr,3,1); } /* show status message -------------------------------------------------------*/ static int showstat(int sess, gtime_t ts, gtime_t te, int *n) { const char type[]="ONGHQLSE"; char msg[1024]="",*p=msg,s[64]; int i; if (sess>0) { p+=sprintf(p,"(%d) ",sess); } if (ts.time!=0) { time2str(ts,s,0); p+=sprintf(p,"%s",s); } if (te.time!=0&&timediff(te,ts)>0.9) { time2str(te,s,0); p+=sprintf(p,"-%s",s+5); } p+=sprintf(p,": "); for (i=0;i<NOUTFILE+1;i++) { if (n[i]==0) continue; p+=sprintf(p,"%c=%d%s",type[i],n[i],i<NOUTFILE?" ":""); } return showmsg(msg); } /* rinex converter for single-session ----------------------------------------*/ static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file, char **ofile) { FILE *ofp[NOUTFILE]={NULL}; strfile_t *str; gtime_t ts={0},te={0},tend={0},time={0}; unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}}; int i,j,nf,type,n[NOUTFILE+1]={0},abort=0; char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024]; char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000"; trace(3,"convrnx_s: sess=%d format=%d file=%s ofile=%s %s %s %s %s %s %s\n", sess,format,file,ofile[0],ofile[1],ofile[2],ofile[3],ofile[4], ofile[5],ofile[6]); /* replace keywords in input file */ if (reppath(file,path,opt->ts,staid,"")<0) { showmsg("no time for input file: %s",file); return 0; } /* expand wild-cards in input file */ for (i=0;i<MAXEXFILE;i++) { if (!(epath[i]=(char *)malloc(1024))) { for (i=0;i<MAXEXFILE;i++) free(epath[i]); return 0; } } nf=expath(path,epath,MAXEXFILE); if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) time=opt->trtcm; if (opt->scanobs) { /* scan observation types */ if (!scan_obstype(format,epath[0],opt,&time)) return 0; } else { /* set observation types by format */ set_obstype(format,opt); } if (!(str=gen_strfile(format,opt->rcvopt,time))) { for (i=0;i<MAXEXFILE;i++) free(epath[i]); return 0; } time=opt->ts.time?opt->ts:(time.time?timeadd(time,TSTARTMARGIN):time); /* replace keywords in output file */ for (i=0;i<NOUTFILE;i++) { paths[i]=s[i]; if (reppath(ofile[i],paths[i],time,staid,"")<0) { showmsg("no time for output path: %s",ofile[i]); for (i=0;i<MAXEXFILE;i++) free(epath[i]); free_strfile(str); return 0; } } /* open output files */ if (!openfile(ofp,paths,path,opt,str->nav)) { for (i=0;i<MAXEXFILE;i++) free(epath[i]); free_strfile(str); return 0; } for (i=0;i<nf&&!abort;i++) { /* open stream file */ if (!open_strfile(str,epath[i])) continue; /* input message */ for (j=0;(type=input_strfile(str))>=-1;j++) { if (j%11==1&&(abort=showstat(sess,te,te,n))) break; /* avioid duplicated if overlapped data */ if (tend.time&&timediff(str->time,tend)<=0.0) continue; /* convert message */ switch (type) { case 1: convobs(ofp,opt,str,n,slips); break; case 2: convnav(ofp,opt,str,n); break; case 3: convsbs(ofp,opt,str,n); break; case 31: convlex(ofp,opt,str,n); break; case -1: n[NOUTFILE]++; break; /* error */ } te=str->time; if (ts.time==0) ts=te; /* set approx position */ if (type==1&&!opt->autopos&&norm(opt->apppos,3)<=0.0) { setapppos(str,opt); } if (opt->te.time&&timediff(te,opt->te)>10.0) break; } /* close stream file */ close_strfile(str); tend=te; /* end time of a file */ } /* set receiver and antenna information to option */ if (format==STRFMT_RTCM2||format==STRFMT_RTCM3) { rtcm2opt(&str->rtcm,opt); } else if (format==STRFMT_RINEX) { rnx2opt(&str->rnx,opt); } /* close output files */ closefile(ofp,opt,str->nav); /* remove empty output files */ for (i=0;i<NOUTFILE;i++) { if (ofp[i]&&n[i]<=0) remove(ofile[i]); } if (ts.time>0) showstat(sess,ts,te,n); for (i=0;i<MAXEXFILE;i++) free(epath[i]); free_strfile(str); if (opt->tstart.time==0) opt->tstart=opt->ts; if (opt->tend .time==0) opt->tend =opt->te; return abort?-1:1; }
const char *print_obj(const ObObj &obj) { static const int64_t BUFFER_SIZE = 128 * 1024; static __thread char buffers[2][BUFFER_SIZE]; static __thread int64_t i = 0; char *buffer = buffers[i++ % 2]; buffer[0] = '\0'; switch (obj.get_type()) { case ObNullType: snprintf(buffer, BUFFER_SIZE, "obj_type=null"); break; case ObIntType: { bool is_add = false; int64_t tmp = 0; obj.get_int(tmp, is_add); snprintf(buffer, BUFFER_SIZE, "obj_type=int value=%ld is_add=%s", tmp, STR_BOOL(is_add)); } break; case ObDateTimeType: { bool is_add = false; ObDateTime tmp = 0; obj.get_datetime(tmp, is_add); snprintf(buffer, BUFFER_SIZE, "obj_type=data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add)); } break; case ObPreciseDateTimeType: { bool is_add = false; ObDateTime tmp = 0; obj.get_precise_datetime(tmp, is_add); snprintf(buffer, BUFFER_SIZE, "obj_type=precise_data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add)); } break; case ObVarcharType: { ObString tmp; obj.get_varchar(tmp); if (NULL != tmp.ptr() && 0 != tmp.length() && !str_isprint(tmp.ptr(), tmp.length())) { char hex_buffer[BUFFER_SIZE] = {'\0'}; common::hex_to_str(tmp.ptr(), tmp.length(), hex_buffer, BUFFER_SIZE); snprintf(buffer, BUFFER_SIZE, "obj_type=var_char value=[0x %s] value_ptr=%p value_length=%d", hex_buffer, tmp.ptr(), tmp.length()); } else { snprintf(buffer, BUFFER_SIZE, "obj_type=var_char value=[%.*s] value_ptr=%p value_length=%d", tmp.length(), tmp.ptr(), tmp.ptr(), tmp.length()); } } break; case ObSeqType: snprintf(buffer, BUFFER_SIZE, "obj_type=seq"); break; case ObCreateTimeType: { ObCreateTime tmp = 0; obj.get_createtime(tmp); snprintf(buffer, BUFFER_SIZE, "obj_type=create_time value=%s", time2str(tmp)); } break; case ObModifyTimeType: { ObModifyTime tmp = 0; obj.get_modifytime(tmp); snprintf(buffer, BUFFER_SIZE, "obj_type=modify_time value=%s", time2str(tmp)); } break; case ObExtendType: { int64_t tmp = 0; obj.get_ext(tmp); snprintf(buffer, BUFFER_SIZE, "obj_type=extend value=%ld", tmp); } break; default: break; } return buffer; }
/* * Used when converting result from a query */ int val2str(MYSQL* _c, db_val_t* _v, char* _s, int* _len) { int l; char* old_s; if (!_c || !_v || !_s || !_len || !*_len) { LOG(L_ERR, "val2str: Invalid parameter value\n"); return -1; } if (VAL_NULL(_v)) { if (*_len < sizeof("NULL")) { LOG(L_ERR, "val2str: Buffer too small\n"); return -1; } *_len = snprintf(_s, *_len, "NULL"); return 0; } switch(VAL_TYPE(_v)) { case DB_INT: if (int2str(VAL_INT(_v), _s, _len) < 0) { LOG(L_ERR, "val2str: Error while converting string to int\n"); return -2; } else { return 0; } break; case DB_BITMAP: if (int2str(VAL_BITMAP(_v), _s, _len) < 0) { LOG(L_ERR, "val2str: Error while converting string to int\n"); return -3; } else { return 0; } break; case DB_DOUBLE: if (double2str(VAL_DOUBLE(_v), _s, _len) < 0) { LOG(L_ERR, "val2str: Error while converting string to double\n"); return -4; } else { return 0; } break; case DB_STRING: l = strlen(VAL_STRING(_v)); if (*_len < (l * 2 + 3)) { LOG(L_ERR, "val2str: Destination buffer too short\n"); return -5; } else { old_s = _s; *_s++ = '\''; _s += mysql_real_escape_string(_c, _s, VAL_STRING(_v), l); *_s++ = '\''; *_s = '\0'; /* FIXME */ *_len = _s - old_s; return 0; } break; case DB_STR: l = VAL_STR(_v).len; if (*_len < (l * 2 + 3)) { LOG(L_ERR, "val2str: Destination buffer too short\n"); return -6; } else { old_s = _s; *_s++ = '\''; _s += mysql_real_escape_string(_c, _s, VAL_STR(_v).s, l); *_s++ = '\''; *_s = '\0'; *_len = _s - old_s; return 0; } break; case DB_DATETIME: if (time2str(VAL_TIME(_v), _s, _len) < 0) { LOG(L_ERR, "val2str: Error while converting string to time_t\n"); return -7; } else { return 0; } break; case DB_BLOB: l = VAL_BLOB(_v).len; if (*_len < (l * 2 + 3)) { LOG(L_ERR, "val2str: Destination buffer too short\n"); return -8; } else { old_s = _s; *_s++ = '\''; _s += mysql_escape_string(_s, VAL_STR(_v).s, l); *_s++ = '\''; *_s = '\0'; *_len = _s - old_s; return 0; } break; default: DBG("val2str: Unknown data type\n"); return -9; } /*return -8; --not reached*/ }
int main(int argc, const char *const *argv) { int mode = 1; const char *const *arg, *psl_file = NULL, *cookie_domain = NULL; psl_ctx_t *psl = (psl_ctx_t *) psl_builtin(); /* set current locale according to the environment variables */ #include <locale.h> setlocale(LC_ALL, ""); for (arg = argv + 1; arg < argv + argc; arg++) { if (!strncmp(*arg, "--", 2)) { if (!strcmp(*arg, "--is-public-suffix")) mode = 1; else if (!strcmp(*arg, "--print-unreg-domain")) mode = 2; else if (!strcmp(*arg, "--print-reg-domain")) mode = 3; else if (!strcmp(*arg, "--print-info")) mode = 99; else if (!strcmp(*arg, "--is-cookie-domain-acceptable") && arg < argv + argc - 1) { mode = 4; cookie_domain = *(++arg); } else if (!strcmp(*arg, "--use-builtin-data")) { psl_free(psl); if (psl_file) { fprintf(stderr, "Dropped data from %s\n", psl_file); psl_file = NULL; } if (!(psl = (psl_ctx_t *) psl_builtin())) printf("No builtin PSL data available\n"); } else if (!strcmp(*arg, "--load-psl-file") && arg < argv + argc - 1) { psl_free(psl); if (psl_file) { fprintf(stderr, "Dropped data from %s\n", psl_file); psl_file = NULL; } if (!(psl = psl_load_file(psl_file = *(++arg)))) { fprintf(stderr, "Failed to load PSL data from %s\n\n", psl_file); psl_file = NULL; } } else if (!strcmp(*arg, "--help")) { fprintf(stdout, "`psl' explores the Public Suffix List\n\n"); usage(0, stdout); } else if (!strcmp(*arg, "--version")) { printf("psl %s\n", PACKAGE_VERSION); printf("libpsl %s\n", psl_get_version()); printf("\n"); printf("Copyright (C) 2014-2015 Tim Ruehsen\n"); printf("License: MIT\n"); exit(0); } else if (!strcmp(*arg, "--")) { arg++; break; } else { fprintf(stderr, "Unknown option '%s'\n", *arg); usage(1, stderr); } } else break; } if (mode != 99) { if (!psl) { fprintf(stderr, "No PSL data available - aborting\n"); exit(2); } if (arg >= argv + argc) { char buf[256], *domain, *lower; size_t len; psl_error_t rc; /* read URLs from STDIN */ while (fgets(buf, sizeof(buf), stdin)) { for (domain = buf; isspace(*domain); domain++); /* skip leading spaces */ if (*domain == '#' || !*domain) continue; /* skip empty lines and comments */ for (len = strlen(domain); len && isspace(domain[len - 1]); len--); /* skip trailing spaces */ domain[len] = 0; if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &lower)) != PSL_SUCCESS) fprintf(stderr, "%s: Failed to convert to lowercase UTF-8 (%d)\n", domain, rc); else if (mode == 1) printf("%s: %d (%s)\n", domain, psl_is_public_suffix(psl, lower), lower); else if (mode == 2) printf("%s: %s\n", domain, psl_unregistrable_domain(psl, lower)); else if (mode == 3) printf("%s: %s\n", domain, psl_registrable_domain(psl, lower)); else if (mode == 4) { char *cookie_domain_lower; if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &cookie_domain_lower)) != PSL_SUCCESS) fprintf(stderr, "%s: Failed to convert cookie domain '%s' to lowercase UTF-8 (%d)\n", domain, cookie_domain, rc); else printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, lower, cookie_domain)); free(cookie_domain_lower); } free(lower); } psl_free(psl); exit(0); } } if (mode == 1) { for (; arg < argv + argc; arg++) printf("%s: %d\n", *arg, psl_is_public_suffix(psl, *arg)); } else if (mode == 2) { for (; arg < argv + argc; arg++) printf("%s: %s\n", *arg, psl_unregistrable_domain(psl, *arg)); } else if (mode == 3) { for (; arg < argv + argc; arg++) printf("%s: %s\n", *arg, psl_registrable_domain(psl, *arg)); } else if (mode == 4) { for (; arg < argv + argc; arg++) printf("%s: %d\n", *arg, psl_is_cookie_domain_acceptable(psl, *arg, cookie_domain)); } else if (mode == 99) { if (psl && psl != psl_builtin()) { printf("suffixes: %d\n", psl_suffix_count(psl)); printf("exceptions: %d\n", psl_suffix_exception_count(psl)); printf("wildcards: %d\n", psl_suffix_wildcard_count(psl)); } psl_free(psl); psl = (psl_ctx_t *) psl_builtin(); if (psl) { printf("builtin suffixes: %d\n", psl_suffix_count(psl)); printf("builtin exceptions: %d\n", psl_suffix_exception_count(psl)); printf("builtin wildcards: %d\n", psl_suffix_wildcard_count(psl)); printf("builtin filename: %s\n", psl_builtin_filename()); printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time())); printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time())); printf("builtin SHA1 file hash: %s\n", psl_builtin_sha1sum()); } else printf("No builtin PSL data available\n"); } psl_free(psl); return 0; }
// convert file ------------------------------------------------------------- void __fastcall TMainWindow::ConvertFile(void) { rnxopt_t rnxopt={0}; AnsiString InFile_Text=InFile->Text; AnsiString OutFile1_Text=OutFile1->Text,OutFile2_Text=OutFile2->Text; AnsiString OutFile3_Text=OutFile3->Text,OutFile4_Text=OutFile4->Text; AnsiString OutFile5_Text=OutFile5->Text,OutFile6_Text=OutFile6->Text; AnsiString OutFile7_Text=OutFile7->Text; int i,format,sat; char file[1024]="",*ofile[7],ofile_[7][1024]={""},msg[256],*p; char buff[256],tstr[32]; double RNXVER[]={2.10,2.11,2.12,3.00,3.01,3.02}; FILE *fp; // abort conversion if (BtnConvert->Caption=="Abort") { abortf=1; return; } for (i=0;i<7;i++) ofile[i]=ofile_[i]; // recognize input file format strcpy(file,InFile_Text.c_str()); if (!(p=strrchr(file,'.'))) p=file; if (Format->ItemIndex==0) { // auto if (!strcmp(p,".rtcm2")) format=STRFMT_RTCM2; else if (!strcmp(p,".rtcm3")) format=STRFMT_RTCM3; else if (!strcmp(p,".gps" )) format=STRFMT_OEM4; else if (!strcmp(p,".ubx" )) format=STRFMT_UBX; else if (!strcmp(p,".log" )) format=STRFMT_SS2; else if (!strcmp(p,".bin" )) format=STRFMT_CRES; else if (!strcmp(p,".jps" )) format=STRFMT_JAVAD; else if (!strcmp(p,".bnx" )) format=STRFMT_BINEX; else if (!strcmp(p,".binex")) format=STRFMT_BINEX; else if (!strcmp(p,".rt17" )) format=STRFMT_RT17; else if (!strcmp(p,".obs" )) format=STRFMT_RINEX; else if (!strcmp(p,".OBS" )) format=STRFMT_RINEX; else if (!strcmp(p,".nav" )) format=STRFMT_RINEX; else if (!strcmp(p,".NAV" )) format=STRFMT_RINEX; else if (!strcmp(p+2,"nav" )) format=STRFMT_RINEX; else if (!strcmp(p+2,"NAV" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"o" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"O" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"n" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"N" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"p" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"P" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"g" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"G" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"h" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"H" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"q" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"Q" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"l" )) format=STRFMT_RINEX; else if (!strcmp(p+3,"L" )) format=STRFMT_RINEX; else { showmsg("file format can not be recognized"); return; } } else { for (i=0;formatstrs[i];i++) { if (Format->Text==formatstrs[i]) break; } if (formatstrs[i]) format=i; else return; } rnxopt.rnxver=RNXVER[RnxVer]; if (format==STRFMT_RTCM2||format==STRFMT_RTCM3||format==STRFMT_RT17) { // input start date/time for rtcm 2 ro rtcm 3 if (StartDialog->ShowModal()!=mrOk) return; rnxopt.trtcm=StartDialog->Time; } if (OutFile1->Enabled&&OutFileEna1->Checked) strcpy(ofile[0],OutFile1_Text.c_str()); if (OutFile2->Enabled&&OutFileEna2->Checked) strcpy(ofile[1],OutFile2_Text.c_str()); if (OutFile3->Enabled&&OutFileEna3->Checked) strcpy(ofile[2],OutFile3_Text.c_str()); if (OutFile4->Enabled&&OutFileEna4->Checked) strcpy(ofile[3],OutFile4_Text.c_str()); if (OutFile5->Enabled&&OutFileEna5->Checked) strcpy(ofile[4],OutFile5_Text.c_str()); if (OutFile6->Enabled&&OutFileEna6->Checked) strcpy(ofile[5],OutFile6_Text.c_str()); if (OutFile7->Enabled&&OutFileEna7->Checked) strcpy(ofile[6],OutFile7_Text.c_str()); // check overwrite output file for (i=0;i<6;i++) { if (!*ofile[i]||!(fp=fopen(ofile[i],"r"))) continue; fclose(fp); ConfDialog->Label2->Caption=ofile[i]; if (ConfDialog->ShowModal()!=mrOk) return; } GetTime(&rnxopt.ts,&rnxopt.te,&rnxopt.tint,&rnxopt.tunit); strncpy(rnxopt.staid,RnxCode.c_str(),31); sprintf(rnxopt.prog,"%s %s",PRGNAME,VER_RTKLIB); strncpy(rnxopt.runby,RunBy.c_str(),31); strncpy(rnxopt.marker,Marker.c_str(),63); strncpy(rnxopt.markerno,MarkerNo.c_str(),31); strncpy(rnxopt.markertype,MarkerType.c_str(),31); for (i=0;i<2;i++) strncpy(rnxopt.name[i],Name[i].c_str(),31); for (i=0;i<3;i++) strncpy(rnxopt.rec [i],Rec [i].c_str(),31); for (i=0;i<3;i++) strncpy(rnxopt.ant [i],Ant [i].c_str(),31); if (AutoPos) { for (i=0;i<3;i++) rnxopt.apppos[i]=AppPos[i]; } for (i=0;i<3;i++) rnxopt.antdel[i]=AntDel[i]; strncpy(rnxopt.rcvopt,RcvOption.c_str(),255); rnxopt.navsys=NavSys; rnxopt.obstype=ObsType; rnxopt.freqtype=FreqType; p=rnxopt.comment[0]; sprintf(p,"log: %-53.53s",file); p=rnxopt.comment[1]; p+=sprintf(p,"format: %s",formatstrs[format]); if (*rnxopt.rcvopt) sprintf(p,", option: %s",rnxopt.rcvopt); for (i=0;i<2;i++) strncpy(rnxopt.comment[i+2],Comment[i].c_str(),63); for (i=0;i<6;i++) strcpy(rnxopt.mask[i],CodeMask[i].c_str()); rnxopt.autopos=AutoPos; rnxopt.scanobs=ScanObs; rnxopt.outiono=OutIono; rnxopt.outtime=OutTime; rnxopt.outleaps=OutLeaps; strcpy(buff,ExSats.c_str()); for (p=strtok(buff," ");p;p=strtok(NULL," ")) { if (!(sat=satid2no(p))) continue; rnxopt.exsats[sat-1]=1; } abortf=0; BtnConvert ->Caption="Abort"; Panel1 ->Enabled=false; Panel2 ->Enabled=false; BtnPlot ->Enabled=false; BtnPost ->Enabled=false; BtnOptions ->Enabled=false; BtnExit ->Enabled=false; Format ->Enabled=false; BtnKey ->Enabled=false; LabelInFile ->Enabled=false; LabelOutDir ->Enabled=false; LabelOutFile->Enabled=false; LabelFormat ->Enabled=false; Message ->Caption=""; if (TraceLevel>0) { traceopen(TRACEFILE); tracelevel(TraceLevel); } // convert to rinex (void)convrnx(format,&rnxopt,file,ofile); if (TraceLevel>0) { traceclose(); } BtnConvert ->Caption="&Convert"; Panel1 ->Enabled=true; Panel2 ->Enabled=true; BtnPlot ->Enabled=true; BtnPost ->Enabled=true; BtnOptions ->Enabled=true; BtnExit ->Enabled=true; Format ->Enabled=true; BtnKey ->Enabled=true; LabelInFile ->Enabled=true; LabelOutDir ->Enabled=true; LabelOutFile->Enabled=true; LabelFormat ->Enabled=true; #if 0 // set time-start/end if time not specified if (!TimeStartF->Checked&&rnxopt.tstart.time!=0) { time2str(rnxopt.tstart,tstr,0); tstr[10]='\0'; TimeY1->Text=tstr; TimeH1->Text=tstr+11; } if (!TimeEndF->Checked&&rnxopt.tend.time!=0) { time2str(rnxopt.tend,tstr,0); tstr[10]='\0'; TimeY2->Text=tstr; TimeH2->Text=tstr+11; } #endif RnxTime=rnxopt.tstart; AddHist(InFile); }
static int32_t mccdaq_callback(uint16_t * d, int32_t max_d) { #define MAX_DATA 1000000 static uint16_t data[MAX_DATA]; static int32_t max_data; static int32_t idx; static uint64_t time_last; static uint16_t pulse_threshold = PULSE_THRESHOLD_NOT_SET; DEBUG("max_data=%d\n", max_data); // keep track of total samples received total_samples_rcvd += max_d; // if mode is PLOT then plot the value; // mode_arg is the number of samples to plot, when this // becomes zero then set mode to IDLE if (mode == PLOT) { int32_t i; for (i = 0; i < max_d; i++) { if (mode_arg <= 0) { mode_arg = 0; mode = IDLE; break; } print_plot_str(d[i], PULSE_THRESHOLD_NOT_SET); mode_arg--; } } // copy received data to array large enough for one second of data if (max_data + max_d > MAX_DATA) { FATAL("too much data %d+%d > %d\n", max_data, max_d, MAX_DATA); } memcpy(data+max_data, d, max_d*sizeof(uint16_t)); max_data += max_d; // determine pule threshold ... // // if there is less than 1000 samples of data available for this second then // return because we want 1000 or more samples to determine the pule_threshold // else if pulse_threshold is not set then // determine the minimum he3 adc value for the 1000 samples, and // set pulse_threshold to that baseline value plus 8 // endif if (max_data < 1000) { return 0; } else if (pulse_threshold == PULSE_THRESHOLD_NOT_SET) { int32_t i; int32_t baseline = 1000000000; for (i = 0; i < 1000; i++) { if (data[i] < baseline) { baseline = data[i]; } } pulse_threshold = baseline + 8; DEBUG("pulse_threshold-2048=%d\n", pulse_threshold-2048); } // search for pulses in the data // - when pulse is found determine // . pulse_start_idx, pulse_end_idx // . pulse_height // . pulse_chan // . pulse_count[MAX_CHANNEL] // - if mode is PULSEMON then // plot the pulse and print pulse height // endif bool in_a_pulse = false; int32_t pulse_start_idx = -1; int32_t pulse_end_idx = -1; while (true) { // terminate this loop when // - near the end of data and not processing a pulse OR // - at the end of data if ((!in_a_pulse && idx >= max_data-10) || (idx == max_data)) { break; } // print warning if data out of range if (data[idx] > 4095) { WARN("data[%d] = %u, is out of range\n", idx, data[idx]); data[idx] = 2048; } // determine the pulse_start_idx and pulse_end_idx if (data[idx] >= pulse_threshold && !in_a_pulse) { in_a_pulse = true; pulse_start_idx = idx; } else if (data[idx] < pulse_threshold && in_a_pulse) { in_a_pulse = false; pulse_end_idx = idx - 1; } // if a pulse has been located ... if (pulse_end_idx != -1) { int32_t pulse_height, pulse_channel; int32_t i; // scan from start to end of pulse to determine pulse_height pulse_height = -1; for (i = pulse_start_idx; i <= pulse_end_idx; i++) { if (data[i] - pulse_threshold > pulse_height) { pulse_height = data[i] - pulse_threshold; } } // determine pulse_channel from pulse_height pulse_channel = pulse_height / ((4096 - pulse_threshold) / MAX_CHANNEL); if (pulse_channel >= MAX_CHANNEL) { WARN("chan being reduced from %d to %d\n", pulse_channel, MAX_CHANNEL-1); pulse_channel = MAX_CHANNEL-1; } // keep track of pulse_count __sync_fetch_and_add(&pulse_count[pulse_channel], 1); // if mode is PULSEMON then plot this pulse if (mode == PULSEMON) { char time_str[MAX_TIME_STR]; printf("%s: pulse: height=%d channel=%d threshold-2048=%d\n", time2str(time_str, get_real_time_us(), false, true, true), pulse_height, pulse_channel, pulse_threshold-2048); for (i = pulse_start_idx; i <= pulse_end_idx; i++) { print_plot_str(data[i], pulse_threshold); } printf("\n"); } // done with this pulse pulse_start_idx = -1; pulse_end_idx = -1; } // move to next data idx++; } // if time has incremented from last time this code block was run then ... uint64_t time_now = time(NULL); if (time_now > time_last) { int32_t chan; // if mode equal INFO then print stats if (mode == INFO) { int64_t duration_secs = time_now - pulse_time_start; printf("time=%d samples=%d mccdaq_restarts=%d pulse_threshold-2048=%d\n", (int32_t)duration_secs, max_data, mccdaq_get_restart_count(), pulse_threshold-2048); printf(" counts = "); for (chan = 0; chan < MAX_CHANNEL; chan++) { printf("%8d ", pulse_count[chan]); } printf("\n"); printf(" cpm = "); for (chan = 0; chan < MAX_CHANNEL; chan++) { printf("%8.2f ", pulse_count[chan] / (duration_secs / 60.0)); } printf("\n"); printf("\n"); } // reset for next second of data time_last = time_now; max_data = 0; idx = 0; pulse_threshold = PULSE_THRESHOLD_NOT_SET; } // if sigint then set mode to IDLE if (sigint) { sigint = false; mode = IDLE; mode_arg = 0; } // return 0, so scanning continues return 0; }
/* ===================================================================*/ void mode_Update() { int position; char str[40]; surfaceT sur; windowT win; if (standby) { // not needed in standby mode return; } for (sur = TOPSIDE; sur <= BOTTOMSIDE; sur++) { for (win = UPPER; win <= LOWER; win++) { clear_display(sur, win); position = 0; switch (displayMode[sur][win]) { case CYCLOCOMPUTER: switch (cycloMode[sur][win]) { case MAXIMUMSPEED: speed2str(maxSpeed, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case AVERAGESPEED: speed2str(avgSpeed, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case CURRENTALTITUDE: altitude2str(currAltitude, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TRIPELEVATIONGAIN: altitude2str(tripElevationGain, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TOTALELEVATIONGAIN: altitude2str(totalElevationGain, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case MAXALTITUDE: altitude2str(maxAltitude, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case INCLINE: break; case TEMPERATURE: temperature2str(temperature, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TRIPDISTANCE: distance2str(tripDistance, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TOTALDISTANCE: distance2str(totalDistance, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TRIPTIME: time2str(tripTime, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case CURRENTTIME: realtime2str(str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case CURRENTDATE: realdate2str(str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case TOTALTIME: time2str(totalTime, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case CHRONOTIME: time2str(chronoTime, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; case CURRENTSPEED: // fall through default: speed2str(currSpeed, str); position = put_str(str, DOS7x12b, displayColor[sur][win], 0, sur, win); break; } // switch break; case STRING: put_str(displayString[sur][win], DOS7x12b, displayColor[sur][win], 0, sur, win); break; case IMAGE: put_Image(displayImage[sur][win], 0, sur, win); break; case LIGHT: // puts_12x16("\333\333\333\333\333\333\333\333", front ? WHITE : RED, 0, sur, win); break; case BLANK: put_str(".", DOS5x12, displayColor[sur][win], 0, sur, win); break; } // switch } // for switch (displayMode[sur][BLING]) { case IMAGE: blingOn[sur] = TRUE; put_Image(displayImage[sur][BLING], 0, sur, BLING); break; case STRING: blingOn[sur] = TRUE; put_str(displayString[sur][BLING], DOS7x12b, displayColor[sur][BLING], 0, sur, BLING); break; case BLANK: // fall through default: // all others are also blank blingOn[sur] = FALSE; break; } } }
/* Data Access Object (DAO) */ static pdb_t dao (int cmd, FILE *f, pdb_t in_db, sort sortby) { pdb_t *pdb=NULL,rec=NULL,hd=NULL; int i=0,ret; char buf[100]; switch (cmd) { case CREATE: fprintf (f,"\"%s\",",in_db->title); fprintf (f,"\"%s\",",in_db->first_name); fprintf (f,"\"%s\",",in_db->last_name); fprintf (f,"\"%s\",",time2str(&in_db->date)); fprintf (f,"\"%s\" \n",in_db->publ); break; case PRINT: for (;in_db;i++) { printf ("Title : %s\n", in_db->title); printf ("Author : %s %s\n", in_db->first_name, in_db->last_name); printf ("Date : %s\n", time2str(&in_db->date)); printf ("Publication : %s\n\n", in_db->publ); if (!((i+1)%3)) { printf ("Press Enter to continue.\n"); ret = scanf ("%*[^\n]"); if (ret<0) return rec; /* handle EOF */ else getchar(); } in_db=in_db->next; } break; case READLINE: if((fscanf(f," \"%[^\"]\",",in_db->title ))<0)break; if((fscanf(f," \"%[^\"]\",",in_db->first_name))<0)break; if((fscanf(f," \"%[^\"]\",",in_db->last_name ))<0)break; if((fscanf(f," \"%[^\"]\",",buf ))<0)break; if((fscanf(f," \"%[^\"]\" ",in_db->publ ))<0)break; in_db->date=str2time (buf); break; case READ: while (!feof(f)) { dao (READLINE,f,in_db,NULL); TRY (rec=malloc(sizeof(db_t))); *rec=*in_db; /* copy contents */ rec->next=hd;/* to linked list */ hd=rec;i++; } if (i<2) { puts ("Empty database. Please create some entries."); fclose (f); exit (0); } break; case SORT: rec=in_db; for (;in_db;i++) in_db=in_db->next; TRY (pdb=malloc(i*sizeof(pdb_t))); in_db=rec; for (i=0;in_db;i++) { pdb[i]=in_db; in_db=in_db->next; } qsort (pdb,i,sizeof in_db,sortby); pdb[i-1]->next=NULL; for (i=i-1;i;i--) { pdb[i-1]->next=pdb[i]; } rec=pdb[0]; FREE (pdb); pdb=NULL; break; case DESTROY: { while ((rec=in_db)) { in_db=in_db->next; FREE (rec); } } } return rec; }
void query_info_print (void) { int i; char buf[1024]; FILE *fp_res, *fp_q; #ifdef TEST FILE *fp_tag, *fp_ne; #endif char minstr[64], maxstr[64], avgstr[64]; int xml_found; #ifdef MT_MODE MUTEX_LOCK (query_info_mutex); #endif fp_res = fopen (LOG_TOP_RES_FILE, "w"); fp_q = fopen (LOG_TOP_Q_FILE, "w"); #ifdef TEST fp_tag = fopen (LOG_TOP_TAG_FILE, "w"); fp_ne = fopen (LOG_TOP_NE_FILE, "w"); #endif if (fp_res == NULL || fp_q == NULL #ifdef TEST || fp_tag == NULL || fp_ne == NULL #endif ) { fprintf (stderr, "%s\n", strerror (errno)); goto query_info_print_end; } qsort (query_info_arr, num_query_info, sizeof (T_QUERY_INFO), sort_func); if (log_top_mode == MODE_PROC_TIME) fprintf (fp_res, "%8s %8s %9s %9s %10s\n", "", "max", "min", "avg", "cnt(err)"); else fprintf (fp_res, "%8s %8s %10s\n", "", "max", "cnt"); fprintf (fp_res, "-----------------------------------------------------\n"); for (i = 0; i < num_query_info; i++) { sprintf (buf, "[Q%d]", i + 1); if (log_top_mode == MODE_PROC_TIME) { fprintf (fp_res, "%-8s %9s %9s %9s %4d (%d)", buf, time2str (query_info_arr[i].max, maxstr), time2str (query_info_arr[i].min, minstr), time2str (query_info_arr[i].sum / query_info_arr[i].count, avgstr), query_info_arr[i].count, query_info_arr[i].err_count); } else { fprintf (fp_res, "%-8s %8d %10d", buf, query_info_arr[i].max, query_info_arr[i].count); } fprintf (fp_q, "%s-------------------------------------------\n", buf); xml_found = sql_info_write (query_info_arr[i].sql, buf, fp_q); if (xml_found) { fprintf (fp_res, "%5s", "X"); } fprintf (fp_res, "\n"); fwrite (query_info_arr[i].cas_log, query_info_arr[i].cas_log_len, 1, fp_q); fprintf (fp_q, "\n"); #ifdef TEST fprintf (fp_tag, "Q%d %s /^%s\n", i + 1, LOG_TOP_Q_FILE, buf); #endif } #ifdef TEST for (i = 0; i < num_query_info_ne; i++) { sprintf (buf, "[N%d]", i + 1); fprintf (fp_ne, "%s-------------------------------------------\n", buf); if (sql_info_write (query_info_arr_ne[i].sql, buf, fp_ne) < 0) { break; } fprintf (fp_ne, "%s\n", query_info_arr_ne[i].cas_log); } #endif fclose (fp_res); fclose (fp_q); #ifdef TEST fclose (fp_tag); fclose (fp_ne); #endif #ifdef TEST sprintf (buf, "sort %s -o %s", LOG_TOP_TAG_FILE, LOG_TOP_TAG_FILE); system (buf); #endif query_info_print_end: #ifdef MT_MODE MUTEX_UNLOCK (query_info_mutex); #endif return; }
/* decode NVS xf5-raw: raw measurement data ----------------------------------*/ static int decode_xf5raw(raw_t *raw) { gtime_t time; double tadj=0.0,toff=0.0,tn; int dTowInt; double dTowUTC, dTowGPS, dTowFrac, L1, P1, D1; double gpsutcTimescale; unsigned char rcvTimeScaleCorr, sys, carrNo; int i,j,prn,sat,n=0,nsat,week; unsigned char *p=raw->buff+2; char *q,tstr[32],flag; trace(4,"decode_xf5raw: len=%d\n",raw->len); /* time tag adjustment option (-TADJ) */ if ((q=strstr(raw->opt,"-tadj"))) { sscanf(q,"-TADJ=%lf",&tadj); } dTowUTC =R8(p); week = U2(p+8); gpsutcTimescale = R8(p+10); /* glonassutcTimescale = R8(p+18); */ rcvTimeScaleCorr = I1(p+26); /* check gps week range */ if (week>=4096) { trace(2,"nvs xf5raw obs week error: week=%d\n",week); return -1; } week=adjgpsweek(week); if ((raw->len - 31)%30) { /* Message length is not correct: there could be an error in the stream */ trace(2,"nvs xf5raw len=%d seems not be correct\n",raw->len); return -1; } nsat = (raw->len - 31)/30; dTowGPS = dTowUTC + gpsutcTimescale; /* Tweak pseudoranges to allow Rinex to represent the NVS time of measure */ dTowInt = 10.0*floor((dTowGPS/10.0)+0.5); dTowFrac = dTowGPS - (double) dTowInt; time=gpst2time(week, dTowInt*0.001); /* time tag adjustment */ if (tadj>0.0) { tn=time2gpst(time,&week)/tadj; toff=(tn-floor(tn+0.5))*tadj; time=timeadd(time,-toff); } /* check time tag jump */ if (raw->time.time&&fabs(timediff(time,raw->time))>86400.0) { time2str(time,tstr,3); trace(2,"nvs xf5raw time tag jump error: time=%s\n",tstr); return 0; } if (fabs(timediff(time,raw->time))<=1e-3) { time2str(time,tstr,3); trace(2,"nvs xf5raw time tag duplicated: time=%s\n",tstr); return 0; } for (i=0,p+=27;(i<nsat) && (n<MAXOBS); i++,p+=30) { raw->obs.data[n].time = time; sys = (U1(p)==1)?SYS_GLO:((U1(p)==2)?SYS_GPS:((U1(p)==4)?SYS_SBS:SYS_NONE)); prn = U1(p+1); if (sys == SYS_SBS) prn += 120; /* Correct this */ if (!(sat=satno(sys,prn))) { trace(2,"nvs xf5raw satellite number error: sys=%d prn=%d\n",sys,prn); continue; } carrNo = I1(p+2); L1 = R8(p+ 4); P1 = R8(p+12); D1 = R8(p+20); /* check range error */ if (L1<-1E10||L1>1E10||P1<-1E10||P1>1E10||D1<-1E5||D1>1E5) { trace(2,"nvs xf5raw obs range error: sat=%2d L1=%12.5e P1=%12.5e D1=%12.5e\n", sat,L1,P1,D1); continue; } raw->obs.data[n].SNR[0]=(unsigned char)(I1(p+3)*4.0+0.5); if (sys==SYS_GLO) { raw->obs.data[n].L[0] = L1 - toff*(FREQ1_GLO+DFRQ1_GLO*carrNo); } else { raw->obs.data[n].L[0] = L1 - toff*FREQ1; } raw->obs.data[n].P[0] = (P1-dTowFrac)*CLIGHT*0.001 - toff*CLIGHT; /* in ms, needs to be converted */ raw->obs.data[n].D[0] = (float)D1; /* set LLI if meas flag 4 (carrier phase present) off -> on */ flag=U1(p+28); raw->obs.data[n].LLI[0]=(flag&0x08)&&!(raw->halfc[sat-1][0]&0x08)?1:0; raw->halfc[sat-1][0]=flag; #if 0 if (raw->obs.data[n].SNR[0] > 160) { time2str(time,tstr,3); trace(2,"%s, obs.data[%d]: SNR=%.3f LLI=0x%02x\n", tstr, n, (raw->obs.data[n].SNR[0])/4.0, U1(p+28) ); } #endif raw->obs.data[n].code[0] = CODE_L1C; raw->obs.data[n].sat = sat; for (j=1;j<NFREQ+NEXOBS;j++) { raw->obs.data[n].L[j]=raw->obs.data[n].P[j]=0.0; raw->obs.data[n].D[j]=0.0; raw->obs.data[n].SNR[j]=raw->obs.data[n].LLI[j]=0; raw->obs.data[n].code[j]=CODE_NONE; } n++; } raw->time=time; raw->obs.n=n; return 1; }
//--------------------------------------------------------------------------- void __fastcall TOptDialog::SaveOpt(AnsiString file) { AnsiString ProxyAddrE_Text=ProxyAddrE->Text; AnsiString ExSatsE_Text=ExSatsE->Text; AnsiString FieldSep_Text=FieldSep->Text; AnsiString RovAnt_Text=RovAnt->Text,RefAnt_Text=RefAnt->Text; AnsiString SatPcvFile_Text=SatPcvFile->Text; AnsiString AntPcvFile_Text=AntPcvFile->Text; AnsiString StaPosFile_Text=StaPosFile->Text; AnsiString GeoidDataFile_Text=GeoidDataFile->Text; AnsiString DCBFile_Text=DCBFile->Text; AnsiString LocalDir_Text=LocalDir->Text; int itype[]={STR_SERIAL,STR_TCPCLI,STR_TCPSVR,STR_NTRIPCLI,STR_FILE,STR_FTP,STR_HTTP}; int otype[]={STR_SERIAL,STR_TCPCLI,STR_TCPSVR,STR_NTRIPSVR,STR_FILE}; TEdit *editu[]={RovPos1,RovPos2,RovPos3}; TEdit *editr[]={RefPos1,RefPos2,RefPos3}; char buff[1024],*p,id[32],comment[256],s[64]; int sat,ex; prcopt_t prcopt=prcopt_default; solopt_t solopt=solopt_default; filopt_t filopt={""}; for (int i=0;i<8;i++) { strtype[i]=i<3?itype[MainForm->Stream[i]]:otype[MainForm->Stream[i]]; strfmt[i]=MainForm->Format[i]; if (!MainForm->StreamC[i]) { strtype[i]=STR_NONE; strcpy(strpath[i],""); } else if (strtype[i]==STR_SERIAL) { strcpy(strpath[i],MainForm->Paths[i][0].c_str()); } else if (strtype[i]==STR_FILE) { strcpy(strpath[i],MainForm->Paths[i][2].c_str()); } else if (strtype[i]<=STR_NTRIPCLI) { strcpy(strpath[i],MainForm->Paths[i][1].c_str()); } else if (strtype[i]<=STR_HTTP) { strcpy(strpath[i],MainForm->Paths[i][3].c_str()); } } nmeareq =MainForm->NmeaReq; nmeapos[0]=MainForm->NmeaPos[0]; nmeapos[1]=MainForm->NmeaPos[1]; svrcycle =SvrCycleE ->Text.ToInt(); timeout =TimeoutTimeE->Text.ToInt(); reconnect =ReconTimeE ->Text.ToInt(); nmeacycle =NmeaCycleE ->Text.ToInt(); buffsize =SvrBuffSizeE->Text.ToInt(); navmsgsel =NavSelectS ->ItemIndex; strcpy(proxyaddr,ProxyAddrE_Text.c_str()); fswapmargin =FileSwapMarginE->Text.ToInt(); prcopt.sbassatsel=SbasSatE->Text.ToInt(); prcopt.mode =PosMode ->ItemIndex; prcopt.nf =Freq ->ItemIndex+1; prcopt.soltype =Solution ->ItemIndex; prcopt.elmin =str2dbl(ElMask ->Text)*D2R; prcopt.dynamics =DynamicModel->ItemIndex; prcopt.tidecorr =TideCorr ->ItemIndex; prcopt.ionoopt =IonoOpt ->ItemIndex; prcopt.tropopt =TropOpt ->ItemIndex; prcopt.sateph =SatEphem ->ItemIndex; if (ExSatsE->Text!="") { strcpy(buff,ExSatsE_Text.c_str()); for (p=strtok(buff," ");p;p=strtok(NULL," ")) { if (*p=='+') {ex=2; p++;} else ex=1; if (!(sat=satid2no(p))) continue; prcopt.exsats[sat-1]=ex; } } prcopt.navsys = (NavSys1->Checked?SYS_GPS:0)| (NavSys2->Checked?SYS_GLO:0)| (NavSys3->Checked?SYS_GAL:0)| (NavSys4->Checked?SYS_QZS:0)| (NavSys5->Checked?SYS_SBS:0)| (NavSys6->Checked?SYS_CMP:0); prcopt.posopt[0]=PosOpt1->Checked; prcopt.posopt[1]=PosOpt2->Checked; prcopt.posopt[2]=PosOpt3->Checked; prcopt.posopt[3]=PosOpt4->Checked; prcopt.posopt[4]=PosOpt5->Checked; prcopt.modear =AmbRes ->ItemIndex; prcopt.glomodear=GloAmbRes ->ItemIndex; prcopt.thresar[0]=str2dbl(ValidThresAR->Text); prcopt.maxout =str2dbl(OutCntResetAmb->Text); prcopt.minfix =str2dbl(FixCntHoldAmb->Text); prcopt.minlock =str2dbl(LockCntFixAmb->Text); prcopt.elmaskar =str2dbl(ElMaskAR ->Text)*D2R; prcopt.elmaskhold=str2dbl(ElMaskHold->Text)*D2R; prcopt.maxtdiff =str2dbl(MaxAgeDiff ->Text); prcopt.maxgdop =str2dbl(RejectGdop ->Text); prcopt.maxinno =str2dbl(RejectThres->Text); prcopt.thresslip=str2dbl(SlipThres ->Text); prcopt.niter =str2dbl(NumIter ->Text); prcopt.syncsol =SyncSol->ItemIndex; if (prcopt.mode==PMODE_MOVEB&&BaselineConst->Checked) { prcopt.baseline[0]=str2dbl(BaselineLen->Text); prcopt.baseline[1]=str2dbl(BaselineSig->Text); } solopt.posf =SolFormat ->ItemIndex; solopt.timef =TimeFormat ->ItemIndex==0?0:1; solopt.times =TimeFormat ->ItemIndex==0?0:TimeFormat->ItemIndex-1; solopt.timeu =str2dbl(TimeDecimal ->Text); solopt.degf =LatLonFormat->ItemIndex; strcpy(solopt.sep,FieldSep_Text.c_str()); solopt.outhead =OutputHead ->ItemIndex; solopt.outopt =OutputOpt ->ItemIndex; solopt.datum =OutputDatum ->ItemIndex; solopt.height =OutputHeight->ItemIndex; solopt.geoid =OutputGeoid ->ItemIndex; solopt.nmeaintv[0]=str2dbl(NmeaIntv1->Text); solopt.nmeaintv[1]=str2dbl(NmeaIntv2->Text); solopt.trace =DebugTrace ->ItemIndex; solopt.sstat =DebugStatus ->ItemIndex; prcopt.eratio[0]=str2dbl(MeasErrR1->Text); prcopt.eratio[1]=str2dbl(MeasErrR2->Text); prcopt.err[1] =str2dbl(MeasErr2->Text); prcopt.err[2] =str2dbl(MeasErr3->Text); prcopt.err[3] =str2dbl(MeasErr4->Text); prcopt.err[4] =str2dbl(MeasErr5->Text); prcopt.sclkstab =str2dbl(SatClkStab->Text); prcopt.prn[0] =str2dbl(PrNoise1->Text); prcopt.prn[1] =str2dbl(PrNoise2->Text); prcopt.prn[2] =str2dbl(PrNoise3->Text); prcopt.prn[3] =str2dbl(PrNoise4->Text); prcopt.prn[4] =str2dbl(PrNoise5->Text); if (RovAntPcv->Checked) strcpy(prcopt.anttype[0],RovAnt_Text.c_str()); if (RefAntPcv->Checked) strcpy(prcopt.anttype[1],RefAnt_Text.c_str()); prcopt.antdel[0][0]=str2dbl(RovAntE->Text); prcopt.antdel[0][1]=str2dbl(RovAntN->Text); prcopt.antdel[0][2]=str2dbl(RovAntU->Text); prcopt.antdel[1][0]=str2dbl(RefAntE->Text); prcopt.antdel[1][1]=str2dbl(RefAntN->Text); prcopt.antdel[1][2]=str2dbl(RefAntU->Text); prcopt.rovpos=RovPosTypeP->ItemIndex<3?0:4; prcopt.refpos=RefPosTypeP->ItemIndex<3?0:4; if (prcopt.rovpos==0) GetPos(RovPosTypeP->ItemIndex,editu,prcopt.ru); if (prcopt.refpos==0) GetPos(RefPosTypeP->ItemIndex,editr,prcopt.rb); strcpy(filopt.satantp,SatPcvFile_Text.c_str()); strcpy(filopt.rcvantp,AntPcvFile_Text.c_str()); strcpy(filopt.stapos, StaPosFile_Text.c_str()); strcpy(filopt.geoid, GeoidDataFile_Text.c_str()); strcpy(filopt.dcb, DCBFile_Text.c_str()); strcpy(filopt.tempdir,LocalDir_Text.c_str()); time2str(utc2gpst(timeget()),s,0); sprintf(comment,"RTKNAVI options (%s, v.%s)",s,VER_RTKLIB); setsysopts(&prcopt,&solopt,&filopt); if (!saveopts(file.c_str(),"w",comment,sysopts)|| !saveopts(file.c_str(),"a","",rcvopts)) return; }
void *Mergetime(void *argument) { int streamID1, streamID2 = CDI_UNDEFID; int tsID2 = 0, recID, varID, levelID; int vlistID1, vlistID2; int nfiles, fileID; int taxisID1, taxisID2 = CDI_UNDEFID; int lcopy = FALSE; int gridsize; int nmiss; int vdate, vtime; int last_vdate = -1, last_vtime = -1; int next_fileID; int skip_same_time = FALSE; int process_timestep; const char *ofilename; double *array = NULL; typedef struct { int streamID; int vlistID; int taxisID; int tsID; int vdate; int vtime; int nrecs; } sfile_t; sfile_t *sf = NULL; cdoInitialize(argument); { char *envstr; envstr = getenv("SKIP_SAME_TIME"); if ( envstr ) { int ival; ival = atoi(envstr); if ( ival == 1 ) { skip_same_time = TRUE; if ( cdoVerbose ) cdoPrint("Set SKIP_SAME_TIME to %d", ival); } } } if ( UNCHANGED_RECORD ) lcopy = TRUE; nfiles = cdoStreamCnt() - 1; sf = (sfile_t*) malloc(nfiles*sizeof(sfile_t)); for ( fileID = 0; fileID < nfiles; fileID++ ) { if ( cdoVerbose ) cdoPrint("process: %s", cdoStreamName(fileID)->args); streamID1 = streamOpenRead(cdoStreamName(fileID)); vlistID1 = streamInqVlist(streamID1); taxisID1 = vlistInqTaxis(vlistID1); sf[fileID].streamID = streamID1; sf[fileID].vlistID = vlistID1; sf[fileID].taxisID = taxisID1; } /* check that the contents is always the same */ for ( fileID = 1; fileID < nfiles; fileID++ ) vlistCompare(sf[0].vlistID, sf[fileID].vlistID, CMP_ALL); /* read the first time step */ for ( fileID = 0; fileID < nfiles; fileID++ ) { sf[fileID].tsID = 0; sf[fileID].nrecs = streamInqTimestep(sf[fileID].streamID, sf[fileID].tsID); if ( sf[fileID].nrecs == 0 ) { streamClose(sf[fileID].streamID); sf[fileID].streamID = -1; } else { sf[fileID].vdate = taxisInqVdate(sf[fileID].taxisID); sf[fileID].vtime = taxisInqVtime(sf[fileID].taxisID); } } ofilename = cdoStreamName(nfiles)->args; if ( !cdoSilentMode && !cdoOverwriteMode ) if ( fileExists(ofilename) ) if ( !userFileOverwrite(ofilename) ) cdoAbort("Outputfile %s already exists!", ofilename); streamID2 = streamOpenWrite(cdoStreamName(nfiles), cdoFiletype()); if ( ! lcopy ) { gridsize = vlistGridsizeMax(sf[0].vlistID); array = (double*) malloc(gridsize*sizeof(double)); } while ( TRUE ) { process_timestep = TRUE; next_fileID = -1; vdate = 0; vtime = 0; for ( fileID = 0; fileID < nfiles; fileID++ ) { if ( sf[fileID].streamID != -1 ) if ( next_fileID == -1 || sf[fileID].vdate < vdate || (sf[fileID].vdate == vdate && sf[fileID].vtime < vtime) ) { next_fileID = fileID; vdate = sf[fileID].vdate; vtime = sf[fileID].vtime; } } fileID = next_fileID; if ( cdoVerbose ) cdoPrint("nextstep = %d vdate = %d vtime = %d", next_fileID, vdate, vtime); if ( next_fileID == -1 ) break; if ( skip_same_time ) if ( vdate == last_vdate && vtime == last_vtime ) { char vdatestr[32], vtimestr[32]; date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); cdoPrint("Timestep %4d in stream %d (%s %s) already exists, skipped!", sf[fileID].tsID+1, sf[fileID].streamID, vdatestr, vtimestr); process_timestep = FALSE; } if ( process_timestep ) { if ( tsID2 == 0 ) { vlistID1 = sf[0].vlistID; vlistID2 = vlistDuplicate(vlistID1); taxisID1 = vlistInqTaxis(vlistID1); taxisID2 = taxisDuplicate(taxisID1); vlistDefTaxis(vlistID2, taxisID2); streamDefVlist(streamID2, vlistID2); } last_vdate = vdate; last_vtime = vtime; taxisCopyTimestep(taxisID2, sf[fileID].taxisID); streamDefTimestep(streamID2, tsID2); for ( recID = 0; recID < sf[fileID].nrecs; recID++ ) { streamInqRecord(sf[fileID].streamID, &varID, &levelID); streamDefRecord(streamID2, varID, levelID); if ( lcopy ) { streamCopyRecord(streamID2, sf[fileID].streamID); } else { streamReadRecord(sf[fileID].streamID, array, &nmiss); streamWriteRecord(streamID2, array, nmiss); } } tsID2++; } sf[fileID].nrecs = streamInqTimestep(sf[fileID].streamID, ++sf[fileID].tsID); if ( sf[fileID].nrecs == 0 ) { streamClose(sf[fileID].streamID); sf[fileID].streamID = -1; } else { sf[fileID].vdate = taxisInqVdate(sf[fileID].taxisID); sf[fileID].vtime = taxisInqVtime(sf[fileID].taxisID); } } streamClose(streamID2); if ( ! lcopy ) if ( array ) free(array); if ( sf ) free(sf); cdoFinish(); return (0); }
void parse_cmd_line(int argc, char **argv, CmdLineParam &clp) { int opt = 0; const char* opt_string = "a:p:o:t:f:s:n:z:i:r:l:q:c:e:m:u:w:g:khx:T:C:A:"; struct option longopts[] = { {"serv_addr", 1, NULL, 'a'}, {"serv_port", 1, NULL, 'p'}, {"login_type", 1, NULL, 'o'}, {"cmd_type", 1, NULL, 't'}, {"ini_fname", 1, NULL, 'f'}, {"timestamp", 1, NULL, 's'}, {"session", 1, NULL, 'n'}, {"time2str", 1, NULL, 'z'}, {"ip2str", 1, NULL, 'i'}, {"version_range", 1, NULL, 'r'}, {"memory_limit", 1, NULL, 'l'}, {"priv_queue_conf", 1, NULL, 'q'}, {"active_limit", 1, NULL, 'c'}, {"expect_result", 1, NULL, 'e'}, {"schema", 1, NULL, 'm'}, {"username", 1, NULL, 'u'}, {"password", 1, NULL, 'w'}, {"log_level", 1, NULL, 'g'}, {"quickly_exit", 1, NULL, 'k'}, {"help", 0, NULL, 'h'}, {"query", 1, NULL, 'x'}, {"timeout", 1, NULL, 'T'}, {"config", 1, NULL, 'g'}, {0, 0, 0, 0} }; memset(&clp, 0, sizeof(clp)); clp.serv_addr = (char*)"localhost"; clp.serv_port = 2700; clp.login_type = (char*)"direct"; clp.timeout = 0; while ((opt = getopt_long(argc, argv, opt_string, longopts, NULL)) != -1) { switch (opt) { case 'a': clp.serv_addr = optarg; break; case 'p': clp.serv_port = atoi(optarg); break; case 'o': clp.login_type = optarg; break; case 't': clp.cmd_type = optarg; break; case 'f': clp.ini_fname = optarg; break; case 's': clp.timestamp = atol(optarg); break; case 'n': clp.session_id = atol(optarg); break; case 'r': clp.version_range = optarg; break; case 'l': clp.memory_limit = optarg; break; case 'q': clp.priv_queue_conf = optarg; break; case 'c': clp.memtable_limit = optarg; break; case 'z': { int64_t timestamp = atol(optarg); fprintf(stdout, "timestamp=%ld str=%s\n", timestamp, time2str(timestamp)); exit(1); } case 'i': { int64_t ip = atoll(optarg); fprintf(stdout, "ip=%ld str=%s\n", ip, tbsys::CNetUtil::addrToString(ip).c_str()); exit(1); } case 'e': clp.expected_result_fname = optarg; break; case 'm': clp.schema_fname = optarg; break; case 'u': clp.username = optarg; break; case 'w': clp.password = optarg; break; case 'g': clp.log_level = optarg; break; case 'x': clp.sql_query = optarg; break; case 'k': clp.quickly_exit = true; break; case 'T': clp.timeout = atol(optarg); break; case 'A': { updateserver::ObUpdateServerConfig conf; fprintf(stdout, "\n"); conf.auto_config_memory(atol(optarg)); exit(1); } case 'C': { updateserver::ObUpdateServerConfig conf; fprintf(stdout, "\n"); conf.auto_config_memory(conf.get_total_memory_limit(atol(optarg))); exit(1); } break; case 'h': default: print_usage(); exit(1); } } if (NULL == clp.serv_addr || 0 == clp.serv_port || NULL == clp.cmd_type || (NULL == clp.ini_fname && 0 == strcmp("apply", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("scan", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("total_scan", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("get", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("param_get", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("umount_store", clp.cmd_type)) || (NULL == clp.version_range && 0 == strcmp("scan", clp.cmd_type)) || (NULL == clp.version_range && 0 == strcmp("total_scan", clp.cmd_type)) || (NULL == clp.version_range && 0 == strcmp("get", clp.cmd_type)) || (0 == clp.session_id && 0 == strcmp("kill_session", clp.cmd_type)) || (0 == clp.session_id && 0 == strcmp("ups_kill_session", clp.cmd_type)) || (0 == clp.timestamp && 0 == strcmp("get_bloomfilter", clp.cmd_type)) || (0 == clp.timestamp && 0 == strcmp("fetch_schema", clp.cmd_type)) || (0 == clp.timestamp && 0 == clp.session_id && 0 == strcmp("get_sstable_range_list", clp.cmd_type)) || (0 == clp.timestamp && 0 == strcmp("get_table_time_stamp", clp.cmd_type)) || (0 == clp.timestamp && 0 == strcmp("reload_store", clp.cmd_type)) || (NULL == clp.log_level && 0 == strcmp("change_log_level", clp.cmd_type)) || (NULL == clp.sql_query && 0 == strcmp("sql_query", clp.cmd_type)) ) { print_usage(); fprintf(stdout, "serv_addr=%s serv_port=%d cmd_type=%s ini_fname=%s timestamp=%ld version_range=%s\n", clp.serv_addr, clp.serv_port, clp.cmd_type, clp.ini_fname, clp.timestamp, clp.version_range); exit(-1); } if ((NULL == clp.ini_fname && 0 == strcmp("print_scanner", clp.cmd_type)) || (NULL == clp.ini_fname && 0 == strcmp("print_schema", clp.cmd_type))) { print_usage(); fprintf(stdout, "cmd_type=%s ini_fname=%s\n", clp.cmd_type, clp.ini_fname); exit(-1); } if(NULL != clp.expected_result_fname && NULL == clp.schema_fname) { print_usage(); fprintf(stdout, "-e and -m must appear together"); exit(-1); } }
void *Tinfo(void *argument) { int vdate_first = 0, vtime_first = 0; int vdate0 = 0, vtime0 = 0; int vdate = 0, vtime = 0; int fdate = 0, ftime = 0; int nrecs, ntsteps; int tsID = 0, ntimeout; int taxisID; int streamID; int vlistID; int year0, month0, day0; int year, month, day; int calendar, unit; int lforecast = FALSE; int incperiod0 = 0, incunit0 = 0; int incperiod = 0, incunit = 0; int its = 0, igap; int ngaps = 0; int ntsm[MAX_GAPS]; int rangetsm[MAX_GAPS][2]; int vdatem[MAX_GAPS][MAX_NTSM]; int vtimem[MAX_GAPS][MAX_NTSM]; juldate_t juldate, juldate0; double jdelta = 0, jdelta0 = 0; int arrow = 0; int i, len; char vdatestr[32], vtimestr[32]; cdoInitialize(argument); streamID = streamOpenRead(cdoStreamName(0)); vlistID = streamInqVlist(streamID); fprintf(stdout, "\n"); taxisID = vlistInqTaxis(vlistID); ntsteps = vlistNtsteps(vlistID); if ( ntsteps != 0 ) { if ( ntsteps == CDI_UNDEFID ) fprintf(stdout, " Time axis : unlimited steps\n"); else fprintf(stdout, " Time axis : %d step%s\n", ntsteps, ntsteps == 1 ? "" : "s"); if ( taxisID != CDI_UNDEFID ) { if ( taxisInqType(taxisID) != TAXIS_ABSOLUTE ) { vdate = taxisInqRdate(taxisID); vtime = taxisInqRtime(taxisID); date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr); unit = taxisInqTunit(taxisID); if ( unit != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(unit)); calendar = taxisInqCalendar(taxisID); if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar)); if ( taxisHasBounds(taxisID) ) fprintf(stdout, " Bounds = true"); fprintf(stdout, "\n"); if ( taxisInqType(taxisID) == TAXIS_FORECAST ) { fdate = taxisInqFdate(taxisID); ftime = taxisInqFtime(taxisID); date2str(fdate, vdatestr, sizeof(vdatestr)); time2str(ftime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " Forecast RefTime = %s %s", vdatestr, vtimestr); unit = taxisInqForecastTunit(taxisID); if ( unit != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(unit)); fprintf(stdout, "\n"); lforecast = TRUE; } } } calendar = taxisInqCalendar(taxisID); fprintf(stdout, "\n"); fprintf(stdout, " Verification Time "); if ( lforecast ) fprintf(stdout, " Forecast Reference Time "); if ( taxisHasBounds(taxisID) ) fprintf(stdout, " lower bound upper bound"); fprintf(stdout, "\n"); fprintf(stdout, "Timestep YYYY-MM-DD hh:mm:ss Increment"); if ( lforecast ) fprintf(stdout, " YYYY-MM-DD hh:mm:ss Period"); if ( taxisHasBounds(taxisID) ) fprintf(stdout, " YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss Difference"); fprintf(stdout, "\n"); tsID = 0; while ( (nrecs = streamInqTimestep(streamID, tsID)) ) { vdate = taxisInqVdate(taxisID); vtime = taxisInqVtime(taxisID); cdiDecodeDate(vdate, &year, &month, &day); date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, "%6d %s %s", tsID+1, vdatestr, vtimestr); if ( tsID ) { cdiDecodeDate(vdate0, &year0, &month0, &day0); juldate0 = juldate_encode(calendar, vdate0, vtime0); juldate = juldate_encode(calendar, vdate, vtime); jdelta = juldate_to_seconds(juldate_sub(juldate, juldate0)); getTimeInc(jdelta, vdate0, vdate, &incperiod, &incunit); /* fprintf(stdout, " %g %g %g %d", jdelta, jdelta/3600, fmod(jdelta,3600), incperiod%3600);*/ len = fprintf(stdout, " %3d %s%s", incperiod, tunits[incunit], abs(incperiod)>1?"s":""); for ( i = 0; i < 11-len; ++i ) fprintf(stdout, " "); } else { vdate_first = vdate; vtime_first = vtime; fprintf(stdout, " --------"); } if ( lforecast ) { fdate = taxisInqFdate(taxisID); ftime = taxisInqFtime(taxisID); date2str(fdate, vdatestr, sizeof(vdatestr)); time2str(ftime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " %s %s", vdatestr, vtimestr); double fc_period = taxisInqForecastPeriod(taxisID); fprintf(stdout, " %7g", fc_period); } if ( taxisHasBounds(taxisID) ) printBounds(taxisID, calendar); if ( tsID > 1 && (incperiod != incperiod0 || incunit != incunit0) ) { if ( tsID == 2 && (jdelta0 > jdelta) ) { jdelta0 = jdelta; incperiod0 = incperiod; incunit0 = incunit; its = fill_gap(ngaps, ntsm, rangetsm, vdatem, vtimem, 1, incperiod0, incunit0, vdate_first, vdate, vtime, calendar, day, juldate0, juldate_encode(calendar, vdate_first, vtime_first)); arrow = '^'; } else { its = fill_gap(ngaps, ntsm, rangetsm, vdatem, vtimem, tsID, incperiod0, incunit0, vdate, vdate0, vtime0, calendar, day0, juldate, juldate0); arrow = '<'; if ( its == 0 && incperiod < 0 ) { its = -1; vdate = vdate0; vtime = vtime0; } } if ( its > 0 ) { ngaps++; if ( cdoVerbose ) fprintf(stdout, " %c--- Gap %d, missing %s%d timestep%s", arrow, ngaps, its>=LIM_NTSM?"more than ":"", its, its>1?"s":""); } else if ( its < 0 ) { if ( cdoVerbose ) fprintf(stdout, " %c--- Wrong date/time information, negative increment!", arrow); } } if ( tsID == 1 ) { jdelta0 = jdelta; incperiod0 = incperiod; incunit0 = incunit; } fprintf(stdout, "\n"); vdate0 = vdate; vtime0 = vtime; tsID++; } } streamClose(streamID); fprintf(stdout, "\n"); date2str(vdate_first, vdatestr, sizeof(vdatestr)); time2str(vtime_first, vtimestr, sizeof(vtimestr)); fprintf(stdout, " Start date : %s %s\n", vdatestr, vtimestr); date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " End date : %s %s\n", vdatestr, vtimestr); fprintf(stdout, " Increment : %3d %s%s\n", incperiod0, tunits[incunit0], incperiod0>1?"s":""); fprintf(stdout, " Number of timesteps : %d\n", tsID); fprintf(stdout, " Gaps identified : %d\n", ngaps); if ( cdoVerbose && ngaps ) { fprintf(stdout, "\nFound potentially %d gap%s in the time series", ngaps, ngaps>1?"s":""); if ( ngaps >= MAX_GAPS ) { ngaps = MAX_GAPS; fprintf(stdout, ", here are the first %d", ngaps); } fprintf(stdout, ":\n"); for ( igap = 0; igap < ngaps; ++igap ) { fprintf(stdout, " Gap %d between timestep %d and %d, missing %d timestep%s", igap+1, rangetsm[igap][0], rangetsm[igap][1], ntsm[igap], ntsm[igap]>1?"s":""); if ( ntsm[igap] >= MAX_NTSM ) { ntsm[igap] = MAX_NTSM; fprintf(stdout, ", here are the first %d", ntsm[igap]); } fprintf(stdout, ":\n"); ntimeout = 0; for ( its = 0; its < ntsm[igap]; ++its ) { if ( ntimeout == 4 ) { ntimeout = 0; fprintf(stdout, "\n"); } vdate = vdatem[igap][its]; vtime = vtimem[igap][its]; date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " %s %s", vdatestr, vtimestr); ntimeout++; tsID++; } fprintf(stdout, "\n"); } } cdoFinish(); return (0); }
/* * SHIT <channel|*> <nick|mask> <action> [expire] <reason> */ void do_shit(COMMAND_ARGS) { /* * on_msg checks CARGS */ char *channel,*nick,*nuh; int shitlevel,days,uaccess,shitaccess; if (CurrentCmd->name == C_QSHIT) { channel = MATCH_ALL; } else { channel = chop(&rest); if (!ischannel(channel) && *channel != '*') { usage: usage(from); /* usage for CurrentCmd->name */ return; } } if ((uaccess = get_useraccess(from,channel)) < cmdaccess) return; if ((nick = chop(&rest)) == NULL) goto usage; if (CurrentCmd->name == C_QSHIT) { shitlevel = DEFAULTSHITLEVEL; days = 86400 * DEFAULTSHITLENGTH; if (*rest == 0) rest = TEXT_DEFAULTSHIT; } else { shitlevel = asc2int(chop(&rest)); if (errno) goto usage; if (shitlevel < 1 || shitlevel > MAXSHITLEVEL) { to_user(from,"Valid levels are from 1 thru " MAXSHITLEVELSTRING); return; } /* * option: expire in XXX days */ days = 86400 * 30; if (*rest >= '1' && *rest <= '9') { days = 86400 * asc2int(chop(&rest)); if (errno) goto usage; } if (*rest == 0) goto usage; } #ifdef CHANBAN if (shitlevel == SHIT_CHANBAN) { nuh = nick; } else #endif /* CHANBAN */ { if ((nuh = nick2uh(from,nick)) == NULL) return; if (find_shit(nuh,channel)) { to_user(from,TEXT_ALREADYSHITTED,nuh); return; } if (uaccess != OWNERLEVEL) { shitaccess = get_useraccess(nuh,channel); if (shitaccess > uaccess) { to_user(from,TEXT_SHITLOWACCESS,nuh); return; } } format_uh(nuh,FUH_USERHOST); } #ifdef DEBUG debug("(do_shit) adding %s to %s (Level %i)\n",nuh,channel,shitlevel); #endif /* DEBUG */ add_shit(from,channel,nuh,rest,shitlevel,now + days); to_user(from,TEXT_HASSHITTED,nuh,channel); to_user(from,TEXT_SHITEXPIRES,time2str(now + days)); check_shit(); }
SaErrorT show_event_log(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid, int show_short, hpi_ui_print_cb_t proc) { SaErrorT rv = SA_OK; SaHpiRptEntryT rptentry; SaHpiEventLogInfoT info; SaHpiEventLogEntryIdT entryid; SaHpiEventLogEntryIdT nextentryid; SaHpiEventLogEntryIdT preventryid; SaHpiEventLogEntryT sel; SaHpiRdrT rdr; SaHpiRptEntryT rpt; char buf[SHOW_BUF_SZ]; char date[30], date1[30]; if (resourceid != SAHPI_UNSPECIFIED_RESOURCE_ID) { rv = saHpiRptEntryGetByResourceId(sessionid, resourceid, &rptentry); if (rv != SA_OK) { snprintf(buf, SHOW_BUF_SZ, "ERROR: saHpiRptEntryGetByResourceId error = %s\n", oh_lookup_error(rv)); proc(buf); return rv; }; if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { proc("ERROR: The designated resource hasn't SEL.\n"); return SA_OK; } }; rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (rv != SA_OK) { snprintf(buf, SHOW_BUF_SZ, "ERROR: saHpiEventLogInfoGet error = %s\n", oh_lookup_error(rv)); proc(buf); return rv; } snprintf(buf, SHOW_BUF_SZ, "EventLog: entries = %d, size = %d, enabled = %d\n", info.Entries, info.Size, info.Enabled); if (proc(buf) != HPI_UI_OK) return(SA_OK); time2str(info.UpdateTimestamp, date, 30); time2str(info.CurrentTime, date1, 30); snprintf(buf, SHOW_BUF_SZ, "UpdateTime = %s CurrentTime = %s Overflow = %d\n", date, date1, info.OverflowFlag); if (proc(buf) != HPI_UI_OK) return(SA_OK); if (info.Entries != 0) { entryid = SAHPI_OLDEST_ENTRY; while (entryid != SAHPI_NO_MORE_ENTRIES) { rv = saHpiEventLogEntryGet(sessionid, resourceid, entryid, &preventryid, &nextentryid, &sel, &rdr, &rpt); if (rv != SA_OK) { snprintf(buf, SHOW_BUF_SZ, "ERROR: saHpiEventLogEntryGet error = %s\n", oh_lookup_error(rv)); proc(buf); return -1; }; if (show_short) { if (show_short_event(&(sel.Event), proc) != HPI_UI_OK) return(SA_OK); } else { if (rpt.ResourceCapabilities != 0) { oh_print_eventlogentry(&sel, &rpt.ResourceEntity, 1); } else if (rdr.RdrType != SAHPI_NO_RECORD) { oh_print_eventlogentry(&sel, &rdr.Entity, 1); } else { oh_print_eventlogentry(&sel, NULL, 1); } } preventryid = entryid; entryid = nextentryid; } } else { proc("SEL is empty\n"); }; return SA_OK; }
void list_sel(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id) { char str[256]; printf("SEL Info:\n"); SaHpiSelInfoT info; SaErrorT rv = saHpiEventLogInfoGet(session_id, resource_id, &info); if (rv != SA_OK) { printf( "Error=%d reading SEL info\n", rv); return; } printf("\tEntries in SEL: %d\n", info.Entries); printf("\tSize: %d\n", info.Size); time2str(info.UpdateTimestamp, str); printf("\tUpdateTimestamp: %s\n", str); time2str(info.CurrentTime, str); printf("\tCurrentTime : %s\n", str); printf("\tEnabled: %s\n", info.Enabled ? "true" : "false"); printf("\tOverflowFlag: %s\n", info.OverflowFlag ? "true" : "false"); printf("\tOverflowAction: " ); switch(info.OverflowAction) { case SAHPI_SEL_OVERFLOW_DROP: printf("SAHPI_SEL_OVERFLOW_DROP\n"); break; case SAHPI_SEL_OVERFLOW_WRAP: printf("SAHPI_SEL_OVERFLOW_WRAP\n"); break; case SAHPI_SEL_OVERFLOW_WRITELAST: printf("SAHPI_SEL_OVERFLOW_WRITELAST\n"); break; default: printf("unknown(0x%x)\n", info.OverflowAction); break; } printf("\tDeleteEntrySupported: %s\n", info.DeleteEntrySupported ? "true" : "false" ); if (info.Entries == 0) return; //else // read sel records SaHpiSelEntryIdT current = SAHPI_OLDEST_ENTRY; do { SaHpiSelEntryIdT prev; SaHpiSelEntryIdT next; SaHpiSelEntryT entry; SaHpiRdrT rdr; SaHpiRptEntryT res; rv = saHpiEventLogEntryGet(session_id, resource_id, current, &prev, &next, &entry, &rdr, &res); if (rv != SA_OK) { printf( "Error=%d reading SEL entry %d\n", rv, current); return; } printf("\t\tEntry %d, prev %d, next %d\n", entry.EntryId, prev, next); time2str(entry.Timestamp, str); printf("\t\t\tTimestamp: %s\n", str); SaHpiRptEntryT rres; rv = saHpiRptEntryGetByResourceId(session_id, entry.Event.Source, &rres ); if ( rv != SA_OK ) printf("\t\t\tSource: unknown\n" ); else { entitypath2string( &rres.ResourceEntity, str, sizeof(str)); printf("\t\t\tSource: %s\n", str ); } printf("\t\t\tEventType: %s\n", eventtype2str(entry.Event.EventType)); time2str(entry.Timestamp, str); printf("\t\t\tEvent timestamp: %s\n", str); printf("\t\t\tSeverity: %s\n", severity2str( entry.Event.Severity ) ); switch(entry.Event.EventType) { case SAHPI_ET_SENSOR: { SaHpiSensorEventT *se = &entry.Event.EventDataUnion.SensorEvent; printf("\t\t\tSensorNum: %d\n", se->SensorNum ); printf("\t\t\tSensorType: %s\n", get_sensor_type(se->SensorType ) ); printf("\t\t\tEventCategory: %s\n", get_sensor_category( se->EventCategory ) ); printf("\t\t\tAssertion: %s\n", se->Assertion ? "TRUE" : "FALSE" ); } break; case SAHPI_ET_HOTSWAP: { SaHpiHotSwapEventT *he = &entry.Event.EventDataUnion.HotSwapEvent; printf("\t\t\tHotSwapState: %s\n", hotswapstate2str( he->HotSwapState ) ); printf("\t\t\tPreviousHotSwapState: %s\n", hotswapstate2str( he->PreviousHotSwapState ) ); } break; case SAHPI_ET_WATCHDOG: break; case SAHPI_ET_OEM: break; case SAHPI_ET_USER: break; } current = next; } while(current != SAHPI_NO_MORE_ENTRIES); }
void *Sinfo(void *argument) { enum {func_generic, func_param, func_name, func_code}; int operatorID; int operfunc, lensemble; int indf; int varID; int gridsize = 0; int gridID, zaxisID, code, tabnum, param; int vdate, vtime; int nvars, ntsteps; int levelsize; int tsteptype, taxisID; char tmpname[CDI_MAX_NAME]; char varname[CDI_MAX_NAME]; char paramstr[32]; char vdatestr[32], vtimestr[32]; const char *modelptr, *instptr; int streamID = 0; int vlistID; int datatype; char pstr[4]; cdoInitialize(argument); cdoOperatorAdd("sinfo", func_generic, 0, NULL); cdoOperatorAdd("sinfop", func_param, 0, NULL); cdoOperatorAdd("sinfon", func_name, 0, NULL); cdoOperatorAdd("sinfoc", func_code, 0, NULL); cdoOperatorAdd("seinfo", func_generic, 1, NULL); cdoOperatorAdd("seinfop", func_param, 1, NULL); cdoOperatorAdd("seinfon", func_name, 1, NULL); cdoOperatorAdd("seinfoc", func_code, 1, NULL); operatorID = cdoOperatorID(); operfunc = cdoOperatorF1(operatorID); lensemble = cdoOperatorF2(operatorID); for ( indf = 0; indf < cdoStreamCnt(); indf++ ) { streamID = streamOpenRead(cdoStreamName(indf)); vlistID = streamInqVlist(streamID); set_text_color(stdout, BRIGHT, BLACK); fprintf(stdout, " File format"); reset_text_color(stdout); fprintf(stdout, " : "); printFiletype(streamID, vlistID); set_text_color(stdout, BRIGHT, BLACK); if ( lensemble ) fprintf(stdout, "%6d : Institut Source Ttype Einfo Levels Num Points Num Dtype : ", -(indf+1)); else fprintf(stdout, "%6d : Institut Source Ttype Levels Num Points Num Dtype : ", -(indf+1)); if ( operfunc == func_name ) fprintf(stdout, "Parameter name"); else if ( operfunc == func_code ) fprintf(stdout, "Table Code"); else fprintf(stdout, "Parameter ID"); if ( cdoVerbose ) fprintf(stdout, " : Extra" ); reset_text_color(stdout); fprintf(stdout, "\n" ); nvars = vlistNvars(vlistID); for ( varID = 0; varID < nvars; varID++ ) { param = vlistInqVarParam(vlistID, varID); code = vlistInqVarCode(vlistID, varID); tabnum = tableInqNum(vlistInqVarTable(vlistID, varID)); gridID = vlistInqVarGrid(vlistID, varID); zaxisID = vlistInqVarZaxis(vlistID, varID); set_text_color(stdout, BRIGHT, BLACK); fprintf(stdout, "%6d", varID+1); reset_text_color(stdout); set_text_color(stdout, RESET, BLACK); fprintf(stdout, " : "); reset_text_color(stdout); set_text_color(stdout, RESET, BLUE); /* institute info */ instptr = institutInqNamePtr(vlistInqVarInstitut(vlistID, varID)); strcpy(tmpname, "unknown"); if ( instptr ) strncpy(tmpname, instptr, CDI_MAX_NAME); limit_string_length(tmpname, CDI_MAX_NAME); fprintf(stdout, "%-8s ", tmpname); /* source info */ modelptr = modelInqNamePtr(vlistInqVarModel(vlistID, varID)); strcpy(tmpname, "unknown"); if ( modelptr ) strncpy(tmpname, modelptr, CDI_MAX_NAME); limit_string_length(tmpname, CDI_MAX_NAME); fprintf(stdout, "%-8s ", tmpname); /* tsteptype */ tsteptype = vlistInqVarTsteptype(vlistID, varID); if ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s ", "constant"); else if ( tsteptype == TSTEP_INSTANT ) fprintf(stdout, "%-8s ", "instant"); else if ( tsteptype == TSTEP_INSTANT2 ) fprintf(stdout, "%-8s ", "instant"); else if ( tsteptype == TSTEP_INSTANT3 ) fprintf(stdout, "%-8s ", "instant"); else if ( tsteptype == TSTEP_MIN ) fprintf(stdout, "%-8s ", "min"); else if ( tsteptype == TSTEP_MAX ) fprintf(stdout, "%-8s ", "max"); else if ( tsteptype == TSTEP_AVG ) fprintf(stdout, "%-8s ", "avg"); else if ( tsteptype == TSTEP_ACCUM ) fprintf(stdout, "%-8s ", "accum"); else if ( tsteptype == TSTEP_RANGE ) fprintf(stdout, "%-8s ", "range"); else if ( tsteptype == TSTEP_DIFF ) fprintf(stdout, "%-8s ", "diff"); else fprintf(stdout, "%-8s ", "unknown"); /* ensemble information */ if ( lensemble ) { int ensID, ensCount, forecast_type; if ( vlistInqVarEnsemble(vlistID, varID, &ensID, &ensCount, &forecast_type) ) fprintf(stdout, "%2d/%-2d ", ensID, ensCount); else fprintf(stdout, "--/-- "); } /* layer info */ levelsize = zaxisInqSize(zaxisID); fprintf(stdout, "%6d ", levelsize); fprintf(stdout, "%3d ", vlistZaxisIndex(vlistID, zaxisID) + 1); /* grid info */ gridsize = gridInqSize(gridID); fprintf(stdout, "%9d ", gridsize); fprintf(stdout, "%3d ", vlistGridIndex(vlistID, gridID) + 1); /* datatype */ datatype = vlistInqVarDatatype(vlistID, varID); datatype2str(datatype, pstr); fprintf(stdout, " %-3s", pstr); if ( vlistInqVarCompType(vlistID, varID) == COMPRESS_NONE ) fprintf(stdout, " "); else fprintf(stdout, "z "); reset_text_color(stdout); set_text_color(stdout, RESET, BLACK); fprintf(stdout, ": "); reset_text_color(stdout); /* parameter info */ cdiParamToString(param, paramstr, sizeof(paramstr)); if ( operfunc == func_name ) vlistInqVarName(vlistID, varID, varname); set_text_color(stdout, BRIGHT, GREEN); if ( operfunc == func_name ) fprintf(stdout, "%-14s", varname); else if ( operfunc == func_code ) fprintf(stdout, "%4d %4d ", tabnum, code); else fprintf(stdout, "%-14s", paramstr); reset_text_color(stdout); if ( cdoVerbose ) { char varextra[CDI_MAX_NAME]; vlistInqVarExtra(vlistID, varID, varextra); fprintf(stdout, " : %s", varextra ); } fprintf(stdout, "\n"); } set_text_color(stdout, BRIGHT, BLACK); fprintf(stdout, " Grid coordinates"); reset_text_color(stdout); fprintf(stdout, " :\n"); printGridInfo(vlistID); set_text_color(stdout, BRIGHT, BLACK); fprintf(stdout, " Vertical coordinates"); reset_text_color(stdout); fprintf(stdout, " :\n"); printZaxisInfo(vlistID); taxisID = vlistInqTaxis(vlistID); ntsteps = vlistNtsteps(vlistID); if ( ntsteps != 0 ) { set_text_color(stdout, BRIGHT, BLACK); fprintf(stdout, " Time coordinate"); reset_text_color(stdout); if ( ntsteps == CDI_UNDEFID ) fprintf(stdout, " : unlimited steps\n"); else fprintf(stdout, " : %d step%s\n", ntsteps, ntsteps == 1 ? "" : "s"); if ( taxisID != CDI_UNDEFID ) { if ( taxisInqType(taxisID) != TAXIS_ABSOLUTE ) { vdate = taxisInqRdate(taxisID); vtime = taxisInqRtime(taxisID); date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr); int tunits = taxisInqTunit(taxisID); if ( tunits != CDI_UNDEFID ) fprintf(stdout, " Units = %s", tunit2str(tunits)); int calendar = taxisInqCalendar(taxisID); if ( calendar != CDI_UNDEFID ) fprintf(stdout, " Calendar = %s", calendar2str(calendar)); if ( taxisHasBounds(taxisID) ) fprintf(stdout, " Bounds = true"); fprintf(stdout, "\n"); if ( taxisInqType(taxisID) == TAXIS_FORECAST ) { vdate = taxisInqFdate(taxisID); vtime = taxisInqFtime(taxisID); date2str(vdate, vdatestr, sizeof(vdatestr)); time2str(vtime, vtimestr, sizeof(vtimestr)); fprintf(stdout, " ForecastRefTime = %s %s", vdatestr, vtimestr); fprintf(stdout, "\n"); } } } fprintf(stdout, " YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss\n"); set_text_color(stdout, RESET, MAGENTA); printTimesteps(streamID, taxisID, cdoVerbose); reset_text_color(stdout); fprintf(stdout, "\n"); } streamClose(streamID); } cdoFinish(); return (0); }