1 /* updated to GRASS 5FP 11/99 Markus Neteler */
2 
3 /***************************************************************************/
4 
5 /***                                                                     ***/
6 
7 /***                            write_rast()                             ***/
8 
9 /***  Extracts real component from complex array and writes as raster.   ***/
10 
11 /***                  Jo Wood, V1.0, 20th October, 1994  		 ***/
12 
13 /***                                                                     ***/
14 
15 /***************************************************************************/
16 
17 #include <grass/raster.h>
18 #include <grass/glocale.h>
19 #include "frac.h"
20 
write_rast(double * data[2],int nn,int step)21 int write_rast(double *data[2],	/* Array holding complex data.          */
22 	       int nn,		/* Size of side of array.               */
23 	       int step		/* Version of file to send.             */
24     )
25 {
26 
27     /*------------------------------------------------------------------*/
28     /*                              INITIALISE                          */
29 
30     /*------------------------------------------------------------------*/
31 
32     DCELL *row_out;		/* Buffers to hold raster rows.         */
33 
34     char file_name[GNAME_MAX];	/* Name of each file to be written      */
35     struct History history;	/* cmd line history metadata */
36 
37     int nrows,			/* Will store the current number of     */
38       ncols,			/* rows and columns in the raster.      */
39       row, col;			/* Counts through each row and column   */
40 
41     /* of the input raster.                 */
42 
43     nrows = Rast_window_rows();	/* Find out the number of rows and      */
44     ncols = Rast_window_cols();	/* columns of the raster view.          */
45 
46     row_out = Rast_allocate_d_buf();
47 
48     /*------------------------------------------------------------------*/
49     /*         Open new file and set the output file descriptor.        */
50 
51     /*------------------------------------------------------------------*/
52 
53     if (Steps != step)
54 	sprintf(file_name, "%s.%d", rast_out_name, step);
55     else
56 	strcpy(file_name, rast_out_name);
57 
58     fd_out = Rast_open_new(file_name, DCELL_TYPE);
59 
60     /*------------------------------------------------------------------*/
61     /*  Extract real component of transform and save as a GRASS raster. */
62 
63     /*------------------------------------------------------------------*/
64 
65     for (row = 0; row < nrows; row++) {
66 	for (col = 0; col < ncols; col++)
67 	    *(row_out + col) = (DCELL) (*(data[0] + row * nn + col) * 100000);
68 
69 	Rast_put_row(fd_out, (DCELL *) row_out, DCELL_TYPE);
70     }
71 
72     Rast_close(fd_out);
73     Rast_short_history(file_name, "raster", &history);
74     Rast_command_history(&history);
75     Rast_write_history(file_name, &history);
76 
77     return 0;
78 }
79