int main(int argc, char* argv[]) { uint8_t opmode = OP_HIDE; if(argc < 2) usage_and_exit(argv); if(!strcmp(argv[1], "-h")) opmode = OP_HIDE; else if(!strcmp(argv[1], "-u")) opmode = OP_UNHIDE; else if(!strcmp(argv[1], "-f")) opmode = OP_ADDFRAME; else usage_and_exit(argv); if( (opmode == OP_UNHIDE && (argc != 4 && argc != 3)) || (opmode == OP_HIDE && argc != 5) || (opmode == OP_ADDFRAME && argc != 4) ) { usage_and_exit(argv); } char* in_file = argv[2]; char* out_file = 0; char* data_file = 0; if(opmode == OP_HIDE) { out_file = argv[3]; data_file = argv[4]; } else if(argc > 3) { out_file = argv[3]; } //printf("opmode=%d, in_file=%s, out_file=%s, data_file=%s\n", // opmode, in_file, out_file, data_file ); uint8_t tiff_mode=0; if(strstr(in_file, ".tif")) tiff_mode = 1; else if(!strstr(in_file, ".bmp")) { fprintf(stderr, "input file must have .tif or .bmp suffix\n"); exit(2); } if(tiff_mode) { handle_tiff(opmode, in_file, out_file, data_file); } else { handle_bmp(opmode, in_file, out_file, data_file); } return 0; }
static void parse_args(int ac, char **av) { int c; gl_env.history_size = 0; gl_env.quiet = 0; gl_env.last_update_time = 0; gl_env.line_by_line = 0; gl_env.interval = 1; while (1) { int option_index = 0; static struct option long_options[] = { {"size", 1, 0, 's'}, {"quiet", 0, 0, 'q'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {"line-by-line", 1, 0, 'l'}, {"interval", 1, 0, 'i'}, {0, 0, 0, 0} }; c = getopt_long(ac, av, "qhvl:s:i:", long_options, &option_index); if (c == -1) break; switch (c) { case 'l': gl_env.line_by_line = atoi(optarg); break; case 'q': gl_env.quiet = 1; break; case 's': gl_env.history_size = atoi(optarg); break; case 'i': gl_env.interval = atoi(optarg); break; case 'v': version_and_exit(); case 'h': usage_and_exit(EXIT_SUCCESS); default: usage_and_exit(EXIT_FAILURE); } } if (isatty(fileno(stdin))) usage_and_exit(EXIT_FAILURE); if (gl_env.history_size == 0) gl_env.history_size = DEFAULT_HISTORY_SIZE; }
// Opens a FILE pointer for input and an ALFileStore for output. Also returns the length of the input file int encodeCommandOpenFiles(int argc, char **argv, FILE **infile, uint64_t *infile_len, ALStore *outfile) { if (argc != 2) usage_and_exit(); const char *infilename = argv[0]; const char *outbasename = argv[1]; struct stat st; _Bool infile_exists = (stat(infilename, &st) == 0); if (!infile_exists) { fprintf(stderr, "Error: encoder cannot find input file %s\n", infilename); return 1; } *infile_len = st.st_size; *infile = fopen(infilename, "r"); if (*infile == NULL) { fprintf(stderr, "Error: encoder cannot open input file %s\n", infilename); return 1; } // printf(" Using legacy format %s \n", OPTIONS.legacy_format?"y":"n"); ALStoreOpenPOSIX(outfile, outbasename, "w", OPTIONS.legacy_format); return 0; }
int main( int argc, char *argv[] ) { MODEL_PARAMS model_params; MODEL_INFO model_info; fprintf(stderr,"\n This is svdinterface.\n\n"); if (argc != 5) usage_and_exit( argv[0], 2 ); if ( strcmp( argv[1], "-singvals" ) != 0 ) usage_and_exit( argv[0], 2 ); hashsing = atoi( argv[2] ); if ( strcmp( argv[3], "-iter" ) != 0 ) usage_and_exit( argv[0], 2 ); hashstep = atoi( argv[4] ); if ( !read_model_params( MODEL_PARAMS_BIN_FILE, &model_params )) { fprintf( stderr, "svdinterface.c: can't read model params file.\n" ); exit(3); } if ( !read_model_info( MODEL_INFO_BIN_FILE, &model_info )) { fprintf( stderr, "svdinterface.c: can't read model info file.\n" ); exit(3); } model_params.singvals = hashsing; model_info.svd_iter = hashstep; hashrow = model_params.rows; hashcol = model_info.columns; sing = (float *) mymalloc(sizeof(float)*hashsing); left = Allocate_Float_Matrix(hashrow,hashsing); right = Allocate_Float_Matrix(hashcol,hashsing); doit( ); if ( !write_model_params( MODEL_PARAMS_BIN_FILE, &model_params )) { fprintf( stderr, "svdinterface.c: can't write model params file.\n" ); exit(3); } if ( !write_model_info( MODEL_INFO_BIN_FILE, &model_info )) { fprintf( stderr, "svdinterface.c: can't write model info file.\n" ); exit(3); } return(0); }
// Opens an ALFileStore for input int commandOpenFiles(int argc, char **argv, ALStore *infile) { if (argc != 1) usage_and_exit(); const char *inbasename = argv[0]; ALError err = ALStoreOpenPOSIX(infile, inbasename, "r", OPTIONS.legacy_format); if (err != ALErrorNone) { fprintf(stderr, "Error: decoder cannot open input files with basename %s\n", inbasename); return 1; } return 0; }
void verify_args(gint argc, gchar **argv) { /* Invalid arg count, abort */ if (argc != 4) usage_and_exit(g_strdup("Invalid number of arguments!")); if (g_strcasecmp(argv[1],"MS1") == 0) type = MS1; else if (g_strcasecmp(argv[1],"MS2") == 0) type = MS2; else if (g_strcasecmp(argv[1],"FREEEMS") == 0) type = FREEEMS; else usage_and_exit(g_strdup_printf("Device type \"%s\" not recognized",argv[1])); if (!g_file_test(argv[2], G_FILE_TEST_EXISTS)) usage_and_exit(g_strdup_printf("Port \"%s\" does NOT exist...",argv[2])); if (!g_file_test(argv[3], G_FILE_TEST_IS_REGULAR)) usage_and_exit(g_strdup_printf("Filename \"%s\" does NOT exist...",argv[3])); }
int main(int argc, char** argv) { if (argc != 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) usage_and_exit(); char newrelic_license_key[256]; strncpy(newrelic_license_key, argv[1], sizeof newrelic_license_key); newrelic_register_message_handler(newrelic_message_handler); newrelic_init(newrelic_license_key, "My Application", "C", "4.8"); // newrelic_enable_instrumentation(1); /* 1 is enable */ /* create the app worker thread to execute "main_worker_function()" */ /* * Our pthread_create() -commented, below- doesn't seem to be strictly * necessary: it is the embedded mode of the NewRelic SDK the one * which starts the SDK engine in a separate pthread (at least in the * NewRelic Agent SDK version 0.16.1), and tracing reveals that this * NewRelic thread is the one which connects to the NewRelic * collector site ("collector*.newrelic.com") and sends the stats * to it. * pthread_t worker_thread; int err = pthread_create(&worker_thread, NULL, main_worker_function, NULL); if (err != 0)) { fprintf(stderr, "ERROR: couldn't create our worker thread:" " error code %d\n", err); return 1; } */ main_worker_function(); /* wait for the application worker thread to finish */ /* if(pthread_join(worker_thread, NULL)) { fprintf(stderr, "Error joining thread\n"); return 2; } */ return 0; }
FILE *open_next_file_from_argv (char ** argv) { FILE *f; if (!argv[optind]) { usage_and_exit (argv[0]); } f = fopen (argv[optind], "r"); if (!f) { fprintf (stderr, "Error, could not open %s\n", argv[optind]); exit (-1); } optind++; return f; }
int main(int argc, char *argv[]) { int byte_count = 0; char tmpstr[512]; uint8_t *buffer; /* Memory buffer */ FILE *input_file; /* Input file */ uint16_t pc; /* Program counter */ options_t options; /* Command-line options parsing results */ parse_args(argc, argv, &options); buffer = calloc(1, 65536); if (NULL == buffer) { usage_and_exit(3, "Could not allocate disassembly memory buffer."); } /* Read file into memory buffer */ input_file = fopen(options.filename, "rb"); if (NULL == input_file) { version(); fprintf(stderr, "File not found or invalid filename : %s\n", options.filename); exit(2); } byte_count = 0; while(!feof(input_file) && ((options.org + byte_count) <= 0xFFFFu) && (byte_count < options.max_num_bytes)) { fread(&buffer[options.org + byte_count], 1, 1, input_file); byte_count++; } fclose(input_file); /* Disassemble contents of buffer */ emit_header(&options, byte_count); pc = options.org; while((pc <= 0xFFFFu) && ((pc - options.org) < byte_count)) { disassemble(tmpstr, buffer, &options, &pc); fprintf(stdout, "%s\n", tmpstr); pc++; } free(buffer); return 0; }
// Opens a FILE pointer for output and an ALFileStore for input int decodeCommandOpenFiles(int argc, char **argv, ALStore *infile, FILE **outfile) { if (argc != 2) usage_and_exit(); const char *inbasename = argv[0]; const char *outfilename = argv[1]; // printf("Using legacy format? %s \n", OPTIONS.legacy_format?"y":"n"); ALError err = ALStoreOpenPOSIX(infile, inbasename, "r", OPTIONS.legacy_format); if (err != ALErrorNone) { fprintf(stderr, "Error: decoder cannot open input files with basename %s\n", inbasename); return 1; } *outfile = fopen(outfilename, "w"); if (*outfile == NULL) { fprintf(stderr, "Error: decoder cannot open output file %s\n", outfilename); return 1; } return 0; }
/** * A polish calculator. * * This could have been solved easier with a stack. */ int main(int argc, const char *argv[]) { const char **op = NULL; const char **p; const char *progname = argv[0]; const char **end = argv + argc - 1; int operand; int res = 0; /* Find the first operator. */ for (; argc > 0; argc--, argv++) { if (is_operator(**argv)) { op = argv; break; } } if (! op) usage_and_exit(progname); res = atoi(*(op -1)); p = op - 2; operand = atoi(*p); while (*p > progname && op <= end) { res = calculate(res, operand, **op); p--; operand = atoi(*p); op++; } printf("%d\n", res); return 0; }
int main(int argc, char **argv) { cmdstr = argv[0]; init_options(); _Bool is_part_size_in_elem = false; int c; while ((c = getopt(argc, argv, ":p:icle:s:xhkmr")) != -1) { switch (c) { case 'p': { uint64_t multi = 1; int arglen = strlen(optarg); _Bool part_size_suffix_power_2 = false; while (arglen > 0) { switch (optarg[arglen - 1]) { case 'e': case 'E': // We must wait until we know the element size before we can scale is_part_size_in_elem = true; break; case 'i': case 'I': part_size_suffix_power_2 = true; break; // NOTE: intentional fall-throughs case 't': case 'T': multi *= part_size_suffix_power_2 ? 1024 : 1000; case 'g': case 'G': multi *= part_size_suffix_power_2 ? 1024 : 1000; case 'm': case 'M': multi *= part_size_suffix_power_2 ? 1024 : 1000; case 'k': case 'K': multi *= part_size_suffix_power_2 ? 1024 : 1000; break; default: arglen = 0; continue; } optarg[arglen-1] = 0; arglen--; } OPTIONS.part_size_in_elem = (uint64_t)atoll(optarg) * multi; if (OPTIONS.part_size_in_elem < MIN_PART_SIZE) { fprintf(stderr, "Error: partition size of %llu specified, but must be at least %llu\n", OPTIONS.part_size_in_elem, MIN_PART_SIZE); exit(1); } // printf("Using partition size of %llu(not accounting for element size, but %s later)\n", OPTIONS.part_size_in_elem, is_part_size_in_elem ? "WILL" : "WON'T"); break; } case 'i': case 'c': case 'x': case 'h': //hybrid index = p4d + rle case 'k': //skipping index = p4d + skipping case 'm': //skipping hybrid index = p4d + rle + skipping case 'r': // expansion/relaxing method if (OPTIONS.index_form_set) { fprintf(stderr, "Error: options -i, -c and -x are mutually exclusive\n"); usage_and_exit(); } OPTIONS.index_form_set = true; if (c == 'i') OPTIONS.index_form = ALInvertedIndex; else if (c == 'c') OPTIONS.index_form = ALCompressionIndex; else if (c == 'h') OPTIONS.index_form = ALCompressedHybridInvertedIndex; //rpfd else if (c == 'k') OPTIONS.index_form = ALCompressedSkipInvertedIndex; else if (c == 'm') OPTIONS.index_form = ALCompressedMixInvertedIndex; else if (c == 'r') OPTIONS.index_form = ALCompressedExpansionII; // epfd else OPTIONS.index_form = ALCompressedInvertedIndex; //x pfd break; case 'l': OPTIONS.legacy_format = true; break; case 'e': if (strcasecmp(optarg, "float") == 0) OPTIONS.datatype = DATATYPE_FLOAT32; else if (strcasecmp(optarg, "double") == 0) OPTIONS.datatype = DATATYPE_FLOAT64; else { fprintf(stderr, "Error: element type must be one of { float | double }, but is %s\n", optarg); usage_and_exit(); } break; case 's': OPTIONS.significant_bits = atoi(optarg); if (OPTIONS.significant_bits < 1 || OPTIONS.significant_bits > 32) { fprintf(stderr, "Error: significant byte count must be between 1 and 32, inclusive, but is %d\n", OPTIONS.significant_bits); usage_and_exit(); } break; case ':': fprintf(stderr, "Option %c missing required argument\n", optopt); usage_and_exit(); break; case '?': default: fprintf(stderr, "Unknown option %c\n", optopt); usage_and_exit(); break; } } // Do some post-calculations based on all options if (!is_part_size_in_elem) { if (OPTIONS.datatype != DATATYPE_UNDEFINED) OPTIONS.part_size_in_elem /= ALDatatypeGetSize(OPTIONS.datatype); } // Now that they've been parsed, skip over the options, to // leave only non-option args argc -= optind; argv += optind; // Make sure there's at least one argument for the command, then capture // it and advance past it if (argc < 1) usage_and_exit(); const char *cmd = argv[0]; argc--; argv++; // Find the matching command (if any), call it, and return the value it returns for (int i = 0; i < NUM_COMMANDS; i++) if (strcmp(COMMANDS[i].name, cmd) == 0) return COMMANDS[i].func(argc, argv); // If no command matches, print an error message fprintf(stderr, "Error: command %s unrecognized\n", cmd); usage_and_exit(); // At the compiler's complaint... return 0; }
int main (int argc, char ** argv) { struct world *world; FILE *f; int c, ret; int head_steps, tail_steps, skip_steps, next_step; int ants_count, resolution; int step; int performance_test; int window_width; int window_height; int hex_size; dump_format = 0; step = 0; head_steps = 0; tail_steps = 0; skip_steps = 1; performance_test = 0; window_width = 800; window_height = 614; hex_size = 3; /* These are used for dump format, since it is difficult to figure them out. */ resolution = 10; ants_count = 32; world = NULL; while ((c=getopt (argc, argv, "wdh:t:s:a:p:W:H:c:")) != EOF) { switch (c) { case 'd': dump_format = 1; break; case 't': if (!optarg) usage_and_exit (argv[0]); tail_steps = atoi (optarg); break; case 's': if (!optarg) usage_and_exit (argv[0]); skip_steps = atoi (optarg); break; case 'r': if (!optarg) usage_and_exit (argv[0]); resolution = atoi (optarg); break; case 'a': if (!optarg) usage_and_exit (argv[0]); ants_count = atoi (optarg); break; case 'h': if (!optarg) usage_and_exit (argv[0]); head_steps = atoi (optarg); break; case 'w': warnings = 1; break; case 'p': if (!optarg) usage_and_exit (argv[0]); performance_test = atoi (optarg); break; case 'W': if (!optarg) usage_and_exit (argv[0]); window_width = atoi (optarg); break; case 'H': if (!optarg) usage_and_exit (argv[0]); window_height = atoi (optarg); break; case 'c': if (!optarg) usage_and_exit (argv[0]); hex_size = atoi (optarg); break; case '?': default: usage_and_exit (argv[0]); } } if (skip_steps < 1 || tail_steps < head_steps) { fprintf (stderr, "Illegal step setting.\n"); exit (-1); } if (dump_format) { next_step = head_steps; f = open_next_file_from_argv (argv); v_set_geometry (window_width, window_height, hex_size); v_initialize (); while (!feof (f)) { if (read_world_as_icfp_dump (&world, f, resolution, resolution, ants_count) == 0) { if (step <= head_steps || step >= tail_steps || step == next_step) { printf ("Step %d ...\n", step); display_world (world); v_refit_view (); if ((ret = v_poll_event (0))) { if (ret == -1) { break; } } next_step = skip_steps+step; } } step++; } fclose (f); } else { f = open_next_file_from_argv (argv); if (read_world (&world, f) != 0) { fprintf (stderr, "Error in reading world map.\n"); exit (-1); } fclose (f); f = open_next_file_from_argv (argv); if (parse_world_trace (world, f) != 0) { fprintf (stderr, "Error in reading world trace.\n"); exit (-1); } fclose (f); v_set_geometry (window_width, window_height, hex_size); v_initialize (); display_world (world); // v_refit_view (); } if (performance_test) { return run_performance_test (world, performance_test); } else { return run_main_loop (world); } }
static void parse_args(int argc, char *argv[], options_t *options) { int arg_idx = 1; unsigned long tmp_value; options->cycle_counting = 0; options->hex_output = 0; options->nes_mode = 0; options->org = 0x8000; options->max_num_bytes = 65536; while (arg_idx < argc) { /* First non-dash-starting argument is assumed to be filename */ if (argv[arg_idx][0] != '-') { break; } /* Got a switch, process it */ switch (argv[arg_idx][1]) { case 'h': case '?': usage_and_exit(0, NULL); break; case 'n': options->nes_mode = 1; break; case 'c': options->cycle_counting = 1; break; case 'd': options->hex_output = 1; break; case 'v': version(); exit(0); break; case 'o': if ((arg_idx == (argc - 1)) || (argv[arg_idx + 1][0] == '-')) { usage_and_exit(1, "Missing argument to -o switch"); } /* Get argument and parse it */ arg_idx++; if (!str_arg_to_ulong(argv[arg_idx], &tmp_value)) { usage_and_exit(1, "Invalid argument to -o switch"); } options->org = (uint16_t)(tmp_value & 0xFFFFu); break; case 'm': if ((arg_idx == (argc - 1)) || (argv[arg_idx + 1][0] == '-')) { usage_and_exit(1, "Missing argument to -m switch"); } /* Get argument and parse it */ arg_idx++; if (!str_arg_to_ulong(argv[arg_idx], &tmp_value)) { usage_and_exit(1, "Invalid argument to -m switch"); } options->max_num_bytes = tmp_value; break; default: version(); usage(); fprintf(stderr, "Unrecognized switch: %s\n", argv[arg_idx]); exit(1); } arg_idx++; } /* Make sure we have a filename left to take after we stopped parsing switches */ if (arg_idx >= argc) { usage_and_exit(1, "Missing filename from command line"); } options->filename = argv[arg_idx]; }
int main( int argc, char *argv[] ) { /** string to print in between documents, * if we are retrieving more than one. */ char *doc_sep_string = "\n===\n\n"; int num_docs_printed = 0; char *model_tag = NULL; char *model_data_dir = NULL; char *model_dir_parent = NULL; int use_working_dir = 0; int have_m_opt = 0; MODEL_PARAMS model_params; CORPUS_FORMAT corpus_format; FILE *corpus_file; off_t curr_doc_id; char *buf, curr_doc[BUFSIZ]; int buf_size; char buf2[BUFSIZ]; char pathbuf[BUFSIZ]; char *tempbuf; if ( (buf = malloc(BUFSIZ)) == NULL) { fprintf( stderr, "Can't malloc() initial buffer.\n"); exit(5); } buf_size = BUFSIZ; if (argc < 2) usage_and_exit( argv[0], 2 ); while( (argc > 1) && (argv[1][0] == '-') ) { switch( argv[1][1] ) { case 't' : use_working_dir = 1; break; case 'c' : if (argc < 3) { print_opt_req_arg("-c"); usage_and_exit( argv[0], 2 ); } ++argv; --argc; model_tag = argv[1]; break; case 'm' : if (argc < 3) { print_opt_req_arg("-m"); usage_and_exit( argv[0], 2 ); } ++argv; --argc; model_dir_parent = argv[1]; have_m_opt = 1; break; default : fprintf( stderr, "\nUnknown option: %s\n\n", argv[1] ); usage_and_exit( argv[0], 2 ); } /* switch( argv[1][1] ) */ /* Move the argument list ahead. The options don't count any longer as input terms. This works only if all options precede the input terms! */ ++argv; --argc; } /* while( (argc > 1) && (argv[1][0] == '-') ) */ if (model_dir_parent == NULL) { if (use_working_dir) { model_dir_parent = getenv(WORKING_DIR_VAR); if (model_dir_parent == NULL) { fprintf( stderr, "-t specified, but %s undefined.\n", WORKING_DIR_VAR ); exit( 2 ); } } else { if ( model_tag != NULL ) { model_dir_parent = search_model_path( model_tag ); if (model_dir_parent == NULL) { fprintf( stderr, "Could not find model with tag \"%s\" in " "Infomap model path.\n", model_tag ); exit( 2 ); } } } } /** at this point we have the appropriate model_data_dir, * however it was specified */ if (model_tag != NULL) { sprintf( pathbuf, "%s/%s", model_dir_parent, model_tag ); model_data_dir = strdup( pathbuf ); } else { if (have_m_opt) { model_data_dir = model_dir_parent; } } sprintf( buf, "%s/%s", model_data_dir, MODEL_PARAMS_BIN_FILE ); if ( !read_model_params( buf, &model_params )) { fprintf( stderr, "Can't read model params file \"%s\"", buf ); exit(3); } sprintf( buf, "%s/%s", model_data_dir, CORPUS_FORMAT_DATA_FILE ); if ( !read_corpus_format( buf, &corpus_format )) { fprintf( stderr, "Can't read corpus format file \"%s\"", buf ); exit(3); } if (model_params.corpus_type == MANY_FILES) { /** * in this case, we read entire files */ while (argc > 1) { memcpy( curr_doc, argv[1], strlen(argv[1])); ++argv; --argc; if ( (corpus_file = fopen( curr_doc, "r" )) == NULL ) { fprintf( stderr, "Can't open document file \"%s\".\n" "Skipping.\n", curr_doc ); continue; } if (num_docs_printed > 0) printf( "%s", doc_sep_string ); while ( fgets( buf, buf_size, corpus_file ) != NULL ) { printf( "%s", buf ); } num_docs_printed++; if ( ferror( corpus_file )) { perror("Error reading document file"); fclose( corpus_file ); continue; } fclose( corpus_file ); } } else if (model_params.corpus_type == ONE_FILE) { /** * in this case, we read from the offsets specified * up to the end of doc tag. */ if ( (corpus_file = fopen( model_params.corpus_filename, "r" )) == NULL ) { fprintf( stderr, "Can't open corpus file \"%s\".\n", model_params.corpus_filename ); exit(3); } while (argc > 1) { curr_doc_id = atol(argv[1]); ++argv; --argc; if ( fseek( corpus_file, curr_doc_id, SEEK_SET ) != 0 ) { fprintf( stderr, "Can't seek to document id %ld " "in corpus file.\n" "Skipping this document.\n", curr_doc_id); continue; } if (num_docs_printed > 0) printf( "%s", doc_sep_string ); while ( fgets( buf, buf_size, corpus_file ) != NULL ) { printf( "%s", buf); sprintf( buf2, "%s\n", corpus_format.e_doc_tag ); if ( strcmp(buf, buf2) == 0) break; } num_docs_printed++; if (ferror(corpus_file)) { perror("Error reading corpus file.\n"); exit(3); } } fclose(corpus_file); free_corpus_format( &corpus_format ); } else { fprintf( stderr, "Unrecognized corpus type in model params object.\n" ); exit(4); } exit(0); }
static void parse_short_options( const char *argument, const char *next_arg, int *index, struct argument_flags *flags) { size_t i; #if DEBUG journal("Parsing options in \"-%s\":\n", argument); #endif /* DEBUG */ for (i = 0; argument[i]; i++) { #if DEBUG journal(" Parsing flag \"-%c\".\n", argument[i]); journal(" flags = {\n"); journal(" ProgramName: %s\n", flags->program_name); journal(" ConfFile: %s\n", flags->conf_file); journal(" QuotesFile: %s\n", flags->quotes_file); journal(" PidFile: %s\n", flags->pid_file); journal(" JournalFile: %s\n", flags->journal_file); journal(" Daemonize: %s\n", BOOLSTR2(flags->daemonize)); journal(" Protocol: %s\n", \ name_option_protocol(flags->tproto, flags->iproto)); journal(" }\n\n"); #endif /* DEBUG */ switch (argument[i]) { case 'f': flags->daemonize = false; break; case 'c': if (!next_arg) { fprintf(stderr, "You must specify a configuration file.\n"); cleanup(EXIT_ARGUMENTS, true); } (*index)++; flags->conf_file = next_arg; break; case 'N': flags->conf_file = NULL; case 'P': if (!next_arg) { fprintf(stderr, "You must specify a pid file.\n"); cleanup(EXIT_ARGUMENTS, true); } (*index)++; flags->pid_file = next_arg; break; case 's': if (!next_arg) { fprintf(stderr, "You must specify a quotes file.\n"); cleanup(EXIT_ARGUMENTS, true); } (*index)++; flags->quotes_file = next_arg; break; case 'j': if (!next_arg) { fprintf(stderr, "You must specify a journal file.\n"); cleanup(EXIT_ARGUMENTS, true); } (*index)++; flags->journal_file = next_arg; break; case '4': if (flags->iproto == PROTOCOL_IPv6) { fprintf(stderr, "Conflicting options passed: -4 and -6.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->iproto = PROTOCOL_IPv4; break; case '6': if (flags->iproto == PROTOCOL_IPv4) { fprintf(stderr, "Conflicting options passed: -4 and -6.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->iproto = PROTOCOL_IPv6; break; case 't': if (flags->tproto == PROTOCOL_UDP) { fprintf(stderr, "Conflicting options passed: -t and -u.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->tproto = PROTOCOL_TCP; break; case 'u': if (flags->tproto == PROTOCOL_TCP) { fprintf(stderr, "Conflicting options passed: -t and -u.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->tproto = PROTOCOL_UDP; break; case 'q': close_journal(); break; default: fprintf(stderr, "Unknown short option: -%c.\n", argument[i]); usage_and_exit(flags->program_name); } } }
/* Process the argument character and its associated value. * This function processes arguments from the command line and * from an argument file associated with the -A argument. * * An argument -ofile.pgn would be passed in as: * 'o' and "file.pgn". * A zero-length string for associated_value is not necessarily * an error, e.g. -e has an optional following filename. * NB: If the associated_value is to be used beyond this function, * it must be copied. */ void process_argument(char arg_letter,const char *associated_value) { /* Provide an alias for associated_value because it will * often represent a file name. */ const char *filename = skip_leading_spaces(associated_value); switch(arg_letter){ case WRITE_TO_OUTPUT_FILE_ARGUMENT: case APPEND_TO_OUTPUT_FILE_ARGUMENT: if(GlobalState.ECO_level > 0){ fprintf(GlobalState.logfile,"-%c conflicts with -E\n", arg_letter); } else if(GlobalState.games_per_file > 0){ fprintf(GlobalState.logfile,"-%c conflicts with -#\n", arg_letter); } else if(GlobalState.output_filename != NULL){ fprintf(GlobalState.logfile, "-%c: File %s has already been selected for output.\n", arg_letter,GlobalState.output_filename); exit(1); } else if(*filename == '\0'){ fprintf(GlobalState.logfile,"Usage: -%cfilename.\n",arg_letter); exit(1); } else{ if(GlobalState.outputfile != NULL){ (void) fclose(GlobalState.outputfile); } if(arg_letter == WRITE_TO_OUTPUT_FILE_ARGUMENT){ GlobalState.outputfile = must_open_file(filename,"w"); } else{ GlobalState.outputfile = must_open_file(filename,"a"); } GlobalState.output_filename = filename; } break; case WRITE_TO_LOG_FILE_ARGUMENT: case APPEND_TO_LOG_FILE_ARGUMENT: /* Take precautions against multiple log files. */ if((GlobalState.logfile != stderr) && (GlobalState.logfile != NULL)){ (void) fclose(GlobalState.logfile); } if(arg_letter == WRITE_TO_LOG_FILE_ARGUMENT){ GlobalState.logfile = fopen(filename,"w"); } else{ GlobalState.logfile = fopen(filename,"a"); } if(GlobalState.logfile == NULL){ fprintf(stderr,"Unable to open %s for writing.\n",filename); GlobalState.logfile = stderr; } break; case DUPLICATES_FILE_ARGUMENT: if(*filename == '\0'){ fprintf(GlobalState.logfile,"Usage: -%cfilename.\n",arg_letter); exit(1); } else if(GlobalState.suppress_duplicates){ fprintf(GlobalState.logfile, "-%c clashes with the -%c flag.\n",arg_letter, DONT_KEEP_DUPLICATES_ARGUMENT); exit(1); } else{ GlobalState.duplicate_file = must_open_file(filename,"w"); } break; case USE_ECO_FILE_ARGUMENT: GlobalState.add_ECO = TRUE; if(*filename != '\0'){ GlobalState.eco_file = copy_string(filename); } else if((filename = getenv("ECO_FILE")) != NULL){ GlobalState.eco_file = filename; } else{ /* Use the default which is already set up. */ } initEcoTable(); break; case ECO_OUTPUT_LEVEL_ARGUMENT: { unsigned level; if(GlobalState.output_filename != NULL){ fprintf(GlobalState.logfile, "-%c: File %s has already been selected for output.\n", arg_letter, GlobalState.output_filename); exit(1); } else if(GlobalState.games_per_file > 0){ fprintf(GlobalState.logfile, "-%c conflicts with -#.\n", arg_letter); exit(1); } else if(sscanf(associated_value,"%u",&level) != 1){ fprintf(GlobalState.logfile, "-%c requires a number attached, e.g., -%c1.\n", arg_letter,arg_letter); exit(1); } else if((level < MIN_ECO_LEVEL) || (level > MAX_ECO_LEVEL)){ fprintf(GlobalState.logfile, "-%c level should be between %u and %u.\n", MIN_ECO_LEVEL,MAX_ECO_LEVEL,arg_letter); exit(1); } else{ GlobalState.ECO_level = level; } } break; case CHECK_FILE_ARGUMENT: if(*filename != '\0'){ /* See if it is a single PGN file, or a list * of files. */ size_t len = strlen(filename); /* Check for a .PGN suffix. */ const char *suffix = output_file_suffix(SAN); if((len > strlen(suffix)) && (stringcompare(&filename[len-strlen(suffix)], suffix) == 0)){ add_filename_to_source_list(filename,CHECKFILE); } else{ FILE *fp = must_open_file(filename,"r"); add_filename_list_from_file(fp,CHECKFILE); (void) fclose(fp); } } break; case FILE_OF_FILES_ARGUMENT: if(*filename != '\0'){ FILE *fp = must_open_file(filename,"r"); add_filename_list_from_file(fp,NORMALFILE); (void) fclose(fp); } else{ fprintf(GlobalState.logfile,"Filename expected with -%c\n", arg_letter); } break; case BOUNDS_ARGUMENT: { /* Bounds on the number of moves are to be found. * "l#" means less-than-or-equal-to. * "g#" means greater-than-or-equal-to. * Otherwise "#" (or "e#") means that number. */ /* Equal by default. */ char which = 'e'; unsigned value; Boolean Ok = TRUE; const char *bound = associated_value; switch(*bound){ case 'l': case 'u': case 'e': which = *bound; bound++; break; default: if(!isdigit((int) *bound)){ fprintf(GlobalState.logfile, "-%c must be followed by e, l, or u.\n", arg_letter); Ok = FALSE; } break; } if(Ok && (sscanf(bound,"%u",&value) == 1)){ GlobalState.check_move_bounds = TRUE; switch(which){ case 'e': GlobalState.lower_move_bound = value; GlobalState.upper_move_bound = value; break; case 'l': if(value <= GlobalState.upper_move_bound){ GlobalState.lower_move_bound = value; } else{ fprintf(GlobalState.logfile, "Lower bound is greater than the upper bound; -%c ignored.\n", arg_letter); Ok = FALSE; } break; case 'u': if(value >= GlobalState.lower_move_bound){ GlobalState.upper_move_bound = value; } else{ fprintf(GlobalState.logfile, "Upper bound is smaller than the lower bound; -%c ignored.\n", arg_letter); Ok = FALSE; } break; } } else{ fprintf(GlobalState.logfile, "-%c should be in the form -%c[elu]number.\n", arg_letter,arg_letter); Ok = FALSE; } if(!Ok){ exit(1); } } break; case GAMES_PER_FILE_ARGUMENT: if(GlobalState.ECO_level > 0){ fprintf(GlobalState.logfile, "-%c conflicts with -E.\n",arg_letter); exit(1); } else if(GlobalState.output_filename != NULL){ fprintf(GlobalState.logfile, "-%c: File %s has already been selected for output.\n", arg_letter, GlobalState.output_filename); exit(1); } else if(sscanf(associated_value,"%u", &GlobalState.games_per_file) != 1){ fprintf(GlobalState.logfile, "-%c should be followed by an unsigned integer.\n", arg_letter); exit(1); } else{ /* Value set. */ } break; case FILE_OF_ARGUMENTS_ARGUMENT: if(*filename != '\0'){ /* @@@ Potentially recursive call. Is this safe? */ read_args_file(filename); } else{ fprintf(GlobalState.logfile,"Usage: -%cfilename.\n", arg_letter); } break; case NON_MATCHING_GAMES_ARGUMENT: if(*filename != '\0'){ if(GlobalState.non_matching_file != NULL){ (void) fclose(GlobalState.non_matching_file); } GlobalState.non_matching_file = must_open_file(filename,"w"); } else{ fprintf(GlobalState.logfile,"Usage: -%cfilename.\n",arg_letter); exit(1); } break; case TAG_EXTRACTION_ARGUMENT: /* A single tag extraction criterion. */ extract_tag_argument(associated_value); break; case LINE_WIDTH_ARGUMENT: { /* Specify an output line width. */ unsigned length; if(sscanf(associated_value,"%u",&length) > 0){ set_output_line_length(length); } else{ fprintf(GlobalState.logfile, "-%c should be followed by an unsigned integer.\n", arg_letter); exit(1); } } break; case HELP_ARGUMENT: usage_and_exit(); break; case OUTPUT_FORMAT_ARGUMENT: /* Whether to use the source form of moves or * rewrite them into another format. */ { OutputFormat format = which_output_format(associated_value); if(format == UCI) { /* Rewrite the game in a format suitable for input to * a UCI-compatible engine. * This is actually LALG but involves adjusting a lot of * the other statuses, too. */ GlobalState.keep_NAGs = FALSE; GlobalState.keep_comments = FALSE; GlobalState.keep_move_numbers = FALSE; GlobalState.keep_checks = FALSE; GlobalState.keep_variations = FALSE; set_output_line_length(5000); format = LALG; } GlobalState.output_format = format; } break; case SEVEN_TAG_ROSTER_ARGUMENT: if(GlobalState.tag_output_format == ALL_TAGS || GlobalState.tag_output_format == SEVEN_TAG_ROSTER) { GlobalState.tag_output_format = SEVEN_TAG_ROSTER; } else { fprintf(GlobalState.logfile, "-%c clashes with another argument.\n", SEVEN_TAG_ROSTER_ARGUMENT); exit(1); } break; case DONT_KEEP_COMMENTS_ARGUMENT: GlobalState.keep_comments = FALSE; break; case DONT_KEEP_DUPLICATES_ARGUMENT: /* Make sure that this doesn't clash with -d. */ if(GlobalState.duplicate_file == NULL){ GlobalState.suppress_duplicates = TRUE; } else{ fprintf(GlobalState.logfile, "-%c clashes with -%c flag.\n", DONT_KEEP_DUPLICATES_ARGUMENT, DUPLICATES_FILE_ARGUMENT); exit(1); } break; case DONT_MATCH_PERMUTATIONS_ARGUMENT: GlobalState.match_permutations = FALSE; break; case DONT_KEEP_NAGS_ARGUMENT: GlobalState.keep_NAGs = FALSE; break; case OUTPUT_FEN_STRING_ARGUMENT: /* Output a FEN string of the final position. * This is displayed in a comment. */ if(GlobalState.add_FEN_comments) { /* Already implied. */ GlobalState.output_FEN_string = FALSE; } else { GlobalState.output_FEN_string = TRUE; } break; case CHECK_ONLY_ARGUMENT: /* Report errors, but don't convert. */ GlobalState.check_only = TRUE; break; case KEEP_SILENT_ARGUMENT: /* Turn off progress reporting. */ GlobalState.verbose = FALSE; break; case USE_SOUNDEX_ARGUMENT: /* Use soundex matches for player tags. */ GlobalState.use_soundex = TRUE; break; case MATCH_CHECKMATE_ARGUMENT: /* Match only games that end in checkmate. */ GlobalState.match_only_checkmate = TRUE; break; case SUPPRESS_ORIGINALS_ARGUMENT: GlobalState.suppress_originals = TRUE; break; case DONT_KEEP_VARIATIONS_ARGUMENT: GlobalState.keep_variations = FALSE; break; case USE_VIRTUAL_HASH_TABLE_ARGUMENT: GlobalState.use_virtual_hash_table = TRUE; break; case TAGS_ARGUMENT: if(*filename != '\0'){ read_tag_file(filename); } break; case TAG_ROSTER_ARGUMENT: if(*filename != '\0'){ read_tag_roster_file(filename); } break; case MOVES_ARGUMENT: if(*filename != '\0'){ /* Where the list of variations of interest are kept. */ FILE *variation_file = must_open_file(filename,"r"); /* We wish to search for particular variations. */ add_textual_variations_from_file(variation_file); fclose(variation_file); } break; case POSITIONS_ARGUMENT: if(*filename != '\0'){ FILE *variation_file = must_open_file(filename,"r"); /* We wish to search for positional variations. */ add_positional_variations_from_file(variation_file); fclose(variation_file); } break; case ENDINGS_ARGUMENT: if(*filename != '\0'){ if(!build_endings(filename)){ exit(1); } } break; default: fprintf(GlobalState.logfile, "Unrecognized argument -%c\n", arg_letter); } }
int main(int argc, char *argv[]) { FILE *FptrNumDocs; ENVIRONMENT env; char *model_data_dir; char pathbuf[BUFSIZ]; char *col_label_file; int write_matlab; int col_labels_from_file; int rows, columns; MODEL_PARAMS model_params; MODEL_INFO model_info; env.word_array = NULL; env.word_tree = NULL; if ( argc != 17 ) usage_and_exit( argv[0], 1 ); if ( strcmp( argv[1], "-mdir" ) != 0 ) usage_and_exit( argv[0], 1 ); model_data_dir = argv[2]; if ( strcmp( argv[3], "-matlab" ) != 0 ) usage_and_exit( argv[0], 1 ); write_matlab = atoi( argv[4] ); if ( strcmp( argv[5], "-precontext" ) != 0 ) usage_and_exit( argv[0], 1 ); pre_context_size = atoi( argv[6] ); if ( strcmp( argv[7], "-postcontext" ) != 0 ) usage_and_exit( argv[0], 1 ); post_context_size = atoi( argv[8] ); if ( strcmp( argv[9], "-rows" ) != 0 ) usage_and_exit( argv[0], 1 ); rows = atoi( argv[10] ); if ( strcmp( argv[11], "-columns" ) != 0 ) usage_and_exit( argv[0], 1 ); columns = atoi( argv[12] ); if ( strcmp( argv[13], "-col_labels_from_file" ) != 0 ) usage_and_exit( argv[0], 1 ); col_labels_from_file = atoi( argv[14] ); if ( strcmp( argv[15], "-col_label_file" ) != 0 ) usage_and_exit( argv[0], 1 ); col_label_file = argv[16]; fprintf( stderr, "model data dir is \"%s\".\n", model_data_dir ); /** Read in current model params **/ sprintf( pathbuf, "%s/%s", model_data_dir, MODEL_PARAMS_BIN_FILE ); if ( !read_model_params( pathbuf, &model_params )) { die( "count_wordvec.c: couldn't read model data file\n" ); } sprintf( pathbuf, "%s/%s", model_data_dir, MODEL_INFO_BIN_FILE ); if ( !read_model_info( pathbuf, &model_info )) { die( "count_wordvec.c: couldn't read model info file\n" ); } if (model_params.rows < rows) { rows = model_params.rows; } else { model_params.rows = rows; } printf("count_wordvec.c: looking for %d rows\n", rows); printf("which had better match %d\n", model_params.rows); model_info.columns = columns; model_info.col_labels_from_file = col_labels_from_file; model_info.pre_context_size = pre_context_size; model_info.post_context_size = post_context_size; model_info.blocksize = BLOCKSIZE; model_info.start_columns = START_COLUMNS; message( "Reading the dictionary... "); if( !read_dictionary( &(env.word_array), &(env.word_tree), model_data_dir )) die( "count_wordvec.c: Can't read the dictionary.\n"); /*** read number of ducuments from file ***/ sprintf( pathbuf, "%s/%s", model_data_dir, FNUM_FILE ); if ( !my_fopen( &FptrNumDocs, pathbuf, "r" )) die( "couldn't open filenames file" ); if( !fscanf( FptrNumDocs, "%d", &numDocs )) die( "can't read numDocs" ); if( !my_fclose( &FptrNumDocs )) die( "couldn't close numDocs file" ); /*****/ /* Set some initial values in the matrix, arrays etc. */ if( !initialize_row_indices( env.word_array, &(env.row_indices), rows )) die( "Couldn't initialize row indices.\n"); if( !initialize_column_indices( env.word_array, &(env.col_indices), columns, col_labels_from_file, col_label_file, &(env.word_tree) )) die( "Couldn't initialize column indices.\n"); /* Allocate memory and set everything to zero. Defined in matrix.h */ if( !initialize_matrix( (MATRIX_TYPE***) &(env.matrix), rows, columns)) die( "Can't initialize matrix.\n"); /* Go through the wordlist, applying process_region to all regions. */ fprintf( stderr, "model data dir is \"%s\".\n", model_data_dir ); fprintf( stderr, "count_wordvec.c: about to call process_wordlist\n" ); if( !process_wordlist( is_target, advance_target, set_region_in, set_region_out, process_region , &env, model_data_dir)) die( "Couldn't process wordlist.\n"); /* Perform some conversion on the matrix. E.g. some kind of normalization. We traditionally take the square root of all entries. */ if( !transform_matrix( (MATRIX_TYPE **) (env.matrix), rows, columns)) die( "Couldn't transform matrix.\n"); /* Write the co-occurrence matrix. */ message( "Writing the co-occurrence matrix.\n"); if( !write_matrix_svd((MATRIX_TYPE **) (env.matrix), rows, columns, model_data_dir )) die( "count_wordvec.c: couldn't write co-occurrence " "matrix in SVD input format.\n" ); if ( write_matlab ) { if ( !write_matrix_matlab( (MATRIX_TYPE **)(env.matrix), rows, columns, model_data_dir )) die( "count_wordvec.c: couldn't write co-occurrence " "matrix in Matlab input format.\n" ); } sprintf( pathbuf, "%s/%s", model_data_dir, MODEL_PARAMS_BIN_FILE ); if ( !write_model_params( pathbuf, &model_params )) { die( "count_wordvec.c: couldn't write model params file\n" ); } sprintf( pathbuf, "%s/%s", model_data_dir, MODEL_INFO_BIN_FILE ); if ( !write_model_info( pathbuf, &model_info )) { die( "count_wordvec.c: couldn't write model info file\n" ); } exit( EXIT_SUCCESS); }
int main(int argc, char** argv) { QApplication app(argc, argv); if(argc != 3) usage_and_exit(argv[0]); QVTKWidget widget; widget.resize(256,256); #if QT_VERSION < 0x040000 app.setMainWidget(&widget); #endif CGAL::Image_3 image; if(!image.read(argv[1])) { std::cerr << "Cannot read image file \"" << argv[1] << "\"!\n"; usage_and_exit(argv[0]); } std::stringstream argv2; argv2 << argv[2]; double isovalue; if(!(argv2 >> isovalue)) { std::cerr << "Invalid iso-value \"" << argv[2] << "\"!\n"; usage_and_exit(argv[0]); } vtkImageData* vtk_image = CGAL::vtk_image_sharing_same_data_pointer(image); vtkRenderer *aRenderer = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(aRenderer); widget.SetRenderWindow(renWin); vtkContourFilter *skinExtractor = vtkContourFilter::New(); skinExtractor->SetInputData(vtk_image); skinExtractor->SetValue(0, isovalue); // skinExtractor->SetComputeNormals(0); vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New(); skinNormals->SetInputConnection(skinExtractor->GetOutputPort()); skinNormals->SetFeatureAngle(60.0); vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New(); skinMapper->SetInputConnection(skinExtractor->GetOutputPort()); skinMapper->ScalarVisibilityOff(); vtkActor *skin = vtkActor::New(); skin->SetMapper(skinMapper); // An outline provides context around the data. // vtkOutlineFilter *outlineData = vtkOutlineFilter::New(); outlineData->SetInputData(vtk_image); vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New(); mapOutline->SetInputConnection(outlineData->GetOutputPort()); vtkActor *outline = vtkActor::New(); outline->SetMapper(mapOutline); outline->GetProperty()->SetColor(0,0,0); // It is convenient to create an initial view of the data. The FocalPoint // and Position form a vector direction. Later on (ResetCamera() method) // this vector is used to position the camera to look at the data in // this direction. vtkCamera *aCamera = vtkCamera::New(); aCamera->SetViewUp (0, 0, -1); aCamera->SetPosition (0, 1, 0); aCamera->SetFocalPoint (0, 0, 0); aCamera->ComputeViewPlaneNormal(); // Actors are added to the renderer. An initial camera view is created. // The Dolly() method moves the camera towards the FocalPoint, // thereby enlarging the image. aRenderer->AddActor(outline); aRenderer->AddActor(skin); aRenderer->SetActiveCamera(aCamera); aRenderer->ResetCamera (); aCamera->Dolly(1.5); // Set a background color for the renderer and set the size of the // render window (expressed in pixels). aRenderer->SetBackground(1,1,1); renWin->SetSize(640, 480); // Note that when camera movement occurs (as it does in the Dolly() // method), the clipping planes often need adjusting. Clipping planes // consist of two planes: near and far along the view direction. The // near plane clips out objects in front of the plane; the far plane // clips out objects behind the plane. This way only what is drawn // between the planes is actually rendered. aRenderer->ResetCameraClippingRange (); // Initialize the event loop and then start it. // iren->Initialize(); // iren->Start(); // It is important to delete all objects created previously to prevent // memory leaks. In this case, since the program is on its way to // exiting, it is not so important. But in applications it is // essential. vtk_image->Delete(); skinExtractor->Delete(); skinNormals->Delete(); skinMapper->Delete(); skin->Delete(); outlineData->Delete(); mapOutline->Delete(); outline->Delete(); aCamera->Delete(); // iren->Delete(); renWin->Delete(); aRenderer->Delete(); widget.show(); app.exec(); return 0; }
static void parse_long_option( const int argc, const char *const argv[], int *i, struct argument_flags *flags) { if (!strcmp(argv[*i], "--help")) { help_and_exit(flags->program_name); } else if (!strcmp(argv[*i], "--version")) { version_and_exit(); } else if (!strcmp(argv[*i], "--foreground")) { flags->daemonize = false; } else if (!strcmp(argv[*i], "--config")) { if (++(*i) == argc) { fprintf(stderr, "You must specify a configuration file.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->conf_file = argv[*i]; } else if (!strcmp(argv[*i], "--noconfig")) { flags->conf_file = NULL; } else if (!strcmp(argv[*i], "--lax")) { fprintf(stderr, "Note: --lax has been enabled. Security checks will *not* be performed.\n"); flags->strict = false; } else if (!strcmp(argv[*i], "--pidfile")) { if (++(*i) == argc) { fprintf(stderr, "You must specify a pid file.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->pid_file = argv[*i]; } else if (!strcmp(argv[*i], "--quotes")) { if (++(*i) == argc) { fprintf(stderr, "You must specify a quotes file.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->quotes_file = argv[*i]; } else if (!strcmp(argv[*i], "--journal")) { if (++(*i) == argc) { fprintf(stderr, "You must specify a journal file.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->journal_file = argv[*i]; } else if (!strcmp(argv[*i], "--ipv4")) { if (flags->iproto == PROTOCOL_IPv6) { fprintf(stderr, "Conflicting options passed: -4 and -6.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->iproto = PROTOCOL_IPv4; } else if (!strcmp(argv[*i], "--ipv6")) { if (flags->iproto == PROTOCOL_IPv4) { fprintf(stderr, "Conflicting options passed: -4 and -6.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->iproto = PROTOCOL_IPv6; } else if (!strcmp(argv[*i], "--tcp")) { if (flags->tproto == PROTOCOL_UDP) { fprintf(stderr, "Conflicting options passed: -t and -u.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->tproto = PROTOCOL_TCP; } else if (!strcmp(argv[*i], "--udp")) { if (flags->tproto == PROTOCOL_TCP) { fprintf(stderr, "Conflicting options passed: -t and -u.\n"); cleanup(EXIT_ARGUMENTS, true); } flags->tproto = PROTOCOL_UDP; } else if (!strcmp(argv[*i], "--quiet")) { close_journal(); } else { printf("Unrecognized long option: %s.\n", argv[*i]); usage_and_exit(flags->program_name); } }
void parse_args(struct options *const opt, const int argc, const char *const argv[]) { struct argument_flags flags; int i; /* Set override flags */ flags.program_name = basename((char *)argv[0]); flags.conf_file = DEFAULT_CONFIG_FILE; flags.quotes_file = NULL; flags.pid_file = NULL; flags.journal_file = NULL; flags.tproto = PROTOCOL_TNONE; flags.iproto = PROTOCOL_INONE; flags.daemonize = BOOLEAN_UNSET; flags.strict = true; /* Set default options, defined in options.h */ opt->port = DEFAULT_PORT; opt->tproto = DEFAULT_TRANSPORT_PROTOCOL; opt->iproto = DEFAULT_INTERNET_PROTOCOL; opt->quotes_file = DEFAULT_QUOTES_FILE; opt->linediv = DEFAULT_LINE_DIVIDER; opt->pid_file = default_pidfile(); opt->require_pidfile = DEFAULT_REQUIRE_PIDFILE; opt->daemonize = DEFAULT_DAEMONIZE; opt->drop_privileges = DEFAULT_DROP_PRIVILEGES; opt->is_daily = DEFAULT_IS_DAILY; opt->pad_quotes = DEFAULT_PAD_QUOTES; opt->allow_big = DEFAULT_ALLOW_BIG; opt->chdir_root = DEFAULT_CHDIR_ROOT; /* Parse arguments */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--")) { break; } else if (!strncmp(argv[i], "--", 2)) { parse_long_option(argc, argv, &i, &flags); } else if (argv[i][0] == '-') { const char *next_arg = (i + 1 == argc) ? NULL : argv[i + 1]; parse_short_options(argv[i] + 1, next_arg, &i, &flags); } else { printf("Unrecognized option: %s.\n", argv[i]); usage_and_exit(flags.program_name); } } /* Override config file options */ opt->strict = flags.strict; if (flags.conf_file) { if (flags.conf_file[0] != '/') { opt->chdir_root = false; } parse_config(flags.conf_file, opt); } if (flags.pid_file) { opt->pid_file = strcmp(flags.pid_file, "none") ? flags.pid_file : NULL; } if (flags.quotes_file) { opt->quotes_file = flags.quotes_file; } if (flags.journal_file && !strcmp(flags.journal_file, "-")) { opt->journal_file = flags.journal_file; } else { opt->journal_file = NULL; } if (flags.iproto != PROTOCOL_INONE) { opt->iproto = flags.iproto; } if (flags.tproto != PROTOCOL_TNONE) { opt->tproto = flags.tproto; } if (flags.daemonize != BOOLEAN_UNSET) { opt->daemonize = flags.daemonize; } #if DEBUG journal("\nContents of struct 'opt':\n"); journal("opt = {\n"); journal(" QuotesFile: %s\n", BOOLSTR(opt->quotes_file)); journal(" PidFile: %s\n", opt->pid_file); journal(" Port: %u\n", opt->port); journal(" QuoteDivider: %s\n", name_option_quote_divider(opt->linediv)); journal(" Protocol: %s\n", name_option_protocol(opt->tproto, opt->iproto)); journal(" Daemonize: %s\n", BOOLSTR(opt->daemonize)); journal(" RequirePidfile: %s\n", BOOLSTR(opt->require_pidfile)); journal(" DropPrivileges: %s\n", BOOLSTR(opt->drop_privileges)); journal(" DailyQuotes: %s\n", BOOLSTR(opt->is_daily)); journal(" AllowBigQuotes: %s\n", BOOLSTR(opt->allow_big)); journal(" ChdirRoot: %s\n", BOOLSTR(opt->chdir_root)); journal("}\n\n"); #endif /* DEBUG */ }
int ACE_TMAIN(int argc, ACE_TCHAR** argv) { int status = 0; const char* exename = "repoctl"; try { // Initialize an ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Grab our information from the command line. Options options(argc, argv); exename = ACE_OS::strdup( options.name().c_str()); OpenDDS::DCPS::DCPSInfo_var ir; OpenDDS::Federator::Manager_var target; OpenDDS::Federator::Manager_var peer; if (options.command() == Options::KILL) { // Resolve the ir reference. std::string iorString("corbaloc:iiop:"); iorString += options.target(); iorString += "/"; iorString += OpenDDS::Federator::REPOSITORY_IORTABLE_KEY; if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: ") ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"), exename, iorString.c_str())); } CORBA::Object_var obj = orb->string_to_object(iorString.c_str()); ir = OpenDDS::DCPS::DCPSInfo::_narrow(obj.in()); if (CORBA::is_nil(ir.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"), exename, iorString.c_str())); return -4; } } else { // Resolve the target reference. std::string iorString("corbaloc:iiop:"); iorString += options.target(); iorString += "/"; iorString += OpenDDS::Federator::FEDERATOR_IORTABLE_KEY; if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: ") ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"), exename, iorString.c_str())); } CORBA::Object_var obj = orb->string_to_object(iorString.c_str()); target = OpenDDS::Federator::Manager::_narrow(obj.in()); if (CORBA::is_nil(target.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"), exename, iorString.c_str())); return -5; } // Join command needs the peer reference resolved as well. if (options.command() == Options::JOIN) { iorString = "corbaloc:iiop:"; iorString += options.peer(); iorString += "/"; iorString += OpenDDS::Federator::FEDERATOR_IORTABLE_KEY; if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: ") ACE_TEXT("attempting to resolve and connect to repository at: %C.\n"), exename, iorString.c_str())); } obj = orb->string_to_object(iorString.c_str()); peer = OpenDDS::Federator::Manager::_narrow(obj.in()); if (CORBA::is_nil(peer.in())) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: %C: could not narrow %C.\n"), exename, iorString.c_str())); return -6; } } } switch (options.command()) { case Options::JOIN: { if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: federating.\n"), exename)); } target->join_federation(peer.in(), options.federationDomain()); } break; case Options::LEAVE: { if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: leaving and shutting down.\n"), exename)); } target->leave_and_shutdown(); } break; case Options::SHUTDOWN: { if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: shutting down.\n"), exename)); } target->shutdown(); } break; case Options::KILL: { if (options.verbose()) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%P|%t) INFO: %C: shutting down.\n"), exename)); } ir->shutdown(); } break; default: ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: %C: unknown command requested.\n "), exename)); usage_and_exit(-7); break; } } catch (const CORBA::Exception& ex) { std::string message = "(%P|%t) ABORT: "; message += exename; message += " : CORBA problem detected.\n"; ex._tao_print_exception(message.c_str()); status = -1; } catch (const std::exception& ex) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ABORT: %C: %C exception caught in main().\n"), ex.what(), exename)); status = -2; } catch (...) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ABORT: %C: unspecified exception caught in main() - panic.\n"), exename)); status = -3; } return status; }
void perror_xu(const char *errstr) { _perror_x(errstr); usage_and_exit(); }
static void build_dataset_1(const char *filename_prefix, const char *transform_name) { // Basic dataset information // NOTE: we have to use an anonymous enum here to define these constants, since // C is picky and doesn't consider a static const int "const enough" to use // as an array length (e.g., if these were static const ints, it would not compile) enum { NUM_DIMS = 1, NUM_TS = 1, NUM_PGS_PER_TS = 1, NUM_VARS = 1, NUM_PGS = NUM_TS * NUM_PGS_PER_TS, }; // Variable names/types static const char *VARNAMES[NUM_VARS] = { "temp" }; static const enum ADIOS_DATATYPES VARTYPES[NUM_VARS] = { adios_real }; // Global and PG dimensions/offsets static const uint64_t GLOBAL_DIMS [NUM_DIMS] = { 16 }; static const uint64_t PG_DIMS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 16 } } }; static const uint64_t PG_OFFSETS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 0 } } }; // Variable data (we can use [TS][PG][16] here because every PG is the same size, 16) static const float TEMP_DATA[NUM_TS][NUM_PGS_PER_TS][16] = { // Timestep 1 // PG 0 in timestep 1 // -1.00000000 -1.00003052 2.00000000 2.00006104 -0x1.000000p+0, -0x1.000200p+0, 0x1.000000p+1, 0x1.000200p+1, // 2.00012207 -30.00000000 -30.00048828 -30.00097656 0x1.000400p+1, -0x1.e00000p+4, -0x1.e00200p+4, -0x1.e00400p+4, // -30.00146484 50.00000000 50.00097656 50.00195312 -0x1.e00600p+4, 0x1.900000p+5, 0x1.900200p+5, 0x1.900400p+5, // 50.00292969 50.00390625 50.00488281 50.00585938 0x1.900600p+5, 0x1.900800p+5, 0x1.900a00p+5, 0x1.900c00p+5, }; static const void *VARBLOCKS_BY_VAR[NUM_VARS] = { TEMP_DATA, }; // Now, collect all this information into specification structs // File specification static const dataset_xml_spec_t XML_SPEC = { .group_name = "S3D", .buffer_size_mb = 128, .write_transport_method = "MPI", .ndim = NUM_DIMS, .nvar = NUM_VARS, .varnames = VARNAMES, .vartypes = VARTYPES, }; // Global space specification static const dataset_global_spec_t GLOBAL_SPEC = { .num_ts = NUM_TS, .num_pgs_per_ts = NUM_PGS_PER_TS, .global_dims = GLOBAL_DIMS, }; // Finally, invoke the dataset builder with this information build_dataset_from_varblocks_by_var( filename_prefix, transform_name, &XML_SPEC, &GLOBAL_SPEC, NUM_TS, NUM_PGS_PER_TS, NUM_DIMS, NUM_VARS, PG_DIMS, PG_OFFSETS, (const void **)VARBLOCKS_BY_VAR); } // Variable data used in datasets 2 and 3 static const float TEMP_DATA_FOR_DS2_AND_DS3[] = { // Timestep 1 -0x1.122f92p-5, 0x1.51e224p-2, -0x1.619b00p-1, 0x1.b0a05ap-2, -0x1.a66e56p-3, 0x1.0021acp-2, -0x1.45eb00p-1, 0x1.ba2cb6p-1, -0x1.34e536p-2, 0x1.985a90p-6, -0x1.75c0a6p-2, 0x1.87e004p-1, -0x1.457d2ap-2, 0x1.15f8c4p-3, -0x1.b53a84p-4, 0x1.8576bep-1, -0x1.4e8798p-4, 0x1.1a16eep-1, -0x1.211a0ep-1, 0x1.7c8df4p-1, -0x1.f6a944p-1, 0x1.c03452p-3, -0x1.d14d2ap-2, 0x1.098d06p-1, -0x1.25ce96p-1, 0x1.1c473ep-1, -0x1.750404p-1, 0x1.41fbc4p-1, -0x1.979e1cp-1, 0x1.2adcccp-1, -0x1.195c60p-2, 0x1.a8c114p-1, -0x1.d3cddep-1, 0x1.ee4930p-1, -0x1.022282p-2, 0x1.eb4ba0p-4, -0x1.b9681ap-3, 0x1.c6fc40p-1, -0x1.f7962ap-1, 0x1.08cca2p-1, -0x1.d3bf16p-1, 0x1.64ecfap-2, -0x1.21594cp-2, 0x1.d9f6a6p-3, -0x1.efe95cp-2, 0x1.8ea7eep-2, -0x1.fbf468p-1, 0x1.21c5a2p-1, -0x1.e16ae6p-1, 0x1.1d0e76p-1, -0x1.3ca72ap-2, 0x1.d8142ap-1, -0x1.8d1b8ap-1, 0x1.86fa2ap-1, -0x1.c3425ep-2, 0x1.65d43ep-2, -0x1.4682d0p-2, 0x1.5a94cap-3, -0x1.f4e5e4p-1, 0x1.d6fc1cp-4, -0x1.818200p-1, 0x1.032826p-2, -0x1.e3a098p-1, 0x1.554fdep-1, // Timestep 2 -0x1.554fdep-1, 0x1.e3a098p-1, -0x1.032826p-2, 0x1.818200p-1, -0x1.d6fc1cp-4, 0x1.f4e5e4p-1, -0x1.5a94cap-3, 0x1.4682d0p-2, -0x1.65d43ep-2, 0x1.c3425ep-2, -0x1.86fa2ap-1, 0x1.8d1b8ap-1, -0x1.d8142ap-1, 0x1.3ca72ap-2, -0x1.1d0e76p-1, 0x1.e16ae6p-1, -0x1.21c5a2p-1, 0x1.fbf468p-1, -0x1.8ea7eep-2, 0x1.efe95cp-2, -0x1.d9f6a6p-3, 0x1.21594cp-2, -0x1.64ecfap-2, 0x1.d3bf16p-1, -0x1.08cca2p-1, 0x1.f7962ap-1, -0x1.c6fc40p-1, 0x1.b9681ap-3, -0x1.eb4ba0p-4, 0x1.022282p-2, -0x1.ee4930p-1, 0x1.d3cddep-1, -0x1.a8c114p-1, 0x1.195c60p-2, -0x1.2adcccp-1, 0x1.979e1cp-1, -0x1.41fbc4p-1, 0x1.750404p-1, -0x1.1c473ep-1, 0x1.25ce96p-1, -0x1.098d06p-1, 0x1.d14d2ap-2, -0x1.c03452p-3, 0x1.f6a944p-1, -0x1.7c8df4p-1, 0x1.211a0ep-1, -0x1.1a16eep-1, 0x1.4e8798p-4, -0x1.8576bep-1, 0x1.b53a84p-4, -0x1.15f8c4p-3, 0x1.457d2ap-2, -0x1.87e004p-1, 0x1.75c0a6p-2, -0x1.985a90p-6, 0x1.34e536p-2, -0x1.ba2cb6p-1, 0x1.45eb00p-1, -0x1.0021acp-2, 0x1.a66e56p-3, -0x1.b0a05ap-2, 0x1.619b00p-1, -0x1.51e224p-2, 0x1.122f92p-5, }; static void build_dataset_2(const char *filename_prefix, const char *transform_name) { // Basic dataset information // NOTE: we have to use an anonymous enum here to define these constants, since // C is picky and doesn't consider a static const int "const enough" to use // as an array length (e.g., if these were static const ints, it would not compile) enum { NUM_DIMS = 2, NUM_TS = 2, NUM_PGS_PER_TS = 4, NUM_VARS = 1, NUM_PGS = NUM_TS * NUM_PGS_PER_TS, }; // Variable names/types static const char *VARNAMES[NUM_VARS] = { "temp" }; static const enum ADIOS_DATATYPES VARTYPES[NUM_VARS] = { adios_real }; // Global and PG dimensions/offsets static const uint64_t GLOBAL_DIMS [NUM_DIMS] = { 8, 8 }; static const uint64_t PG_DIMS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 2, 8 }, { 2, 8 }, { 2, 8 }, { 2, 8 }, }, // Timestep 1 { { 2, 8 }, { 2, 8 }, { 2, 8 }, { 2, 8 }, }, // Timestep 2 }; static const uint64_t PG_OFFSETS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 0, 0 }, { 2, 0 }, { 4, 0 }, { 6, 0 }, }, // Timestep 1 { { 0, 0 }, { 2, 0 }, { 4, 0 }, { 6, 0 }, }, // Timestep 2 }; static const void *VARBLOCKS_BY_VAR[NUM_VARS] = { TEMP_DATA_FOR_DS2_AND_DS3, }; // Now, collect all this information into specification structs // File specification static const dataset_xml_spec_t XML_SPEC = { .group_name = "S3D", .buffer_size_mb = 128, .write_transport_method = "MPI", .ndim = NUM_DIMS, .nvar = NUM_VARS, .varnames = VARNAMES, .vartypes = VARTYPES, }; // Global space specification static const dataset_global_spec_t GLOBAL_SPEC = { .num_ts = NUM_TS, .num_pgs_per_ts = NUM_PGS_PER_TS, .global_dims = GLOBAL_DIMS, }; // Finally, invoke the dataset builder with this information build_dataset_from_varblocks_by_var( filename_prefix, transform_name, &XML_SPEC, &GLOBAL_SPEC, NUM_TS, NUM_PGS_PER_TS, NUM_DIMS, NUM_VARS, PG_DIMS, PG_OFFSETS, (const void **)VARBLOCKS_BY_VAR); } static void build_dataset_3(const char *filename_prefix, const char *transform_name) { // Basic dataset information // NOTE: we have to use an anonymous enum here to define these constants, since // C is picky and doesn't consider a static const int "const enough" to use // as an array length (e.g., if these were static const ints, it would not compile) enum { NUM_DIMS = 3, NUM_TS = 2, NUM_PGS_PER_TS = 8, NUM_VARS = 1, NUM_PGS = NUM_TS * NUM_PGS_PER_TS, }; // Variable names/types static const char *VARNAMES[NUM_VARS] = { "temp" }; static const enum ADIOS_DATATYPES VARTYPES[NUM_VARS] = { adios_real }; // Global and PG dimensions/offsets static const uint64_t GLOBAL_DIMS [NUM_DIMS] = { 4, 4, 4 }; static const uint64_t PG_DIMS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, }, // Timestep 1 { { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 }, }, // Timestep 2 }; static const uint64_t PG_OFFSETS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 0, 0, 0 }, { 0, 0, 2 }, { 0, 2, 0 }, { 0, 2, 2 }, { 2, 0, 0 }, { 2, 0, 2 }, { 2, 2, 0 }, { 2, 2, 2 }, }, // Timestep 1 { { 0, 0, 0 }, { 0, 0, 2 }, { 0, 2, 0 }, { 0, 2, 2 }, { 2, 0, 0 }, { 2, 0, 2 }, { 2, 2, 0 }, { 2, 2, 2 }, }, // Timestep 2 }; static const void *VARBLOCKS_BY_VAR[NUM_VARS] = { TEMP_DATA_FOR_DS2_AND_DS3, }; // Now, collect all this information into specification structs // File specification static const dataset_xml_spec_t XML_SPEC = { .group_name = "S3D", .buffer_size_mb = 128, .write_transport_method = "MPI", .ndim = NUM_DIMS, .nvar = NUM_VARS, .varnames = VARNAMES, .vartypes = VARTYPES, }; // Global space specification static const dataset_global_spec_t GLOBAL_SPEC = { .num_ts = NUM_TS, .num_pgs_per_ts = NUM_PGS_PER_TS, .global_dims = GLOBAL_DIMS, }; // Finally, invoke the dataset builder with this information build_dataset_from_varblocks_by_var( filename_prefix, transform_name, &XML_SPEC, &GLOBAL_SPEC, NUM_TS, NUM_PGS_PER_TS, NUM_DIMS, NUM_VARS, PG_DIMS, PG_OFFSETS, (const void **)VARBLOCKS_BY_VAR); } static void build_dataset_particle(const char *filename_prefix, const char *transform_name) { // Basic dataset information // NOTE: we have to use an anonymous enum here to define these constants, since // C is picky and doesn't consider a static const int "const enough" to use // as an array length (e.g., if these were static const ints, it would not compile) enum { NUM_DIMS = 2, NUM_TS = 2, NUM_PGS_PER_TS = 2, NUM_VARS = 1, NUM_PGS = NUM_TS * NUM_PGS_PER_TS, }; // Variable names/types static const char *VARNAMES[NUM_VARS] = { "temp" }; static const enum ADIOS_DATATYPES VARTYPES[NUM_VARS] = { adios_real }; // Global and PG dimensions/offsets static const uint64_t GLOBAL_DIMS [NUM_DIMS] = { 3, 64 }; static const uint64_t PG_DIMS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 3, 32 }, { 3, 32 } }, { { 3, 32 }, { 3, 32 } } }; static const uint64_t PG_OFFSETS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 0, 0 }, { 0, 32 }, }, { { 0, 0 }, { 0, 32 }, }, }; // Variable data (we can use [TS][PG][96] here because every PG is the same size, 96) static const float TEMP_DATA[NUM_TS][NUM_PGS_PER_TS][96] = { // Timestep 1 // PG 0 in timestep 1 -10.033470, 10.329965, -10.690636, 10.422486, -10.206265, 10.250129, -10.636559, 10.863623, -10.301656, 10.024924, -10.364993, 10.765381, -10.317861, 10.135729, -10.106746, 10.760672, -10.081673, 10.550956, -10.564651, 10.743271, -10.981760, 10.218850, -10.454396, 10.518654, -10.573842, 10.555231, -10.728546, 10.628874, -10.796128, 10.583715, -10.274767, 10.829598, -10.913680, 10.965403, -10.252085, 10.119946, -10.215530, 10.888643, -10.983567, 10.517186, -10.913568, 10.348560, -10.282567, 10.231427, -10.484288, 10.389313, -10.992099, 10.565961, -10.940269, 10.556751, -10.309232, 10.922029, -10.775600, 10.763627, -10.440682, 10.349442, -10.318858, 10.169230, -10.978316, 10.114986, -10.752945, 10.253083, -10.944585, 10.666625, -100.033470, 100.329964, -100.690636, 100.422485, -100.206268, 100.250130, -100.636559, 100.863625, -100.301659, 100.024925, -100.364990, 100.765381, -100.317863, 100.135727, -100.106743, 100.760674, -100.081673, 100.550957, -100.564651, 100.743271, -100.981758, 100.218849, -100.454399, 100.518654, -100.573845, 100.555229, -100.728546, 100.628876, -100.796127, 100.583717, -100.274765, 100.829597, // PG 1 in timestep 1 -100.913681, 100.965401, -100.252083, 100.119942, -100.215530, 100.888641, -100.983566, 100.517189, -100.913567, 100.348557, -100.282570, 100.231430, -100.484291, 100.389313, -100.992096, 100.565964, -100.940269, 100.556747, -100.309235, 100.922028, -100.775604, 100.763626, -100.440681, 100.349442, -100.318855, 100.169228, -100.978317, 100.114990, -100.752945, 100.253082, -100.944588, 100.666626, -1000.033447, 1000.329956, -1000.690613, 1000.422485, -1000.206238, 1000.250122, -1000.636536, 1000.863647, -1000.301636, 1000.024902, -1000.364990, 1000.765381, -1000.317871, 1000.135742, -1000.106750, 1000.760681, -1000.081665, 1000.550964, -1000.564636, 1000.743286, -1000.981750, 1000.218872, -1000.454407, 1000.518677, -1000.573853, 1000.555237, -1000.728577, 1000.628845, -1000.796143, 1000.583740, -1000.274780, 1000.829590, -1000.913696, 1000.965393, -1000.252075, 1000.119934, -1000.215515, 1000.888672, -1000.983582, 1000.517212, -1000.913574, 1000.348572, -1000.282593, 1000.231445, -1000.484314, 1000.389282, -1000.992126, 1000.565979, -1000.940247, 1000.556763, -1000.309204, 1000.922058, -1000.775574, 1000.763611, -1000.440674, 1000.349426, -1000.318848, 1000.169250, -1000.978333, 1000.114990, -1000.752930, 1000.253113, -1000.944580, 1000.666626, // Timestep 2 // PG 0 in timestep 2 -10.218485, 10.196670, -10.786571, 10.434015, -10.085313, 10.770138, -10.951201, 10.998879, -10.118698, 10.233769, -10.230308, 10.602986, -10.623081, 10.222406, -10.168947, 10.563350, -10.779158, 10.478179, -10.485379, 10.554758, -10.241806, 10.926062, -10.904201, 10.560665, -10.095291, 10.882517, -10.675652, 10.848236, -10.135600, 10.620235, -10.514861, 10.354085, -10.816905, 10.301431, -10.788100, 10.902218, -10.071568, 10.739302, -10.901097, 10.190267, -10.973071, 10.131405, -10.793253, 10.596152, -10.353811, 10.962200, -10.159503, 10.132969, -10.440379, 10.644882, -10.687727, 10.682186, -10.570944, 10.591928, -10.242850, 10.666235, -10.474444, 10.918502, -10.514470, 10.610044, -10.538737, 10.029331, -10.964128, 10.355642, -100.218483, 100.196671, -100.786568, 100.434013, -100.085312, 100.770134, -100.951202, 100.998878, -100.118698, 100.233772, -100.230309, 100.602989, -100.623085, 100.222404, -100.168945, 100.563347, -100.779160, 100.478180, -100.485382, 100.554756, -100.241806, 100.926064, -100.904198, 100.560661, -100.095291, 100.882515, -100.675652, 100.848236, -100.135597, 100.620239, -100.514862, 100.354088, // PG 1 in timestep 2 -100.816902, 100.301430, -100.788101, 100.902214, -100.071571, 100.739304, -100.901100, 100.190269, -100.973068, 100.131409, -100.793251, 100.596153, -100.353813, 100.962204, -100.159500, 100.132965, -100.440376, 100.644882, -100.687729, 100.682182, -100.570946, 100.591927, -100.242851, 100.666237, -100.474442, 100.918503, -100.514473, 100.610046, -100.538734, 100.029327, -100.964127, 100.355644, -1000.218506, 1000.196655, -1000.786560, 1000.434021, -1000.085327, 1000.770142, -1000.951172, 1000.998901, -1000.118713, 1000.233765, -1000.230286, 1000.602966, -1000.623108, 1000.222412, -1000.168945, 1000.563354, -1000.779175, 1000.478149, -1000.485352, 1000.554749, -1000.241821, 1000.926086, -1000.904175, 1000.560669, -1000.095276, 1000.882507, -1000.675659, 1000.848206, -1000.135620, 1000.620239, -1000.514832, 1000.354065, -1000.816895, 1000.301453, -1000.788086, 1000.902222, -1000.071594, 1000.739319, -1000.901123, 1000.190247, -1000.973083, 1000.131409, -1000.793274, 1000.596130, -1000.353821, 1000.962219, -1000.159485, 1000.132996, -1000.440369, 1000.644897, -1000.687744, 1000.682190, -1000.570923, 1000.591919, -1000.242859, 1000.666260, -1000.474426, 1000.918518, -1000.514465, 1000.610046, -1000.538757, 1000.029358, -1000.964111, 1000.355652, }; static const void *VARBLOCKS_BY_VAR[NUM_VARS] = { TEMP_DATA }; // Now, collect all this information into specification structs // File specification static const dataset_xml_spec_t XML_SPEC = { .group_name = "S3D", .buffer_size_mb = 128, .write_transport_method = "MPI", .ndim = NUM_DIMS, .nvar = NUM_VARS, .varnames = VARNAMES, .vartypes = VARTYPES, }; // Global space specification static const dataset_global_spec_t GLOBAL_SPEC = { .num_ts = NUM_TS, .num_pgs_per_ts = NUM_PGS_PER_TS, .global_dims = GLOBAL_DIMS, }; // Finally, invoke the dataset builder with this information build_dataset_from_varblocks_by_var( filename_prefix, transform_name, &XML_SPEC, &GLOBAL_SPEC, NUM_TS, NUM_PGS_PER_TS, NUM_DIMS, NUM_VARS, PG_DIMS, PG_OFFSETS, (const void **)VARBLOCKS_BY_VAR); } static void build_dataset_unevenpg(const char *filename_prefix, const char *transform_name) { // Copied with only pg dim and offset modification from ds2 // Basic dataset information // NOTE: we have to use an anonymous enum here to define these constants, since // C is picky and doesn't consider a static const int "const enough" to use // as an array length (e.g., if these were static const ints, it would not compile) enum { NUM_DIMS = 2, NUM_TS = 2, NUM_PGS_PER_TS = 4, NUM_VARS = 1, NUM_PGS = NUM_TS * NUM_PGS_PER_TS, }; // Variable names/types static const char *VARNAMES[NUM_VARS] = { "temp" }; static const enum ADIOS_DATATYPES VARTYPES[NUM_VARS] = { adios_real }; // Global and PG dimensions/offsets static const uint64_t GLOBAL_DIMS [NUM_DIMS] = { 8, 8 }; static const uint64_t PG_DIMS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 2, 8 }, { 2, 8 }, { 2, 8 }, { 2, 8 }, }, // Timestep 1 { { 8, 2 }, { 8, 2 }, { 8, 2 }, { 8, 2 }, }, // Timestep 2 }; static const uint64_t PG_OFFSETS [NUM_TS][NUM_PGS_PER_TS][NUM_DIMS] = { { { 0, 0 }, { 2, 0 }, { 4, 0 }, { 6, 0 }, }, // Timestep 1 { { 0, 0 }, { 0, 2 }, { 0, 4 }, { 0, 6 }, }, // Timestep 2 }; static const void *VARBLOCKS_BY_VAR[NUM_VARS] = { TEMP_DATA_FOR_DS2_AND_DS3, }; // Now, collect all this information into specification structs // File specification static const dataset_xml_spec_t XML_SPEC = { .group_name = "S3D", .buffer_size_mb = 128, .write_transport_method = "MPI", .ndim = NUM_DIMS, .nvar = NUM_VARS, .varnames = VARNAMES, .vartypes = VARTYPES, }; // Global space specification static const dataset_global_spec_t GLOBAL_SPEC = { .num_ts = NUM_TS, .num_pgs_per_ts = NUM_PGS_PER_TS, .global_dims = GLOBAL_DIMS, }; // Finally, invoke the dataset builder with this information build_dataset_from_varblocks_by_var( filename_prefix, transform_name, &XML_SPEC, &GLOBAL_SPEC, NUM_TS, NUM_PGS_PER_TS, NUM_DIMS, NUM_VARS, PG_DIMS, PG_OFFSETS, (const void **)VARBLOCKS_BY_VAR); } static void usage_and_exit() { int i; fprintf(stderr, "Usage: build_standard_dataset <dataset-id> <filename-prefix> [<transform-type>]\n"); fprintf(stderr, "\n"); fprintf(stderr, " dataset-id: the ID of a standard dataset packaged in this executable:\n"); fprintf(stderr, " - 'DS1': 1 variable, 2D array of floats\n"); fprintf(stderr, "\n"); fprintf(stderr, " filename-prefix: the filename prefix for the XML and BP files to be generated.\n"); fprintf(stderr, " - Example: filename-prefix = 'some/path/myfile':\n"); fprintf(stderr, " -> produces some/path/myfile.xml, some/path/myfile.bp:\n"); fprintf(stderr, "\n"); fprintf(stderr, " transform-type: the data transform to apply (default: none). May include\n"); fprintf(stderr, " transform parameters, just like in an ADIOS XML file."); fprintf(stderr, "\n"); fprintf(stderr, "Available datasets:\n"); for (i = 0; i < NUM_DATASETS; ++i) fprintf(stderr, "- \"%s\": %s\n", DATASETS[i].name, DATASETS[i].desc); exit(1); } int main(int argc, char **argv) { if (argc < 3 || argc > 4) usage_and_exit(); const char *dataset_id = argv[1]; const char *path = argv[2]; const char *transform_name = (argc >= 4) ? argv[3] : "none"; int i; const dataset_info_t *dataset = NULL; for (i = 0; i < NUM_DATASETS; ++i) if (strcasecmp(dataset_id, DATASETS[i].name) == 0) dataset = &DATASETS[i]; if (dataset == NULL) { fprintf(stderr, "Error: '%s' does not name a dataset packaged in this executable\n", dataset_id); usage_and_exit(); } MPI_Init(&argc, &argv); // Invoke the builder function for the selected dataset (*dataset->builder_fn)(path, transform_name); MPI_Finalize(); return 0; }
int main(int argc, char** argv) { int64 counter=0; if (argc < 2) { usage_and_exit(); } const char* config_url = argv[1]; struct sconfig* config=sconfig_read(config_url); // this is the beginning of the table struct lensum_hash* hash = NULL; struct lensum* lensum = lensum_new(config->nbin); struct lensum* lensum_tot = lensum_new(config->nbin); while (lensum_read(stdin, lensum)) { counter++; if (counter == 1) { wlog("first lensum: %ld %ld %.8g %ld\n", lensum->index, lensum->zindex, lensum->weight, lensum->totpairs); } if ((counter % 10000) == 0) { wlog("."); } if (((counter+1) % 1000000) == 0) { wlog("\n"); comma_print(stderr,counter+1); wlog("\n"); } struct lensum_hash* this_lens = find_lens(hash, lensum->zindex); if (this_lens == NULL) { // copy of lensum made inside struct lensum_hash* lh = lensum_hash_fromlensum(lensum); // this gets expanded to lh->lensum->zindex HASH_ADD_INT64(hash, lensum->zindex, lh); } else { lensum_add(this_lens->lensum, lensum); } lensum_add(lensum_tot, lensum); } wlog("\nlast lensum: %ld %ld %.8g %ld\n", lensum->index, lensum->zindex, lensum->weight, lensum->totpairs); wlog("Read a total of %ld\n", counter); // this is the summary lensum_print(lensum_tot); wlog("Writing results to stdout\n"); struct lensum_hash *tlensum=NULL; for(tlensum=hash; tlensum != NULL; tlensum=tlensum->hh.next) { lensum_write(tlensum->lensum, stdout); } wlog("Done\n"); return 0; }
int main (int argc, char **argv) { rcComm_t *conn = NULL; rodsEnv irods_env; rErrMsg_t err_msg; dataObjInp_t data_obj; openedDataObjInp_t open_obj; int open_fd; char *new_host = NULL; int status; char *obj_name = NULL; char *buffer; char prog_name[255]; size_t buf_size = DEFAULT_BUFFER_SIZE; int verbose = 0; int opt; unsigned long total_written = 0; int write_to_irods = 1; int server_set = 0; while ((opt = getopt(argc, argv, "b:vhrdw")) != -1) { switch (opt) { case 'b': buf_size = atoi(optarg); if (buf_size <= 0) { error_and_exit(conn, "Error: buffer size must be greater than 0.\n"); } break; case 'v': verbose = 1; break; case 'r': write_to_irods = 0; break; case 'w': // dummy write option to be enforced later break; case 'd': server_set = 1; break; case 'h': usage_and_exit(argv[0], EXIT_SUCCESS); break; default: usage_and_exit(argv[0], EXIT_FAILURE); break; } } if (optind >= argc) { fprintf(stderr, "Error: Missing iRODS file.\n"); usage_and_exit(argv[0], EXIT_FAILURE); } obj_name = argv[optind]; if ((buffer = malloc(buf_size)) == NULL) { error_and_exit(conn, "Error: unable to set buffer to size %ld\n", buf_size); } // set the client name so iRODS knows what program is connecting to it sprintf(prog_name, "%s:%s", PACKAGE_NAME, PACKAGE_VERSION); if (verbose) { fprintf(stderr, "Setting client name to: %s\n", prog_name); } setenv(SP_OPTION, prog_name, 1); // lets get the irods environment if ((status = getRodsEnv(&irods_env)) < 0) { error_and_exit(conn, "Error: getRodsEnv failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } if ((status = irods_uri_check(obj_name, &irods_env, verbose)) < 0) { error_and_exit(conn, "Error: invalid uri: %s\n", obj_name); } else if (status > 0) { server_set = 1; } if (verbose) { fprintf(stderr, "host %s\nzone %s\nuser %s\nport %d\n", irods_env.rodsHost, irods_env.rodsZone, irods_env.rodsUserName, irods_env.rodsPort); } #if IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4001008 init_client_api_table(); #endif // make the irods connections conn = rcConnect(irods_env.rodsHost, irods_env.rodsPort, irods_env.rodsUserName, irods_env.rodsZone, 0, &err_msg); if (!conn) { print_irods_error("Error: rcConnect failed:", &err_msg); exit(EXIT_FAILURE); } #if IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4001008 status = clientLogin(conn, "", ""); #else status = clientLogin(conn); #endif if (status < 0) { error_and_exit(conn, "Error: clientLogin failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } // set up the data object memset(&data_obj, 0, sizeof(data_obj)); strncpy(data_obj.objPath, obj_name, MAX_NAME_LEN); if (write_to_irods) { data_obj.openFlags = O_WRONLY; } else { data_obj.openFlags = O_RDONLY; } data_obj.dataSize = 0; // talk to server if (write_to_irods) { if (!server_set) { if ((status = rcGetHostForPut(conn, &data_obj, &new_host)) < 0) { error_and_exit(conn, "Error: rcGetHostForPut failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } choose_server(&conn, new_host, &irods_env, verbose); free(new_host); } if ((open_fd = rcDataObjCreate(conn, &data_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjCreate failed with status %d:%s\n", open_fd, get_irods_error_name(open_fd, verbose)); } } else { if (!server_set) { if ((status = rcGetHostForGet(conn, &data_obj, &new_host)) < 0) { error_and_exit(conn, "Error: rcGetHostForGet failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } choose_server(&conn, new_host, &irods_env, verbose); free(new_host); } if ((open_fd = rcDataObjOpen(conn, &data_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjOpen failed with status %d:%s\n", open_fd, get_irods_error_name(open_fd, verbose)); } } // the read/write loop while (1) { bytesBuf_t data_buffer; long read_in; long written_out; // set up common data elements memset(&open_obj, 0, sizeof(open_obj)); open_obj.l1descInx = open_fd; data_buffer.buf = buffer; // time to read something if (write_to_irods) { read_in = fread(buffer, 1, buf_size, stdin); open_obj.len = read_in; data_buffer.len = open_obj.len; } else { open_obj.len = buf_size; data_buffer.len = open_obj.len; if ((read_in = rcDataObjRead(conn, &open_obj, &data_buffer)) < 0) { error_and_exit(conn, "Error: rcDataObjRead failed with status %ld:%s\n", read_in, get_irods_error_name(read_in, verbose)); } } if (verbose) { fprintf(stderr, "%ld bytes read\n", read_in); } if (!read_in) break; // now try and write something if (write_to_irods) { open_obj.len = read_in; data_buffer.len = open_obj.len; if ((written_out = rcDataObjWrite(conn, &open_obj, &data_buffer)) < 0) { error_and_exit(conn, "Error: rcDataObjWrite failed with status %ld\n", written_out, get_irods_error_name(written_out, verbose)); } } else { written_out = fwrite(buffer, 1, read_in, stdout); } if (verbose) { fprintf(stderr, "%ld bytes written\n", written_out); } total_written += written_out; if (read_in != written_out) { error_and_exit(conn, "Error: write fail %ld written, should be %ld.\n", written_out, read_in); } }; if (verbose) { fprintf(stderr, "Total bytes written %ld\n", total_written); } if ((status = rcDataObjClose(conn, &open_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjClose failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } rcDisconnect(conn); free(buffer); exit(EXIT_SUCCESS); }