コード例 #1
0
ファイル: fit__misc_c.c プロジェクト: Starlink/starlink
static void TreeFree( NodeRef node, int *status )
  {
  if ( !_ok(status) || (! node) )
    return;

  if ( node->lhs )
    TreeFree( node->lhs, status );
  if ( node->rhs )
    TreeFree( node->rhs, status );

  free( node );
  }
コード例 #2
0
ファイル: tree.c プロジェクト: jpmcd/HPC15-ParallelBoosting
void TreeFree(Node *node) {

/* Recursively frees dynamically allocated trees
 */

    if (node == NULL)
        return;
    
    TreeFree(node->left);
    TreeFree(node->right);
    free(node);
    return;
}
コード例 #3
0
ファイル: parse.c プロジェクト: PoCTo/yamsh
Tree* ParseBuildTree(List* L,Err* E){
    if (L==NULL) return NULL;
    List* Lold=L;
    Tree* Told;
    Tree* T=TreeInit();
    ParseStates state=CMD;
    ParseMorpheme("(",&state,&T);
    while (state!=PARSEERROR && L!=NULL){
        Lold=L;
        ParseMorpheme((char*)L->data,&state,&T);
        L=L->next;
    }
    ParseMorpheme(")",&state,&T);
    if (state==PARSEERROR){
        if (T!=NULL) while (T->parent!=NULL) T=T->parent;
        TreeFree(T);
        E->pres=1;
        E->err=realloc(E->err,(50+strlen(Lold->data)*sizeof(char)));
        strcpy(E->err,"Syntax error near: \0");
        strcpy((E->err)+strlen(E->err),(char*)Lold->data);
        return NULL;
    }
    Told=T;
    while (T->parent!=NULL) T=T->parent;
    ParseTreeFixNULL(T);
    return T;
}
コード例 #4
0
ファイル: TdiGetDbi.c プロジェクト: LucyScott/mdsplus
/*-------------------------------------------------------------------
        Use a different default, shot, or experiment.
                USING(expression, [DEFAULT], [SHOTID], [EXPT])
        Note that DEFAULT may be NID/PATH and will not be data at same.
*/
STATIC_ROUTINE int fixup_nid(int *pin, /* NID pointer */ int arg,
                             struct descriptor_d *pout)
{
    int status = 0;
    char *path = TreeGetPath(*pin);
    if (path != NULL) {
        unsigned short len = (unsigned short)strlen(path);
        StrCopyR(pout, &len, path);
        TreeFree(path);
        status = 1;
    }
    return status;
}
コード例 #5
0
ファイル: Broker.c プロジェクト: eclipse/mosquitto.rsmb
/**
 * Shutdown the broker.
 * @param rc - startup success code
 */
