int main(int argc, char *argv[]) { if (argc != 4) { fprintf(stderr, "ERROR: Invalid usage.\nUSAGE: %s LOCATIONS PATH COUNT\n", argv[0]); return EXIT_FAILURE; } sscanf(argv[3], "%d", &num_cities); distances = alloc2dcontiguous(num_cities, num_cities); if ( parse_input_file(argv[1], num_cities) != 0) return EXIT_FAILURE; if (parse_path_file(argv[2], num_cities) != 0) return EXIT_FAILURE; /* --------------------------------------------------------------------- */ /* | Memory deallocation and exit | */ /* frees up the memory allocated for our arrays. * * recall that the array was initiated in one * * contiguous chunk, so one call to free should * * deallocate the whole underlying structure. */ free(&distances[0][0]); free(distances); return EXIT_SUCCESS; /* | | */ /* --------------------------------------------------------------------- */ }
int main(int argc, char *argv[]) { MY_INIT(argv[0]); { uint row_count; struct errors *error_head; struct languages *lang_head; DBUG_ENTER("main"); charsets_dir= DEFAULT_CHARSET_DIR; my_umask_dir= 0777; if (get_options(&argc, &argv)) DBUG_RETURN(1); if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head))) { fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); DBUG_RETURN(1); } #if MYSQL_VERSION_ID >= 50100 && MYSQL_VERSION_ID < 50500 /* Number of error messages in 5.1 - do not change this number! */ #define MYSQL_OLD_GA_ERROR_MESSAGE_COUNT 641 #elif MYSQL_VERSION_ID >= 50500 && MYSQL_VERSION_ID < 50600 /* Number of error messages in 5.5 - do not change this number! */ #define MYSQL_OLD_GA_ERROR_MESSAGE_COUNT 728 #endif #if MYSQL_OLD_GA_ERROR_MESSAGE_COUNT if (row_count != MYSQL_OLD_GA_ERROR_MESSAGE_COUNT) { fprintf(stderr, "Can only add new error messages to latest GA. "); fprintf(stderr, "Use ER_UNKNOWN_ERROR instead.\n"); fprintf(stderr, "Expected %u messages, found %u.\n", MYSQL_OLD_GA_ERROR_MESSAGE_COUNT, row_count); DBUG_RETURN(1); } #endif if (lang_head == NULL || error_head == NULL) { fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); DBUG_RETURN(1); } if (create_header_files(error_head)) { fprintf(stderr, "Failed to create header files\n"); DBUG_RETURN(1); } if (create_sys_files(lang_head, error_head, row_count)) { fprintf(stderr, "Failed to create sys files\n"); DBUG_RETURN(1); } clean_up(lang_head, error_head); DBUG_LEAVE; /* Can't use dbug after my_end() */ my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return 0; } }
void parse_command_line(int argc, char** argv, std::vector<Bridge>& bridges, std::list<int32_t>& send_order) { parse_input_file(argv[1], bridges); // Parse rest of line for ordering for (auto i = 2; i < argc; ++i) { send_order.push_back(std::stoi(std::string(argv[i]))); } }
bool checkSelfConjugate(vec_mp test_point, BertiniRealConfig & program_options, boost::filesystem::path input_file) { // setup input file int *declarations = NULL; partition_parse(&declarations, input_file, "func_input_real", "config_real",0); // the 0 means not self conjugate free(declarations); //check existence of the required witness_data file. FILE *IN = safe_fopen_read("witness_data"); fclose(IN); //we put the point and its conjugate into the same member points file and run the membership test simultaneously with one bertini call. membership_test_input_file("input_membership_test", "func_input_real", "config_real",3); //setup member_points file, including both the first witness point, and its complex-conjugate write_member_points_sc(test_point);//,fmt int blabla; parse_input_file("input_membership_test", &blabla); membershipMain(13423, blabla, 0, 1, 0); initMP(mpf_get_default_prec()); std::vector<int> component_numbers = read_incidence_matrix(); if (component_numbers[0]==component_numbers[1]) { // printf("component IS self conjugate\n"); return true; } else { // printf("component is NOT self conjugate\n"); return false; } }
// The main printing driver. int main(int argc, char** argv) { if (argc < 2) { usage(argv[0]); return -1; } // Web page input source. std::string input; if (argc == 2) { // Read from file. if (!parse_input_file(argv[1], input)) { std::cout << "Error: Unable to open file '" << argv[1] << "'\n"; return 1; } } else if (argc == 3) { // Fetch an http request. if (!get_http_request(argv[1], argv[2], input)) { std::cout << "Error: Unable to get path '" << argv[2] << "' from host '" << argv[1] << "'\n"; return 1; } } // Build a token list. std::vector<std::string> token_list = webex::lexer::build_tokens(input); if (token_list.empty()) { std::cout << "Error: No token list generated.\n"; return 2; } std::cout << "Token list generated.\n"; // Parse the token list into a tree. webex::Source* tree = webex::parser::build_tree(token_list); if (!tree) { std::cout << "Error: No parse tree generated.\n"; return 3; } std::cout << "Parse tree generated.\n"; // Print the contents of the tree. webex::Tag_print printer(std::cout); printer.eval(tree); // Clean up. delete tree; return 0; }
w_err_t parse_line(char *buff,pack_info_s *info) { w_int32_t cnt; char *str[2]; cnt = wind_strsplit(buff,'=',str,2); WIND_ASSERT_RETURN(cnt == 2,W_ERR_FAIL); if(wind_strcmp(str[0],"arch") == 0) { wind_strcpy(info->arch_name,str[1]); wind_notice("arch : %s",info->arch_name); } else if(wind_strcmp(str[0],"cpu") == 0) { wind_strcpy(info->cpu_name,str[1]); wind_notice("cpu : %s",info->cpu_name); } else if(wind_strcmp(str[0],"board") == 0) { wind_strcpy(info->board_name,str[1]); wind_notice("board : %s",info->board_name); } else if(wind_strcmp(str[0],"hardversion") == 0) { parse_version(&info->hw_version,str[1]); wind_notice("hard_version : %d.%d.%d",DWORD_HBYTE2(info->hw_version), DWORD_HBYTE3(info->hw_version),DWORD_HBYTE4(info->hw_version)); } else if(wind_strcmp(str[0],"softversion") == 0) { parse_version(&info->sw_version,str[1]); wind_notice("soft_version : %d.%d.%d",DWORD_HBYTE2(info->sw_version), DWORD_HBYTE3(info->sw_version),DWORD_HBYTE4(info->sw_version)); } //else if(wind_strcmp(str[0],"encrypt") == 0) // parse_encrypt_type(info,str[1]); //else if(wind_strcmp(str[0],"encryptkey") == 0) // parse_encrypt_key(info,str[1]); else if(wind_strcmp(str[0],"inputfile") == 0) { parse_input_file(info,str[1]); } else if(wind_strcmp(str[0],"outputfile") == 0) { wind_strcpy(info->output_file,str[1]); wind_notice("outputfile : %s",info->output_file); } return W_ERR_OK; }
int get_incidence_number(vec_mp test_point, BertiniRealConfig & program_options, boost::filesystem::path input_file) { // setup input file int *declarations = NULL; partition_parse(&declarations, input_file, "func_input_real", "config_real",0); // the 0 means not self conjugate free(declarations); //check existence of the required witness_data file. FILE *IN = NULL; IN = safe_fopen_read("witness_data"); fclose(IN); //only need to do this once. we put the point and its conjugate into the same member points file and run the membership test simultaneously with one bertini call. membership_test_input_file("input_membership_test", "func_input_real", "config_real",3); //setup member_points file, including both the first witness point, and its complex-conjugate write_member_points_singlept(test_point); // std::vector<std::string> command_line_options; // command_line_options.push_back("input_membership_test"); // int blabla; parse_input_file("input_membership_test", &blabla); membershipMain(13423, blabla, 0, 1, 0); initMP(mpf_get_default_prec()); // bertini_main_wrapper(command_line_options, 1, 0,0); std::vector<int> component_number = read_incidence_matrix(); return component_number[0]; }
int main(int argc, char *argv[]) { MY_INIT(argv[0]); { uint row_count; struct errors *error_head; struct languages *lang_head; DBUG_ENTER("main"); charsets_dir= DEFAULT_CHARSET_DIR; my_umask_dir= 0777; if (get_options(&argc, &argv)) DBUG_RETURN(1); if (!(row_count= parse_input_file(TXTFILE, &error_head, &lang_head))) { fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); DBUG_RETURN(1); } if (lang_head == NULL || error_head == NULL) { fprintf(stderr, "Failed to parse input file %s\n", TXTFILE); DBUG_RETURN(1); } if (create_header_files(error_head)) { fprintf(stderr, "Failed to create header files\n"); DBUG_RETURN(1); } if (create_sys_files(lang_head, error_head, row_count)) { fprintf(stderr, "Failed to create sys files\n"); DBUG_RETURN(1); } clean_up(lang_head, error_head); DBUG_LEAVE; /* Can't use dbug after my_end() */ my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return 0; } }
QuickUnion* create_quick_union(const std::string& file_name) { int size = 0; i__pair *int_list = nullptr; parse_input_file(file_name,size,&int_list); if(int_list != nullptr && size != 0) { QuickUnion *uFind = new QuickUnion(); uFind->printData(); for(int index = 0; index < size ; index++) { if(!uFind->is_connected(int_list[index].first_number, int_list[index].second_number)) { uFind->m_createUnion(int_list[index].first_number, int_list[index].second_number); } } delete[] int_list; return uFind; } return nullptr; }
int main(int argc, char **argv) { void (*hook_print_SE)(const qnu*, const Lagr*, const nmpc&) = NULL; void (*hook_print_LG)(const qnu*, const Lagr*, const nmpc&, const float*) = NULL; void (*hook_print_SD)(const unsigned int*, const double*) = NULL; void (*hook_print_TR)(const unsigned int*, const double*) = NULL; double (*hook_exec_control_horiz)(qnu*, const nmpc&, robot*) = NULL; char errnote[256]; unsigned int sd_loop = 0, k = 0, current_tgt_no = 0; float tgtdist, grad_dot_grad = 0.; robot vme; double sd_loop_time, time_last_cmd_sent = 0, now; nmpc C; cl_opts clopts = { false }; parse_command_line(argc, argv, &vme, &clopts); parse_input_file(C, vme.conffile()); print_greeting(C); qnu* qu = (qnu*) calloc(C.N, sizeof(qnu)); Lagr* p = (Lagr*) calloc(C.N, sizeof(Lagr)); //cmd* cmd_horiz = (cmd*) calloc(C.C, sizeof(cmd)); float* grad = (float*) calloc(C.N + 1, sizeof(float)); float* last_grad = (float*) calloc(C.N + 1, sizeof(float)); double* time_to_tgt = (double*) calloc(C.ntgt, sizeof(float)); C.cur_tgt = C.tgt; C.control_step = 0; init_qu_and_p(qu, p, C); tgtdist = C.tgttol + 1; // Just to get us into the waypoint loop. C.horizon_loop = 0; /* * This next block of decisions sort out the hooks used to print output. * Rather than include the ifs in each loop, I'm using function pointers * which are set at runtime based on CL flags for verbosity. */ if (clopts.selec_verbose) { hook_print_SE = &print_pathnerr; hook_print_LG = &print_LG; hook_print_SD = &print_SD; hook_print_TR = &print_TR; } else if (clopts.selec_verbose) { hook_print_SE = &empty_output_hook; hook_print_LG = &empty_output_hook; hook_print_SD = &empty_output_hook; hook_print_TR = &empty_output_hook; } else { if (clopts.selec_state_and_error_SE) hook_print_SE = &print_pathnerr; else hook_print_SE = &empty_output_hook; if (clopts.selec_lagrange_grad_LG) hook_print_LG = &print_LG; else hook_print_LG = &empty_output_hook; if (clopts.selec_SD_converged_SD) hook_print_SD = &print_SD; else hook_print_SD = &empty_output_hook; if (clopts.selec_target_reached_TR) hook_print_TR = &print_TR; else hook_print_TR = &empty_output_hook; } if (clopts.selec_sim) hook_exec_control_horiz = &exec_control_horiz_dummy; else hook_exec_control_horiz = &exec_control_horiz_vme; if (!clopts.selec_sim) { vme.tcp_connect(); vme.update_poshead(qu, C); } /* * Enter the loop which will take us through all waypoints. */ while (current_tgt_no < C.ntgt) { time_to_tgt[current_tgt_no] = -wall_time(); C.cur_tgt = &C.tgt[current_tgt_no * 2]; tgtdist = C.tgttol + 1; while (tgtdist > .1) { C.horizon_loop += 1; sd_loop = 0; sd_loop_time = -wall_time(); /* * SD loop. */ while (1) { sd_loop += 1; grad_dot_grad = 0.; /* * The core of the gradient decent is in the next few lines: */ tgtdist = predict_horizon(qu, p, C); get_gradient(qu, p, C, grad); for (k = 0; k < C.N; k++) { grad_dot_grad += grad[k] * last_grad[k]; } /* * Detect direction changes in the gradient by inspecting the * product <grad, last_grad>. If it is positive, then the * iterations are successfully stepping to the minimum, and we * can accelerate by increasing dg. If we overshoot (and the * product becomes negative), then backstep and drop dg to a * safe value. */ if (grad_dot_grad > 0) { C.dg *= 2; for (k = 0; k < C.N; ++k) { qu[k].Dth -= C.dg * grad[k]; } } else { C.dg = 0.1; // TODO: Adaptive. for (k = 0; k < C.N; ++k) { qu[k].Dth += C.dg * grad[k]; } } swap_fptr(&grad, &last_grad); if (last_grad[C.N] < .1) break; if (sd_loop >= MAX_SD_ITER) { sprintf(errnote, "Reached %d SD iterations. Stopping.", sd_loop); report_error(EXCEEDED_MAX_SD_ITER, errnote); } } hook_print_SE(qu, p, C); hook_print_LG(qu, p, C, grad); sd_loop_time += wall_time(); hook_print_SD(&sd_loop, &sd_loop_time); C.control_step += C.C; hook_exec_control_horiz(qu, C, &vme); for (k = 0; k < C.N - C.C - 1; ++k) { // cmd_horiz[k].v = qu[k].v; // cmd_horiz[k].Dth = qu[k].Dth; qu[k].v = qu[k + C.C].v; qu[k].Dth = qu[k + C.C].Dth; } if (C.control_step > MAX_NMPC_ITER * C.C) { sprintf(errnote, "Reached %d NMPC steps without reaching tgt. Stopping.", MAX_NMPC_ITER); report_error(TRAPPED_IN_NMPC_LOOP, errnote); } /* * The last thing we do is get the new position and heading for * the next SD calculation. */ // vme.update_poshead(qu); } time_to_tgt[current_tgt_no] += wall_time(); hook_print_TR(¤t_tgt_no, &time_to_tgt[current_tgt_no]); ++current_tgt_no; } return 0; }
int main(int argc, char* argv[]) { if (argc <= 1) { printf("wine spec file convert tool\nusage: %s specfile(16bit only) module name\n%s specfile(16bit only) -DEF\n", argv[0], argv[0]); fatal_error("file argument '%s' not allowed in this mode\n", argv[0]); } DLLSPEC *spec = alloc_dll_spec(); spec_file_name = argv[1]; exec_mode = MODE_DLL; spec->type = SPEC_WIN16; spec->file_name = spec_file_name; output_file = stdout; // init_dll_name(spec); if (argc > 2) { if (!strcmp(argv[2], "-DEF")) { exec_mode = MODE_DEF; } else { spec->main_module = xstrdup(argv[2]); spec->dll_name = xstrdup(argv[2]); } } else { init_dll_name(spec); } switch (exec_mode) { case MODE_DEF: if (!spec_file_name) fatal_error("missing .spec file\n"); if (!parse_input_file(spec)) break; output_def_file(spec, 1); break; case MODE_DLL: if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE) spec->characteristics |= IMAGE_FILE_DLL; /* fall through */ case MODE_EXE: load_resources(argv, spec); load_import_libs(argv); if (spec_file_name && !parse_input_file(spec)) break; if (fake_module) { if (spec->type == SPEC_WIN16) output_fake_module16(spec); else output_fake_module(spec); break; } //read_undef_symbols(spec, argv); switch (spec->type) { case SPEC_WIN16: output_spec16_file(spec); break; case SPEC_WIN32: BuildSpec32File(spec); break; default: assert(0); } break; } if (nb_errors) exit(1); return EXIT_SUCCESS; }
/******************************************************************* * main */ int main(int argc, char **argv) { DLLSPEC *spec = alloc_dll_spec(); #ifdef SIGHUP signal( SIGHUP, exit_on_signal ); #endif signal( SIGTERM, exit_on_signal ); signal( SIGINT, exit_on_signal ); output_file = stdout; argv = parse_options( argc, argv, spec ); switch(exec_mode) { case MODE_DLL: spec->characteristics |= IMAGE_FILE_DLL; load_resources( argv, spec ); load_import_libs( argv ); if (!spec_file_name) fatal_error( "missing .spec file\n" ); if (!parse_input_file( spec )) break; switch (spec->type) { case SPEC_WIN16: if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] ); BuildSpec16File( output_file, spec ); break; case SPEC_WIN32: read_undef_symbols( spec, argv ); BuildSpec32File( output_file, spec ); break; default: assert(0); } break; case MODE_EXE: if (spec->type == SPEC_WIN16) fatal_error( "Cannot build 16-bit exe files\n" ); if (!spec->file_name) fatal_error( "executable must be named via the -F option\n" ); load_resources( argv, spec ); load_import_libs( argv ); if (spec_file_name && !parse_input_file( spec )) break; read_undef_symbols( spec, argv ); BuildSpec32File( output_file, spec ); break; case MODE_DEF: if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] ); if (spec->type == SPEC_WIN16) fatal_error( "Cannot yet build .def file for 16-bit dlls\n" ); if (!spec_file_name) fatal_error( "missing .spec file\n" ); if (!parse_input_file( spec )) break; BuildDef32File( output_file, spec ); break; case MODE_RELAY16: if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] ); BuildRelays16( output_file ); break; case MODE_RELAY32: if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] ); BuildRelays32( output_file ); break; default: usage(1); break; } if (nb_errors) exit(1); if (output_file_name) { fclose( output_file ); if (output_file_source_name) assemble_file( output_file_source_name, output_file_name ); output_file_name = NULL; } return 0; }
/******************************************************************* * main */ int main(int argc, char **argv) { DLLSPEC *spec = alloc_dll_spec(); #ifdef SIGHUP signal( SIGHUP, exit_on_signal ); #endif signal( SIGTERM, exit_on_signal ); signal( SIGINT, exit_on_signal ); output_file = stdout; argv = parse_options( argc, argv, spec ); switch(exec_mode) { case MODE_DLL: if (spec->subsystem != IMAGE_SUBSYSTEM_NATIVE) spec->characteristics |= IMAGE_FILE_DLL; /* fall through */ case MODE_EXE: load_resources( argv, spec ); load_import_libs( argv ); if (spec_file_name && !parse_input_file( spec )) break; if (fake_module) { if (spec->type == SPEC_WIN16) output_fake_module16( spec ); else output_fake_module( spec ); break; } read_undef_symbols( spec, argv ); switch (spec->type) { case SPEC_WIN16: output_spec16_file( spec ); break; case SPEC_WIN32: BuildSpec32File( spec ); break; default: assert(0); } break; case MODE_DEF: if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] ); if (!spec_file_name) fatal_error( "missing .spec file\n" ); if (!parse_input_file( spec )) break; output_def_file( spec, 1 ); break; case MODE_IMPLIB: if (!spec_file_name) fatal_error( "missing .spec file\n" ); if (!parse_input_file( spec )) break; output_import_lib( spec, argv ); break; case MODE_RESOURCES: load_resources( argv, spec ); output_res_o_file( spec ); break; default: usage(1); break; } if (nb_errors) exit(1); if (output_file_name) { if (fclose( output_file ) < 0) fatal_perror( "fclose" ); if (output_file_source_name) assemble_file( output_file_source_name, output_file_name ); output_file_name = NULL; } return 0; }
void parse_args (int argc, char **argv, frame_info * frame, int *psy, unsigned long *num_samples, char inPath[MAX_NAME_SIZE], char outPath[MAX_NAME_SIZE], char **mot_file, char **icy_file) { FLOAT srate; int brate; frame_header *header = frame->header; int err = 0, i = 0; long samplerate = 0; /* preset defaults */ inPath[0] = '\0'; outPath[0] = '\0'; header->lay = DFLT_LAY; switch (DFLT_MOD) { case 's': header->mode = MPG_MD_STEREO; header->mode_ext = 0; break; case 'd': header->mode = MPG_MD_DUAL_CHANNEL; header->mode_ext = 0; break; /* in j-stereo mode, no default header->mode_ext was defined, gave error.. now default = 2 added by MFC 14 Dec 1999. */ case 'j': header->mode = MPG_MD_JOINT_STEREO; header->mode_ext = 2; break; case 'm': header->mode = MPG_MD_MONO; header->mode_ext = 0; break; default: fprintf (stderr, "%s: Bad mode dflt %c\n", programName, DFLT_MOD); abort (); } *psy = DFLT_PSY; if ((header->sampling_frequency = SmpFrqIndex ((long) (1000 * DFLT_SFQ), &header->version)) < 0) { fprintf (stderr, "%s: bad sfrq default %.2f\n", programName, DFLT_SFQ); abort (); } header->bitrate_index = 14; brate = 0; switch (DFLT_EMP) { case 'n': header->emphasis = 0; break; case '5': header->emphasis = 1; break; case 'c': header->emphasis = 3; break; default: fprintf (stderr, "%s: Bad emph dflt %c\n", programName, DFLT_EMP); abort (); } header->copyright = 0; header->original = 0; header->error_protection = FALSE; header->dab_extension = 0; glopts.input_select = INPUT_SELECT_WAV; /* process args */ while (++i < argc && err == 0) { char c, *token, *arg, *nextArg; int argUsed; token = argv[i]; if (*token++ == '-') { if (i + 1 < argc) nextArg = argv[i + 1]; else nextArg = ""; argUsed = 0; if (!*token) { /* The user wants to use stdin and/or stdout. */ if (inPath[0] == '\0') strncpy (inPath, argv[i], MAX_NAME_SIZE); else if (outPath[0] == '\0') strncpy (outPath, argv[i], MAX_NAME_SIZE); } while ((c = *token++)) { if (*token /* NumericQ(token) */ ) arg = token; else arg = nextArg; switch (c) { case 'm': argUsed = 1; if (*arg == 's') { header->mode = MPG_MD_STEREO; header->mode_ext = 0; } else if (*arg == 'd') { header->mode = MPG_MD_DUAL_CHANNEL; header->mode_ext = 0; } else if (*arg == 'j') { header->mode = MPG_MD_JOINT_STEREO; } else if (*arg == 'm') { header->mode = MPG_MD_MONO; header->mode_ext = 0; } else { fprintf (stderr, "%s: -m mode must be s/d/j/m not %s\n", programName, arg); err = 1; } break; case 'y': *psy = atoi (arg); argUsed = 1; break; case 'L': glopts.show_level = 1; break; case 's': argUsed = 1; srate = atof (arg); /* samplerate = rint( 1000.0 * srate ); $A */ samplerate = (long) ((1000.0 * srate) + 0.5); if ((header->sampling_frequency = SmpFrqIndex ((long) samplerate, &header->version)) < 0) err = 1; break; case 'j': glopts.input_select = INPUT_SELECT_JACK; break; case 'b': argUsed = 1; brate = atoi (arg); break; case 'd': argUsed = 1; if (*arg == 'n') header->emphasis = 0; else if (*arg == '5') header->emphasis = 1; else if (*arg == 'c') header->emphasis = 3; else { fprintf (stderr, "%s: -d emp must be n/5/c not %s\n", programName, arg); err = 1; } break; case 'P': argUsed = 1; *mot_file = arg; break; case 'p': argUsed = 1; header->dab_length = atoi(arg); break; case 'c': header->copyright = 1; break; case 'o': header->original = 1; break; case 'e': header->error_protection = TRUE; break; case 'r': glopts.usepadbit = FALSE; header->padding = 0; break; case 'q': argUsed = 1; glopts.quickmode = TRUE; glopts.usepsy = TRUE; glopts.quickcount = atoi (arg); if (glopts.quickcount == 0) { /* just don't use psy model */ glopts.usepsy = FALSE; glopts.quickcount = FALSE; } break; case 'a': glopts.downmix = TRUE; header->mode = MPG_MD_MONO; header->mode_ext = 0; break; case 'x': glopts.byteswap = TRUE; break; case 'v': argUsed = 1; glopts.vbr = TRUE; glopts.vbrlevel = atof (arg); glopts.usepadbit = FALSE; /* don't use padding for VBR */ header->padding = 0; /* MFC Feb 2003: in VBR mode, joint stereo doesn't make any sense at the moment, as there are no noisy subbands according to bits_for_nonoise in vbr mode */ header->mode = MPG_MD_STEREO; /* force stereo mode */ header->mode_ext = 0; break; case 'V': glopts.input_select = INPUT_SELECT_VLC; break; case 'W': argUsed = 1; *icy_file = arg; break; case 'l': argUsed = 1; glopts.athlevel = atof(arg); break; case 'h': usage (); break; case 'g': glopts.channelswap = TRUE; break; case 't': argUsed = 1; glopts.verbosity = atoi (arg); break; default: fprintf (stderr, "%s: unrec option %c\n", programName, c); err = 1; break; } if (argUsed) { if (arg == token) token = ""; /* no more from token */ else ++i; /* skip arg we used */ arg = ""; argUsed = 0; } } } else { if (inPath[0] == '\0') strcpy (inPath, argv[i]); else if (outPath[0] == '\0') strcpy (outPath, argv[i]); else { fprintf (stderr, "%s: excess arg %s\n", programName, argv[i]); err = 1; } } } /* Always enable DAB mode */ header->error_protection = TRUE; header->dab_extension = 2; header->padding = 0; glopts.dab = TRUE; if (header->dab_extension) { /* in 48 kHz */ /* if the bit rate per channel is less then 56 kbit/s, we have 2 scf-crc */ /* else we have 4 scf-crc */ /* in 24 kHz, we have 4 scf-crc, see main loop */ if (brate / (header->mode == MPG_MD_MONO ? 1 : 2) >= 56) header->dab_extension = 4; } if (err) usage (); /* If err has occured, then call usage() */ if (glopts.input_select != INPUT_SELECT_JACK && inPath[0] == '\0') usage (); /* If not in jack-mode and no file specified, then call usage() */ if (outPath[0] == '\0') { /* replace old extension with new one, 1992-08-19, 1995-06-12 shn */ new_ext (inPath, DFLT_EXT, outPath); } if (glopts.input_select == INPUT_SELECT_JACK) { musicin.jack_name = inPath; *num_samples = MAX_U_32_NUM; #if defined(JACK_INPUT) setup_jack(header, musicin.jack_name); #else fprintf(stderr, "JACK input not compiled in\n"); exit(1); #endif } else if (glopts.input_select == INPUT_SELECT_WAV) { if (!strcmp (inPath, "-")) { musicin.wav_input = stdin; /* read from stdin */ *num_samples = MAX_U_32_NUM; } else { if ((musicin.wav_input = fopen (inPath, "rb")) == NULL) { fprintf (stderr, "Could not find \"%s\".\n", inPath); exit (1); } parse_input_file (musicin.wav_input, inPath, header, num_samples); } } else if (glopts.input_select == INPUT_SELECT_VLC) { if (samplerate == 0) { fprintf (stderr, "Samplerate not specified\n"); exit (1); } *num_samples = MAX_U_32_NUM; int channels = (header->mode == MPG_MD_MONO) ? 1 : 2; #if defined(VLC_INPUT) if (vlc_in_prepare(glopts.verbosity, samplerate, inPath, channels, *icy_file) != 0) { fprintf(stderr, "VLC initialisation failed\n"); exit(1); } #else fprintf(stderr, "VLC input not compiled in\n"); exit(1); #endif } else { fprintf(stderr, "INVALID INPUT\n"); exit(1); } /* check for a valid bitrate */ if (brate == 0) brate = bitrate[header->version][10]; /* Check to see we have a sane value for the bitrate for this version */ if ((header->bitrate_index = BitrateIndex (brate, header->version)) < 0) err = 1; bs.zmq_framesize = 3 * brate; /* All options are hunky dory, open the input audio file and return to the main drag */ open_bit_stream_w (&bs, outPath, BUFFER_SIZE); }
void nullspace_config_setup_right(NullspaceConfiguration *ns_config, vec_mp *pi, // an array of projections, the number of which is the target dimensions int ambient_dim, int *max_degree, // a pointer to the value std::shared_ptr<SystemRandomizer> randomizer, const WitnessSet & W, SolverConfiguration & solve_options) { ns_config->set_side(nullspace_handedness::RIGHT); int toss; parse_input_file(W.input_filename(), &toss); // re-create the parsed files for the stuffs (namely the SLP). ns_config->set_randomizer(randomizer); // set the pointer. this randomizer is for the underlying system. *max_degree = randomizer->max_degree()-1; // minus one for differentiated degree ns_config->max_degree = *max_degree; // set some integers ns_config->num_projections = ambient_dim; ns_config->num_v_vars = W.num_natural_variables()-1; ns_config->num_synth_vars = W.num_synth_vars(); // this may get a little crazy if we chain into this more than once. this code is written to be called into only one time beyond the first. ns_config->num_natural_vars = W.num_natural_variables(); ns_config->ambient_dim = ambient_dim; ns_config->target_projection = (vec_mp *) br_malloc(ns_config->num_projections * sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_projections; ii++) { init_vec_mp2(ns_config->target_projection[ii], W.num_variables(),solve_options.T.AMP_max_prec); ns_config->target_projection[ii]->size = W.num_variables(); vec_cp_mp(ns_config->target_projection[ii], pi[ii]); } ns_config->num_jac_equations = (ns_config->num_natural_vars - 1);// N-1; the subtraction of 1 is for the 1 hom-var. // me must omit any previously added synthetic vars. ns_config->num_additional_linears = ambient_dim-1; ns_config->num_v_linears = ns_config->num_jac_equations; // this check is correct. int check_num_func = randomizer->num_rand_funcs() + ns_config->num_jac_equations + ns_config->num_additional_linears + W.num_patches() + 1; // +1 for v patch from this incoming computation int check_num_vars = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars; if (check_num_func != check_num_vars) { std::cout << color::red(); std::cout << "mismatch in number of equations...\n" << std::endl; std::cout << "left: " << check_num_func << " right " << check_num_vars << std::endl; std::cout << color::console_default(); throw std::logic_error("logic error in nullspace_left"); } // set up the linears in $v$ ( the M_i linears) ns_config->v_linears = (vec_mp *)br_malloc(ns_config->num_v_linears*sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_v_linears; ii++) { init_vec_mp2(ns_config->v_linears[ii],ns_config->num_v_vars,solve_options.T.AMP_max_prec); ns_config->v_linears[ii]->size = ns_config->num_v_vars; for (int jj=0; jj<ns_config->num_v_vars; jj++){ get_comp_rand_mp(&ns_config->v_linears[ii]->coord[jj]); // should this be real? no. } } // the last of the linears will be used for the slicing, and passed on to later routines int offset = 1; ns_config->additional_linears_terminal = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp)); ns_config->additional_linears_starting = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_additional_linears; ii++) { init_vec_mp2(ns_config->additional_linears_terminal[ii],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->additional_linears_terminal[ii]->size = W.num_variables(); for (int jj=0; jj<W.num_natural_variables(); jj++){ get_comp_rand_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); // should this be real? no. } for (int jj=W.num_natural_variables(); jj<W.num_variables(); jj++) { set_zero_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); } init_vec_mp2(ns_config->additional_linears_starting[ii],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->additional_linears_starting[ii]->size = W.num_variables(); vec_cp_mp(ns_config->additional_linears_starting[ii], W.linear(ii+offset)); } // set up the patch in $v$. we will include this in an inversion matrix to get the starting $v$ values. init_vec_mp2(ns_config->v_patch,ns_config->num_v_vars,solve_options.T.AMP_max_prec); ns_config->v_patch->size = ns_config->num_v_vars; for (int ii=0; ii<ns_config->num_v_vars; ii++) { get_comp_rand_mp(&ns_config->v_patch->coord[ii]); } mat_mp temp_getter; init_mat_mp2(temp_getter,0, 0,solve_options.T.AMP_max_prec); temp_getter->rows = 0; temp_getter->cols = 0; //the 'ns_config->starting_linears' will be used for the x variables. we will homotope to these 1 at a time ns_config->starting_linears = (vec_mp **)br_malloc( randomizer->num_rand_funcs()*sizeof(vec_mp *)); for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) { int curr_degree = std::max(0,randomizer->randomized_degree(ii)-1); ns_config->starting_linears[ii] = (vec_mp *) br_malloc(curr_degree*sizeof(vec_mp)); make_matrix_random_mp(temp_getter,curr_degree, W.num_natural_variables(), solve_options.T.AMP_max_prec); // this matrix is nearly orthogonal for (unsigned int jj=0; jj<curr_degree; jj++) { init_vec_mp2(ns_config->starting_linears[ii][jj],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->starting_linears[ii][jj]->size = W.num_variables(); for (int kk=0; kk<W.num_natural_variables(); kk++) { set_mp(&ns_config->starting_linears[ii][jj]->coord[kk], &temp_getter->entry[jj][kk]); } for (int kk=W.num_natural_variables(); kk<W.num_variables(); kk++) { set_zero_mp(&ns_config->starting_linears[ii][jj]->coord[kk]); } } } clear_mat_mp(temp_getter); return; }