[GRASS-SVN] r44507 - grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 2 04:38:50 EST 2010


Author: mmetz
Date: 2010-12-02 01:38:49 -0800 (Thu, 02 Dec 2010)
New Revision: 44507

Removed:
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_files.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_method.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/compress.c
Modified:
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/Makefile
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cp.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/defs.h
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/env.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/equ.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/exec.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/get_wind.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/global.h
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/local_proto.h
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/main.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/nearest.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/readcell.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/rectify.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/report.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/target.c
Log:
sync to i.rectify part 2, non-interacitveand scriptable

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/Makefile
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/Makefile	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/Makefile	2010-12-02 09:38:49 UTC (rev 44507)
@@ -11,8 +11,5 @@
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
-default: etc
+default: cmd
 
-$(PGM).tmp.html: description.html
-	$(INSTALL_DATA) $< $@
-

Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_files.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_files.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_files.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_method.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_method.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/ask_method.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/bilinear_f.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -8,7 +8,6 @@
  *  it falls back to nearest neighbor.
  */
 
-#include <grass/gis.h>
 #include <math.h>
 #include "global.h"
 

Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/compress.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/compress.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/compress.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -1,9 +0,0 @@
-#include "global.h"
-
-int compress(char *name)
-{
-    return 0;
-    /*
-       return 1;
-     */
-}

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cp.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cp.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cp.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/cubic_f.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -9,7 +9,6 @@
  *  it falls back to nearest neighbor.
  */
 
-#include <grass/gis.h>
 #include <math.h>
 #include "global.h"
 

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/defs.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/defs.h	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/defs.h	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/env.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/env.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/env.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/equ.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/equ.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/equ.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/exec.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/exec.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/exec.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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);
 
     G_done_msg(" ");
+
     return 0;
 }

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/get_wind.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/get_wind.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/get_wind.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/global.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/global.h	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/global.h	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/local_proto.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/local_proto.h	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/local_proto.h	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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,21 @@
 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);
 
 /* report.c */
-int report(char *, char *, char *, long, long, int);
+int report(long, int);
 
 /* target.c */
 int get_target(char *);

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/main.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/main.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/main.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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 = "300";
+    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")))
+	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 = seg_mb_total * max_mb_elev / (max_mb_img + max_mb_elev);
+	    seg_mb_img = seg_mb_total * max_mb_img / (max_mb_img + max_mb_elev);
+	}
+    }
+
     /* 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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/nearest.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/nearest.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/nearest.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/readcell.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/readcell.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/readcell.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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)
@@ -48,11 +46,11 @@
     c->refs = (int *)G_malloc(nblocks * sizeof(int));
 
     if (nblocks < nx * ny) {
-	/* Temporary file must be created in output location */
-	select_target_env();
+	/* Temporary file must be created in input location/mapset */
+	select_current_env();
 	filename = G_tempfile();
-	if (!target_env)
-	    select_current_env();
+	if (target_env)
+	    select_target_env();
 	c->fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
 	if (c->fd < 0)
 	    G_fatal_error(_("Unable to open temporary file"));
@@ -103,6 +101,9 @@
 	    c->refs[i] = i;
 	}
 
+    if (target_env)
+	select_current_env();
+
     return c;
 }
 

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/rectify.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/rectify.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/rectify.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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,9 +112,9 @@
     }
     G_percent(1, 1, 1);
 
+    G_close_cell(outfd);
     G_free(trast);
 
-    G_close_cell(outfd);
     close(ibuffer->fd);
     G_free(ibuffer);
 
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/report.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/report.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/report.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/target.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/target.c	2010-12-02 05:07:58 UTC (rev 44506)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/i.photo.rectify/target.c	2010-12-02 09:38:49 UTC (rev 44507)
@@ -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);
 }



More information about the grass-commit mailing list