/** * Init the Sally tool * @param argc number of arguments * @param argv arguments */ static void sally_init() { int ehash; const char *cfg_str; if (verbose > 1) config_print(&cfg); /* Set delimiters */ config_lookup_string(&cfg, "features.ngram_delim", &cfg_str); if (strlen(cfg_str) > 0) fvec_delim_set(cfg_str); /* Check for TFIDF weighting */ config_lookup_string(&cfg, "features.vect_embed", &cfg_str); if (!strcasecmp(cfg_str, "tfidf")) idf_create(input); /* Load stop words */ config_lookup_string(&cfg, "input.stopword_file", &cfg_str); if (strlen(cfg_str) > 0) stopwords_load(cfg_str); /* Check for feature hash table */ config_lookup_int(&cfg, "features.explicit_hash", &ehash); config_lookup_string(&cfg, "features.hash_file", &cfg_str); if (ehash || strlen(cfg_str) > 0) { info_msg(1, "Enabling feature hash table."); fhash_init(); } /* Open input */ config_lookup_string(&cfg, "input.input_format", &cfg_str); input_config(cfg_str); info_msg(1, "Opening '%0.40s' with input module '%s'.", input, cfg_str); entries = input_open(input); if (entries < 0) fatal("Could not open input source"); /* Open output */ config_lookup_string(&cfg, "output.output_format", &cfg_str); output_config(cfg_str); info_msg(1, "Opening '%0.40s' with output module '%s'.", output, cfg_str); if (!output_open(output)) fatal("Could not open output destination"); }
int main(int argc, char **argv) { int o; printf("\nCSF[%d] starting...\n", (int)getpid()); realpath(argv[0], exec_path); if (set_working_dir(exec_path) != 0) { PRINT("Can not set the working directory."); return (2); } set_conf_file(CONF_FILE); while(-1 != (o = getopt(argc, argv, "f:hv"))) { switch(o) { case 'f': set_conf_file(optarg); break; case 'v': output_config(); return 0; case 'h': show_help(); return 0; default: break; } } /* init each modules */ if (csf_init() < 0) { PRINT("CSF init failed. Exited."); return (2); } set_signals(); save_pid(argv[0]); /* starts the server */ server_init(&main_conf); WLOG_ERR("Fatal Error, SERVER DOWN!"); logger_deinit(); PRINT("Fatal Error, SERVER DOWN!"); return (2); }
/* init the CSF modules */ static int csf_init(void) { int rc; csf_conf_init(&main_conf); if (config_init() < 0) return CSF_ERR; else output_config(); /* start log */ if (main_conf.log_ident[0] == '\0') comm_handle.logp = logger_init(NULL, DEFAULT_WLOG_IDENT, LOG_CONS|LOG_PID, LOG_LOCAL6); else comm_handle.logp = logger_init(NULL, main_conf.log_ident, LOG_CONS|LOG_PID, LOG_LOCAL6); // comm_handle.mntp = monitor_init(NULL, main_conf.monitor_bind_ip, main_conf.monitor_port); comm_handle.sribp = request_info_init(&main_conf); if (main_conf.monitor_enable) { // if (monitor_start() < 0) { // WLOG_ERR("Monitor start failed."); // PRINT("Monitor start failed."); // } } if (main_conf.daemonize) daemonize(1, 1); set_maxfd(); /* * We prealloc the mempool * XXX We use pipeline_queue_size may not be suited? */ mp_init(main_conf.pipeline_queue_size / 10, main_conf.pipeline_queue_size / 2); rc = mod_config_init(&main_conf, &mod_queue_head, &gvcb, &comm_handle); if (rc != CSF_OK) { return (CSF_ERR); } /* * init pipeline module * (call the initialization function defined at protocol source file) */ if (!TAILQ_EMPTY(&mod_queue_head)) { rc = pipeline_init(&mod_queue_head, main_conf.pipeline_queue_size, main_conf.request_timeout); if (rc != PIPELINE_INIT_OK) { WLOG_ERR("Can not init pipeline."); PRINT("Can not init pipeline."); return (CSF_ERR); } } /*init protocol module*/ rc = app_proto_init(main_conf.protocol_module, main_conf.cp_ops, &gvcb, &comm_handle); if (rc < 0) return (CSF_ERR); return (CSF_OK); }
void read_particles(char *filename) { int64_t i, j, gadget = 0, gadget_internal = 0; int64_t p_start = num_p; float dx, ds, z, a, vel_mul; double *origin, origin_offset[3] = {0}; if (!strcasecmp(FILE_FORMAT, "ASCII")) load_particles(filename, &p, &num_p); else if (!strncasecmp(FILE_FORMAT, "GADGET", 6)) { if (!strcasecmp(FILE_FORMAT, "GADGET_INTERNAL") || !strcasecmp(FILE_FORMAT, "GADGET2_INTERNAL")) gadget_internal = 1; load_particles_gadget2(filename, &p, &num_p); gadget = 1; } else if (!strncasecmp(FILE_FORMAT, "ART", 3)) load_particles_art(filename, &p, &num_p); else if (!strncasecmp(FILE_FORMAT, "INTERNAL", 8)) { load_particles_internal(filename, &p, &num_p); } else if (!strncasecmp(FILE_FORMAT, "GENERIC", 7)) { assert(load_particles_generic != NULL); load_particles_generic(filename, &p, &num_p); } else if (!strncasecmp(FILE_FORMAT, "TIPSY", 5)) { load_particles_internal(filename, &p, &num_p); } else { fprintf(stderr, "[Error] Unknown filetype %s!\n", FILE_FORMAT); exit(1); } if (LIMIT_RADIUS) { for (i=p_start; i<num_p; i++) { for (j=0, ds=0; j<3; j++) { dx = p[i].pos[j]-LIMIT_CENTER[j]; ds+=dx*dx; } if (ds > LIMIT_RADIUS*LIMIT_RADIUS) { num_p--; p[i] = p[num_p]; i--; } } } if (LIGHTCONE) { init_cosmology(); if (strlen(LIGHTCONE_ALT_SNAPS)) { for (i=0; i<3; i++) if (LIGHTCONE_ORIGIN[i] || LIGHTCONE_ALT_ORIGIN[i]) break; if (i<3) { //Same box coordinates, different intended locations if (LIGHTCONE == 1) { for (i=0; i<3; i++) origin_offset[i] = LIGHTCONE_ORIGIN[i] - LIGHTCONE_ALT_ORIGIN[i]; } } else { //Offset everything for (i=0; i<3; i++) origin_offset[i] = -BOX_SIZE; } BOX_SIZE *= 2.0; } origin = (LIGHTCONE == 2) ? LIGHTCONE_ALT_ORIGIN : LIGHTCONE_ORIGIN; for (i=p_start; i<num_p; i++) { if (LIGHTCONE == 2) p[i].id = -p[i].id; //Make ids different for (j=0,dx=0; j<3; j++) { ds = p[i].pos[j] - origin[j]; dx += ds*ds; p[i].pos[j] -= origin_offset[j]; } if (!gadget) continue; dx = sqrt(dx); z = comoving_distance_h_to_redshift(dx); a = scale_factor(z); vel_mul = (gadget_internal) ? (1.0/a) : sqrt(a); for (j=0; j<3; j++) p[i].pos[j+3] *= vel_mul; } } output_config(NULL); }