23 #define AS_DEF_WINDOW -1 
  109 #include <grass/vask.h> 
  110 #include <grass/gis.h> 
  111 #include <grass/edit.h> 
  114 static void format_value(
int (*func) (
double, 
char *, 
int),
 
  115                          double x, 
char *
buf, 
int projection);
 
  116 static void format_northing(
double north, 
char *
buf, 
int projection);
 
  117 static void format_easting(
double east, 
char *
buf, 
int projection);
 
  118 static void format_resolution(
double res, 
char *
buf, 
int projection);
 
  119 static int hitreturn(
void);
 
  122 static char *cellhd_screen[] = {
 
  123     "                           IDENTIFY CELL HEADER",
 
  125     "           ============================= DEFAULT REGION ========",
 
  126     "           |          Default North:                           |",
 
  128     "           |           =======  CELL HEADER  =======           |",
 
  129     "           |           | NORTH EDGE:               |           |",
 
  131     " Def. West |WEST EDGE  |                           |EAST EDGE  | Def. East",
 
  133     "           |           | SOUTH EDGE:               |           |",
 
  134     "           |           =============================           |",
 
  136     "           |          Default South:                           |",
 
  137     "           =====================================================",
 
  138     "           PROJECTION:                                ZONE:",
 
  142 static char *window_screen[] = {
 
  145     "           ============================= DEFAULT REGION ========",
 
  146     "           |          Default North:                           |",
 
  148     "           |           =======  YOUR REGION  =======           |",
 
  149     "           |           | NORTH EDGE:               |           |",
 
  151     " Def. West |WEST EDGE  |                           |EAST EDGE  | Def. East",
 
  153     "           |           | SOUTH EDGE:               |           |",
 
  154     "           |           =============================           |",
 
  156     "           |          Default South:                           |",
 
  157     "           =====================================================",
 
  158     "           PROJECTION:                                ZONE:",
 
  160     "                   Default   GRID RESOLUTION   Region",
 
  161     "                            --- East-West ---",
 
  162     "                            -- North-South --",
 
  166 static char *def_window_screen[] = {
 
  167     "                         DEFINE THE DEFAULT REGION",
 
  172     "                       ====== DEFAULT REGION =======",
 
  175     "            WEST EDGE  |                           |EAST EDGE",
 
  178     "                       =============================",
 
  182     "           PROJECTION:                                ZONE:",
 
  191 static void format_value(
int (*func) (
double, 
char *, 
int),
 
  192                          double x, 
char *
buf, 
int projection)
 
  194     if (projection != PROJECTION_XY) {
 
  195         int k = (projection == PROJECTION_LL) ? 3600 : 1;
 
  196         int i = (
int)(x * k + (x < 0 ? -0.5 : 0.5));
 
  201     func(x, buf, projection);
 
  206 static void format_northing(
double north, 
char *buf, 
int projection)
 
  212 static void format_easting(
double east, 
char *buf, 
int projection)
 
  218 static void format_resolution(
double res, 
char *buf, 
int projection)
 
  232     char ll_def_north[20];
 
  233     char ll_def_south[20];
 
  234     char ll_def_east[20];
 
  235     char ll_def_west[20];
 
  236     char ll_def_ewres[20];
 
  237     char ll_def_nsres[20];
 
  241     struct Cell_head def_wind;
 
  242     double north, south, east, west;
 
  244     char buf[64], 
buf2[30], *p;
 
  250     if (type == 
AS_CELLHD && (cellhd->rows <= 0 || cellhd->cols <= 0)) {
 
  251         G_message(
"E_edit_cellhd() - programmer error");
 
  252         G_message(
"  ** rows and cols must be positive **");
 
  259         if (cellhd->proj < 0) {
 
  260             cellhd->proj = def_wind.proj;
 
  261             cellhd->zone = def_wind.zone;
 
  263         else if (cellhd->zone < 0)
 
  264             cellhd->zone = def_wind.zone;
 
  269         prj = 
"** unknown **";
 
  270     sprintf(projection, 
"%d (%s)", cellhd->proj, prj);
 
  273         if (cellhd->west >= cellhd->east || cellhd->south >= cellhd->north) {
 
  274             cellhd->north = def_wind.north;
 
  275             cellhd->south = def_wind.south;
 
  276             cellhd->west = def_wind.west;
 
  277             cellhd->east = def_wind.east;
 
  280                 cellhd->ew_res = def_wind.ew_res;
 
  281                 cellhd->ns_res = def_wind.ns_res;
 
  282                 cellhd->rows = def_wind.rows;
 
  283                 cellhd->cols = def_wind.cols;
 
  287         if (cellhd->proj != def_wind.proj) {
 
  290                     (
"header projection %d differs from default projection %d",
 
  291                      cellhd->proj, def_wind.proj);
 
  294                     (
"region projection %d differs from default projection %d",
 
  295                      cellhd->proj, def_wind.proj);
 
  297             if (!
G_yes(
"do you want to make them match? ", 1))
 
  300             cellhd->proj = def_wind.proj;
 
  301             cellhd->zone = def_wind.zone;
 
  304         if (cellhd->zone != def_wind.zone) {
 
  306                 G_message(
"header zone %d differs from default zone %d",
 
  307                           cellhd->zone, def_wind.zone);
 
  309                 G_message(
"region zone %d differs from default zone %d",
 
  310                           cellhd->zone, def_wind.zone);
 
  312             if (!
G_yes(
"do you want to make them match? ", 1))
 
  315             cellhd->zone = def_wind.zone;
 
  324         format_northing(def_wind.north, ll_def_north, def_wind.proj);
 
  325         format_northing(def_wind.south, ll_def_south, def_wind.proj);
 
  326         format_easting(def_wind.east, ll_def_east, def_wind.proj);
 
  327         format_easting(def_wind.west, ll_def_west, def_wind.proj);
 
  328         format_resolution(def_wind.ew_res, ll_def_ewres, def_wind.proj);
 
  329         format_resolution(def_wind.ns_res, ll_def_nsres, def_wind.proj);
 
  338     format_northing(cellhd->north, ll_north, cellhd->proj);
 
  339     format_northing(cellhd->south, ll_south, cellhd->proj);
 
  340     format_easting(cellhd->east, ll_east, cellhd->proj);
 
  341     format_easting(cellhd->west, ll_west, cellhd->proj);
 
  342     format_resolution(cellhd->ew_res, ll_ewres, cellhd->proj);
 
  343     format_resolution(cellhd->ns_res, ll_nsres, cellhd->proj);
 
  351             screen = cellhd_screen;
 
  354             screen = def_window_screen;
 
  357             screen = window_screen;
 
  364             V_line(line++, *screen++);
 
  367         V_ques(ll_north, 
's', 6, 36, 10);
 
  368         V_ques(ll_south, 
's', 10, 36, 10);
 
  369         V_ques(ll_west, 
's', 9, 12, 10);
 
  370         V_ques(ll_east, 
's', 9, 52, 10);
 
  373             V_ques(ll_ewres, 
's', 18, 48, 10);
 
  374             V_ques(ll_nsres, 
's', 19, 48, 10);
 
  378             V_const(ll_def_north, 
's', 3, 36, 10);
 
  379             V_const(ll_def_south, 
's', 13, 36, 10);
 
  380             V_const(ll_def_west, 
's', 9, 1, 10);
 
  381             V_const(ll_def_east, 
's', 9, 65, 10);
 
  384                 V_const(ll_def_ewres, 
's', 18, 21, 10);
 
  385                 V_const(ll_def_nsres, 
's', 19, 21, 10);
 
  389         V_const(projection, 
's', 15, 23, (
int)strlen(projection));
 
  390         V_const(&cellhd->zone, 
'i', 15, 60, 3);
 
  407             G_warning(
"Illegal value for north: %s", ll_north);
 
  412             G_warning(
"Illegal value for south: %s", ll_south);
 
  417             G_warning(
"Illegal value for east: %s", ll_east);
 
  422             G_warning(
"Illegal value for west: %s", ll_west);
 
  428                 G_warning(
"Illegal east-west resolution: %s", ll_ewres);
 
  433                 G_warning(
"Illegal north-south resolution: %s", ll_nsres);
 
  444         north = cellhd->north;
 
  445         south = cellhd->south;
 
  448         nsres = cellhd->ns_res;
 
  449         ewres = cellhd->ew_res;
 
  460             nsres = cellhd->ns_res;
 
  461             ewres = cellhd->ew_res;
 
  465         fprintf(stderr, 
"\n\n");
 
  466         G_message(
"  projection:   %s", projection);
 
  471         fprintf(stderr, 
"  north:       %s", buf);
 
  473         if (strcmp(buf, buf2) != 0) {
 
  475             fprintf(stderr, 
"  (Changed to match resolution)");
 
  477         fprintf(stderr, 
"\n");
 
  481         fprintf(stderr, 
"  south:       %s", buf);
 
  482         if (strcmp(buf, buf2) != 0) {
 
  484             fprintf(stderr, 
"  (Changed to match resolution)");
 
  486         fprintf(stderr, 
"\n");
 
  490         fprintf(stderr, 
"  east:        %s", buf);
 
  491         if (strcmp(buf, buf2) != 0) {
 
  493             fprintf(stderr, 
"  (Changed to match resolution)");
 
  495         fprintf(stderr, 
"\n");
 
  499         fprintf(stderr, 
"  west:        %s", buf);
 
  500         if (strcmp(buf, buf2) != 0) {
 
  502             fprintf(stderr, 
"  (Changed to match resolution)");
 
  504         fprintf(stderr, 
"\n\n");
 
  508         fprintf(stderr, 
"  e-w res:     %s", buf);
 
  509         if (strcmp(buf, buf2) != 0) {
 
  511             fprintf(stderr, 
"  (Changed to conform to grid)");
 
  513         fprintf(stderr, 
"\n");
 
  517         fprintf(stderr, 
"  n-s res:     %s", buf);
 
  518         if (strcmp(buf, buf2) != 0) {
 
  520             fprintf(stderr, 
"  (Changed to conform to grid)");
 
  522         fprintf(stderr, 
"\n\n");
 
  524         G_message(
"  total rows:  %15d", cellhd->rows);
 
  525         G_message(
"  total cols:  %15d", cellhd->cols);
 
  527         sprintf(buf, 
"%lf", (
double)cellhd->rows * cellhd->cols);
 
  528         *(p = strchr(buf, 
'.')) = 0;
 
  531         fprintf(stderr, 
"\n");
 
  534             if (cellhd->north > def_wind.north) {
 
  535                 G_warning(
"north falls outside the default region");
 
  539             if (cellhd->south < def_wind.south) {
 
  540                 G_warning(
"south falls outside the default region");
 
  544             if (cellhd->proj != PROJECTION_LL) {
 
  545                 if (cellhd->east > def_wind.east) {
 
  546                     G_warning(
"east falls outside the default region");
 
  550                 if (cellhd->west < def_wind.west) {
 
  551                     G_warning(
"west falls outside the default region");
 
  560             fprintf(stderr, 
"\nDo you accept this header? (y/n) [%s] > ",
 
  563             fprintf(stderr, 
"\nDo you accept this region? (y/n) [%s] > ",
 
  591 static int hitreturn(
void)
 
  595     fprintf(stderr, 
"hit RETURN -->");
 
  596     if (!fgets(buf, 100, stdin))
 
  600     if (!strncmp(buf, 
"exit", 
sizeof(buf)))
 
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
 
void V_clear(void)
Zero out prompt and answer arrays. 
 
int V_line(int linenumber, const char *text)
 
int G_yes(const char *question, int dflt)
Ask a yes/no question. 
 
int G_get_default_window(struct Cell_head *window)
read the default region 
 
int V_call(void)
Interact with the user. 
 
int E_edit_cellhd(struct Cell_head *cellhd, int type)
 
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double. 
 
void G_message(const char *msg,...)
Print a message to stderr. 
 
int G_strip(char *buf)
Removes all leading and trailing white space from string. 
 
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header. 
 
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
 
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double. 
 
int V_const(void *src, int var_type, int row, int col, int length)
 
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
 
int G_insert_commas(char *buf)
Inserts commas into a number string. 
 
char * G__projection_name(int n)
 
char * G_squeeze(char *line)
Remove superfluous white space. 
 
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double. 
 
int V_ques(void *src, int var_type, int row, int col, int length)
 
void V_intrpt_ok(void)
Allow CTRL-C.