[GRASS-SVN] r36684 - grass-addons/raster/r.terracost
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 11 12:17:15 EDT 2009
Author: neteler
Date: 2009-04-11 12:17:14 -0400 (Sat, 11 Apr 2009)
New Revision: 36684
Removed:
grass-addons/raster/r.terracost/boundarySort.cc
grass-addons/raster/r.terracost/tileSplit.cc
Modified:
grass-addons/raster/r.terracost/Makefile
grass-addons/raster/r.terracost/main.cc
grass-addons/raster/r.terracost/stats.cc
grass-addons/raster/r.terracost/stats.h
Log:
atanner: fixes. It now compiles
Modified: grass-addons/raster/r.terracost/Makefile
===================================================================
--- grass-addons/raster/r.terracost/Makefile 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/Makefile 2009-04-11 16:17:14 UTC (rev 36684)
@@ -6,10 +6,10 @@
include $(MODULE_TOPDIR)/include/Make/Module.make
-LIBS = $(GISLIB) $(IOSTREAMLIB)
-DEPLIBS = $(GISDEP) $(IOSTREAMDEP)
+LIBES = $(GISLIB) $(IOSTREAMLIB)
+DEPENDENCIES = $(GISDEP) $(IOSTREAMDEP)
default: cmd
$(BIN)/$(PGM)$(EXE): $(ARCH_CMD_OBJS) $(DEPENDENCIES)
- $(CXX) $(LDFLAGS) $(IOSTREAMFLAG) $(XTRA_LDFLAGS) $(EXTRA_CFLAGS) $(NLS_CFLAGS) -o $@ $(ARCH_CMD_OBJS) $(FMODE_OBJ) $(LIBES) $(MATHLIB) $(XDRLIB) $(IOSTREAM_LIB)
+ $(CXX) $(LDFLAGS) $(IOSTREAMFLAG) $(XTRA_LDFLAGS) $(EXTRA_CFLAGS) $(NLS_CFLAGS) -o $@ $(ARCH_CMD_OBJS) $(FMODE_OBJ) $(MATHLIB) $(XDRLIB) $(LIBES)
Deleted: grass-addons/raster/r.terracost/boundarySort.cc
===================================================================
--- grass-addons/raster/r.terracost/boundarySort.cc 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/boundarySort.cc 2009-04-11 16:17:14 UTC (rev 36684)
@@ -1,125 +0,0 @@
-/*
-
- Copyright (C) 2006 Thomas Hazel, Laura Toma, Jan Vahrenhold and
- Rajiv Wickremesinghe
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
-*/
-
-
-/*
- * sort boundary stream
- *
- * rajiv wickremesinghe 2005
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <grass/iostream/ami.h>
-
-#include "input.h"
-#include "config.h"
-#include "sortutils.h"
-
-void
-usage() {
- fprintf(stderr, "boudarySort [options]\n"
- "-h this help"
- "-i input boundary stream"
- "-o output sorted stream (defaults to same as -i"
- "-c config file name");
-
-}
-
-int
-main(int argc, char **argv) {
- char *stream_name=NULL;
- char *config_file=NULL;
- char *sorted_name=NULL;
- AMI_STREAM< ijCostType<costSourceType> > *bndstr;
- int ch;
-
- while ((ch = getopt(argc, argv, "ho:i:c:")) != -1) {
- switch (ch) {
- case 'i':
- stream_name = strdup(optarg);
- break;
- case 'o':
- sorted_name = strdup(optarg);
- break;
- case 'c':
- config_file = strdup(optarg);
- break;
- case 'h':
- default:
- usage();
- exit(0);
- }
- }
-
- if(!config_file || !stream_name) {
- usage();
- exit(1);
- }
- if(! sorted_name) {
- sorted_name = stream_name;
- }
-
- readConfigFile(config_file);
- stats = new statsRecorder("stats.out");
-
- bndstr = new AMI_STREAM< ijCostType<costSourceType> >(stream_name);
- assert(bndstr);
- bndstr->persist(PERSIST_PERSISTENT);
-
- MinIOCostCompareType<costSourceType> sortFun = MinIOCostCompareType<costSourceType>();
- sortFun.setTileSize(tsr, tsc);
-
- sort(&bndstr, sortFun);
-
- const char *new_name = bndstr->name();
- if(strcmp(new_name, sorted_name) == 0) {
- fprintf(stderr, "output in %s\n", sorted_name);
- goto done;
- }
- fprintf(stderr, "trying to rename %s to %s\n", new_name, sorted_name);
-
- // try to rename
- if(rename(new_name, sorted_name) == 0) { // success
- fprintf(stderr, "output renamed to %s\n", sorted_name);
- goto done;
- }
- perror("rename failed");
-
- // rename failed; copy the file
- {
- fprintf(stderr, "trying to copy\n");
- char buf[BUFSIZ];
- sprintf(buf, "/bin/cp \"%s\" \"%s\"", new_name, sorted_name);
- int status = system(buf);
- if(WIFEXITED(status)) {
- if(WEXITSTATUS(status) == 0) {
- fprintf(stderr, "output copied to %s\n", sorted_name);
- goto done;
- }
- }
- }
-
- fprintf(stderr, "boundarySort: Failed!!!\n");
- exit(1);
-
- done:
- return 0;
-}
Modified: grass-addons/raster/r.terracost/main.cc
===================================================================
--- grass-addons/raster/r.terracost/main.cc 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/main.cc 2009-04-11 16:17:14 UTC (rev 36684)
@@ -117,7 +117,7 @@
mem->key = "memory";
mem->type = TYPE_INTEGER;
mem->required = NO;
- mem->answer = "400"; /* 400MB default value */
+ mem->answer = G_store("400"); /* 400MB default value */
mem->description = _("Main memory size (in MB)");
/* temporary STREAM path */
@@ -126,7 +126,7 @@
streamdir->key = "STREAM_DIR";
streamdir->type = TYPE_STRING;
streamdir->required = NO;
- streamdir->answer = "/var/tmp";
+ streamdir->answer = G_store("/var/tmp");
streamdir->description= _("Location of temporary STREAMs");
/* temporary VTMPDIR path */
@@ -208,7 +208,7 @@
numtiles->type = TYPE_INTEGER;
numtiles->required = NO;
numtiles->description= _("Number of tiles (-h for info)");
- numtiles->answer = "-1";
+ numtiles->answer = G_store("-1");
/* Stem name for stream outputs; used in conjunction with step0 flag */
struct Option *s0out;
@@ -217,7 +217,7 @@
s0out->type = TYPE_STRING;
s0out->required = NO;
s0out->description= _("Stream name stem for step 0 output");
- s0out->answer = S0OUT_ANS;
+ s0out->answer = G_store(S0OUT_ANS);
struct Option *s0bnd;
s0bnd = G_define_option() ;
@@ -225,7 +225,7 @@
s0bnd->type = TYPE_STRING;
s0bnd->required = NO;
s0bnd->description= _("Stream name for boundary data structure");
- s0bnd->answer = S0BND_ANS;
+ s0bnd->answer = G_store(S0BND_ANS);
/* Name for config file output */
struct Option *s1out;
@@ -234,7 +234,7 @@
s1out->type = TYPE_STRING;
s1out->required = NO;
s1out->description= _("Output file for step 1");
- s1out->answer = S1OUT_ANS;
+ s1out->answer = G_store(S1OUT_ANS);
/* Name for config file output */
struct Option *s2bout;
@@ -243,7 +243,7 @@
s2bout->type = TYPE_STRING;
s2bout->required = NO;
s2bout->description= _("Output file for source to boundary stream");
- s2bout->answer = S2BOUT_ANS;
+ s2bout->answer = G_store(S2BOUT_ANS);
/* Name for config file output */
struct Option *config;
@@ -252,7 +252,7 @@
config->type = TYPE_STRING;
config->required = NO;
config->description= _("Name for config file");
- config->answer = CONFIG_ANS;
+ config->answer = G_store(CONFIG_ANS);
/* Name for config file output */
struct Option *phaseBnd;
@@ -261,7 +261,7 @@
phaseBnd->type = TYPE_STRING;
phaseBnd->required = NO;
phaseBnd->description= _("Name for phase2Bnd file");
- phaseBnd->answer = PHASE2BND_ANS;
+ phaseBnd->answer = G_store(PHASE2BND_ANS);
/* stats file */
@@ -271,7 +271,7 @@
stats_opt->type = TYPE_STRING;
stats_opt->required = NO;
stats_opt->description= _("Stats file");
- stats_opt->answer = STATS_ANS;
+ stats_opt->answer = G_store(STATS_ANS);
struct Option *tilesAreSorted;
tilesAreSorted = G_define_option();
@@ -279,7 +279,7 @@
tilesAreSorted->type = TYPE_STRING;
tilesAreSorted->required = NO;
tilesAreSorted->description = _("Tiles are sorted (used in grid version) (y/n)");
- tilesAreSorted->answer = "no";
+ tilesAreSorted->answer = G_store("no");
/* ************************* */
Modified: grass-addons/raster/r.terracost/stats.cc
===================================================================
--- grass-addons/raster/r.terracost/stats.cc 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/stats.cc 2009-04-11 16:17:14 UTC (rev 36684)
@@ -113,7 +113,7 @@
int
-noclobberFile(char * const fname) {
+noclobberFile(const char * fname) {
int fd=-1;
while(fd<0) {
@@ -136,8 +136,8 @@
return fd;
}
-char*
-noclobberFileName(char *fname) {
+const char*
+noclobberFileName(const char *fname) {
int fd;
fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
if(fd < 0) {
@@ -162,7 +162,7 @@
/* ********************************************************************** */
-statsRecorder::statsRecorder(char * const fname) {
+statsRecorder::statsRecorder(const char * fname) {
//note: in the new version of gcc there is not constructor for
//ofstream that takes an fd; wrote another noclobber() function that
//closes fd and returns the name;
Modified: grass-addons/raster/r.terracost/stats.h
===================================================================
--- grass-addons/raster/r.terracost/stats.h 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/stats.h 2009-04-11 16:17:14 UTC (rev 36684)
@@ -35,7 +35,7 @@
Rtimer tm;
void *bss;
public:
- statsRecorder(char * const fname);
+ statsRecorder(const char * fname);
/* ~statsRecorder() { */
/* this->flush(); */
/* } */
Deleted: grass-addons/raster/r.terracost/tileSplit.cc
===================================================================
--- grass-addons/raster/r.terracost/tileSplit.cc 2009-04-11 15:10:38 UTC (rev 36683)
+++ grass-addons/raster/r.terracost/tileSplit.cc 2009-04-11 16:17:14 UTC (rev 36684)
@@ -1,260 +0,0 @@
-/*
-
- Copyright (C) 2006 Thomas Hazel, Laura Toma, Jan Vahrenhold and
- Rajiv Wickremesinghe
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
-*/
-
-/*
- * split stream into tiles
- *
- * rajiv wickremesinghe 2005
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <assert.h>
-
-#include <grass/iostream/ami.h>
-#include "locator.h"
-#include "input.h"
-#include "config.h"
-#include "queue.h"
-
-
-static void
-usage() {
- printf("usage: tileSplit [options]\n");
-// printf(" -n<arity>\n");
- printf(" -i<input> (default=stdin)\n");
- printf(" -o<outroot>\n");
- printf(" -c<config>\n");
-}
-
-#define BUFFER_SIZE (32<<10)
-
-static int opencalls = 0;
-
-void
-file_name(char *buf, char *outroot, int id) {
- sprintf(buf, "%s-%04d", outroot, id);
-}
-
-
-int
-open_file(char *outroot, int id, int truncate) {
- char buf[BUFSIZ];
-
- opencalls++;
-
- file_name(buf, outroot, id);
- int fd = open(buf, O_WRONLY | O_CREAT | (truncate?O_TRUNC:O_APPEND), 0666);
- if(fd < 0) {
- perror(buf);
- exit(1);
- }
- return fd;
-}
-
-typedef struct open_stream_t {
- int id;
- TAILQ_ENTRY(open_stream_t) link;
-} open_stream_t;
-
-TAILQ_HEAD(qhead, open_stream_t) qhead = TAILQ_HEAD_INITIALIZER(qhead);
-#define QSIZ 200
-
-void
-qinit() {
- int i;
- for(i=0; i<QSIZ; i++) {
- open_stream_t *strm = (open_stream_t *)malloc(sizeof(open_stream_t));
- assert(strm);
- strm->id = -1;
- TAILQ_INSERT_TAIL(&qhead, strm, link);
- }
-}
-
-AMI_STREAM<ijCostSource> *
-get_stream(AMI_STREAM<ijCostSource> **outstrms, char *outroot, int id) {
- int fd;
- static int inited = 0;
-
- if(!inited) {
- qinit();
- }
- inited = 1;
-
- if(!outstrms[id]) { // must open
- open_stream_t *strm = TAILQ_FIRST(&qhead);
- if(strm->id >= 0) { // clean head if needed
- delete outstrms[strm->id];
- outstrms[strm->id] = NULL;
- }
- TAILQ_REMOVE(&qhead, strm, link);
- strm->id = id;
- fd = open_file(outroot, id, 0);
- outstrms[id] = new AMI_STREAM<ijCostSource>(fd, AMI_APPEND_WRITE_STREAM);
- TAILQ_INSERT_TAIL(&qhead, strm, link);
- }
- return outstrms[id];
-}
-
-
-int
-main(int argc, char **argv) {
- int fdin = STDIN_FILENO;
- char *path = NULL;
- int arity=0;
- int reclen;
- int off;
- AMI_STREAM<ijCostSource> **outstrms;
- char *config_file=NULL;
- char *outroot = NULL;
- int ch;
- int group = 1;
-
- while ((ch = getopt(argc, argv, "ho:i:c:g:n:")) != -1) {
- switch (ch) {
- case 'i':
- path = optarg;
- break;
- case 'o':
- outroot = strdup(optarg);
- break;
- case 'n':
- arity = atoi(optarg);
- break;
- case 'g':
- group = atoi(optarg);
- break;
- case 'c':
- config_file = strdup(optarg);
- break;
- case 'h':
- usage();
- exit(0);
- }
- }
-
- if(path) {
- fdin = open(path, O_RDONLY);
- if(fdin < 0) {
- perror(path);
- exit(1);
- }
- }
-
- if(!outroot || !config_file || group<1) {
- usage();
- exit(1);
- }
-
- readConfigFile(config_file);
- if(arity >= g.ntiles) {
- arity = g.ntiles;
- group = 1;
- } else if(arity) {
- // arity gets precedence
- group = (g.ntiles + arity - 1) / arity; // roundup
- } else {
- assert(group > 0);
- arity = (g.ntiles + group - 1) / group; // roundup
- }
-
- off_t expectedSize = (off_t)(tsr-2) * (tsc-2) * sizeof(ijCostSource) * group;
- fprintf(stderr, "arity=%d\n", arity);
- fprintf(stderr, "sizeof(ijCostSource)=%d expected file size=%lld\n",
- sizeof(ijCostSource), expectedSize);
- fprintf(stderr, "group=%d\n", group);
-
- reclen = sizeof(ijCostSource);
- assert(reclen < BUFFER_SIZE);
-
- outstrms = (AMI_STREAM<ijCostSource>**)malloc(sizeof(AMI_STREAM<ijCostSource>*) * arity);
- assert(outstrms);
-
- for(int i=0; i<arity; i++) {
- int fd = open_file(outroot, i, 1);
- close(fd);
- outstrms[i] = NULL;
- }
-
- IJClassifier ijcc(config_file);
- int nread = 0;
- int nwrite = 0;
-
- cerr << "Running split..." << endl;
-
- AMI_STREAM<ijCostSource> *strm = new AMI_STREAM<ijCostSource>(fdin, AMI_READ_STREAM);
- while(!strm->eof()) {
- ijCostSource *record;
- AMI_err ae;
-
- ae = strm->read_item(&record);
- if(ae == AMI_ERROR_END_OF_STREAM) {
- continue;
- }
- assert(ae == AMI_ERROR_NO_ERROR);
- nread++;
-
- off = ijcc.classify(record) % arity;
- //assert(off < arity);
- //assert(off >= 0);
-
- ae = get_stream(outstrms, outroot, off)->write_item(*record);
- assert(ae == AMI_ERROR_NO_ERROR);
- nwrite++;
- }
-
- for(int i=0; i<arity; i++) {
- //fprintf(stderr, "output [%d] length = %ld\n", i, (long)outstrms[i]->tell());
- char buf[BUFSIZ];
- file_name(buf, outroot, i);
- printf("%s\n", buf);
- if(outstrms[i]) {
- delete outstrms[i];
- }
- }
-#ifndef NDEBUG
- fprintf(stderr, "Checking file sizes...");
- for(int i=0; i<arity; i++) {
- char buf[BUFSIZ];
- file_name(buf, outroot, i);
- struct stat sb;
- if(stat(buf, &sb)) {
- perror(buf);
- exit(1);
- }
- if(sb.st_size != expectedSize) {
- fprintf(stderr, "file size mismatch for %s\n", buf);
- exit(1);
- }
- }
- fprintf(stderr, " done\n");
-#endif
- free(outstrms);
-
- //fprintf(stderr, "%d records read; %d records written\n", nread, nwrite);
- assert(nread == nwrite);
- //fprintf(stderr, "input length = %ld\n", (long)strm->tell());
-
- fprintf(stderr, "open calls = %d\n", opencalls);
-
- return 0;
-}
More information about the grass-commit
mailing list