V1_0.java [src/java/m/watershed/stream_raster] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.watershed.stream_raster;

import csip.ModelDataService;
import javax.ws.rs.Path;
import csip.annotations.*;
import java.io.*;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.*;
import csip.api.server.Executable;

/**
 * Stream Raster Threshold
 *
 * @author JK (using OD's template)
 */
@Name("stream_raster")
@Description("Example of stream raster threshold")
@Path("m/stream_raster/1.0")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "/bin/lin-amd64/threshold", type = EXECUTABLE, id = "threshold")

public class V1_0 extends ModelDataService {

    // 2) watershed
    @Override
    protected void doProcess() throws Exception {
        String ip = request().getRemoteAddr();

        String file1 = parameter().getString("w_flow_acc");
        File file_1 = attachments().getFile(file1);
        String acc_str_path = file_1.getPath();

        String thr = parameter().getString("threshold");
        String wd = workspace().getDir().toString();

        //Executable e = resources().getExe("mpirun");
        //File e2 = resources().getFile("threshold");
        Executable e = resources().getExe("threshold");
        //e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-ssa", acc_str_path, "-src", wd + "/src.tif", "-thresh", thr);        
        e.addArguments("-ssa", acc_str_path, "-src", wd + "/src.tif", "-thresh", thr);
        e.exec();
    }

    // 3) provide the temperature as a result.
    @Override
    protected void postProcess() throws Exception {
        File ws = workspace().getDir();
        results().put(new File(ws, "src.tif"), "Threshold stream raster");

    }

}