const JSONNode JSONModelGetter::operator()(uint64_t fn){ JSONNode::const_iterator it = data->find(num2str(fn)); if(it!=data->end()) { return *it; } return JSONNode(); }
int main(int argc,char *args[]){ //get input int n=0; clock_t begin,end; if(argc<2){ puts("Too less input"); return 1; }else{ n = num2str(args[1]); } begin = clock(); int* A = randMatrix(n,n*n); end = clock(); double time_spent = (double)(end-begin)/CLOCKS_PER_SEC; //InsertionSort insertionSort(A,n); puts("SORTED"); for(int i=0;i<n;i++){ printf("index %d : %d\n",i,A[i]); } //RECORD FILE* fout = fopen("cResult.txt","a"); fprintf(fout,"input size : %10d , time %10f\n",n,time_spent); fclose(fout); }
void cESBTL::pdbReadAtom (const std::string& fileIn, cSetPoint3<double>& atomList, const std::string& atomName) { checkExtension(fileIn); ESBTL::PDB_line_selector pdbSelector; std::vector<ESBTL::Default_system> pdbSystems; ESBTL::All_atom_system_builder<ESBTL::Default_system> pdbBuilder(pdbSystems, pdbSelector.max_nb_systems()); require(ESBTL::read_a_pdb_file(fileIn, pdbSelector, pdbBuilder, Occupancy_policy_all()), "cannot read PDB file"); require(!pdbSystems.empty(), "No PDB system"); require( pdbSystems.size() == 1, "More than one PDB system: pdbSystems.size() = " + num2str(pdbSystems.size())); require(!pdbSystems[0].has_no_model(), "No model in 1st PDB system"); require( pdbSystems[0].number_of_models() == 1, "More than one model in PDB system: pdbSystems[0].number_of_models() = " + num2str(pdbSystems[0].number_of_models())); for (ESBTL::Default_system::Models_iterator iterModel = pdbSystems[0].models_begin(); iterModel != pdbSystems[0].models_end(); iterModel++) { const ESBTL::Default_system::Model& model = *iterModel; for (ESBTL::Default_system::Model::Atoms_const_iterator iterAtom = model.atoms_begin(); iterAtom != model.atoms_end(); iterAtom++) { if ((atomName != "" && iterAtom->atom_name() == atomName) || atomName == "") { atomList.push_back(cVector3<double>(iterAtom->x(),iterAtom->y(),iterAtom->z())); } } } }
void cSystem::checkComputingResource(unsigned int nGPU, unsigned int nCPU) { std::string message; std::string hostname = getComputerName(); unsigned int nGPUmax = 0, nCPUmax = 0; nGPUmax = getNumGPUs(); message = "(" + hostname + ") "; message += "has only " + num2str(nGPUmax) + " GPUs!"; require(nGPU <= nGPUmax, message.c_str()); nCPUmax = getNumProcessors(); message = "(" + hostname + ") "; message += "has only " + num2str(nCPUmax) + " CPU cores!"; require(nCPU <= nCPUmax, message.c_str()); }
int main(int argc, char *args[]){ srand(time(NULL)); int n = num2str(args[1]); matrix A = {.col = n, .row = n, .arr = randArray(n*n)}; matrix B = {.col = n, .row = n, .arr = randArray(n*n)}; matrix* C = multiply(A,B); for(int i=0;i<C->row;i++){ for(int j=0;j<C->col;j++){ printf("%d ",C->arr[i*C->col+j]); } puts(""); } return 0; } int* randArray(int n){ int *arr =(int*)malloc(sizeof(int)*n); for(int i=0;i<n;i++){ arr[i] = rand()%(n*n); printf("val : %d\n",arr[i]); } puts(""); return arr; } int num2str(char* str){ int len = strlen(str); int tmp = 1,val = 0; for(int i=len-1;i>=0;i--){ val+=(str[i]-'0')*tmp; tmp*=10; } return val; }
//マッチした結果を正規表現キャプチャしたものだけを取得する. std::map<std::string , std::string> GetRegexpCapture() const { _USE_WINDOWS_ENCODING; std::map<std::string , std::string> ret; for(auto it = this->Track.pickupRules.begin(); it != this->Track.pickupRules.end() ; ++it) { const SPPHRASERULE* rule = *it; const int captureNumber = _wtoi(rule->pszName); //キャプチャされた値が入っているところまでスキップ unsigned int count = 0; const SPPHRASEELEMENT * pElem = this->Phrase->pElements; for (; count < rule->ulFirstElement ; ++pElem , count ++) ; //そこから指定された数の文字列を結合したものがキャプチャした結果になる。 std::string str; for (count = 0; count < rule->ulCountOfElements ; ++pElem , count ++) { str = str + _W2A(pElem->pszLexicalForm); } ret[num2str(captureNumber)] = str; } return ret; }
xreturn::r<std::string> ActionImplement::Telnet(const std::string& host,int port,const std::string& wait,const std::string& send,const std::string& recv) { //ASIO作成 boost::asio::io_service io_service; //名前解決 boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::query query(host , num2str( port )); boost::asio::ip::tcp::endpoint endpoint(*resolver.resolve(query)); boost::asio::ip::tcp::socket socket(io_service); //接続 boost::system::error_code error ; socket.connect(endpoint,error); if (error) { return xreturn::error("ホストに接続できません host:" + host + " port:" + num2str(port) ); } //まずは相手の言い分を聞きます. if (!wait.empty()) { boost::asio::streambuf wait_body; boost::asio::read_until(socket, wait_body,wait ,error ); } //送信 if (!send.empty() ) { boost::asio::streambuf request; std::ostream request_stream(&request); request_stream << send << std::flush; boost::asio::write(socket, request); } std::string ret; //最後に会いての言い分を聞いてから通信を切ります。 if (!recv.empty()) { //貴方の意見は? boost::asio::streambuf respons_body; boost::asio::read_until(socket, respons_body,recv ,error ); ret = boost::asio::buffer_cast<const char*>(respons_body.data()); } return ret; }
vector<string> summaryRanges(vector<int>& nums) { vector<string> ret; int i = 0, j = 0, n = nums.size(); for (; ; ) { if (i >= n) break; for (; j+1 < n && nums[j]+1 == nums[j+1]; ) { ++j; } string tmp(num2str(nums[i])); if (i < j) { tmp += "->" + num2str(nums[j]); } ret.push_back(tmp); i = j + 1; j = j + 1; } return ret; }
void xAxis(int x, int y) { int i; gfx_line(0, y / 2, x, y / 2); for(i = 1; i <=21; i++) { gfx_line(i * (x / 22.), (y / 2) - 10, i * (x / 22.), (y / 2) + 10); gfx_text(i * (x / 22.), (y / 2) + 15, num2str(i - 11)); } }
void yAxis(int x, int y) { int i; gfx_line(x / 2, 0, x / 2, y); for(i = 1; i <= 21; i++) { gfx_line((x / 2) - 10, i * (y / 22.), (x / 2) + 10, i * (y / 22.)); gfx_text((x / 2) - 15, (22 - i) * (y / 22.), num2str(i - 11)); } }
const map<uint64_t, set<string> > FullnameNode::match(const Model &m, ModelGetter *getter){ map<uint64_t, set<string> > ret; if(m.attr<bool>("deleted")) return ret; uint64_t fn = m.fullname(); if(fn == operands[0].as_fullname()){ ret[fn].insert("#"+num2str(fn)); } return ret; }
string getHint(string secret, string guess) { int a = 0, b = 0; string s; vector<int> v(secret.size(), 0); for(int i = 0; i < guess.size(); i++) { if(guess[i] == secret[i]) a++; else { for(int j = 0; j < secret.size(); j++) if(secret[j]==guess[i]&&secret[j]!=guess[j]&&v[j]!=1) { b++; v[j] = 1; break; } } } s = num2str(a) + "A" + num2str(b) + "B"; return s; }
SHORT keycode(void) { USHORT key; char image[6], *s; key= getkey(); s= num2str(image, key, 5, '\0'); while (*s) view_addkey (*s++); }
void xAxis(){ int i,j; gfx_color(0,0,255); gfx_line(0,250,500,250); for(i=0,j=-10;i <= 500,j<=10; i+=25,j++){ gfx_line(i,240,i,260); gfx_color(255,255,255); gfx_text(i,275, num2str(j)); } }
void yAxis(){ int i,j; gfx_color(0,0,255); gfx_line(250,0,250,500); for(i=0,j=-10;i<=500,j<=10;i+=25,j++){ gfx_line(240,i,260,i); gfx_color(255,255,255); gfx_text(225,i, num2str(j)); } }
const map<uint64_t, set<string> > EachNode::match(const Model &m, ModelGetter *getter){ map<uint64_t, set<string> > ret; if(m.attr<bool>("deleted")) return ret; uint64_t fn = m.fullname(); string type = m.type(); if(type == etype){ ret[fn].insert("#"+num2str(fn)); } return ret; }
void cESBTL::pdbTransRotTrans(const std::string& fileIn, const std::string& fileOut, const cVector3<double>& offset1, const cVector3<double>& angle, const cVector3<double>& offset2) { checkExtension(fileIn); checkExtension(fileOut); // input ESBTL::PDB_line_selector pdbSelector; std::vector<ESBTL::Default_system> pdbSystems; ESBTL::All_atom_system_builder<ESBTL::Default_system> pdbBuilder(pdbSystems, pdbSelector.max_nb_systems()); require(ESBTL::read_a_pdb_file(fileIn, pdbSelector, pdbBuilder, Occupancy_policy_all()), "cannot read PDB file"); require(!pdbSystems.empty(), "No PDB system"); require( pdbSystems.size() == 1, "More than one PDB system: pdbSystems.size() = " + num2str(pdbSystems.size())); require(!pdbSystems[0].has_no_model(), "No model in 1st PDB system"); require( pdbSystems[0].number_of_models() == 1, "More than one model in 1st PDB system: pdbSystems[0].number_of_models() = " + num2str(pdbSystems[0].number_of_models())); // output std::ofstream output(fileOut.c_str()); assure(output); // translate - rotate - translate cVector3<double> pointRot; cMatrix33<double> matRot; transform_rotmat(angle[0], angle[1], angle[2], matRot[0][0], matRot[0][1], matRot[0][2], matRot[1][0], matRot[1][1], matRot[1][2], matRot[2][0], matRot[2][1], matRot[2][2], ROT3D_RIGHT_ZYZ); for (ESBTL::Default_system::Models_iterator iterModel = pdbSystems[0].models_begin(); iterModel != pdbSystems[0].models_end(); iterModel++) { const ESBTL::Default_system::Model& model = *iterModel; for (ESBTL::Default_system::Model::Atoms_const_iterator iterAtom = model.atoms_begin(); iterAtom != model.atoms_end(); iterAtom++) { ESBTL::Default_system::Atom atom(*iterAtom); pointRot = matRot * cVector3<double>(atom.x() + offset1[0], atom.y() + offset1[1], atom.z() + offset1[2]); atom.x() = pointRot[0] + offset2[0]; atom.y() = pointRot[1] + offset2[1]; atom.z() = pointRot[2] + offset2[2]; output << ESBTL::PDB::get_atom_pdb_format(atom) << "\n"; } } }
int main(int argc, char *argv[]) { char *path = "sequences/cokecan/img"; char *ext = "png"; int numLength = 5; char numString[numLength+1]; char filename[255]; int start = 0; int end = 291; cv::Point2f initTopLeft(150,82); cv::Point2f initBottomDown(170,118); CMT cmt; //cmt.estimateRotation = false; for(int i = start; i <= end; i++) { num2str(numString, numLength+1, i); sprintf(filename, "%s%s.%s", path, numString, ext); #ifdef DEBUG_MODE qDebug() << filename; #endif cv::Mat img = cv::imread(filename); cv::Mat im_gray; cv::cvtColor(img, im_gray, CV_RGB2GRAY); if(i == start) cmt.initialise(im_gray, initTopLeft, initBottomDown); cmt.processFrame(im_gray); for(int i = 0; i<cmt.trackedKeypoints.size(); i++) cv::circle(img, cmt.trackedKeypoints[i].first.pt, 3, cv::Scalar(255,255,255)); cv::line(img, cmt.topLeft, cmt.topRight, cv::Scalar(255,255,255)); cv::line(img, cmt.topRight, cmt.bottomRight, cv::Scalar(255,255,255)); cv::line(img, cmt.bottomRight, cmt.bottomLeft, cv::Scalar(255,255,255)); cv::line(img, cmt.bottomLeft, cmt.topLeft, cv::Scalar(255,255,255)); #ifdef DEBUG_MODE qDebug() << "trackedKeypoints"; for(int i = 0; i<cmt.trackedKeypoints.size(); i++) qDebug() << cmt.trackedKeypoints[i].first.pt.x << cmt.trackedKeypoints[i].first.pt.x << cmt.trackedKeypoints[i].second; qDebug() << "box"; qDebug() << cmt.topLeft.x << cmt.topLeft.y; qDebug() << cmt.topRight.x << cmt.topRight.y; qDebug() << cmt.bottomRight.x << cmt.bottomRight.y; qDebug() << cmt.bottomLeft.x << cmt.bottomLeft.y; #endif imshow("frame", img); cv::waitKey(1); } return 0; }
bool read_record(Driver* driver, string record){ if (record == CONTINUE) return true; if (isallspace(record)) return false; istringstream is(record, ios::in); string line; int i = 0; do{ ++i; line = line.substr(0, line.find(COMMENT)); if (!line.empty() && !isallspace(line)){ char tag = line[0]; string line2 = line.substr(1); try{ switch(tag){ case OBJTAG: if (driver->target.empty()) read_objective(driver, line2); break; case ARGTAG: if (driver->arg.empty()) driver->set_args(line2); break; //case EXTTAG: // driver->set_externals(line2, true);//externalise the list provided in line2 // break; //case INTTAG: // driver->set_externals(line2, false);//internalise the list provided in line2 // break; case EXTTAG://w/ simply set externals with '\' driver->set_externals_gfa(line2); break; case VMAXTAG: driver->lp->setVMax(str2double(line2)); break; // case TTAG: // if (driver->thermo) ((ThermoLP*)driver->lp)->setTemperature(T0 + str2double(line2)); // break; default: try{ read_constraint(driver, line, tag); } catch(exception &e){;} } } catch(exception &e) { throw runtime_error(string("error in line ") + num2str(i) + ": " + e.what()); } } } while(getline(is, line, NEWLINE)); return true; }
//获取STM32内部温度传感器的温度 //temp:存放温度字符串的首地址.如"28.3"; //temp,最少得有5个字节的空间! void get_temperature(u8 *temp) { u16 t; float temperate; temperate=Get_Adc_Average(ADC_CH_TEMP,10); temperate=temperate*(3.3/4096); temperate=(1.43-temperate)/0.0043+25; //计算出当前温度值 t=temperate*10;//得到温度 num2str(t/10,temp,2); temp[2]='.';temp[3]=t%10+'0';temp[4]=0; //最后添加结束符 }
void global_config_save(FILE *fp) { GdkColor c; fprintf(fp, "# fbpanel <profile> config file\n"); fprintf(fp, "# see http://fbpanel.sf.net/docs.html for complete configuration guide\n"); fprintf(fp, "\n\n"); fprintf(fp, "Global {\n"); fprintf(fp, " edge = %s\n", num2str(edge_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(edge_opt)) + 1, "none")); fprintf(fp, " allign = %s\n", num2str(allign_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(allign_opt)) + 1, "none")); fprintf(fp, " margin = %d\n", (int) margin_adj->value); fprintf(fp, " widthtype = %s\n", num2str(width_pair, gtk_combo_box_get_active(GTK_COMBO_BOX(width_opt)) + 1, "none")); fprintf(fp, " width = %d\n", (int) width_adj->value); fprintf(fp, " height = %d\n", (int) height_adj->value); fprintf(fp, " transparent = %s\n", num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tr_checkb)), "false")); gtk_color_button_get_color(GTK_COLOR_BUTTON(tr_colorb), &c); fprintf(fp, " tintcolor = #%06x\n", gcolor2rgb24(&c)); fprintf(fp, " alpha = %d\n", gtk_color_button_get_alpha(GTK_COLOR_BUTTON(tr_colorb)) * 0xff / 0xffff); fprintf(fp, " setdocktype = %s\n", num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_dt_checkb)), "true")); fprintf(fp, " setpartialstrut = %s\n", num2str(bool_pair, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop_st_checkb)), "true")); fprintf(fp, "}\n\n"); }
//w/gni/ read record for Gene nutrient interaction(gni) bool read_record_gni(Driver* driver, Model* model, string record){ if (record == CONTINUE) return true; if (isallspace(record)) return false; istringstream is(record, ios::in); string line; int i = 0; do{ ++i; line = line.substr(0, line.find(COMMENT)); if (!line.empty() && !isallspace(line)){ char tag = line[0]; string line2 = line.substr(1); try{ switch(tag){ case OBJTAG: if (driver->target.empty()) throw runtime_error("please specify a biomass reaction!"); driver->gni->set_nts(line2, driver->externals, driver->model); // driver->gni->map_nt_reac(model); break; case DOLTAG: driver->gni->set_ntsp(line2); break; case ARGTAG: if (driver->arg.empty()) driver->set_args(line.substr(1)); break; // case EXTTAG: // driver->set_externals(line2, true);//externalise the list provided in line2 // break; // case INTTAG: // driver->set_externals(line2, false);//internalise the list provided in line2 // break; case EXTTAG: driver->set_externals_gfa(line2); break; default: try{ read_constraint_mod(driver, line, tag); } catch(exception &e){;} } } catch(exception &e) { throw runtime_error(string("error in line ") + num2str(i) + ": " + e.what()); } } } while(getline(is, line, NEWLINE)); return true; }
void Frame::write2file(string fname) { fname = fname + num2str(id) + ".txt"; ofstream file(fname.c_str()); for(int i=0; i<lines.size(); ++i) { if(lines[i].haveDepth) { file<<lines[i].line3d.A.x<<'\t'<<lines[i].line3d.A.y<<'\t'<<lines[i].line3d.A.z<<'\t' <<lines[i].line3d.B.x<<'\t'<<lines[i].line3d.B.y<<'\t'<<lines[i].line3d.B.z<<'\n'; } } {} file.close(); }
void print_table( const int& maxX, const int& maxY, const int& offY, const int& cursor ){ int maxPos = std::min( maxY, (int)options.tasks.size()); int gpos = maxX * .75; // print the table row mvaddstr(offY, 5, "Task Name"); mvaddstr(offY, gpos+2, "Task Groups"); string bar; for( int i=0; i<maxX; i++ ) bar+= '-'; mvaddstr( offY+1, 0, bar.c_str()); // print the columns for( size_t i=2+offY; i<maxY-5; i++ ) mvaddstr( i, gpos, "|" ); // print each row for( size_t i=0; i<maxPos; i++ ){ // name string name_entry = num2str(i+1) + string(": ") + options.tasks[i].name.c_str(); if( name_entry.size() >= gpos ) name_entry = name_entry.substr(0,gpos-1); // groups string group_entry = ""; for( int j=0; j<options.tasks[i].groups.size(); j++ ){ if( j == 0 ){ group_entry = options.tasks[i].groups[j]; } else { group_entry += string(", ") + options.tasks[i].groups[j]; } } if( i == cursor ){ attron( A_STANDOUT ); } mvaddstr( 2+i+offY, 3, name_entry.c_str() ); mvaddstr( 2+i+offY, gpos+2, group_entry.c_str()); if( i == cursor ){ attroff( A_STANDOUT ); } } }
/* * Client specific ETA */ static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *je) { struct gfio_client *gc = client->client_data; struct gui_entry *ge = gc->ge; static int eta_good; char eta_str[128]; char output[256]; char tmp[32]; double perc = 0.0; int i2p = 0; gdk_threads_enter(); eta_str[0] = '\0'; output[0] = '\0'; if (je->eta_sec != INT_MAX && je->elapsed_sec) { perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); eta_to_str(eta_str, je->eta_sec); } sprintf(tmp, "%u", je->nr_running); gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), tmp); sprintf(tmp, "%u", je->files_open); gtk_entry_set_text(GTK_ENTRY(ge->eta.files), tmp); #if 0 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) { if (je->m_rate || je->t_rate) { char *tr, *mr; mr = num2str(je->m_rate, 4, 0, i2p); tr = num2str(je->t_rate, 4, 0, i2p); gtk_entry_set_text(GTK_ENTRY(ge->eta); p += sprintf(p, ", CR=%s/%s KB/s", tr, mr); free(tr); free(mr); } else if (je->m_iops || je->t_iops)
// Encodes a tree to a single string. string serialize(TreeNode* root) { string ret, tmp; TreeNode dummy(0); dummy.right=root; queue<TreeNode*> q; q.push(&dummy); while (!q.empty()) { TreeNode *ptr = q.front(); q.pop(); if (ptr) { TreeNode *lft = ptr->left; TreeNode *rht = ptr->right; tmp = "null"; if (lft) { tmp = num2str(lft->val); q.push(lft); } ret += tmp + "|"; tmp = "null"; if (rht) { tmp = num2str(rht->val); q.push(rht); } ret += tmp + "|"; } } return ret; }
void cmd_readtest (uint64_t cluster, uint64_t size) { char buf[512]; uint64_t clustersize = size / 512; float time_before = SYSTIME; // Bytes lesen for (uint64_t b = 0; b < clustersize + 1; ++b) fat_read_file (cluster, (unsigned char *)buf, b); float duration = SYSTIME - time_before; uart_puts_P("Read "); uart_puts(num2str(size/1000, 10)); uart_puts_P(" kBytes in "); uart_puts(num2str(duration * 1000, 10)); uart_puts_P(" milliseconds.\r\n"); uart_puts_P("(Speed: "); uart_puts(num2str(((size / 1000) / duration), 10)); uart_puts_P(" kByte/s)\r\n"); }
string BinOpValue::getValue(){ string a=this->a->getValue(); string b=this->b->getValue(); if(!op.compare("+")){ try{ double x=str2num(a); double y=str2num(b); return num2str(x+y); }catch(string &tx){ return a+b; }//end try }else if(!op.compare("-")){ TRY_NUM(-); }else if(!op.compare("*")){
void status_col (SHORT col) { //static SHORT old_col= -1; static SHORT old_col = 1; char image[12], *s; //if (old_col == ++col) return; if (old_col == col) return; DBG_STATUS(dout<<"status_col short col = "<<col<<endl); s= num2str(image, col, 5, 0); left_just (s, 5); DBG_STATUS(dout<<"status_col string col = "<<col<<endl); statw.put(0, 71, s); old_col = col; }
ostream &operator << (ostream &out, const stomap &sto){ if (sto.size() > 0){ strvec items; for (stomap::const_iterator it = sto.begin(); it != sto.end(); ++it){ double coef = it->second; string item = (coef == 1) ? "" : num2str(coef) + SPACE; item += it->first; items.push_back(item); } int i; for (i = 0; i < items.size() - 1; i++) out << items[i] << SPACE << PLUS << SPACE; out << items[i]; } return out; }