V1_0.java [src/java/m/watershed/fill_sinks] 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.fill_sinks;

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

/**
 * Fill sinks
 *
 * @author JK (using OD's template)
 */
@Name("fill_sinks")
@Description("Example of an fill sinks")
@Path("m/fill_sinks/1.0")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "/bin/lin-amd64/pitremove", type = EXECUTABLE, id = "pitremove")

public class V1_0 extends ModelDataService {

    // 2) watershed
    @Override
    protected void doProcess() throws Exception {

        String file1 = parameter().getString("dem");
        File file_obj = attachments().getFile(file1);

        String orig_DEM_path = file_obj.getPath();
        String wd = workspace().getDir().toString();

        //Executable e = resources().getExe("mpirun");
        //File e2 = resources().getFile("pitremove");
        Executable e = resources().getExe("pitremove");
        //e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-z", orig_DEM_path, "-fel", wd + "/dem_fill.tif");        
        e.addArguments("-z", orig_DEM_path, "-fel", wd + "/dem_fill.tif");
        e.exec();
    }

    // 3) provide the result.
    @Override
    protected void postProcess() throws Exception {
        String ip = request().getRemoteAddr();
        File ws = workspace().getDir();
        results().put(new File(ws, "dem_fill.tif"), "Filled DEM");

    }

}