Strdeq_t arithprog_rclass(const RTree_t *nptr) { Strdeq_t opsd; const RTree_t *t = nptr; Intdeq_t sd; t = t->child; /* temp pointer */ if(Ruletype::Splitter == t->rtype) { Strdeq_t str_deq = arithprog_rclass(t); Strdeqitr_t sdi = str_deq.begin(); for( ; sdi != str_deq.end(); ++sdi) sd.push_back(atoi((*sdi).data())); } else sd = get_series(t); /* starting number deque */ t = t->next; Intdeq_t dd = get_series(t); /* difference number deque */ t = t->next; Intdeq_t ld = get_series(t); /* length deque */ Intdeqitr_t li = ld.begin(); /* length iterator */ for( ; li != ld.end(); ++li) { /* If length is zero there is nothing todo */ if(0 == *li) continue; /* If length is one the difference has no significance and all the elements in the stating number deque should be added */ if(1 == *li) { /* string buffer */ char sb[32] = {}; Intdeqitr_t si = sd.begin(); for( ; si != sd.end(); ++si) { sprintf(sb, "%d", *si); opsd.push_back(sb); } continue; } Intdeqitr_t di = dd.begin(); for( ; di != dd.end(); ++di) { Intdeqitr_t si = sd.begin(); /* starting number interator */ for( ; si != sd.end(); ++si) { if(Ruletype::Splitter == nptr->rtype) arithprog_splitter(opsd, *si, *di, *li); else opsd.push_back(arithmetic_progression(*si, *di, *li)); } } } return opsd; }
Strdeq_t constant_rclass(const RTree_t *nptr) { char ca[32]; Strdeq_t opsd; Intdeq_t ideq = get_series(nptr); Intdeqitr_t i = ideq.begin(); for( ; i != ideq.end(); ++i) { sprintf(ca, "%d", *i); opsd.push_back(ca); } return opsd; }
Strdeq_t repeat_rclass(const RTree_t *nptr) { Strdeq_t opsd; /* output string deque */ Intdeq_t ideq = get_series(nptr); /* next rule string deque */ Strdeq_t nrsd = rule_interpreter(nptr->next); Intdeqitr_t i = ideq.begin(); print_deque(nrsd); for( ; i != ideq.end(); ++i) { Strdeqitr_t s = nrsd.begin(); for( ; s != nrsd.end(); ++s) opsd.push_back(repeat_string((*s).data(), *i)); } return opsd; }
void create_edge( struct NodeStorage* store,unsigned tail,unsigned head ) { EdgeSeries* target; if( store->nodes[ tail ].out.n_edges ) { target = get_series( store,tail,store->nodes[ tail ].out.n_edges-1 ); if( !( store->nodes[ tail ].out.n_edges%store->edge_stride ) ) { target->next = malloc( sizeof (EdgeSeries) ); target->next->data = malloc( store->edge_stride*sizeof (Edge) ); target->next->next = NULL; target = target->next; } } else target = &( store->nodes[ tail ].out.first ); target->data[ store->nodes[ tail ].out.n_edges%store->edge_stride ].head = head; store->nodes[ tail ].out.n_edges++; }
int main(int argc,char **argv) { char stdi=0,*done,alldone; int i; long n; long maxlength; double min,max; FILE *file; if (scan_help(argc,argv)) show_options(argv[0]); scan_options(argc,argv); #ifndef OMIT_WHAT_I_DO if (verbosity&VER_INPUT) what_i_do(argv[0],WID_STR); #endif infile=search_datafile(argc,argv,&column,verbosity); if (infile == NULL) stdi=1; if (outfile == NULL) { if (!stdi) { check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1)); strcpy(outfile,infile); strcat(outfile,".ros"); } else { check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1)); strcpy(outfile,"stdin.ros"); } } test_outfile(outfile); series=(double*)get_series(infile,&length,exclude,column,verbosity); rescale_data(series,length,&min,&max); if (epsset) eps0 /= max; check_alloc(list=(long*)malloc(length*sizeof(long))); check_alloc(lyap=(double*)malloc((steps+1)*sizeof(double))); check_alloc(found=(long*)malloc((steps+1)*sizeof(long))); check_alloc(done=(char*)malloc(length)); for (i=0;i<=steps;i++) { lyap[i]=0.0; found[i]=0; } for (i=0;i<length;i++) done[i]=0; maxlength=length-delay*(dim-1)-steps-1-mindist; alldone=0; file=fopen(outfile,"w"); if (verbosity&VER_INPUT) fprintf(stderr,"Opened %s for writing\n",outfile); for (eps=eps0;!alldone;eps*=1.1) { epsinv=1.0/eps; put_in_boxes(); alldone=1; for (n=0;n<=maxlength;n++) { if (!done[n]) done[n]=make_iterate(n); alldone &= done[n]; } if (verbosity&VER_USR1) fprintf(stderr,"epsilon: %e already found: %ld\n",eps*max,found[0]); } for (i=0;i<=steps;i++) if (found[i]) fprintf(file,"%d %e\n",i,lyap[i]/found[i]/2.0); fclose(file); return 0; }
int main(int argc,char **argv) { char stdi=0; unsigned long i,j; double x,norm,size=1.0,size2=1.0; double min,max; double *series; double average,var; long *box; FILE *fout; if (scan_help(argc,argv)) show_options(argv[0]); scan_options(argc,argv); #ifndef OMIT_WHAT_I_DO if (verbosity&VER_INPUT) what_i_do(argv[0],WID_STR); #endif infile=search_datafile(argc,argv,&column,verbosity); if (infile == NULL) stdi=1; if (outfile == NULL) { if (!stdi) { check_alloc(outfile=(char*)calloc(strlen(infile)+5,1)); strcpy(outfile,infile); strcat(outfile,".his"); } else { check_alloc(outfile=(char*)calloc((size_t)10,1)); strcpy(outfile,"stdin.his"); } } if (!my_stdout) test_outfile(outfile); series=(double*)get_series(infile,&length,exclude,column,verbosity); variance(series,length,&average,&var); min=max=series[0]; for (i=1;i<length;i++) { if (series[i] < min) min=series[i]; else if (series[i] > max) max=series[i]; } max -= min; for (i=0;i<length;i++) series[i]=(series[i]-min); if (base > 0) { check_alloc(box=(long*)malloc(sizeof(long)*base)); for (i=0;i<base;i++) box[i]=0; size=1./base; size2=(1.0-size/2.0)*max; for (i=0;i<length;i++) { if (series[i] > size2) series[i]=size2; j=(long)(series[i]*base/max); box[j]++; } } if (!density) norm=1.0/(double)length; else norm=1.0/(double)length*(double)base/max; if (!my_stdout) { fout=fopen(outfile,"w"); if (verbosity&VER_INPUT) fprintf(stderr,"Opened %s for writing\n",outfile); fprintf(fout,"#interval of data: [%e:%e]\n",min,max+min); fprintf(fout,"#average= %e\n",average); fprintf(fout,"#standard deviation= %e\n",var); for (i=0;i<base;i++) { x=(double)(i*size); fprintf(fout,"%e %e\n",(x+size/2.0)*max+min,(double)box[i]*norm); } fclose(fout); } else { if (verbosity&VER_INPUT) fprintf(stderr,"Writing to stdout\n"); fprintf(stdout,"#interval of data: [%e:%e]\n",min,max+min); fprintf(stdout,"#average= %e\n",average); fprintf(stdout,"#standard deviation= %e\n",var); for (i=0;i<base;i++) { x=(double)(i*size); fprintf(stdout,"%e %e\n",(x+size/2.0)*max+min,(double)box[i]*norm); fflush(stdout); } } return 0; }
gboolean process_pe_message(xmlNode * msg, xmlNode * xml_data, crm_client_t * sender) { static char *last_digest = NULL; static char *filename = NULL; time_t execution_date = time(NULL); const char *sys_to = crm_element_value(msg, F_CRM_SYS_TO); const char *op = crm_element_value(msg, F_CRM_TASK); const char *ref = crm_element_value(msg, F_CRM_REFERENCE); crm_trace("Processing %s op (ref=%s)...", op, ref); if (op == NULL) { /* error */ } else if (strcasecmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if (safe_str_eq(crm_element_value(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE)) { /* ignore */ } else if (sys_to == NULL || strcasecmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_trace("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if (strcasecmp(op, CRM_OP_PECALC) == 0) { int seq = -1; int series_id = 0; int series_wrap = 0; char *digest = NULL; const char *value = NULL; pe_working_set_t data_set; xmlNode *converted = NULL; xmlNode *reply = NULL; gboolean is_repoke = FALSE; gboolean process = TRUE; crm_config_error = FALSE; crm_config_warning = FALSE; was_processing_error = FALSE; was_processing_warning = FALSE; set_working_set_defaults(&data_set); digest = calculate_xml_versioned_digest(xml_data, FALSE, FALSE, CRM_FEATURE_SET); converted = copy_xml(xml_data); if (cli_config_update(&converted, NULL, TRUE) == FALSE) { data_set.graph = create_xml_node(NULL, XML_TAG_GRAPH); crm_xml_add_int(data_set.graph, "transition_id", 0); crm_xml_add_int(data_set.graph, "cluster-delay", 0); process = FALSE; free(digest); } else if (safe_str_eq(digest, last_digest)) { crm_info("Input has not changed since last time, not saving to disk"); is_repoke = TRUE; free(digest); } else { free(last_digest); last_digest = digest; } if (process) { do_calculations(&data_set, converted, NULL); } series_id = get_series(); series_wrap = series[series_id].wrap; value = pe_pref(data_set.config_hash, series[series_id].param); if (value != NULL) { series_wrap = crm_int_helper(value, NULL); if (errno != 0) { series_wrap = series[series_id].wrap; } } else { crm_config_warn("No value specified for cluster" " preference: %s", series[series_id].param); } seq = get_last_sequence(PE_STATE_DIR, series[series_id].name); crm_trace("Series %s: wrap=%d, seq=%d, pref=%s", series[series_id].name, series_wrap, seq, value); data_set.input = NULL; reply = create_reply(msg, data_set.graph); CRM_ASSERT(reply != NULL); if (is_repoke == FALSE) { free(filename); filename = generate_series_filename(PE_STATE_DIR, series[series_id].name, seq, HAVE_BZLIB_H); } crm_xml_add(reply, F_CRM_TGRAPH_INPUT, filename); crm_xml_add_int(reply, "graph-errors", was_processing_error); crm_xml_add_int(reply, "graph-warnings", was_processing_warning); crm_xml_add_int(reply, "config-errors", crm_config_error); crm_xml_add_int(reply, "config-warnings", crm_config_warning); if (crm_ipcs_send(sender, 0, reply, crm_ipc_server_event) == FALSE) { crm_err("Couldn't send transition graph to peer, discarding"); } free_xml(reply); cleanup_alloc_calculations(&data_set); if (was_processing_error) { crm_err("Calculated transition %d (with errors), saving inputs in %s", transition_id, filename); } else if (was_processing_warning) { crm_warn("Calculated transition %d (with warnings), saving inputs in %s", transition_id, filename); } else { crm_notice("Calculated transition %d, saving inputs in %s", transition_id, filename); } if (crm_config_error) { crm_notice("Configuration ERRORs found during PE processing." " Please run \"crm_verify -L\" to identify issues."); } if (is_repoke == FALSE && series_wrap != 0) { unlink(filename); crm_xml_add_int(xml_data, "execution-date", execution_date); write_xml_file(xml_data, filename, HAVE_BZLIB_H); write_last_sequence(PE_STATE_DIR, series[series_id].name, seq + 1, series_wrap); } else { crm_trace("Not writing out %s: %d & %d", filename, is_repoke, series_wrap); } free_xml(converted); } return TRUE; }
int main(int argc,char** argv) { char stdi=0; long i; FILE *fout=NULL; if (scan_help(argc,argv)) show_options(argv[0]); scan_options(argc,argv); #ifndef OMIT_WHAT_I_DO if (verbosity&VER_INPUT) what_i_do(argv[0],WID_STR); #endif infile=search_datafile(argc,argv,&column,verbosity); if (infile == NULL) stdi=1; if (outfile == NULL) { if (!stdi) { check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1)); strcpy(outfile,infile); strcat(outfile,".cor"); } else { check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1)); strcpy(outfile,"stdin.cor"); } } if (!stout) test_outfile(outfile); array=(double*)get_series(infile,&length,exclude,column,verbosity); if (tau >= length) tau=length-1; variance(array,length,&av,&var); if (normalize) { for (i=0;i<length;i++) array[i] -= av; } if (!stout) { fout=fopen(outfile,"w"); if (verbosity&VER_INPUT) fprintf(stderr,"Opened %s for writing\n",outfile); fprintf(fout,"# average=%e\n",av); fprintf(fout,"# standard deviation=%e\n",var); } else { if (verbosity&VER_INPUT) fprintf(stderr,"Writing to stdout\n"); fprintf(stdout,"# average=%e\n",av); fprintf(stdout,"# standard deviation=%e\n",var); } if (normalize) var *= var; else var=1.0; for (i=0;i<=tau;i++) if (!stout) { fprintf(fout,"%ld %e\n",i,corr(i)/var); fflush(fout); } else { fprintf(stdout,"%ld %e\n",i,corr(i)/var); fflush(stdout); } if (!stout) fclose(fout); if (outfile != NULL) free(outfile); if (infile != NULL) free(infile); free(array); return 0; }
gboolean process_pe_message(xmlNode *msg, xmlNode *xml_data, IPC_Channel *sender) { gboolean send_via_disk = FALSE; const char *sys_to = crm_element_value(msg, F_CRM_SYS_TO); const char *op = crm_element_value(msg, F_CRM_TASK); const char *ref = crm_element_value(msg, XML_ATTR_REFERENCE); crm_debug_3("Processing %s op (ref=%s)...", op, ref); if(op == NULL) { /* error */ } else if(strcasecmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(safe_str_eq(crm_element_value(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE)) { /* ignore */ } else if(sys_to == NULL || strcasecmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_debug_3("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcasecmp(op, CRM_OP_PECALC) == 0) { int seq = -1; int series_id = 0; int series_wrap = 0; char *filename = NULL; char *graph_file = NULL; const char *value = NULL; pe_working_set_t data_set; xmlNode *converted = NULL; xmlNode *reply = NULL; gboolean process = TRUE; #if HAVE_BZLIB_H gboolean compress = TRUE; #else gboolean compress = FALSE; #endif crm_config_error = FALSE; crm_config_warning = FALSE; was_processing_error = FALSE; was_processing_warning = FALSE; graph_file = crm_strdup(CRM_STATE_DIR"/graph.XXXXXX"); graph_file = mktemp(graph_file); converted = copy_xml(xml_data); if(cli_config_update(&converted, NULL, TRUE) == FALSE) { set_working_set_defaults(&data_set); data_set.graph = create_xml_node(NULL, XML_TAG_GRAPH); crm_xml_add_int(data_set.graph, "transition_id", 0); crm_xml_add_int(data_set.graph, "cluster-delay", 0); process = FALSE; } if(process) { do_calculations(&data_set, converted, NULL); } series_id = get_series(); series_wrap = series[series_id].wrap; value = pe_pref(data_set.config_hash, series[series_id].param); if(value != NULL) { series_wrap = crm_int_helper(value, NULL); if(errno != 0) { series_wrap = series[series_id].wrap; } } else { crm_config_warn("No value specified for cluster" " preference: %s", series[series_id].param); } seq = get_last_sequence(PE_STATE_DIR, series[series_id].name); data_set.input = NULL; reply = create_reply(msg, data_set.graph); CRM_ASSERT(reply != NULL); filename = generate_series_filename( PE_STATE_DIR, series[series_id].name, seq, compress); crm_xml_add(reply, F_CRM_TGRAPH_INPUT, filename); crm_xml_add_int(reply, "graph-errors", was_processing_error); crm_xml_add_int(reply, "graph-warnings", was_processing_warning); crm_xml_add_int(reply, "config-errors", crm_config_error); crm_xml_add_int(reply, "config-warnings", crm_config_warning); if(send_ipc_message(sender, reply) == FALSE) { if(sender && sender->ops->get_chan_status(sender) == IPC_CONNECT) { send_via_disk = TRUE; crm_err("Answer could not be sent via IPC, send via the disk instead"); crm_info("Writing the TE graph to %s", graph_file); if(write_xml_file(data_set.graph, graph_file, FALSE) < 0) { crm_err("TE graph could not be written to disk"); } } else { crm_info("Peer disconnected, discarding transition graph"); } } free_xml(reply); cleanup_alloc_calculations(&data_set); if(series_wrap != 0) { write_xml_file(xml_data, filename, compress); write_last_sequence(PE_STATE_DIR, series[series_id].name, seq+1, series_wrap); } if(was_processing_error) { crm_err("Transition %d:" " ERRORs found during PE processing." " PEngine Input stored in: %s", transition_id, filename); } else if(was_processing_warning) { crm_warn("Transition %d:" " WARNINGs found during PE processing." " PEngine Input stored in: %s", transition_id, filename); } else { crm_info("Transition %d: PEngine Input stored in: %s", transition_id, filename); } if(crm_config_error) { crm_info("Configuration ERRORs found during PE processing." " Please run \"crm_verify -L\" to identify issues."); } else if(crm_config_warning) { crm_info("Configuration WARNINGs found during PE processing." " Please run \"crm_verify -L\" to identify issues."); } if(send_via_disk) { reply = create_reply(msg, NULL); crm_xml_add(reply, F_CRM_TGRAPH, graph_file); crm_xml_add(reply, F_CRM_TGRAPH_INPUT, filename); CRM_ASSERT(reply != NULL); if(send_ipc_message(sender, reply) == FALSE) { crm_err("Answer could not be sent"); } free_xml(reply); } free_xml(converted); crm_free(graph_file); crm_free(filename); } else if(strcasecmp(op, CRM_OP_QUIT) == 0) { crm_warn("Received quit message, terminating"); exit(0); } return TRUE; }