Procházet zdrojové kódy

i.vi: fix the check for the existence of the 'redchan' variable (#1378)

Tomas Zigo před 4 roky
rodič
revize
427df25493
1 změnil soubory, kde provedl 11 přidání a 5 odebrání
  1. 11 5
      imagery/i.vi/main.c

+ 11 - 5
imagery/i.vi/main.c

@@ -275,7 +275,7 @@ int main(int argc, char *argv[])
                 || !(opt.blue->answer)) )
 	G_fatal_error(_("evi index requires blue, red and nir maps"));
 
-	if (!strcasecmp(viflag, "evi2") && (!(opt.red->answer) || !(opt.nir->answer) ) )
+    if (!strcasecmp(viflag, "evi2") && (!(opt.red->answer) || !(opt.nir->answer) ) )
 	G_fatal_error(_("evi2 index requires red and nir maps"));
 	
     if (!strcasecmp(viflag, "vari") && (!(opt.red->answer) || !(opt.green->answer)
@@ -347,7 +347,9 @@ int main(int argc, char *argv[])
 	G_percent(row, nrows, 2);
 
 	/* read input maps */
-	Rast_get_row(infd_redchan,inrast_redchan,row,data_type_redchan);
+	if (redchan) {
+	    Rast_get_row(infd_redchan,inrast_redchan,row,data_type_redchan);
+	}
 	if (nirchan) {
 	    Rast_get_row(infd_nirchan,inrast_nirchan,row,data_type_nirchan);
 	}
@@ -366,6 +368,7 @@ int main(int argc, char *argv[])
 	/* process the data */
 	for (col = 0; col < ncols; col++)
 	{
+	    if (redchan) {
 	    switch(data_type_redchan){
 		    case CELL_TYPE:
 			d_redchan   = (double) ((CELL *) inrast_redchan)[col];
@@ -379,6 +382,7 @@ int main(int argc, char *argv[])
 			d_redchan   = ((DCELL *) inrast_redchan)[col];
 			break;
 	    }
+	    }
 	    if (nirchan) {
 		switch(data_type_nirchan){
 		    case CELL_TYPE:
@@ -525,9 +529,11 @@ int main(int argc, char *argv[])
 	Rast_put_f_row(outfd, outrast);
     }
     G_percent(1, 1, 1);
-      
-    G_free(inrast_redchan);
-    Rast_close(infd_redchan);
+
+    if (redchan) {
+	G_free(inrast_redchan);
+	Rast_close(infd_redchan);
+    }
     if (nirchan) {
     	G_free(inrast_nirchan);
     	Rast_close(infd_nirchan);