/** Return the Caption for the OS, typically a longer string \returns Caption for OS, intended for display/human reader \throws SCXCoreLib::SCXNotSupportedException - if not implemented for the platform */ std::wstring SCXOSTypeInfo::GetCaption() const { #if defined(linux) return m_linuxDistroCaption; #elif defined(sun) || defined(hpux) // append in caption the system name and release. string capt(m_unameInfo.sysname); capt.append(" "); capt.append(m_unameInfo.release); return SCXCoreLib::StrFromMultibyte(capt); #elif defined(aix) // append in caption the system name and release. string capt(m_unameInfo.sysname); capt.append(" "); capt.append(m_unameInfo.version); capt.append("."); capt.append(m_unameInfo.release); return SCXCoreLib::StrFromMultibyte(capt); #elif defined(macos) // append in caption the system name and release. wstring capt(m_osName); capt.append(L" "); capt.append(m_osVersion); return capt; #else throw SCXCoreLib::SCXNotSupportedException(L"GetCaption()", SCXSRCLOCATION); #endif }
bool Consistency::lockFile(std::string &fName ) { //test for a lock std::string lockFile(fName); lockFile += ".lock" ; std::string test("/bin/bash -c \'test -e ") ; test += lockFile ; test += '\'' ; std::string lock("/bin/bash -c \'touch "); lock += lockFile ; lock += " &> /dev/null\'" ; // see 'man system' for the return value, here we expect 0, // if file exists. size_t count=0; // THIS WILL lock until the lock-file is removed while ( ! system( test.c_str() ) ) { sleep( 1 ) ; // in seconds ++count; if( count == 1800 ) // 1/2 hr { std::string key("8_3"); if( notes->inq( key, "PT") ) { std::string capt("consistency-check table is locked for 1/2 hour") ; (void) notes->operate(capt) ; qa->setExit( notes->getExitValue() ) ; } } } if( system( lock.c_str() ) ) { std::string key("8_2"); if( notes->inq( key, "PT") ) { std::string capt("could not lock the consistency-check table") ; if( notes->operate(capt) ) qa->setExit( notes->getExitValue() ) ; } return true; } return false; }
int SyncFiles::printTimelessFile(std::string &str) { // true below means: print only marked entries if( ensemble->sz > 1 ) { // occurence within an ensemble of files: error std::string key("17_1"); std::string capt("Determination of temporal sequence of files failed."); // More than a single file is an error; output filenames ensemble->enablePrintOnlyMarked(); str = ensemble->getOutput() ; return 10; } else if( ensemble->sz == 1 ) { if( ensemble->member[0]->state.size() ) { ensemble->enablePrintOnlyMarked(); str = ensemble->getOutput() ; return 3; // a fixed field file, but with error } else return 4; // a fixed field file } else { ensemble->enablePrintOnlyMarked(); str = ensemble->getOutput() ; return 3 ; // unspecific error } }
void FileDialog::_Update(void) { _curDir = NULL; std::string capt(_save ? "Save to..." : "Open file..."); capt += " ["; capt += GetDirName(); capt += ']'; gcn::Window::setCaption(capt); }
int main() { int i; char string[100]; printf("Enter a line: "); gets(string); capt(string); return 0; }
void Consistency::write(Variable &dataVar, std::string& entryID) { // store meta data info std::string md; getMetaData(dataVar, entryID, md); std::string pFile = projectTableFile.getFile(); lockFile(pFile); // open the file for appending. std::fstream oifs; oifs.open(pFile.c_str(), std::ios::in | std::ios::out ); if( !oifs) // does not exist oifs.open(pFile.c_str(), std::ios::out | std::ios::trunc | std::ios::in); if (! oifs.is_open() ) { std::string key("8_1"); if( notes->inq( key, "PT") ) { std::string capt("could not create a consistency-check table") ; if( notes->operate(capt) ) { notes->setCheckMetaStr( qa->fail ); qa->setExit( notes->getExitValue() ) ; } } } else { // append oifs.seekp(0, std::ios::end); oifs << md << std::flush; oifs.close(); } unlockFile(pFile); return; }
int main(void){ char input[9] = " "; char ch; int i = 0; bool flagBegin = false; while(1){ strcpy(input, " "); flagBegin = false; i = 0; //reset index ch = getche(); if(ch == '0'){ flagBegin = true; input[i++] = ch; while(flagBegin == true){ input[i] = getche(); if(input[i++] != '1' && i < 7){ break; } if(i == 7){ input[i] = getch(); if(strcmp(input, flag) == 0){ printf("%s\n", "HDLC flag detected! Printing keystrokes to console!\n"); capt(); flagBegin = false; }else{ flagBegin = false; } } } } } return 0; }
void QA::openQA_Nc(InFile &in) { // Generates a new nc file for QA results or // opens an existing one for appending data. // Copies time variable from input-nc file. // name of the result file was set before if ( !qaFile.is() ) { std::string key("00"); if( notes->inq( key) ) { std::string capt("openQA_Nc(): undefined file.") ; (void) notes->operate(capt) ; notes->setCheckStatus("QA_open", n_fail); setExitState( notes->getExitState() ) ; return; } } nc = new NcAPI; if( notes ) nc->setNotes(notes); if( nc->open(qaFile.getFile(), "NC_WRITE", false) ) { // continue a previous session importedRecFromPrevQA=nc->getNumOfRecords(); currQARec += importedRecFromPrevQA; if( currQARec ) isNotFirstRecord = true; initDataOutputBuffer(); initResumeSession(); isResumeSession=true; return; } // So, we have to generate a netCDF file from almost scratch; isFirstFile=true; if( currQARec == 0 && in.nc.getNumOfRecords() == 1 ) qaTime.isSingleTimeValue = true; // open new netcdf file if( qaNcfileFlags.size() ) nc->create(qaFile.getFile(), qaNcfileFlags); else nc->create(qaFile.getFile(), "NC_NETCDF4"); if( isCheckTimeValues) { if( qaTime.time_ix > -1 ) qaTime.openQA_NcContrib(nc); else { // dimensions qaTime.name="fixed"; nc->defineDim("fixed", 1); } } // create variable for the data statistics etc. for( size_t m=0 ; m < qaExp.varMeDa.size() ; ++m ) qaExp.varMeDa[m].qaData.openQA_NcContrib(nc, qaExp.varMeDa[m].var); // global atts at creation. initGlobalAtts(in); initDataOutputBuffer(); return; }
bool QA::init(void) { // Open the qa-result.nc file, when available or create // it from scratch. Meta data checks are performed. // Initialisation of time and time boundary testing. // Eventually, entry() is called to test the data of fields. notes->init(); // safe qaExp.setParent(this); qaTime.setParent(this); // default for the qaFile setFilename( pIn->file ); // apply parsed command-line args applyOptions(); std::string vName(qaExp.getVarnameFromFilename()); if(isRequiredVariable) pIn->pullMetaData('V', vName); if(isRequiredTime && !isRequiredVariable) pIn->pullMetaData('T'); if(isRequiredGlobal) pIn->pullMetaData('G'); initCheckStatus(); // check for CF Convention. if(isCheckCF) { cF->setDataVarName(vName); cF->setFilename(pIn->file); (void) cF->run(); } // exclude user-defined data variables from any checking pIn->excludeVars(); qaTime.init(optStr); qaExp.init(optStr); // DRS specifications if(isCheckDRS_F || isCheckDRS_P) { drs_cv_table.setParent(this); drs_cv_table.setPath(tablePath); drs_cv_table.applyOptions(optStr); drs_cv_table.read(); } // experiment specific obj: set parent, pass over options // check consistency between sub-sequent files or experiments if(isCheckCNSTY && (fileSequenceState == 's' || fileSequenceState == 'x') ) { // return true for a) no previous check available, // b) deviation from a privous check are found if( checkConsistency(*pIn, optStr, tablePath) ) qaExp.run(); } else qaExp.run(); // check existence of any data at all if( pIn->ncRecBeg == 0 && pIn->ncRecEnd == 0 ) { isCheckData=false; std::string key("6_15"); if( notes->inq( key, fileStr) ) { std::string capt("No records in the file") ; if( notes->operate(capt) ) { notes->setCheckStatus(n_data, n_fail ); setExitState( notes->getExitState() ) ; } } } if( isCheckData ) { if( !checkDataBody() ) { isCheckData = false; notes->setCheckStatus(n_data, n_fail); setExitState(2); // return true; } } if(isCheckTimeValues && !qaTime.isTime) notes->setCheckStatus(n_time, "FIXED"); if(isCheckTimeValues) { if( qaTime.isTime) { if( !checkDataBody(qaTime.name) ) { // time is defined, but there is no data qaTime.isTime = false; notes->setCheckStatus(n_time, n_fail); setExitState(2); } } } if(isCheckData || isCheckTimeValues) { notes->setConstraintFreq( qaExp.getFrequency() ); // enable detection of outlier and replicated records setProcessing(); // open netCDF for creating, continuation or resuming qa_<varname>.nc. // note that this must happen before checkMetaData which uses currQARec openQA_Nc(*pIn); if( isExit() || qaExp.isUseStrict || qaTime.isNoProgress ) { isCheckData=false; return true; } } if( isCheckData || isCheckTimeValues ) { // set pointer to function for operating tests // execPtr = &IObj::entry ; (void) entry(); } return true; // only meta-data check }
int main(int argc, char *argv[]) { long int frame_count = 0; VideoTransfer *video_transfer; // video file name address const char* filename = argc == 2 ? argv[1] : "/home/Max/prj/videos/helicopter.mpg"; int tracking_mode = AUTO_TRACKING; bool debug_mode = false; bool small_target = true; first_frame = true; // window captured from the camera(video file), window in which we are // searching target, target etalon image window captured_window, search_window, etalon_window; //init captured, search, track and etalon windows parameters init_windows_params(&captured_window, &search_window, &track_window, &etalon_window); // Matrixes for original and grayscaled images cv::Mat src_host, src_gray; // init pointer on image float *image; image = (float *)calloc(captured_window.width * captured_window.height, sizeof(float)); // getting frame information cv::VideoCapture capt(filename); // declare tracking class Tracking track (captured_window, track_window, etalon_window, GAUSSS_FILTER_SIZE, FILTRATION_THRESHOLD); video_transfer = new VideoTransfer("data_ready_imit_to_interface", "data_accepted_imit_to_interface", "prc_term_imit_to_interface", __KEY_VALUE); for (;;) { // break if frame isn't readable if (capt.read(src_host) == false) break; // convert to grayscale image cv::cvtColor(src_host, src_gray, CV_RGB2GRAY); // create float matrix of greyscale image for(int i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) image[i]= (float)*src_gray.ptr(0,i); // getting video frame to GPU track.getImage(image, track_window, frame_count); if(first_frame == true) small_target = true; switch(tracking_mode) { case AUTO_TRACKING: if(small_target == true) { small_target = contrast_tracking(&track, image, &track_window, &first_frame, AUTO_TRACKING, debug_mode); } /* if(first_frame == true) { printf("First frame: %s",(small_target)?"true":"false"); getchar(); } */ if(small_target == false) { if(first_frame == true) { track.getImage(image, track_window, frame_count); } small_target = correlation_tracking(track, image, &track_window, &first_frame, AUTO_TRACKING, debug_mode); } break; case CORRELATION_TRACKING: correlation_tracking(track, image, &track_window, &first_frame, CORRELATION_TRACKING, debug_mode); break; case CONTRAST_TRACKING: contrast_tracking(&track, image, &track_window, &first_frame, CONTRAST_TRACKING, debug_mode); break; case NONE_TRACKING: break; } // drawing target marker cv::circle(src_host, cvPoint(captured_window.width / 2 + track_window.centerX - 1, captured_window.height / 2 + track_window.centerY - 1), 5, CV_RGB(255, 0, 0), 1, 8); // showing result image cv::imshow("Video", src_host); cv::Mat output(SCREEN_HEIGHT, SCREEN_WIDTH, CV_8UC3, src_host.data); /* if (video_transfer->pass_frame(output.data) == false) { break; } */ // getting mouse pointer position when right button is clicked cv::setMouseCallback("Video", mouse_callback); // getting input key and/or waiting 30 ms char c = cvWaitKey(20); // break if Esc is pressed if (c == 27) break; // update frame number frame_count++; } // Cleanup host free(image); delete video_transfer; return EXIT_SUCCESS; }
bool Consistency::check(Variable &dataVar, std::string entryID) { // return value is true, when there is not a project table, yet. // Search the project table for an entry // matching the varname and frequency (account also rotated). // Open project table. Mode: read std::string str0(projectTableFile.getFile()); std::ifstream ifs(str0.c_str(), std::ios::in); if( !ifs.is_open() ) // file does not exist return true; // causes writing of a new entry size_t sz_PV = entryID.size(); std::string t_md; bool notFound=true; while( getline(ifs, str0) ) { if( str0.substr(0,sz_PV) != entryID ) continue; // found a valid entry notFound=false; t_md = hdhC::stripSides(str0) ; // read aux-lines while( getline(ifs, str0) ) { str0 = hdhC::stripSides(str0) ; if( str0.substr(0,4) != "aux=" ) goto BREAK ; // found the end of the entry t_md += '\n'; t_md += str0 ; } } if(notFound) return true; // entry not found BREAK: // close the project table ifs.close(); // get meta data info from the file std::string f_md; getMetaData(dataVar, entryID, f_md); // Comparison of meta-data from the project table and the file, respectively. // Note that the direct comparison fails because of different spaces. // Deviating distribution of auxiliaries and attributes is tolerated. // Use index-vector for book-keeping. // Meaning: x=split, t=file, t=table, a=attribute, eq=(att-name,att-value) Split splt_xt(t_md, '\n'); Split splt_xf(f_md, '\n'); size_t xt_sz=splt_xt.size(); size_t xf_sz=splt_xf.size(); std::vector<std::string> xf; for( size_t i=0 ; i < xf_sz ; ++i ) xf.push_back( hdhC::stripSides(splt_xf[i]) ); std::vector<std::string> xt; for( size_t i=0 ; i < xt_sz ; ++i ) xt.push_back( hdhC::stripSides(splt_xt[i]) ); // simple test for identity if( xt_sz == xf_sz ) { bool is=true; for( size_t i=0 ; i < xt_sz ; ++i ) { if( xt[i] != xf[i] ) { is=false ; break; } } if( is ) return false; } // store indexes std::vector<int> xf_ix; for( size_t i=0 ; i < xf_sz ; ++i ) xf_ix.push_back( i ); std::vector<int> xt_ix; for( size_t i=0 ; i < xt_sz ; ++i ) xt_ix.push_back( i ); // At first, test whether total auxiliary entries are identical. for( size_t i=0 ; i < xt_sz ; ++i ) { for( size_t j=0 ; j < xf_sz ; ++j ) { // only test strings for indexes still to be checked if( xt_ix[i] > -1 && xf_ix[i] > -1 && xf[j] == xt[i] ) { xt_ix[i] = -1; xf_ix[j] = -1; break; } } } Split xf_a; // meta-data from file xf_a.setSeparator(','); Split xt_a; // from the table xt_a.setSeparator(','); Split xf_eq; xf_eq.setSeparator('='); Split xt_eq; xt_eq.setSeparator('='); bool isMissAux; for( size_t ixt=0 ; ixt < xt_ix.size() ; ++ixt ) { int jt=xt_ix[ixt]; if( jt < 0 ) continue; // passed already a check isMissAux=true; //split at comma xt_a = xt[jt] ; for( size_t ixf=0 ; ixf < xf_ix.size() ; ++ixf ) { int jf=xf_ix[ixf]; if( jf < 0 ) continue; // passed already a check //split at comma xf_a = xf[jf] ; // compare the names of the auxiliaries if( xf_a[0] != xt_a[0] ) continue; isMissAux=false; // scan the attributes for( size_t ita=1 ; ita < xt_a.size() ; ++ita ) { // split at '=' xt_eq = xt_a[ita] ; bool isAttMissing=true; for( size_t ifa=1 ; ifa < xf_a.size() ; ++ifa ) { // split at '=' xf_eq = xf_a[ifa] ; if( xt_eq[0] == xf_eq[0] ) // found identical attribute names { isAttMissing=false; if( xt_eq[1] == xf_eq[1] ) // found identical values break; // try the next attribute // this is a very special one for time: one wit separator T and/or Z // the other one without std::string auxName; if( xt_a[0].substr(0,4) == "aux=" ) auxName = xt_a[0].substr(4) ; else auxName = xt_a[0] ; if( auxName == "time" ) { Split x_tt(xt_eq[1]," TZ",true) ; Split x_ff(xf_eq[1]," TZ",true) ; if( x_tt.size() == x_ff.size() ) { bool is=true; for(size_t c=0 ; c < x_tt.size() ; ++c ) if( x_tt[c] != x_ff[c] ) is=false; if(is) break; } } // different values --> annotation status=true; std::string key("8_8"); if( notes->inq( key, dataVar.name ) ) { std::string capt; if( xt_a[0].substr(0,4) == "aux=" ) { capt = "auxiliary "; capt += hdhC::tf_var(auxName, hdhC::colon) ; } else capt += hdhC::tf_var(xt_a[0], hdhC::colon) ; if( xt_eq[0] == "values" ) capt += "data has changed"; else { capt += xt_eq[0] ; capt += " has changed from"; capt += hdhC::tf_val(xt_eq[1]) ; capt += " to"; capt += hdhC::tf_val(xf_eq[1]) ; } capt += " across experiment or sub-temporal files"; (void) notes->operate(capt) ; notes->setCheckMetaStr( "FAIL" ); } break; // try next } } if( isAttMissing ) { status=true; std::string key("8_7"); if( notes->inq( key, dataVar.name ) ) { std::string capt; if( xt_a[0].substr(0,4) == "aux=" ) { capt = "auxiliary "; capt += hdhC::tf_var(xt_a[0].substr(4), hdhC::colon) ; } else capt += hdhC::tf_var(xt_a[0], hdhC::colon) ; if( xt_eq[0] == "values" ) capt += "no data"; else { capt += hdhC::tf_att(xt_eq[0]); capt += "is missing " ; } if( qa->currQARec ) capt += "across sub-temporal files"; else capt += "across experiments"; (void) notes->operate(capt) ; notes->setCheckMetaStr( "FAIL" ); } } } } if( isMissAux ) { status=true; std::string key("8_4"); if( notes->inq( key, dataVar.name ) ) { std::string capt; if( xt_a[0].substr(0,4) == "aux=" ) { capt = "auxiliary "; capt += hdhC::tf_var(xt_a[0].substr(4), hdhC::colon) ; } else capt += hdhC::tf_var(xt_a[0], hdhC::colon) ; capt += "missing across experiments or sub-temporal files"; (void) notes->operate(capt) ; notes->setCheckMetaStr( "FAIL" ); } } } // test for missing attributes in the table (reversed for-loops) bool isAddAux=true; for( size_t ixf=0 ; ixf < xf_ix.size() ; ++ixf ) { int jf=xf_ix[ixf]; if( jf < 0 ) continue; // passed already a check isAddAux=true; //split at comma xf_a = xf[jf] ; for( size_t ixt=0 ; ixt < xt_ix.size() ; ++ixt ) { int jt=xt_ix[ixt]; if( jt < 0 ) continue; // passed already a check //split at comma xt_a = xt[jt] ; // compare the names of the auxiliaries if( xf_a[0] != xt_a[0] ) continue; // found identical auxiliaries isAddAux=false; // scan the attributes for( size_t ifa=1 ; ifa < xf_a.size() ; ++ifa ) { // split at '=' xf_eq = xf_a[ifa] ; bool isAddAtt=true; for( size_t ita=1 ; ita < xt_a.size() ; ++ita ) { // split at '=' xt_eq = xt_a[ita] ; if( xt_eq[0] == xf_eq[0] ) // found identical attribute names { isAddAtt=false; break; } } if( isAddAtt ) { status=true; // additional attribute of auxiliary in the file std::string key("8_6"); if( notes->inq( key, dataVar.name ) ) { std::string capt; if( xt_a[0].substr(0,4) == "aux=" ) { capt = "auxiliary "; capt += hdhC::tf_var(xf_a[0].substr(4), hdhC::colon) ; } else capt += hdhC::tf_var(xf_a[0], hdhC::colon) ; if( xt_eq[0] == "values" ) { capt += "additional data across experiments or sub-temporal files"; } else { capt += hdhC::tf_att(xf_eq[0]); capt += "is new across experiments or sub-temporal files"; } (void) notes->operate(capt) ; notes->setCheckMetaStr( "FAIL" ); } } } } if( isAddAux ) { status=true; std::string key("8_5"); if( notes->inq( key, dataVar.name) ) { std::string capt("additional auxiliary "); if( xf_a[0].size() > 4 ) capt += hdhC::tf_var(xf_a[0].substr(4)) ; else capt += hdhC::tf_var(xf_a[0]) ; capt += "across experiments or sub-temporal files"; (void) notes->operate(capt) ; notes->setCheckMetaStr( "FAIL" ); } } } return false; }