[GRASS-SVN] r44655 - in grass/branches/releasebranch_6_4/imagery/i.ortho.photo: . i.photo.rectify menu

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 22 05:10:33 EST 2010


Author: mmetz
Date: 2010-12-22 02:10:33 -0800 (Wed, 22 Dec 2010)
New Revision: 44655

Added:
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/env.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/i.photo.rectify.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/target.c
Removed:
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_files.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_method.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/compress.c
Modified:
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/Makefile
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/README
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cp.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/defs.h
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/description.html
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/env.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/equ.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/exec.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/get_wind.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/global.h
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/local_proto.h
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/main.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/nearest.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/readcell.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/rectify.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/report.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/target.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/local_proto.h
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/menu.c
   grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/run.c
Log:
merge r44507-44509,44521-44523 from devbr6


Property changes on: grass/branches/releasebranch_6_4/imagery/i.ortho.photo
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/branches/develbranch_6/imagery/i.ortho.photo:44349-44350,44472-44477,44500-44502
   + /grass/branches/develbranch_6/imagery/i.ortho.photo:44349-44350,44472-44477,44500-44502,44507-44509,44521-44523

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/Makefile
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/Makefile	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/Makefile	2010-12-22 10:10:33 UTC (rev 44655)
@@ -11,8 +11,5 @@
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
-default: etc
+default: cmd
 
-$(PGM).tmp.html: description.html
-	$(INSTALL_DATA) $< $@
-

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/README
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/README	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/README	2010-12-22 10:10:33 UTC (rev 44655)
@@ -4,14 +4,10 @@
  - have changed elev reading from CELL to raster_type to support
    also FP elevations
 
- 
-Bugs:
- - somewhere the map_type is undefined in an underlying function (can't 
-   identify), so I added G_suppress_warnings(1) at top of rectify.c
-   -> the module works well
+12/2010: Markus Metz
 
- - when DEBUG3 is activated, the module silently stops in exec.c at
-   select_current_env() (line 87). Why???
-   However, not a real bug. Seems to be a problem of exit status or
-   whatever.
+ - sync'ed to i.rectify as far as possible
+ - the module is now non-interactive and stand-alone: 
+   typing i.photo.rectify on the commandline pops up a gui if GRASS is started with a gui
+ - i.ortho.photo has a new interactive part to set the options for i.photo.rectify 
 

Deleted: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_files.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_files.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_files.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,109 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <grass/glocale.h>
-#include "global.h"
-#include <grass/vask.h>
-
-#define NFILES 15
-
-int ask_files(char *groupname)
-{
-    char result[NFILES][15];
-    int repeat;
-    int do_all;
-    int i, k, f1;
-    int *r;
-    char **nm;
-
-    r = ref_list;
-    nm = new_name;
-
-    repeat = 0;
-
-    /* name extension for rectified maps */
-    extension = (char *)G_malloc(GNAME_MAX * sizeof(char));
-    sprintf(extension, ".ortho");
-
-    repeat = 1;
-    while (repeat) {
-	repeat = 0;
-	V_clear();
-	V_line(1, _("Enter an extension to be appended to rectified maps:"));
-	V_ques(extension, 's', 3, 0, 20);
-	V_intrpt_ok();
-	if (!V_call())
-	    exit(0);
-
-	/* test for legal file name */
-	sprintf(result[0], "%s%s", group.group_ref.file[0].name, extension);
-	if (G_legal_filename(result[0]) < 0) {
-	    G_clear_screen();
-	    fprintf(stderr, _("Extension <%s> is illegal"), extension);
-	    repeat = G_yes(_("\nChoose another extension? "), 1);
-	    if (!repeat) {
-		fprintf(stderr,_("Orthorectification cancelled."));
-		exit(0);
-	    }
-	}
-    }
-	
-    G_debug(1, "Extension: %s", extension);
-
-    /* rectify all files ? */
-    do_all = 1;
-    G_clear_screen();
-    do_all = G_yes(_("\nRectify all files in the group? "), do_all);
-
-    /* create list of files to be rectified */
-    f1 = 0;
-    for (i = 0; i < group.group_ref.nfiles && i < NFILES; i++) {
-	int ok = 1;
-	char buf[100];
-
-	if (!do_all) {
-	    sprintf(buf, _("\nRectify image <%s>? "), group.group_ref.file[i].name);
-	    ok = G_yes(buf, ok);
-	}
-	if (ok) {
-	    sprintf(result[i], "%s%s", group.group_ref.file[i].name, extension);
-	    *r++ = f1++;
-	    *nm++ = G_store(result[i]);
-	}
-    }
-    for (i = f1; i < NFILES; i++) {
-	result[i][0] = 0;
-    }
-
-    /* check if raster exists in target location/mapset */
-    select_target_env();
-    repeat = 0;
-    G_clear_screen();
-    for (i = 0; i < NFILES; i++) {
-	if (result[i][0] && G_find_cell(result[i], G_mapset())) {
-	    if (!repeat++) {
-		repeat = 1;
-		fprintf(stderr, "\n");
-		fprintf(stderr,
-			"** The following raster maps already exist in\n");
-		fprintf(stderr, "** LOCATION %s, MAPSET %s:\n\n",
-			G_location(), G_mapset());
-	    }
-	    fprintf(stderr, "%-18s\n", result[i]);
-	}
-    }
-    select_current_env();
-    if (repeat) {
-	if (!G_yes("\n\nOk to overwrite? ", 0)) {
-	    fprintf(stderr,_("Orthorectification cancelled."));
-	    exit(0);
-	}
-    }
-
-    for (k = 0; k < group.group_ref.nfiles; k++)
-	if (ref_list[k] >= 0)
-	    return 1;
-    fprintf(stderr, "No files selected! Bye\n");
-    G_sleep(3);
-    exit(0);
-}

Deleted: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_method.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_method.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/ask_method.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,109 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "global.h"
-
-int ask_method(void)
-{
-    int f1, f2, count, max_rows, max_cols;
-    int nx, ny;
-    struct Cell_head win;
-    double max_mb_img, max_mb_elev, max_mb;
-    
-    fprintf(stderr, "\n\n");
-    while (1) {
-	char buf[100];
-
-	G_clear_screen();
-	fprintf(stderr, _("Please select one of the following interpolation methods\n"));
-	fprintf(stderr, _(" 1. nearest neighbor\n"));
-	fprintf(stderr, _(" 2. bilinear\n"));
-	fprintf(stderr, _(" 3. bicubic\n"));
-	fprintf(stderr, _(" 4. bilinear with fallback\n"));
-	fprintf(stderr, _(" 5. bicubic with fallback\n"));
-	fprintf(stderr, "> ");
-	if (!G_gets(buf))
-	    continue;
-	G_strip(buf);
-
-	if (strcmp(buf, "1") == 0) {
-	    interpolate = p_nearest;
-	    method = "nearest";
-	    break;
-	}
-	if (strcmp(buf, "2") == 0) {
-	    interpolate = p_bilinear;
-	    method = "bilinear";
-	    break;
-	}
-	if (strcmp(buf, "3") == 0) {
-	    interpolate = p_cubic;
-	    method = "bicubic";
-	    break;
-	}
-	if (strcmp(buf, "4") == 0) {
-	    interpolate = p_bilinear_f;
-	    method = "bilinear_f";
-	    break;
-	}
-	if (strcmp(buf, "5") == 0) {
-	    interpolate = p_cubic_f;
-	    method = "bicubic_f";
-	    break;
-	}
-    }
-
-    count = max_rows = max_cols = 0;
-    for (f1 = 0; f1 < group.group_ref.nfiles; f1++) {
-	if (ref_list[f1] >= 0) {
-	    f2 = ref_list[f1];
-	    G_get_cellhd(group.group_ref.file[f2].name,
-			 group.group_ref.file[f2].mapset, &win);
-	    if (max_rows < win.rows)
-		max_rows = win.rows;
-	    if (max_cols < win.cols)
-		max_cols = win.cols;
-	}
-    }
-
-    ny = (max_rows + BDIM - 1) / BDIM;
-    nx = (max_cols + BDIM - 1) / BDIM;
-
-    max_mb_img = ((double)nx * ny * sizeof(block)) / (1<<20);
-
-    ny = (target_window.rows + BDIM - 1) / BDIM;
-    nx = (target_window.cols + BDIM - 1) / BDIM;
-
-    max_mb_elev = ((double)nx * ny * sizeof(block)) / (1<<20);
-    max_mb = max_mb_img + max_mb_elev + 0.5; /* + 0.5 for rounding */
-    if (max_mb < 1)
-	max_mb = 1;
-
-    fprintf(stderr, "\n\n");
-    while (1) {
-	char buf[100];
-	int seg_mb;
-
-	fprintf(stderr, _("Amount of memory to use in MB\n"));
-	fprintf(stderr, _("RETURN   use %d MB to keep all data in RAM\n"), (int)(max_mb));
-	fprintf(stderr, "> ");
-	if (!G_gets(buf))
-	    continue;
-
-	if (*buf == 0) {		/* all in memory */
-	    seg_mb_elev = max_mb_elev;
-	    seg_mb_img = max_mb_img;
-	    break;
-	}
-
-	G_strip(buf);
-	if ((seg_mb = atoi(buf)) > 0) {
-	    seg_mb_elev = seg_mb * max_mb_elev / (max_mb_img + max_mb_elev);
-	    seg_mb_img = seg_mb * max_mb_img / (max_mb_img + max_mb_elev);
-	    break;
-	}
-    }
-
-    fprintf(stderr, "\n\n");
-
-    return 0;
-}

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -11,7 +11,6 @@
  */
 
 #include <math.h>
