00001 #include "gis.h" 00002 #include <stdio.h> 00003 00024 char * 00025 G_align_window (window, ref) 00026 struct Cell_head *window, *ref; 00027 { 00028 int preserve; 00029 double floor(), ceil(); 00030 00031 window->ns_res = ref->ns_res; 00032 window->ew_res = ref->ew_res; 00033 window->zone = ref->zone; 00034 window->proj = ref->proj; 00035 00036 preserve = window->proj == PROJECTION_LL && window->east == (window->west+360); 00037 window->south = 00038 G_row_to_northing (ceil(G_northing_to_row (window->south, ref)), ref); 00039 window->north = 00040 G_row_to_northing (floor(G_northing_to_row (window->north, ref)), ref); 00041 window->east = 00042 G_col_to_easting (ceil(G_easting_to_col (window->east, ref)), ref); 00043 window->west = 00044 G_col_to_easting (floor(G_easting_to_col (window->west, ref)), ref); 00045 00046 if (window->proj == PROJECTION_LL) 00047 { 00048 while (window->north > 90.0) 00049 window->north -= window->ns_res; 00050 while (window->south < -90.0) 00051 window->south += window->ns_res; 00052 if (preserve) 00053 window->east = window->west + 360; 00054 else 00055 while (window->east - window->west > 360.0) 00056 window->east -= window->ew_res; 00057 } 00058 00059 return G_adjust_Cell_head (window, 0, 0); 00060 }