static void save_db(const char *fn, struct res_db *db) { FILE *fp = fopen(fn, "w"); struct conv_res *cr; if (!fp) { printf("failed to open (%s) to write\n", fn); return ; } for (cr = db->res_list.next; cr; cr = cr->next) { dump_res(fp, cr); } }
static void dump_res(Resource *n, int l) { int i; for (i=0; i<n->c; i++) { if (n->v[i].subres) { printf("%*cn[%s] = {\n", l, ' ', n->v[i].name? n->v[i].name :""); dump_res(n->v[i].subres, l+3); printf("%*c}\n", l, ' '); } else printf("%*cn[%s] = v[%s]\n", l, ' ', n->v[i].name? n->v[i].name :"", n->v[i].value? n->v[i].value :""); } }
int run_tests(int argc, char **args) { memset(&test_main, 0, sizeof(test_main)); int arg; int incl_filter = 0; int excl_filter = 0; for (arg = 1; arg < argc; arg++) { if (strlen(args[arg]) == 0) continue; if (0 == strcmp("-f", args[arg])) { incl_filter = 1; continue; } if (0 == strcmp("-e", args[arg])) { excl_filter = 1; continue; } if (incl_filter) { strcpy(test_main.incl_filter, args[arg]); incl_filter = 0; } else if (excl_filter) { strcpy(test_main.excl_filter, args[arg]); excl_filter = 0; } else { printf("running tests from %s\n", args[arg]); FILE *fd = fopen(args[1], "r"); if (fd == NULL) { printf("%s not found\n", args[arg]); return -2; } test_main.spec = fd; } } DBGT("adding suites...\n"); add_suites(); DBGT("%i tests added\n", test_main.test_count); if (test_main.spec) { fclose(test_main.spec); } if (test_main.test_count == 0) { printf("No tests to run\n"); return 0; } int fd_success = open("_tests_ok", O_APPEND | O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); int fd_bad = open("_tests_fail", O_APPEND | O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); DBGT("running tests...\n"); int ok = 0; int failed = 0; int stopped = 0; test *cur_t = test_main.tests; int i = 1; while (cur_t) { cur_t->setup(cur_t); test *next_test = cur_t->_next; DBGT("TEST %i/%i : running test %s\n", i, test_main.test_count, cur_t->name); i++; int start_error_count = get_error_count(); int res = cur_t->f(cur_t); if (res == TEST_RES_OK && get_error_count() != start_error_count) { res = TEST_RES_FAIL; } cur_t->test_result = res; int fd = res == TEST_RES_OK ? fd_success : fd_bad; write(fd, cur_t->name, strlen(cur_t->name)); write(fd, "\n", 1); switch (res) { case TEST_RES_OK: ok++; printf(" .. ok\n"); break; case TEST_RES_FAIL: failed++; printf(" .. FAILED\n"); if (test_main.on_stop) test_main.on_stop(cur_t); add_res(cur_t, &test_main.failed, &test_main.failed_last); break; case TEST_RES_ASSERT: stopped++; printf(" .. ABORTED\n"); if (test_main.on_stop) test_main.on_stop(cur_t); add_res(cur_t, &test_main.stopped, &test_main.stopped_last); break; } cur_t->teardown(cur_t); free(cur_t); cur_t = next_test; } close(fd_success); close(fd_bad); DBGT("ran %i tests\n", test_main.test_count); printf("Test report, %i tests\n", test_main.test_count); printf("%i succeeded\n", ok); printf("%i failed\n", failed); dump_res(&test_main.failed); printf("%i stopped\n", stopped); dump_res(&test_main.stopped); if (ok < test_main.test_count) { printf("\nFAILED\n"); return -1; } else { printf("\nALL TESTS OK\n"); return 0; } }
int Video::upload_data( const uint64_t fileSize, const string &sha, const uint64_t sliceSize, const string &sign, const string &url, const string &srcPath, const uint64_t offset, const string &session ) { int ret = 0; char tmp_buf[1024]; char buf[sliceSize]; vector<string> headers; headers.push_back("Authorization: " + sign); ifstream fileInput(srcPath.c_str(), ios::in | ios::binary); fileInput.seekg(offset); uint64_t pos = offset; while (fileSize > pos) { reset(); uint64_t len =0; fileInput.read(buf, sliceSize); len = fileInput.gcount(); struct curl_httppost *firstitem = NULL, *lastitem = NULL; ret = curl_formadd(&firstitem, &lastitem, CURLFORM_COPYNAME, "op", CURLFORM_COPYCONTENTS, "upload_slice", CURLFORM_END); snprintf(tmp_buf, sizeof(tmp_buf), "%lu", pos); ret = curl_formadd(&firstitem, &lastitem, CURLFORM_COPYNAME, "offset", CURLFORM_COPYCONTENTS, tmp_buf, CURLFORM_END); ret = curl_formadd(&firstitem, &lastitem, CURLFORM_COPYNAME, "session", CURLFORM_COPYCONTENTS, session.c_str(), CURLFORM_END); ret = curl_formadd(&firstitem, &lastitem, CURLFORM_COPYNAME, "filecontent", CURLFORM_BUFFER, "data", CURLFORM_BUFFERPTR, buf, CURLFORM_BUFFERLENGTH, len, CURLFORM_END); int retry_times = 0; do { sendRequest( url, 1, &headers, NULL, firstitem); dump_res(); if (retCode == 0) { break; } retry_times++; } while(retry_times < MAX_RETRY_TIMES); curl_formfree(firstitem); if (retCode != 0) { return retCode; } pos += sliceSize; } return retCode; }
int Video::upload_slice( const string &srcPath, const string &bucketName, const string &dstPath, const string &videoCover, const string &bizAttr, const string &title, const string &desc, const string &magicContext, const int sliceSize, const string &session) { reset(); int ret = 0; ret = access(srcPath.c_str(), F_OK | R_OK); if (ret != 0) { retCode = VIDEO_FILE_NOT_EXISTS; retMsg = "file not exist or can not be read..."; return retCode; } string encodePath = videoUrlEncode(dstPath); uint64_t expired = time(NULL) + EXPIRED_SECONDS; string url = generateResUrl(bucketName, encodePath); string sign = Auth::appSign( APPID, SECRET_ID, SECRET_KEY, expired, bucketName); vector<string> headers; headers.push_back("Authorization: " + sign); uint64_t fileSize = 0; string sha1 = genFileSHA1AndLen(srcPath, &fileSize); upload_prepare(fileSize, sha1, sign, url, videoCover, bizAttr, title, desc, magicContext, session, sliceSize); dump_res(); if (retCode != 0) { return retCode; } if (retJson["data"].isMember("url")) { //秒传成功,直接返回了url return retCode; } if (!retJson["data"].isMember("offset") || !retJson["data"].isMember("session") || !retJson["data"].isMember("slice_size")) { return retCode; } upload_data(fileSize, sha1, retJson["data"]["slice_size"].asUInt64(), sign, url, srcPath, retJson["data"]["offset"].asUInt64(), retJson["data"]["session"].asString()); return retCode; }
void resource_dump (Resource *r) { dump_res (r, 0); }
int gmx_mindist(int argc, char *argv[]) { const char *desc[] = { "[THISMODULE] computes the distance between one group and a number of", "other groups. Both the minimum distance", "(between any pair of atoms from the respective groups)", "and the number of contacts within a given", "distance are written to two separate output files.", "With the [TT]-group[tt] option a contact of an atom in another group", "with multiple atoms in the first group is counted as one contact", "instead of as multiple contacts.", "With [TT]-or[tt], minimum distances to each residue in the first", "group are determined and plotted as a function of residue number.[PAR]", "With option [TT]-pi[tt] the minimum distance of a group to its", "periodic image is plotted. This is useful for checking if a protein", "has seen its periodic image during a simulation. Only one shift in", "each direction is considered, giving a total of 26 shifts.", "It also plots the maximum distance within the group and the lengths", "of the three box vectors.[PAR]", "Also [gmx-distance] calculates distances." }; const char *bugs[] = { "The [TT]-pi[tt] option is very slow." }; static gmx_bool bMat = FALSE, bPI = FALSE, bSplit = FALSE, bMax = FALSE, bPBC = TRUE; static gmx_bool bGroup = FALSE; static real rcutoff = 0.6; static int ng = 1; static gmx_bool bEachResEachTime = FALSE, bPrintResName = FALSE; t_pargs pa[] = { { "-matrix", FALSE, etBOOL, {&bMat}, "Calculate half a matrix of group-group distances" }, { "-max", FALSE, etBOOL, {&bMax}, "Calculate *maximum* distance instead of minimum" }, { "-d", FALSE, etREAL, {&rcutoff}, "Distance for contacts" }, { "-group", FALSE, etBOOL, {&bGroup}, "Count contacts with multiple atoms in the first group as one" }, { "-pi", FALSE, etBOOL, {&bPI}, "Calculate minimum distance with periodic images" }, { "-split", FALSE, etBOOL, {&bSplit}, "Split graph where time is zero" }, { "-ng", FALSE, etINT, {&ng}, "Number of secondary groups to compute distance to a central group" }, { "-pbc", FALSE, etBOOL, {&bPBC}, "Take periodic boundary conditions into account" }, { "-respertime", FALSE, etBOOL, {&bEachResEachTime}, "When writing per-residue distances, write distance for each time point" }, { "-printresname", FALSE, etBOOL, {&bPrintResName}, "Write residue names" } }; output_env_t oenv; t_topology *top = NULL; int ePBC = -1; char title[256]; real t; rvec *x; matrix box; gmx_bool bTop = FALSE; FILE *atm; int i, j, nres = 0; const char *trxfnm, *tpsfnm, *ndxfnm, *distfnm, *numfnm, *atmfnm, *oxfnm, *resfnm; char **grpname; int *gnx; atom_id **index, *residues = NULL; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, "-od", "mindist", ffWRITE }, { efXVG, "-on", "numcont", ffOPTWR }, { efOUT, "-o", "atm-pair", ffOPTWR }, { efTRO, "-ox", "mindist", ffOPTWR }, { efXVG, "-or", "mindistres", ffOPTWR } }; #define NFILE asize(fnm) if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME | PCA_TIME_UNIT | PCA_BE_NICE, NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv)) { return 0; } trxfnm = ftp2fn(efTRX, NFILE, fnm); ndxfnm = ftp2fn_null(efNDX, NFILE, fnm); distfnm = opt2fn("-od", NFILE, fnm); numfnm = opt2fn_null("-on", NFILE, fnm); atmfnm = ftp2fn_null(efOUT, NFILE, fnm); oxfnm = opt2fn_null("-ox", NFILE, fnm); resfnm = opt2fn_null("-or", NFILE, fnm); if (bPI || resfnm != NULL) { /* We need a tps file */ tpsfnm = ftp2fn(efTPS, NFILE, fnm); } else { tpsfnm = ftp2fn_null(efTPS, NFILE, fnm); } if (!tpsfnm && !ndxfnm) { gmx_fatal(FARGS, "You have to specify either the index file or a tpr file"); } if (bPI) { ng = 1; fprintf(stderr, "Choose a group for distance calculation\n"); } else if (!bMat) { ng++; } snew(gnx, ng); snew(index, ng); snew(grpname, ng); if (tpsfnm || resfnm || !ndxfnm) { snew(top, 1); bTop = read_tps_conf(tpsfnm, title, top, &ePBC, &x, NULL, box, FALSE); if (bPI && !bTop) { printf("\nWARNING: Without a run input file a trajectory with broken molecules will not give the correct periodic image distance\n\n"); } } get_index(top ? &(top->atoms) : NULL, ndxfnm, ng, gnx, index, grpname); if (bMat && (ng == 1)) { ng = gnx[0]; printf("Special case: making distance matrix between all atoms in group %s\n", grpname[0]); srenew(gnx, ng); srenew(index, ng); srenew(grpname, ng); for (i = 1; (i < ng); i++) { gnx[i] = 1; grpname[i] = grpname[0]; snew(index[i], 1); index[i][0] = index[0][i]; } gnx[0] = 1; } if (resfnm) { nres = find_residues(top ? &(top->atoms) : NULL, gnx[0], index[0], &residues); if (debug) { dump_res(debug, nres, residues, index[0]); } } if (bPI) { periodic_mindist_plot(trxfnm, distfnm, top, ePBC, gnx[0], index[0], bSplit, oenv); } else { dist_plot(trxfnm, atmfnm, distfnm, numfnm, resfnm, oxfnm, rcutoff, bMat, top ? &(top->atoms) : NULL, ng, index, gnx, grpname, bSplit, !bMax, nres, residues, bPBC, ePBC, bGroup, bEachResEachTime, bPrintResName, oenv); } do_view(oenv, distfnm, "-nxy"); if (!bPI) { do_view(oenv, numfnm, "-nxy"); } return 0; }