/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs; nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); if (SUBJECTS_DIR == NULL) { printf("ERROR: SUBJECTS_DIR not defined in environment\n"); exit(1); } return 0; }
int ft_printf(char const *format, ...) { int tab[2]; va_list ap; char *c; t_specs opt; init_tab2(tab); c = ft_strdup(format); va_start(ap, format); while (c[tab[0]]) { if (c[tab[0]] == '{' && verif_colour(c, tab[0])) c = treat_colours(c, &tab[0]); else if (c[tab[0]] == '%') { opt = check_options(ap, format, &tab[0]); if (c[tab[0]] == 'n') treat_n(ap, &tab[0], tab[1]); else tab[1] += ft_option_printf(ap, c, &tab[0], opt); } else ft_printf2(c, &tab[0], &tab[1]); } va_end(ap); return (tab[1]); }
int check_format(const char *format) { t_struct form; int i; i = 0; init_struct(&form); while ((check_options(format[i], &form)) == 1) i++; while ((check_minimal_large(format[i], &form)) == 1) i++; if (format[i] == '.') { form.prec = 0; while ((check_precision(format[++i], &form)) == 1) continue; } while (format[i] == 'h' || format[i] == 'l' || format[i] == 'j' || format[i] == 'z') { check_size_modifier(format + i, &form); i++; if ((&form)->hh > 0 || (&form)->ll > 0) i++; } check_type(format[i]) == 1 ? (&form)->type = format[i] : 0; return (check_block(ft_strsub(format, 0, i + 1), &form)); }
/** * Tell a hardware driver to scan for devices. * * In addition to the detection, the devices that are found are also * initialized automatically. On some devices, this involves a firmware upload, * or other such measures. * * The order in which the system is scanned for devices is not specified. The * caller should not assume or rely on any specific order. * * Before calling sr_driver_scan(), the user must have previously initialized * the driver by calling sr_driver_init(). * * @param driver The driver that should scan. This must be a pointer to one of * the entries returned by sr_driver_list(). Must not be NULL. * @param options A list of 'struct sr_hwopt' options to pass to the driver's * scanner. Can be NULL/empty. * * @return A GSList * of 'struct sr_dev_inst', or NULL if no devices were * found (or errors were encountered). This list must be freed by the * caller using g_slist_free(), but without freeing the data pointed * to in the list. * * @since 0.2.0 */ SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options) { GSList *l; if (!driver) { sr_err("Invalid driver, can't scan for devices."); return NULL; } if (!driver->context) { sr_err("Driver not initialized, can't scan for devices."); return NULL; } if (options) { if (check_options(driver, options, SR_CONF_SCAN_OPTIONS, NULL, NULL) != SR_OK) return NULL; } l = driver->scan(driver, options); sr_spew("Scan of '%s' found %d devices.", driver->name, g_slist_length(l)); return l; }
int main(int argc, char *argv[]) { char *filename, *outputDir; wlImages cursors; /* Process options and reset argument pointer */ check_options(argc, argv); argc -= optind; argv += optind; /* Terminate if wrong number of parameters are specified */ if (argc != 2) die("Wrong number of parameters.\nUse --help to show syntax.\n"); /* Process parameters */ filename = argv[0]; outputDir = argv[1]; /* Read the pic file */ cursors = wlCursorsReadFile(filename); if (!cursors) { die("Unable to read cursors from %s: %s\n", filename, strerror(errno)); } /* Write the PNG files */ writePngs(outputDir, cursors); /* Free resources */ wlImagesFree(cursors); /* Success */ return 0; }
int main(int argc, char **argv) { t_lman *a; t_lman *b; t_lman *retain; t_options *options; int arg; arg = 1; if (argc < 2) ft_error(); else { options_initializer(&options); lman_initialiser(&a); lman_initialiser(&b); lman_initialiser(&retain); arg += check_options(argv, &options); list_maker(argc, argv, &a, arg); if (sort_checker(&a) == 1) return (0); solve(&a, &b, &retain); final_print(&options, &a, &retain); } return (0); }
int builtin_echo(t_list *list, char **cmd) { t_echo *echo; char *printable; int i; (void)list; if ((echo = init_echo()) == NULL) return (FAILURE); i = 0; while (cmd[++i]) { if (echo->check_flags == 1 && strlen(cmd[i]) >= 1 && cmd[i][0] == '-') check_options(echo, cmd[i]) ? (echo->i = i) : (echo->i = i); else { echo->check_flags = 0; if ((printable = preparsing_echo(echo, cmd)) != NULL) { echo_print(echo, printable); xfree(printable); } break; } } echo->flag_n == 0 ? write(1, "\n", 1) : 0; return (SUCCESS); }
int main(int argc, char **argv){ int ie = 0; float itr_f = 0; int itr_i = 0; struct options *opt; opt = alloc_options(); init_options(opt); get_options(argc-1, argv+1, opt); if((*opt).help == 1){ help(); ie = 1; } if((*opt).stat == 1){ status(); ie = 1; } if((*opt).check == 1){ check_options(opt); ie = 1; } if(ie > 0){ exit(0); } itr_f = 1 / ((*opt).on + (*opt).off); itr_i = (int)itr_f; printf("%d\n",itr_i); return(0); }
void init_parse_options(int argc, char **argv) { /* TODO: sort these to match declaration of __fehoptions */ /* For setting the command hint on X windows */ cmdargc = argc; cmdargv = argv; /* Set default options */ memset(&opt, 0, sizeof(fehoptions)); opt.display = 1; opt.aspect = 1; opt.slideshow_delay = 0.0; opt.magick_timeout = -1; opt.thumb_w = 60; opt.thumb_h = 60; opt.thumb_redraw = 10; opt.menu_font = estrdup(DEFAULT_MENU_FONT); opt.font = NULL; opt.menu_bg = estrdup(PREFIX "/share/feh/images/menubg_default.png"); opt.max_height = opt.max_width = UINT_MAX; opt.start_list_at = NULL; opt.jump_on_resort = 1; opt.screen_clip = 1; #ifdef HAVE_LIBXINERAMA /* if we're using xinerama, then enable it by default */ opt.xinerama = 1; #endif /* HAVE_LIBXINERAMA */ feh_getopt_theme(argc, argv); D(("About to check for theme configuration\n")); feh_check_theme_options(argv); D(("About to parse commandline options\n")); /* Parse the cmdline args */ feh_parse_option_array(argc, argv, 1); /* If we have a filelist to read, do it now */ if (opt.filelistfile) { /* joining two reverse-sorted lists in this manner works nicely for us here, as files specified on the commandline end up at the *end* of the combined filelist, in the specified order. */ D(("About to load filelist from file\n")); filelist = gib_list_cat(filelist, feh_read_filelist(opt.filelistfile)); } D(("Options parsed\n")); filelist_len = gib_list_length(filelist); if (!filelist_len) show_mini_usage(); check_options(); feh_prepare_filelist(); return; }
int main(int argc, char *argv[]) { char *source, *dest; wlImage pic; /* Process options and reset argument pointer */ check_options(argc, argv); argc -= optind; argv += optind; /* Terminate if wrong number of parameters are specified */ if (argc != 2) die("Wrong number of parameters.\nUse --help to show syntax.\n"); /* Process parameters */ source = argv[0]; dest = argv[1]; /* Read the pic file */ pic = wlPicReadFile(source); if (!pic) { die("Unable to read PIC file %s: %s\n", source, strerror(errno)); } /* Write the PNG file */ writePng(dest, pic); /* Free resources */ wlImageFree(pic); /* Success */ return 0; }
int main(int argc, char **argv){ struct options *opt; int ie = 0; FILE *IN; int is_open = 0; int c; opt = alloc_options(); init_options(opt); get_options(argc-1, argv+1, opt); if(argc == 1){ (*opt).help = 1; } if((*opt).help == 1){ help(); ie = 1; } if((*opt).stat == 1){ status(); ie = 1; } if((*opt).check == 1){ check_options(opt); ie = 1; } if(ie == 1){ exit(0); } // open file if((IN = fopen((*opt).in,"r")) == NULL){ perror((*opt).in); exit(1); } is_open = 1; // main function c = 1; int DLM_ACC = 1; int R_COUNT = 0; int BRK_REMAIN = 0; while(c != EOF){ //while((c = fgetc(IN)) != EOF){ c = print_CHAR(IN,&DLM_ACC,&R_COUNT,&BRK_REMAIN,(*opt).war); } // close file if(is_open > 0){ fclose(IN); } // finish return(0); }
static int deal_options(char **options, int listsize, char **list) { int i; i = 1; while (i < listsize && tru_arg(list[i]) && isoption(list[i])) ft_strjoinfree(options, list[i++] + 1); check_options(*options); if (i < listsize && ft_strcmp(list[i], "--") == 0) i++; return (i); }
int main(int ac, char **av) { char board[8][8] = {{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}}; int i; solution *s = 0; options op; if (!check_options(ac, av, &op)) return 0; printf("\nFor a total of %d possibilities\n", op.brute_force ? put_queen_brute(1, board, 0, &s, &op) : put_queen(1, board, 0, &s, &op)); clear_list(&s); return 0; }
int main(int argc, char **argv){ struct options *opt; int ie = 0; FILE *IN; int c; int IN_BRK = 0; opt = alloc_options(); init_options(opt); get_options(argc-1, argv+1, opt); if(argc == 1){ (*opt).help = 1; } if((*opt).help == 1){ help(); ie = 1; } if((*opt).stat == 1){ status(); ie = 1; } if((*opt).check == 1){ check_options(opt); ie = 1; } if(ie == 1){ exit(0); } if((IN = fopen((*opt).fname, "r")) == NULL){ perror((*opt).fname); exit(1); } while((c = fgetc(IN)) != EOF){ //putc(c,stdout); if(c == (int)(*opt).brk_start){ IN_BRK++; }else if(c == (int)(*opt).brk_end){ IN_BRK--; }else{ ; } //printf("%d",IN_BRK); if((IN_BRK == 0) && (c == (int)(*opt).dlm)){ putc('\n',stdout); }else{ putc(c,stdout); } } fclose(IN); return(0); }
int split_for_main(int *opt, char **argv, int argc, char **params) { if (argc >= 1) { check_options(opt, argv); if (!opt[14]) ft_sort_ascii(params); if (opt[5] == -1) return (0); if (opt[3] == 1 && opt[4] == 0) ft_revtab(params); } return (1); }
/*------------------------------------------------------------------------- * Function: h5repack * * Purpose: locate all high-level HDF5 objects in the file * and compress/chunk them using options * * Algorithm: 2 traversals are made to the file; the 1st builds a list of * the objects, the 2nd makes a copy of them, using the options; * the reason for the 1st traversal is to check for invalid * object name requests * * Return: 0, ok, -1, fail * * Programmer: [email protected] * * Date: September, 22, 2003 * *------------------------------------------------------------------------- */ int h5repack(const char* infile, const char* outfile, pack_opt_t *options) { /* check input */ if (check_options(options) < 0) return -1; /* check for objects in input that are in the file */ if (check_objects(infile, options) < 0) return -1; /* copy the objects */ if (copy_objects(infile, outfile, options) < 0) return -1; return 0; }
int main(int argc, char **argv){ struct options *opt; opt = alloc_options(); init_options(opt); get_options(argc-1, argv+1, opt); if((*opt).help == 1){ help(); } if((*opt).stat == 1){ status(); } if((*opt).check == 1){ check_options(opt); } return(0); }
int main(int argc, char **argv){ struct options *opt; int ie = 0; FILE *FP; double re,im; complex **xtable; int i,j; opt = alloc_options(); init_options(opt); get_options(argc-1, argv+1, opt); if(argc == 1){ (*opt).help = 1; } if((*opt).help == 1){ help(); ie = 1; } if((*opt).stat == 1){ status(); ie = 1; } if((*opt).check == 1){ check_options(opt); ie = 1; } if(strlen((*opt).file) == 0){ ie = 1; } if(ie == 1){ exit(0); } /* main routine */ xtable = x_alloc_mat((*opt).nlines,(*opt).ntuples); FP = fopen((*opt).file,"r"); read_xtable_from_stream((*opt).nlines,(*opt).ntuples,FP,xtable); //fscanf(FP,"%lf%lf",&x); fclose(FP); //printf("%lf %lf\n",creal(x),cimag(x)); for(i=0;i<(*opt).nlines;i++){ for(j=0;j<(*opt).ntuples;j++){ printf(" %lf+%lfI",creal(xtable[i][j]),cimag(xtable[i][j])); } printf("\n"); } return(0); }
census_ht *census_ht_create(const census_ht_option *option) { int i; census_ht *ret = NULL; check_options(option); ret = (census_ht *)gpr_malloc(sizeof(census_ht)); ret->size = 0; ret->num_buckets = option->num_buckets; ret->buckets = (bucket *)gpr_malloc(sizeof(bucket) * ret->num_buckets); ret->options = *option; /* initialize each bucket */ for (i = 0; i < ret->options.num_buckets; i++) { ret->buckets[i].prev_non_empty_bucket = -1; ret->buckets[i].next_non_empty_bucket = -1; ret->buckets[i].next = NULL; } return ret; }
Program_Options::Program_Options(int argc, const char** argv) { try { app_name = fs::basename(argv[0]); main_desc = new_ptr<po::options_description>("Options"); new_desc = new_ptr<po::options_description>("Options"); build_desc = new_ptr<po::options_description>("Options"); command_container = new_ptr<Commands>( Commands { {"new" , new_desc}, {"build" , build_desc} }); init_main_description(); init_new_description(); init_build_description(); try { parsed = new_ptr<po::parsed_options>( po::command_line_parser(argc, argv). options(*main_desc). positional(pos_options). allow_unregistered(). run()); po::store(*parsed, vm); check_options(); } catch(boost::program_options::required_option& e) { throw Exception(LOW, e.what(), 2, __LINE__, fs::basename(__FILE__), __func__); } catch(boost::program_options::error& e) { throw Exception(LOW, e.what(), 2, __LINE__, fs::basename(__FILE__), __func__); } } catch(const Exception& e ) { if (e.get_level() == LOW) { cout << get_main_help() << endl ; } } }
int main(int argc, char *argv[]) { uint16_t filter_types[] = { SCAMPER_FILE_OBJ_TRACELB, SCAMPER_FILE_OBJ_TRACE, SCAMPER_FILE_OBJ_PING, SCAMPER_FILE_OBJ_DEALIAS, SCAMPER_FILE_OBJ_TBIT, SCAMPER_FILE_OBJ_NEIGHBOURDISC, SCAMPER_FILE_OBJ_STING, SCAMPER_FILE_OBJ_CYCLE_START, SCAMPER_FILE_OBJ_CYCLE_STOP, }; uint16_t filter_cnt = sizeof(filter_types)/sizeof(uint16_t); int rc; #if defined(DMALLOC) free(malloc(1)); #endif atexit(cleanup); if(check_options(argc, argv) == -1) { return -1; } if((filter = scamper_file_filter_alloc(filter_types, filter_cnt)) == NULL) { fprintf(stderr, "could not allocate filter\n"); return -1; } if(options & OPT_SORT) { rc = sort_cat(); } else { rc = simple_cat(); } return rc; }
/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs; char *surf1_fname ; char *surf2_fname ; char *out_fname ; MRI_SURFACE *mris1, *mris2 ; nargs = handle_version_option (argc, argv, vcid, "$Name: $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); if (SUBJECTS_DIR == NULL) { printf("ERROR: SUBJECTS_DIR not defined in environment\n"); exit(1); } surf1_fname = argv[0] ; surf2_fname = argv[1] ; out_fname = argv[2] ; mris1 = MRISread(surf1_fname) ; if (mris1 == NULL) ErrorExit(ERROR_NOFILE, "could not read surface 1 from %s", surf1_fname) ; mris2 = MRISread(surf2_fname) ; if (mris2 == NULL) ErrorExit(ERROR_NOFILE, "could not read surface 2 from %s", surf2_fname) ; compute_surface_distance(mris1, mris2, mris1) ; MRISwriteValues(mris1, out_fname) ; return 0; }
int main(int argc, char **argv) { int val = 0; set_global_debug_level_fc(&val); set_pseudo2d_domain_fc(&val); #ifdef HAVE_MPI MPI_Init(&argc, &argv); #endif #ifdef HAVE_PETSC PetscErrorCode ierr = PetscInitialize(&argc, &argv, NULL, PETSC_NULL); #endif check_options(); #ifdef HAVE_MPI MPI_Finalize(); #endif return 0; }
int parse_command_line(t_server *server, int ac, char *av[]) { char c; t_team *t; init_serv(server); while ((c = getopt(ac, av, "dp:x:y:c:t:n:")) != -1) { if (c == '?') return (EXIT_FAILURE); if (c == 'p' && listen_on_port(server, optarg, SOCK_STREAM)) return (EXIT_FAILURE); if (add_numbers(c, server, optarg)) return (EXIT_FAILURE); if (c == 'd') server->debug = 1; if (c == 'n' && (t = malloc(sizeof(t_team)))) add_team_names(t, server, ac, av); } return (check_options(server, ac, av)); }
int main(int argc, char **argv) { const struct cmd_struct *cmd; const char *bname; int ret; if ((bname = strrchr(argv[0], '/')) != NULL) bname++; else bname = argv[0]; if (!strcmp(bname, "btrfsck")) { argv[0] = "check"; } else { argc--; argv++; check_options(argc, argv); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { usage_command_group_short(&btrfs_cmd_group); exit(1); } } cmd = parse_command_token(argv[0], &btrfs_cmd_group); handle_help_options_next_level(cmd, argc, argv); crc32c_optimization_init(); fixup_argv0(argv, cmd->token); ret = cmd->fn(argc, argv); btrfs_close_all_devices(); exit(ret); }
int main(int argc, char *argv[]) { Net network = NULL; int flags = 0; output out = NULL; char * file_name = NULL; flags = check_options(argc, argv); network = read_data(file_name); out = out_new(); dinic(network, &out, flags); out_print(out,flags); out_destroy(out); net_destroy(network); return 0; }
int main( int argc, char **argv ) { NAImporterParms parms; GList *import_results; NAImporterResult *result; #if !GLIB_CHECK_VERSION( 2,36, 0 ) g_type_init(); #endif GOptionContext *context = init_options(); check_options( argc, argv, context ); NAPivot *pivot = na_pivot_new(); na_pivot_set_loadable( pivot, !PIVOT_LOAD_DISABLED & !PIVOT_LOAD_INVALID ); na_pivot_load_items( pivot ); parms.uris = g_slist_prepend( NULL, uri ); parms.check_fn = NULL; parms.check_fn_data = NULL; parms.preferred_mode = IMPORTER_MODE_ASK; parms.parent_toplevel = NULL; import_results = na_importer_import_from_uris( pivot, &parms ); result = import_results->data; if( result->imported ){ na_object_dump( result->imported ); g_object_unref( result->imported ); } na_core_utils_slist_dump( NULL, result->messages ); na_core_utils_slist_free( result->messages ); return( 0 ); }
int load_opts(char *filename) { FILE *in; char *line = NULL; int n; int err = 0; if((in = fopen(filename, "r")) == NULL) return -1; for(n = 1;!feof(in); n++) { line = getaline(in); if(feof(in)) break; if(line && *line) { opt_line_remove_comments(line); if(*line) err += opt_parse_line(line, n, filename) ? 1:0; } free(line); line = NULL; } free(line); /* post-initialization */ err += check_options(); if(!strcasecmp(opt_get_str(STR_PRESERVE_FIELDS), "standard")) init_standard_fields(); return err; }
/*---------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs, n, err; char tmpstr[2000], *signstr=NULL,*SUBJECTS_DIR, fname[2000]; //char *OutDir = NULL; RFS *rfs; int nSmoothsPrev, nSmoothsDelta; MRI *z, *zabs=NULL, *sig=NULL, *p=NULL; int FreeMask = 0; int nthSign, nthFWHM, nthThresh; double sigmax, zmax, threshadj, csize, csizeavg, searchspace,avgvtxarea; int csizen; int nClusters, cmax,rmax,smax; SURFCLUSTERSUM *SurfClustList; struct timeb mytimer; LABEL *clabel; FILE *fp, *fpLog=NULL; nargs = handle_version_option (argc, argv, vcid, "$Name: stable5 $"); if (nargs && argc - nargs == 1) exit (0); argc -= nargs; cmdline = argv2cmdline(argc,argv); uname(&uts); getcwd(cwd,2000); Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); dump_options(stdout); if(LogFile){ fpLog = fopen(LogFile,"w"); if(fpLog == NULL){ printf("ERROR: opening %s\n",LogFile); exit(1); } dump_options(fpLog); } if(SynthSeed < 0) SynthSeed = PDFtodSeed(); srand48(SynthSeed); SUBJECTS_DIR = getenv("SUBJECTS_DIR"); // Create output directory printf("Creating %s\n",OutTop); err = fio_mkdirp(OutTop,0777); if(err) exit(1); for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ if(SignList[nthSign] == 0) signstr = "abs"; if(SignList[nthSign] == +1) signstr = "pos"; if(SignList[nthSign] == -1) signstr = "neg"; sprintf(tmpstr,"%s/fwhm%02d/%s/th%02d", OutTop,(int)round(FWHMList[nthFWHM]), signstr,(int)round(10*ThreshList[nthThresh])); sprintf(fname,"%s/%s.csd",tmpstr,csdbase); if(fio_FileExistsReadable(fname)){ printf("ERROR: output file %s exists\n",fname); if(fpLog) fprintf(fpLog,"ERROR: output file %s exists\n",fname); exit(1); } err = fio_mkdirp(tmpstr,0777); if(err) exit(1); } } } // Load the target surface sprintf(tmpstr,"%s/%s/surf/%s.%s",SUBJECTS_DIR,subject,hemi,surfname); printf("Loading %s\n",tmpstr); surf = MRISread(tmpstr); if(!surf) return(1); // Handle masking if(LabelFile){ printf("Loading label file %s\n",LabelFile); sprintf(tmpstr,"%s/%s/label/%s.%s.label", SUBJECTS_DIR,subject,hemi,LabelFile); if(!fio_FileExistsReadable(tmpstr)){ printf(" Cannot find label file %s\n",tmpstr); sprintf(tmpstr,"%s",LabelFile); printf(" Trying label file %s\n",tmpstr); if(!fio_FileExistsReadable(tmpstr)){ printf(" ERROR: cannot read or find label file %s\n",LabelFile); exit(1); } } printf("Loading %s\n",tmpstr); clabel = LabelRead(NULL, tmpstr); mask = MRISlabel2Mask(surf, clabel, NULL); FreeMask = 1; } if(MaskFile){ printf("Loading %s\n",MaskFile); mask = MRIread(MaskFile); if(mask == NULL) exit(1); } if(mask && SaveMask){ sprintf(tmpstr,"%s/mask.mgh",OutTop); printf("Saving mask to %s\n",tmpstr); err = MRIwrite(mask,tmpstr); if(err) exit(1); } // Compute search space searchspace = 0; nmask = 0; for(n=0; n < surf->nvertices; n++){ if(mask && MRIgetVoxVal(mask,n,0,0,0) < 0.5) continue; searchspace += surf->vertices[n].area; nmask++; } printf("Found %d voxels in mask\n",nmask); if(surf->group_avg_surface_area > 0) searchspace *= (surf->group_avg_surface_area/surf->total_area); printf("search space %g mm2\n",searchspace); avgvtxarea = searchspace/nmask; printf("average vertex area %g mm2\n",avgvtxarea); // Determine how many iterations are needed for each FWHM nSmoothsList = (int *) calloc(sizeof(int),nFWHMList); for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ nSmoothsList[nthFWHM] = MRISfwhm2niters(FWHMList[nthFWHM], surf); printf("%2d %5.1f %4d\n",nthFWHM,FWHMList[nthFWHM],nSmoothsList[nthFWHM]); if(fpLog) fprintf(fpLog,"%2d %5.1f %4d\n",nthFWHM,FWHMList[nthFWHM],nSmoothsList[nthFWHM]); } printf("\n"); // Allocate the CSDs for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ csd = CSDalloc(); sprintf(csd->simtype,"%s","null-z"); sprintf(csd->anattype,"%s","surface"); sprintf(csd->subject,"%s",subject); sprintf(csd->hemi,"%s",hemi); sprintf(csd->contrast,"%s","NA"); csd->seed = SynthSeed; csd->nreps = nRepetitions; csd->thresh = ThreshList[nthThresh]; csd->threshsign = SignList[nthSign]; csd->nullfwhm = FWHMList[nthFWHM]; csd->varfwhm = -1; csd->searchspace = searchspace; CSDallocData(csd); csdList[nthFWHM][nthThresh][nthSign] = csd; } } } // Alloc the z map z = MRIallocSequence(surf->nvertices, 1,1, MRI_FLOAT, 1); // Set up the random field specification rfs = RFspecInit(SynthSeed,NULL); rfs->name = strcpyalloc("gaussian"); rfs->params[0] = 0; rfs->params[1] = 1; printf("Thresholds (%d): ",nThreshList); for(n=0; n < nThreshList; n++) printf("%5.2f ",ThreshList[n]); printf("\n"); printf("Signs (%d): ",nSignList); for(n=0; n < nSignList; n++) printf("%2d ",SignList[n]); printf("\n"); printf("FWHM (%d): ",nFWHMList); for(n=0; n < nFWHMList; n++) printf("%5.2f ",FWHMList[n]); printf("\n"); // Start the simulation loop printf("\n\nStarting Simulation over %d Repetitions\n",nRepetitions); if(fpLog) fprintf(fpLog,"\n\nStarting Simulation over %d Repetitions\n",nRepetitions); TimerStart(&mytimer) ; for(nthRep = 0; nthRep < nRepetitions; nthRep++){ msecTime = TimerStop(&mytimer) ; printf("%5d %7.1f ",nthRep,(msecTime/1000.0)/60); if(fpLog) { fprintf(fpLog,"%5d %7.1f ",nthRep,(msecTime/1000.0)/60); fflush(fpLog); } // Synthesize an unsmoothed z map RFsynth(z,rfs,mask); nSmoothsPrev = 0; // Loop through FWHMs for(nthFWHM=0; nthFWHM < nFWHMList; nthFWHM++){ printf("%d ",nthFWHM); if(fpLog) { fprintf(fpLog,"%d ",nthFWHM); fflush(fpLog); } nSmoothsDelta = nSmoothsList[nthFWHM] - nSmoothsPrev; nSmoothsPrev = nSmoothsList[nthFWHM]; // Incrementally smooth z MRISsmoothMRI(surf, z, nSmoothsDelta, mask, z); // smooth z // Rescale RFrescale(z,rfs,mask,z); // Slightly tortured way to get the right p-values because // RFstat2P() computes one-sided, but I handle sidedness // during thresholding. // First, use zabs to get a two-sided pval bet 0 and 0.5 zabs = MRIabs(z,zabs); p = RFstat2P(zabs,rfs,mask,0,p); // Next, mult pvals by 2 to get two-sided bet 0 and 1 MRIscalarMul(p,p,2.0); sig = MRIlog10(p,NULL,sig,1); // sig = -log10(p) for(nthThresh = 0; nthThresh < nThreshList; nthThresh++){ for(nthSign = 0; nthSign < nSignList; nthSign++){ csd = csdList[nthFWHM][nthThresh][nthSign]; // If test is not ABS then apply the sign if(csd->threshsign != 0) MRIsetSign(sig,z,0); // Get the max stats sigmax = MRIframeMax(sig,0,mask,csd->threshsign, &cmax,&rmax,&smax); zmax = MRIgetVoxVal(z,cmax,rmax,smax,0); if(csd->threshsign == 0){ zmax = fabs(zmax); sigmax = fabs(sigmax); } // Mask if(mask) MRImask(sig,mask,sig,0.0,0.0); // Surface clustering MRIScopyMRI(surf, sig, 0, "val"); if(csd->threshsign == 0) threshadj = csd->thresh; else threshadj = csd->thresh - log10(2.0); // one-sided test SurfClustList = sclustMapSurfClusters(surf,threshadj,-1,csd->threshsign, 0,&nClusters,NULL); // Actual area of cluster with max area csize = sclustMaxClusterArea(SurfClustList, nClusters); // Number of vertices of cluster with max number of vertices. // Note: this may be a different cluster from above! csizen = sclustMaxClusterCount(SurfClustList, nClusters); // Area of this cluster based on average vertex area. This just scales // the number of vertices. csizeavg = csizen * avgvtxarea; if(UseAvgVtxArea) csize = csizeavg; // Store results csd->nClusters[nthRep] = nClusters; csd->MaxClusterSize[nthRep] = csize; csd->MaxSig[nthRep] = sigmax; csd->MaxStat[nthRep] = zmax; } // Sign } // Thresh } // FWHM printf("\n"); if(fpLog) fprintf(fpLog,"\n"); if(SaveEachIter || fio_FileExistsReadable(SaveFile)) SaveOutput(); if(fio_FileExistsReadable(StopFile)) { printf("Found stop file %s\n",StopFile); goto finish; } } // Simulation Repetition finish: SaveOutput(); msecTime = TimerStop(&mytimer) ; printf("Total Sim Time %g min (%g per rep)\n", msecTime/(1000*60.0),(msecTime/(1000*60.0))/nthRep); if(fpLog) fprintf(fpLog,"Total Sim Time %g min (%g per rep)\n", msecTime/(1000*60.0),(msecTime/(1000*60.0))/nthRep); if(DoneFile){ fp = fopen(DoneFile,"w"); fprintf(fp,"%g\n",msecTime/(1000*60.0)); fclose(fp); } printf("mri_mcsim done\n"); if(fpLog){ fprintf(fpLog,"mri_mcsim done\n"); fclose(fpLog); } exit(0); }
void parse_command_line(int argc, const char* argv[], const char** fname1, const char** fname2, const char** objname1, const char** objname2, diff_opt_t* options) { int i; int opt; struct exclude_path_list *exclude_head, *exclude_prev, *exclude_node; /* process the command-line */ memset(options, 0, sizeof (diff_opt_t)); /* assume equal contents initially */ options->contents = 1; /* NaNs are handled by default */ options->do_nans = 1; /* init for exclude-path option */ exclude_head = NULL; /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { switch ((char)opt) { default: usage(); h5diff_exit(EXIT_FAILURE); case 'h': usage(); h5diff_exit(EXIT_SUCCESS); case 'V': print_version(h5tools_getprogname()); h5diff_exit(EXIT_SUCCESS); case 'v': options->m_verbose = 1; /* This for loop is for handling style like * -v, -v1, --verbose, --verbose=1. */ for (i = 1; i < argc; i++) { /* * short opt */ if (!strcmp (argv[i], "-v")) /* no arg */ { opt_ind--; options->m_verbose_level = 0; break; } else if (!strncmp (argv[i], "-v", (size_t)2)) { options->m_verbose_level = atoi(&argv[i][2]); break; } /* * long opt */ if (!strcmp (argv[i], "--verbose")) /* no arg */ { options->m_verbose_level = 0; break; } else if ( !strncmp (argv[i], "--verbose", (size_t)9) && argv[i][9]=='=') { options->m_verbose_level = atoi(&argv[i][10]); break; } } break; case 'q': /* use quiet mode; supress the message "0 differences found" */ options->m_quiet = 1; break; case 'r': options->m_report = 1; break; case 'l': options->follow_links = TRUE; break; case 'x': options->no_dangle_links = 1; break; case 'E': options->exclude_path = 1; /* create linked list of excluding objects */ if( (exclude_node = (struct exclude_path_list*) HDmalloc(sizeof(struct exclude_path_list))) == NULL) { printf("Error: lack of memory!\n"); h5diff_exit(EXIT_FAILURE); } /* init */ exclude_node->obj_path = (char*)opt_arg; exclude_node->obj_type = H5TRAV_TYPE_UNKNOWN; exclude_prev = exclude_head; if (NULL == exclude_head) { exclude_head = exclude_node; exclude_head->next = NULL; } else { while(NULL != exclude_prev->next) exclude_prev=exclude_prev->next; exclude_node->next = NULL; exclude_prev->next = exclude_node; } break; case 'd': options->d=1; if ( check_d_input( opt_arg )==-1) { printf("<-d %s> is not a valid option\n", opt_arg ); usage(); h5diff_exit(EXIT_FAILURE); } options->delta = atof( opt_arg ); /* -d 0 is the same as default */ if (options->delta == 0) options->d=0; break; case 'p': options->p=1; if ( check_p_input( opt_arg )==-1) { printf("<-p %s> is not a valid option\n", opt_arg ); usage(); h5diff_exit(EXIT_FAILURE); } options->percent = atof( opt_arg ); /* -p 0 is the same as default */ if (options->percent == 0) options->p = 0; break; case 'n': options->n=1; if ( check_n_input( opt_arg )==-1) { printf("<-n %s> is not a valid option\n", opt_arg ); usage(); h5diff_exit(EXIT_FAILURE); } options->count = atol( opt_arg ); break; case 'N': options->do_nans = 0; break; case 'c': options->m_list_not_cmp = 1; break; case 'e': options->use_system_epsilon = 1; break; } } /* check options */ check_options(options); /* if exclude-path option is used, keep the exclude path list */ if (options->exclude_path) options->exclude = exclude_head; /* check for file names to be processed */ if (argc <= opt_ind || argv[ opt_ind + 1 ] == NULL) { error_msg("missing file names\n"); usage(); h5diff_exit(EXIT_FAILURE); } *fname1 = argv[ opt_ind ]; *fname2 = argv[ opt_ind + 1 ]; *objname1 = argv[ opt_ind + 2 ]; if ( *objname1 == NULL ) { *objname2 = NULL; return; } if ( argv[ opt_ind + 3 ] != NULL) { *objname2 = argv[ opt_ind + 3 ]; } else { *objname2 = *objname1; } }