static char *MdsGetString(char *in) { char *out = NULL; int status; struct descriptor in_d = {0,DTYPE_T,CLASS_S,0}; EMPTYXD(xd); in_d.length = strlen(in); in_d.pointer = in; status = TdiCompile(&in_d, &xd MDS_END_ARG); if(status & 1) status = TdiData(&xd, &xd MDS_END_ARG); if(!(status & 1)) { strncpy(error_message, MdsGetMsg(status), 512); return NULL; } if(!xd.pointer) { strcpy(error_message, "Missing data"); return NULL; } if(xd.pointer->dtype != DTYPE_T) { MdsFree1Dx(&xd, NULL); strcpy(error_message, "Not a string"); return NULL; } out = (char *)malloc(xd.pointer->length + 1); memcpy(out, xd.pointer->pointer, xd.pointer->length); out[xd.pointer->length] = 0; MdsFree1Dx(&xd, NULL); error_message[0] = 0; return out; }
JNIEXPORT void JNICALL Java_LocalDataProvider_SetEnvironmentSpecific(JNIEnv *env, jobject obj, jstring in, jstring jdefNode) { int status, nid; const char *in_char = (*env)->GetStringUTFChars(env, in, 0); const char *defNode; struct descriptor in_d = {0,DTYPE_T,CLASS_S,0}; EMPTYXD(xd); error_message[0] = 0; if(in_char && *in_char) { in_d.length = strlen(in_char); in_d.pointer = (char *)in_char; status = TdiCompile(&in_d, &xd MDS_END_ARG); if(status & 1) status = TdiData(&xd, &xd MDS_END_ARG); if(!(status & 1)) strncpy(error_message, MdsGetMsg(status), 512); MdsFree1Dx(&xd, NULL); (*env)->ReleaseStringUTFChars(env, in, in_char); } if(jdefNode) { defNode = (*env)->GetStringUTFChars(env, jdefNode, 0); status = TreeFindNode((char *)defNode, &nid); if(status & 1) TreeSetDefaultNid(nid); (*env)->ReleaseStringUTFChars(env, jdefNode, defNode); } }
int l8201___init(struct descriptor *niddsc_ptr, InInitStruct *setup) { int status; return_on_error(TdiData(setup->download,&data MDS_END_ARG),status); pio(9,0); stop(16); pio(11,&zero); pio(26,0); return status; }
static float MdsGetFloat(char *in) { float ris = 0; int status; struct descriptor in_d = {0,DTYPE_T,CLASS_S,0}; EMPTYXD(xd); in_d.length = strlen(in); in_d.pointer = in; status = TdiCompile(&in_d, &xd MDS_END_ARG); if(status & 1) status = TdiData(&xd, &xd MDS_END_ARG); if(status & 1) status = TdiFloat(&xd, &xd MDS_END_ARG); if(!(status & 1)) { strncpy(error_message, MdsGetMsg(status), 512); return 0; } if(!xd.pointer) { strcpy(error_message, "Missing data"); return 0; } if(xd.pointer->class != CLASS_S) { strcpy(error_message, "Not a scalar"); return 0; } switch(xd.pointer->dtype) { case DTYPE_BU: case DTYPE_B : ris = (float)(*(char *)xd.pointer->pointer); break; case DTYPE_WU: case DTYPE_W : ris = (float)(*(short *)xd.pointer->pointer); break; case DTYPE_LU: case DTYPE_L : ris = (float)(*(int *)xd.pointer->pointer); break; case DTYPE_F : ris = *(float *)xd.pointer->pointer; break; case DTYPE_FS: ris = *(float *)xd.pointer->pointer; break; case DTYPE_D : case DTYPE_G : ris = *(float *)xd.pointer->pointer; break; default: sprintf(error_message, "Not a supported type %d", xd.pointer->dtype); return 0; } MdsFree1Dx(&xd, NULL); error_message[0] = 0; return ris; }
int l8206___init(struct descriptor *niddsc_ptr, InInitStruct *setup) { int status; int download_nid = setup->head_nid + L8206_N_DOWNLOAD; pio(9,0); if (TreeIsOn(download_nid) & 1) { data.arsize = sizeof(buffer); return_on_error(TdiData(setup->download,&data MDS_END_ARG),status); stop(16,16384,buffer); stop(16,16384,&buffer[16384]); stop(16,16384,&buffer[32768]); stop(16,16384,&buffer[49152]); } pio(18,&zero); pio(11,&zero); pio(26,&zero); return status; }
int TdiGetSlope( struct descriptor_window *window_ptr, struct descriptor_slope *slope_ptr, struct descriptor_xd *out_ptr) { struct descriptor_xd xat0 = EMPTY_XD; int ndesc = slope_ptr->ndesc; int nseg = (ndesc + 2)/3; int status=0, jseg, kseg; int k0, k1, left, right; struct descriptor k0_dsc = {sizeof(int),DTYPE_L,CLASS_S,0}; struct descriptor k1_dsc = {sizeof(int),DTYPE_L,CLASS_S,0}; k0_dsc.pointer = (char *)&k0; k1_dsc.pointer = (char *)&k1; /***************** Get window limits. *****************/ if (ndesc <= 0) status = TdiMISS_ARG; else if (window_ptr && window_ptr->startidx) status = TdiGetLong(window_ptr->startidx, &k0); else k0 = -HUGE; if (status & 1 && window_ptr && window_ptr->endingidx) status = TdiGetLong(window_ptr->endingidx, &k1); else k1 = HUGE; if (status & 1 && window_ptr) status = TdiData(window_ptr->value_at_idx0, &xat0); else if (status & 1) status = TdiData(window_ptr, &xat0); /******************************************** Single slope with no begin or end. X[i] = (dX/di)*RANGE(startidx,endidx) + X[0]. ********************************************/ if ((ndesc<2 || !slope_ptr->segment[0].begin) && (ndesc<3 || !slope_ptr->segment[0].ending)) { if (status & 1) status = TdiRange(&k0_dsc, &k1_dsc, out_ptr); if (status & 1) status = TdiMultiply(slope_ptr->segment[0].slope, out_ptr, out_ptr); if (status & 1 && xat0.pointer) status = TdiAdd(&xat0, out_ptr, out_ptr); } /********************************* Multiple segments. Get each slope, begin, and end. May omit first begin and last end. *********************************/ else if (status & 1) { struct descriptor left_dsc = {sizeof(left),DTYPE_L,CLASS_S,0}; struct descriptor right_dsc = {sizeof(right),DTYPE_L,CLASS_S,0}; DESCRIPTOR_RANGE(ramp, 0, 0, 0); struct descriptor_xd (*pbegin)[], (*pend)[]=0, (*pslope)[]=0, *(*pvlist)[]=0, tmp1; int (*pcnt)[]=0; int virt = (sizeof(struct descriptor_xd)*3 + sizeof(struct descriptor_xd *))*nseg + sizeof(int)*(nseg + 1); left_dsc.pointer = (char *)&left; right_dsc.pointer = (char *)&right; ramp.begin = &left_dsc; ramp.ending = &right_dsc; /************************************** Dynamic allocation of descriptors. Memory for begin[nseg], end[nseg], slope[nseg], *vlist[nseg], cnt[nseg+1]. **************************************/ status = (pbegin = malloc(virt)) != NULL; if (status & 1) { pend = (struct descriptor_xd (*)[])&(*pbegin)[nseg]; pslope = (struct descriptor_xd (*)[])&(*pend)[nseg]; pvlist = (struct descriptor_xd *(*)[])&(*pslope)[nseg]; pcnt = (int (*)[])&(*pvlist)[nseg]; } /************************************************************************************* Find the number of points in interior segments, if any. For 1ms sampling, begin=0s, 1000 points, end=.999s, no sample is taken at 1s. Ideal expression: FLOOR((end - begin)/slope + 1) but not less than zero. WARNING: round-off may change by +-1, could change next by -+1 if end(j)==begin(j+1). WARNING: to prevent swings, ASSUME that divisor is close and round. Must be exact int. Expression: NINT((end - begin)/slope + 1) *************************************************************************************/ tmp1 = EMPTY_XD; for (jseg = 0; jseg < nseg; ++jseg) { (*pslope)[jseg] = (*pbegin)[jseg] = (*pend)[jseg] = EMPTY_XD; if (status & 1) status = TdiEvaluate(slope_ptr->segment[jseg].slope, &(*pslope)[jseg]); if (status & 1 && jseg*3+1 < ndesc) status = TdiEvaluate(slope_ptr->segment[jseg].begin, &(*pbegin)[jseg]); if (status & 1 && jseg*3+2 < ndesc) status = TdiEvaluate(slope_ptr->segment[jseg].ending, &(*pend)[jseg]); if (jseg == 0 && !slope_ptr->segment[0].begin) {(*pcnt)[1] = HUGE; continue;} if (jseg == nseg-1 && !slope_ptr->segment[jseg].ending) {(*pcnt)[nseg] = HUGE; continue;} if (status & 1) status = TdiSubtract((*pend)[jseg].pointer, (*pbegin)[jseg].pointer, &tmp1); if (status & 1) status = TdiDivide(&tmp1, (*pslope)[jseg].pointer, &tmp1); if (status & 1) status = TdiNint(&tmp1, &tmp1); if (status & 1) status = TdiGetLong(&tmp1, &left); (*pcnt)[jseg+1] = MAX(left + 1, 0); } /******************************************** Find the segment with value at index 0. Use first segment where expression is true: (0 LE slope[0]) EQV (x[0] LT begin[kseg+1]]). WARNING use .pointer to not free it. ********************************************/ if (status & 1) status = TdiLe(0, (*pslope)[0].pointer, &tmp1); if (status & 1) status = TdiGetLong(&tmp1, &left); for (kseg = 0; status & 1 && kseg < nseg-1; ++kseg) { status = TdiLt(xat0.pointer, (*pbegin)[kseg+1].pointer, &tmp1); if (status & 1) status = TdiGetLong(&tmp1, &right); if (left == right) break; } /******************************************** With index 0 in kseg, what is index at begin? left = (begin[kseg] - xat0)/slope[kseg] right = (end[0] - xat0)/slope[0]+1 for kseg=0. Trigger time xat0 implies next clock is at index 0, thus round down, more negative. Then adjust and accumulate counts. ********************************************/ if (kseg == 0 && !slope_ptr->segment[0].begin) { if (status & 1) status = TdiSubtract((*pend)[0].pointer, &xat0, &tmp1); if (status & 1) status = TdiDivide(&tmp1, (*pslope)[0].pointer, &tmp1); if (status & 1) status = TdiGetLong(&tmp1, &right); (*pcnt)[0] = MAX(right + 1, 0) - (*pcnt)[1]; } else { /******************************************* To make FLOOR work, must be floating divide. Generally, result is a negative number. *******************************************/ if (status & 1) status = TdiSubtract((*pbegin)[kseg].pointer, &xat0, &tmp1); if (status & 1) status = TdiFloat(&tmp1, &tmp1); if (status & 1) status = TdiDivide(&tmp1, (*pslope)[kseg].pointer, &tmp1); if (status & 1) status = TdiFloor(&tmp1, &tmp1); if (status & 1) status = TdiGetLong(&tmp1, &left); /*************************************** Definition of kseg gives cnt[kseg] <= 0. Check that cnt[kseg+1] >= 0. For xat0 near start[kseg+1], get cnt[kseg+1] = 0. ***************************************/ (*pcnt)[0] = MAX(left, -(*pcnt)[kseg+1]); for (jseg = kseg; --jseg >= 0;) (*pcnt)[0] -= (*pcnt)[jseg+1]; } for (jseg = 0; jseg < nseg; ++jseg) (*pcnt)[jseg+1] += (*pcnt)[jseg]; if (k0 < (*pcnt)[0]) k0 = (*pcnt)[0]; if (k1 >= (*pcnt)[nseg]) k1 = (*pcnt)[nseg] - 1; /******************************** For each segment generate result. ASSUMES ramp < 0 is 0 elements. [*:0] * slope[0] + end[0] or [0:*] * slope[jseg] + begin[jseg] Reuse slope as segment dsc. ********************************/ for (jseg = nseg; --jseg >= 0;) { left = MAX(k0 - (*pcnt)[jseg], 0); right = MIN((*pcnt)[jseg+1] - 1, k1) - (*pcnt)[jseg]; if (left > right) (*pvlist)[jseg] = 0; else if (jseg == 0 && !slope_ptr->segment[0].begin) { left -= (*pcnt)[1] - (*pcnt)[0] - 1; right -= (*pcnt)[1] - (*pcnt)[0] - 1; if (status & 1) status = TdiMultiply(&ramp, &(*pslope)[0], &tmp1); if (status & 1) status = TdiAdd(&tmp1, &(*pend)[0], &(*pslope)[0]); (*pvlist)[0] = &(*pslope)[0]; } else { if (status & 1) status = TdiMultiply(&ramp, &(*pslope)[jseg], &tmp1); if (status & 1) status = TdiAdd(&tmp1, &(*pbegin)[jseg], &(*pslope)[jseg]); (*pvlist)[jseg] = &(*pslope)[jseg]; } } /************************ Make segments into whole. ************************/ if (status & 1) status = Tdi1Vector(0, nseg, (*pvlist), out_ptr); MdsFree1Dx(&tmp1, NULL); for (jseg = nseg; --jseg >= 0;) { MdsFree1Dx(&(*pslope)[jseg], NULL); MdsFree1Dx(&(*pbegin)[jseg], NULL); MdsFree1Dx(&(*pend)[jseg], NULL); } if (pbegin != NULL) free(pbegin); } MdsFree1Dx(&xat0, NULL); /********************************************* When first index is not 0, we must set bounds. *********************************************/ if (window_ptr && status & 1 && k0 != 0) { DESCRIPTOR_RANGE(range, 0, 0, 0); range.begin = &k0_dsc; range.ending = &k1_dsc; status = TdiSetRange(&range, out_ptr, out_ptr); } return status; }
int mit_clock__get_setup(Dptr niddsc_ptr, Dptr method, DecoderSetup *setup, EventMask *event_mask, Dptr *output) { int status; InGet_setupStruct s; status = mit_clock___get_setup(niddsc_ptr,&s); if (status & 1) { float duty_cycle; int invert = 0; static float frequency[2]; float max_period; float period; static float dt; DESCRIPTOR_FLOAT(dt_dsc,&dt); int pulses; int clock_source; static DESCRIPTOR(expr, "* : * : $"); static EMPTYXD(out); DESCRIPTOR_A(frequency_a,sizeof(float),DTYPE_NATIVE_FLOAT,(char *)frequency,sizeof(frequency)); memset(event_mask,0,sizeof(EventMask)); status = TdiData(s.frequency,(struct descriptor *)&frequency_a MDS_END_ARG); if (!(status & 1)) { status = TIMING$_INVCLKFRQ; goto error; } if (frequency[1] == frequency[0]) duty_cycle = .5; else if (frequency[1] < 0.0) { invert = 1; duty_cycle = -frequency[1]; } else if (frequency[1] > 0.0) duty_cycle = frequency[1]; if ( (frequency[0] <= 0.0) || (duty_cycle <= 0.0) || (duty_cycle >= 1.0) ) { status = TIMING$_INVCLKFRQ; goto error; } max_period = 1/frequency[0]; for (clock_source = EXT_1MHZ, period = 1E-6; period * 65534 < max_period && clock_source <= EXT_100HZ; clock_source++, period *= 10); if (clock_source > EXT_100HZ) { status = TIMING$_INVCLKFRQ; goto error; } setup->output_control = TOGGLE; setup->start_high = 0; setup->count_up = 0; setup->bcd_count = 0; setup->repeat_count = 1; setup->double_load = 1; setup->special_gate = 0; setup->clock_source = clock_source; setup->falling_edge = 0; setup->gating = GATE_NONE; pulses = max_period/period + .4999; setup->load = pulses * duty_cycle + .4999; setup->hold = pulses - setup->load; if (setup->load == 0) { setup->load++; setup->hold--; } if (setup->hold == 0) { setup->load--; setup->hold++; } dt = period*(setup->load + setup->hold); if (invert) { int tmp = setup->load; setup->load = setup->hold; setup->hold = tmp; setup->start_high = 1; } status = TdiCompile(&expr, &dt_dsc, &out MDS_END_ARG); if (status&1) { static int output_nid; static DESCRIPTOR_NID(output_dsc,(char *)&output_nid); output_nid = s.head_nid + MIT_CLOCK_N_OUTPUT; status = TreePutRecord(output_nid, (struct descriptor *)&out,0); if (status&1) *output = &output_dsc; else *output=0; } else *output = 0; GenDeviceFree(&s); } return status; error: GenDeviceFree(&s); return status; }
static void *MdsGetArray(char *in, int *out_dim, int is_float, int is_byte, int is_double) { float *float_ris = NULL; double *double_ris = NULL; int *int_ris = NULL; char *byte_ris = NULL; int status, dim, i; struct descriptor in_d = {0,DTYPE_T,CLASS_S,0}; EMPTYXD(xd); struct descriptor_a *arr_ptr; char *expanded_in; error_message[0] = 0; *out_dim = 0; if(is_float) { expanded_in = malloc(strlen(in) + 16); sprintf(expanded_in, "fs_float((%s))", in); in_d.length = strlen(expanded_in); in_d.pointer = expanded_in; } else if(is_double) { expanded_in = malloc(strlen(in) + 16); sprintf(expanded_in, "ft_float((%s))", in); in_d.length = strlen(expanded_in); in_d.pointer = expanded_in; } else { expanded_in = malloc(strlen(in) + 16); sprintf(expanded_in, "long((%s))", in); in_d.length = strlen(expanded_in); in_d.pointer = expanded_in; /* in_d.length = strlen(in); in_d.pointer = in;*/ } status = TdiCompile(&in_d, &xd MDS_END_ARG); if(is_float) free(expanded_in); if(status & 1) status = TdiData(&xd, &xd MDS_END_ARG); if(!(status & 1)) { strncpy(error_message, MdsGetMsg(status), 512); return 0; } if(!xd.pointer) { strcpy(error_message, "Missing data"); return 0; } if(xd.pointer->class != CLASS_A) { if(!is_float && !is_double) /*Legal only if used to retrieve the shot number*/ { int_ris = malloc(sizeof(int)); switch(xd.pointer->dtype) { case DTYPE_BU: case DTYPE_B : int_ris[0] = *((char *)xd.pointer->pointer); break; case DTYPE_WU: case DTYPE_W : int_ris[0] = *((short *)xd.pointer->pointer); break; case DTYPE_LU: case DTYPE_L : int_ris[0] = *((int *)xd.pointer->pointer); break; case DTYPE_F : case DTYPE_FS : int_ris[0] = *((int *)xd.pointer->pointer); break; } *out_dim = 1; return int_ris; } strcpy(error_message, "Not an array"); return 0; } arr_ptr = (struct descriptor_a *)xd.pointer; /* if(arr_ptr->dtype == DTYPE_F || arr_ptr->dtype == DTYPE_D || arr_ptr->dtype == DTYPE_G || arr_ptr->dtype == DTYPE_H) { status = TdiFloat(&xd, &xd MDS_END_ARG); arr_ptr = (struct descriptor_a *)xd.pointer; } */ *out_dim = dim = arr_ptr->arsize/arr_ptr->length; if(is_float) float_ris = (float *)malloc(sizeof(float) * dim); else if(is_double) double_ris = (double *)malloc(sizeof(double) * dim); else if(is_byte) byte_ris = malloc(dim); else int_ris = (int *)malloc(sizeof(int) * dim); switch(arr_ptr->dtype) { case DTYPE_BU: case DTYPE_B : for(i = 0; i < dim; i++) if(is_float) float_ris[i] = ((char *)arr_ptr->pointer)[i]; else if(is_double) double_ris[i] = ((char *)arr_ptr->pointer)[i]; else if(is_byte) byte_ris[i] = ((char *)arr_ptr->pointer)[i]; else int_ris[i] = ((char *)arr_ptr->pointer)[i]; break; case DTYPE_WU: case DTYPE_W : for(i = 0; i < dim; i++) if(is_float) float_ris[i] = ((short *)arr_ptr->pointer)[i]; else if(is_double) double_ris[i] = ((char *)arr_ptr->pointer)[i]; else if(is_byte) byte_ris[i] = (char)(((short *)arr_ptr->pointer)[i]); else int_ris[i] = ((short *)arr_ptr->pointer)[i]; break; case DTYPE_LU: case DTYPE_L : for(i = 0; i < dim; i++) if(is_float) float_ris[i] = (float)(((int *)arr_ptr->pointer)[i]); if(is_double) double_ris[i] = (double)(((int *)arr_ptr->pointer)[i]); else if(is_byte) byte_ris[i] = ((int *)arr_ptr->pointer)[i]; else int_ris[i] = ((int *)arr_ptr->pointer)[i]; break; case DTYPE_F : case DTYPE_FS : for(i = 0; i < dim; i++) if(is_float) float_ris[i] = ((float *)arr_ptr->pointer)[i]; else if(is_double) double_ris[i] = (double)((float *)arr_ptr->pointer)[i]; else if(is_byte) byte_ris[i] = (char)(((float *)arr_ptr->pointer)[i]); else int_ris[i] = (int)(((float *)arr_ptr->pointer)[i]); break; case DTYPE_FT : for(i = 0; i < dim; i++) if(is_float) float_ris[i] = (float)((double *)arr_ptr->pointer)[i]; else if(is_double) { double_ris[i] = ((double *)arr_ptr->pointer)[i]; } else if(is_byte) byte_ris[i] = (char)(((double *)arr_ptr->pointer)[i]); else int_ris[i] = (int)(((double *)arr_ptr->pointer)[i]); break; case DTYPE_D : case DTYPE_G : default: strcpy(error_message, "Not a supported type"); return NULL; } MdsFree1Dx(&xd, NULL); error_message[0] = 0; if(is_float) return float_ris; else if(is_double) return double_ris; else if(is_byte) return byte_ris; return int_ris; }
static int Store(struct descriptor *niddsc_ptr, InStoreStruct *setup, int sort) { static struct descriptor rpt_name = {0,DTYPE_T,CLASS_D,0}; static struct descriptor name = {0,DTYPE_T,CLASS_D,0}; static struct descriptor names[10] = {{0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}, {0,DTYPE_T,CLASS_D,0}}; static struct descriptor_xd limits[10] = {{0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}, {0,DTYPE_DSC,CLASS_XD,0,0}}; TIME *tims[10]; float *vals[10]; int nums[10]; int sizes[10]; int delete_file_nid = setup->head_nid + PARAGON_HIST_N_DELETE_FILE; int i; int status; char line[256]; FILE *file; int isftp; status = PARAGON_FTP_COPY(setup->report_name,&rpt_name,&isftp); if (!(status & 1)) { return(status); } for (i=0; i<10; i++) { int name_nid = setup->head_nid + PARAGON_HIST_N_NAME_0 + i; nums[i] = 0; tims[i] = NULL; vals[i] = NULL; status = DevText(&name_nid, &names[i]); if (status) { static int limit_nid; static DESCRIPTOR_NID(nid_dsc,&limit_nid); limit_nid = setup->head_nid + PARAGON_HIST_N_LIMIT_0 + i; status = TdiData(&nid_dsc, &limits[i] MDS_END_ARG); if (!(status&1)) MdsFree1Dx(&limits[i],0); nums[i] = 0; sizes[i] = INITIAL_SIZE; tims[i] = (TIME *)malloc(sizeof(TIME)*INITIAL_SIZE); vals[i] = (float *)malloc(sizeof(float)*INITIAL_SIZE); } } file = fopen(rpt_name.pointer,"r"); if (file != NULL) { while(fgets(line,255,file)) { TIME time; float value; if (strlen(line) >= 70) { if (ParseHistorian(line, &name, &value, &time) ) { for (i=0; i<10;) { if (StrCompare(&name, &names[i])==0) break; else i++; } if (i < 10) { if (nums[i] >= sizes[i]) { TIME *t_time = tims[i]; float *t_val = vals[i]; int j; tims[i] = (TIME *)malloc(sizeof(TIME)*sizes[i]*2); vals[i] = (float *)malloc(sizeof(float)*sizes[i]*2); for (j=0; j<sizes[i]; j++) { (tims[i])[j] = t_time[j]; (vals[i])[j] = t_val[j]; } sizes[i]*=2; free(t_time); free(t_val); } (tims[i])[nums[i]] = time; (vals[i])[nums[i]] = value; nums[i]++; } } } } fclose(file); for (i=0; i<10; i++) { if (nums[i]) { int value_nid = setup->head_nid + PARAGON_HIST_N_VALUE_0 + i; if (TreeIsOn(value_nid)&1) StoreSignal(value_nid, nums[i], vals[i], tims[i], &limits[i], sort); } if (vals[i]) free(vals[i]); if (tims[i]) free(tims[i]); } PARAGON_FTP_DELETE(setup->report_name,TreeIsOn(delete_file_nid)); } return 1; }
int Tdi1GetDbi(int opcode, int narg, struct descriptor *list[], struct descriptor_xd *out_ptr) { int status = 1; struct descriptor_d string = { 0, DTYPE_T, CLASS_D, 0 }; struct descriptor_xd tmp = EMPTY_XD; struct item *key_ptr = 0; int index; DBI_ITM lst[] = { {sizeof(index), DbiINDEX, 0, 0} , EOL, EOL }; lst[0].pointer = (unsigned char *)&index; /********************** String of item to find. **********************/ status = TdiData(list[0], &tmp MDS_END_ARG); if (status & 1) status = TdiUpcase(&tmp, &string MDS_END_ARG); if (status & 1) { key_ptr = (struct item *)bsearch(&string, table, numtab, siztab, (int (*)(const void *, const void *)) compare); if (key_ptr == 0) status = TdiBAD_INDEX; } StrFree1Dx(&string); MdsFree1Dx(&tmp, NULL); /********************************** Somebody might want others in pool. **********************************/ if (status & 1 && narg > 1) status = TdiGetLong(list[1], &index); else index = 0; /*********************** Get the item asked for. Fixed length or varying. ***********************/ if (status & 1) { lst[1].code = key_ptr->item_code; if ((lst[1].buffer_length = key_ptr->item_length) != 0) { status = MdsGet1DxS((unsigned short *)&lst[1].buffer_length, &key_ptr->item_dtype, out_ptr); if (status & 1) { lst[1].pointer = (unsigned char *)out_ptr->pointer->pointer; status = TreeGetDbi(lst); } } else { lst[1].buffer_length = 0; lst[1].pointer = NULL; status = TreeGetDbi(lst); if (status & 1) { struct descriptor ans = { 0, DTYPE_T, CLASS_S, 0 }; if (lst[1].pointer) { ans.length = strlen((char *)lst[1].pointer); ans.pointer = (char *)lst[1].pointer; } status = MdsCopyDxXd(&ans, out_ptr); if (ans.pointer) TreeFree(ans.pointer); } } } return status; }
int Tdi1Using(int opcode, int narg, struct descriptor *list[], struct descriptor_xd *out_ptr) { int status = 1; void *ctx; int reset_ctx = 0; int nid, shot, stat1; struct descriptor def = { 0, DTYPE_T, CLASS_D, 0 }, expt = def; unsigned char omits[] = { DTYPE_PATH, 0 }; /********************** Evaluate with current. Use current if omitted. Must get expt if shot. **********************/ if (narg > 1 && status & 1) { if (list[1]) { struct descriptor_xd xd = EMPTY_XD; status = TdiGetData(omits, list[1], &xd); if (status & 1 && xd.pointer) switch (xd.pointer->dtype) { case DTYPE_T: case DTYPE_PATH: status = StrCopyDx(&def, xd.pointer); break; default: status = TdiINVDTYDSC; break; } MdsFree1Dx(&xd, NULL); } if (!list[1] || def.length == 0) { DBI_ITM def_itm[] = { {0, DbiDEFAULT, 0, 0} , EOL }; status = TreeGetDbi(def_itm); if (def_itm[0].pointer == NULL) { STATIC_CONSTANT DESCRIPTOR(top, "\\TOP"); StrCopyDx(&def, &top); status = 1; } else { unsigned short len = (unsigned short)strlen((char *)def_itm[0].pointer); StrCopyR(&def, &len, def_itm[0].pointer); TreeFree(def_itm[0].pointer); } if (status & 1) { stat1 = StrPosition(&def, &coloncolon, 0) + 1; status = StrRight(&def, &def, &stat1); } if (status & 1) *def.pointer = '\\'; } } if ((narg > 2) && ((list[2] != 0) || ((narg > 3) && (list[3] != 0))) && ((status & 1) != 0)) { if (list[2]) status = TdiGetLong(list[2], &shot); else { DBI_ITM shot_itm[] = { {sizeof(shot), DbiSHOTID, 0, 0} , EOL }; shot_itm[0].pointer = (unsigned char *)&shot; status = TreeGetDbi(shot_itm); } if (status & 1) { if (narg > 3 && list[3]) status = TdiData(list[3], &expt MDS_END_ARG); else { DBI_ITM expt_itm[] = { {0, DbiNAME, 0, 0} , EOL }; status = TreeGetDbi(expt_itm); if (expt_itm[0].pointer) { unsigned short len = (unsigned short)strlen((char *)expt_itm[0].pointer); StrCopyR(&expt, &len, expt_itm[0].pointer); TreeFree(expt_itm[0].pointer); } } } /********************* Set new tree and path. Allow some rel paths. *********************/ if (status & 1) { char *tree = MdsDescrToCstring(&expt); ctx = TreeSwitchDbid(0); reset_ctx = 1; status = TreeOpen(tree, shot, 1); MdsFree(tree); } } if (narg > 1) { char *path = MdsDescrToCstring(&def); if (status & 1) status = TreeSetDefault(path, &nid); MdsFree(path); if (narg > 2) StrFree1Dx(&expt); StrFree1Dx(&def); } /*********************** Evaluate with temporary. ***********************/ if (status & 1) { struct descriptor_xd tmp = EMPTY_XD; status = TdiEvaluate(list[0], &tmp MDS_END_ARG); if (status & 1) status = MdsCopyDxXdZ((struct descriptor *)&tmp, out_ptr, NULL, fixup_nid, NULL, fixup_path, NULL); MdsFree1Dx(&tmp, NULL); } if (reset_ctx) { while (TreeClose(0, 0) & 1) ; TreeFreeDbid(TreeSwitchDbid(ctx)); } return status; }