Пример #1
0
void get_string(void)
{ char c, delim = loc[-1]; /* what started the string */
  id_loc=id_first = &mod_text[1]; copy_char(delim);
  if (delim=='L')
    *id_loc++=delim=*loc++; /* after `\.L' comes the real delimiter */
  else if (delim=='<') delim='>'; /* for file names in \&{\#include} lines */
  do
  { if (loc>=limit)
    { err_print("! String didn't end"); loc=limit; break; }
		   
    copy_char(c=*loc++);
    if (c=='\\')
      if (loc<limit) copy_char(*loc++);
        /* record `\.\\|c|' with |c!='\n'| literally */
      else if (get_line())
        if (program==cweave) --id_loc; /* |CWEAVE| erases backslash */
	else copy_char('\n'); /* but |CTANGLE| copies escaped newline */
      else
      { loc=buffer;
        err_print("! Input ended in middle of string");
		   
        break;
      }
    else if (!including_header_file && c=='@')
      if (*loc=='@') ++loc; /* undouble \:@ */
      else err_print("! Double @ required in strings");
		      
  }
  while (c!=delim);
  if (id_loc>=mod_text_end)
  { print("\n! String too long: "); 
    term_write(mod_text+1,25); err_print("..");
  }
}
Пример #2
0
	bool get_get_param (void) {
		if (* command != '?' && * command != '&') return false;
		command++;
		char * cp = key;
		while (* command > 32 && * command != '=') copy_char (& cp, & command); * cp = '\0';
		if (* command == '=') command++;
		cp = area;
		while (* command > 32 && * command != '&') copy_char (& cp, & command); * cp = '\0';
		return true;
	}
Пример #3
0
	PrologElement * get_partial_request (void) {
		skip_whitespaces ();
		if (* command != '/') return 0;
		command++;
		int ap = 0; area [0] = '\0';
		char * cp = area;
		while (* command != '/' && * command != '?' && * command > 32) copy_char (& cp, & command);
		* cp = '\0';
		return interpret ();
	}
Пример #4
0
	bool get_param (void) {
		if (key_pending [0] != '\0') {
			strcpy (key, key_pending); strcpy (area, parameter_pending);
			key_pending [0] = parameter_pending [0] = '\0';
			return true;
		}
		if (* command <= 32) {skip_line (); return false;}
		char * cp = key;
		while (* command > 32 && * command != '=') copy_char (& cp, & command);
		* cp = '\0';
		if (strcmp (key, boundary) == 0) {
			command = strstr (command, "name=");
			if (command == 0) return false;
			while (* command > 32 && * command != '"') command++; command++;
			cp = key;
			while (* command > 32 && * command != '"') * cp++ = * command++;
			* cp = '\0';
			if (strstr (command, "filename=") == command + 3) {
				strcpy (key_pending, key); strcat (key_pending, "_filename");
				char * sub1 = parameter_pending;
				char * sub2 = command + 13;
				while (* sub2 > 0 && * sub2 != '"') * sub1++ = * sub2++; * sub1 = '\0';
				skip_line ();
			}
			skip_line ();
			skip_line ();
			cp = area;
			char * terminator = strstr (command, boundary);
			while (terminator != 0 && command < terminator - 2) * cp++ = * command++;
			skip_line ();
			* cp = '\0';
			return true;
		}
		if (boundary [0] != '\0' && strstr (key, boundary) == key) return false;
		if (* command == '=') command++;
		cp = area;
		while (* command > 32 && * command != '&') copy_char (& cp, & command);
		* cp = '\0';
		if (* command == '&') command++;
		return true;
	}