void Broker_shutdown(int rc)
{
	FUNC_ENTRY;
	if (rc != -99)
	{
		time_t now = 0;

		Log_setPublish(false);
#if !defined(NO_BRIDGE)
		Bridge_terminate(&(BrokerState.bridge));
#endif
		if (rc != -98)
		{
			if (rc != -97)
			{
				if (BrokerState.persistence)
					SubscriptionEngines_save(BrokerState.se);
				Protocol_terminate();
				Socket_terminate();
				SubscriptionEngines_terminate(BrokerState.se);

				Log(LOG_INFO, 44, NULL, BrokerState.msgs_sent);
				Log(LOG_INFO, 43, NULL, BrokerState.msgs_received);
				time(&(now));
				Log(LOG_INFO, 42, NULL, (int)difftime(now, BrokerState.start_time));
				Log(LOG_INFO, 55, NULL, Heap_get_info()->max_size);
			}
		}
		TreeFree(BrokerState.clients);
		TreeFree(BrokerState.disconnected_clients);
#if defined(MQTTS)
		TreeFree(BrokerState.mqtts_clients);
		TreeFree(BrokerState.disconnected_mqtts_clients);
#endif
		Persistence_free_config(&BrokerState);
	}
	FUNC_EXIT;
}
コード例 #6
0
ファイル: Interpreter.c プロジェクト: cool91788/OpenComputer
void interpret(char *cFile) { // 解譯器主程式                  
	printf("interpret file:%s\n", cFile);
	char *cText = fileToStr(cFile);               //   讀取檔案到 cText 字串中。   
	SymTable *symTable = SymTableNew();
	Scanner *scanner = ScannerNew(cText);
	Tree *tree = parse(cText, symTable);           //   剖析程式 (cText) 轉為語法樹 
/*	Interpreter *inter = InterNew(); 
	inter->tree = parser->tree;
	char rzVar[100];
	InterRun(inter, inter->tree, rzVar);
	InterFree(inter); */
	TreeFree(tree);
	memFree(cText);
	ERROR();
}
コード例 #7
0
ファイル: TdiGetDbi.c プロジェクト: LucyScott/mdsplus
STATIC_ROUTINE int fixup_path(struct descriptor *pin, int arg,
                              struct descriptor_d *pout)
{
    int status = 0;
    char *pathin = MdsDescrToCstring(pin);
    char *path = TreeAbsPath(pathin);
    MdsFree(pathin);
    if (path != NULL) {
        unsigned short len = (unsigned short)strlen(path);
        StrCopyR(pout, &len, path);
        TreeFree(path);
        status = 1;
    }
    return status;
}
コード例 #8
0
ファイル: parse.c プロジェクト: PoCTo/yamsh
Tree* ParseFull(char* c, Err* E){
    Tree* T;
    List* L=ParseBuildList(c,E);
    (E->pres)=0;
    if ((E->pres)==1) {
        ListClear(L);
        return NULL;
    }
    T=ParseBuildTree(L,E);
    ListClear(L);
    if ((E->pres)==1) {
        TreeFree(T);
        return NULL;
    }
    return T;
}
コード例 #9
0
ファイル: Socket.c プロジェクト: charliexp/mqttsn_secure
/**
 * Terminate the socket module for outbound communications only
 */
void Socket_outTerminate()
{
	FUNC_ENTRY;
#if defined(USE_POLL)
	TreeFree(s.fds_tree);
#else
	ListFree(s.connect_pending);
	ListFree(s.write_pending);
	ListFree(s.clientsds);
#endif
	ListFree(s.newSockets);
	SocketBuffer_terminate();
#if defined(WIN32)
	WSACleanup();
#endif
	FUNC_EXIT;
}
コード例 #10
0
ファイル: l8590_mem.c プロジェクト: LucyScott/mdsplus
static void Load(Widget w)
{
  char *l8590_memname;
  static char nodename[13];
  static NCI_ITM itmlst[] = {{12,NciNODE_NAME,nodename,0},{0,0,0,0}};
  int i;
  XtPointer temp;
  int nid;
  int found = False;
  XtVaGetValues(w, XmNuserData, &temp, NULL);
  nid =  (intptr_t)temp;
  l8590_memname = TreeGetPath(nid);
  XmListDeleteAllItems(w);
  for (i=1;i<17;i++)
  {
    int ctx = 0;
    int dig_nid;
    int status;
    XmString item;
    char digname[512];
    sprintf(digname,"%s:L8590_%d",l8590_memname,i);
    status = TreeFindNode(digname,&dig_nid);
    if (status & 1)
    {
      TreeGetNci(dig_nid,itmlst);
      item = XmStringCreateSimple(nodename);
      XmListAddItem(w, item, 0);
      XmStringFree(item);
      found = True;
    }
    else
      break;
  }
  TreeFree(l8590_memname);
  if (!found)
  {
    XmString item = XmStringCreateSimple("Add L8590_1");
    XmListAddItem(w, item, 0);
    XmStringFree(item);
  }
}
コード例 #11
0
ファイル: debug.c プロジェクト: PoCTo/yamsh
void printcommandtree(char* cmd){
    Err* E=ErrInit();
    FILE *f=NULL;
    Tree* T=ParseFull(cmd,E);
    if ((E->pres)==0) ErrFree(E);
    else {
        f=fopen("/tmp/shell.dot","w");
        //if (f<0) perror("Debug file open");
        printf("%s\n",E->err);
        ErrFree(E);
        fclose(f);
        return;
    }
    f=fopen("/tmp/shell.dot","w");
    //if (f<0) perror("Debug file open");
    fprintf(f,"Digraph mega{\n");
    printtree(T,f);
    TreeFree(T);
    fprintf(f,"}\n");
    fclose(f);
}
コード例 #12
0
	/****************************************************************
	 * TclDirectory:
	 * Perform directory function
	 ****************************************************************/
