예제 #1
0
파일: main.c 프로젝트: JiGroup/common
int main (int argc, char *argv[])
{
    char lineBuf[MAXLINE];
    char refName[40], refb, alignString[10000], qualityString[10000];
    int pos, totDepth;
    int i;
    FILE *plfid;
    
    if (argc == 1) {
        fprintf(stderr, "Usage: pileup2dc [in.pileup]\n");
        return 1;
    }
    
    
    // open the pileup file for reading
    // die if error opening or reading file
    plfid = fopen(argv[1], "rd");
    
    
    // get the number of positions in the pileup
    int numLines = get_filelength(plfid);
    
    // allocate space for the depth chart
    pile_t pile[numLines];
    
    // read the pileup file and store in the structure
    for (i=0; i<numLines; i++) {
        fgets(lineBuf, MAXLINE, plfid);
        sscanf(lineBuf, "%s\t%d\t%c\t%d\t%s\t%s", refName, &pos, &refb, 
               &totDepth, alignString, qualityString);
        
        pile[i].pos = pos;
        parse_align_string ( toupper(refb), alignString, &pile[i] );
    }
    
    fclose(plfid);
    
    // export the pileup structure in depth chart format
    export_depthchart ( pile, numLines);
    
    return 0;
}
void filter_calcs(void) {
	
    //External variables
    extern char filtersinput[FILEPATH_LENGTH];
    extern char galssedinput[FILEPATH_LENGTH];
    extern char starssedinput[FILEPATH_LENGTH];
	
    //Internal variables
    long *N,ii;
    long sedlength = 0;
    long regridfactor;
    long filterlength[Nfilter]; 

    double *pnorm;
    double *filtlamb,*filtthru;

    //Allocate temporary variables
    N     = (long *)malloc(sizeof(long));
    pnorm = (double *)malloc(sizeof(double));
	
    //How many filters?
    get_num_files(filtersinput, N);
    Nfilter = *N;
    if (Nfilter<2) {
        printf("Need more than 1 filter\n");
        return;
    }
    printf("\n\nFound %ld Filters\n",Nfilter);
	
    //Read in the number of star/galaxy SEDs
    get_num_files(starssedinput, N);
    Nstartemplate = *N;
    get_num_files(galssedinput, N);
    Ngaltemplate  = *N;
	
    //Find the finest SED amongst the bunch
    for (ii=0;ii<Nstartemplate;ii++) {	
        get_filelength(ii,starssedinput,N);
        if (*N * 2 > sedlength) 
            sedlength = *N * 2;
    }
    for (ii=0;ii<Ngaltemplate;ii++) {	
        get_filelength(ii,galssedinput,N);
        if (*N * 2 > sedlength)
            sedlength = *N * 2;
    }
	
	
    //Allocate final filter arrays, which are globals
    filter_lgth_fine = (long *)malloc(Nfilter*sizeof(long)); 
    filter_lamb_fine = malloc(Nfilter*sizeof(double*));
    filter_thru_fine = malloc(Nfilter*sizeof(double*));
    norm             = (double *)malloc(Nfilter*sizeof(double));
	
	
    //Loop over the filters in the file
    for (ii=0;ii<Nfilter;ii++) {
		
        //get length
        get_filelength(ii,filtersinput, N);
        filterlength[ii]     = *N;
        regridfactor = round((float)sedlength / (float)*N);
        filter_lgth_fine[ii] = *N * regridfactor;
		
        //alloc filter arrays
        filtlamb = (double *)malloc(*N * sizeof(double));
        filtthru = (double *)malloc(*N * sizeof(double));
        filter_lamb_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
        filter_thru_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
        
        //read in the 2 column ascii filter file
        read_file(ii,filtersinput,filtlamb,filtthru);
        
        //regrid the filter to user spec, using gsl spline interpolation
        regrid_filter(filtlamb,filtthru,filterlength[ii],filter_lgth_fine[ii], \
                      filter_lamb_fine[ii],filter_thru_fine[ii]);
                    
        //calculate the flux zeropoint
        calc_normalization(filter_lamb_fine[ii],filter_thru_fine[ii], \
                           filter_lgth_fine[ii],pnorm);
        norm[ii] = *pnorm;
        printf("Filter %ld has (AB) zeropoint flux normalization: %g\n",ii,norm[ii]);
		
        free(filtlamb);
        free(filtthru);
    }
    free(pnorm);
    free(N);
	

}