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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 16 09:43:39 EDT 2008


Author: hamish
Date: 2008-10-16 09:43:39 -0400 (Thu, 16 Oct 2008)
New Revision: 33917

Modified:
   grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c
   grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c
Log:
update to use G_parser, modern ways

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c	2008-10-16 13:19:19 UTC (rev 33916)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c	2008-10-16 13:43:39 UTC (rev 33917)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <grass/glocale.h>
 #include "global.h"
 #include <grass/vask.h>
 
@@ -32,7 +33,7 @@
 	ln = 2;
 	V_clear();
 	V_line(0,
-	       "Please select the file(s) you wish to rectify by naming an output file");
+	       _("Please select the file(s) you wish to rectify by naming an output file"));
 	if (!repeat)
 	    for (i = 0; i < NFILES; i++)
 		result[i][0] = 0;

Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c	2008-10-16 13:19:19 UTC (rev 33916)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c	2008-10-16 13:43:39 UTC (rev 33917)
@@ -6,11 +6,12 @@
  *               Markus Neteler <neteler itc.it>, 
  *               Bernhard Reiter <bernhard intevation.de>, 
  *               Glynn Clements <glynn gclements.plus.com>, 
- *               Hamish Bowman <hamish_nospam yahoo.com>
- * PURPOSE:      rectifies an image by using the image to photo coordinate 
- *               transformation matrix
- * COPYRIGHT:    (C) 1999-2006 by the GRASS Development Team
+ *               Hamish Bowman <hamish_b yahoo.com>
  *
+ * PURPOSE:      Rectifies an image by using the image to photo coordinate 
+ *                 transformation matrix
+ * COPYRIGHT:    (C) 1999-2008 by the GRASS Development Team
+ *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
  *               for details.
@@ -19,56 +20,71 @@
 #define GLOBAL
 #include <stdlib.h>
 #include <string.h>
+#include <grass/gis.h>
 #include <grass/imagery.h>
+#include <grass/glocale.h>
 #include "global.h"
 
 int main(int argc, char *argv[])
 {
-    char *name, *location, *mapset, *camera, msg[100];
+
+    char name[GNAME_MAX];
+    char *camera;
     int n, nfiles;
     char tl[100];
     char math_exp[100];
     char units[100];
     char nd[100];
 
+    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.");
+
+    group_opt = G_define_standard_option(G_OPT_I_GROUP);
+    group_opt->description =
+	_("Name of imagery group for ortho-rectification");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
 #ifdef DEBUG3
+/* slowly convert these to G_debug() */
     Bugsr = fopen("ortho_rectify.rst", "w");
-    if (Bugsr == NULL) {
-	sprintf(msg, "Cant open debug file ortho_rectify\n");
-	G_fatal_error(msg);
-    }
+    if (Bugsr == NULL)
+	G_fatal_error("Can't open debug file \"ortho_rectify.rst\"");
 #endif
 
-    if (argc != 2) {
-	fprintf(stderr, "usage: %s group\n", argv[0]);
-	exit(1);
-    }
 
-    G_gisinit(argv[0]);
     G_suppress_masking();	/* need to do this for target location */
 
-    name = (char *)G_malloc(40 * sizeof(char));
-    location = (char *)G_malloc(80 * sizeof(char));
-    mapset = (char *)G_malloc(80 * sizeof(char));
+    strcpy(name, group_opt->answer);
+
     camera = (char *)G_malloc(40 * sizeof(char));
-    elev_layer = (char *)G_malloc(40 * sizeof(char));
-    mapset_elev = (char *)G_malloc(40 * sizeof(char));
+    elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char));
+    mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
 
     /* get group ref */
-    name = argv[1];
     strcpy(group.name, name);
-    if (!I_find_group(group.name)) {
-	fprintf(stderr, "Group [%s] not found\n", group.name);
-	exit(1);
-    }
+    if (!I_find_group(group.name))
+	G_fatal_error(_("Group [%s] not found"), group.name);
 
     /* get the group ref */
     I_get_group_ref(group.name, (struct Ref *)&group.group_ref);
     nfiles = group.group_ref.nfiles;
-    if (nfiles <= 0) {
-	sprintf(msg, "No files in this group!\n");
-	G_fatal_error(msg);
-    }
+    if (nfiles <= 0)
+	G_fatal_error(_("No files in this group!"));
+
     ref_list = (int *)G_malloc(nfiles * sizeof(int));
     new_name = (char **)G_malloc(nfiles * sizeof(char *));
     for (n = 0; n < nfiles; n++)
@@ -80,17 +96,14 @@
     /* ask for files to be rectified */
     ask_files(group.name);
 
-#ifdef DEBUG3
-    fprintf(Bugsr, "Looking for elevation file in group: %s\n", group.name);
-#endif
 
+    G_debug(1, "Looking for elevation file in group: <%s>", group.name);
+
     /* get the block elevation layer raster map  in target location */
     I_get_group_elev(group.name, elev_layer, mapset_elev, tl, math_exp,
 		     units, nd);
 
-#ifdef DEBUG3
-    fprintf(Bugsr, "Block elevation: %s in %s\n", elev_layer, mapset_elev);
-#endif
+    G_debug(1, "Block elevation: <%s> in <%s>", elev_layer, mapset_elev);
 
     /* get the elevation layer header in target location */
     select_target_env();
@@ -98,25 +111,19 @@
     select_current_env();
 
     /** look for camera info  for this block **/
-    if (!I_get_group_camera(group.name, camera)) {
-	sprintf(msg, "No camera reference file selected for group [%s]\n",
-		group.name);
-	G_fatal_error(msg);
-    }
-    if (!I_get_cam_info(camera, &group.camera_ref)) {
-	sprintf(msg, "Bad format in camera file for group [%s]\n",
-		group.name);
-	G_fatal_error(msg);
-    }
+    if (!I_get_group_camera(group.name, camera))
+	G_fatal_error(_("No camera reference file selected for group [%s]"),
+		      group.name);
 
+    if (!I_get_cam_info(camera, &group.camera_ref))
+	G_fatal_error(_("Bad format in camera file for group [%s]"),
+		      group.name);
+
     /* get initial camera exposure station, if any */
     if (I_find_initial(group.name)) {
-	if (!I_get_init_info(group.name, &group.camera_exp)) {
-	    sprintf(msg,
-		    "Bad format in initial exposusre station file for group [%s]\n",
-		    group.name);
-	    G_warning(msg);
-	}
+	if (!I_get_init_info(group.name, &group.camera_exp))
+	    G_warning(_("Bad format in initial exposusre station file for group [%s]"),
+		      group.name);
     }
 
     /* read the reference points for the group, compute image-to-photo trans. */
@@ -140,5 +147,5 @@
     /*  go do it */
     exec_rectify();
 
-    exit(0);
+    exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list