void toggle_setting (void) { if (hilite_item == (NUM_SETTINGS - 1)) { write_config_file(); display_options(); return; } switch (hilite_item) { case 0: wireframe ^= 1; break; case 1: anti_alias_gfx ^= 1; break; case 2: planet_render_style = (planet_render_style + 1) % 4; break; case 3: hoopy_casinos ^= 1; break; case 4: instant_dock ^= 1; break; } highlight_setting (hilite_item); }
int main() { display_options(); calculate_price(); display_price(); return 0; }
int sensor_data_proc(int msg, DIALOG *d, int c) { int ret; int reset = FALSE; ret = nostretch_icon_proc(msg, d, c); // call the parent object if (msg == MSG_GOTMOUSE) // if we got mouse, display description sprintf(button_description, "Display current sensor data (RPM, Engine Load, Coolant Temperature, Speed, etc.)"); if (ret == D_CLOSE) // trap the close value { if (comport.status != READY) { reset = TRUE; if (open_comport() != 0) { comport.status = NOT_OPEN; // reset comport status while (comport.status == NOT_OPEN) { if (alert("COM Port could not be opened.", "Please check that port settings are correct", "and that no other application is using it", "&Configure Port", "&Ignore", 'c', 'i') == 1) display_options(); else comport.status = USER_IGNORED; } } else comport.status = READY; } display_sensor_dialog(reset); // display sensor data dialog strcpy(button_description, welcome_message); return D_REDRAW; } return ret; // return }
int options_proc(int msg, DIALOG *d, int c) { static int chip_was_reset = FALSE; int old_port; int ret; switch (msg) { case MSG_GOTMOUSE: // if we got mouse, display description sprintf(button_description, "Select system of measurements (US or Metric), and select serial port."); break; case MSG_IDLE: if (comport.number == -1 && comport.status != USER_IGNORED) display_options(); if (comport.status == NOT_OPEN) { if (alert("COM Port could not be opened.", "Please check that port settings are correct", "and that no other application is using it", "&Configure Port", "&Ignore", 'c', 'i') == 1) display_options(); else comport.status = USER_IGNORED; } else if ((comport.status == READY) && (chip_was_reset == FALSE)) // if the port is ready, { reset_chip(); chip_was_reset = TRUE; } break; } ret = nostretch_icon_proc(msg, d, c); // call the parent object if (ret == D_CLOSE) // trap the close value { old_port = comport.number; display_options(); // display options dialog if (comport.number != old_port) chip_was_reset = FALSE; return D_REDRAWME; } return ret; // return }
static int display_banner(void) { display_options(); printf("CPU: ADSP %s " "(Detected Rev: 0.%d) " "(%s boot)\n", gd->bd->bi_cpu, bfin_revid(), get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE)); return 0; }
int clear_codes_proc(int msg, DIALOG *d, int c) { int ret; switch (msg) { case MSG_READ_CODES: case MSG_CLEAR_CODES: // if we are currently reading or clearing codes, and the button is enabled, if (!(d->flags & D_DISABLED)) { d->flags |= D_DISABLED; // disable the button return D_REDRAWME; } break; case MSG_READY: // if we're not reading or clearing codes, and the button is disabled, if (d->flags & D_DISABLED) { d->flags &= ~D_DISABLED; // enable it return D_REDRAWME; } break; } ret = d_button_proc(msg, d, c); if (ret == D_CLOSE) { while (!simulate && comport.status != READY) { if (alert("Port is not ready.", "Please check that you specified the correct port", "and that no other application is using it", "Configure &Port", "&Cancel", 'p', 'c') == 1) display_options(); // let the user choose correct settings else return D_REDRAWME; } // if user confirmed that he wants to erase the codes, if(popup_dialog(confirm_clear_dialog, 6) == 5) { if (simulate) trouble_codes_simulator(FALSE); else broadcast_dialog_message(MSG_CLEAR_CODES, 0); //send everyone MSG_CLEAR_CODES } return D_REDRAWME; } return ret; }
void read_codes() { while (comport.status != READY) { if (alert("Port is not ready.", "Please check that you specified the correct port", "and that no other application is using it", "Configure &Port", "&Cancel", 'p', 'c') == 1) display_options(); // let the user choose correct settings else return; } clear_trouble_codes(); num_of_codes_reported = 0; mil_is_on = FALSE; broadcast_dialog_message(MSG_READY, 0); broadcast_dialog_message(MSG_READ_CODES, 0); }
/*----------------------------------------------------------------------------- * Parse command line, set options, including opts.files with list of * input files, including parsing of '@' lists *----------------------------------------------------------------------------*/ void parse_argv( int argc, char *argv[] ) { int arg; init_module(); if ( argc == 1 ) exit_copyright(); /* exit if no arguments */ process_options( &arg, argc, argv ); /* process all options, set arg to next */ if ( arg >= argc ) error_no_src_file(); /* no source file */ if ( opts.verbose ) display_options(); /* display status messages of select assembler options */ if ( ! get_num_errors() ) process_files( arg, argc, argv ); /* process each source file */ }
options() { /** change options... **/ /* return: * > 0 if restort was done - to indicate we might need to * change the page of our headers as a consequence * of the new sort order * < 0 if user entered 'x' to quit elm immediately * 0 otherwise */ int ch, resort = 0; char *strcpy(), temp[SLEN]; /* needed when an option is run through * expand_env(), because that function * is destructive of the original */ display_options(); clearerr(stdin); while(1) { ClearLine(LINES-4); Centerline(LINES-4, "Select first letter of option line, '>' to save, or 'i' to return to index."); PutLine0(LINES-2, 0, "Command: "); ch = ReadCh(); ch = tolower(ch); clear_error(); /* remove possible "sorting" message etc... */ one_liner(one_liner_for(ch)); switch (ch) { case 'c' : optionally_enter(raw_calendar_file, 2, 23, FALSE, FALSE); strcpy(temp, raw_calendar_file); expand_env(calendar_file, temp); break; case 'd' : optionally_enter(raw_pager, 3, 23, FALSE, FALSE); strcpy(temp, raw_pager); expand_env(pager, temp); clear_pages = (equal(pager, "builtin+") || equal(pager, "internal+")); break; case 'e' : optionally_enter(raw_editor, 4, 23, FALSE, FALSE); strcpy(temp, raw_editor); expand_env(editor, temp); break; case 'f' : optionally_enter(raw_folders, 5, 23, FALSE, FALSE); strcpy(temp, raw_folders); expand_env(folders, temp); break; case 's' : if(change_sort(6,23)) resort++; break; case 'o' : optionally_enter(raw_sentmail, 7, 23, FALSE, FALSE); strcpy(temp, raw_sentmail); expand_env(sent_mail, temp); break; case 'p' : optionally_enter(raw_printout, 8, 23, FALSE, FALSE); strcpy(temp, raw_printout); expand_env(printout, temp); break; case 'y' : optionally_enter(full_username, 9, 23, FALSE, FALSE); break; case 'a' : on_or_off(&arrow_cursor, 12, 23); break; case 'm' : on_or_off(&mini_menu, 13, 23); headers_per_page = LINES - (mini_menu ? 13 : 8); break; case 'u' : switch_user_level(&user_level,15, 23); break; case 'n' : on_or_off(&names_only, 16, 23); break; case '?' : options_help(); PutLine0(LINES-2,0,"Command: "); break; case '>' : printf("Save options in .elm/elmrc..."); fflush(stdout); save_options(); break; case 'x' : return(-1); /* exit elm */ case 'q' : /* pop back up to previous level, in this case == 'i' */ case 'i' : /* return to index screen */ return(resort ? 1 : 0); case ctrl('L'): display_options(); break; default: error("Command unknown!"); } } }
/** * @function main */ int main( int argc, char *argv[] ) { bool quit = false; countPath = 0; //-- Initialize if( init() == false ) { return 1; } //-- Load the files if( load_files() == false ) { return 1; } //-- Clip tiles clip_tiles(); //-- Create grid Grid2D g( SIZE_X, SIZE_Y ); //-- Create HomoPath object HP2D h( &g ); //-- Put the obstacles in the borders createBorderingObstacles( &g ); //-- Display options display_options(); //-- Start SDL while( quit == false ) { while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } else if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case 's': { printf("-- Starting planner \n"); MOUSE_MODE = -1; CallPlanner( &g, &h ); printf("--* To see options again press [q] \n"); break; } case 'v': { printf("-- Click one location to be the initial vertex \n"); MOUSE_MODE = 0; break; } case 'o': { printf("-- Click one location to be obstacle \n"); MOUSE_MODE = 1; break; } case 'x': { printf("-- Pick a grid to check the possible paths \n"); MOUSE_MODE = 2; countPath = 0; // Start seeing the first path break; } case 'p': { printf("-- Check available paths for designated grid \n"); countPath++; countPath = ( countPath % numPaths ); } case 'q': { display_options(); } } } else if( event.type == SDL_MOUSEBUTTONDOWN ) { if( event.button.button == SDL_BUTTON_LEFT ) { int x = event.button.x; int y = event.button.y; Pos p = GetMousePos( x, y ); switch( MOUSE_MODE ) { case 0: { printf("--> V0 located at (%d, %d) \n", p.x, p.y ); p0.x = p.x; p0.y = p.y; printf("--* To see options again press [q] \n"); break; } case 1: { printf("--> Obstacle located at (%d, %d) \n", p.x, p.y ); if( g.GetState(p) == false ) { g.SetState( p, true ); } else { g.SetState( p, false ); } printf("--* To see options again press [q] \n"); break; } case 2: { printf( "--> Locating paths for (%d %d) \n", p.x, p.y ); gPaths = h.PrintPath(p); numPaths = gPaths.size(); printf("--* To see options again press [q] \n"); break; } } } } //-- Draw DrawScene( &g ); } // end while SDL_PollEvent } // end while quit clean_up(); return 0; }
int main(void) { unsigned process_id=0; unsigned scheduler=0; unsigned total_time=0; unsigned time_quantum=0; unsigned fixed_response_time=0; char option; char *str=NULL; struct process_node *p=NULL,*q=NULL,*r=NULL,*start=NULL; system("clear"); printf("STARTING SIMULATION: "); do { q=create_process(process_id++); if(p!=NULL) add_process(p,q); else p=q; printf("\nOne more process: (y/n) "); fflush(stdin); scanf("%s",&option); }while(option!='n'); display_process(p); printf("\nPress y to continue\n"); fflush(stdin); scanf("%s",&option); do { scheduler=0; scheduler=display_options(); str=NULL; switch(scheduler) { case 1:/* if(total_time=fcfs_process_arrives_in_system(p)) { str="FCFS (Process Creation)"; }*/ break; case 2:/* if(total_time=fcfs_process_arrives_in_ready_queue(p)) { str="FCFS (Arrival in Ready Queue)"; }*/ break; case 3: if(total_time=priority_scheduler(p)) { str="Priority Scheduler"; } break; case 4:/* if(total_time=sjf_scheduler(p)) { str="Shortest Job First Scheduler"; }*/ break; case 5:/* if(total_time=srtf_scheduler(p)) { str="Shortest Remaining Time First Scheduler"; }*/ break; case 6:/* printf("\nEnter time quantum: "); fflush(stdin); scanf("%u",&time_quantum); if(total_time=round_robin_scheduler(p,time_quantum)) { str="Round Robin Scheduler"; }*/ break; case 7:/* printf("\nEnter fixed response duration: "); fflush(stdin); scanf("%u",&fixed_response_time); if(total_time=round_robin_scheduler_2(p,fixed_response_time)) { str="Round Robin Scheduler 2"; }*/ break; case 8://display process details display_process(p); break; case 9://add another process q=create_process(process_id++); if(!isEmpty(p)) add_process(p,q); else p=q; break; case 10: for(start=p;start!=NULL;) { r=start; start=start->next; free(r); r=NULL; } exit(0); break; default: printf("\nError: Pls try again\n"); } if(scheduler>=1 && scheduler<=7)//!=8 && scheduler!=0) { if(total_time) { display_statistics(p,str,total_time); clear_statistics(p); } else { printf("\nScheduler failed\n"); } } }while(1); return 0; }
static int display_banner(void) { display_options(); return 0; }
void get_options(int argc, char **argv, OPTION *options, char *help) { int i, j, found; /* For each argument in the command line. */ i = 1; while(i < argc) { found = 0, j = 0; /* * Search for the current word in the option list. */ while(!found) { /* * If the option was not found. */ if(strcmp(argv[i], "-help") == 0) { display_options(argv, options, help); } else if(options[j].name == NULL) { bad_option(argv, i); display_options(argv, options, help); } /* * If the word is found in the option list. */ else if(strcmp(argv[i], options[j].name) == 0) { /* * Check the type, make sure we have another arg * coming if needed, eat up the next arg, set * the value of the parameter, and display help * if needed. */ found = 1; switch(options[j].type) { case OPT_INT: if(i + 1 >= argc) { bad_option(argv, i); display_options(argv, options, help); } *(int *)options[j].ptr = atoi(argv[i + 1]); i += 2; break; case OPT_DOUBLE: if(i + 1 >= argc) { bad_option(argv, i); display_options(argv, options, help); } *(double *)options[j].ptr = atof(argv[i + 1]); i += 2; break; case OPT_STRING: if(i + 1 >= argc) { bad_option(argv, i); display_options(argv, options, help); } *(char **)options[j].ptr = argv[i + 1]; i += 2; break; case OPT_SWITCH: *(int *)options[j].ptr = !*(int *)options[j].ptr; i += 1; break; case OPT_OTHER: if(((int (*)())options[j].ptr)(argv, argc, options, &i, j)) { bad_option(argv, i); display_options(argv, options, help); } break; default: break; } } j++; } } }
static void mainmenu(void) { int menuresult[1]; int n = 1, logoheight, i; const char *const *copybanner = nh_get_copyright_banner(); const char **nhlogo; char verstr[32]; nh_bool first = TRUE; snprintf(verstr, ARRAY_SIZE(verstr), "Version %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); #if defined(NETCLIENT) if (ui_flags.connection_only) { netgame(); return; } #endif load_keymap(); /* netgame() assumes the keymap isn't loaded */ while (n >= 0) { if (COLS >= 100) { nhlogo = nhlogo_large; logoheight = sizeof (nhlogo_large) / sizeof (nhlogo_large[0]); } else { nhlogo = nhlogo_small; logoheight = sizeof (nhlogo_small) / sizeof (nhlogo_small[0]); } wclear(basewin); wattron(basewin, A_BOLD | COLOR_PAIR(4)); for (i = 0; i < logoheight; i++) { wmove(basewin, i, (COLS - strlen(nhlogo[0])) / 2); if (nhlogo[i]) waddstr(basewin, nhlogo[i]); } wattroff(basewin, A_BOLD | COLOR_PAIR(4)); mvwaddstr(basewin, LINES - 3, 0, copybanner[0]); mvwaddstr(basewin, LINES - 2, 0, copybanner[1]); mvwaddstr(basewin, LINES - 1, 0, copybanner[2]); mvwaddstr(basewin, LINES - 4, COLS - strlen(verstr), verstr); wnoutrefresh(basewin); if (first) { network_motd(); first = FALSE; } menuresult[0] = EXITGAME; /* default action */ if (!override_hackdir) curses_display_menu_core( STATIC_MENULIST(mainmenu_items), NULL, PICK_ONE, menuresult, curses_menu_callback, 0, logoheight - 1, COLS, LINES - 3, FALSE, NULL, FALSE); else curses_display_menu_core( STATIC_MENULIST(mainmenu_items_noclient), NULL, PICK_ONE, menuresult, curses_menu_callback, 0, logoheight - 1, COLS, LINES - 3, FALSE, NULL, FALSE); if (*menuresult == CURSES_MENU_CANCELLED && !ui_flags.done_hup) continue; switch (menuresult[0]) { case NEWGAME: rungame(FALSE); break; case LOAD: loadgame(); break; case REPLAY: replay(); break; case OPTIONS: display_options(TRUE); break; #if defined(NETCLIENT) case NETWORK: free_keymap(); /* don't use the local keymap for server play */ netgame(); load_keymap(); break; #endif case TOPTEN: show_topten(NULL, -1, FALSE, FALSE); break; case EXITGAME: case CURSES_MENU_CANCELLED: /* in case of hangup */ n = -1; /* simulate menu cancel */ break; } } free_keymap(); }
// heart of the trouble_code_reader module: int tr_code_proc(int msg, DIALOG *d, int c) { static char vehicle_response[1024]; // character buffer for car response static int first_read_occured = FALSE; static int receiving_response = FALSE; // flag, "are we receiving response?" static int verifying_connection = FALSE; // flag, "are we verifying connection?" static int current_request = CRQ_NONE; // NUM_OF_CODES, READ_CODES, CLEAR_CODES int response_status = EMPTY; // EMPTY, DATA, PROMPT int response_type; // BUS_BUSY, BUS_ERROR, DATA_ERROR, etc. int pending_codes_cnt = 0; char comport_buffer[256]; // temporary storage for comport data char buf1[64]; char buf2[64]; switch (msg) { case MSG_IDLE: if (!first_read_occured) { if (!simulate) read_codes(); first_read_occured = TRUE; return D_O_K; } if (simulate) break; if (comport.status == READY) { if (!receiving_response) { if (verifying_connection) { send_command("0100"); // send request that requires a response receiving_response = TRUE; // now we're waiting for response vehicle_response[0] = 0; //get buffer ready for the response start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer } else if (current_request == READ_PENDING) { send_command("07"); // request "pending" codes receiving_response = TRUE; // and receiving response vehicle_response[0] = '\0'; // clear the buffer start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer... } } else { response_status = read_comport(comport_buffer); if (response_status == DATA) // if data detected in com port buffer { // append contents of comport_buffer to vehicle_response: strcat(vehicle_response, comport_buffer); start_serial_timer(OBD_REQUEST_TIMEOUT); // we got data, reset the timer } else if (response_status == PROMPT) // if ">" is detected { receiving_response = FALSE; // we're not waiting for response any more stop_serial_timer(); // stop the timer // append contents of comport_buffer to vehicle_response: strcat(vehicle_response, comport_buffer); if (verifying_connection) // *** if we are verifying connection *** { // NOTE: we only get here if we got "NO DATA" somewhere else response_type = process_response("0100", vehicle_response); verifying_connection = FALSE; // we're not verifying connection anymore if (response_type == HEX_DATA) // if everything seems to be fine now, { if (current_request == CLEAR_CODES) alert("There may have been a temporary loss of connection.", "Please try clearing codes again.", NULL, "OK", NULL, 0, 0); else if (current_request == NUM_OF_CODES) alert("There may have been a temporary loss of connection.", "Please try reading codes again.", NULL, "OK", NULL, 0, 0); else if (current_request == READ_CODES) { current_request = READ_PENDING; break; } } else if (response_type == ERR_NO_DATA) { if (current_request == CLEAR_CODES) // if we were clearing codes, alert("Communication problem: vehicle did not confirm successful", "deletion of trouble codes. Please check connection to the vehicle,", "make sure the ignition is ON, and try clearing the codes again.", "OK", NULL, 0, 0); else // if we were reading codes or requesting number or DTCs alert("There may have been a loss of connection.", "Please check connection to the vehicle,", "and make sure the ignition is ON", "OK", NULL, 0, 0); } else display_error_message(response_type, FALSE); broadcast_dialog_message(MSG_READY, 0); // tell everyone we're done } else if (current_request == NUM_OF_CODES) // *** if we are getting number of codes *** { response_type = process_response("0101", vehicle_response); if (response_type == ERR_NO_DATA) // if we received "NO DATA" verifying_connection = TRUE; // verify connection else if (response_type != HEX_DATA) // if we got an error, handle_errors(response_type, NUM_OF_CODES); // handle it else // if process response returned HEX_DATA (i.e. there are no errors) { // extract # of codes from vehicle_response num_of_codes_reported = handle_num_of_codes(vehicle_response); send_command("03"); // request "stored" codes current_request = READ_CODES; // we're reading stored codes now receiving_response = TRUE; // and receiving response vehicle_response[0] = '\0'; // clear the buffer start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer... } } else if (current_request == READ_CODES) // if we are reading codes, { response_type = process_response("03", vehicle_response); if (response_type == ERR_NO_DATA) // vehicle didn't respond, check connection { if (num_of_codes_reported > 0) verifying_connection = TRUE; else current_request = READ_PENDING; } else if (response_type == HEX_DATA) { handle_read_codes(vehicle_response, FALSE); current_request = READ_PENDING; } else // if we got an error handle_errors(response_type, READ_CODES); } else if(current_request == READ_PENDING) // if we are reading pending codes, { response_type = process_response("07", vehicle_response); if (response_type == ERR_NO_DATA) { if (get_number_of_codes() == 0 && num_of_codes_reported == 0) alert("No Diagnostic Trouble Codes (DTCs) detected", NULL, NULL, "OK", NULL, 0, 0); } else if(response_type != HEX_DATA) // if we got an error, { handle_errors(response_type, READ_PENDING); break; } else // if there were *no* errors, pending_codes_cnt = handle_read_codes(vehicle_response, TRUE); // if number of DTCs reported by 0101 request does not equal either number or total DTCs or just stored DTCs if ((get_number_of_codes() != num_of_codes_reported) && (get_number_of_codes() - pending_codes_cnt != num_of_codes_reported)) { sprintf(buf1, "Vehicle reported %i Diagnostic Trouble Codes (DTCs).", num_of_codes_reported); sprintf(buf2, "However, %i non-pending DTC(s) have been successfully read.", get_number_of_codes() - pending_codes_cnt); alert(buf1, buf2, "Try reading codes again.", "OK", NULL, 0, 0); } populate_trouble_codes_list(); broadcast_dialog_message(MSG_READY, 0); // tell everyone we're done } else if(current_request == CLEAR_CODES) { response_type = process_response("04", vehicle_response); if (response_type == ERR_NO_DATA)// vehicle didn't respond, check connection verifying_connection = TRUE; else if(response_type != HEX_DATA) // if we got an error, handle_errors(response_type, CLEAR_CODES); else // if everything's fine (received confirmation) { clear_trouble_codes(); num_of_codes_reported = 0; mil_is_on = FALSE; broadcast_dialog_message(MSG_READY, 0); } } } else if (serial_time_out) // if request timed out, { stop_serial_timer(); receiving_response = FALSE; num_of_codes_reported = 0; mil_is_on = FALSE; clear_trouble_codes(); broadcast_dialog_message(MSG_READY, 0); if(alert("Device is not responding.", "Please check that it is connected", "and the port settings are correct", "OK", "&Configure Port", 27, 'c') == 2) display_options(); // let the user choose correct settings while (comport.status == NOT_OPEN) { if (alert("Port is not ready.", "Please check that you specified the correct port", "and that no other application is using it", "&Configure Port", "&Ignore", 'c', 'i') == 1) display_options(); // let the user choose correct settings else comport.status = USER_IGNORED; } } } } break; // end case MSG_IDLE case MSG_START: first_read_occured = FALSE; num_of_codes_reported = 0; mil_is_on = FALSE; // fall through case MSG_READY: receiving_response = FALSE; verifying_connection = FALSE; current_request = CRQ_NONE; break; case MSG_READ_CODES: if (comport.status == READY) { send_command("0101"); // request number of trouble codes start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer current_request = NUM_OF_CODES; receiving_response = TRUE; // now we're waiting for response vehicle_response[0] = 0; clear_trouble_codes(); num_of_codes_reported = 0; mil_is_on = FALSE; } else serial_time_out = TRUE; break; case MSG_CLEAR_CODES: if (comport.status == READY) { send_command("04"); // "clear codes" request current_request = CLEAR_CODES; receiving_response = TRUE; // now we're waiting for response vehicle_response[0] = 0; start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer } else serial_time_out = TRUE; break; case MSG_END: stop_serial_timer(); break; } return D_O_K; } // end of tr_codes_proc()
int main(int argc, char **argv) { int seed = 1, xdim = 0, ydim = 1, csz = 0, yindex = 0, ssz = 0; int clever = 0, regress = 0, dump = 0, best = 0, wfirst = 0, lazy = 0; int offset = 0, xdelta = 0, tube = 0; double trate = 2.0, tfinal = 10.0; double C = 100, aux = 0.5, tol = 1e-3, eps = 1e-12, regeps = 0.1; char *fname = NULL, *kname = "gauss", *dtype = "ascii"; OPTION opts[] = { { "-dtype", OPT_STRING, &dtype, "data type. Value should be one of: " "ascii, double, short (short_val / 1000.0 = dbl_val), or map " "(memory-mapped file of doubles)" }, { "-kernel", OPT_STRING, &kname, "SVM kernel. Value should be one of: " "gauss, poly, tanh, or linear" }, { "-xdim", OPT_INT, &xdim, "dimensionality of input points" }, { "-ydim", OPT_INT, &ydim, "dimensionality of target points" }, { "-ssz", OPT_INT, &ssz, "subset size" }, { "-fname", OPT_STRING, &fname, "data file name" }, { "-seed", OPT_INT, &seed, "random number seed for shuffled indices" }, { "-C", OPT_DOUBLE, &C, "maximum size for Lagrange multipliers" }, { "-aux", OPT_DOUBLE, &aux, "auxiliary parameter: variance for Gaussian kernels, " "power for polynomials, and threshold for sigmoids" }, { "-tol", OPT_DOUBLE, &tol, "tolerance for classification errors" }, { "-eps", OPT_DOUBLE, &eps, "floating point epsilon" }, { "-csz", OPT_INT, &csz, "kernel output cache size" }, { "-yindex", OPT_INT, &yindex, "which y[] to classify" }, { "-clever", OPT_SWITCH, &clever, "use 'ultra clever' incremental outputs" }, { "-best", OPT_SWITCH, &best, "use best step if relatively easy to compute" }, { "-wfirst", OPT_SWITCH, &wfirst, "Always attempt to optimize worst KKT exemplar first" }, { "-lazy", OPT_SWITCH, &lazy, "only do a hard search over all multipliers when necessary" }, { "-tube", OPT_SWITCH, &tube, "use tube shrinking heuristic?" }, { "-trate", OPT_DOUBLE, &trate, "tube shrinking factor" }, { "-tfinal", OPT_DOUBLE, &tfinal, "final tube shrinkage" }, { "-regress",OPT_SWITCH, ®ress, "assume this is a regression problem (not classification)" }, { "-regeps", OPT_DOUBLE, ®eps, "epsilon for regression problems" }, { "-xdelta", OPT_INT, &xdelta, "space between x's (only for time delayed time series)" }, { "-offset", OPT_INT, &offset, "space between x's and y's (only for time delayed time series)" }, { "-dump", OPT_SWITCH, &dump, "dump SVM output to file?" }, { NULL, OPT_NULL, NULL, NULL } }; SERIES *ser; DSM_FILE *dsmfile; DATASET *data; SVM *svm; SMORCH smorch = SMORCH_DEFAULT; FILE *fp; unsigned i, sz, j; double *x, *y; get_options(argc, argv, opts, NULL, NULL, 0); if(fname == NULL || xdim <= 0) { display_options(argv[0], opts, NULL); exit(1); } srandom(seed); if (!strcmp(dtype, "ascii")) { ser = series_read_ascii(fname); ser->x_width = xdim; ser->y_width = ydim; if (xdelta > 0 && offset > 0) { ser->x_delta = xdelta; ser->offset = offset; ser->step = 1; } else { ser->x_delta = ser->y_delta = ser->offset = 1; ser->step = ser->x_width + ser->y_width; } data = dataset_create(&dsm_series_method, ser); } else if (!strcmp(dtype, "map")) { dsmfile = dsm_file(fname); dsmfile->x_width = xdim; dsmfile->y_width = ydim; dsmfile->x_read_width = xdim * sizeof(double); dsmfile->y_read_width = ydim * sizeof(double); dsmfile->offset = dsmfile->skip = 0; dsmfile->step = dsmfile->x_read_width + dsmfile->y_read_width; dsmfile->type = SL_DOUBLE; dsm_file_initiate(dsmfile); data = dataset_create(&dsm_file_method, dsmfile); } else if (!strcmp(dtype, "double")) { data = create_double_dataset(fname, xdim, ydim); } else if (!strcmp(dtype, "short")) { data = create_short_dataset(fname, xdim, ydim); } else { display_options(argv[0], opts, NULL); exit(1); } smorch.data = data; /* Set up the proper kernel to use. */ if(!strcmp(kname, "gauss")) smorch.kernel = svm_kernel_gauss; else if(!strcmp(kname, "poly")) smorch.kernel = svm_kernel_poly; else if(!strcmp(kname, "tanh")) smorch.kernel = svm_kernel_tanh; else if(!strcmp(kname, "linear")) smorch.kernel = svm_kernel_linear; else { display_options(argv[0], opts, NULL); exit(1); } smorch.cache_size = csz; smorch.yindex = yindex; smorch.aux = aux; smorch.C = C; smorch.tol = tol; smorch.eps = eps; smorch.hook = myhook; smorch.finalhook = myfinalhook; smorch.subset_size = ssz; smorch.ultra_clever = clever; smorch.best_step = best; smorch.worst_first = wfirst; smorch.lazy_loop = lazy; smorch.regression = regress; smorch.regeps = regeps; smorch.tube = tube; smorch.tube_rate = trate; smorch.tube_final = tfinal; svm = smorch_train(&smorch); svm_write(svm, "tsvm.svm"); if (dump) { fp = fopen("tsvm.tst", "w"); sz = dataset_size(data); for (i = 0; i < sz; i++) { x = dataset_x(data, i); y = dataset_y(data, i); for (j = 0; j < xdim; j++) fprintf(fp, "% .4f ", x[j]); fprintf(fp, "% .4f ", y[yindex]); fprintf(fp, "% .4f\n", svm_output(svm, x)); } fclose(fp); } svm_destroy(svm); exit(0); }