/// The concentration parameter form a file. Note that the mass should be Mvir in h^{-1} Msun double cosmology::c_gen(double M, double z) { /// First initialize if not initialized if (!bool_gen){ init_gen(z); }else if(z!=z_gen){ init_gen(z); } /// Spline interpolate double xM=log10(M); double concen; if(xM<xMmin){ concen=cMmin+dymin*(xM-xMmin); }else{ if(xM>xMmax){ concen=cMmax+dymax*(xM-xMmax); }else{ concen=gsl_spline_eval(gen_spline,xM,gen_acc); } } //std::cout<<xM<<" "<<concen<<std::endl; return pow(10.,concen); }
OpWithSeq::OpWithSeq( int method, void *ptr_res, OpWithSeq *ch ) { // WRITE_... init_gen(); switch ( method ) { case STRING_add_NUM : type = WRITE_ADD; break; case STRING_init_NUM: type = WRITE_INIT; break; case STRING_reassign_NUM: type = WRITE_REASSIGN; break; case STRING___return___NUM: type = WRITE_RET; break; default: assert(0); } this->ptr_res = ptr_res; add_child( ch ); }
OpWithSeq::OpWithSeq( int method, const char *name, OpWithSeq *ch ) { // WRITE_... init_gen(); switch ( method ) { case STRING_add_NUM : type = WRITE_ADD; break; case STRING_init_NUM: type = WRITE_INIT; break; case STRING_reassign_NUM: type = WRITE_REASSIGN; break; case STRING___return___NUM: type = WRITE_RET; break; default: assert(0); } cpp_name_str = strdup( name ); add_child( ch ); }
int main(int argc, char* argv[]) { // initialize the environment SuifEnv* suif_env = new SuifEnv; suif_env->init(); init_gen(suif_env); // transform the input arguments into a stream of input tokens TokenStream token_stream(argc, argv); // execute the Module "gen" ModuleSubSystem* mSubSystem = suif_env->get_module_subsystem(); mSubSystem->execute("gen", &token_stream); delete suif_env; return 0; }
void run_code(void) { /* If no compile errors run the current code. */ if (!had_error && did_gen) { if (compile_only) { printf ("@r\n"); out_count = 0; } else execute (); } /* Reinitialize the code generation and machine. */ if (did_gen) init_gen(); else had_error = FALSE; }
int main(int argc, char* argv[]) { int randnum = 0; char* nvram = NULL, *value = NULL; char* delimiter = NULL, *tmp, *del; int position=0, c, i = 0, func = 0, val; char help_msg[2048] = "Usage: xobjconf [-s | -x <nvram variable>] {[-a | -m <values> -p <position>] | [ -n <to get # of digits>] | [-i <position>] | [-v <value>] | [-e <value>] | [ -r <position>] | [ -o <new delimiter>]} [-d delimiter]\n\n"; init_gen( ); strcat(help_msg, "xobjconf command summary\n"); strcat(help_msg, "\txobjconf is a function to insert/delete/modify/view nvram variable by delimiter(s).\n"); strcat(help_msg, "\t<nvram variable>:input a nvram variable.\n"); strcat(help_msg, "\tdelimiter:a delimiter which is a seperator.\n"); strcat(help_msg, "\t-s : to specify a nvram variable.\n"); strcat(help_msg, "\t-x : to get total counts of token by specified delimiter.\n"); strcat(help_msg, "\t-d : to specify a delimiter.\n"); strcat(help_msg, "\t-a:insert a value to the nvram variable by delimiter.\n"); strcat(help_msg, "\t-r : remove a value from a nvram variable by specfied position.\n"); strcat(help_msg, "\t-v : remove a value from a nvram variable by specfied value.\n"); strcat(help_msg, "\t-e : to check a value in a nvram variable is exist or not.\n"); strcat(help_msg, "\t-o : to replace delimiters in a token list by new delimiters.\n"); strcat(help_msg, "\t-n : to get digits in a nvram variable by speficied counts.\n"); strcat(help_msg, "\t-m : to change a value by spcified position from a nvram variable.\n"); strcat(help_msg, "\t-i : to return the value which is at the specified position from a nvram variable by delimiter.\n\n"); if(argc <= 1 || ((isgraph(*argv[1]) || ispunct(*argv[1])) && *argv[1]!='-')){ fprintf(stderr, "%s", help_msg); exit(0); } while ((c = getopt(argc, argv, "a:d:e:i:m:n:o:p:r:v:s:x:h")) != -1){ switch (c) { case 'a': func = 1; value = optarg; break; case 'r': func = 2; position = atoi(optarg); break; case 'm': func = 3; value = optarg; break; case 's': nvram = optarg; break; case 'i': func = 4; position = atoi(optarg); break; case 'v': func = 5; value = optarg; position = 1; break; case 'x': func = 6; nvram = optarg; break; case 'e': func = 7; value = optarg; position = 1; break; case 'n': func = 8; val = atoi(optarg); position = 1; break; case 'o': func = 9; value = optarg; break; case 'p': position = atoi(optarg); break; case 'd': delimiter = optarg; break; case 'h': fprintf(stderr, "%s", help_msg); exit(0); break; default: fprintf(stderr, "%s", help_msg); exit(0); break; } } if(nvram_get(nvram) == NULL && delimiter != NULL && nvram != NULL){ if(func == 1 && value != NULL){ nvram_set(nvram, ""); //printf("Inserting '%s' at position 1 ...\n", value); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //tmp = StrDup(insert_str(nvram_get(nvram), value, delimiter, 1)); //nvram_set(nvram, value); nvram_set(nvram, StrDup(insert_str(nvram_get(nvram), value, delimiter, 1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(delimiter != NULL && position > 0 && nvram != NULL){ if(func == 1 && value != NULL){ //printf("Inserting %s at position %d ...\n", value, position); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //nvram_set(nvram, value); nvram_set(nvram, insert_str(nvram_get(nvram), value, delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 2){ //printf("Deleting position %d of %s ... \n", position, nvram); //tmp = StrDup(nvram_get(nvram)); //value = delete_str(nvram_get(nvram), delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 3 && value != NULL){ //printf("Modifying position %d by %s ... \n", position, value); //tmp = StrDup(nvram_get(nvram)); //value = modify_str(nvram_get(nvram), value, delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, StrDup(modify_str(nvram_get(nvram), value, delimiter, position))); printf("%s\n", nvram_get(nvram)); } else if(func == 4){ //printf("\nReading the values from nvram variable %s ... \n", nvram); tmp = StrDup(nvram_get(nvram)); printf("%s\n", index_str(tmp, delimiter, position)); } else if(func == 5){ /*c = matchStrPosAt(delimiter, StrDup(nvram_get(nvram)), -1) + 1; for (i = 1; i <= c ; i++) { tmp = StrDup(nvram_get(nvram)); printf("tmp = %s\n", tmp); del = StrDup(index_str(tmp, delimiter, i)); printf("%s[%d] = %s\n", nvram, i, del); if(!strcmp(del, value)){ printf("value %s is matched in %s\n", value, nvram_get(nvram)); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, i)); printf("delete '%s' which is spcified at position %d\n", value, i); break; } }*/ nvram_set(nvram, delete_val(nvram_get(nvram), value, delimiter)); printf("%s\n", nvram_get(nvram)); } else if(func == 7){ tmp = StrDup(nvram_get(nvram)); if(val_exist(tmp, value, delimiter)) printf("%s is exist\n", value); else printf("%s is not exist\n", value); } else if(func == 8){ tmp = StrDup(nvram_get(nvram)); printf("%s\n", str2digits(tmp, delimiter, val)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(func == 6 && delimiter != NULL && nvram != NULL){ position = matchStrPosAt(delimiter, nvram_get(nvram), -1) + 1; printf("%d\n", position); /*printf("Number of token counts is %d\n", position); for(i = 1; i <= position; i++){ tmp = StrDup(nvram_get(nvram)); printf("\t%s\n", index_str(tmp, delimiter, i)); }*/ } else if(func == 9 && delimiter != NULL && nvram != NULL && value != NULL){ /* this code section is fix the old delimiter(s) is a subset of new delimiter(s) issue */ randnum = number_range(6, 16); tmp = StrDup(nvram_get(nvram)); if(strstr(value, delimiter) && strlen(value) > strlen(delimiter)){ char temp_deli[]="olddeliisasubsetofnewdeli"; random_string(temp_deli, randnum); nvram_set(nvram, replaceall(tmp, delimiter, temp_deli, -2, matchStrPosAt(delimiter, tmp, -1))); strcpy(tmp, nvram_get(nvram)); nvram_set(nvram, replaceall(tmp, temp_deli, value, -2, matchStrPosAt(temp_deli, tmp, -1))); } else nvram_set(nvram, replaceall(tmp, delimiter, value, -2, matchStrPosAt(delimiter, tmp, -1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } //StrFree(tmp); return 0; }
int main(int argc,char** argv){ cmdline::parser cp; const std::string udelim = "\n\t\t"; cp.add<std::string>("mode", 'm', "Specify a mode shown below."_s+udelim+ "c:Calculate with CPU. Need --cparam,--input" + udelim + "g:Calculate with GPU. Need --cparam,--input" + udelim + "v:Visualize the result.Need --cparam,--vparam" + udelim + "d:Diff calc parameter file. Need --cparam,--cparam2" + udelim + "gp:Generate default parameter files. Use --cparam,--vparam for output."+udelim+ "i:Generate initial cell data file.Need --cparam,--output"); cp.add<std::string>("input", 'i', "Cell data file.", false); cp.add<std::string>("output",'o', "Cell data output file(for init)",false); cp.add<std::string>("cparam", '\0', "Specify an parameter file path for calculation.",false); cp.add<std::string>("cparam2", '\0', "Additional parameter file (for diff)",false); cp.add<std::string>("vparam", '\0', "Specify an parameter file path for visualization.",false); cp.add<std::string>("initial", '\0', "Start calculation with initial state (without specifying initial data file)",false); cp.parse_check(argc, argv); auto mode = cp.get<std::string>("mode"); bool is_gpu = mode == "g"; bool is_vis = mode == "v"; bool is_cpu = mode == "c"; bool is_diff = mode == "d"; bool is_gen = mode == "gp"; bool is_init = mode == "i"; static void* aptr = malloc(sizeof(const CalcParams)); auto EH = ErrorHandling(cp); if(is_init){ EH.check("cparam","output"); set_param(cp,aptr); try{ init_gen_output(cp.get<std::string>("output"),16,8); }catch(std::exception& e){ std::cerr << e.what() << std::endl; std::exit(1); } } if (is_gen) { if (cp.exist("cparam")) { std::cout << "Generate cparam as " << cp.get<std::string>("cparam") << std::endl; CalcParams().generate_paramfile(cp.get<std::string>("cparam")); } if (cp.exist("vparam")) { std::cout << "Generate vparam as " << cp.get<std::string>("vparam") << std::endl; VisParams().generate_paramfile(cp.get<std::string>("vparam")); } } if (is_diff) { EH.check("cparam","cparam2"); try { const CalcParams cp1 = CalcParams(cp.get<std::string>("cparam")); const CalcParams cp2 = CalcParams(cp.get<std::string>("cparam2")); std::cout << "Compare " << cp.get<std::string>("cparam") << " and " << cp.get<std::string>("cparam2") <<std::endl; CalcParams::diff(cp1, cp2); } catch (std::exception& e) { std::cerr << e.what() << std::endl; std::exit(1); } } if (is_cpu || is_gpu) { const bool init_exist=cp.exist("initial"); if(init_exist){ EH.check("cparam"); }else{ EH.check("cparam","input"); } set_param(cp,aptr); CellManager cman; try { if(init_exist){ auto inum=parse_init_setting(cp.get<std::string>("initial")); cman=init_gen(std::get<0>(inum),std::get<1>(inum)); }else{ cman.load(cp.get<std::string>("input")); } } catch (std::exception& e) { std::cerr << e.what() << std::endl; std::exit(1); } //connect_cell(cman); calc_with_cpu(cman); } if (is_vis) { EH.check("cparam","vparam"); set_param(cp,aptr); try { VisParams vp(cp.get<std::string>("vparam")); init_visualizer(&argc, argv,vp); visualize(); } catch (std::exception& e) { std::cerr << e.what() << std::endl; std::exit(1); } } std::cout<<"Done."<<std::endl; }
OpWithSeq::OpWithSeq( const char *cpp_name ) : type( SYMBOL ) { init_gen(); cpp_name_str = strdup( cpp_name ); }
OpWithSeq::OpWithSeq( int t ) : type( t ) { init_gen(); }