/* FFT for GRASS by: Central Washington University GIS Laboratory Programmer: David B. Satnik Original FFT function provided by: Programmer : Ali R. Vali Center for Space Research WRW 402 University of Texas Austin, TX 78712-1085 (512) 471-6824 */ #define MAIN #include #include #include #include #include #include #include "globals.h" #include "local_proto.h" int main (int argc, char *argv[]) { /* Global variable & function declarations */ int inputfd, realfd, imagfd; /* the input and output file descriptors */ char *inmapset; /* the input mapset name */ struct Cell_head window; CELL *cell_row, *cell_row2; double max, min, scale, temp; int i,j; /* Loop control variables */ int or,oc; /* Original dimensions of image */ int rows,cols; /* Smallest powers of 2 >= number of rows & columns */ long totsize; /* Total number of data points */ double *data[2]; /* Data structure containing real & complex values of FFT */ int save_args(); /* function to stash the command line arguments */ struct GModule *module; struct Option *op1, *op2, *op3, *op4; const char *me; int maskfd; G_gisinit(argv[0]); me = G_program_name(); module = G_define_module(); module->keywords = _("imagery"); module->description = _("Fast Fourier Transform (FFT) for image processing."); /* define options */ op1=G_define_option(); op1->key = "input_image"; op1->type = TYPE_STRING; op1->required =YES; op1->multiple =NO; op1->gisprompt = "old,cell,raster"; op1->description = _("input raster file being fft"); op2=G_define_option(); op2->key = "real_image"; op2->type = TYPE_STRING; op2->required =YES; op2->multiple =NO; op2->gisprompt = "new,cell,raster"; op2->description = _("output real part arrays stored as raster file"); op3=G_define_option(); op3->key = "imaginary_image"; op3->type = TYPE_STRING; op3->required =YES; op3->multiple =NO; op3->gisprompt = "new,cell,raster"; op3->description = _("output imaginary part arrays stored as raster file"); op4=G_define_option(); op4->key = "range"; op4->type = TYPE_INTEGER; op4->required =NO; op4->multiple =NO; op4->answer ="255"; op4->description = _("Range of values in output display files"); /*call parser*/ if(G_parser(argc, argv)) exit(-1); strcpy(Cellmap_orig, op1->answer) ; strcpy(Cellmap_real, op2->answer) ; strcpy(Cellmap_imag, op3->answer) ; /* open input cell map */ if ((inmapset = G_find_cell(Cellmap_orig, "")) == NULL) { G_fatal_error(_("%s: %s - Unable to open the input raster map\n"), me, Cellmap_orig); exit(1); } inputfd = G_open_cell_old(Cellmap_orig, inmapset); if(inputfd < 0) exit(1); if ((maskfd = G_maskfd()) >= 0) G_warning(_("Raster MASK found, consider to remove " "(see man-page). Will continue...")); /* check command line args for validity */ if (G_legal_filename(Cellmap_real) < 0) { G_fatal_error(_("%s: %s - illegal file name for real part\n"), me, Cellmap_real); exit(1); } if (G_legal_filename(Cellmap_imag) < 0) { G_fatal_error(_("%s: %s - illegal file name for imaginary part\n"), me, Cellmap_imag); exit(1); } sscanf(op4->answer, "%d", &Range); if (Range<=0) G_fatal_error(_("Range less than or equal to zero not allowed.")); G_get_set_window(&window); /* get the current window for later */ put_orig_window(&window); /* get the rows and columns in the current window */ or = G_window_rows(); oc = G_window_cols(); rows = max_pow2(or); cols = max_pow2(oc); totsize = rows * cols; /* fprintf(stderr,"Power 2 values : %d rows %d columns\n",rows,cols); */ /* Allocate appropriate memory for the structure containing the real and complex components of the FFT. DATA[0] will contain the real, and DATA[1] the complex component. */ data[0] = (double *) G_malloc((rows*cols)*sizeof(double)); data[1] = (double *) G_malloc((rows*cols)*sizeof(double)); if (data[0] == NULL || data[1] == NULL) G_fatal_error(_("Insufficent memory for allocation of data sturcture")); /* Initialize real & complex components to zero */ G_message(_("Initializing data...\n")); { register double *dptr1, *dptr0 ; dptr0=data[0] ; dptr1=data[1] ; for (i=0; i -min ? max : -min); { register double *data0, *data1 ; register CELL *cptr1, *cptr2 ; for (i=0; i