-#include <grass/gis.h>
 #include "global.h"
 
 void p_bilinear(struct cache *ibuffer,	  /* input buffer                */
@@ -25,7 +24,7 @@
     int row;			/* row indices for interp        */
     int col;			/* column indices for interp     */
     int i, j;
-    DCELL t, u;			/* intermediate slope            */
+    double t, u;		/* intermediate slope            */
     DCELL result;		/* result of interpolation       */
     DCELL c[2][2];
 

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -8,7 +8,6 @@
  *  it falls back to nearest neighbor.
  */
 
-#include <grass/gis.h>
 #include <math.h>
 #include "global.h"
 

Deleted: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/compress.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/compress.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/compress.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,9 +0,0 @@
-#include "global.h"
-
-int compress(char *name)
-{
-    return 0;
-    /*
-       return 1;
-     */
-}

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cp.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cp.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cp.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -5,13 +5,11 @@
 int get_conz_points(void)
 {
     char msg[200];
+    /* struct Ortho_Control_Points cpz; */
 
     if (!I_get_con_points(group.name, &group.control_points))
 	exit(0);
 
-    /* compute photo coordinates of image control points  */
-    /* I_convert_con_points (group.name, &group.control_points, &group.photo_points,  group.E12, group.N12); */
-
     sprintf(msg, _("Control Z Point file for group [%s] in [%s] \n \n"),
 	    group.name, G_mapset());
 
@@ -23,12 +21,12 @@
     case -1:
 	strcat(msg, _("Poorly placed Control Points!\n"));
 	strcat(msg, _("Can not generate the transformation equation.\n"));
-	strcat(msg, _("Run OPTION 7 again!\n"));
+	strcat(msg, _("Run OPTION 7 of i.ortho.photo again!\n"));
 	break;
     case 0:
 	strcat(msg, _("No active Control Points!\n"));
 	strcat(msg, _("Can not generate the transformation equation.\n"));
-	strcat(msg, _("Run OPTION 7 !\n"));
+	strcat(msg, _("Run OPTION 7 of i.ortho.photo!\n"));
 	break;
     default:
 	return 1;
@@ -39,9 +37,8 @@
 int get_ref_points(void)
 {
     char msg[200];
+    /* struct Ortho_Photo_Points cp; */
 
-    /* struct Ref_Points cp; */
-
     if (!I_get_ref_points(group.name, &group.photo_points))
 	exit(0);
 
@@ -53,27 +50,15 @@
     case -1:
 	strcat(msg, _("Poorly placed Reference Points!\n"));
 	strcat(msg, _("Can not generate the transformation equation.\n"));
-	strcat(msg, _("Run OPTION 5 again!\n"));
+	strcat(msg, _("Run OPTION 5 of i.ortho.photo again!\n"));
 	break;
 
     case 0:
 	strcat(msg, _("No active Reference Points!\n"));
 	strcat(msg, _("Can not generate the transformation equation.\n"));
-	strcat(msg, _("Run OPTION 5!\n"));
+	strcat(msg, _("Run OPTION 5 of i.ortho.photo!\n"));
 	break;
     default:
-	E12a = E12[0];
-	E12b = E12[1];
-	E12c = E12[2];
-	N12a = N12[0];
-	N12b = N12[1];
-	N12c = N12[2];
-	E21a = E21[0];
-	E21b = E21[1];
-	E21c = E21[2];
-	N21a = N21[0];
-	N21b = N21[1];
-	N21c = N21[2];
 	return 1;
     }
     G_fatal_error(msg);

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -12,7 +12,6 @@
  *  NULL they where filled with their neighbor
  */
 
-#include <grass/gis.h>
 #include <math.h>
 #include "global.h"
 
@@ -27,7 +26,7 @@
     int row;			/* row indices for interp        */
     int col;			/* column indices for interp     */
     int i, j;
-    DCELL t, u;			/* intermediate slope            */
+    double t, u;		/* intermediate slope            */
     DCELL result;		/* result of interpolation       */
     DCELL val[4];		/* buffer for temporary values   */
     DCELL cell[4][4];

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -9,7 +9,6 @@
  *  it falls back to nearest neighbor.
  */
 
-#include <grass/gis.h>
 #include <math.h>
 #include "global.h"
 

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/defs.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/defs.h	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/defs.h	2010-12-22 10:10:33 UTC (rev 44655)
@@ -26,3 +26,10 @@
 #define BLOCK(c,y,x) (BKPTR((c),(y),(x)) ? BKPTR((c),(y),(x)) : get_block((c),BKIDX((c),(y),(x))))
 #define CPTR(c,y,x) (&(*BLOCK((c),HI((y)),HI((x))))[LO((y))][LO((x))])
 
+struct menu
+{
+    func method;		/* routine to interpolate new value      */
+    char *name;			/* method name                           */
+    char *text;			/* menu display - full description       */
+};
+

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/description.html
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/description.html	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/description.html	2010-12-22 10:10:33 UTC (rev 44655)
@@ -13,24 +13,38 @@
 compensated for relief distortions and photographic tilt. Upon completion of
 the program the rectified image is deposited in a previously targeted GRASS
 LOCATION.
-<P> You are asked to select the file(s) within the imagery group
-to be rectified:
-<P> Please select the file(s) to rectify by naming an
-output file <P> <PRE>
+<P>
+Images can be resampled with various different interpolation methods: 
+nearest neighbor assignment, bilinear and bicubic interpolation. The 
+bilinear and bicubic interpolation methods are also available with a
+fallback option. These methods "fall back" to simpler interpolation 
+methods along NULL borders. That is, from bicubic to bilinear to nearest.
+<P>
+The process may take an hour or more depending on the size of the image,
+the speed of the computer, the number files, and the size and resolution
+of the selected window.
+<P>
+The rectified image will be located in the target LOCATION when the program
+is completed. The original unrectified files are not modified or removed.
+<P>
+<EM>i.photo.rectify</EM> can be run directly, specifying options in the 
+command line or the GUI, or it can be invoked as OPTION 8 through 
+<A HREF="i.ortho.photo.html">i.ortho.photo</A>. If invoked though 
+<A HREF="i.ortho.photo.html">i.ortho.photo</A>, an interactive terminal 
+is used to determine the options.
 
-                    gs13.1 in PERMANENT   gs13.orect...
-                    gs14.1 in PERMANENT   .............
-
-     (enter list by any name to get a list of existing raster maps)
-
-	    AFTER COMPLETING ALL ANSWERS, HIT &lt;ESC&gt; TO CONTINUE
-	               (OR &lt;Ctrl-C&gt; TO CANCEL)
-</PRE>
+<H4>Interactive mode</H4>
+<P> You are first asked if all images within the imagery group should 
+be rectified. If this option is not chosen, you are asked to specify for 
+each image within the imagery group whether it should be rectified or not.
 <P>
-<P>
 More than one file may be rectified at a time.  Each file
-should have a unique output file name.
+should have a unique output file name. The next prompt asks you for an 
+extension to be appended to the rectified images.
 <P>
+After that you are asked if overwriting existing maps in the target 
+location and mapset should be allowed.
+<P>
 The next prompt asks you to select one of two windows:
 <P>
 <PRE>
@@ -40,17 +54,26 @@
       &gt;
 </PRE>
 <P>
+If you choose option 2, you can also specify a desired target resolution.
+<P>
 <EM>i.photo.rectify</EM> will only rectify that portion of the
 image that occurs within the chosen window.  Only that portion will be
 relocated in the target database. It is therefore important to check the
 current window in the target LOCATION if choice number one is selected.
 <P>
-The process may take an hour or more depending on the size of the image,
-the speed of the computer, the number files, and the size and resolution
-of the selected window.
+Next you are asked to select an interpolation method.
+<PRE>
+      Please select one of the following interpolation methods
+      1. nearest neighbor
+      2. bilinear
+      3. bicubic
+      4. bilinear with fallback
+      5. bicubic with fallback
+      &gt;
+</PRE>
 <P>
-The rectified image will be located in the target LOCATION when the program
-is completed. The original unrectified files are not modified or removed.
+The last prompt will ask you about the amount of memory to be used by
+<EM>i.photo.rectify</EM>.
 
 <H2>SEE ALSO</H2>
 
@@ -59,14 +82,15 @@
 <A HREF="i.photo.camera.html">i.photo.camera</A><br>
 <A HREF="i.photo.2image.html">i.photo.2image</A><br>
 <A HREF="i.photo.2target.html">i.photo.2target</A><br>
-<A HREF="i.photo.init.html">i.photo.init</A>
+<A HREF="i.photo.init.html">i.photo.init</A><br>
+<A HREF="i.rectify.html">i.rectify</A><br>
 </EM>
 
 
-
 <H2>AUTHOR</H2>
 Mike Baba,  DBA Systems, Inc.<br>
-Updated rectification and elevation map to FP 1/2002 Markus Neteler
+Updated rectification and elevation map to FP 1/2002 Markus Neteler<br>
+Bugfixes and enhancements 12/2010 Markus Metz
 
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/env.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/env.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/env.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,5 +1,6 @@
 #include <unistd.h>
 #include "global.h"
+
 static int which_env = -1;	/* 0 = cur, 1 = target */
 
 int select_current_env(void)

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/equ.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/equ.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/equ.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,11 +1,13 @@
 #include "global.h"
 
+/* compute target to photo equation */
 int Compute_ortho_equation(void)
 {
 
     /* struct Ortho_Control_Points  temp_points; */
     double e0, e1, e2, n0, n1, n2, z1, z2;
     int status, i;
+    struct Ortho_Control_Points temp_points;
 
     /* alloc and fill temp control points */
     temp_points.count = 0;
@@ -27,6 +29,7 @@
 	n2 = group.control_points.n2[i];
 	z2 = group.control_points.z2[i];
 
+	/* image to photo transformation */
 	I_georef(e1, n1, &e0, &n0, group.E12, group.N12);
 	I_new_con_point(&temp_points, e0, n0, z1, e2, n2, z2, status);
     }
@@ -46,6 +49,7 @@
     return 0;
 }
 
+/* compute photo to image equation */
 int Compute_ref_equation(void)
 {
     group.ref_equation_stat = I_compute_ref_equations(&group.photo_points,

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/exec.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/exec.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/exec.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -5,6 +5,7 @@
    Handles things like support files.
  */
 
+#include <string.h>
 #include <unistd.h>
 #include <time.h>
 #include <sys/types.h>
@@ -12,17 +13,18 @@
 #include <fcntl.h>
 #include "global.h"
 
-int exec_rectify(void)
+int exec_rectify(char *extension, char *interp_method)
 {
     char *name;
     char *mapset;
     char *result;
-    int i, n;
+    char *type;
+    int n;
     struct Colors colr;
     struct Categories cats;
     struct History hist;
     int colr_ok, hist_ok, cats_ok;
-    long start_time, rectify_time, compress_time;
+    long start_time, rectify_time;
     double aver_z;
     int elevfd;
     struct cache *ebuffer;
@@ -36,14 +38,13 @@
 	    target_window.rows, target_window.cols, target_window.north,
 	    target_window.south, target_window.west, target_window.east);
 
-    elevfd = G_open_cell_old(elev_layer, mapset_elev);
+    elevfd = G_open_cell_old(elev_name, elev_mapset);
     if (elevfd < 0) {
 	G_fatal_error(_("Could not open elevation raster"));
 	return 1;
     }
-    G_debug(1, "elev layer = %s  mapset elev = %s elevfd = %d",
-	    elev_layer, mapset_elev, elevfd);
     ebuffer = readcell(elevfd, seg_mb_elev, 1);
+    select_target_env();
     G_close_cell(elevfd);
 
     /* get an average elevation of the control points */
@@ -52,20 +53,25 @@
 
     /* rectify each file */
     for (n = 0; n < group.group_ref.nfiles; n++) {
-	G_debug(2, "I look for files to ortho rectify");
-
-	if ((i = ref_list[n]) < 0)
+	if (!ref_list[n])
 	    continue;
-	name = group.group_ref.file[i].name;
-	mapset = group.group_ref.file[i].mapset;
-	result = new_name[n];
 
+	name = group.group_ref.file[n].name;
+	mapset = group.group_ref.file[n].mapset;
+	result =
+	    G_malloc(strlen(group.group_ref.file[n].name) + strlen(extension) + 1);
+	strcpy(result, group.group_ref.file[n].name);
+	strcat(result, extension);
+
 	G_debug(2, "ORTHO RECTIFYING:");
 	G_debug(2, "NAME %s", name);
 	G_debug(2, "MAPSET %s", mapset);
 	G_debug(2, "RESULT %s", result);
 	G_debug(2, "select_current_env...");
 
+	G_message(_("Rectified input raster map <%s> will be saved as <%s>"),
+		  name, result);
+
 	select_current_env();
 
 	cats_ok = G_read_cats(name, mapset, &cats) >= 0;
@@ -77,7 +83,7 @@
 
 	G_debug(2, "Starting the rectification...");
 
-	if (rectify(name, mapset, ebuffer, aver_z, result)) {
+	if (rectify(name, mapset, ebuffer, aver_z, result, interp_method)) {
 	    G_debug(2, "Done. Writing results...");
 	    select_target_env();
 	    if (cats_ok) {
@@ -90,20 +96,25 @@
 	    }
 	    if (hist_ok)
 		G_write_history(result, &hist);
+
+	    /* Initialze History */
+	    type = "raster";
+	    G_short_history(name, type, &hist);
+	    G_write_history(result, &hist);
+
 	    select_current_env();
 	    time(&rectify_time);
-	    compress_time = rectify_time;
-	    report(name, mapset, result, rectify_time - start_time,
-		   compress_time - rectify_time, 1);
+	    report(rectify_time - start_time, 1);
 	}
-	else {
-	    G_debug(2, "Could not rectify. Mhhh.");
-	    report(name, mapset, result, (long)0, (long)0, 0);
-	}
+	else
+	    report((long)0, 0);
+
+	G_free(result);
     }
     close(ebuffer->fd);
-    G_free(ebuffer);
+    release_cache(ebuffer);
 
     G_done_msg(" ");
+
     return 0;
 }

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/get_wind.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/get_wind.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/get_wind.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -5,39 +5,38 @@
 
 int get_ref_window(struct Cell_head *cellhd)
 {
-    int k, f1, f2;
+    int i;
     int count;
     struct Cell_head win;
 
     /* from all the files in the group, get max extends and min resolutions */
     count = 0;
-    for (f1 = 0; f1 < group.group_ref.nfiles; f1++) {
-	if (ref_list[f1] >= 0) {
-	    if (count++ == 0) {
-		f2 = ref_list[f1];
-		G_get_cellhd(group.group_ref.file[f2].name,
-			     group.group_ref.file[f2].mapset, cellhd);
-	    }
-	    else {
-		k = ref_list[f1];
-		G_get_cellhd(group.group_ref.file[k].name,
-			     group.group_ref.file[k].mapset, &win);
-		/* extends */
-		if (cellhd->north < win.north)
-		    cellhd->north = win.north;
-		if (cellhd->south > win.south)
-		    cellhd->south = win.south;
-		if (cellhd->west > win.west)
-		    cellhd->west = win.west;
-		if (cellhd->east < win.east)
-		    cellhd->east = win.east;
-		/* resolution */
-		if (cellhd->ns_res > win.ns_res)
-		    cellhd->ns_res = win.ns_res;
-		if (cellhd->ew_res > win.ew_res)
-		    cellhd->ew_res = win.ew_res;
-	    }
+    for (i = 0; i < group.group_ref.nfiles; i++) {
+	if (!ref_list[i])
+	    continue;
+
+	if (count++ == 0) {
+	    G_get_cellhd(group.group_ref.file[i].name,
+			 group.group_ref.file[i].mapset, cellhd);
 	}
+	else {
+	    G_get_cellhd(group.group_ref.file[i].name,
+			 group.group_ref.file[i].mapset, &win);
+	    /* max extends */
+	    if (cellhd->north < win.north)
+		cellhd->north = win.north;
+	    if (cellhd->south > win.south)
+		cellhd->south = win.south;
+	    if (cellhd->west > win.west)
+		cellhd->west = win.west;
+	    if (cellhd->east < win.east)
+		cellhd->east = win.east;
+	    /* min resolution */
+	    if (cellhd->ns_res > win.ns_res)
+		cellhd->ns_res = win.ns_res;
+	    if (cellhd->ew_res > win.ew_res)
+		cellhd->ew_res = win.ew_res;
+	}
     }
 
     /* if the north-south is not multiple of the resolution,
@@ -53,75 +52,6 @@
     return 1;
 }
 
-int get_target_window(void)
-{
-    struct Cell_head cellhd;
-    double res;
-
-    fprintf(stderr, "\n\n");
-    while (1) {
-	char buf[100];
-
-	fprintf(stderr, "Please select one of the following options\n");
-	fprintf(stderr,
-		" 1. Use the current window in the target location\n");
-	fprintf(stderr,
-		" 2. Determine the smallest window which covers the image\n");
-	fprintf(stderr, "> ");
-	if (!G_gets(buf))
-	    continue;
-	G_strip(buf);
-
-	if (strcmp(buf, "1") == 0) {
-	    return 1;
-	}
-	if (strcmp(buf, "2") == 0)
-	    break;
-    }
-    
-    /* ask for target resolution */
-    while (1) {
-	char buf[100];
-
-	fprintf(stderr, "Desired target resolution\n");
-	fprintf(stderr,
-		" RETURN   determine automatically\n");
-	fprintf(stderr, "> ");
-	if (!G_gets(buf))
-	    continue;
-
-	if (*buf == 0) {  /* determine automatically */
-	    res = -1;
-	    break;
-	}
-
-	G_strip(buf);
-
-	if ((res = atof(buf)) <= 0) {
-	    fprintf(stderr, "Resolution must be larger than zero!");
-	    G_clear_screen();
-	}
-	else
-	    break;
-    }
-
-    /* get reference window: max extend, min resolution */
-    get_ref_window(&cellhd);
-
-    G_debug(1, "current window: n s = %f %f,", cellhd.north,
-	    cellhd.south);
-    G_debug(1, "current window: w e = %f %f,", cellhd.west,
-	    cellhd.east);
-
-    georef_window(&cellhd, &target_window, res);
-    
-    select_target_env();
-    if (G_put_window(&target_window) >= 0)
-	fprintf(stderr, "Window Saved!\n");
-    select_current_env();
-    return 0;
-}
-
 int georef_window(struct Cell_head *w1, struct Cell_head *w2, double res)
 {
     double n, e, z1, ad;
@@ -196,7 +126,7 @@
     if (e < w2->west)
 	w2->west = e;
 
-    I_georef(w1->east, w1->south, &e0, &n0, group.E12, N12);
+    I_georef(w1->east, w1->south, &e0, &n0, group.E12, group.N12);
     I_inverse_ortho_ref(e0, n0, aver_z, &e, &n, &z1, &group.camera_ref,
 			group.XC, group.YC, group.ZC, group.MI);
 

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/global.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/global.h	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/global.h	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,3 +1,4 @@
+#include <grass/gis.h>
 #include <grass/imagery.h>
 #include <grass/ortholib.h>
 #include <grass/glocale.h>
@@ -4,47 +5,14 @@
 #include "orthophoto.h"
 #include "defs.h"
 
-#ifndef GLOBAL
-#define GLOBAL extern
-#endif
+extern func interpolate;	/* interpolation routine */
 
-/* activate debug in Gmakefile */
-#ifdef  DEBUG3
-GLOBAL FILE *Bugsr;
-#endif
+extern int seg_mb_img, seg_mb_elev;
+extern char *extension;
+extern int *ref_list;
+extern struct Ortho_Image_Group group;
+extern char *elev_name;
+extern char *elev_mapset;
+extern struct Cell_head target_window;
 
-GLOBAL func interpolate;	/* interpolation routine */
-
-GLOBAL int seg_mb_img, seg_mb_elev;
-GLOBAL char *method;
-GLOBAL int temp_fd;
-GLOBAL CELL **cell_buf;
-GLOBAL char *temp_name;
-
-GLOBAL char *extension;
-GLOBAL double target_res;
-
-GLOBAL int *ref_list;
-GLOBAL char **new_name;
-
-
-GLOBAL struct Ortho_Image_Group group;
-GLOBAL struct Ortho_Photo_Points cp;
-GLOBAL struct Ortho_Control_Points cpz;
-GLOBAL struct Ortho_Control_Points temp_points;
-GLOBAL struct Ortho_Camera_File_Ref cam_info;
-
-GLOBAL struct Cell_head elevhd;
-GLOBAL char *elev_layer;
-GLOBAL char *mapset_elev;
-
-
-/* georef coefficients */
-GLOBAL double E12[3], N12[3], Z12[3];
-GLOBAL double E21[3], N21[3], Z21[3];
-GLOBAL double E12a, E12b, E12c, N12a, N12b, N12c;
-GLOBAL double E21a, E21b, E21c, N21a, N21b, N21c;
-
-GLOBAL struct Cell_head target_window;
-
 #include "local_proto.h"

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/local_proto.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/local_proto.h	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/local_proto.h	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,9 +1,3 @@
-/* ask_files.c */
-int ask_files(char *);
-
-/* ask_method.c */
-int ask_method(void);
-
 /* aver_z.c */
 int get_aver_elev(struct Ortho_Control_Points *, double *);
 
@@ -24,21 +18,22 @@
 int Compute_ref_equation(void);
 
 /* exec.c */
-int exec_rectify(void);
+int exec_rectify(char *, char *);
 
 /* get_wind.c */
-int get_target_window(void);
+int get_ref_window(struct Cell_head *);
 int georef_window(struct Cell_head *, struct Cell_head *, double);
 
 /* rectify.c */
-int rectify(char *, char *, struct cache *, double, char *);
+int rectify(char *, char *, struct cache *, double, char *, char *);
 
 /* readcell.c */
 struct cache *readcell(int, int, int);
 block *get_block(struct cache *, int);
+void release_cache(struct cache *);
 
 /* report.c */
-int report(char *, char *, char *, long, long, int);
+int report(long, int);
 
 /* target.c */
 int get_target(char *);

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/main.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/main.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/main.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -10,7 +10,7 @@
  *               Markus Metz
  *
  * PURPOSE:      Rectifies an image by using the image to photo coordinate 
- *                 transformation matrix
+ *               and photo to target transformation matrices
  * COPYRIGHT:    (C) 1999-2010 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
@@ -18,18 +18,47 @@
  *               for details.
  *
  *****************************************************************************/
-#define GLOBAL
+
 #include <stdlib.h>
 #include <string.h>
-#include <grass/gis.h>
-#include <grass/imagery.h>
-#include <grass/glocale.h>
 #include "global.h"
 
+int seg_mb_img, seg_mb_elev;
+
+int *ref_list;
+struct Ortho_Image_Group group;
+
+char *elev_name;
+char *elev_mapset;
+
+func interpolate;
+
+struct Cell_head target_window;
+
+void err_exit(char *, char *);
+
+/* modify this table to add new methods */
+struct menu menu[] = {
+    {p_nearest, "nearest", "nearest neighbor"},
+    {p_bilinear, "bilinear", "bilinear"},
+    {p_cubic, "cubic", "cubic convolution"},
+    {p_bilinear_f, "bilinear_f", "bilinear with fallback"},
+    {p_cubic_f, "cubic_f", "cubic convolution with fallback"},
+    {NULL, NULL, NULL}
+};
+
+static char *make_ipol_list(void);
+
 int main(int argc, char *argv[])
 {
+    char extension[INAME_LEN];
+    char *ipolname;		/* name of interpolation method */
+    int method;
+    char *seg_mb;
+    int i, m, k = 0;
+    int got_file = 0, target_overwrite = 0;
+    char *overstr;
 
-    char name[GNAME_MAX];
     char *camera;
     int n, nfiles;
     char tl[100];
@@ -37,73 +66,152 @@
     char units[100];
     char nd[100];
 
+    struct Cell_head cellhd, elevhd;
+
+    struct Option *grp,         /* imagery group */
+     *ifile,			/* input files */
+     *ext,			/* extension */
+     *tres,			/* target resolution */
+     *mem,			/* amount of memory for cache */
+     *interpol;			/* interpolation method:
+				   nearest neighbor, bilinear, cubic */
+    struct Flag *c, *a;
     struct GModule *module;
-    struct Option *group_opt;
 
-    /* must run in a term window */
-    G_putenv("GRASS_UI_TERM", "1");
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
     module->keywords = _("imagery, orthorectify");
     module->description =
-	_("Interactively select or modify the imagery group target.");
+	_("Orthorectifies an image by using the image to photo coordinate transformation matrix.");
 
-    group_opt = G_define_standard_option(G_OPT_I_GROUP);
-    group_opt->description =
-	_("Name of imagery group for ortho-rectification");
+    grp = G_define_standard_option(G_OPT_I_GROUP);
 
+    ifile = G_define_standard_option(G_OPT_R_INPUTS);
+    ifile->required = NO;
+
+    ext = G_define_option();
+    ext->key = "extension";
+    ext->type = TYPE_STRING;
+    ext->required = YES;
+    ext->multiple = NO;
+    ext->description = _("Output raster map(s) suffix");
+
+    tres = G_define_option();
+    tres->key = "res";
+    tres->type = TYPE_DOUBLE;
+    tres->required = NO;
+    tres->description = _("Target resolution (ignored if -c flag used)");
+
+    mem = G_define_option();
+    mem->key = "memory";
+    mem->type = TYPE_DOUBLE;
+    mem->key_desc = "memory in MB";
+    mem->required = NO;
+    mem->answer = "100";
+    mem->description = _("Amount of memory to use in MB");
+
+    ipolname = make_ipol_list();
+
+    interpol = G_define_option();
+    interpol->key = "method";
+    interpol->type = TYPE_STRING;
+    interpol->required = NO;
+    interpol->answer = "nearest";
+    interpol->options = ipolname;
+    interpol->description = _("Interpolation method to use");
+
+    c = G_define_flag();
+    c->key = 'c';
+    c->description =
+	_("Use current region settings in target location (def.=calculate smallest area)");
+
+    a = G_define_flag();
+    a->key = 'a';
+    a->description = _("Rectify all raster maps in group");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    /* get the method */
+    for (method = 0; (ipolname = menu[method].name); method++)
+	if (strcmp(ipolname, interpol->answer) == 0)
+	    break;
 
-    G_suppress_masking();	/* need to do this for target location */
+    if (!ipolname)
+	G_fatal_error(_("<%s=%s> unknown %s"),
+		      interpol->key, interpol->answer, interpol->key);
+    interpolate = menu[method].method;
 
-    strcpy(name, group_opt->answer);
+    G_strip(grp->answer);
+    strcpy(group.name, grp->answer);
+    strcpy(extension, ext->answer);
 
+    seg_mb = NULL;
+    if (mem->answer) {
+	if (atoi(mem->answer) > 0)
+	    seg_mb = mem->answer;
+    }
+
+    if (!ifile->answers)
+	a->answer = 1;		/* force all */
+
+    /* Find out how many files on command line */
+    if (!a->answer) {
+	for (k = 0; ifile->answers[k]; k++);
+    }
+
     camera = (char *)G_malloc(GNAME_MAX * sizeof(char));
-    elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char));
-    mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
+    elev_name = (char *)G_malloc(GNAME_MAX * sizeof(char));
+    elev_mapset = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
 
     /* find group */
-    strcpy(group.name, name);
     if (!I_find_group(group.name))
-	G_fatal_error(_("Group [%s] not found"), group.name);
+	G_fatal_error(_("Group <%s> not found"), group.name);
 
     /* get the group ref */
     if (!I_get_group_ref(group.name, (struct Ref *)&group.group_ref))
-	G_fatal_error(_("Could not read REF file for group [%s]"), group.name);
+	G_fatal_error(_("Could not read REF file for group <%s>"), group.name);
     nfiles = group.group_ref.nfiles;
-    if (nfiles <= 0)
-	G_fatal_error(_("No files in this group!"));
+    if (nfiles <= 0) {
+	G_important_message(_("Group <%s> contains no raster maps; run i.group"),
+			    grp->answer);
+	exit(EXIT_SUCCESS);
+    }
 
     ref_list = (int *)G_malloc(nfiles * sizeof(int));
-    new_name = (char **)G_malloc(nfiles * sizeof(char *));
-    for (n = 0; n < nfiles; n++)
-	ref_list[n] = -1;
 
-    /* get the target */
-    get_target(group.name);
+    if (a->answer) {
+	for (n = 0; n < group.group_ref.nfiles; n++) {
+	    ref_list[n] = 1;
+	}
+    }
+    else {
+	char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *name;
 
-    /* ask for files to be rectified */
-    ask_files(group.name);
+	for (n = 0; n < group.group_ref.nfiles; n++)
+		ref_list[n] = 0;
 
-    G_debug(1, "Looking for elevation file in group: <%s>", group.name);
+	for (m = 0; m < k; m++) {
+	    got_file = 0;
+	    if (G__name_is_fully_qualified(ifile->answers[m], xname, xmapset))
+		name = xname;
+	    else
+		name = ifile->answers[m];
 
-    /* get the block elevation layer raster map in target location */
-    if (!I_get_group_elev(group.name, elev_layer, mapset_elev, tl,
-			 math_exp, units, nd))
-	G_fatal_error(_("No target elevation model selected for group <%s>"),
-		      group.name);
+	    got_file = 0;
+	    for (n = 0; n < group.group_ref.nfiles; n++) {
+		if (strcmp(name, group.group_ref.file[n].name) == 0) {
+		    got_file = 1;
+		    ref_list[n] = 1;
+		    break;
+		}
+	    }
+	    if (got_file == 0)
+		err_exit(ifile->answers[m], group.name);
+	}
+    }
 
-    G_debug(1, "Block elevation: <%s> in <%s>", elev_layer, mapset_elev);
-
-    /* get the elevation layer header in target location */
-    select_target_env();
-    G_get_cellhd(elev_layer, mapset_elev, &elevhd);
-    select_current_env();
-
     /** look for camera info for this block **/
     if (!I_get_group_camera(group.name, camera))
 	G_fatal_error(_("No camera reference file selected for group <%s>"),
@@ -126,15 +234,146 @@
     /* read the control points for the group, convert to photo coords. */
     get_conz_points();
 
-    /* ask for window to be used in target location */
+    /* get the target */
+    get_target(group.name);
+    
+    /* Check the GRASS_OVERWRITE environment variable */
+    if ((overstr = getenv("GRASS_OVERWRITE")))  /* OK ? */
+	target_overwrite = atoi(overstr);
+
+    if (!target_overwrite) {
+	/* check if output exists in target location/mapset */
+	char result[GNAME_MAX];
+	
+	select_target_env();
+	for (i = 0; i < group.group_ref.nfiles; i++) {
+	    if (!ref_list[i])
+		continue;
+
+	    strcpy(result, group.group_ref.file[i].name);
+	    strcat(result, extension);
+	    
+	    if (G_legal_filename(result) < 0)
+		G_fatal_error(_("Extension <%s> is illegal"), extension);
+		
+	    if (G_find_cell(result, G_mapset())) {
+		G_warning(_("The following raster map already exists in"));
+		G_warning(_("target LOCATION %s, MAPSET %s:"),
+			  G_location(), G_mapset());
+		G_warning("<%s>", result);
+		G_fatal_error(_("Orthorectification cancelled."));
+	    }
+	}
+	select_current_env();
+    }
+    else
+	G_debug(1, "Overwriting OK");
+
+    /* do not use current region in target location */
+    if (!c->answer) {
+	double res = -1;
+	
+	if (tres->answer) {
+	    if (!((res = atof(tres->answer)) > 0))
+		G_warning(_("Target resolution must be > 0, ignored"));
+	}
+	/* get reference window from imagery group */
+	get_ref_window(&cellhd);
+	georef_window(&cellhd, &target_window, res);
+    }
+
+    G_verbose_message(_("Using region: N=%f S=%f, E=%f W=%f"), target_window.north,
+	      target_window.south, target_window.east, target_window.west);
+
+    G_debug(1, "Looking for elevation file in group: <%s>", group.name);
+
+    /* get the block elevation layer raster map in target location */
+    if (!I_get_group_elev(group.name, elev_name, elev_mapset, tl,
+			 math_exp, units, nd))
+	G_fatal_error(_("No target elevation model selected for group <%s>"),
+		      group.name);
+
+    G_debug(1, "Block elevation: <%s> in <%s>", elev_name, elev_mapset);
+
+    /* get the elevation layer header in target location */
+    select_target_env();
+    G_get_cellhd(elev_name, elev_mapset, &elevhd);
     select_current_env();
-    get_target_window();
+    
+    /* determine memory for elevation and imagery */
+    seg_mb_img = seg_mb_elev = -1;
+    if (seg_mb) {
+	int max_rows, max_cols;
+	int nx, ny;
+	double max_mb_img, max_mb_elev;
+	int seg_mb_total;
 
-    /* ask for interpolation method and amount of memory to be used */
-    ask_method();
+	max_rows = max_cols = 0;
+	for (i = 0; i < group.group_ref.nfiles; i++) {
+	    if (ref_list[i]) {
+		G_get_cellhd(group.group_ref.file[i].name,
+			     group.group_ref.file[i].mapset, &cellhd);
+		if (max_rows < cellhd.rows)
+		    max_rows = cellhd.rows;
+		if (max_cols < cellhd.cols)
+		    max_cols = cellhd.cols;
+	    }
+	}
 
+	ny = (max_rows + BDIM - 1) / BDIM;
+	nx = (max_cols + BDIM - 1) / BDIM;
+
+	max_mb_img = ((double)nx * ny * sizeof(block)) / (1<<20);
+
+	ny = (target_window.rows + BDIM - 1) / BDIM;
+	nx = (target_window.cols + BDIM - 1) / BDIM;
+
+	max_mb_elev = ((double)nx * ny * sizeof(block)) / (1<<20);
+
+	if ((seg_mb_total = atoi(seg_mb)) > 0) {
+	    seg_mb_elev = max_mb_elev * (seg_mb_total / (max_mb_img + max_mb_elev)) + 0.5;
+	    seg_mb_img = max_mb_img * (seg_mb_total / (max_mb_img + max_mb_elev)) + 0.5;
+	}
+    }
+
     /* go do it */
-    exec_rectify();
+    exec_rectify(extension, interpol->answer);
 
     exit(EXIT_SUCCESS);
 }
+
+
+void err_exit(char *file, char *grp)
+{
+    int n;
+
+    G_warning(_("Input raster map <%s> does not exist in group <%s>."),
+	    file, grp);
+    G_message(_("Try:"));
+
+    for (n = 0; n < group.group_ref.nfiles; n++)
+	G_message("%s@%s", group.group_ref.file[n].name, group.group_ref.file[n].mapset);
+
+    G_fatal_error(_("Exit!"));
+}
+
+static char *make_ipol_list(void)
+{
+    int size = 0;
+    int i;
+    char *buf;
+
+    for (i = 0; menu[i].name; i++)
+	size += strlen(menu[i].name) + 1;
+
+    buf = G_malloc(size);
+    *buf = '\0';
+
+    for (i = 0; menu[i].name; i++) {
+	if (i)
+	    strcat(buf, ",");
+	strcat(buf, menu[i].name);
+    }
+
+    return buf;
+}

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/nearest.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/nearest.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/nearest.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -4,7 +4,6 @@
  */
 
 #include <math.h>
-#include <grass/gis.h>
 #include "global.h"
 
 void p_nearest(struct cache *ibuffer,	 /* input buffer                  */

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/readcell.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/readcell.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/readcell.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -10,8 +10,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
 #include "global.h"
 
 struct cache *readcell(int fdi, int size, int target_env)
@@ -26,9 +24,19 @@
     int nblocks;
     int i;
 
+    if (target_env)
+	select_target_env();
+    else
+	select_current_env();
+
     nrows = G_window_rows();
     ncols = G_window_cols();
 
+    /* Temporary file must be created in the same location/mapset 
+     * where the module was called */
+    if (target_env)
+	select_current_env();
+
     ny = (nrows + BDIM - 1) / BDIM;
     nx = (ncols + BDIM - 1) / BDIM;
 
@@ -48,11 +56,7 @@
     c->refs = (int *)G_malloc(nblocks * sizeof(int));
 
     if (nblocks < nx * ny) {
-	/* Temporary file must be created in output location */
-	select_target_env();
 	filename = G_tempfile();
-	if (!target_env)
-	    select_current_env();
 	c->fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
 	if (c->fd < 0)
 	    G_fatal_error(_("Unable to open temporary file"));
@@ -60,6 +64,8 @@
     }
     else
 	c->fd = -1;
+	
+    G_debug(1, "%d of %d blocks in memory", nblocks, nx * ny);
 
     G_important_message(_("Allocating memory and reading input map..."));
     G_percent(0, nrows, 5);
@@ -69,6 +75,8 @@
 
     tmpbuf = (DCELL *) G_malloc(nx * sizeof(block));
 
+    if (target_env)
+	select_target_env();
     for (row = 0; row < nrows; row += BDIM) {
 	int x, y;
 
@@ -103,6 +111,9 @@
 	    c->refs[i] = i;
 	}
 
+    if (target_env)
+	select_current_env();
+
     return c;
 }
 
@@ -126,7 +137,17 @@
 	G_fatal_error(_("Error seeking on segment file"));
 
     if (read(c->fd, p, sizeof(block)) < 0)
-	G_fatal_error(_("Error writing segment file"));
+	G_fatal_error(_("Error reading segment file"));
 
     return p;
 }
+
+void release_cache(struct cache *c)
+{
+    G_free(c->refs);
+    G_free(c->blocks);
+    G_free(c->grid);
+    
+    G_free(c);
+    c = NULL;
+}

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/rectify.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/rectify.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/rectify.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -7,23 +7,21 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <grass/glocale.h>
 #include "global.h"
-#include "local_proto.h"
 
 int rectify(char *name, char *mapset, struct cache *ebuffer,
-            double aver_z, char *result)
+            double aver_z, char *result, char *interp_method)
 {
     struct Cell_head cellhd;
     int ncols, nrows;
     int row, col;
+    double row_idx, col_idx;
     int infd, outfd;
     RASTER_MAP_TYPE map_type;
     int cell_size;
     void *trast, *tptr;
     double n1, e1, z1;
     double nx, ex, nx1, ex1, zx1;
-    double row_idx, col_idx;
     struct cache *ibuffer;
 
     select_current_env();
@@ -34,20 +32,12 @@
      * set window to cellhd first to be able to read file exactly
      */
     G_set_window(&cellhd);
-    G_debug(2, "cellhd: rs=%d cs=%d n=%f s=%f w=%f e=%f\n",
-	    cellhd.rows, cellhd.cols, cellhd.north,
-	    cellhd.south, cellhd.west, cellhd.east);
-
     infd = G_open_cell_old(name, mapset);
     if (infd < 0) {
 	return 0;
     }
     map_type = G_get_raster_map_type(infd);
     cell_size = G_raster_size(map_type);
-    if (strcmp(method, "nearest") != 0) {
-	map_type = DCELL_TYPE;
-	cell_size = G_raster_size(map_type);
-    }
 
     ibuffer = readcell(infd, seg_mb_img, 0);
 
@@ -56,13 +46,24 @@
     G_message(_("Rectify <%s@%s> (location <%s>)"),
 	      name, mapset, G_location());
     select_target_env();
+    G_set_window(&target_window);
     G_message(_("into  <%s@%s> (location <%s>) ..."),
 	      result, G_mapset(), G_location());
 
-    G_set_window(&target_window);
     nrows = target_window.rows;
     ncols = target_window.cols;
 
+    if (strcmp(interp_method, "nearest") != 0) {
+	map_type = DCELL_TYPE;
+	cell_size = G_raster_size(map_type);
+    }
+
+    /* open the result file into target window
+     * this open must be first since we change the window later
+     * raster maps open for writing are not affected by window changes
+     * but those open for reading are
+     */
+
     outfd = G_open_raster_new(result, map_type);
     trast = G_allocate_raster_buf(map_type);
 
@@ -111,11 +112,11 @@
     }
     G_percent(1, 1, 1);
 
+    G_close_cell(outfd);
     G_free(trast);
 
-    G_close_cell(outfd);
     close(ibuffer->fd);
-    G_free(ibuffer);
+    release_cache(ibuffer);
 
     if (G_get_cellhd(result, G_mapset(), &cellhd) < 0)
 	return 0;
@@ -127,14 +128,14 @@
 
     if (target_window.proj != cellhd.proj) {
 	cellhd.proj = target_window.proj;
-	G_warning(_("%s@%s: projection doesn't match current settings"),
-		name, mapset);
+	G_warning(_("Raster map <%s@%s>: projection don't match current settings"),
+		  name, mapset);
     }
 
     if (target_window.zone != cellhd.zone) {
 	cellhd.zone = target_window.zone;
-	 G_warning(_("%s@%s: zone doesn't match current settings"),
-		name, mapset);
+	G_warning(_("Raster map <%s@%s>: zone don't match current settings"),
+		  name, mapset);
     }
 
     select_current_env();

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/report.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/report.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/report.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,22 +1,14 @@
 #include "global.h"
+
 int
-report(char *name, char *mapset, char *result, long rectify, long compress,
-       int ok)
+report(long rectify, int ok)
 {
     int minutes, hours;
     long seconds;
     long ncells;
 
-    select_current_env();
-    fprintf(stderr, "***********************************************\n");
-    fprintf(stderr, "Rectify [%s in %s] (LOCATION %s)\n",
-	    name, mapset, G_location());
-    fprintf(stderr, " into  [%s in ", result);
-    select_target_env();
-    fprintf(stderr, "%s] (LOCATION %s)\n", G_mapset(), G_location());
-    fprintf(stderr, "%s\n", ok ? "complete" : "failed");
+    fprintf(stderr, "%s\n", ok ? _("complete") : _("failed"));
     fprintf(stderr, "-----------------------------------------------\n");
-    select_current_env();
 
     if (!ok)
 	return 1;
@@ -26,31 +18,17 @@
     hours = minutes / 60;
     minutes -= hours * 60;
     ncells = target_window.rows * target_window.cols;
-    fprintf(stderr, " %d rows, %d cols (%ld cells) completed in ",
+    fprintf(stderr, _(" %d rows, %d cols (%ld cells) completed in "),
 	    target_window.rows, target_window.cols, ncells);
     if (hours)
-	fprintf(stderr, "%d:%02d:%02ld\n", hours, minutes, seconds % 60);
+	fprintf(stderr, "%d:%02d:%02ld hours\n", hours, minutes, seconds % 60);
     else
-	fprintf(stderr, "%d:%02ld\n", minutes, seconds % 60);
+	fprintf(stderr, "%d:%02ld minutes\n", minutes, seconds % 60);
     if (seconds)
-	fprintf(stderr, " %.1f cells per minute\n",
+	fprintf(stderr, _(" %.1f cells per minute\n"),
 		(60.0 * ncells) / ((double)seconds));
 
-    fprintf(stderr, "\n");
+    fprintf(stderr, "-----------------------------------------------\n");
 
-    seconds = compress;
-
-    if (seconds <= 0)
-	return 1;
-
-    minutes = seconds / 60;
-    hours = minutes / 60;
-    minutes -= hours * 60;
-    fprintf(stderr, " data compression required an additional ");
-    if (hours)
-	fprintf(stderr, "%d:%02d:%02ld\n", hours, minutes, seconds % 60);
-    else
-	fprintf(stderr, "%d:%02ld\n", minutes, seconds % 60);
-
-    return 0;
+    return 1;
 }

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/target.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/target.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/i.photo.rectify/target.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -10,13 +10,13 @@
     int stat;
 
     if (!I_get_target(name, location, mapset)) {
-	sprintf(buf, "Target information for group [%s] missing.\n", name);
+	sprintf(buf, _("Target information for group <%s> missing.\n"), name);
 	goto error;
     }
 
     sprintf(buf, "%s/%s", G_gisdbase(), location);
     if (access(buf, 0) != 0) {
-	sprintf(buf, "Target location [%s] not found\n", location);
+	sprintf(buf, _("Target location <%s> not found\n"), location);
 	goto error;
     }
     select_target_env();
@@ -28,8 +28,8 @@
 	select_current_env();
 	return 1;
     }
-    sprintf(buf, "Mapset [%s] in target location [%s] - ", mapset, location);
-    strcat(buf, stat == 0 ? "permission denied\n" : "not found\n");
+    sprintf(buf, _("Mapset <%s> in target location <%s> - "), mapset, location);
+    strcat(buf, stat == 0 ? _("permission denied\n") : _("not found\n"));
   error:
     G_fatal_error(buf);
 }

Copied: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/env.c (from rev 44509, grass/branches/develbranch_6/imagery/i.ortho.photo/menu/env.c)
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/env.c	                        (rev 0)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/env.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include "local_proto.h"
+
+static int which_env = -1;	/* 0 = cur, 1 = target */
+
+int select_current_env(void)
+{
+    if (which_env < 0) {
+	G__create_alt_env();
+	which_env = 0;
+    }
+    if (which_env != 0) {
+	G__switch_env();
+	which_env = 0;
+    }
+
+    return 0;
+}
+
+int select_target_env(void)
+{
+    if (which_env < 0) {
+	G__create_alt_env();
+	which_env = 1;
+    }
+    if (which_env != 1) {
+	G__switch_env();
+	which_env = 1;
+    }
+
+    return 0;
+}
+
+int show_env(void)
+{
+    fprintf(stderr, "env(%d) switch to LOCATION %s, MAPSET %s\n", which_env,
+	    G__getenv("LOCATION_NAME") ==
+	    NULL ? "?" : G__getenv("LOCATION_NAME"),
+	    G__getenv("MAPSET") == NULL ? "?" : G__getenv("MAPSET"));
+    G_sleep(2);
+
+    return 0;
+}

Copied: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/i.photo.rectify.c (from rev 44508, grass/branches/develbranch_6/imagery/i.ortho.photo/menu/i.photo.rectify.c)
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/i.photo.rectify.c	                        (rev 0)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/i.photo.rectify.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -0,0 +1,283 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/vask.h>
+#include <grass/imagery.h>
+#include <grass/ortholib.h>
+#include <grass/glocale.h>
+#include "orthophoto.h"
+#include "local_proto.h"
+
+#define L2BDIM 6
+#define BDIM (1<<(L2BDIM))
+#define L2BSIZE (2*(L2BDIM))
+#define BSIZE (1<<(L2BSIZE))
+#define HI(i) ((i)>>(L2BDIM))
+#define LO(i) ((i)&((BDIM)-1))
+
+typedef DCELL block[BDIM][BDIM];   /* FCELL sufficient ? */
+
+/* interactive command line construction for i.photo.rectify */
+/* return 1 on success, 0 on failure
+ */
+int rectify(char *groupname)
+{
+    int i, max_rows, max_cols;
+    int nx, ny;
+    struct Cell_head win, target_window;
+    double max_mb_img, max_mb_elev, max_mb;
+    struct Ortho_Image_Group group;
+    int do_all, ok, repeat, use_target_window;
+    char extension[GNAME_MAX];
+    char result[GNAME_MAX];
+
+    char pgm[1024];
+    int stat;
+
+    sprintf(pgm, "i.photo.rectify  group=%s", groupname);
+    strcpy(group.name, groupname);
+
+    /* get group ref */
+    if (!I_get_group_ref(group.name, (struct Ref *)&group.group_ref)) {
+	fprintf(stderr, _("Could not read REF file for group [%s]"), group.name);
+	fprintf(stderr, _("Orthorectification cancelled"));
+	return 0;
+    }
+    if (group.group_ref.nfiles <= 0) {
+	fprintf(stderr, _("No files in this group!"));
+	fprintf(stderr, _("Orthorectification cancelled"));
+	return 0;
+    }
+    
+    /* get target location/mapset */
+    get_target(group.name, &target_window);
+
+    /* rectify all images in group ? */
+    do_all = 1;
+    if (group.group_ref.nfiles > 1) {
+	G_clear_screen();
+	do_all = G_yes(_("\nRectify all images in the group? "), do_all);
+    }
+    
+    if (!do_all) {
+	int got_one = 0;
+	/* create list of files to be rectified */
+	for (i = 0; i < group.group_ref.nfiles; i++) {
+	    ok = 1;
+	    char buf[100];
+
+	    sprintf(buf, _("\nRectify image <%s>? "), group.group_ref.file[i].name);
+	    ok = G_yes(buf, ok);
+	    if (ok) {
+		if (!got_one) {
+		    sprintf(pgm, "%s input=%s@%s", pgm, group.group_ref.file[i].name, group.group_ref.file[i].mapset);
+		}
+		else {
+		    sprintf(pgm, "%s,%s@%s", pgm, group.group_ref.file[i].name, group.group_ref.file[i].mapset);
+		}
+		got_one = 1;
+	    }
+	}
+	if (!got_one) {
+	    fprintf(stderr,_("\nNo images selected, orthorectification cancelled."));
+	    G_sleep(3);
+	    return 0;
+	}
+    }
+    else
+	sprintf(pgm, "%s -a", pgm);
+    
+    /* name extension for rectified maps */
+    sprintf(extension, ".ortho");
+
+    repeat = 1;
+    while (repeat) {
+	repeat = 0;
+	V_clear();
+	V_line(1, _("Enter an extension to be appended to rectified maps:"));
+	V_ques(extension, 's', 3, 0, 20);
+	V_intrpt_ok();
+	if (!V_call())
+	    return 0;
+
+	/* test for legal file name */
+	sprintf(result, "%s%s", group.group_ref.file[0].name, extension);
+	if (G_legal_filename(result) < 0) {
+	    G_clear_screen();
+	    fprintf(stderr, _("Extension <%s> is illegal"), extension);
+	    repeat = G_yes(_("\nChoose another extension? "), 1);
+	    if (!repeat) {
+		fprintf(stderr,_("Orthorectification cancelled."));
+		G_sleep(3);
+		return 0;
+	    }
+	}
+    }
+    sprintf(pgm, "%s extension=%s", pgm, extension);
+    
+    /* overwrite maps in target location/mapset */
+    G_clear_screen();
+    ok = G_yes(_("\nOverwrite maps in target location/mapset? "), 0);
+    if (ok) {
+	sprintf(pgm, "%s --o", pgm);
+    }
+
+    /* use current region settings in target location (def.=calculate smallest area) ? */
+    use_target_window = 0;
+    while (1) {
+	char buf[100];
+
+	fprintf(stderr, "Please select one of the following options\n");
+	fprintf(stderr,
+		" 1. Use the current window in the target location\n");
+	fprintf(stderr,
+		" 2. Determine the smallest window which covers the image\n");
+	fprintf(stderr, "> ");
+	if (!G_gets(buf))
+	    continue;
+	G_strip(buf);
+
+	if (strcmp(buf, "1") == 0) {
+	    use_target_window = 1;
+	    break;
+	}
+	if (strcmp(buf, "2") == 0)
+	    break;
+    }
+
+    if (use_target_window) {
+	sprintf(pgm, "%s -c", pgm);
+    }
+    else {
+	/* ask for target resolution */
+	double res = -1;
+	
+	while (1) {
+	    char buf[100];
+
+	    fprintf(stderr, "Desired target resolution\n");
+	    fprintf(stderr,
+		    " RETURN   determine automatically\n");
+	    fprintf(stderr, "> ");
+	    if (!G_gets(buf))
+		continue;
+
+	    if (*buf == 0) {  /* determine automatically */
+		break;
+	    }
+
+	    G_strip(buf);
+
+	    if ((res = atof(buf)) <= 0) {
+		fprintf(stderr, "Resolution must be larger than zero!");
+		G_clear_screen();
+	    }
+	    else
+		break;
+	}
+	if (res > 0)
+	    sprintf(pgm, "%s res=%f", pgm, res);
+    }
+
+    /* interpolation method */
+    while (1) {
+	char buf[100];
+
+	G_clear_screen();
+	fprintf(stderr, "\n");
+	fprintf(stderr, _("Please select one of the following interpolation methods\n"));
+	fprintf(stderr, _(" 1. nearest neighbor\n"));
+	fprintf(stderr, _(" 2. bilinear\n"));
+	fprintf(stderr, _(" 3. bicubic\n"));
+	fprintf(stderr, _(" 4. bilinear with fallback\n"));
+	fprintf(stderr, _(" 5. bicubic with fallback\n"));
+	fprintf(stderr, "> ");
+	if (!G_gets(buf))
+	    continue;
+	G_strip(buf);
+
+	if (strcmp(buf, "1") == 0) {
+	    sprintf(pgm, "%s method=nearest", pgm);
+	    break;
+	}
+	if (strcmp(buf, "2") == 0) {
+	    sprintf(pgm, "%s method=bilinear", pgm);
+	    break;
+	}
+	if (strcmp(buf, "3") == 0) {
+	    sprintf(pgm, "%s method=cubic", pgm);
+	    break;
+	}
+	if (strcmp(buf, "4") == 0) {
+	    sprintf(pgm, "%s method=bilinear_f", pgm);
+	    break;
+	}
+	if (strcmp(buf, "5") == 0) {
+	    sprintf(pgm, "%s method=cubic_f", pgm);
+	    break;
+	}
+    }
+
+    /* amount of memory to use */
+    if (use_target_window) {
+	max_rows = max_cols = 0;
+	for (i = 0; i < group.group_ref.nfiles; i++) {
+	    G_get_cellhd(group.group_ref.file[i].name,
+			 group.group_ref.file[i].mapset, &win);
+	    if (max_rows < win.rows)
+		max_rows = win.rows;
+	    if (max_cols < win.cols)
+		max_cols = win.cols;
+	}
+
+	ny = (max_rows + BDIM - 1) / BDIM;
+	nx = (max_cols + BDIM - 1) / BDIM;
+
+	max_mb_img = ((double)nx * ny * sizeof(block)) / (1<<20);
+
+	ny = (target_window.rows + BDIM - 1) / BDIM;
+	nx = (target_window.cols + BDIM - 1) / BDIM;
+
+	max_mb_elev = ((double)nx * ny * sizeof(block)) / (1<<20);
+	max_mb = ceil(max_mb_img + max_mb_elev);
+	if (max_mb < 1)
+	    max_mb = 1;
+    }
+    else
+	/* skip calculating mimimum window, use default */
+	max_mb = 100;
+
+    fprintf(stderr, "\n\n");
+    while (1) {
+	char buf[100];
+	int seg_mb = max_mb + 0.5;
+
+	fprintf(stderr, _("Amount of memory to use in MB\n"));
+	if (use_target_window)
+	    fprintf(stderr, _("RETURN   use %d MB to keep all data in RAM\n"), seg_mb);
+	else {
+	    fprintf(stderr, _("RETURN   use %d MB\n"), seg_mb);
+	}
+	fprintf(stderr, "> ");
+	if (!G_gets(buf))
+	    continue;
+
+	if (*buf == 0) {		/* all in memory */
+	    sprintf(pgm, "%s memory=%d", pgm, seg_mb);
+	    break;
+	}
+
+	G_strip(buf);
+	if ((seg_mb = atoi(buf)) > 0) {
+	    sprintf(pgm, "%s memory=%d", pgm, seg_mb);
+	    break;
+	}
+    }
+
+    if ((stat = G_system(pgm)))
+	G_sleep(3);
+
+    return stat;
+}

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/local_proto.h
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/local_proto.h	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/local_proto.h	2010-12-22 10:10:33 UTC (rev 44655)
@@ -1,3 +1,13 @@
+/* env.c */
+int select_current_env(void);
+int select_target_env(void);
+
+/* i.photo.rectify.c */
+int rectify(char *);
+
 /* run.c */
 int run_etc_imagery(char *, char *);
 int run_system(char *);
+
+/* target.c */
+int get_target(char *, struct Cell_head *);

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/menu.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/menu.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/menu.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -128,7 +128,12 @@
 	    run_etc_imagery("i.photo.init", group.name);
 	if (strcmp(buf, "7") == 0)
 	    run_etc_imagery("i.photo.2target", group.name);
-	if (strcmp(buf, "8") == 0)
-	    run_etc_imagery("i.photo.rectify", group.name);
+	if (strcmp(buf, "8") == 0) {
+	    rectify(group.name);
+	    /*
+	    sprintf(buf, "i.photo.rectify group=%s", group.name);
+	    run_system(buf);
+	    */
+	}
     }
 }

Modified: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/run.c
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/run.c	2010-12-22 10:05:10 UTC (rev 44654)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/run.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -12,9 +12,9 @@
     /* but for now they live in etc/  */
     sprintf(buf, "%s/etc/%s  %s", G_gisbase(), pgm, group);
 
-    if (stat = G_system(buf))
+    if ((stat = G_system(buf)))
 	G_sleep(3);
-    return 0;
+    return stat;
 }
 
 int run_system(char *pgm)
