Skip to content

Commit

Permalink
fixes & log
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrichet committed Oct 4, 2021
1 parent 460f709 commit 76956f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/funz/Telemac/TelemacCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public TelemacOutReader(TelemacLauncher l) {
protected int runCommand() throws Exception {
int ret = super.runCommand();
if (ret != 0) {
System.err.println("Failed to run Telemac !");
return ret;
}

Expand Down Expand Up @@ -76,7 +77,8 @@ protected int runCommand() throws Exception {
if (pois.isEmpty()) {
System.err.println("Could not find .poi file !");
return ret;
}
} else
System.err.println("Will read poi: "+pois);

if (TelemacHelper.writeCSVfromCASRES(cas, pois)) {
File resfile = new File(cas.getAbsoluteFile().getParentFile(), TelemacHelper.readFichiersDe(cas, "RESULT")[0]);
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/funz/Telemac/TelemacHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class TelemacHelper {
RES_VAR.put("BOTTOM", "B");
RES_VAR.put("FROUDE", "F");
RES_VAR.put("DEBIT SCALAIRE", "Q");
RES_VAR.put("SCALAR FLOWRATE", "Q");
RES_VAR.put("DEBIT SUIVANT X", "I");
RES_VAR.put("DEBIT SUIVANT Y", "J");
RES_VAR.put("FROTTEMENT", "W");
Expand Down Expand Up @@ -144,9 +146,10 @@ static Map<String, double[][]> extractPOIfromRES(File res, Properties poi) throw

for (int vi = 0; vi < s.getVariables().length; vi++) {
String v = s.getVariables()[vi];
//System.err.println("Reading " + v + " at:");
//System.err.println("> Reading " + v + " at:");
for (String p : poi.stringPropertyNames()) {
//System.err.println(p);
try {
//System.err.println("> "+p);
if (poi.getProperty(p).contains(",") && poi.getProperty(p).contains(":")) { // so, this is a x0,y0:nx,ny:x1,y1 zone poi
String cs = poi.get(p).toString();
String cs0 = cs.substring(0, cs.indexOf(":"));
Expand Down Expand Up @@ -186,7 +189,7 @@ static Map<String, double[][]> extractPOIfromRES(File res, Properties poi) throw
}
}
dat.put(RES_VAR.get(v) + "_" + p, d);
dat.put(p+"_xy", xy);
dat.put("xy_" + p, xy);

} else if (poi.getProperty(p).contains(",")) { // so, this is a x,y poi, to get containing cell results
double[] d = new double[s.getPasDeTemps().length];
Expand Down Expand Up @@ -216,6 +219,11 @@ static Map<String, double[][]> extractPOIfromRES(File res, Properties poi) throw
}
dat.put(RES_VAR.get(v) + "_" + p, new double[][]{d});
}
}catch (Exception e) {
System.err.println("Failed to read " + v + " at: "+p+" :");
e.printStackTrace();
dat.put(RES_VAR.get(v) + "_" + p, new double[][]{});
}
}
}

Expand Down Expand Up @@ -309,6 +317,7 @@ static void write(File f, String s) {
}*/

static String printDoubleArray2D(double[][] d) {
if (d==null || d.length==0) return null;
Object[] o = new Object[d[0].length];
for (int i = 0; i < o.length; i++) {
Object[] oi = new Object[d.length];
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/funz/Telemac/TelemacIOPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -140,7 +142,10 @@ public boolean accept(File pathname) {

pois.putAll(m);
} catch (Exception ex) {
ex.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
lout.put("error","Could not read poi file "+file.getName()+" : "+sw.toString());
}
}
}
Expand All @@ -157,15 +162,21 @@ public boolean accept(File pathname) {

lout.putAll(TelemacHelper.extractPOIfromCASRES(cas, pois));
} catch (Exception e) {
lout.put("error","Could not read coord "+pois+" in results of cas "+cas.getName()+" : "+e.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
lout.put("error","Could not read coord "+pois+" in results of cas "+cas.getName()+" : "+sw.toString());
}
}

for (File f : csvfiles) {
try {
lout.put(f.getName().substring(0, f.getName().indexOf(".csv")), readDoubleArray2D(FileUtils.readFileToString(f)));
} catch (IOException ex) {
lout.put("error","Could not read file "+f.getName()+" : "+ex.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
lout.put("error","Could not read csv file "+f.getName()+" : "+sw.toString());
}
}

Expand Down

0 comments on commit 76956f7

Please sign in to comment.