Exemplo n.º 1
0
void qsort_3 (int *arr, int size, const int numThreads) {
  //temp vals
  int i;
  //initialize stack
  stackT work;
  stackElementT element = {0, size-1};
  StackInit (&work, 2*(size/SWITCH_THRESH+1));
  StackPush (&work, element);
  //initialize all threads
  pthread_t *threads;
  threads = malloc (numThreads * sizeof(pthread_t));
  /*
  if (posix_memalign((void **)&threads, sizeof(pthread_t), MAX_THRDS*sizeof(pthread_t))) {
    perror("posix_memalign");
    exit(-1);
  }
  */
  int busyThreads = 0;
  struct qsort_3_args shared_arg = {arr, &work, &busyThreads};
  for (i = 0; i < numThreads; i++) {
#ifdef DEBUG
    printf("Creating thread %d\n", i+1);
#endif
    if (pthread_create(&threads[i], NULL, qsort_3_thread, &shared_arg)) {
      perror("pthread_create");
      exit(-1);
    }
  }
#ifdef DEBUG
  printf("Created all threads\n");
#endif
  //destroy all threads
  int status;
  for (i=0; i<numThreads; i++) {
#ifdef DEBUG
    printf("Joining thread %d\n", i+1);
#endif
    pthread_join(threads[i], (void **)&status);
  }
#ifdef DEBUG
  printf("Joined all threads\n");
#endif
  free(threads);
  //destroy stack
  StackDestroy (&work);
  return;
}
Exemplo n.º 2
0
void CreateProc(pstack_t **head, struct SyncMethod *type, char *_Str) {
	char *str_buf, *number_buf;
	proc_t process;
	type->process_count++;
	str_buf = (char *)malloc(MAX_STR_SIZE * sizeof(char));
	if (str_buf == NULL) {
		StackClear(head);
		ErrorMessage("Memory allocation error. ");
		exit(EXIT_FAILURE);
	}
	number_buf = (char *)malloc(MAX_PROC_COUNT * sizeof(char));
	if (number_buf == NULL) {
		free(str_buf);
		StackClear(head);
		ErrorMessage("Memory allocation error. ");
		exit(EXIT_FAILURE);
	}
	itoa(type->process_count, number_buf, 10);
	strcpy(str_buf, _Str);
	strcat(str_buf, " ");
	strcat(str_buf, number_buf);
	ZeroMemory(&(process.startupInfo), sizeof(process.startupInfo));
	(process.startupInfo).cb = sizeof(process.startupInfo);
	ZeroMemory(&(process.procInfo), sizeof(process.procInfo));
	if (!CreateProcess(NULL, 
					   str_buf, 
					   NULL,	
					   NULL, 
					   FALSE, 
					   0, 
					   NULL, 
					   NULL, 
					   &(process.startupInfo), 
					   &(process.procInfo))) {
		free(str_buf);
		free(number_buf);
		StackClear(head);
		ErrorMessage("Process creation error.");
		exit(EXIT_FAILURE);
	}
	StackPush(process, head);
	free(str_buf);
	free(number_buf);
	return;
}
void LoadBalanceInverseOperator::Reshape(Ifpack_Preconditioner* prec, 
                                         const LoadBalanceOperator& Op, 
                                         const bool ownership)
{
  ResetTimer();
  StackPush();

  Op_ = Op;

  if (GetParticipation()) RCPRowMatrix_ = Op.GetRCPRowMatrix();
  else                    RCPRowMatrix_ = Teuchos::null;

  if (GetParticipation()) RCPData_ = Teuchos::rcp(prec,ownership);
  else                    RCPData_ = Teuchos::null;

  StackPop();
  UpdateTime();
}
Exemplo n.º 4
0
int 
InverseOperator::Apply(const MultiVector& x, MultiVector& y) const
{
  ResetTimer();
  StackPush();

  if (GetDomainSpace() != x.GetVectorSpace())
    ML_THROW("DomainSpace and x.GetVectorSpace() differ", -1);

  if (GetRangeSpace() != y.GetVectorSpace())
    ML_THROW("RangeSpace and y.GetVectorSpace() differ", -1);

  int x_nv = x.GetNumVectors();
  int y_nv = y.GetNumVectors();
  double FL = 0.0;
  if (RCPData_ != Teuchos::null)
    FL = RCPData_->ComputeFlops();

  if (x_nv != y_nv)
    ML_THROW("Number of vectors of x and y differ (" +
             GetString(x_nv) + " vs. " + GetString(x_nv), -1);

  for (int v = 0 ; v < x_nv ; ++v) {

    Epetra_Vector x_Epetra(View,RowMatrix()->OperatorDomainMap(),
                           (double*)&(x(0,v)));
    Epetra_Vector y_Epetra(View,RowMatrix()->OperatorRangeMap(),
                           (double*)&(y(0,v)));

    if (RCPData_ != Teuchos::null)
      RCPData_->ApplyInverse(x_Epetra,y_Epetra);
    else if (RCPMLPrec_ != Teuchos::null)
      RCPMLPrec_->ApplyInverse(x_Epetra,y_Epetra);
    else
      ML_THROW("Neither Ifpack nor ML smoother is properly set up", -1);
  }

  StackPop();
  if (RCPData_ != Teuchos::null)
    UpdateFlops(RCPData_->ComputeFlops() - FL);
  UpdateTime();

  return(0);
}
Exemplo n.º 5
0
int main(void)
{
  Stack s;
  
  if(StackAlloc(&s, 100) == -1){
    puts("すたっくの確保に失敗しました。");
    return (1);
  }
  
  while(1){
    int m, x;
    
    printf("現在のでーた数:%d/%d\n", StackNo(&s), StackSize(&s));
    printf("(1)ぷっしゅ (2)ぽっぷ (0)終了 :");
    scanf("%d", &m);

    if(m == 0){
      break;
    }

    switch (m){
    case 1:
      printf("でーた:");
      scanf("%d", &x);
      if(StackPush(&s, x) == -1){
	puts("すたっくへのぷっしゅに失敗しました。");
      }
      break;
    case 2:
      if(StackPop(&s, &x) == -1){
	puts("ぽっぷできません。");
      }else{
	printf("ぽっぷしたでーたは%dです。\n", x);
      }
      break;
    }
  }

  StackFree(&s);

  return (0);
}
Exemplo n.º 6
0
/** @brief This function gives the button functionality
	@param panel the panel handle of the panel on which the button is used
	@param control the control on which the event is generated
	@param event the type of event generated (i.e. left-click causes EVENT_COMMIT)
	@param *callbackData stores the data returned to the UI handled internally by LabWindows
	@param eventData1 stores ancillary information such as the mouse x-position within the panel
	@param eventData2 stores ancillary information such as the mouse y-position within the panel
	@return 1 or 0 specifies whether or not the event should be swallowed. 0 is default-no and 1 is yes-swallow.

### EXTERNAL VARIABLES
    - extern int @ref panelHandle - "OpenPET.c"
	- extern int @ref panelHandle_timemode_mb - "OpenPET.c"
	- extern int @ref panelHandle_timemode_duc - "OpenPET.c"
	- extern int @ref panelHandle_timemode_db - "OpenPET.c"
	- extern int @ref panelHandle_timemode - "OpenPET.c" 
	- extern Stack @ref panel_stack - "UI_Common.c"
	- extern OpenPETTree @ref current_location - "UI_Common.c"

### ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES
	Errors may be generated by CVI/LabWindows. The LabWindows documentation is available online 
	at <a href="linkURL"> http://zone.ni.com/reference/en-XX/help/370051V-01/ </a>.
	
###	ALGORITHM
	When the button is clicked, the current location is updated, the proper panel is displayed, and the
	stack is updated.
	
###	DEVELOPMENT HISTORY
       Date    |  Author         |  Email Address     | Ver. |Description Of Change  
	   --------|-----------------|--------------------|------|---------------------
	 08/09/2013| George Netscher | [email protected] | 1.0  |conclusion of summer work
	 
### Copyright (c) 2013 by LBNL. All Rights Reserved.
*/
int CVICALLBACK TimeModeDB (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			// switch on control for DB0...DB7
			switch (control)
			{
				case TIMEMODEDB_BUTTON_0:
					current_location.DB = 0;
					break;
				case TIMEMODEDB_BUTTON_1:
					current_location.DB = 1;
					break;
				case TIMEMODEDB_BUTTON_2:
					current_location.DB = 2;
					break;
				case TIMEMODEDB_BUTTON_3:
					current_location.DB = 3;
					break;
				case TIMEMODEDB_BUTTON_4:
					current_location.DB = 4;
					break;
				case TIMEMODEDB_BUTTON_5:
					current_location.DB = 5;
					break;
				case TIMEMODEDB_BUTTON_6:
					current_location.DB = 6;
					break;
				case TIMEMODEDB_BUTTON_7:
					current_location.DB = 7;
					break;
			}
			
			DisplayPanel (panelHandle_timemode);
			StackPush(&panel_stack, panel); 
			HidePanel (panel);
			break;
	}
	return 0;
}
Exemplo n.º 7
0
/** @brief This function gives the button functionality
	@param panel the panel handle of the panel on which the button is used
	@param control the control on which the event is generated
	@param event the type of event generated (i.e. left-click causes EVENT_COMMIT)
	@param *callbackData stores the data returned to the UI handled internally by LabWindows
	@param eventData1 stores ancillary information such as the mouse x-position within the panel
	@param eventData2 stores ancillary information such as the mouse y-position within the panel
	@return 1 or 0 specifies whether or not the event should be swallowed. 0 is default-no and 1 is yes-swallow.

### EXTERNAL VARIABLES
    - extern int @ref panelHandle - "OpenPET.c"
	- extern int @ref panelHandle_fmmode_mb - "OpenPET.c"
	- extern int @ref panelHandle_fmmode_duc - "OpenPET.c"
	- extern int @ref panelHandle_fmmode - "OpenPET.c" 
	- extern Stack @ref panel_stack - "UI_Common.c"
	- extern OpenPETTree @ref current_location - "UI_Common.c"

### ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES
	Errors may be generated by CVI/LabWindows. The LabWindows documentation is available online 
	at <a href="linkURL"> http://zone.ni.com/reference/en-XX/help/370051V-01/ </a>.
	
###	ALGORITHM
	When the button is clicked, the current location is updated, the proper panel is displayed, and the
	stack is updated.
	
###	DEVELOPMENT HISTORY
       Date    |  Author         |  Email Address     | Ver. |Description Of Change  
	   --------|-----------------|--------------------|------|---------------------
	 08/09/2013| George Netscher | [email protected] | 1.0  |conclusion of summer work
	 
### Copyright (c) 2013 by LBNL. All Rights Reserved.
*/
int CVICALLBACK FloodMapModeDUC (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			// switch on control for DUC0...DUC7
			switch (control)
			{
				case FMMODEDU_BUTTON_0:
					current_location.DUC = 0;
					break;
				case FMMODEDU_BUTTON_1:
					current_location.DUC = 1;
					break;
				case FMMODEDU_BUTTON_2:
					current_location.DUC = 2;
					break;
				case FMMODEDU_BUTTON_3:
					current_location.DUC = 3;
					break;
				case FMMODEDU_BUTTON_4:
					current_location.DUC = 4;
					break;
				case FMMODEDU_BUTTON_5:
					current_location.DUC = 5;
					break;
				case FMMODEDU_BUTTON_6:
					current_location.DUC = 6;
					break;
				case FMMODEDU_BUTTON_7:
					current_location.DUC = 7;
					break;
			}
			
			DisplayPanel (panelHandle_fmmode);
			StackPush(&panel_stack, panel); 
			HidePanel (panel);
			break;
	}
	return 0;
}
Exemplo n.º 8
0
/** @brief This function gives the button functionality
	@param panel the panel handle of the panel on which the button is used
	@param control the control on which the event is generated
	@param event the type of event generated (i.e. left-click causes EVENT_COMMIT)
	@param *callbackData stores the data returned to the UI handled internally by LabWindows
	@param eventData1 stores ancillary information such as the mouse x-position within the panel
	@param eventData2 stores ancillary information such as the mouse y-position within the panel
	@return 1 or 0 specifies whether or not the event should be swallowed. 0 is default-no and 1 is yes-swallow.

### EXTERNAL VARIABLES
    - extern int @ref panelHandle - "OpenPET.c"
	- extern int @ref panelHandle_usermode_mb - "OpenPET.c"
	- extern int @ref panelHandle_usermode_duc - "OpenPET.c"
	- extern int @ref panelHandle_usermode_db - "OpenPET.c"
	- extern int @ref panelHandle_usermode - "OpenPET.c" 
	- extern Stack @ref panel_stack - "UI_Common.c"
	- extern OpenPETTree @ref current_location - "UI_Common.c"

### ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES
	Errors may be generated by CVI/LabWindows. The LabWindows documentation is available online 
	at <a href="linkURL"> http://zone.ni.com/reference/en-XX/help/370051V-01/ </a>.
	
###	ALGORITHM
	When the button is clicked, the current location is updated, the proper panel is displayed, and the
	stack is updated.
	
###	DEVELOPMENT HISTORY
       Date    |  Author         |  Email Address     | Ver. |Description Of Change  
	   --------|-----------------|--------------------|------|---------------------
	 08/09/2013| George Netscher | [email protected] | 1.0  |conclusion of summer work
	 
### Copyright (c) 2013 by LBNL. All Rights Reserved.
*/
int CVICALLBACK UserModeMB (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			// switch on control for MB0...MB7
			switch (control)
			{
				case USERMODEMB_BUTTON_0:
					current_location.MB = 0;
					break;
				case USERMODEMB_BUTTON_1:
					current_location.MB = 1;
					break;
				case USERMODEMB_BUTTON_2:
					current_location.MB = 2;
					break;
				case USERMODEMB_BUTTON_3:
					current_location.MB = 3;
					break;
				case USERMODEMB_BUTTON_4:
					current_location.MB = 4;
					break;
				case USERMODEMB_BUTTON_5:
					current_location.MB = 5;
					break;
				case USERMODEMB_BUTTON_6:
					current_location.MB = 6;
					break;
				case USERMODEMB_BUTTON_7:
					current_location.MB = 7;
					break;
			}
			
			DisplayPanel (panelHandle_usermode_duc);
			StackPush(&panel_stack, panel); 
			HidePanel (panel);
			break;
	}
	return 0;
}
int main(void){

  int a[]={10,20,30,40,50,60};
  int array_size = sizeof(a)/sizeof(a[0]);
  int element_size = sizeof(int);
  int i;
  Stack stackInt;
 
  StackNew(&stackInt,element_size);
  for(i=0;i<array_size;i++){
    StackPush(&stackInt,&a[i]);
  }
  int value; 
  while(!StackEmpty(&stackInt)){
    StackPop(&stackInt, &value);
    printf("Popped Value: %d\n",value);
  }

  StackDispose(&stackInt);
  return 0;
}
stk_stack* RBEnumerate(rb_red_blk_tree* tree, void* low, void* high) {
  stk_stack* enumResultStack;
  rb_red_blk_node* nil=tree->nil;
  rb_red_blk_node* x=tree->root->left;
  rb_red_blk_node* lastBest=nil;

  enumResultStack=StackCreate();
  while(nil != x) {
    if ( 1 == (tree->comp_func(x->key,high)) ) { /* x->key > high */
      x=x->left;
    } else {
      lastBest=x;
      x=x->right;
    }
  }
  while ( (lastBest != nil) && (1 != tree->comp_func(low,lastBest->key))) {
    StackPush(enumResultStack,lastBest);
    lastBest=TreePredecessor(tree,lastBest);
  }
  return(enumResultStack);
}
Exemplo n.º 11
0
int main()
{
	const char *friends[] = {"xx", "jj", "kk"};
	Stack stringStack;
	StackNew(&stringStack, sizeof(char*), freeFn);

	int i;
	for(i = 0; i < 3; ++i) {
		char *copy = strdup(friends[i]);
		StackPush(&stringStack, &copy);
	}

	char *name;
	for(i = 0; i < 3; ++i) {
		StackPop(&stringStack, &name);
		printf("%s\n", name);
		free(name);
	}

	StackDispose(&stringStack);
	return 0;
}
Exemplo n.º 12
0
// ======================================================================
MultiVector Redistribute(const MultiVector& y, const int NumEquations)
{
  StackPush();

  if (y.GetMyLength() % NumEquations)
    ML_THROW("NumEquations does not divide MyLength()", -1);

  if (y.GetNumVectors() != 1)
    ML_THROW("Redistribute() works with single vectors only", -1);

  Space NewSpace(y.GetMyLength() / NumEquations);

  MultiVector y2(NewSpace, NumEquations);

  for (int i = 0 ; i < y2.GetMyLength() ; ++i)
    for (int j = 0 ; j < NumEquations ; ++j)
      y2(i, j) = y(j + NumEquations * i);

  StackPop();

  return(y2);
}
Exemplo n.º 13
0
STKSTACK
RbEnumerate (RBTREE tree, RBKEY low, RBKEY high)
{
	STKSTACK enumResultStack=0;
	RBNODE nil=tree->nil;
	RBNODE x=tree->root->left;
	RBNODE lastBest=nil;

	enumResultStack=StackCreate();
	while(nil != x) {
		if ( 0 < (TreeCompare(tree, x->key, high)) ) { /* x->key > high */
			x=x->left;
		} else {
			lastBest=x;
			x=x->right;
		}
	}
	while ( (lastBest != nil) && (0 >= TreeCompare(tree, low,lastBest->key))) {
		StackPush(enumResultStack,lastBest);
		lastBest=RbTreePredecessor(tree,lastBest);
	}
	return(enumResultStack);
}
std::ostream& LoadBalanceInverseOperator::Print(std::ostream& os, const bool verbose) const
{

  StackPush();

  if (GetMyPID() == 0) {
    os << "***MLAPI::InverseOperator" << std::endl;
    os << "Label             = " << GetLabel() << std::endl;
    os << "Number of rows    = " << GetRangeSpace().GetNumGlobalElements() << std::endl;
    os << "Number of columns = " << GetRangeSpace().GetNumGlobalElements() << std::endl;
    os << "Flop count        = " << GetFlops() << std::endl;
    os << "Cumulative time   = " << GetTime() << std::endl;
    if (GetTime() != 0.0)
      os << "MFlops rate       = " << 1.0e-6 * GetFlops() / GetTime() << std::endl;
    else
      os << "MFlops rate       = 0.0" << std::endl;
    os << std::endl;
  }

  StackPop();

  return(os);

}
Exemplo n.º 15
0
int main(void)
{
    int i;
    char *cadenas[] = {"hola", "mundo", "caca"};
    char *p;

    Stack test;
    StackNew(&test, sizeof(char *), dispose_string);

    for(i=0; i<3; i++)
    {
        p = strdup(cadenas[i]);
        StackPush(&test, &p);
    }

    for(i=0; i<3; i++)
    {
        StackPop(&test, &p);
        printf("%s ", p);
    }

    printf("\nComplete");
    return 0;
}
Exemplo n.º 16
0
static void CheckBrackets(Stack *s, char c) {
  Element top_element;
  switch (c) {
    case '(':
    case '[':
    case '{':
      top_element.c = c;
      top_element.line = line;
      top_element.col = col;
      StackPush(s, &top_element);
      break;
    case ')':
      StackPop(s, &top_element);
      if (top_element.c != '(') {
        printf("line %d, col %d: error: miss match for %c character.\n",
               line, col, c);
      }
      break;
    case ']':
      StackPop(s, &top_element);
      if (top_element.c != '[') {
        printf("line %d, col %d: error: miss match for %c character.\n",
               line, col, c);
      }
      break;
    case '}':
      StackPop(s, &top_element);
      if (top_element.c != '{') {
        printf("line %d, col %d: error: miss match for %c character.\n",
               line, col, c);
      }
      break;
    default:
      break;
  }
}
Exemplo n.º 17
0
void StackPush( int type, char *str )
{
	StackPush( type, str, (int)strlen(str)+1 );
}
Exemplo n.º 18
0
/** @brief This function gives the tree functionality
	@param panel the panel handle of the panel on which the button is used
	@param control the control on which the event is generated
	@param event the type of event generated (i.e. left-click causes EVENT_COMMIT)
	@param *callbackData stores the data returned to the UI handled internally by LabWindows
	@param eventData1 stores ancillary information such as the mouse x-position within the panel
	@param eventData2 stores ancillary information such as the mouse y-position within the panel
	@return 1 or 0 specifies whether or not the event should be swallowed. 0 is default-no and 1 is yes-swallow.

### EXTERNAL VARIABLES
    - extern int @ref panelHandle - "OpenPET.c"
	- extern int @ref panelHandle_fmmode_mb - "OpenPET.c"
	- extern int @ref panelHandle_fmmode_duc - "OpenPET.c"
	- extern int @ref panelHandle_fmmode - "OpenPET.c" 
	- extern Stack @ref panel_stack - "UI_Common.c"
	- extern OpenPETTree @ref current_location - "UI_Common.c"

### ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES
	Errors may be generated by CVI/LabWindows. The LabWindows documentation is available online 
	at <a href="linkURL"> http://zone.ni.com/reference/en-XX/help/370051V-01/ </a>.
	
###	ALGORITHM
	The tree item double-clicked on is given as an index in eventData2. The tag is extracted (i.e. MB0DUC1DB2).
	This tag is parsed to specify the new desired location. The new panel is displayed and the stack is
	updated to allow the desired functionality in the back button.
	
###	DEVELOPMENT HISTORY
       Date    |  Author         |  Email Address     | Ver. |Description Of Change  
	   --------|-----------------|--------------------|------|---------------------
	 08/09/2013| George Netscher | [email protected] | 1.0  |conclusion of summer work
	 
### Copyright (c) 2013 by LBNL. All Rights Reserved.
*/
int CVICALLBACK FloodMapModeTree (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	char item_tag[32];
	OpenPETTree new_location;
	int i, idx=0, current_boards[3]={-1,-1,-1};
	
	switch (event)
	{
		case EVENT_COMMIT:

			// eventData2 contains index of tree item double-clicked
			GetTreeItemTag(panel, control, eventData2, item_tag);
			
			// update current_location so panel will initialize properly
			OpenPETTreeInit(&new_location);   // set to (-1, -1, -1, "NULL")
			new_location.mode = current_location.mode;
			
			for(i=0; i<32; i++)
			{
				// walk through tag string and pull out board numbers
				if( isdigit(item_tag[i]) )
				{
					current_boards[idx++] = (int)(item_tag[i] - '0');
				}
			}
			new_location.MB = current_boards[0];
			new_location.DUC = current_boards[1];
			new_location.DB = current_boards[2];
			
			// clear panel stack up to root panel 
			while( StackPeek(&panel_stack) != panelHandle )
			{
				StackPop(&panel_stack);	
			}
			
			// determine proper panel to display
			/*
			if(new_location.DB != -1) 
			{
				StackPush(&panel_stack, panelHandle_fmmode_mb); 
				StackPush(&panel_stack, panelHandle_fmmode_duc); 
				
				HidePanel (panel);				
				DisplayPanel (panelHandle_fmmode);
				
			}
			*/
			if (new_location.DUC != -1)
			{
				HidePanel(panel);				
				StackPush(&panel_stack, panelHandle_fmmode_mb); 
				StackPush(&panel_stack, panelHandle_fmmode_duc); 
				DisplayPanel(panelHandle_fmmode);
			}
			else if (new_location.MB != -1)
			{
				HidePanel(panel);
				StackPush(&panel_stack, panelHandle_fmmode_mb); 
				DisplayPanel(panelHandle_fmmode_duc);
			}
			else if (new_location.MB == -1)
			{
				HidePanel(panel);
				DisplayPanel(panelHandle_fmmode_mb);
			}
			else {
				HidePanel(panel); 
				DisplayPanel(StackPop(&panel_stack));
			}
			
			current_location.MB = new_location.MB;
			current_location.DUC = new_location.DUC;
			current_location.DB = new_location.DB;
			break;
	}
	return 0;
}
Exemplo n.º 19
0
/** @brief This function gives the tree functionality
	@param panel the panel handle of the panel on which the button is used
	@param control the control on which the event is generated
	@param event the type of event generated (i.e. left-click causes EVENT_COMMIT)
	@param *callbackData stores the data returned to the UI handled internally by LabWindows
	@param eventData1 stores ancillary information such as the mouse x-position within the panel
	@param eventData2 stores ancillary information such as the mouse y-position within the panel
	@return 1 or 0 specifies whether or not the event should be swallowed. 0 is default-no and 1 is yes-swallow.

### EXTERNAL VARIABLES
    - extern int @ref panelHandle - "OpenPET.c"
	- extern int @ref panelHandle_timemode_mb - "OpenPET.c"
	- extern int @ref panelHandle_timemode_duc - "OpenPET.c"
	- extern int @ref panelHandle_timemode_db - "OpenPET.c"
	- extern int @ref panelHandle_timemode - "OpenPET.c" 
	- extern Stack @ref panel_stack - "UI_Common.c"
	- extern OpenPETTree @ref current_location - "UI_Common.c"

### ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES
	Errors may be generated by CVI/LabWindows. The LabWindows documentation is available online 
	at <a href="linkURL"> http://zone.ni.com/reference/en-XX/help/370051V-01/ </a>.
	
###	ALGORITHM
	The tree item double-clicked on is given as an index in eventData2. The tag is extracted (i.e. MB0DUC1DB2).
	This tag is parsed to specify the new desired location. The new panel is displayed and the stack is
	updated to allow the desired functionality in the back button.
	
###	DEVELOPMENT HISTORY
       Date    |  Author         |  Email Address     | Ver. |Description Of Change  
	   --------|-----------------|--------------------|------|---------------------
	 08/09/2013| George Netscher | [email protected] | 1.0  |conclusion of summer work
	 
### Copyright (c) 2013 by LBNL. All Rights Reserved.
*/
int CVICALLBACK TimeModeDBTree (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	char item_tag[32];
	OpenPETTree new_location;
	int i, idx, current_boards[3]={-1,-1,-1};
	
	switch (event)
	{
		case EVENT_COMMIT:
			// eventData2 contains index of tree item double-clicked
			GetTreeItemTag(panel, control, eventData2, item_tag);
			
			// update current_location so panel will initialize properly
			OpenPETTreeInit(&new_location);   // set to (-1, -1, -1, "NULL")
			new_location.mode = current_location.mode;
			
			if(system_size == 1)
				// large system -> fill in MB, DUC, and DB board locations
				idx = 0;
			else if(system_size == 2)
				// medium system -> fill in DUC and DB board locations
				idx = 1;
			else if(system_size == 3)
				// small system -> only fill in DB board location
				idx = 2;
			for(i=0; i<32; i++)
			{
				// walk through tag string and pull out board numbers
				if( isdigit(item_tag[i]) )
				{
					current_boards[idx++] = (int)(item_tag[i] - '0');
				}
			}
			new_location.MB = current_boards[0];
			new_location.DUC = current_boards[1];
			new_location.DB = current_boards[2];
			
			// clear panel stack up to root panel 
			while( StackPeek(&panel_stack) != panelHandle )
			{
				StackPop(&panel_stack);	
			}
			
			// determine proper panel to display
			if(new_location.DB != -1) 
			{
				if(system_size == 1)
					// large size
					StackPush(&panel_stack, panelHandle_timemode_mb); 
				if(system_size == 1 || system_size == 2)
					// large or medium size
					StackPush(&panel_stack, panelHandle_timemode_duc);
				
				StackPush(&panel_stack, panelHandle_timemode_db);
				
				HidePanel (panel);				
				DisplayPanel (panelHandle_timemode);
				
			}
			else if (new_location.DUC != -1)
			{
				// in small size, this will never be reached because DUC always equals -1
				if(system_size == 1)
					// large size
					StackPush(&panel_stack, panelHandle_timemode_mb); 
				if(system_size == 1 || system_size == 2)
					// large or medium size
					StackPush(&panel_stack, panelHandle_timemode_duc); 
				
				HidePanel(panel);
				DisplayPanel(panelHandle_timemode_db);
			}
			else if (new_location.MB != -1)
			{
				// in small or medium size, this will never be reached because MB always equals -1
				if(system_size == 1)
					// large size
					StackPush(&panel_stack, panelHandle_timemode_mb);
				
				HidePanel(panel);  
				DisplayPanel(panelHandle_timemode_duc);
			}
			else 
			{
				// only large system should reach here
				HidePanel(panel);
				DisplayPanel(panelHandle_timemode_mb);
			}
			
			current_location.MB = new_location.MB;
			current_location.DUC = new_location.DUC;
			current_location.DB = new_location.DB;
			
			break;
	}
	return 0;
}
Exemplo n.º 20
0
int main()
{
	struct timeval t1, t2;
	double elapsedTime;
	srand(time(NULL));
	int i;
	int r;
	int result; 

	printf("Testing Queue\n");
	// start timer
	gettimeofday(&t1, NULL);
	Queue* queue = CreateQueue();

	for(i = 0; i < NO_OF_ELEMENTS ; i++)
	{
		// Generate a random value and put that to stack
		r = rand();	
		result = QueueEnqueue(queue, r);
		if(result != 0)
		{
			printf("Error in enqueuing queue\n");
		}
	}

	for(i = 0; i < NO_OF_ELEMENTS ; i++)
	{
		result =QueueDequeue(queue, &r);
		if(result != 0)
		{
			printf("Error in dequeuing queue\n");
		}
	}

	DeleteQueue(queue);

	// Time calculation
	gettimeofday(&t2, NULL);
	elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
	elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
	printf("Elapsed time %f\nQueue testing completed...\n", elapsedTime);
	
	printf("\nTesting Stack\n");
	// start timer
	gettimeofday(&t1, NULL);

	Stack* stack = CreateStack();
	for(i = 0; i < NO_OF_ELEMENTS ; i++)
	{
		// Generate a random value and put that to stack
		r = rand();	
		result = StackPush(stack, r);
		if(result != 0)
		{
			printf("Error in pushing to stack");
		}
	}

	for(i = 0; i < NO_OF_ELEMENTS ; i++)
	{
		result = StackPop(stack, &r);
		if(result != 0)
		{
			printf("Error in poping stack");
		}
	}
	
	DeleteStack(stack); 

	// Time calculation
	gettimeofday(&t2, NULL);
	elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
	elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;

	printf("Elapsed time %f\nStack testing completed...\n", elapsedTime);

	return 0;
}
Exemplo n.º 21
0
void Push(void){
	TransferAndDraw();
	transform_dirty = 1;
	StackPush();
}
Exemplo n.º 22
0
// strongly connected components
// function takes graph, current node, index array, lowlink array, stack and 
// boolean for nodes in stack
void SCC(Graph* mygraph, int u, int index[], int lowlink[], stackT stack, 
                                                                int inStack[])
{   
    // assign current stack to global stack variable
    stackGl = stack;
    counter = counter + 1;
    index[u] = lowlink[u] = counter;
    
    // add current node to stack
    StackPush(&stackGl, u);
    
    // change current node to true 
    inStack[u] = 1;
    
    // create adjacency list
    // it is outlist of current node
    List* adj = (List*)malloc(sizeof(List));
    adj = mygraph->table[u].outlist;   
    
    // while there is a node outlist of current node
    // update lowlink of current node
    while(adj != NULL)
    {
        // adjacent node of the current node
        int v = adj->index;
        
        // if adjacent node has not discovered yet
        // send node to strongly connected component function
        // update the lowlink of the current node
        if (index[v] == -1)
        {
            SCC(mygraph, v, index, lowlink, stackGl, inStack);        
            lowlink[u] = min(lowlink[u],lowlink[v]);       
        }
        // if adjacent node is already discovered 
        // update lowlink number of the current node anyway
        else if(inStack[v] == 1)
        {
            lowlink[u] = min(lowlink[u], index[v]);
        }

        // pass to next node
        adj = adj->next;
    }
    
    int tmp;
    
    // if lowlink number of current node is equal to the index number of same
    // node, print the node
    if(lowlink[u] == index[u])
    {
        // if current node is in not in the top the stack
        // find the node and print out
        while (stackGl.contents[stackGl.top] != u)
        {
            tmp = stackGl.contents[stackGl.top];
            printf("%d ", tmp);
            inStack[tmp] = 0;
            StackPop(&stackGl);
            
        }
        // print it
        tmp = stackGl.contents[stackGl.top];
        printf(" %d\n ", tmp);
        inStack[tmp] = 0;
        
        // remove nodes from stack
        StackPop(&stackGl);
    }
    
}
Exemplo n.º 23
0
void Enqueue(queue* q, int val)
{
    StackPush(q->b, val);
}
Exemplo n.º 24
0
static void Filter(const wchar_t *sFilter, bool bCaseSensitive)
{
	if (sFilter!=NULL) {
		size_t nFilter = wcslen(sFilter);
		if (nFilter>0xFFFF) nFilter = 0xFFFF;
		wchar_t *sFilterLower=NULL;
		EditorUndoRedo eur = {sizeof(EditorUndoRedo)};
		EditorSetPosition es = {sizeof(EditorSetPosition)};
		char *Lines; //маска удалённых строк

		Lines = MakeLineMask();
		StackPush(Lines);

		if (nFilter<=MAX_PATTERN_LEN) {
			SearchPrepare(ctx, sFilter, bCaseSensitive);
		}
		else {
			SearchHPrepare(ctx, sFilter, (WORD)nFilter, bCaseSensitive);
			if (!bCaseSensitive) {
				SetLength(&sFilterLower, (int)nFilter);
				wcscpy(sFilterLower, sFilter);
				CharLower(sFilterLower);
			}
		}
		//непустой фильтр - создаём блок Undo и меняем текст внутри него
		eur.Command=EUR_BEGIN;
		Info.EditorControl(-1, ECTL_UNDOREDO, 0, &eur);

		//ищем текст из диалога в каждой строке
		EditorInfo einfo = {sizeof(EditorInfo)};
		Info.EditorControl(-1, ECTL_GETINFO, 0, &einfo);
		intptr_t nLines = einfo.TotalLines;
		intptr_t line = nLines;
		es.CurPos = 0;
		es.CurTabPos = es.LeftPos = es.Overtype = es.TopScreenLine = -1;
		while (--line>=0) {
			es.CurLine = line;
			Info.EditorControl(-1, ECTL_SETPOSITION, 0, &es);

			EditorGetString egs = {sizeof(EditorGetString), -1};
			Info.EditorControl(-1, ECTL_GETSTRING, 0, &egs);
			const wchar_t *found;
			if (nFilter <= MAX_PATTERN_LEN)
				found = Search(ctx, egs.StringText);
			else
				found = SearchH(ctx,
					bCaseSensitive ? sFilter : sFilterLower,
					(WORD)nFilter,
					egs.StringText,
					egs.StringLength,
					bCaseSensitive);
			if (found==NULL) {
				Info.EditorControl(-1, ECTL_DELETESTRING, 0, NULL);
				MarkDeletedLine(Lines, line);
			}
		}

		es.CurLine = 0;
		es.CurPos = 0;
		es.TopScreenLine = 0;
		es.CurTabPos = es.LeftPos = es.Overtype = -1;
		Info.EditorControl(-1, ECTL_SETPOSITION, 0, &es);

		RemoveHighlight();

		eur.Command=EUR_END;
		Info.EditorControl(-1, ECTL_UNDOREDO, 0, &eur);

		nChanges++;
		if (nFilter<=MAX_PATTERN_LEN) {
			SearchUnprepare(ctx,sFilter,bCaseSensitive);
		}
		else {
			if (!bCaseSensitive)
				SetLength(&sFilterLower, 0);
		}
	}
}
Exemplo n.º 25
0
void empilha(Estado estadoRetorno) {
    StackPush(&pilha, estadoRetorno);
}
Exemplo n.º 26
0
void StackPushStr( char *str )
{
	StackPush( HSPVAR_FLAG_STR, str, (int)strlen(str)+1 );
}
Exemplo n.º 27
0
void PushBank(UINT8 b)
{
  StackPush(bank_stack, b);
  SWITCH_ROM_MBC1(b);
}
Exemplo n.º 28
0
int main()
{
	int i,r;
	printf("Testing Queue\n");
	Queue* queue = CreateQueue();

	printf("Inserting values\n");
	for(i = 0; i < 5 ; i++)
	{	
		printf("%d\n",i);
		int result = QueueEnqueue(queue, i);
		if(result == 0)
		{
			printf("%d\n",i);
		}
		else
		{
			printf("Error in enqueuing queue\n");
		}
	}

	printf("Removing values\n");
	for(i = 0; i < 5 ; i++)
	{
		int result =QueueDequeue(queue, &r);
		if(result == 0)
		{
			printf("%d\n",r);
		}
		else
		{
			printf("Error in dequeuing queue\n");
		}
	}

	DeleteQueue(queue);

	printf("\nTesting Stack\n");

	Stack* stack = CreateStack();
	for(i = 0; i < 5 ; i++)
	{
		int result = StackPush(stack, i);
		if(result == 0)
		{
			printf("%d\n",i);
		}
		else
		{
			printf("Error in pushing to stack");
		}
	}

	for(i = 0; i < 5 ; i++)
	{
		int result = StackPop(stack, &r);
		if(result == 0)
		{
			printf("%d\n",r);
		}
		else
		{
			printf("Error in popping values");
		}
	}
	
	DeleteStack(stack); 
	return 0;
}
Exemplo n.º 29
0
int main(int argc, char* argv[], char** envp)
{

	int i = 0;
	int count = 20;
	char *s1 = "abcdefg";
	char *s2 = "g";
	size_t len1 = 0;
	size_t n = 3;
	char dest[20];

	node_t *node1 = NULL;
	node_t *node2 = NULL;
	node_t *node3 = NULL;
	node_t *node4 = NULL;
	node_t *node5 = NULL;
	
	char *t = NULL;	
	
	stack_t *stack = NULL;
	size_t n1 = 1;
	size_t n2 = 2;
	size_t n3 = 3;
	size_t n4 = 4;
	size_t n5 = 5;
	
	/*__________  RecFibonacci  __________*/
	printf("\n[%s %s %d]RecFibonacci\n", __FILE__, __func__, __LINE__);
	
	for (i = 0; i < count; ++i)
	{
		printf("RecFibonacci(%i):%i\n", i , RecFibonacci(i));
	}
	
	/*__________  RecStrlen  __________*/
	printf("\n[%s %s %d]RecStrlen\n", __FILE__, __func__, __LINE__);
	
	len1 = RecStrlen(s1);
	printf("len1:%lu\n", len1);
	
	/*__________  RecStrcmp  __________*/
	printf("\n[%s %s %d]RecStrcmp\n", __FILE__, __func__, __LINE__);
	
	printf("RecStrcmp(s1, s2): %i\n", RecStrcmp(s1, s2));
	
	
	/*__________  RecStrncmp  __________*/
	printf("\n[%s %s %d]RecStrncmp\n", __FILE__, __func__, __LINE__);
	
	printf("RecStrncmp(s1, s2, n): %i\n", RecStrncmp(s1, s2, n));


	/*__________  RecStrstr  __________*/
	printf("\n[%s %s %d]RecStrstr\n", __FILE__, __func__, __LINE__);
	
	printf("RecStrstr(s1, s2):%s\n", RecStrstr(s1, s2));
	
	/*__________  RecStrcpy  __________*/
	printf("\n[%s %s %d]RecStrcpy\n", __FILE__, __func__, __LINE__);
	t = RecStrcpy(dest, s1);
	printf("RecStrcpy(dest, s1):%s		expected result:%s\n", t, dest);
	
	
	/*__________  RecStrcat  __________*/
	printf("\n[%s %s %d]RecStrcat\n", __FILE__, __func__, __LINE__);
	
	printf("RecStrcat(dest, s1):%s		expected result:%s\n", 
			RecStrcat(dest, s1), 						"abcgefgabcdefg");
	
	/*__________  RecSlistFlip  __________*/
	printf("\n[%s %s %d]RecSListFlip\n", __FILE__, __func__, __LINE__);
	
	node5 = SListCreateNode((void*)5, NULL);
	node4 = SListCreateNode((void*)4, node5);
	node3 = SListCreateNode((void*)3, node4);
	node2 = SListCreateNode((void*)2, node3);
	node1 = SListCreateNode((void*)1, node2);
	
	printf("SListCount(node1):%lu\n", SListCount(node1));
	
	RecSListFlip(node1);
	
	printf("SListCount(node1):%lu\n", SListCount(node5));
	
	SListFreeAll(node5);
	
	/*__________  Compere  __________*/
	printf("\n[%s %s %d]Compere\n", __FILE__, __func__, __LINE__);
	
	printf("Compere(&n1, &n2):%i		expected result:1\n", Compere(&n1, &n2));
	
	printf("Compere(&n1, &n1):%i		expected result:1\n", Compere(&n1, &n2));
	
	printf("Compere(&n2, &n1):%i		expected result:0\n", Compere(&n2, &n1));
	/*_________________________  END Compere _______________________*/
	
	
	/*________________________________________________________________*/
	printf("\n[%s %s %d]RecStackSort\n", __FILE__, __func__, __LINE__);
	/*_________________________  RecStackSort  _______________________*/
	
	stack = StackCreate(sizeof(size_t), 5);
	assert(stack);
	
	StackPush(stack, &n3);
	StackPush(stack, &n2);
	StackPush(stack, &n5);
	StackPush(stack, &n4);
	StackPush(stack, &n1);

	RecStackSort(stack, &Compere, sizeof(size_t));
	
	for( ; StackSize(stack); StackPop(stack))
	{
		printf("StackPeek(stack):%lu\n", *(size_t*)StackPeek(stack));
	}
	
	StackDestroy(stack);	
	
	
	return(0);
}
Exemplo n.º 30
0
/* Pushed an element on the stack */
static inline void Push(Stack *stack, Element *top) {
  if (!StackPush(stack, top)) {
    printf("Error: memory overflow!");
    exit(1);
  }
}