Пример #1
0
int main(int argc, char ** argv){
	
	if (argc < 4){
		printf("USAGE: naive_multiply input_file_1.ext input_file_2.ext output_file.ext\n");
		printf("where ext is either hdf5 or txt\n");
		return 0;
	}
	
	std::string in1_str(argv[1]);//convert char* -> string
	std::string in2_str(argv[2]);
	std::string out_str(argv[3]);
	
	std::string in1_ext= GetFileExtension(in1_str);//extract file extention
	std::string in2_ext= GetFileExtension(in2_str);
	std::string out_ext= GetFileExtension(out_str);
	
	std::vector<int> in1(0,0);//doesn't matter what we initialize to, read will clear it
	std::vector<int> in2(0,0);
	std::vector<int> out(0,0);
	
	//read first input file
	if(in1_ext.compare("txt")==0){
		text_read(in1_str,in1);
	}else{// if(in1_ext.compare("hdf5")==0){
		hdf5_read(in1_str,in1);//hdf5 read
	}//else{
	//	std::cout << in1_ext << " files not supported!!" << std::endl;
	//	return 1;
	//}
	
	//read second input file
	if(in2_ext.compare("txt")==0){
		text_read(in2_str,in2);
	}else{// if(out_ext.compare("hdf5")==0){
		hdf5_read(in2_str,in2);//hdf5 read
	}//else{
	//	std::cout << in2_ext << " files not supported!" << std::endl;
	//	return 1;
	//}
	
	clock_t start=clock();
	//do the matrix multiply
	multiply(in1,in2,out);
	std::cout << (in1[0]) << "	" << (clock()-start) << std::endl;
	
	//write the output file
	if(out_ext.compare("txt")==0){
		text_write(out_str,out);
	}else if(out_ext.compare("hdf5")==0){
		hdf5_write(out_str,out);//hdf5 write
	}else{
		std::cout << out_ext << " files not supported" << std::endl;
		return 1;
	}
	
	return 0;
}
Пример #2
0
int write_raw_hdf5(hid_t input, FILE *raw){

    int width,height;
    unsigned char *buf;
    hsize_t dims[10];
    hid_t memtype,dset,group;
    herr_t status;
    int kk,ntot;
    double lut[1000],lut_max;

    for(kk=0;kk<1000;kk++) lut[kk] = 0;
 
    hdf5_read(lut,input,"/","","Analog Cal Reconstruction Levels",'d');
    
    lut_max = 0;
    for(kk=0;kk<1000;kk++) if(fabs(lut[kk])>lut_max) lut_max = fabs(lut[kk]);

    //lut_max = lut_max*1.41421;

    hdf5_read(dims,input,"/S01","B001","",'n');
    height = (int)dims[0];
    width = (int)dims[1];
    ntot = height * width;
    
    buf = (unsigned char *)malloc(height*width*sizeof(unsigned char)*2);

    group = H5Gopen(input,"/S01",H5P_DEFAULT);
    dset = H5Dopen (group,"B001",H5P_DEFAULT);
    
    // data come as signed character with zero mean
    memtype = H5T_STD_U8LE;

    status = H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);

    for(kk=0;kk<ntot*2;kk++) buf[kk] = (unsigned char)(127.0*lut[(int)buf[kk]]/lut_max+127.0);

    printf("Writing raw..Image Size: %d X %d...\n",width,height);

    /* write the data file */
    fwrite(buf,sizeof(unsigned char),height*width*2,raw);

    free(buf);
    return(1);
}
Пример #3
0
int pop_led_hdf5(hid_t input,state_vector *sv){
    int i,count,iy;
    char tmp_c[200],date[200];
    double t[200],t0,t_tmp;
    unsigned short tmp_i[200];
    double x[600], v[600];
    
    hdf5_read(tmp_i,input,"/","","Number of State Vectors",'i');
    count = tmp_i[0];
    
    hdf5_read(tmp_c,input,"/","","Reference UTC",'c');
    cat_nums(date,tmp_c);
    str_date2JD(tmp_c,date);
    t0 = str2double(tmp_c);
    date[4]='\0';
    iy = (int)str2double(date);
    hdf5_read(t,input,"/","","State Vectors Times",'d');
    hdf5_read(x,input,"/","","ECEF Satellite Position",'d');
    hdf5_read(v,input,"/","","ECEF Satellite Velocity",'d');
    //fprintf(stderr,"%.15f\n",x[3]);
    
    for (i=0;i<count;i++){
        t_tmp = t[i]/86400.0+t0;
        sv[i].yr = iy;
        sv[i].jd = (int)(t_tmp - trunc(t_tmp/1000.0)*1000.0);
        sv[i].sec = (t_tmp - trunc(t_tmp))*86400.0;
        sv[i].x = (double)x[i*3];
        sv[i].y = (double)x[i*3+1];
        sv[i].z = (double)x[i*3+2];
        sv[i].vx = (double)v[i*3];
        sv[i].vy = (double)v[i*3+1];
        sv[i].vz = (double)v[i*3+2];
        //fprintf(stderr,"%d %d %.3f %.6f %.6f %.6f %.8f %.8f %.8f \n",sv[i].yr,sv[i].jd,sv[i].sec,x[i*3],x[i*3+1],x[i*3+2],v[i*3],v[i*3+1],v[i*3+2]);
    }

    printf("%d Lines Written for Orbit...\n",count);

    return(count);
}
Пример #4
0
/*----------------------------------------------------------------------------------------------------------------------------*/
int main(int argcount, char** argvector) {

	// basic variables
	char file[1024]; 
	char outfile[1024];
	char buf[32];

	int steps, counter;

	double perc;

	// check whether the right amount of arguments is given
	if (argcount != 2) {
		fprintf(stderr, "Please provide only a filename to read from, process will terminate.\n");
		return EXIT_FAILURE;
	}

	// copy the filename, we will need it
	strncpy(file, argvector[1], 1024);

	// user output
	fprintf(stderr, "Reading file: %s\n", file);

	// read from the given file, check whether successful
	struct parameters *param = hdf5_init(file);

	if (param == NULL) {
		return EXIT_FAILURE;
	}

	// copy the number of steps we have
	steps = param->steps;

	// initiate the SDL libraries, check if successful
	if (initiate(param) != EXIT_SUCCESS) 
		return EXIT_FAILURE;

	// user output
	fprintf(stderr, "Computing...\n");

	// initiate counter
	counter = 0;

	// iterate over all 50 steps, compute filenames and make pictures
	for (int i=0; i<=steps; i+=3) {
		// compute percentage of completed iterations
		perc = 100.*i/steps;

		// output percentage to user
		fprintf(stderr, "Progress: \t\t[");

		for (int j=0; j<floor(perc); j++) {
			fprintf(stderr, "=");
		}

		if (perc != 100)
			fprintf(stderr, ">");

		for (int j=floor(perc)+1; j<100; j++) {
			fprintf(stderr, ".");
		}

		fprintf(stderr, "] \t%.1lf%%\r", perc);

		// compute the next filename
		strncpy(outfile, "/home/ayra/.images/image_", 984);

		sprintf(buf, "%d", counter);
		strncat(outfile, buf, 32);
		strncat(outfile, ".bmp\0", 5);

		// update position and psi4 array to the next step
		hdf5_read(i);

		// build the picture
		draw_picture(i, outfile);

		// increase counter
		counter++;
	}

	// user output
	fprintf(stderr, "\nDone!\n\n");

	// free memory used by SDL
	destroy();

	// free struct, return to caller
	free(param->positions);
	free(param->psi4);
	free(param->psi6);
	free(param);

	return EXIT_SUCCESS;
}
Пример #5
0
int pop_prm_hdf5(struct PRM *prm,hid_t input,char *file_name){
    char tmp_c[200],rec[100],date[100];
    double tmp_d[200];
    double c_speed = 299792458.0;
    hsize_t dims[10];
    int nrng = 0;
    
    set_prm_defaults(prm); /* use many default values */
    prm->first_sample = 0;
    prm->SLC_scale = 1.0;
    prm->az_res = 3.0;
    prm->xmi = 127.0; /* this is the mean value of one pair.  need to do more */
    prm->xmq = 127.0;
    strasign(prm->dtype,"a",0,0);
    prm->SC_identity = 8; /* (1)-ERS1 (2)-ERS2 (3)-Radarsat (4)-Envisat (5)-ALOS (6)-  (7)-TSX (8)-CSK (9)-RS2 (10) Sentinel-1a*/
    prm->ra = 6378137.00; //equatorial_radius
    prm->rc = 6356752.31; //polar_radius
    strcpy(tmp_c,file_name);
    strcat(tmp_c,".raw");
    strcpy(prm->input_file,tmp_c);
    strcpy(tmp_c,file_name);
    strcat(tmp_c,".LED");
    strcpy(prm->led_file,tmp_c);
    strcpy(tmp_c,file_name);
    strcat(tmp_c,".SLC");
    strcpy(prm->SLC_file,tmp_c);
    
    hdf5_read(tmp_d,input,"/S01","","Sampling Rate",'d');
    prm->fs = tmp_d[0];
    
    hdf5_read(tmp_d,input,"/","","Radar Wavelength",'d');
    prm->lambda = tmp_d[0];
    
    hdf5_read(tmp_d,input,"/S01","","Range Chirp Rate",'d');
    prm->chirp_slope = tmp_d[0];
    
    hdf5_read(tmp_d,input,"/S01","","Range Chirp Length",'d');
    prm->pulsedur = tmp_d[0];
    
    hdf5_read(rec,input,"/","","Acquisition Mode",'c');
    hdf5_read(tmp_d,input,"/S01","","PRF",'d');
    prm->prf = tmp_d[0];
    if(strcmp(rec,"SPOTLIGHT") == 0){
        hdf5_read(tmp_d,input,"/S01","SBI","Line Time Interval",'d');
        prm->prf = 1.0/tmp_d[0];
    }
    
    hdf5_read(rec,input,"/","","Product Type",'c');
    if(strcmp(rec,"RAW_B") == 0){
        // RAW
        printf("Product Type being RAW...\n");
        hdf5_read(tmp_d,input,"/S01","B001","Range First Times",'d');
        prm->near_range = tmp_d[0]*c_speed/2;
        
        hdf5_read(tmp_c,input,"/","","Scene Sensing Start UTC",'c');
        cat_nums(date,tmp_c);
        str_date2JD(tmp_c,date);
        prm->clock_start = str2double(tmp_c);
        date[4]='\0';
        prm->SC_clock_start = prm->clock_start + 1000.*str2double(date);
        
    }else if (strcmp(rec,"SCS_B") == 0){
        // SLC
        printf("Product Type being SLC...\n");
        hdf5_read(tmp_d,input,"/S01","SBI","Zero Doppler Range First Time",'d');
        prm->near_range = tmp_d[0]*c_speed/2;
        
        hdf5_read(tmp_c,input,"/","","Reference UTC",'c');
        hdf5_read(tmp_d,input,"/S01","SBI","Zero Doppler Azimuth First Time",'d');
        cat_nums(date,tmp_c);
        str_date2JD(tmp_c,date);
        prm->clock_start = str2double(tmp_c) + tmp_d[0]/86400.0;
        date[4]='\0';
        prm->SC_clock_start = prm->clock_start + 1000.*str2double(date);
        
        prm->fdd1 = 0.0;
        prm->fddd1 = 0.0;
        
    }else{
        // Unknown type
        fprintf(stderr,"Product type being nither RAW nor SLC...\n");
        return(-1);
    }
    
    hdf5_read(tmp_c,input,"/","","Orbit Direction",'c');
    if(strcmp(tmp_c,"ASCENDING") == 0){
        strasign(prm->orbdir,"A",0,0);
    }
    else{
        strasign(prm->orbdir,"D",0,0);
    }
    
    hdf5_read(tmp_c,input,"/","","Look Side",'c');
    if(strcmp(tmp_c,"RIGHT") == 0){
        strasign(prm->lookdir,"R",0,0);
    }
    else{
        strasign(prm->lookdir,"L",0,0);
    }
    
    hdf5_read(dims,input,"/S01","B001","",'n');

    prm->bytes_per_line = (int)dims[1]*2;
    prm->good_bytes = prm->bytes_per_line;
    prm->num_rng_bins = prm->bytes_per_line/2;

    /* pad the near and far range with 1200 samples */
    prm->chirp_ext	= 2400;
    nrng = 2 + (int)(prm->num_rng_bins/1200.);
    prm->num_rng_bins = 1200 * nrng;
    
    prm->num_lines = (int)dims[0] - (int)dims[0]%4;
    prm->SC_clock_stop = prm->SC_clock_start + prm->num_lines/prm->prf/86400;
    prm->clock_stop = prm->clock_start + prm->num_lines/prm->prf/86400;
    prm->nrows = 8192;
    prm->num_valid_az = 6400;
    prm->num_patches = (int)((float)prm->num_lines/prm->num_valid_az + 0.5);

    printf("PRM set for Image File...\n");
    
    return(1);
}
Пример #6
0
/*-------------------------------------------------------------------------------------------------------*/
int main (int argcount, char** argvector) {

	int 	ret_thread;

	time_t 	inittime, currenttime, runtime;
	char*	timestring;

	// check whether the right amount of arguments is given
	if (argcount != 2) {
		fprintf(stderr, "Please provide only a filename to read from, process will terminate.\n");
		return EXIT_FAILURE;
	}

	// user output
	fprintf(stderr, "Reading file...\n");

	// read from the given file, check whether successful
	struct parameters *param = hdf5_read(argvector[1]);

	if (param == NULL) {
		return EXIT_FAILURE;
	}

	// copy data from struct
	N 			= param->N;
	steps		= param->steps;
	positions 	= param->positions;

	// user output
	fprintf(stderr, "Allocating memory...\n");

	// allocate memory, check whether successful
	psi4 	= malloc((steps+1)*N*sizeof(double));
	psi6 	= malloc((steps+1)*N*sizeof(double));
	laning 	= malloc((steps+1)*N*sizeof(double));

	if (psi4 == NULL || psi6 == NULL || laning == NULL) {
		fprintf(stderr, "Memory for psi and laning values could not be allocated, process will terminate. \n");
		return EXIT_FAILURE;
	}

	// construct a new struct, initiate the helper file
	struct variables var = {.N = N, .positions = positions, .psi4 = psi4, .psi6 = psi6, .laning = laning};
	init(&var);

	// user output
	fprintf(stderr, "Starting computation...\n");

	// get current time, needed for runtime
	time(&inittime);

	// set waiting values
	psi4_done 	= 0;
	psi6_done 	= 0;
	laning_done = 0;

	// initiate threads, check if successful
	threads = malloc(3*sizeof(pthread_t));

	ret_thread 	= pthread_create(&(threads[0]), NULL, (void*)&thread_psi4, NULL);

	if (ret_thread != 0) {
		fprintf(stderr, "Thread %d could not be created. \n", 0);
		exit(EXIT_FAILURE);
	}
	
	ret_thread 	= pthread_create(&(threads[1]), NULL, (void*)&thread_psi6, NULL);

	if (ret_thread != 0) {
		fprintf(stderr, "Thread %d could not be created. \n", 1);
		exit(EXIT_FAILURE);
	}
	
	ret_thread 	= pthread_create(&(threads[2]), NULL, (void*)&thread_laning, NULL);

	if (ret_thread != 0) {
		fprintf(stderr, "Thread %d could not be created. \n", 2);
		exit(EXIT_FAILURE);
	}

	// wait until all threads have finished iterating
	while(psi4_done != 1 || psi6_done != 1 || laning_done != 1) {
		// compute and print runtime to user, wait for half a second
		time(&currenttime);
		runtime = currenttime - inittime;

		fprintf(stderr, "Computing time: \t\t\t%d s\r", (int)(runtime));

		usleep(500*1000);
	}

	fprintf(stderr, "\nDone, writing to file...\n");
	// create a new struct for storing data to file
	struct analysis data = {.N = N, .steps = steps, .file = argvector[1], .psi4 = psi4, .psi6 = psi6, .laning = laning};

	// store data to file
	if (add_analysis(&data) != EXIT_SUCCESS) 
		return EXIT_FAILURE;

	// user output
	fprintf(stderr, "Finished successfully!\n");

	// return to caller
	return EXIT_SUCCESS;
}
Пример #7
0
/*----------------------------------------------------------------------------------------------------------------------------*/
int main(int argcount, char** argvec) {

	// basic variables
	char	infile[1024];
	int 	N;

	double* positions;

	double 	min = 1.0;


	// check if the right number of arguments ist given
	if (argcount != 2) {
		fprintf(stderr, "Please provide a filename to read from. \n");
		return EXIT_FAILURE;
	}

	// read the filenames and binsize
	strncpy(infile, argvec[1], 1024);

	// read data from file
	struct parameters *param = hdf5_init(infile);

	// calculate fraction of A particles and the cutoff sizes
	N 		= param->N;
	
	// copy the current positions
	positions = param->positions;

	// iterate over the last half of the steps
	for (int step=round(param->last_step/2.)+1; step<=param->last_step; step++) {

		// read the current step, increment step counter (done so nobody f***s up in determining the amount of steps read)
		hdf5_read(step);

		double loc_min = param->L_y;
		double dx, dy, r;

		for (int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {

				if (i==j)
					continue;

				dx = positions[2*i] 	- positions[2*j];
				dy = positions[2*i+1] 	- positions[2*j+1];

				r  = sqrt(dx*dx + dy*dy);

				if (r < loc_min)
					loc_min = r;
			}
		}

		if (loc_min < min)
			min = loc_min;
		
	}

	fprintf(stdout, "%lf\n", min);

	free(positions);
	free(param);

	// return to caller
	return EXIT_SUCCESS;
}