/* Cconvolution.cpp */ #include "defs.h" //function prototypes int load_kernels(MONO_KERNELS *, char []); int load_geometry(DOUBLE_GRID *, char []); int load_beam(BEAM *, char []); int calc_deff(DOUBLE_GRID *,DOUBLE_GRID *, DOUBLE_GRID *, BEAM *); int terma_kerma(DOUBLE_GRID *,DOUBLE_GRID *,DOUBLE_GRID *,MONO_KERNELS *,DOUBLE_GRID *); int make_poly_kernel(MONO_KERNELS *, KERNEL *); int calc_dose(DOUBLE_GRID *,DOUBLE_GRID *,DOUBLE_GRID *,KERNEL *,BEAM *, DOUBLE_GRID *); int terma_dose_masks(DOUBLE_GRID *, DOUBLE_GRID *, BEAM *); int convolution(MONO_KERNELS *, BEAM *, DOUBLE_GRID *, char *); char errstr[200]; // error string that all routines have access to int main(int argc, char *argv[]) // Expects four input arguments: // 1) kernel_filenames -- contains a list of the kernel files // 2) geometry_filenames -- contains a list of the geometry files // 3) beamspec batch file -- locations of beamspec files in batch // 4) beamlet batch file -- locations of resulting beamlets in batch { int i,j; char beamspec_filename[100]; char dose_filename[100]; char tmpstr[200]; DOUBLE_GRID density; MONO_KERNELS mono_kernels; BEAM beam; FILE *beam_batch_file; FILE *dose_batch_file; FILE *beam_file; /* // print the arguments printf("Input arguments:\n"); for (j=1;jx_count; N = density->y_count; Q = density->z_count; Ntotal = M*N*Q; // attempt to open the dose file if ((dose_file = fopen(dose_filename,"wb")) == NULL) { sprintf(errstr,"Failed to open dose file"); return(FAILURE); } // Allocate memory for all of the grids and fill them all with zeros if ((terma_mask.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for terma_mask."); return(FAILURE); } if ((dose_mask.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for dose_mask."); return(FAILURE); } if ((deff.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for deff."); return(FAILURE); } if ((terma.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for terma."); return(FAILURE); } if ((kermac.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for kermac."); return(FAILURE); } if ((dose.matrix = (double *)malloc(sizeof(double)*Ntotal)) == NULL) { sprintf(errstr,"Could not allocate memory for dose."); return(FAILURE); } for (i=0;i 0.0) Nind++; // allocate memory for sparse dose data dose_ind = (int *)malloc(sizeof(int)*Nind); dose_data = (double *)malloc(sizeof(double)*Nind); // store the sparse data j = 0; // index just for the sparse data for (i=0;i 0.0) { dose_ind[j] = i; dose_data[j] = dose.matrix[i]; j++; } // save dose to a file // save the total file size first, then the number of non-zero elements fwrite(&M,sizeof(int),1,dose_file); fwrite(&N,sizeof(int),1,dose_file); fwrite(&Q,sizeof(int),1,dose_file); fwrite(&Nind,sizeof(int),1,dose_file); fwrite(dose_ind,sizeof(int),Nind,dose_file); fwrite(dose_data,sizeof(double),Nind,dose_file); fclose(dose_file); //diagnostic lines: /* FILE *fid; fid = fopen("dose.bin","wb"); fwrite(dose.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("terma.bin","wb"); fwrite(terma.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("kermac.bin","wb"); fwrite(kermac.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("deff.bin","wb"); fwrite(deff.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("terma_mask.bin","wb"); fwrite(terma_mask.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("dose_mask.bin","wb"); fwrite(dose_mask.matrix,sizeof(double),Ntotal,fid); fclose(fid); fid = fopen("density.bin","wb"); fwrite(density->matrix,sizeof(double),Ntotal,fid); fclose(fid); */ // free the calculation grids free(terma_mask.matrix); free(dose_mask.matrix); free(deff.matrix); free(terma.matrix); free(kermac.matrix); free(dose.matrix); free(poly_kernel.angular_boundary); free(poly_kernel.radial_boundary); // free(poly_kernel.total_matrix); for (j=0;j