#include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_ROOTPATH_LEN 100 #define MAX_FULLPATH_LEN 150 #define MAX_OBJECTS 64000 //max objects per frame #define MAX_NUM_SETS 100 //maximum number of image sets to process #define MAX_FILESIZE 2252800 // maximum size (in bytes) of image files allowed; 2200kB #define PATH_BKGRND "PROC/BKGRND/" #define PATH_DATASET "PROC/DATASETS/" #define DEBUG 1 int main(int argc, char *argv[]){ char raw_fn[MAX_FULLPATH_LEN], dataset_fn[MAX_FULLPATH_LEN], obj_count_fn[MAX_FULLPATH_LEN], align_fn[MAX_FULLPATH_LEN], bead_fn[MAX_FULLPATH_LEN], object_dir[MAX_FULLPATH_LEN], ROOT_PATH[MAX_ROOTPATH_LEN], curr_fn_index[5], curr_set_index[4], curr_obj_count[20], text[500], dataset_name[MAX_FULLPATH_LEN], error_string[200]; int num_frames, num_sets, set_index[MAX_NUM_SETS], curr_set, field_size, success, curr_frame, frame_counter=0; FILE *infile[MAX_NUM_SETS], *outfile; //short unsigned int input_frame=0, short unsigned int input_frame=0, input_set=0, input_size=0, input_centroid_x=0, input_centroid_y=0, input_border=0, input_value=0, input_border_temp=0; field_size = sizeof(unsigned short int); //****************** Parse command-line arguments ********************** // strcpy(ROOT_PATH, argv[1]); strcpy(dataset_name, argv[2]); num_sets = argc - 3; // //********************************************************************** //********* Open input bkgrnd files and output dataset files *********** // if(DEBUG) fprintf(stderr, "Opening input bkgrnd files and output dataset file (%d sets).\n",num_sets); // Generate filename for current output (dataset) file strcpy(dataset_fn, ""); strcat(dataset_fn, ROOT_PATH); strcat(dataset_fn, PATH_DATASET); strcat(dataset_fn, dataset_name); strcat(dataset_fn, ".dataset"); if(DEBUG) fprintf(stderr, "Opening file %s for output: ", dataset_fn); if((outfile = fopen(dataset_fn, "w")) == NULL){ fprintf(stderr, "ERROR OPENING OUTFILE.\n"); exit(42); } if(DEBUG) fprintf(stderr, "%s\n", strerror(errno)); for(curr_set = 0; curr_set < num_sets; curr_set++){ set_index[curr_set] = atoi(argv[curr_set+3]); //set indices come from cmd-line args sprintf(curr_set_index, "%03d", *(set_index + curr_set)); //convert to 0-padded 4-digit // Generate filename for current input (bead) file strcpy(bead_fn, ""); strcat(bead_fn, ROOT_PATH); strcat(bead_fn, PATH_BKGRND); strcat(bead_fn, curr_set_index); strcat(bead_fn, ".bkgrnd"); // Open files if(DEBUG) fprintf(stderr, "Opening file %s for input: ", bead_fn); if((*(infile + curr_set) = fopen(bead_fn, "r")) == NULL){ fprintf(stderr, "ERROR OPENING INFILE.\n"); exit(42); } if(DEBUG)fprintf(stderr, "%s\n", strerror(errno)); } // //********************************************************************** curr_frame = 0; while(!feof(*infile)){ frame_counter++; if((success=fread(&input_set, field_size, 1, *infile)) < 1){ break; } if(DEBUG){ fprintf(stderr, "Current frame %d\n", frame_counter); } if((success=fwrite(&input_set, field_size, 1, outfile)) < 1){ fprintf(stderr, "ERROR writing input_set to bead file %4.0d", curr_set); exit(42); } for(curr_set = 1; curr_set < num_sets; curr_set++){ if((success=fread(&input_set, field_size, 1, *(infile + curr_set))) < 1){ fprintf(stderr, "ERROR reading input_value from bead file %4.0d", curr_set); exit(42); } if((success=fwrite(&input_set, field_size, 1, outfile)) < 1){ fprintf(stderr, "ERROR writing input_value to bead file %4.0d", curr_set); exit(42); } }//end for(curr_set) }//end while(!eof) for(curr_set = 0; curr_set < num_sets; curr_set++){ fclose(*(infile + curr_set)); } fclose(outfile); // //********************************************************************** }