@Override public void run(){
  amIActive=true;
  int row, col, x, y;
  float progress=0;
  double z;
  int i, b, c, ICLCA;
  boolean flag=false;
  double flowDir=0;
  double outletID=0;
  double SCAValue;
  double maxSCA, d1, d2;
  if (args.length <= 0) {
    showFeedback("Plugin parameters have not been set.");
    return;
  }
  String pointerHeader=args[0];
  String caHeader=args[1];
  String outputHeader=args[2];
  double SCAThreshold=Double.parseDouble(args[3]);
  if (pointerHeader.isEmpty() || caHeader.isEmpty() || outputHeader.isEmpty()) {
    showFeedback("One or more of the input parameters have not been set properly.");
    return;
  }
  try {
    pointer=new WhiteboxRaster(pointerHeader,"r");
    int rows=pointer.getNumberRows();
    int cols=pointer.getNumberColumns();
    double noData=pointer.getNoDataValue();
    String tempFile=caHeader.replace(".dep","_temp.dep");
    FileUtilities.copyFile(new File(caHeader),new File(tempFile));
    FileUtilities.copyFile(new File(caHeader.replace(".dep",".tas")),new File(tempFile.replace(".dep",".tas")));
    contArea=new WhiteboxRaster(tempFile,"rw");
    contArea.isTemporaryFile=true;
    WhiteboxRaster output=new WhiteboxRaster(outputHeader,"rw",caHeader,WhiteboxRaster.DataType.FLOAT,-999);
    output.setDataScale(WhiteboxRasterBase.DataScale.CATEGORICAL);
    output.setPreferredPalette("categorical1.pal");
    outletID=1;
    for (row=0; row < rows; row++) {
      for (col=0; col < cols; col++) {
        if (pointer.getValue(row,col) != noData) {
          flag=false;
          for (i=0; i < 8; i++) {
            if (pointer.getValue(col + dX[i],row + dY[i]) == inflowingVals[i]) {
              flag=true;
            }
          }
          if (!flag) {
            flag=false;
            x=col;
            y=row;
            do {
              flowDir=pointer.getValue(y,x);
              if (flowDir > 0) {
                i=(int)(Math.log(flowDir) / LnOf2);
                x+=dX[i];
                y+=dY[i];
              }
 else {
                flag=true;
              }
              SCAValue=contArea.getValue(y,x);
              if (SCAValue >= SCAThreshold) {
                maxSCA=-99999;
                ICLCA=8;
                for (i=0; i < 8; i++) {
                  b=x + dX[i];
                  c=y + dY[i];
                  if (pointer.getValue(c,b) == inflowingVals[i]) {
                    z=contArea.getValue(c,b);
                    if (z > maxSCA) {
                      maxSCA=z;
                      ICLCA=i;
                    }
                  }
                }
                b=x + dX[ICLCA];
                c=y + dY[ICLCA];
                if (contArea.getValue(c,b) > SCAThreshold) {
                  flag=true;
                }
 else {
                  d1=Math.abs(contArea.getValue(c,b) - SCAThreshold);
                  d2=Math.abs(contArea.getValue(y,x) - SCAThreshold);
                  if (d1 < d2) {
                    output.setValue(c,b,outletID);
                    decrementFlowpath(c,b,contArea.getValue(c,b));
                  }
 else {
                    output.setValue(y,x,outletID);
                    decrementFlowpath(y,x,contArea.getValue(y,x));
                  }
                  outletID++;
                }
              }
            }
 while (!flag);
          }
        }
 else {
          output.setValue(row,col,noData);
        }
      }
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(100f * row / (rows - 1));
      updateProgress("Loop 1 of 2:",(int)progress);
    }
    for (row=0; row < rows; row++) {
      for (col=0; col < cols; col++) {
        if (output.getValue(row,col) == -999 && pointer.getValue(row,col) != noData) {
          flag=false;
          x=col;
          y=row;
          do {
            flowDir=pointer.getValue(y,x);
            if (flowDir > 0) {
              c=(int)(Math.log(flowDir) / LnOf2);
              x+=dX[c];
              y+=dY[c];
              z=output.getValue(y,x);
              if (z != -999) {
                outletID=z;
                flag=true;
              }
            }
 else {
              outletID=noData;
              flag=true;
            }
          }
 while (!flag);
          flag=false;
          x=col;
          y=row;
          output.setValue(y,x,outletID);
          do {
            flowDir=pointer.getValue(y,x);
            if (flowDir > 0) {
              c=(int)(Math.log(flowDir) / LnOf2);
              x+=dX[c];
              y+=dY[c];
              z=output.getValue(y,x);
              if (z != -999) {
                flag=true;
              }
            }
 else {
              flag=true;
            }
            output.setValue(y,x,outletID);
          }
 while (!flag);
        }
 else         if (pointer.getValue(row,col) == noData) {
          output.setValue(row,col,noData);
        }
      }
      if (cancelOp) {
        cancelOperation();
        return;
      }
      progress=(float)(100f * row / (rows - 1));
      updateProgress("Loop 2 of 2:",(int)progress);
    }
    output.addMetadataEntry("Created by the " + getDescriptiveName() + " tool.");
    output.addMetadataEntry("Created on " + new Date());
    pointer.close();
    contArea.close();
    output.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 ; int row , col , x , y ; float progress = 0 ; double z ; int i , b , c , ICLCA ; boolean flag = false ; double flowDir = 0 ; double outletID = 0 ; double SCAValue ; double maxSCA , d1 , d2 ; if ( args . length <= 0 ) { showFeedback ( "Plugin parameters have not been set." ) ; return ; } String pointerHeader = args [ 0 ] ; String caHeader = args [ 1 ] ; String outputHeader = args [ 2 ] ; double SCAThreshold = Double . parseDouble ( args [ 3 ] ) ; if ( pointerHeader . isEmpty ( ) || caHeader . isEmpty ( ) || outputHeader . isEmpty ( ) ) { showFeedback ( "One or more of the input parameters have not been set properly." ) ; return ; } try { pointer = new WhiteboxRaster ( pointerHeader , "r" ) ; int rows = pointer . getNumberRows ( ) ; int cols = pointer . getNumberColumns ( ) ; double noData = pointer . getNoDataValue ( ) ; String tempFile = caHeader . replace ( ".dep" , "_temp.dep" ) ; FileUtilities . copyFile ( new File ( caHeader ) , new File ( tempFile ) ) ; FileUtilities . copyFile ( new File ( caHeader . replace ( ".dep" , ".tas" ) ) , new File ( tempFile . replace ( ".dep" , ".tas" ) ) ) ; contArea = new WhiteboxRaster ( tempFile , "rw" ) ; contArea . isTemporaryFile = true ; WhiteboxRaster output = new WhiteboxRaster ( outputHeader , "rw" , caHeader , WhiteboxRaster . DataType . FLOAT , - 999 ) ; output . setDataScale ( WhiteboxRasterBase . DataScale . CATEGORICAL ) ; output . setPreferredPalette ( "categorical1.pal" ) ; outletID = 1 ; for ( row = 0 ; row < rows ; row ++ ) { for ( col = 0 ; col < cols ; col ++ ) { if ( pointer . getValue ( row , col ) != noData ) { flag = false ; for ( i = 0 ; i < 8 ; i ++ ) { if ( pointer . getValue ( col + dX [ i ] , row + dY [ i ] ) == inflowingVals [ i ] ) { flag = true ; } } if ( ! flag ) { flag = false ; x = col ; y = row ; do { flowDir = pointer . getValue ( y , x ) ; if ( flowDir > 0 ) { i = ( int ) ( Math . log ( flowDir ) / LnOf2 ) ; x += dX [ i ] ; y += dY [ i ] ; } else { flag = true ; } SCAValue = contArea . getValue ( y , x ) ; if ( SCAValue >= SCAThreshold ) { maxSCA = - 99999 ; ICLCA = 8 ; for ( i = 0 ; i < 8 ; i ++ ) { b = x + dX [ i ] ; c = y + dY [ i ] ; if ( pointer . getValue ( c , b ) == inflowingVals [ i ] ) { z = contArea . getValue ( c , b ) ; if ( z > maxSCA ) { maxSCA = z ; ICLCA = i ; } } } b = x + dX [ ICLCA ] ; c = y + dY [ ICLCA ] ; if ( contArea . getValue ( c , b ) > SCAThreshold ) { flag = true ; } else { d1 = Math . abs ( contArea . getValue ( c , b ) - SCAThreshold ) ; d2 = Math . abs ( contArea . getValue ( y , x ) - SCAThreshold ) ; if ( d1 < d2 ) { output . setValue ( c , b , outletID ) ; decrementFlowpath ( c , b , contArea . getValue ( c , b ) ) ; } else { output . setValue ( y , x , outletID ) ; decrementFlowpath ( y , x , contArea . getValue ( y , x ) ) ; } outletID ++ ; } } } while ( ! flag ) ; } } else { output . setValue ( row , col , noData ) ; } } if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 100f * row / ( rows - 1 ) ) ; updateProgress ( "Loop 1 of 2:" , ( int ) progress ) ; } for ( row = 0 ; row < rows ; row ++ ) { for ( col = 0 ; col < cols ; col ++ ) { if ( output . getValue ( row , col ) == - 999 && pointer . getValue ( row , col ) != noData ) { flag = false ; x = col ; y = row ; do { flowDir = pointer . getValue ( y , x ) ; if ( flowDir > 0 ) { c = ( int ) ( Math . log ( flowDir ) / LnOf2 ) ; x += dX [ c ] ; y += dY [ c ] ; z = output . getValue ( y , x ) ; if ( z != - 999 ) { outletID = z ; flag = true ; } } else { outletID = noData ; flag = true ; } } while ( ! flag ) ; flag = false ; x = col ; y = row ; output . setValue ( y , x , outletID ) ; do { flowDir = pointer . getValue ( y , x ) ; if ( flowDir > 0 ) { c = ( int ) ( Math . log ( flowDir ) / LnOf2 ) ; x += dX [ c ] ; y += dY [ c ] ; z = output . getValue ( y , x ) ; if ( z != - 999 ) { flag = true ; } } else { flag = true ; } output . setValue ( y , x , outletID ) ; } while ( ! flag ) ; } else if ( pointer . getValue ( row , col ) == noData ) { output . setValue ( row , col , noData ) ; } } if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( float ) ( 100f * row / ( rows - 1 ) ) ; updateProgress ( "Loop 2 of 2:" , ( int ) progress ) ; } output . addMetadataEntry ( "Created by the " + getDescriptiveName ( ) + " tool." ) ; output . addMetadataEntry ( "Created on " + new Date ( ) ) ; pointer . close ( ) ; contArea . close ( ) ; output . 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 .
