set_window.c

Go to the documentation of this file.
00001 /*
00002  *******************************************************************
00003  * G_set_window (window)
00004  *     Cell_head *window          window to become operative window
00005  *
00006  *   Establishes 'window' as the current working window.  Any opened
00007  *   cell files has its file-to-window mapping reworked.
00008  *
00009  *******************************************************************
00010  * G_get_set_window (window)
00011  *     Cell_head *window
00012  * 
00013  *   The current working window values are returned in the structure
00014  *   'window'.
00015  *******************************************************************/
00016 
00017 #include "gis.h"
00018 #include "glocale.h"
00019 #include "G.h"
00020 
00021 int G_get_set_window (struct Cell_head *window)
00022 {
00023     G__init_window() ;
00024     G_copy((char *) window, (char *) &G__.window, sizeof(*window) ) ;
00025     
00026     return 1;
00027 }
00028 
00029 int G_set_window (struct Cell_head *window)
00030 {
00031     int i;
00032     int maskfd;
00033     char *err;
00034 
00035 /* adjust window, check for valid window */
00036 /* adjust the real one, not a copy
00037     G_copy (&twindow, window, sizeof(struct Cell_head));
00038     window = &twindow;
00039 */
00040 
00041     if ((err = G_adjust_Cell_head (window, 0,0)))
00042     {
00043         G_warning ("G_set_window(): %s", err);
00044         return -1;
00045     }
00046 
00047 /* except for MASK, cell files open for read must have same projection
00048  * and zone as new window
00049  */
00050     maskfd = G__.auto_mask > 0 ? G__.mask_fd : - 1;
00051     for (i = 0; i < MAXFILES; i++)
00052     {
00053         if (G__.fileinfo[i].open_mode == OPEN_OLD)
00054         {
00055             if (G__.fileinfo[i].cellhd.zone == window->zone &&
00056                 G__.fileinfo[i].cellhd.proj == window->proj)
00057                     continue;
00058             if (i != maskfd)
00059             {
00060                 G_warning (_("G_set_window(): projection/zone differs from that of currently open raster files"));
00061                 return -1;
00062             }
00063         }
00064     }
00065 
00066 /* close the mask */
00067     if (G__.auto_mask > 0)
00068     {
00069         G_close_cell (maskfd);
00070 /*      free (G__.mask_buf);*/
00071         G__.mask_fd = -1;
00072         G__.auto_mask = -1;     /* turn off masking */
00073     }
00074 
00075 /* copy the window to the current window */
00076     G_copy ((char *) &G__.window, (char *) window, sizeof (*window));
00077 
00078     G__.window_set = 1;
00079 
00080 /* now for each possible open cell file, recreate the window mapping */
00081 /*
00082  * also the memory for reading and writing must be reallocated for all opened
00083  * cell files
00084 */
00085     for (i = 0; i < MAXFILES; i++)
00086     {
00087         if(G__.fileinfo[i].open_mode != OPEN_OLD &&
00088            G__.fileinfo[i].open_mode != OPEN_NEW_UNCOMPRESSED &&
00089            G__.fileinfo[i].open_mode != OPEN_NEW_COMPRESSED &&
00090            G__.fileinfo[i].open_mode != OPEN_NEW_RANDOM)
00091               continue;
00092 
00093         if (G__.fileinfo[i].open_mode == OPEN_OLD)
00094             G__create_window_mapping (i);
00095 /* code commented 10/1999 due to problems */
00096 /*      else */
00097         /* opened for writing */
00098 /*      {
00099             free(G__.fileinfo[i].data);
00100             G__.fileinfo[i].data = (unsigned char *) G_calloc (G__.window.cols,
00101                  G_raster_size(G__.fileinfo[i].map_type));
00102         }
00103 */
00104         /* allocate null bitstream buffers for reading/writing null rows */
00105 /*      for (j=0;j< NULL_ROWS_INMEM; j++)
00106         {
00107            free(G__.fileinfo[i].NULL_ROWS[j]);
00108            G__.fileinfo[i].NULL_ROWS[j] = G__allocate_null_bits(G__.window.cols);
00109         }
00110 */
00111 
00112         /* initialize : no NULL rows in memory */
00113 /*      G__.fileinfo[i].min_null_row = (-1) * NULL_ROWS_INMEM;
00114         if(G__.fileinfo[i].null_cur_row > 0)
00115         {
00116             G_warning(
00117              "Calling G_set_window() in the middle of writing map %s", 
00118                        G__.fileinfo[i].name);
00119             G__.fileinfo[i].null_cur_row = 0;
00120         }
00121 */
00122     }
00123 
00124 /* turn masking (back) on if necessary */
00125     G__check_for_auto_masking ();
00126 
00127 /* reallocate/enlarge the G__. buffers for reading raster maps */
00128     G__reallocate_null_buf();
00129     G__reallocate_mask_buf();
00130     G__reallocate_temp_buf();
00131     G__reallocate_work_buf(sizeof(DCELL));
00132     G__reallocate_work_buf(XDR_DOUBLE_NBYTES);
00133     /* we want the number of bytes per cell to be maximum
00134        so that there is enough memory for reading and writing rows */
00135 
00136     return 1;
00137 }

Generated on Wed Aug 23 17:49:23 2006 for GRASS by  doxygen 1.4.7