@Override public void run(){
  amIActive=true;
  String inputHeader=null;
  String outputHeader=null;
  String histoFile=null;
  double range=0;
  int numIterations=0;
  double z=0;
  int row, col;
  float progress=0;
  double[] data1;
  double[] data2;
  if (args.length <= 0) {
    showFeedback("Plugin parameters have not been set.");
    return;
  }
  for (int i=0; i < args.length; i++) {
    if (i == 0) {
      inputHeader=args[i];
    }
 else     if (i == 1) {
      outputHeader=args[i];
    }
 else     if (i == 2) {
      histoFile=args[i];
    }
 else     if (i == 3) {
      range=Double.parseDouble(args[i]);
    }
 else     if (i == 4) {
      numIterations=Integer.parseInt(args[i]);
    }
 else     if (i == 5) {
      numBands=Integer.parseInt(args[i]);
    }
  }
  if ((inputHeader == null) || (outputHeader == null)) {
    showFeedback("One or more of the input parameters have not been set properly.");
    return;
  }
  try {
    DEM=new WhiteboxRaster(inputHeader,"r");
    rows=DEM.getNumberRows();
    cols=DEM.getNumberColumns();
    noData=DEM.getNoDataValue();
    double[][] output=new double[rows][cols];
    for (int iterationNum=0; iterationNum < numIterations; iterationNum++) {
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(0 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      tempGrid1=new double[rows][cols];
      tempGrid2=new double[rows][cols];
      for (row=0; row < rows; row++) {
        for (col=0; col < cols; col++) {
          tempGrid2[row][col]=noData;
        }
      }
      TurningBandSimulation(range);
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(1 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      HistogramMatching(histoFile);
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(2 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      for (row=0; row < rows; row++) {
        data1=DEM.getRowValues(row);
        for (col=0; col < cols; col++) {
          if (data1[col] != noData) {
            tempGrid1[row][col]=data1[col] + tempGrid2[row][col];
          }
 else {
            tempGrid1[row][col]=noData;
          }
        }
      }
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(3 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      FillDepressions();
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(4 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      for (row=0; row < rows; row++) {
        for (col=0; col < cols; col++) {
          if (tempGrid2[row][col] > tempGrid1[row][col]) {
            output[row][col]+=1;
          }
        }
      }
      progress=(float)(5 * 100f / 5);
      updateProgress("Loop " + (iterationNum + 1) + " of "+ numIterations+ ": ",(int)progress);
      if (cancelOp) {
        cancelOperation();
        return;
      }
    }
    outputFile=new WhiteboxRaster(outputHeader,"rw",inputHeader,WhiteboxRaster.DataType.FLOAT,0);
    outputFile.setPreferredPalette("spectrum.pal");
    for (row=0; row < rows; row++) {
      data1=DEM.getRowValues(row);
      for (col=0; col < cols; col++) {
        if (data1[col] != noData) {
          outputFile.setValue(row,col,output[row][col]);
        }
 else {
          outputFile.setValue(row,col,noData);
        }
      }
    }
    outputFile.addMetadataEntry("Created by the " + getDescriptiveName() + " tool.");
    outputFile.addMetadataEntry("Created on " + new Date());
    DEM.close();
    outputFile.close();
    returnData(outputHeader);
  }
 catch (  OutOfMemoryError oe) {
    myHost.showFeedback("An out-of-memory error has occurred during operation.");
  }
catch (  Exception e) {
    myHost.showFeedback("An error has occurred during operation. See log file for details.");
    myHost.logException("Error in " + getDescriptiveName(),e);
  }
 finally {
    updateProgress("Progress: ",0);
    amIActive=false;
    myHost.pluginComplete();
  }
}

@ Override public void run ( ) { amIActive = true ; String inputHeader = null ; String outputHeader = null ; String histoFile = null ; double range = 0 ; int numIterations = 0 ; double z = 0 ; int row , col ; float progress = 0 ; double [ ] data1 ; double [ ] data2 ; if ( args . length <= 0 ) { showFeedback ( "Plugin parameters have not been set." ) ; return ; } for ( int i = 0 ; i < args . length ; i ++ ) { if ( i == 0 ) { inputHeader = args [ i ] ; } else if ( i == 1 ) { outputHeader = args [ i ] ; } else if ( i == 2 ) { histoFile = args [ i ] ; } else if ( i == 3 ) { range = Double . parseDouble ( args [ i ] ) ; } else if ( i == 4 ) { numIterations = Integer . parseInt ( args [ i ] ) ; } else if ( i == 5 ) { numBands = Integer . parseInt ( args [ i ] ) ; } } if ( ( inputHeader == null ) || ( outputHeader == null ) ) { showFeedback ( "One or more of the input parameters have not been set properly." ) ; return ; } try { DEM = new WhiteboxRaster ( inputHeader , "r" ) ; rows = DEM . getNumberRows ( ) ; cols = DEM . getNumberColumns ( ) ; noData = DEM . getNoDataValue ( ) ; double [ ] [ ] output = new double [ rows ] [ cols ] ; for ( int iterationNum = 0 ; iterationNum < numIterations ; iterationNum ++ ) { if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 0 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; tempGrid1 = new double [ rows ] [ cols ] ; tempGrid2 = new double [ rows ] [ cols ] ; for ( row = 0 ; row < rows ; row ++ ) { for ( col = 0 ; col < cols ; col ++ ) { tempGrid2 [ row ] [ col ] = noData ; } } TurningBandSimulation ( range ) ; if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 1 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; HistogramMatching ( histoFile ) ; if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 2 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; for ( row = 0 ; row < rows ; row ++ ) { data1 = DEM . getRowValues ( row ) ; for ( col = 0 ; col < cols ; col ++ ) { if ( data1 [ col ] != noData ) { tempGrid1 [ row ] [ col ] = data1 [ col ] + tempGrid2 [ row ] [ col ] ; } else { tempGrid1 [ row ] [ col ] = noData ; } } } if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 3 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; FillDepressions ( ) ; if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 4 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; for ( row = 0 ; row < rows ; row ++ ) { for ( col = 0 ; col < cols ; col ++ ) { if ( tempGrid2 [ row ] [ col ] > tempGrid1 [ row ] [ col ] ) { output [ row ] [ col ] += 1 ; } } } progress = ( float ) ( 5 * 100f / 5 ) ; updateProgress ( "Loop " + ( iterationNum + 1 ) + " of " + numIterations + ": " , ( int ) progress ) ; if ( cancelOp ) { cancelOperation ( ) ; return ; } } outputFile = new WhiteboxRaster ( outputHeader , "rw" , inputHeader , WhiteboxRaster . DataType . FLOAT , 0 ) ; outputFile . setPreferredPalette ( "spectrum.pal" ) ; for ( row = 0 ; row < rows ; row ++ ) { data1 = DEM . getRowValues ( row ) ; for ( col = 0 ; col < cols ; col ++ ) { if ( data1 [ col ] != noData ) { outputFile . setValue ( row , col , output [ row ] [ col ] ) ; } else { outputFile . setValue ( row , col , noData ) ; } } } outputFile . addMetadataEntry ( "Created by the " + getDescriptiveName ( ) + " tool." ) ; outputFile . addMetadataEntry ( "Created on " + new Date ( ) ) ; DEM . close ( ) ; outputFile . close ( ) ; returnData ( outputHeader ) ; } catch ( OutOfMemoryError oe ) { myHost . showFeedback ( "An out-of-memory error has occurred during operation." ) ; } catch ( Exception e ) { myHost . showFeedback ( "An error has occurred during operation. See log file for details." ) ; myHost . logException ( "Error in " + getDescriptiveName ( ) , e ) ; } finally { updateProgress ( "Progress: " , 0 ) ; amIActive = false ; myHost . pluginComplete ( ) ; } }
used to execute this plugin tool .
