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

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;

/**
 * Grid_analysis
 *
 * @author JK (using OD's template)
 */
@Name("grid_analysis")
@Description("Example of grid analysis")
@Path("m/grid_analysis/1.0")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "/bin/lin-amd64/gridnet", type = EXECUTABLE, id = "gridnet")

public class V1_0 extends ModelDataService {

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

        String file1 = parameter().getString("flow_8_dir");
        File file_obj = attachments().getFile(file1);
        String flow_8dir_path = file_obj.getPath();
        String wd = workspace().getDir().toString();

        //Executable e = resources().getExe("mpirun");
        //File e2 = resources().getFile("gridnet");
        Executable e = resources().getExe("gridnet");
        //e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-p", flow_8dir_path, "-plen", wd + "/plen.tif", "-tlen", wd + "/tlen.tif", "-gord", wd + "/gord.tif");        
        e.addArguments("-p", flow_8dir_path, "-plen", wd + "/plen.tif", "-tlen", wd + "/tlen.tif", "-gord", wd + "/gord.tif");
        e.exec();
    }

    // 3) provide the result.
    @Override
    protected void postProcess() throws Exception {
        File ws = workspace().getDir();
        results().put(new File(ws, "plen.tif"), "Longest flow path");
        results().put(new File(ws, "tlen.tif"), "Total lengths of flow path");
        results().put(new File(ws, "gord.tif"), "Grid network order");
    }
}