@@ -23,7 +23,7 @@
     int stat;
 
     sprintf(buf, "%s", pgm);
-    if (stat = G_system(buf))
+    if ((stat = G_system(buf)))
 	G_sleep(3);
-    return ((int)stat);
+    return stat;
 }

Copied: grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/target.c (from rev 44508, grass/branches/develbranch_6/imagery/i.ortho.photo/menu/target.c)
===================================================================
--- grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/target.c	                        (rev 0)
+++ grass/branches/releasebranch_6_4/imagery/i.ortho.photo/menu/target.c	2010-12-22 10:10:33 UTC (rev 44655)
@@ -0,0 +1,38 @@
+#include <unistd.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/imagery.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+int get_target(char *name, struct Cell_head *target_window)
+{
+    char location[40];
+    char mapset[40];
+    char buf[1024];
+    int stat;
+
+    if (!I_get_target(name, location, mapset)) {
+	sprintf(buf, "Target information for group [%s] missing.\n", name);
+	goto error;
+    }
+
+    sprintf(buf, "%s/%s", G_gisdbase(), location);
+    if (access(buf, 0) != 0) {
+	sprintf(buf, "Target location [%s] not found\n", location);
+	goto error;
+    }
+    select_target_env();
+    G__setenv("LOCATION_NAME", location);
+    stat = G__mapset_permissions(mapset);
+    if (stat > 0) {
+	G__setenv("MAPSET", mapset);
+	G_get_window(target_window);
+	select_current_env();
+	return 1;
+    }
+    sprintf(buf, "Mapset [%s] in target location [%s] - ", mapset, location);
+    strcat(buf, stat == 0 ? "permission denied\n" : "not found\n");
+  error:
+    G_fatal_error(buf);
+}



More information about the grass-commit mailing list