Пример #5
0
unsigned int ImageSplit(unsigned char *data,int width, int height){
    int i,j,k;
	int w,h;
	int left,right;
	int pixel_num = 0;
	int top_height,bot_height;
	int new_height = getImageHeight(data,width,height,&top_height,&bot_height);
	int l_width = ((width*3+3)>>2)<<2;
	
	float calc_out[ANN_OUTPUT_NUM];
	int   calc_iout[ANN_OUTPUT_NUM];
	
	unsigned char recogArr[13]={0};
	int index = 0;
	left = right = 0;
	
	while(1){
		if (left >= width){
		    break;
		}
		
		while(left < width){
		    pixel_num = 0;
		    for (i=0; i<height; i++){/*scan from bottom to top*/
                k = i*l_width + left*3;
				if (data[k] == 0 && data[k+1] == 0 && data[k+2] == 0){
				    pixel_num ++;
				}
			}
			
			if (pixel_num <= 1){
			    left ++;
			}
			else{
			    break;
			}
		}
		
		right = left + 1;
		
		if (right >= width){
		    break;
		}
		
		while(right < width){
		    pixel_num = 0;
		    for (i=0;i<height; i++){
                k = i*l_width + right*3;
				if (data[k] == 0 && data[k+1] == 0 && data[k+2] == 0){
				    pixel_num ++;
				}
			}
			
			if (pixel_num > 1){
			    right++;
			}
			else{
			    break;
			}
		}
		
		if (right >= width){
		    break;
		}
		
		if ((right-left) <= 2){
		    left = right + 1;
			continue;
		}
		
		if (IsHorizonLine(data,left,right,width,height) == 1){ /* symbol "-" ? */
		    left = right + 1;
		    continue;
		}
		
		set_verticalbar_blue(data,width,height,left,right-1);
#if 1		
		int recogNum = 0;
		if ((right-left) <= MAX_CHAR_WIDTH){
		    int top_pos = 0;
			int bot_pos = 0;
//			int left_pos = 0;
//			int right_pos = 0;
			getSlicedHeight(data,left,right,width,height,&top_pos,&bot_pos);
//			getSlicedWidth(data,left,right,width,height,&left_pos,&right_pos);
//		    unsigned char *one_ch = new unsigned char[(right-left)*(top_height-bot_height+1)];
            unsigned char *one_ch = new unsigned char[(right-left + 1)*(top_pos-bot_pos+1)];
			if (one_ch == NULL){
			    printf("(%d) allocate memory failed\n",__LINE__);
			}
			copy_char(data,one_ch,left,right,top_pos,bot_pos,width);
			unsigned char *norm_data = new unsigned char[NORM_WIDTH*NORM_HEIGHT];
			if (norm_data == NULL){
			    printf("(%d) allocate memory failed\n",__LINE__);
			}
			
//			norm_data = ImageNorm(one_ch,right-left,top_height-bot_height+1);
            norm_data = ImageNorm(one_ch,norm_data,right - left+1, top_pos-bot_pos+1);
//			ImageThinning(norm_data,NORM_WIDTH,NORM_HEIGHT);
			float *feature_vector = new float[MAX_FEATURE_LEN];
			if (feature_vector == NULL){
			    printf("(%d) allocate memory failed\n",__LINE__);
			}
            memset(feature_vector,0,MAX_FEATURE_LEN);

            getfeatureVector(norm_data,feature_vector,NORM_WIDTH,NORM_HEIGHT);
#if 1
			PRINT_NORM(norm_data,NORM_WIDTH,NORM_HEIGHT);
			PRINT_FEATURE(feature_vector,MAX_FEATURE_LEN);
#endif
            
            recogDigital(feature_vector,&calc_out[0]);
			
			printf("%f %f %f %f\n",calc_out[0],calc_out[1],calc_out[2],calc_out[3]);
			
			for (i=0; i<4; i++){
			    if (fabs(calc_out[i]) > 0.5){
				    calc_iout[i] = 1;
					
				}
				else{
				    calc_iout[i] = 0;
				}
			}
			
		    printf("%d  %d %d %d\n",calc_iout[0],calc_iout[1],calc_iout[2],calc_iout[3]);
			recogNum = (calc_iout[0]<<3)+(calc_iout[1]<<2) + (calc_iout[2]<<1) + calc_iout[3];
			
		    if (recogNum > 9){
		         printf("recognized failure(recogNum = %d)\n",recogNum);
			     recogArr[index]='X';
				 index++;
//			     exit(1);
		    }
		    else{
		        printf("%d\n",recogNum);
				recogArr[index]=recogNum;
				index++;
		    }

#if 1			
			set_verticalbar_blue(data,width,height,left,right-1);
#endif
            delete[] one_ch;
            delete[] norm_data;
			delete[] feature_vector;
		}
		else{
#if 1
		    int new_left  = left;
		    int new_right = new_left + MIN_WINDOW_LEN;
			int loop = 0;
			while(new_right < right){
			    int recog_sliced = 0;
				int temp_left = 0;
				int temp_right = 0;
//				printf("new_left =%d, new_right=%d,left=%d,right=%d\n",new_left,new_right,left,right);
				
				if ((new_right - new_left) == MIN_WINDOW_LEN){
				    printf("new_left=%d,new_right=%d,left=%d,right=%d\n",new_left,new_right,left,right);
					if (IsHorizonLine(data,new_left,new_right,width,height) == 1){
					    new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
						continue;
					}
					
				    recog_sliced = recog_one_sliced(data,new_left,new_right,top_height, bot_height, width,height);
					
					if (recog_sliced != 1){
					    temp_left = new_left -1;
						temp_right = new_right -1;
						printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
						
						if (IsHorizonLine(data,temp_left,temp_right,width,height) == 1){
						    new_left = temp_right + 1;
							new_right = new_left + MIN_WINDOW_LEN;
							continue;
						}
						
						recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
						if (recog_sliced != 1){
						    temp_left = new_left + 1;
							temp_right = new_right + 1;
							if (temp_right >= right){
							    new_right = right;/*do nothing, end this while loop*/
							}
							else{
							    printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
								if (IsHorizonLine(data,temp_left,temp_right,width,height) == 1){
								    new_left = temp_right + 1;
									new_right = new_left + MIN_WINDOW_LEN;
									continue;
								}
							    recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
								if (recog_sliced != 1){
								    //new_right = new_left + MAX_WINDOW_LEN;
									
									//if (new_right >= right){
									//    new_right = right -1;
									//}
									new_right = new_left + MIN_WINDOW_LEN + 1;
									
								}
								else{
								    printf("%d\n",recog_sliced);
									recogArr[index]=recog_sliced;
									index++;
									//new_left = new_right + 1;
									new_left = temp_right + 1;
									new_right = new_left + MIN_WINDOW_LEN ;
									/*go to next loop*/
								}
							}
						}
						else{
						    printf("%d\n",recog_sliced);
							recogArr[index] = recog_sliced;
							index++;
							new_left = temp_right + 1;
							new_right = new_left + MIN_WINDOW_LEN;
						}
					}
					else{
					    printf("%d\n",recog_sliced);
						recogArr[index] = recog_sliced;
						index++;
					    new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
						/*if new_right > right, end this while loop*/
					}
				}
				
				if ((new_right - new_left) == (MIN_WINDOW_LEN + 1)){
				    printf("new_left=%d,new_right=%d,left=%d,right=%d\n",new_left,new_right,left,right);
					if (IsHorizonLine(data,new_left,new_right,width,height) == 1){
					    new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
						continue;
					}
					recog_sliced = recog_one_sliced(data,new_left,new_right,top_height, bot_height, width,height);
					if (recog_sliced != 1){
					    temp_left = new_left - 1;
						temp_right = new_right - 1;
						printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
						if (IsHorizonLine(data,temp_left,temp_right,width, height) == 1){
						    new_left = new_right + 1;
							new_right = new_left + MIN_WINDOW_LEN;
							continue;
						}
						
						recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
						if (recog_sliced != 1){
						    temp_left = new_left + 1;
							temp_right = new_right + 1;
							 printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
							if (temp_right >= right){
							    new_right = right; /*do nothing, just end this loop*/
							}
							else{
							    if (IsHorizonLine(data,temp_left,temp_right,width,height) == 1){
								    new_left = temp_right + 1;
									new_right = new_left + MIN_WINDOW_LEN;
									continue;
								}
								
								recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
								if (recog_sliced != 1){
								    new_right = new_left + MAX_WINDOW_LEN;
									if (new_right >= right){
									    new_right = right - 1;
									}
								}
								else{
								    printf("%d\n",recog_sliced);
									recogArr[index] = recog_sliced;
									index++;
									
									new_left = temp_right + 1;
									new_right = new_left + MIN_WINDOW_LEN;
								}
							}
							
						}
						else{
						    printf("%d\n",recog_sliced);
							recogArr[index] = recog_sliced;
							index ++;
							
							new_left = temp_right + 1;
							new_right = new_left + MIN_WINDOW_LEN; /*if new_right > right,just end this loop*/
						}
					}
					else{
					    printf("%d\n",recog_sliced);
						recogArr[index] = recog_sliced;
						index++;
						
					    new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
					}
				}
				
				if ((new_right - new_left) > (MIN_WINDOW_LEN+1) && (new_right - new_left) <= MAX_WINDOW_LEN){
				    printf("new_left=%d,new_right=%d,left=%d,right=%d\n",new_left,new_right,left,right);
				    recog_sliced = recog_one_sliced(data,new_left,new_right,top_height,bot_height,width,height);
					if ((recog_sliced == 1 || recog_sliced < 0 || recog_sliced >= 10) /*|| (index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
					    /*failed*/
						temp_left = new_left -1;
						temp_right = new_right -1;
						/*recognize again*/
						printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
						recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
						if ((recog_sliced < 0 || recog_sliced >= 10)/* ||(index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
						    /*failed again*/
							temp_left = new_left + 1;
							temp_right = new_right + 1;
							if (temp_right >= right){
							    temp_right = right -1;
							}
							
							/*the last try*/
							printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
							recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
							if (( recog_sliced < 0 || recog_sliced >= 10) /*||(index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
							    /*still failed*/
								/*keep new_left unchange*/
								new_right = new_left + (MAX_WINDOW_LEN + 1);
								if (new_right >= right){
								    new_right ++;/*here just end this loop*/
								}
							}
							else{
							    /*success*/
							    printf("%d\n",recog_sliced);
								recogArr[index]=recog_sliced;
								index++;
								new_left = temp_right + 1;
								new_right = new_left + MIN_WINDOW_LEN;
								/*go to next loop*/
							}
							
							
						}
						else{
						    /*success*/
							printf("%d\n",recog_sliced);
							recogArr[index] = recog_sliced;
							index++;
							new_left = temp_right + 1;
							new_right = new_left + MIN_WINDOW_LEN;
							/*go to next loop*/
						}
					}
					else{
					    printf("%d\n",recog_sliced);
						recogArr[index]=recog_sliced;
						index++;
						new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
						/*go to next while loop. if new_right > right, just stop this while loop*/
					}
				}
				
				if ((new_right - new_left) == (MAX_WINDOW_LEN + 1)){
				    printf("new_left=%d,new_right=%d,left=%d,right=%d\n",new_left,new_right,left,right);
				    recog_sliced = recog_one_sliced(data,new_left,new_right,top_height,bot_height,width,height);
					if ((recog_sliced < 0 || recog_sliced >= 10) /*|| (index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
					    /*failed*/
						temp_left = new_left - 1;
						temp_right = new_right -1;
						/*recognize again*/
						printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
						recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
						if ((recog_sliced < 0 || recog_sliced >= 10) /*|| (index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
						    /*failed again*/
							temp_left = new_left + 1;
							temp_right = new_right + 1;
							if (temp_right >= right){
							    temp_right = right -1;
							}
							
							/*last recog try*/
							printf("new_left=%d,new_right=%d,left=%d,right=%d\n",temp_left,temp_right,left,right);
							recog_sliced = recog_one_sliced(data,temp_left,temp_right,top_height,bot_height,width,height);
							if ((recog_sliced == 1 || recog_sliced < 0 || recog_sliced >= 10) /*|| (index == 1 && (recog_sliced != 3 || recog_sliced != 5 || recog_sliced != 8))*/){
							    /*totally failed*/
								new_left = new_right + 1;
								new_right = new_left + MIN_WINDOW_LEN;
								/*do not do it again*/
								printf("%d:recog given up\n",__LINE__);
								recogArr[index]='X';
								index++;
							}
							else{
							    printf("%d\n",recog_sliced);
								recogArr[index]=recog_sliced;
								index++;
								new_left = temp_right + 1;
								new_right = new_left + MIN_WINDOW_LEN;
								/*go to next loop*/
							}
							
						}
						else{
						    printf("%d\n",recog_sliced);
							recogArr[index]=recog_sliced;
							index++;
							new_left = temp_right + 1;
							new_right = new_left + MIN_WINDOW_LEN;
						}
					}
					else{
					    /*success*/
						printf("%d\n",recog_sliced);
						recogArr[index]=recog_sliced;
						index++;
						new_left = new_right + 1;
						new_right = new_left + MIN_WINDOW_LEN;
						/*if new_right >= right ,just end this loop*/
					}
				}
			}  
#endif 			
		}
#endif		
		left = right;
		
	}
	
	for (i=0; i<index; i++){
	    if (recogArr[i] !='X'){
		    printf("%d",recogArr[i]);
		}
		else{
		    printf("%c",recogArr[i]);
		}
	}
	printf("\n");
}
Пример #6
0
void featureExtract(unsigned char *data,int width, int height)
{
    int i=0; 
	int j=0;
	int k=0;
	
	float calc_out[ANN_OUTPUT_NUM];
	int   calc_iout[ANN_OUTPUT_NUM];
	
	int l_width = ((width*3 + 3)>>2)<<2;
    unsigned char *norm_data = new unsigned char[NORM_WIDTH*NORM_HEIGHT];	
	for (i=0; i<width; i++){
	    for (j=MIN_WINDOW_LEN; j<= MAX_WINDOW_LEN; j++){
	        int new_left = i;
		    int new_right = i+j;
		    int top_height = 0;
		    int bot_height = 0;
		    
		    getSlicedHeight(data,new_left,new_right,width,height,&top_height,&bot_height);
		    printf("left=%d,right=%d,top=%d,bot=%d\n",new_left,new_right,top_height,bot_height);
		    unsigned char *one_ch = new unsigned char[(new_right-new_left + 1)*(top_height-bot_height+1)];
		    copy_char(data,one_ch,new_left,new_right,top_height,bot_height,width);
		    
		    ImageNorm(one_ch,norm_data,new_right - new_left+1, top_height-bot_height+1);
		    
		    float *feature_vector = new float[MAX_FEATURE_LEN];
		    memset(feature_vector,0,MAX_FEATURE_LEN);
		    getfeatureVector(norm_data,feature_vector,NORM_WIDTH,NORM_HEIGHT);
			int index = 0;
			float maxsim=getsimvalue(feature_vector,10,144,&index);
		    recogDigital(feature_vector,&calc_out[0]);
			//printf("calc_out[0]=%0.3f,calc_out[1]=%0.3f,calc_out[2]=%0.3f,calc_out[3]=%0.3f\n",calc_out[0],calc_out[1],calc_out[2],calc_out[3]);
		    PRINT_NORM(norm_data,NORM_WIDTH,NORM_HEIGHT);
	        PRINT_FEATURE(feature_vector,MAX_FEATURE_LEN);
			printf("calc_out[0]=%0.3f,calc_out[1]=%0.3f,calc_out[2]=%0.3f,calc_out[3]=%0.3f\n",calc_out[0],calc_out[1],calc_out[2],calc_out[3]);
			/*check calc_out*/
			int flag = 1;
			for (k=0; k<4; k++){
			    if (calc_out[k] <= -0.1){
				    printf("refused\n");
					flag = 0;
					break;
				}
				else if (calc_out[k] >= 0.1 && calc_out[k] < 0.85){
				    printf("refused\n");
					flag = 0;
					break;
				}
			}
			
			if (flag == 1){
			    int recogNUM = 0;
			    for (k=0; k<4; k++){
			        if (fabs(calc_out[k]) < 0.1){
				        recogNUM = 2*recogNUM;
				    }
					else{
					    recogNUM = 2*recogNUM + 1;
					}
				}
				
				printf("recogNUM=%d\n",recogNUM);
			}
			
			printf("maxsim=%f,index=%d,train_result=%d\n",maxsim,index,train_result[index]);
		}
	}
	

}
Пример #7
0
int recog_one_sliced(unsigned char *data,int sliced_left, int sliced_right, int top_height, int bot_height, int image_width, int image_height)
{
    int i;
	int recogNum = 0;
	float calc_out[ANN_OUTPUT_NUM];
	
	int left_pos = 0;
	int right_pos = 0;
	int top_pos = 0;
	int bot_pos = 0;
	
//	getSlicedWidth(data,sliced_left,sliced_right,image_width,image_height,&left_pos,&right_pos);
	getSlicedHeight(data,sliced_left,sliced_right,image_width,image_height,&top_pos,&bot_pos);
	
//    unsigned char *sliced = new unsigned char[(sliced_right - sliced_left + 1)*(top_height - bot_height + 1)];
    unsigned char *sliced = new unsigned char[(sliced_right - sliced_left + 1)*(top_pos - bot_pos + 1)];
	
	if (sliced == NULL){
	    printf("(line=%d)allocate memory failure!\n",__LINE__);
	    exit(1);
	}
	
//	copy_char(data,sliced,sliced_left,sliced_right,top_height,bot_height,image_width);
    copy_char(data,sliced,sliced_left,sliced_right,top_pos,bot_pos,image_width);
	unsigned char *norm_data = new unsigned char[NORM_WIDTH*NORM_HEIGHT];
//	norm_data = ImageNorm(sliced,sliced_right - sliced_left + 1,top_height - bot_height + 1);
    norm_data = ImageNorm(sliced,norm_data,sliced_right - sliced_left + 1, top_pos - bot_pos + 1);
//	ImageThinning(norm_data,NORM_WIDTH,NORM_HEIGHT);
	delete[] sliced;
	
	
	float *feature_vector = new float[MAX_FEATURE_LEN];
	if (feature_vector == NULL){
		printf("(line=%d)allocate memory failure!\n",__LINE__);
		exit(1);
	}
	memset(feature_vector,0,MAX_FEATURE_LEN);
	getfeatureVector(norm_data,feature_vector, NORM_WIDTH,NORM_HEIGHT);
				
	PRINT_NORM(norm_data,NORM_WIDTH,NORM_HEIGHT);
	PRINT_FEATURE(feature_vector,MAX_FEATURE_LEN);
	
	recogDigital(feature_vector,&calc_out[0]);
	printf("%f %f %f %f\n",calc_out[0],calc_out[1],calc_out[2],calc_out[3]);
	
	/*check ANN output*/
#if 0	
	int neg_num = 0;
	for (i = 0; i<4; i++){
	    if (calc_out[i] < -0.2){
		    return -1;
		}
		else if (calc_out[i] < -0.1 && calc_out[i] >= -0.2){
		    neg_num ++;
			if (neg_num >=2){
			    return -1;
			}
		}
		else if (calc_out[i] > 0 && fabs(calc_out[i] - 0.5) <= 0.25){
		    return -1;
		}
	}
#endif

    for (i=0; i<4; i++){
        if (calc_out[i] < (-0.2)){
		    printf("calc_out[%d]=%f\n",i,calc_out[i]);
		    return -1;
		}
		else if (calc_out[i] >= 0.25 && calc_out[i] <= 0.75){
		    printf("calc_out[%d]=%f\n",i,calc_out[i]);
		    return -1;
		}
	}	
	
	for (i=0; i<4; i++){
	    if (fabs(calc_out[i]) > 0.5){
		    recogNum = 2*recogNum + 1;
		}
		else{
		    recogNum = 2*recogNum;
		}
	}
	printf("recogNum=%d\n",recogNum);
	return recogNum;
}
Пример #8
0
Alignment* copy_aln ( Alignment *A, Alignment *B)
        {
	  int a, b;
	  int nnseq;
	  int nlen;
	  /*	  c[100]=10;*/



	  if ( A==NULL){free_aln(B); return NULL;}

	  nnseq=MAX(A->nseq, A->max_n_seq);
	  nlen=A->len_aln+1;
	  if (B)
	    B=realloc_alignment2 (B, nnseq, nlen);
	  else
	    B=declare_aln2 (nnseq, nlen);
	  B->S=A->S;


	  /*SIZES*/
	  B->max_len=A->max_len;
	  B->min_len=A->min_len;
	  B->declared_len=nlen;
	  B->max_n_seq=nnseq;

	  B->nseq=A->nseq;
	  B->len_aln=A->len_aln;


/*sequence Information*/
	    if ( A->generic_comment)
	      {
		vfree(B->generic_comment);
		B->generic_comment=vcalloc (strlen(A->generic_comment)+1, sizeof (char));
		sprintf ( B->generic_comment, "%s", A->generic_comment);
	      }
	    if ( (A->S)==NULL){vfree (B->len); B->len=vcalloc ( A->max_n_seq, sizeof (int));}
	    ga_memcpy_int ( A->len, B->len, B->nseq);

	    B->seq_comment=copy_char ( A->seq_comment,  B->seq_comment,  -1,-1);
	    B->aln_comment=copy_char ( A->aln_comment,  B->aln_comment,  -1,-1);

	    B->name=copy_char ( A->name,     B->name,     -1,-1);

	    B->file=copy_char ( A->file,     B->file,     -1,-1);
	    B->tree_order=copy_char ( A->tree_order,     B->tree_order,     -1,-1);
	    B->expanded_order=A->expanded_order;
	    free_char ( B->seq_al, -1);
	    B->seq_al=declare_char(B->max_n_seq, B->declared_len);
	    // HERE ("A: MAX_NSEQ=%d %d %d %d",B->nseq, B->max_n_seq, B->declared_len, B->len_aln);
	    // HERE ("B: MAX_NSEQ=%d %d %d %d",A->nseq, A->max_n_seq, A->declared_len, A->len_aln);
	    for ( a=0; a< nnseq; a++)
	      {
		if (A->seq_al[a])
		  {
		    for ( b=0; b< A->len_aln; b++)
		      B->seq_al[a][b]=A->seq_al[a][b];
		  }
	      }



	    B->order=copy_int  ( A->order,    B->order,    -1, -1);
	    B->S=A->S;
	    if (A->seq_cache)
	        {
		B->seq_cache=copy_int  ( A->seq_cache,    B->seq_cache,-1,-1);
		}

	    if (A->cdna_cache)
	        {
		B->cdna_cache=copy_int  ( A->cdna_cache,    B->cdna_cache,-1,-1);
		}

	    B->P=copy_profile (A->P);

	    B->Dp_result=A->Dp_result;

/*Score*/

	    if ( (A->S)==NULL){vfree (B->score_seq); B->score_seq=vcalloc ( A->max_n_seq, sizeof (int));}
	    ga_memcpy_int(  A->score_seq,B->score_seq,B->nseq);
	    B->score_res=A->score_res;

	    B->score_aln=A->score_aln;
	    B->score=A->score;
	    B->ibit=A->ibit;
	    B->cpu=A->cpu;
	    B->finished=A->finished;

/*Output Options*/
	    B->output_res_num=A->output_res_num;
	    B->residue_case=A->residue_case;
	    B->expand=A->expand;

	    B->CL=A->CL;
	    B->random_tag=A->random_tag;

/*Make the function Recursive */
	    if ( A->A)
	      {
		B->A=copy_aln (A->A, NULL);
	      }
	    else B->A=NULL;

	    return B;
	}