void show_editor() { parse_from_file(); editor_initialize(); flush_on_screen(); show_cursor(); }
GridMapData::GridMapData (SCM desc) { grid_width = -1; grid_height = -1; while (!gh_null_p (desc)) { SCM symbol = gh_caar(desc); SCM data = gh_cdar(desc); if (gh_equal_p (gh_symbol2scm ("file"), symbol)) { parse_from_file (data); } else { std::cout << "GridMapData: Unknown data type: '" << std::flush; gh_display (symbol); std::cout << "' with data: " << std::flush; gh_display (data); std::cout << std::endl; return; } desc = gh_cdr (desc); } }
int vbucket_config_parse(VBUCKET_CONFIG_HANDLE handle, vbucket_source_t data_source, const char *data) { if (data_source == LIBVBUCKET_SOURCE_FILE) { return parse_from_file(handle, data); } else { return parse_from_memory(handle, data); } }
int vbucket_config_parse2(VBUCKET_CONFIG_HANDLE handle, vbucket_source_t data_source, const char *data, const char *peername) { handle->localhost = peername; handle->nlocalhost = peername ? strlen(peername) : 0; if (data_source == LIBVBUCKET_SOURCE_FILE) { return parse_from_file(handle, data); } else { return parse_from_memory(handle, data); } }
int main(int an, char **ac) { struct xmlnode *scene, *hypervisor, *mmu, *map, *guest; char fn[128]; uint64_t i, j; if (an != 2) { fprintf(stderr, "ERROR: need build directory argument.\n"); return 1; } sprintf(fn, "%s/scenario_p_laidout.xml", ac[1]); scene = parse_from_file(fn, STRUCT_SCENARIO); if (!scene) { fprintf(stderr, "ERROR: could not load scenario: %s.\n", xml_errormsg); return 1; } // --------------------------------------------------------------------------- hypervisor = get_child(scene, STRUCT_HYPERVISOR); mmu = get_child(hypervisor, STRUCT_MMU); iterate_over_children(i, mmu, STRUCT_MAP, map) { if (strcmp(map->attrs[MAP_ATTR_XREF].value.string, "core_rx") == 0) { globals_window[0] = get_dict_hex(map->attrs + MAP_ATTR_BASE, 0); break; } } globals_window[1] = ~0UL; prepare_map(scene, mmu); layout_map_fixmaps(scene, mmu); layout_map(scene, mmu, -1); for (i = 0; i < hypervisor->attrs[HYPERVISOR_ATTR_NCPUS].value.number; i++) { struct range *Rclone = clone_range(map_range); layout_map(scene, mmu, i); map_range = Rclone; } map_range = NULL; iterate_over_children(i, scene, STRUCT_GUEST, guest) { mmu = get_child(guest, STRUCT_MMU); iterate_over_children(j, mmu, STRUCT_MAP, map) { if (!attr_exists(map->attrs + MAP_ATTR_BASE)) { fprintf(stderr, "ERROR: no dynamic placement for guests.\n"); return 1; } } }
/** * \brief Main entry of the program * \details The 2 variables \b argc and \b argv are used for extracting * command line parameters. * \param argc Number of arguments, at least one as \b argv contains at least the program's name. * \param argv[] Array of character strings containing the arguments. * \return On exit returns EXIT_SUCCESS, EXIT_FAILURE otherwise. */ int main(int argc, char** argv) { /* arguments parsing, we need at least "prog_name -i an_input_file" * prints some more instructions if needed */ if (argc < 3) { fprintf(stdout,"[Info] No input file ! \n"); help(argv); return EXIT_SUCCESS; } uint32_t i; char seed[128] = ""; char inpf[FILENAME_MAX] = ""; DATA dat ; SPDAT spdat = {5,5,0.5,NULL,0}; ATOM *at = NULL; // function pointers for energy and gradient, and trajectory get_ENER = NULL; get_DV = NULL; write_traj= &(write_dcd); // arguments parsing for (i=1; i<(uint32_t)argc; i++) { // get name of input file if (!strcasecmp(argv[i],"-i")) { sprintf(inpf,"%s",argv[++i]); } // get user specified seed, 128 characters max, keep it as a string for the moment else if (!strcasecmp(argv[i],"-seed")) { sprintf(seed,"%s",argv[++i]); } // reopen stdout to user specified file else if (!strcasecmp(argv[i],"-o")) { freopen(argv[++i],"w",stdout); is_stdout_redirected = 1 ; } // specify the logging level else if (!strcasecmp(argv[i],"-log")) { if (!strcasecmp(argv[++i],"no")) { LOG_SEVERITY = LOG_NOTHING; } else if (!strcasecmp(argv[i],"err")) { LOG_SEVERITY = LOG_ERROR; } else if (!strcasecmp(argv[i],"warn")) { LOG_SEVERITY = LOG_WARNING; } else if (!strcasecmp(argv[i],"info")) { LOG_SEVERITY = LOG_INFO; } else if (!strcasecmp(argv[i],"dbg")) { LOG_SEVERITY = LOG_DEBUG; } else fprintf(stdout,"[Warning] Unknown log level '%s' : default value used.\n\n",argv[i]); } #ifdef _OPENMP // if compiled with openMP the user can specify a maximum number of cpus to use // check if it is not higher than the real amount of cpus else if (!strcasecmp(argv[i],"-np")) { nthreads=atoi(argv[++i]); ncpus=omp_get_num_procs(); (nthreads < ncpus) ? omp_set_num_threads(nthreads) : omp_set_num_threads(ncpus); //omp_set_num_threads(nthreads); } #endif // print help and proper exit else if ( !strcasecmp(argv[i],"-h") || !strcasecmp(argv[i],"-help") || !strcasecmp(argv[i],"--help") ) { help(argv); return EXIT_SUCCESS; } // error if unknown command line option else { fprintf(stdout,"[Error] Argument '%s' is unknown.\n",argv[i]); help(argv); exit(-2); } } //prepare log files if necessary init_logfiles(); // Print date and some env. variables fprintf(stdout,"Welcome to %s ! Command line arguments succesfully parsed, now intialising parameters...\n\n",argv[0]); fprintf(stdout,"Logging level is : %s : see the documentation to see which .log files are generated, and what they contain.\n\n",get_loglevel_string()); fprintf(stdout,"Now printing some local informations : \n"); fprintf(stdout,"DATE : %s\n",get_time()); fprintf(stdout,"HOSTNAME : %s\n",getenv("HOSTNAME")); fprintf(stdout,"USER : %s\n",getenv("USER")); fprintf(stdout,"PWD : %s\n",getenv("PWD")); /* * Random numbers can be generated by using the standard functions from the C library (no guarantee on the quality) * or by using the dSFMT generator (default, extremely stable, no redudancy ) * if STDRAND is defined we use the C library. * * Random numbers are stored in a double array dat.rn, of size dat.nrn * * If no string seed was passed by command line we generate one by using the unix timestamp * -For STDRAND, this is directly used for srand() * -For dSFMT, an array of integers generated by using the string seed is sent to dsfmt_init_by_array * */ if (!strlen(seed)) sprintf(seed,"%d",(uint32_t)time(NULL)) ; LOG_PRINT(LOG_INFO,"seed = %s \n",seed); dat.nrn = 2048 ; dat.rn = calloc(dat.nrn,sizeof dat.rn); #ifdef STDRAND srand( (uint32_t)labs(atol(seed)) ); #else dat.seeds = calloc(strlen(seed),sizeof dat.seeds); for (i=0; i<(uint32_t)strlen(seed); i++) dat.seeds[i] = (uint32_t) seed[i] << 8; for (i=0; i<(uint32_t)strlen(seed); i++) dat.seeds[i] *= (dat.seeds[strlen(seed)-1]+i+1); dsfmt_init_by_array(&(dat.dsfmt),dat.seeds,(int32_t)strlen(seed)); for (i=0; i<(uint32_t)strlen(seed); i++) { LOG_PRINT(LOG_INFO,"dat.seeds[%d] = %d \n",strlen(seed)-1-i,dat.seeds[strlen(seed)-1-i]); } #endif // parse input file, initialise atom list parse_from_file(inpf,&dat,&spdat,&at); // set the pointer to the default V and dV functions if(get_ENER==NULL) get_ENER = &(get_LJ_V); if(get_DV==NULL) get_DV = &(get_LJ_DV); // allocate arrays used by energy minimisation function alloc_minim(&dat); // sum up parameters to output file #ifdef _OPENMP fprintf(stdout,"\nStarting program with %d threads (%d cpus available)\n\n",nthreads,ncpus); #else fprintf(stdout,"\nStarting program in sequential mode\n\n"); #endif fprintf(stdout,"Seed = %s \n\n",seed); if (get_ENER==&(get_LJ_V)) fprintf(stdout,"Using L-J potential\n"); else if (get_ENER==&(get_AZIZ_V)) fprintf(stdout,"Using Aziz potential\n"); #ifdef LUA_PLUGINS else if (get_ENER==&(get_lua_V)) fprintf(stdout,"Using plugin pair potential\n"); else if (get_ENER==&(get_lua_V_ffi)) fprintf(stdout,"Using plugin ffi potential\n"); #endif if (charmm_units) fprintf(stdout,"Using CHARMM units.\n\n"); else fprintf(stdout,"Using REDUCED units.\n\n"); fprintf(stdout,"Energy saved each %d steps in file %s\n",io.esave,io.etitle); fprintf(stdout,"Trajectory saved each %d steps in file %s\n",io.trsave,io.trajtitle); fprintf(stdout,"Initial configuration saved in file %s\n",io.crdtitle_first); fprintf(stdout,"Final configuration saved in file %s\n\n",io.crdtitle_last); // get values of best minima for several well known LJ clusters getValuesFromDB(&dat); // set the inverse temperature depending of the type of units used if (charmm_units) dat.beta = 1.0/(KBCH*dat.T); else dat.beta = 1.0/(dat.T); // again print parameters fprintf(stdout,"method = %s\n",dat.method); fprintf(stdout,"natom = %d\n",dat.natom); fprintf(stdout,"nsteps = %"PRIu64"\n",dat.nsteps); fprintf(stdout,"T = %lf \n",dat.T); fprintf(stdout,"beta = %lf\n",dat.beta); if(dat.d_max_when==0) fprintf(stdout,"dmax = %lf (fixed) \n\n",dat.d_max); else fprintf(stdout,"dmax = %4.2lf updated each %d steps for " "targeting %4.2lf %% of acceptance \n\n",dat.d_max,dat.d_max_when,dat.d_max_tgt); // then depending of the type of simulation run calculation if (strcasecmp(dat.method,"metrop")==0) { start_classic(&dat,at); } else if (strcasecmp(dat.method,"spav")==0) { start_spav(&dat,&spdat,at); } else { LOG_PRINT(LOG_ERROR,"Method [%s] unknowm.\n",dat.method); free(dat.rn); #ifndef STDRAND free(dat.seeds); #endif exit(-3); } #ifdef __unix__ // compatible with some unixes-like OS: the struct rusage communicates with the kernel directly. struct rusage infos_usage; getrusage(RUSAGE_SELF,&infos_usage); fprintf(stdout,"Maximum amount of memory used in kBytes is : %ld\n",infos_usage.ru_maxrss); fprintf(stdout,"Execution time in Seconds : %lf\n", (double)infos_usage.ru_utime.tv_sec+(double)infos_usage.ru_utime.tv_usec/1000000.0 + (double)infos_usage.ru_stime.tv_sec+(double)infos_usage.ru_stime.tv_usec/1000000.0 ); #endif fprintf(stdout,"End of program\n"); // free memory and exit properly free(dat.rn); #ifndef STDRAND free(dat.seeds); #endif free(at); dealloc_minim(); #ifdef LUA_PLUGINS end_lua(); #endif //LUA_PLUGINS // closing log files is the last thing to do as errors may occur at the end close_logfiles(); return EXIT_SUCCESS; }