void write_eig_sys_bin(const char* prefix, const int config_i, const int t, const int nb_ev, Eigen::MatrixXcd& V) { const int V3 = pars -> get_int("V3"); std::string path = pars -> get_path("res"); //set up filename char file [200]; sprintf(file, "%s/%s.%04d.%03d", path.c_str(), prefix, config_i, t); //sprintf(file, "%s.%04d.%03d", prefix, config_i, t); if(check_trace(V, nb_ev) != true){ std::cout << "Timeslice: " << t << ": Eigenvectors damaged, abort writing" << std::endl; exit(1); } std::cout << "Writing to file:" << file << std::endl; std::ofstream outfile(file, std::ofstream::binary); std::streamsize begin = outfile.tellp(); std::streamsize eigsys_bytes =2*3*V3*nb_ev*sizeof(double); outfile.write(reinterpret_cast<char*> (V.data()), eigsys_bytes); std::streamsize end = outfile.tellp(); if ( (end - begin)/eigsys_bytes != 1 ){ std::cout << "Timeslice: " << t << " Error: write incomplete, exiting" << std::endl; std::cout << (end-begin) << " bytes instead of expected "<< eigsys_bytes << " bytes" << std::endl; exit(1); } //std::cout << end - begin << " bytes written" << std::endl; outfile.close(); }
//Reads in Eigenvectors from one Timeslice in binary format to V void read_evectors_bin_ts(const char * path, const char* prefix, const int config_i, const int t, const int nb_ev, Eigen::MatrixXcd& V) { int V3 = pars -> get_int("V3"); //bool thorough = pars -> get_int("strict"); const int dim_row = 3 * V3; //TODO: Change path getting to something keyword independent //buffer for read in std::complex<double>* eigen_vec = new std::complex<double>[dim_row]; //setting up file char filename[200]; sprintf(filename, "%s/%s.%04d.%03d", path, prefix, config_i, t); std::cout << "Reading file: " << filename << std::endl; std::ifstream infile(filename, std::ifstream::binary); for (int nev = 0; nev < nb_ev; ++nev) { infile.read( reinterpret_cast<char*> (eigen_vec), 2*dim_row*sizeof(double)); V.col(nev) = Eigen::Map<Eigen::VectorXcd, 0 >(eigen_vec, dim_row); eof_check(t,nev,nb_ev,infile.eof()); } if(check_trace(V, nb_ev) != true){ std::cout << "Timeslice: " << t << ": Eigenvectors damaged, exiting" << std::endl; exit(0); } //clean up delete[] eigen_vec; infile.close(); }
int check_trace_body(Settings *opts, Trace_reader *trc, srf_t *srf) { char name[512]; Spot_info spot = { NULL, 0, 0, 0, 0, 0, 0 }; ztr_t *ztr = NULL; ztr_chunk_t *chunk; int start_chunk = 0; int i; if (-1 == construct_trace_name(srf->th.id_prefix, (unsigned char *)srf->tb.read_id, srf->tb.read_id_length, name, sizeof(name))) { printf("Couldn't construct read name\n"); return -1; } if (0 != decode_name(name, &spot)) { printf("Couldn't decode read name.\n"); return -1; } if (opts->verbosity > 0) { printf("%s\n", name); } if (0 != read_trace_data(opts, trc, &spot)) { printf("Couldn't get trace data for %s\n", name); return -1; } mfseek(srf->mf, srf->mf_end, SEEK_SET); if (srf->tb.trace_size) { mfwrite(srf->tb.trace, 1, srf->tb.trace_size, srf->mf); free(srf->tb.trace); srf->tb.trace = NULL; } mftruncate(srf->mf, mftell(srf->mf)); mfseek(srf->mf, srf->mf_pos, SEEK_SET); if (srf->ztr) { start_chunk = srf->ztr->nchunks; ztr = ztr_dup(srf->ztr); } if (NULL == partial_decode_ztr(srf, srf->mf, ztr)) { printf("Couldn't decode ZTR data for %s\n", name); return -1; } for (i = start_chunk; i < ztr->nchunks; i++) { chunk = &ztr->chunk[i]; if (opts->verbosity > 1) { printf(" Chunk %d type %.4s\n", i, (char *) &chunk->type); } switch (chunk->type) { case ZTR_TYPE_BASE: if (0 != uncompress_chunk(ztr, chunk)) { printf("Couldn't uncompress BASE chunk\n"); return -1; } if (trc->seq_len + 1 != chunk->dlength || 0 != memcmp(trc->seq, chunk->data + 1, trc->seq_len)) { printf("Sequence differs for %s\n", name); return -1; } break; case ZTR_TYPE_CNF1: if (0 != uncompress_chunk(ztr, chunk)) { printf("Couldn't uncompress CNF1 chunk\n"); return -1; } if (trc->seq_len + 1 != chunk->dlength || 0 != memcmp(trc->qual, chunk->data + 1, trc->seq_len)) { printf("CNF1 confidence values differ for %s\n", name); return -1; } break; case ZTR_TYPE_CNF4: if (0 != uncompress_chunk(ztr, chunk)) { printf("Couldn't uncompress CNF4 chunk\n"); return -1; } if (0 != check_cnf4(ztr, chunk, trc)) { printf("CNF4 confidence values differ for %s\n", name); return -1; } break; case ZTR_TYPE_SMP4: if (0 != uncompress_chunk(ztr, chunk)) { printf("Couldn't uncompress SMP4 chunk\n"); return -1; } if (0 != check_trace(ztr, chunk, trc)) { printf("Trace doesn't match for %s\n", name); return -1; } break; default: printf("Found unexpected chunk type in trace body for %s\n", name); return -1; } } delete_ztr(ztr); return 0; }
int trace_address (lua_State *L) { TRACE* v1 = check_trace(L,1); ADDRINT r = TRACE_Address(*v1); lua_pushnumber(L, r); return 1; }
int mark(int argc, char *argv[], int retc, char *retv[] ) { int firstarg, cmd_is_ds, mark_ret_val, num_num_args, reset_flag, trace_flag; double mark_args[ 4 ]; /************************************************************************/ /* Check for `reset' as a keyword. Need to verify syntax. Three */ /* situations: "reset" used improperly; "reset" used correctly; */ /* no "reset" keyword. */ /************************************************************************/ reset_flag = check_reset( argc, argv ); if (reset_flag < 0) ABORT; else if (reset_flag > 0) { if (do_mark_reset() == 0) RETURN; else ABORT; } /************************************************************************/ /* Check for `trace' as a keyword. Situation is similar to `reset', */ /* except there is no file name and the returned value distinguishes */ /* `trace' as first from `trace' as last argument (the only 2 choices) */ /************************************************************************/ firstarg = 1; /* Skip command name */ trace_flag = check_trace( argc, argv ); if (trace_flag < 0) ABORT; if (trace_flag != 0) { if (retc > 2) { Werrprintf( "%s: cannot return more than 2 values when using `trace' keyword", argv[ 0 ] ); ABORT; } if (trace_flag == 1) /* Skip over 1st argument */ firstarg = 2; /* if it was `trace' */ else /* Otherwise it was the last */ argc--; /* argument, so reduce total */ } /* number of arguments by 1 */ /************************************************************************/ /* Extract numeric values, number of numeric values. The `mark' */ /* command accepts 0, 1, 2 or 4 such arguments. If `num_vals_args' */ /* returns -1, the subroutine has already posted an error message. */ /************************************************************************/ num_num_args = num_vals_args( firstarg, argc, argv, &mark_args[ 0 ], 4 ); if (num_num_args < 0) ABORT; else if (num_num_args == 3 || num_num_args > 4) { Werrprintf( "%s: incorrect number of numeric arguments", argv[ 0 ] ); ABORT; } /************************************************************************/ /* Get the current graphics command to establish if DS was the last */ /* such command executed. In that case, we perform a 1D operation */ /* unless MARK was called with 4 numeric arguments. */ /* */ /* Abort if current graphics command is not DS or DCONI. Add checks */ /* for other display commands (DCON, DPCON, etc.) here if required. */ /************************************************************************/ cmd_is_ds = WgraphicsdisplayValid( "ds" ); if ( !cmd_is_ds && !WgraphicsdisplayValid( "dconi" ) && num_num_args == 0 ) { Werrprintf( "%s: requires arguments when no data displayed", argv[ 0 ] ); ABORT; } /************************************************************************/ /* `init2d' subroutine defines `d2flag' and many other important */ /* variables. First argument instructs `init2d' to set "reverse" */ /* flag if trace = "f1". Second argument instructs `init2d' to */ /* prepare chart variables for displaying data. */ /************************************************************************/ if (init2d( 1, 1 )) ABORT; /************************************************************************/ /* Now that `d2flag' is defined, check on 4 more error conditions: */ /* A. 2D data is present, last command not `ds', 1 numeric argument */ /* and no `trace' keyword. */ /* B. No 2D data present and 4 numeric arguments entered. */ /* C. No 2D data present and the `trace' keyword was used. */ /* D. No 2D data present and command returns more than 2 values. */ /************************************************************************/ if (d2flag) { if (trace_flag == 0 && cmd_is_ds == 0 && num_num_args == 1) { Werrprintf( "%s: 'trace' keyword required with 2D data and 1 numeric argument", argv[ 0 ] ); ABORT; } } else { /* No 2D data */ if (num_num_args == 4) { Werrprintf( "%s: Cannot have 4 numeric arguments with 1D data", argv[ 0 ] ); ABORT; } if (trace_flag) { Werrprintf( "%s: Cannot use 'trace' keyword with 1D data", argv[ 0 ] ); ABORT; } if (retc > 2) { Werrprintf( "%s: Cannot return more than 2 values with 1D data", argv[ 0 ] ); ABORT; } } /* 2D operations. If 2D data is present and the `trace' keyword was NOT selected, then there were either 2 or 4 numeric arguments. */ if (num_num_args == 4 || (d2flag && trace_flag == 0 && cmd_is_ds == 0)) { mark_ret_val = do_2d_mark( retc, retv, num_num_args, &mark_args[ 0 ] ); } /* 1D operations. Come here if A. num_num_args != 4 AND B. d2flag is clear OR trace_flag is set OR cmd_is_ds is set. */ else { mark_ret_val = do_1d_mark( cmd_is_ds, retc, retv, num_num_args, &mark_args[ 0 ] ); } if (mark_ret_val == 0) RETURN; else ABORT; }
int trace_stub_size (lua_State *L) { TRACE* v1 = check_trace(L,1); USIZE r = TRACE_StubSize(*v1); lua_pushnumber(L, r); return 1; }
int trace_rtn (lua_State *L) { TRACE* v1 = check_trace(L,1); RTN_to_lua(L, TRACE_Rtn(*v1)); return 1; }
int trace_bbl_head (lua_State *L) { TRACE* v1 = check_trace(L,1); BBL_to_lua(L, TRACE_BblHead(*v1)); return 1; }
int trace_num_bbl (lua_State *L) { TRACE* v1 = check_trace(L,1); UINT32 r = TRACE_NumBbl(*v1); lua_pushnumber(L, r); return 1; }
int trace_bbl_tail (lua_State *L) { TRACE* v1 = check_trace(L,1); BBL_to_lua(L, TRACE_BblTail(*v1)); return 1; }
int trace_original (lua_State *L) { TRACE* v1 = check_trace(L,1); BOOL r = TRACE_Original(*v1); lua_pushboolean(L, r); return 1; }
int trace_has_fall_through (lua_State *L) { TRACE* v1 = check_trace(L,1); BOOL r = TRACE_HasFallThrough(*v1); lua_pushboolean(L, r); return 1; }