Example #1
0
static char *merge_input(char *input, char **buf, size_t *buflen)
{
	char *p, *ip;
	size_t offset = 0;

	offset = strlen(*buf);
	if (offset <= 0)
		return NULL;

	ip = input;
	while ((*buf)[offset - 1] == '\n' && (*ip == '\t' || *ip == ' ')) {
		while (*ip == '\t' || *ip == ' ')
			++ip;
		(*buf)[offset - 1] = ' ';
		p = cgetline(ip, buf, offset, buflen);
		if (!p)
			return NULL;
		if (p == ip)
			break;
		offset += p - ip;
		ip = p;
	}

	return ip;
}
Example #2
0
char *parse_header(char *input, struct MailHeader *mh)
{
	static char *buf = NULL;
	static size_t buflen = BUF_LEN;
	char *next_line = NULL;
	int i;
	int (*cmpfun)(const char *, const char *, size_t);

	if (!input || !mh)
		return NULL;

	/*
	 * Set default value
	 */
	memset(mh, 0, sizeof(struct MailHeader));
	strcpy(mh->content_type, "text/plain");
	strcpy(mh->charset, "iso-8859-1");
	strcpy(mh->transenc, "7bit");

	if (!buf)
		buf = (char *)malloc(buflen);
	if (!buf)
		return NULL;
	memset(buf, 0, buflen);

	next_line = cgetline(input, &buf, 0, &buflen);
	while (buf[0] && buf[0] != '\n') {
		for (i = 0 ; hh[i].header ; ++i) {
			cmpfun = (hh[i].casesence) ? strncmp : strncasecmp;
			if (!cmpfun(buf, hh[i].header, strlen(hh[i].header))) {
				if (hh[i].multiline)
					next_line = merge_input(next_line, &buf, &buflen);
				if (hh[i].hdl(buf + strlen(hh[i].header) + 1, mh)) {
					next_line = NULL;
					dbg("Error at %s %30.30s\n", hh[i].header, buf + strlen(hh[i].header) + 1);
					goto out;
				}
				break;
			}
		}
		next_line = cgetline(next_line, &buf, 0, &buflen);
	}

out:
	return next_line;
}
Example #3
0
static int print_simple_content(char *input, FILE *output, char *errmsg, struct MailHeader *mh, char **next_line)
{
	static char *buf = NULL;
	static size_t buflen = BUF_LEN;
	char *ptr;
	iconv_t tobig5 = (iconv_t) -1;
	size_t offset;
	unsigned char isbase64 = 0, isqp = 0;
	int rt = 0;

	dbg("In print_simple_content.\n");

	if (output) {
		if (is_notmycharset(mh->charset))
			tobig5 = iconv_open("big5//TRANSLIT//IGNORE", mh->charset);

		if (!strncasecmp(mh->transenc, "base64", 6))
			isbase64 = 1;
		else if (!strncasecmp(mh->transenc, "quoted-printable", 16))
			isqp = 1;
	}

	if (!buf)
		buf = malloc(buflen);
	if (!buf) {
		rt = ERROR;
		goto out;
	}

	*next_line = cgetline(input, &buf, 0, &buflen);
	while (buf[0]) {
		offset = strlen(mh->boundary);
		if (offset && (ptr = strstr(buf, mh->boundary)) != NULL) {
			if (ptr[offset] == '\n')
				rt = HIT_BOUNDARY;
			else
				rt = HIT_END_BOUNDARY;
			break;
		}

		if (isbase64) {
			offset = mmdecode((unsigned char *)buf, 'b', (unsigned char *)buf);
			buf[offset] = '\0';
		} else if (isqp) {
			str_deqp(buf, buf);
		}

		if (tobig5 != (iconv_t)-1) {
			if (!str_conv(tobig5, buf, buflen)) {
				sprintf(errmsg, "%s CONVERR(%s)", mh->charset, strerror(errno));
				rt = ERROR;
				break;
			}
		}
		if (output)
			fputs(buf, output);
		*next_line = cgetline(*next_line, &buf, 0, &buflen);
	}

	if (tobig5 != (iconv_t)-1)
		iconv_close(tobig5);

out:
	return rt;

}
Example #4
0
File: 2dx_ML.c Project: C-CINA/2dx
int main()
{ 
	int dir,m,i,j,k,n,num_line, Symmetry1;
	int num_images,  *pa,sx;   /*  Prepare for merge Nimages images together into a stack of num_images patches*/

	FILE *input;
	char oneline[100];
	char *c; 
        char *tmpstring;
        char *SYMname;
	char  *imagename, *profilename, *resultsfilename, *imagenumber, *temp_imagename;
	int oversizexy[2], realcellxy[2], realcellxy1[2];
	float angle[3];


        tmpstring=(char *)calloc(200,sizeof(char));
        SYMname=(char *)calloc(200,sizeof(char));
	imagename=(char *)calloc(400,sizeof(char));
	profilename=(char *)calloc(400,sizeof(char));
	imagenumber=(char *)calloc(200,sizeof(char));
	temp_imagename=(char *)calloc(200,sizeof(char));
	resultsfilename=(char *)calloc(200,sizeof(char));

	printf("\n2dx_ML: Performs Maximum Likelihood processing. \n");

	scanf("%d",&doMLorCC);
	if(doMLorCC==0)
		printf("Weights for ref calculation... = from Maximum Likelihood estimate\n");
	else
		printf("Weights for ref calculation... = from Cross-Correlation between particle and old reference\n");
	
	scanf("%s",resultsfilename);
	
	printf("Results File Name............. = %s \n",resultsfilename);

	input=fopen("2dx_image.cfg" ,"r"); 

	/*  input  parameters from 2dx_image.cfg to generate stacks*/

	printf("\nReading  Parameters for ML:\n");
        strcpy(tmpstring,"imagename");
	imagename=cgetline(input,tmpstring);
	strcpy(temp_imagename, imagename);
	strcat(imagename,".mrc");
	printf("Image Name..................... = %s \n",imagename);

        strcpy(tmpstring,"imagenumber");
	imagenumber=cgetline(input,tmpstring);
	printf("Image Number................... = %s \n",imagenumber);

	strcpy(profilename,"image_ctfcor_profile.dat");
	printf("Profile Name................... = %s \n",profilename);


        strcpy(tmpstring,"CS");
	if(fgetline(input,tmpstring,&CS)==0) 
 		printf("CS............................. = %f  \n",CS); 
        else
 		printf(":: ERROR in CS assignment.");

        strcpy(tmpstring,"KV");
	if(fgetline(input,tmpstring, &KV )==0)
		printf("KV............................. = %f  \n",KV); 
        else
 		printf(":: ERROR in KV assignment.");

        strcpy(tmpstring,"RESMIN");
	if(fgetline(input,tmpstring, &RESMIN )==0)  
		printf("RESMIN......................... = %f  \n",RESMIN); 
        else
 		printf(":: ERROR in RESMIN assignment.");

        strcpy(tmpstring,"RESMAX");
	if(fgetline(input,tmpstring,&RESMAX )==0) 
		printf("RESMAX......................... = %f  \n",RESMAX); 
        else
 		printf(":: ERROR in RESMAX assignment.");

        strcpy(tmpstring,"defocus");
	if(fgetline(input,tmpstring, defocus)==0)
	{ 
		DIFMID1=defocus[0];
		DIFMID2=defocus[1];
		ANGAST=defocus[2];
		printf("DFMID1,DFMID2,ANGAST........... = %f,%f,%f\n",DIFMID1,DIFMID2, ANGAST); 
	}

        strcpy(tmpstring,"ML_do_whiten");         
	if(*(cgetline(input,tmpstring))=='y')
	{   do_whiten =1;
		printf("do_whiten...................... = yes \n");
	}
	else
	{   do_whiten=0;
		printf("do_whiten...................... = no \n");
	}

        strcpy(tmpstring,"ML_correct_CTF");         
	if(*(cgetline(input,tmpstring))=='y')
	{   correct_CTF =1;
		printf("correct_CTF.................... = yes \n");
	}
	else
	{   correct_CTF=0;
		printf("correct_CTF.................... = no \n");
	}

        strcpy(tmpstring,"stepdigitizer");         
	if(fgetline(input,tmpstring,&DSTEP )==0)  
		printf("DSTEP.......................... = %f\n",DSTEP); 

        strcpy(tmpstring,"magnification");         
	if(fgetline(input,tmpstring, &XMAG)==0)
		printf("Magnification (XMAG)........... = %f \n",XMAG);
	/*
		 if(igetline(input, "ML_oversizexy", oversizexy)==0)  
		 {   oversized_x=oversizexy[0];
		 oversized_y=oversizexy[1];
		 printf("ML_oversizexy................. = %d,%d\n",oversized_x,oversized_y);
		 } 
		 else printf("parameter ML_oversizexy does not exists \n");   
	 */

        strcpy(tmpstring,"ML_realcellxy_outer");         
	if(igetline(input,tmpstring, realcellxy)==0)  
	{   realcell_x=realcellxy[0];
		realcell_y=realcellxy[1];
		printf("ML_realcellxy_outer............ = %d,%d\n",realcell_x,realcell_y);
	}
	else printf("parameter ML_realcellxy_outer does not exists \n");    
	/*    
				if(igetline(input, "ML_realcellxy_inner", realcellxy1)==0)  
				{   realcell_x1=realcellxy1[0];
				realcell_y1=realcellxy1[1];
				printf("ML_realcellxy_inner............ = %d,%d\n",realcell_x1,realcell_y1);
				} 
				else printf("parameter ML_realcell_xy1 does not exists \n");   
	 */
	realcell_x1=realcell_x;
	realcell_y1=realcell_y;

        strcpy(tmpstring,"ML_mask_radius");         
	if(igetline(input,tmpstring, &mask_radius)==0) 
		printf("Mask radius.................... = %d \n",mask_radius); 
	else printf("parameter ML_mask_radius does not exists \n");   

        strcpy(tmpstring,"ML_iteration");         
	if(igetline(input,tmpstring, &Iteration)==0) 
		printf("Iteration...................... = %d \n",Iteration); 
	else printf("parameter ML_iteration does not exists \n");   

        strcpy(tmpstring,"ML_threshold_method");         
	if(igetline(input,tmpstring, &threshold_method)==0) 
	{     
		if(threshold_method==0)
		{   
                        strcpy(tmpstring,"ML_absolute_threshold");      
			if(fgetline(input,tmpstring, &threshold)==0) 
				printf("Absolute Threshold value....... = %f \n",threshold);
			else  printf("parameter ML_absolute_threshold does not exists \n");     
		}
		else  
		{               
                        strcpy(tmpstring,"ML_relative_threshold");      
                        if(fgetline(input,tmpstring, &relative_threshold)==0)    
			printf("Percentage of peaks to use..... = %.2f\n",relative_threshold);
			else printf("parameter ML_relative_threshold does not exists \n");
		}
	}
	else printf("parameter ML_threshold_method does not exists \n");   

        strcpy(tmpstring,"ML_ref_ind");         
	if(igetline(input,tmpstring, &ref_ind)==0) 
	{    
		if ( ref_ind == 0 ) 
			printf("Initial Reference (ref_ind).... = average reference \n");
		else if ( ref_ind == 1 ) 
			printf("Initial Reference (ref_ind).... = random noise \n");
		else if ( ref_ind == 2 )
			printf("Initial Reference (ref_ind).... = random particle \n");
		else
			printf("::Initial Reference (ref_ind).... = ILLEGAL CHOICE !!!! \n");
	}
	else printf("parameter ML_ref_ind does not exists \n");   

	/*
		 if(igetline(input, "ML_DS_ratio", &DS_ratio)==0) 
		 printf("DS_ratio............................ = %d \n",DS_ratio); 
		 else printf("parameter DS_ratio does not exists \n");  
	 */
        strcpy(tmpstring,"ML_rotational_symmetry");      
	if(igetline(input,tmpstring, &Symmetry1)==0) 
	{   if(Symmetry1==0) Symmetry=1;
		else if(Symmetry1==1) Symmetry=2;
		else if(Symmetry1==2) Symmetry=3;
		else if(Symmetry1==3) Symmetry=4;
		else if(Symmetry1==4) Symmetry=5;
		else if(Symmetry1==5) Symmetry=6;
		printf("Rotational Symmetry of Particle = %d \n",Symmetry); 
	}
	else printf("parameter Symmetry does not exists \n");  

        strcpy(tmpstring,"ML_lp_method");      
	if(igetline(input,tmpstring, &lp_method)==0) 
	{   
		if(lp_method==1)
			printf("Low-Pass filter................ = Gaussian \n");
		else if(lp_method==2)
			printf("Low-Pass filter................ = Sharp cutoff \n");
		else
			printf("Low-Pass filter................ = None \n");
	}
	else printf("parameter ML_lp_method does not exists \n");   	

        strcpy(tmpstring,"ML_lp_radius");      
	if(fgetline(input,tmpstring,&lp_radius)==0)
		printf("lp_radius...................... = %f \n",lp_radius); 
	else printf("paramter lp_radius does not exists \n");

        strcpy(tmpstring,"ML_MinMaxStep_angle");      
	if(fgetline(input,tmpstring, angle)==0)
	{ 
		min_angle=angle[0];
		max_angle=angle[1];
		step_angle=angle[2];
		printf("min_angle,max_angle,step_angle. = %f,%f,%f \n",min_angle, max_angle, step_angle);
	}
	else printf("Angle parameters do not exists \n"); 

        strcpy(tmpstring,"ML_terminate_ML");      
	if(fgetline(input,tmpstring,&Terminate_ML)==0)
		printf("Terminate_ML................... = %f \n",Terminate_ML); 
	else printf("paramter ML_terminate does not exists \n");

        strcpy(tmpstring,"ML_B_factor");      
	if(fgetline(input,tmpstring,&B_fac)==0)
		printf("B_factor....................... = %f \n",B_fac); 
	else printf("paramter B_factor does not exists \n");

        strcpy(tmpstring,"ML_A_factor");      
	if(fgetline(input,tmpstring,&A)==0)
		printf("A_factor....................... = %f \n",A); 
	else printf("paramter A_factor does not exists \n");

        strcpy(tmpstring,"SYM");      
	SYMname=cgetline(input,tmpstring);
	printf("Space Group.................... = %s \n",SYMname);
        SYM=0;
        if(strncmp(SYMname,"p12",3) == 0) SYM=1;
        if(strncmp(SYMname,"p22",3) == 0) SYM=1;
        if(strncmp(SYMname,"p42",3) == 0) SYM=1;
        if(strncmp(SYMname,"p31",3) == 0) SYM=1;
        if(strncmp(SYMname,"p32",3) == 0) SYM=1;
        if(strncmp(SYMname,"p62",3) == 0) SYM=1;

        strcpy(tmpstring,"ctfrev");         
	if(*(cgetline(input,tmpstring))=='y')
	{    contrast=-1;
		printf("Contrast of final map.......... = positive\n");
	}
	else
	{   contrast=1;
		printf("Contrast of final map.......... = negative\n");
	}

        strcpy(tmpstring,"phaori");      
	if(fgetline(input,tmpstring,phaori)==0)
	{	
                printf("Phase Origin................... = %f %f\n",phaori[0],phaori[1]);
                if(SYM==1)
                {       
 		        printf(":: Adding 180deg phaseshift to phase origin, due to screw axis symmetry.\n");
                        phaori[0]+=180.0;
                }
        }
        else
 		printf(":: ERROR in Phase Origin assignment.");

        strcpy(tmpstring,"lattice");      
	if(fgetline(input,tmpstring,lattice)==0)
		printf("Reciprocal Lattice............. = %f %f %f %f\n",lattice[0],lattice[1],lattice[2],lattice[3]);
        else
 		printf(":: ERROR in Reciprocal Lattice assignment.");

	fclose(input);


	free(imagenumber); 
	free(temp_imagename); 

	printf("\n::Starting ML\n\n");
	fflush(stdout);

	/*   ML main program */

	ML(imagename, profilename,resultsfilename); 
	printf("\n::2dx_ML finished correctly\n\n");
	fflush(stdout);

	free(profilename); 
	free(imagename); 
	free(resultsfilename);  




	return 0;
}