int   TclDirectory()
   {
    unsigned int   usage;
    char  *tagnam;
    char  textLine[128];
    static char  fmtTotal[] = "Total of %d node%s.";
    static char  fmtGrandTotal[] = "Grand total of %d node%s.";
    static DYNAMIC_DESCRIPTOR(dsc_nodnam);
    static DYNAMIC_DESCRIPTOR(dsc_nodeList);
    static DYNAMIC_DESCRIPTOR(dsc_outline);
    char  *pathnam;

    int nid;
    int status;
    void  *ctx = 0;
    void  *ctx2 = 0;
    int   found = 0;
    int   grand_found = 0;
    int   first_tag;
    int   full;
    static int   nodnamLen;

    static int   retlen;
    int last_parent_nid = -1;
    int version;
    static int parent_nid;
    static char nodnamC[12+1];
    static int relationship;
    int previous_relationship;
    static unsigned char nodeUsage;
    static NCI_ITM general_info_list[] = {
          {4,NciPARENT,&parent_nid,0}
         ,{12,NciNODE_NAME,nodnamC,&nodnamLen}
         ,{4,NciPARENT_RELATIONSHIP,&relationship,0}
         ,{1,NciUSAGE,&nodeUsage,0}
         ,{0,NciEND_OF_LIST,0,0}
         };
    static int elmnt;
    static DYNAMIC_DESCRIPTOR(dsc_allUsage);
    static DYNAMIC_DESCRIPTOR(dsc_usageStr);
    int usageMask = -1;


    parent_nid = 0;

    full = cli_present("FULL") & 1;
    if (cli_present("USAGE") & 1)
       {
        usageMask = 0;
        str_free1_dx(&dsc_allUsage);
        while (cli_get_value("USAGE",&dsc_usageStr) & 1)
           {
            str_concat(&dsc_allUsage,&dsc_allUsage,&dsc_usageStr,",",0);

            str_concat(&dsc_usageStr,"USAGE.",&dsc_usageStr,0);
            if (cli_get_value(&dsc_usageStr,&dsc_usageStr) & 1)
               {
                sscanf(dsc_usageStr.dscA_pointer,"%d",&usage);
                usageMask = usageMask | (1 << usage);
               }
            else
                MdsMsg(0,"Error getting usage id#",0);
           }
       }
    str_free1_dx(&dsc_outline);
    while (cli_get_value("NODE",&dsc_nodeList) & 1)
       {
        l2u(dsc_nodeList.dscA_pointer,0);
        for (elmnt=0; str_element(&dsc_nodnam,elmnt,',',&dsc_nodeList) & 1; elmnt++)
           {
            while ((status = TreeFindNodeWild(dsc_nodnam.dscA_pointer,&nid,&ctx,usageMask)) & 1)
               {
                grand_found++;
                status = TreeGetNci(nid,general_info_list);
                nodnamC[nodnamLen] = '\0';
                if (parent_nid != last_parent_nid)
                   {
                    if (found)
                       {
                        if (!full && dsc_outline.dscW_length)
			{
                            TclTextOut(dsc_outline.dscA_pointer);
                            str_free1_dx(&dsc_outline);
                        }
                        TclTextOut("  ");
                        sprintf(textLine,fmtTotal,found,(found>1)?"s":"");
                        TclTextOut(textLine);
                       }
                    TclTextOut("  ");
                    pathnam = TreeGetPath(parent_nid);
                    TclTextOut(pathnam);
                    TreeFree(pathnam);		/* free the string	*/
                    TclTextOut("  ");
                    found = 0;
                    last_parent_nid = parent_nid;
                    previous_relationship = relationship;
                   }
                found++;
                if (full)
                   {
                    if (previous_relationship != relationship)
                       {
                        TclTextOut("  ");
                        previous_relationship = relationship;
                       }
                    if (relationship == NciK_IS_CHILD)
                        str_concat(&dsc_outline,"  ",nodnamC,0);
                    else
                        str_concat(&dsc_outline," :",nodnamC,0);

                    ctx2 = 0;
                    first_tag = 1;
                    while (tagnam = TreeFindNodeTags(nid,&ctx2))
                       {
                        str_concat(&dsc_outline,&dsc_outline,
                                (first_tag?" tags: \\":",\\"),tagnam,0);
                        TreeFree(tagnam);
                        first_tag = 0;
                       }
                    TclTextOut(dsc_outline.dscA_pointer);
                    str_free1_dx(&dsc_outline);
                    version=0;
                    while(doFull(nid,nodeUsage,version++)&1);
#ifdef vms
                    else
                      lib$signal(status,0);
#endif
                   }
                else
                   {
                    if (previous_relationship != relationship)
                       {
                        TclTextOut(dsc_outline.dscA_pointer);
                        str_free1_dx(&dsc_outline);
                        TclTextOut("  ");
                        previous_relationship = relationship;
                       }
                    if (relationship == NciK_IS_CHILD)
                        str_concat(&dsc_outline,
                            &dsc_outline,"  ",nodnamC,0);
                    else
                        str_concat(&dsc_outline,
                            &dsc_outline," :",nodnamC,0);
                    if (dsc_outline.dscW_length > 60)
                       {
                        TclTextOut(dsc_outline.dscA_pointer);
                        str_free1_dx(&dsc_outline);
                       }
                   }
               }
            TreeFindNodeEnd(&ctx);
           }
コード例 #13
0
ファイル: t4012.c プロジェクト: LucyScott/mdsplus
static int ReadChannel(InStoreStruct *setup, int chunk,int samples,unsigned short *buffer,int *samples_read,int *nid,float *calib)
{
  int chunk_address =  0x0B000 | chunk;
  int points_to_read;
  int status=1;
  int tries;
  for (points_to_read = chunksize; status & 1 && points_to_read; points_to_read = chunksize)
  {
    struct { unsigned short status;
             unsigned short bytcnt;
             unsigned int   dummy;} iosb = {0,0};
    int try;
    static DESCRIPTOR_A(calib_a, sizeof(*calib), DTYPE_NATIVE_FLOAT, 0, 2*sizeof(*calib));
    static DESCRIPTOR_NID(nid_dsc,0);
    void *arglist[] = {0,&nid_dsc,&calib_a MDS_END_ARG};
    calib_a.pointer = (char *)calib;
    nid_dsc.pointer = (char *)nid;
    arglist[0] = (void *)(sizeof(arglist)/sizeof(arglist[0]));
    AccessTraq(setup,chunk_address,24,arglist,TdiData);
    pio(8,0,0);
    for (try = 0;(try < 20) && (!(CamQ(0)&1)) && (status & 1);try++) {pio(8,0,0);}
    pio(10,0,0);
    return_on_error(DevCamChk(CamQstopw(setup->name,0,2,points_to_read,buffer + *samples_read,16,(short *)&iosb),&one,0),status);
    status = status & 1 ? iosb.status : status;
    *samples_read += iosb.bytcnt/2;
    if (iosb.bytcnt/2 != points_to_read) break;
    chunk_address += max_chunks_per_io;
  }
  return status;
}

static int AccessTraq(InStoreStruct *setup, int data,int memsize,void *arglist,int (*routine)())
{ int try;
  int status;
  int called = 0;
  if (max_time > 0) {
    if ((time(0)-start_time) > max_time) {
      printf("T4012 AccessTraq timeout, data=%d\n",data);
      return DEV$_BAD_MODE;
    }
  }
  piomem(17,0,&data,memsize);
  for (try = 0;(try < 30) && (!(CamQ(0)&1)) && (status &1);try++) 
  {
    if (arglist && !called) {
      called = 1;
      LibCallg(arglist,routine);
    }
    else
      DevWait((float).001);
    piomem(17,0,&data,memsize);
  }
  if (try == 30) status = DEV$_CAM_NOSQ;
  if (arglist &&!called) LibCallg(arglist,routine);
  return status;
}

int t4012__dw_setup( struct descriptor *niddsc, struct descriptor *methoddsc, Widget parent)
{ 
  static String uids[] = {"T4012.uid"};
  static int nid;
  static MrmRegisterArg uilnames[] = {{"nid",(XtPointer)0},{"Load",(XtPointer)Load}};
  static NCI_ITM   nci[] = {{4, NciCONGLOMERATE_NIDS, (unsigned char *)&nid, 0}, {0, NciEND_OF_LIST, 0, 0}};
  TreeGetNci(*(int *)niddsc->pointer, nci);
  uilnames[0].value = (char *)0+nid;
  return XmdsDeviceSetup(parent, (int *)niddsc->pointer, uids, XtNumber(uids), "T4012", uilnames, XtNumber(uilnames), 0);
}

static void Load(Widget w)
{
  char *t4012name;
  char dignam[512];
  int i;
  XtPointer user_data;
  int nid;
  int found = False;
  XtVaGetValues(w, XmNuserData, &user_data, NULL);
  nid = (intptr_t)user_data;
  t4012name = TreeGetPath(nid);
  strcpy(dignam,t4012name);
  strcat(dignam,":T28%%_");
  TreeFree(t4012name);
  XmListDeleteAllItems(w);
  for (i=1;i<17;i++)
  {
    int dig_nid;
    int status;
    XmString item;
    int len = strlen(dignam);
    dignam[len++]=i<10 ? '0' : '1';
    dignam[len++]='0'+(i % 10);
    dignam[len++]=0;
    status = TreeFindNode(dignam,&dig_nid);
    if (status & 1)
    {
      NCI_ITM itmlst[] = {{512,NciNODE_NAME,0,0},{0,0,0,0}};
      itmlst[0].pointer = dignam;
      TreeGetNci(dig_nid,itmlst);
      item = XmStringCreateSimple(dignam);
      XmListAddItem(w, item, 0);
      XmStringFree(item);
      found = True;
    }
    else
      break;
  }
  if (!found)
  {
    XmString item = XmStringCreateSimple("Add T28xx_01");
    XmListAddItem(w, item, 0);
    XmStringFree(item);
  }
}
コード例 #14
0
ファイル: t4012.c プロジェクト: LucyScott/mdsplus
int t4012___store(int *niddsc, InStoreStruct *setup)
{ 
  int channels;
  int pts;
  int memPerChannel;
  int channels_read;
  int dig;
  int dig_nid;
  static int memsize=0;
  static unsigned short *mem;
  int idxmin;
  int idxmax;
  char digname[512];
  char *nodename;
  int chan_nid = 0;
  struct _t4012_status { unsigned    sampling  : 1;
                         unsigned    calibrate : 1;
                         unsigned    master_armed : 1;
                         unsigned    master_enabled : 1;
                         unsigned    stop_received : 1;
                         unsigned    triggered : 1;
                         unsigned    t4012p : 1;
                         unsigned    cal_mem : 1;
                         unsigned : 24;
                       } dig_status;
  int status;
  static short offset;
  static float coefficient;
  static float f[2];
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0);
  static int *lbound = &raw.bounds[0].l;
  static int *ubound = &raw.bounds[0].u;
  static unsigned int *acoef  = &raw.m[0];
  static DESCRIPTOR_A(f2_d,sizeof(f[0]),DTYPE_NATIVE_FLOAT,f,8);
  static DESCRIPTOR(counts_str,"counts");
  static DESCRIPTOR(volts_str,"volts");
  static DESCRIPTOR(seconds_str,"seconds");
  static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l);
  static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u);
  static int trigger_nid;
  static DESCRIPTOR_NID(stop_d,&trigger_nid);
  static int switch_trig_nid;
  static DESCRIPTOR_NID(swi_d,&switch_trig_nid);
  static int extern_clock_nid;
  static DESCRIPTOR_NID(ext_clock_d,&extern_clock_nid);
  static struct descriptor offset_d = {2,DTYPE_W, CLASS_S, (char *)&offset};
  static DESCRIPTOR_FLOAT(coef_d,&coefficient);
  static DESCRIPTOR_FLOAT(f1_d,f);
  static int _roprand = 32768;
  static DESCRIPTOR_FLOAT(roprand,&_roprand);
  static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0};
  static DESCRIPTOR_FUNCTION_2(subtract_exp,(unsigned char *)&OpcSubtract,&value,&offset_d);
  static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&subtract_exp);
  static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str);
  static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str);
  static DESCRIPTOR_FUNCTION_2(rangesub,(unsigned char *)&OpcSubtract,0,&f1_d);
  static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&stop_d);
  static struct descriptor *begin_ptrs[] = {&roprand,0};
  static struct descriptor *end_ptrs[] = {(struct descriptor *)&rangesub,&roprand};
  static DESCRIPTOR_APD(begin_apd,0,begin_ptrs,2);
  static DESCRIPTOR_APD(end_apd,0,end_ptrs,2);
  static DESCRIPTOR_RANGE(int_clock1_d,0,0,&f1_d);
  static DESCRIPTOR_RANGE(int_clock2_d,&begin_apd,&end_apd,&f2_d);
  static int clock_out_nid;
  static DESCRIPTOR_NID(clock_out_d,&clock_out_nid);
  static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out_d);
  static DESCRIPTOR_WITH_UNITS(seconds,&dimension,&seconds_str);
  static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&seconds);
  void *ctx = 0;
  max_time=-1;
  trigger_nid = setup->head_nid + T4012_N_TRIGGER;
  switch_trig_nid = setup->head_nid + T4012_N_SWITCH_TRIG;
  extern_clock_nid = setup->head_nid + T4012_N_EXTERN_CLOCK;
  clock_out_nid = setup->head_nid + T4012_N_CLOCK_OUT;
  pio(8,0,0);
  status = Input(setup,14);
  dig_status = *(struct _t4012_status *)&status;
  if (dig_status.sampling)
  {
    return DEV$_NOT_TRIGGERED;
  }
  channels = Input(setup,1);
  pts = Input(setup,2);
  memPerChannel = Input(setup,3) * 1024;

  if (Input(setup,7) == 1)
    TreePutRecord(clock_out_nid,(struct descriptor *)&ext_clock_d,0);
  else
  {
    int shift = Input(setup,6);
    f[0] = freqs[Input(setup,4)];
    if (shift)
    {
      f[1] = freqs[Input(setup,5)];
      rangesub.arguments[0] = begin_ptrs[1] = (shift == 1) ? &swi_d : &stop_d;
      TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock2_d,0);
    }
    else
      TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock1_d,0);
  }
  idxmin = (pts - 8.)/8. * memPerChannel;
  idxmax = idxmin + memPerChannel - 1;
  if (memsize < (memPerChannel * 2))
  {
    if (memsize) free(mem);
    memsize = memPerChannel * 2;
    mem = malloc(memsize);
  }
  return_on_error(AccessTraq(setup,0x8001,16,0,0),status); /* Remote control */
  nodename = TreeGetPath(setup->head_nid);
  strcpy(digname,nodename);
  TreeFree(nodename);
  strcat(digname,":T28%%_%%");
  status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE);
  for (dig=1,channels_read=0;(channels_read < channels) && (status & 1);dig++)
  {
    static int dig_nids[1+8*T28XX_K_NODES_PER_INP];
    static int nidlen;
    static NCI_ITM itmlst[] = {{sizeof(dig_nids),NciCONGLOMERATE_NIDS,(unsigned char *)&dig_nids,&nidlen},
                               {0,NciEND_OF_LIST,0,0}};
    if (status & 1)
    {
      int i;
      int digchannels;
      status = TreeGetNci(dig_nid,itmlst);
      digchannels = (nidlen/sizeof(dig_nid)-1)/T28XX_K_NODES_PER_INP;
      for (i=0;i<digchannels && (status & 1) && channels_read < channels;i++)
      {
        if (TreeIsOn(CNID(i,HEAD))&1)
        {
          int channel_select = 0x0A000 | (channels_read + 1);
          AccessTraq(setup,channel_select,24,0,0);
          if (chan_nid && (*acoef > 1))
          {
            return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status);
            chan_nid = 0;
          }
          else
            DevWait((float).005);

          chan_nid = CNID(i,HEAD);
          *lbound = (DevLong(&CNID(i,STARTIDX),(int *)lbound) & 1) ? min(idxmax,max(idxmin,*lbound)) : idxmin;
          *ubound = (DevLong(&CNID(i,ENDIDX), (int *)ubound) & 1) ?  min(idxmax,max(idxmin,*ubound)) : idxmax;
          *acoef = *ubound - *lbound + 1;
          if (*acoef > 0)
          {
            int points_read = 0;
            int first_sample_offset = *lbound-idxmin;
            int chunk = first_sample_offset/1024;
            int chunk_offset = first_sample_offset % 1024;
            float calib[]={0,0};
            status = ReadChannel(setup, chunk,*acoef+chunk_offset,mem,&points_read,&CNID(i,CALIBRATION),calib);
            if (status & 1)
            {
              offset = calib[0];
              if (calib[0] == calib[1])
                coefficient = (offset > 1000) ? 10./4096 : 5./4096.;
              else
                coefficient = calib[1];
              raw.pointer = (char *)(mem + chunk_offset);
              raw.a0 = raw.pointer - *lbound * sizeof(*mem);
              *ubound = (points_read - chunk_offset) + *lbound - 1;
              *acoef = (points_read - chunk_offset);
              raw.arsize = *acoef * 2;
            }
          }
        }
        channels_read++;
      }
    }
    if (channels_read < channels  && (status & 1)) status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE);
  }
  TreeFindNodeEnd(&ctx);
  if (chan_nid && (*acoef > 1)) return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status);
  return status;
}
コード例 #15
0
ファイル: nnhierarchy.c プロジェクト: cyb3727/annrecognition
int main(int argc, char **argv)
{
  char *nn_file;
  FILE *fp;
  int **samples, **s1, **s2;
  int i,j,k,c;
  int num_samples;
  int nclusters;
  Partition p;
  int min_dist_thres, max_dist_thres;
  Tree *trees, tree;

  if(argc < 6) {
    printf("Usage:\n%s <nn_file> <num_samples> <shared_thres> <start_dist_thres> <end_dist_thres>\n",
	   argv[0]);
    printf("To generate a hierarchy from <num_samples> lines of the neighbor file <nn_file>.\n");
    printf("dist_thres = distance threshold (k-nearest)\n");
    printf("end_dist_thres <= neighbors in nn_file\n");
    printf("tree goes to stdout\n");
    exit(1);
  }

  nn_file = argv[1];
  num_samples = atoi(argv[2]);
  shared_thres = atoi(argv[3]);
  min_dist_thres = atoi(argv[4]);
  max_dist_thres = atoi(argv[5]);

  /* Read in neighbor file */
  fp = fopen(nn_file, "r");
  if(!fp) {
    printf("Cannot open `%s'\n", nn_file);
    exit(1);
  }
  samples = Allocate(num_samples, int*);
  for(s1=samples,i=0;i<num_samples;s1++,i++) {
    *s1 = Allocate(max_dist_thres+1, int);
    for(j=0;j<=max_dist_thres;j++) {
      fscanf(fp, "%d", &(*s1)[j]);
    }
    while(fgetc(fp) != '\n');
  }
  fclose(fp);

  /* Initialize the partition and trees */
  p = PartitionCreate(num_samples);
  trees = Allocate(num_samples, Tree);
  for(i=0;i<num_samples;i++) {
    trees[i] = TreeCreate(IntCreate(i+BASE));
  }

  /* loop all possible partitions */
#if JP
  dist_thres = max_dist_thres;
  for(;shared_thres >= 0;shared_thres--) {
#else
  for(dist_thres = min_dist_thres;dist_thres <= max_dist_thres;dist_thres++) {
#endif
    /* Form clusters */
    PartitionRefine(p, (void*)samples, (CmpFunc*)EquivNN);

    /* Set j = size of largest class */
    j = PartitionClassSize(p,1);
    for(c=2;c <= p->num_classes;c++) {
      i = PartitionClassSize(p,c);
      if(i > j) j = i;
    }
    fprintf(stderr, "%d %d %d %d ", 
	    dist_thres, shared_thres, p->num_classes, j);
    fprintf(stderr, "\n");
    fflush(stdout);

    /* create next level of tree */
    /* loop classes */
    for(c = 1;c <= p->num_classes;c++) {
      if(PartitionClassSize(p, c) <= 1) continue;
      tree = TreeCreate(IntCreate(dist_thres));
      {PartitionIter(p,c,e) {
        TreeAddChildUnique(tree, trees[e]);
        trees[e] = tree;
      }}
    }
  }
  PartitionFree(p);

  /* put all existing trees under one tree */
  tree = TreeCreate(IntCreate(dist_thres));
  for(i=0;i<num_samples;i++) {
    TreeAddChildUnique(tree, trees[i]);
  }

  TreeWrite(stdout, tree, IntWrite);
  TreeFree(tree, free);
  exit(0);
}
コード例 #16
0
ファイル: io.c プロジェクト: skewray/skewray_old
void IOfree(void)
    {
    TreeFree( tree, free ) ;
    tree = (TREE *) 0 ;			/* so that it can't be referenced */
    }
コード例 #17
0
STATIC_ROUTINE int DependencyGet(int prec,
                                 struct descriptor_r *pin,
                                 struct descriptor_d *pout)
{
    int now = 0, status = 1;
    struct descriptor *pwhich = 0;

    switch (pin->dtype) {
    case DTYPE_EVENT:
        status =
            StrConcat((struct descriptor *)pout, (struct descriptor *)pout,
                      &LEFT_ANGLE, pin, &RIGHT_ANGLE MDS_END_ARG);
        break;
    case DTYPE_NID:
        {
            char *path = TreeGetMinimumPath(0, *(int *)pin->pointer);
            if (path != NULL) {
                DESCRIPTOR_FROM_CSTRING(path_d, path);
                status = StrAppend(pout, &path_d);
                TreeFree(path);
            } else
                status = TreeFAILURE;
        }
        break;
    case DTYPE_PATH:
        status = StrAppend(pout, pin);
        break;
    case DTYPE_DEPENDENCY:
        switch (*(short *)pin->pointer) {
        case TreeDEPENDENCY_AND:
            now = P_AND;
            pwhich = (struct descriptor *)&AND;
            break;
        case TreeDEPENDENCY_OR:
            now = P_OR;
            pwhich = (struct descriptor *)&OR;
            break;
        default:
            status = TdiINV_OPC;
            break;
        }
        if (status & 1 && now < prec)
            status = StrAppend(pout, &LEFT_PAREN);
        if (status & 1)
            status =
                DependencyGet(now - 1, (struct descriptor_r *)pin->dscptrs[0],
                              pout);
        if (status & 1)
            status = StrAppend(pout, pwhich);
        if (status & 1)
            status =
                DependencyGet(now + 1, (struct descriptor_r *)pin->dscptrs[1],
                              pout);
        if (status & 1 && now < prec)
            status = StrAppend(pout, &RIGHT_PAREN);
        break;
    case DTYPE_CONDITION:
        switch (*((short *)pin->pointer)) {
        case TreeNEGATE_CONDITION:
            pwhich = (struct descriptor *)&NEGATE;
            break;
        case TreeIGNORE_UNDEFINED:
            pwhich = (struct descriptor *)&IGNORE_UNDEFINED;
            break;
        case TreeIGNORE_STATUS:
            pwhich = (struct descriptor *)&IGNORE_STATUS;
            break;
        default:
            status = TdiINV_OPC;
            break;
        }
        if (status & 1)
            status = StrAppend(pout, pwhich);
        if (status & 1)
            status =
                DependencyGet(P_UNARY, (struct descriptor_r *)pin->dscptrs[0],
                              pout);
        break;
    default:
        status = TdiINVDTYDSC;
        break;
    }
    return status;
}
コード例 #18
0
ファイル: TdiGetDbi.c プロジェクト: LucyScott/mdsplus
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;
}
コード例 #19
0
ファイル: TdiGetDbi.c プロジェクト: LucyScott/mdsplus
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;
}