diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java @ 8877:9f7a285b0ee3

Some work on SINFO FlowDepth
author gernotbelger
date Thu, 08 Feb 2018 18:48:24 +0100
parents 1009cab0f86b
children 64ca63f79f6f
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java	Thu Feb 08 18:47:36 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthExporter.java	Thu Feb 08 18:48:24 2018 +0100
@@ -17,6 +17,7 @@
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.common.utils.Config;
@@ -44,7 +45,7 @@
 // REMARK: must be public because its registered in generators.xml
 public class FlowDepthExporter extends AbstractExporter {
 
-    /** The log used in this exporter.*/
+    /** The log used in this exporter. */
     private static Logger log = Logger.getLogger(FlowDepthExporter.class);
 
     private static final String CSV_KM_HEADER = "sinfo.export.flow_depth.csv.header.km";
@@ -59,52 +60,58 @@
     private static final String CSV_MEAN_BED_HEIGHT_HEADER_SHORT = "sinfo.export.flow_depth.csv.header.mean_bed_height.short";
     private static final String CSV_SOUNDING_HEADER = "sinfo.export.flow_depth.csv.header.sounding";
     private static final String CSV_LOCATION_HEADER = "sinfo.export.flow_depth.csv.header.location";
-    
-    private static final String CSV_META_HEADER_RESULT =
-        "sinfo.export.flow_depth.csv.meta.header.result";
-
-    private static final String CSV_META_HEADER_RESULT_LABEL =
-            "sinfo.export.flow_depth.csv.meta.header.result.label";
-    
-    private static final String CSV_META_VERSION =
-    		"sinfo.export.flow_depth.csv.meta.version";
-
-    private static final String CSV_META_VERSION_LABEL =
-            "sinfo.export.flow_depth.csv.meta.version.label";
-    
-    private static final String CSV_META_USER =
-    		"sinfo.export.flow_depth.csv.meta.user";
-    
-    private static final String CSV_META_USER_LABEL =
-            "sinfo.export.flow_depth.csv.meta.user.label";
-    
-    private static final String CSV_META_CREATION =
-        "sinfo.export.flow_depth.csv.meta.creation";
 
-    private static final String CSV_META_CREATION_LABEL =
-            "sinfo.export.flow_depth.csv.meta.creation.label";
-    
-    private static final String CSV_META_RIVER =
-        "sinfo.export.flow_depth.csv.meta.river";
-
-    private static final String CSV_META_RIVER_LABEL =
-            "sinfo.export.flow_depth.csv.meta.river.label";
-    
-    private static final String CSV_META_HEADER_SOUNDING =
-    		"sinfo.export.flow_depth.csv.meta.header.sounding";
+    private static final String CSV_META_HEADER_RESULT = "sinfo.export.flow_depth.csv.meta.header.result";
 
-    private static final String CSV_META_HEADER_WATERLEVEL =
-    		"sinfo.export.flow_depth.csv.meta.header.waterlevel";
-
-    private static final String CSV_META_RANGE =
-            "sinfo.export.flow_depth.csv.meta.range";
+    private static final String CSV_META_HEADER_RESULT_LABEL = "sinfo.export.flow_depth.csv.meta.header.result.label";
 
-    private static final String CSV_META_RANGE_LABEL =
-            "sinfo.export.flow_depth.csv.meta.range.label";
-    
+    private static final String CSV_META_VERSION = "sinfo.export.flow_depth.csv.meta.version";
+
+    private static final String CSV_META_VERSION_LABEL = "sinfo.export.flow_depth.csv.meta.version.label";
+
+    private static final String CSV_META_USER = "sinfo.export.flow_depth.csv.meta.user";
+
+    private static final String CSV_META_USER_LABEL = "sinfo.export.flow_depth.csv.meta.user.label";
+
+    private static final String CSV_META_CREATION = "sinfo.export.flow_depth.csv.meta.creation";
+
+    private static final String CSV_META_CREATION_LABEL = "sinfo.export.flow_depth.csv.meta.creation.label";
+
+    private static final String CSV_META_RIVER = "sinfo.export.flow_depth.csv.meta.river";
+
+    private static final String CSV_META_RIVER_LABEL = "sinfo.export.flow_depth.csv.meta.river.label";
+
+    private static final String CSV_META_HEADER_SOUNDING = "sinfo.export.flow_depth.csv.meta.header.sounding";
+
+    private static final String CSV_META_HEADER_SOUNDING_YEAR = "sinfo.export.flow_depth.csv.meta.header.sounding.year";
+
+    private static final String CSV_META_HEADER_SOUNDING_TYPE = "sinfo.export.flow_depth.csv.meta.header.sounding.type";
+
+    private static final String CSV_META_HEADER_SOUNDING_PRJ = "sinfo.export.flow_depth.csv.meta.header.sounding.prj";
+
+    private static final String CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL = "sinfo.export.flow_depth.csv.meta.header.sounding.elevationmodel";
+
+    private static final String CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL_ORIGINAL = "sinfo.export.flow_depth.csv.meta.header.sounding.elevationmodel.original";
+
+    private static final String CSV_META_HEADER_WATERLEVEL = "sinfo.export.flow_depth.csv.meta.header.waterlevel";
+
+    private static final String CSV_META_HEADER_WATERLEVEL_NAME = "sinfo.export.flow_depth.csv.meta.header.waterlevel.name";
+
+    private static final String CSV_META_HEADER_WATERLEVEL_ELEVATION_MODEL = "sinfo.export.flow_depth.csv.meta.header.waterlevel.elevationmodel";
+
+    private static final String CSV_META_HEADER_WATERLEVEL_EVALUATOR = "sinfo.export.flow_depth.csv.meta.header.waterlevel.evaluator";
+
+    private static final String CSV_META_HEADER_WATERLEVEL_GAUGE = "sinfo.export.flow_depth.csv.meta.header.waterlevel.gauge";
+
+    private static final String CSV_META_HEADER_WATERLEVEL_YEAR = "sinfo.export.flow_depth.csv.meta.header.waterlevel.year";
+
+    private static final String CSV_META_RANGE = "sinfo.export.flow_depth.csv.meta.range";
+
+    private static final String CSV_META_RANGE_LABEL = "sinfo.export.flow_depth.csv.meta.range.label";
+
     private static final String CSV_META_HEIGHT_UNIT_RIVER = "sinfo.export.flow_depth.csv.meta.height_unit.river";
-    
-    private static final String JASPER_FILE     = "/jasper/sinfo.flowdepth.jasper";
+
+    private static final String JASPER_FILE = "/jasper/sinfo.flowdepth.jasper";
 
     private static final String UNIT_M = "m";
 
@@ -112,37 +119,37 @@
 
     private static final String UNIT_CUBIC_M = "m³/s";
 
-    /** The storage that contains the current calculation result.*/
+    /** The storage that contains the current calculation result. */
     private FlowDepthCalculationResults data = null;
 
-	/**
-	 * Formats header with unit
-	 */
-	private String msgUnit(final String key, String unit ) {
-	    
-	    final String msg = msg(key);
-	    return String.format("%s [%s]", msg, unit);
+    /**
+     * Formats header with unit
+     */
+    private String msgUnit(final String key, final String unit) {
+
+        final String msg = msg(key);
+        return String.format("%s [%s]", msg, unit);
     }
-    
+
     @Override
-    protected void addData(Object d) {
-    	/* reset */
-    	data = null;
+    protected void addData(final Object d) {
+        /* reset */
+        this.data = null;
 
         if (d instanceof CalculationResult) {
 
-        	final Object dat = ((CalculationResult)d).getData();
-        	if( dat != null )
-        		data = (FlowDepthCalculationResults)dat;
+            final Object dat = ((CalculationResult) d).getData();
+            if (dat != null)
+                this.data = (FlowDepthCalculationResults) dat;
         }
     }
-    
+
     @Override
-    protected void writeCSVData(CSVWriter writer) {
+    protected void writeCSVData(final CSVWriter writer) {
         log.info("FlowDepthExporter.writeCSVData");
 
         /* fetch calculation results */
-        final FlowDepthCalculationResults results = data;
+        final FlowDepthCalculationResults results = this.data;
 
         final boolean useTkh = results.isUseTkh();
         final River river = results.getRiver();
@@ -152,116 +159,115 @@
         writeCSVHeader(writer, river, useTkh);
 
         for (final FlowDepthCalculationResult result : results.getResults()) {
-        	writeCSVFlowDepthResult(writer, result, useTkh);
-		}
+            writeCSVFlowDepthResult(writer, result, useTkh);
+        }
     }
 
-    private void writeCSVFlowDepthResult(final CSVWriter writer, final FlowDepthCalculationResult result, final boolean useTkh) {
+    private void writeCSVFlowDepthResult(final CSVWriter writer, final FlowDepthCalculationResult result,
+            final boolean useTkh) {
+
+        /* first some specific metadata */
+        final BedHeightInfo sounding = result.getSounding();
+        final WstInfo wst = result.getWst();
+
+        // "##METADATEN PEILUNG"
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING);
+
+        // "# Jahr der Peilung: "
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_YEAR, Integer.toString(sounding.getYear()));
+        // "# Aufnahmeart: "
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_TYPE, sounding.getType());
+        // "# Lagesystem: "
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_PRJ, sounding.getLocationSystem());
+        // "# Höhensystem: "
+        // TODO: klären einheit oder name des höhensystems?
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL, sounding.getCurElevationModelName());
+        // "# ursprüngliches Höhensystem: "
+        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING_ELEVATIOIN_MODEL_ORIGINAL,
+                sounding.getOldElevationModelName());
+
+        // "##METADATEN WASSERSPIEGELLAGE"
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL);
+        // "# Bezeichnung der Wasserspiegellage: "
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_NAME, wst.getLabel());
+        // "# Höhensystem der Wasserspiegellage: "
+        // FIXME: discussion!
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_ELEVATION_MODEL, "FIXME");
+        // "# Auswerter: ": discussion!
+        // FIXME: discussion!
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_EVALUATOR, "FIXME");
+        // "# Bezugspegel: " discussion
+        // FIXME: Umsetzung IDENTISCH zu allen möglichen Arten wie ein WSPL berechnet wird....
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_GAUGE, "FIXME");
+        // "# Jahr/Zeitraum der Wasserspiegellage: "
+        // FIXME: discussion!
+        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL_YEAR, Integer.toString(wst.getYear()));
+
+        /* nwo the value rows */
         final Collection<FlowDepthRow> rows = result.getRows();
         for (final FlowDepthRow flowDepthRow : rows) {
-        	writeCSVFlowDepthRow(writer, flowDepthRow, useTkh);
-		}
-	}
+            writeCSVFlowDepthRow(writer, flowDepthRow, useTkh);
+        }
+    }
 
-	private void writeCSVMeta(final CSVWriter writer, final FlowDepthCalculationResults results) {
+    private void writeCSVMeta(final CSVWriter writer, final FlowDepthCalculationResults results) {
         log.info("FlowDepthExporter.writeCSVMeta");
 
         final String calcModeLabel = results.getCalcModeLabel();
         final River river = results.getRiver();
-        writeCSVMetaEntry(writer, CSV_META_HEADER_RESULT, msg( CSV_META_HEADER_RESULT_LABEL ), river.getName(), calcModeLabel );
+        writeCSVMetaEntry(writer, CSV_META_HEADER_RESULT, msg(CSV_META_HEADER_RESULT_LABEL), river.getName(),
+                calcModeLabel);
 
-		// "# FLYS-Version: "
-        writeCSVMetaEntry(writer, CSV_META_VERSION, msg( CSV_META_VERSION_LABEL ), FLYS.VERSION );
+        // "# FLYS-Version: "
+        writeCSVMetaEntry(writer, CSV_META_VERSION, msg(CSV_META_VERSION_LABEL), FLYS.VERSION);
 
-		// "# Bearbeiter: "
-        writeCSVMetaEntry(writer, CSV_META_USER, msg( CSV_META_USER_LABEL ), results.getUser() );
+        // "# Bearbeiter: "
+        writeCSVMetaEntry(writer, CSV_META_USER, msg(CSV_META_USER_LABEL), results.getUser());
 
         // "# Datum der Erstellung: "
-        final Locale locale = Resources.getLocale(context.getMeta());
+        final Locale locale = Resources.getLocale(this.context.getMeta());
         final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
-        writeCSVMetaEntry(writer, CSV_META_CREATION, msg( CSV_META_CREATION_LABEL ), df.format(new Date()) );
+        writeCSVMetaEntry(writer, CSV_META_CREATION, msg(CSV_META_CREATION_LABEL), df.format(new Date()));
 
         // "# Gewässer: "
-        writeCSVMetaEntry(writer, CSV_META_RIVER, msg( CSV_META_RIVER_LABEL ), river.getName() );
+        writeCSVMetaEntry(writer, CSV_META_RIVER, msg(CSV_META_RIVER_LABEL), river.getName());
 
         // "# Höhensystem des Flusses: "
+        // FIXME: klären, was ist gemeint?
         final Unit wstUnit = river.getWstUnit();
         writeCSVMetaEntry(writer, CSV_META_HEIGHT_UNIT_RIVER, wstUnit.getName());
 
         // "# Ort/Bereich (km): "
-        writeCSVMetaEntry(writer, CSV_META_RANGE, msg( CSV_META_RANGE_LABEL ), getKmFormatter().format(results.getFrom() ), getKmFormatter().format( results.getTo()));
-
-        // "##METADATEN PEILUNG"
-        writeCSVMetaEntry(writer, CSV_META_HEADER_SOUNDING );
-
-        // FIXME: check: macht nicht viel sinn da es mehrere geben kann.. oder immer wieder wiederholen?
-//        "# Jahr der Peilung: "
-        // FIXME
-//        "# Aufnahmeart: "
-        // FIXME
-//        "# Lagesystem: "
-        // FIXME
-//        "# Höhensystem: "
-        // FIXME
-//        "# ursprüngliches Höhensystem: "
-        // FIXME
-//        "##METADATEN WASSERSPIEGELLAGE"
-        writeCSVMetaEntry(writer, CSV_META_HEADER_WATERLEVEL );
-//        "# Bezeichnung der Wasserspiegellage: "
-        // FIXME
-//        "# Höhensystem der Wasserspiegellage: "
-        // FIXME
-//        "# Auswerter: "
-        // FIXME
-//        "# Bezugspegel: "
-        // FIXME
-//        "# Jahr/Zeitraum der Wasserspiegellage: "
-        // FIXME
-
-        // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel)
-        // TODO: unklar, es wird kein W eingegeben
-
-        // "# Q (m³/s): " (nur bei Eingabe des Durchflusses)        
-        // TODO: unklar, es wird kein Q eingegeben
+        writeCSVMetaEntry(writer, CSV_META_RANGE, msg(CSV_META_RANGE_LABEL), getKmFormatter().format(results.getFrom()),
+                getKmFormatter().format(results.getTo()));
 
         writer.writeNext(new String[] { "" });
     }
 
-
-    private void writeCSVMetaEntry(CSVWriter writer, String message, Object... messageArgs) {
-
-        CallMeta meta = context.getMeta();
+    private void writeCSVMetaEntry(final CSVWriter writer, final String message, final Object... messageArgs) {
 
-        writer.writeNext(new String[] {
-                Resources.getMsg(
-                    meta,
-                    message,
-                    message,
-                    messageArgs)
-            });		
+        final CallMeta meta = this.context.getMeta();
+
+        writer.writeNext(new String[] { Resources.getMsg(meta, message, message, messageArgs) });
     }
-    
-	/**
+
+    /**
      * Write the header, with different headings depending on whether at a
      * gauge or at a location.
-	 * @param river 
-	 * @param useTkh 
+     *
+     * @param river
+     * @param useTkh
      */
-    private void writeCSVHeader(
-        final CSVWriter writer,
-        final River river, 
-        final boolean useTkh
-    ) {
+    private void writeCSVHeader(final CSVWriter writer, final River river, final boolean useTkh) {
         log.info("FlowDepthExporter.writeCSVHeader");
 
         final Collection<String> header = new ArrayList<>(11);
-        
+
         header.add(msg(CSV_KM_HEADER));
         header.add(msgUnit(CSV_FLOWDEPTH_HEADER, UNIT_M));
-        if( useTkh )
-        {
-        	header.add(msgUnit(CSV_FLOWDEPTHTKH_HEADER, UNIT_M));
-        	header.add(msgUnit(CSV_TKH_HEADER, UNIT_CM));
+        if (useTkh) {
+            header.add(msgUnit(CSV_FLOWDEPTHTKH_HEADER, UNIT_M));
+            header.add(msgUnit(CSV_TKH_HEADER, UNIT_CM));
         }
 
         final String wstUnitName = river.getWstUnit().getName();
@@ -273,138 +279,136 @@
         header.add(msg(CSV_SOUNDING_HEADER));
         header.add(msg(CSV_LOCATION_HEADER));
 
-       writer.writeNext(header.toArray(new String[header.size()]));
+        writer.writeNext(header.toArray(new String[header.size()]));
     }
 
     /**
      * Format a row of a flow depth result into an array of string, both used by csv and pdf
-     * @param useTkh 
+     *
+     * @param useTkh
      */
-    private String[] formatFlowDepthRow(
-    		final FlowDepthRow row, 
-    		boolean useTkh ) {
+    private String[] formatFlowDepthRow(final FlowDepthRow row, final boolean useTkh) {
 
-    	final Collection<String> lines = new ArrayList<>(11);
-    	
-    	// Fluss-km
-    	lines.add( getKmFormatter().format( row.getStation() ) );
-    	
-    	// Fließtiefe [m]
-    	lines.add( getFlowDepthFormatter().format( row.getFlowDepth() ) );
-    	
-    	if( useTkh )
-    	{
-    		// Fließtiefe mit TKH [m]
-    		lines.add( getFlowDepthFormatter().format( row.getFlowDepthWithTkh() ) );
-    		
-    		// TKH [cm]
-    		lines.add( getTkhFormatter().format( row.getTkh() ) );
-    	}
-    	
-    	// Wasserstand [NN + m]
-    	lines.add( getW2Formatter().format( row.getWaterlevel() ) );
-    	
-    	// Q [m³/s]
-    	lines.add( getQFormatter().format( row.getDischarge() ) );
-    	
-    	// Bezeichnung
-    	lines.add( row.getWaterlevelLabel() );
-    	
-    	// Bezugspegel
-    	lines.add( row.getGauge() );
-    	
-    	// Mittlere Sohlhöhe [NN + m]
-    	lines.add( getMeanBedHeighFormatter().format( row.getMeanBedHeight( ) ) );
-    	
-    	// Peilung/Epoche
-    	lines.add( row.getSoundageLabel() );
+        final Collection<String> lines = new ArrayList<>(11);
 
-    	// Lage
-    	lines.add( row.getLocation() );
-    	
-    	return lines.toArray(new String[lines.size()]);
+        // Fluss-km
+        lines.add(getKmFormatter().format(row.getStation()));
+
+        // Fließtiefe [m]
+        lines.add(getFlowDepthFormatter().format(row.getFlowDepth()));
+
+        if (useTkh) {
+            // Fließtiefe mit TKH [m]
+            lines.add(getFlowDepthFormatter().format(row.getFlowDepthWithTkh()));
+
+            // TKH [cm]
+            lines.add(getTkhFormatter().format(row.getTkh()));
+        }
+
+        // Wasserstand [NN + m]
+        lines.add(getW2Formatter().format(row.getWaterlevel()));
+
+        // Q [m³/s]
+        final double discharge = row.getDischarge();
+        if( Double.isNaN(discharge))
+            lines.add(StringUtils.EMPTY);
+        else
+            lines.add(getQFormatter().format(discharge));
+
+        // Bezeichnung
+        lines.add(row.getWaterlevelLabel());
+
+        // Bezugspegel
+        lines.add(row.getGauge());
+
+        // Mittlere Sohlhöhe [NN + m]
+        lines.add(getMeanBedHeighFormatter().format(row.getMeanBedHeight()));
+
+        // Peilung/Epoche
+        lines.add(row.getSoundageLabel());
+
+        // Lage
+        lines.add(row.getLocation());
+
+        return lines.toArray(new String[lines.size()]);
     }
+
     /**
      * Write "rows" of csv data from wqkms with writer.
-     * @param useTkh 
+     *
+     * @param useTkh
      */
-    private void writeCSVFlowDepthRow(
-        final CSVWriter writer,
-        final FlowDepthRow row, 
-        final boolean useTkh
-    ) {
+    private void writeCSVFlowDepthRow(final CSVWriter writer, final FlowDepthRow row, final boolean useTkh) {
         log.debug("FlowDepthExporter.writeCSVFlowDepthRow");
 
         final String[] formattedRow = formatFlowDepthRow(row, useTkh);
-        writer.writeNext( formattedRow );
+        writer.writeNext(formattedRow);
     }
 
-	@Override
-    protected void writePDF(OutputStream outStream) {
+    @Override
+    protected void writePDF(final OutputStream outStream) {
         log.debug("write PDF");
-        
+
         final JRDataSource source = createJRData();
 
         final String confPath = Config.getConfigDirectory().toString();
 
-        // FIXME: distinguish between with and without tkh: we need two jasper reports! 
+        // FIXME: distinguish between with and without tkh: we need two jasper reports!
 
-        final Map<String,Object> parameters = new HashMap<>();
+        final Map<String, Object> parameters = new HashMap<>();
         parameters.put("ReportTitle", "Exported Data");
         try {
-            final JasperPrint print = JasperFillManager.fillReport(
-                confPath + JASPER_FILE,
-                parameters,
-                source);
+            final JasperPrint print = JasperFillManager.fillReport(confPath + JASPER_FILE, parameters, source);
             JasperExportManager.exportReportToPdfStream(print, outStream);
         }
-        catch(JRException je) {
+        catch (final JRException je) {
             log.warn("Error generating PDF Report!", je);
         }
     }
 
     private JRDataSource createJRData() {
-    	
+
         /* fetch calculation results */
-        final FlowDepthCalculationResults results = data;
-    	
-    	final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource();
-    	
+        final FlowDepthCalculationResults results = this.data;
+
+        final MetaAndTableJRDataSource source = new MetaAndTableJRDataSource();
+
         addJRMetaData(source, results);
 
         final boolean useTkh = results.isUseTkh();
-        
+
         for (final FlowDepthCalculationResult result : results.getResults()) {
-			addJRTableData(source, result, useTkh);
-		}
+            addJRTableData(source, result, useTkh);
+        }
 
         return source;
     }
 
-	private void addJRMetaData(final MetaAndTableJRDataSource source, FlowDepthCalculationResults results) {
-
-	    final River river = results.getRiver();
-	    final String wstUnitName = river.getWstUnit().getName();
+    private void addJRMetaData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResults results) {
 
-	    /* general metadata */
-	    source.addMetaData("header", msg(CSV_META_HEADER_RESULT_LABEL));
-	    source.addMetaData("calcMode", results.getCalcModeLabel());
+        final River river = results.getRiver();
+        final String wstUnitName = river.getWstUnit().getName();
 
-	    source.addMetaData("version_label", msg(CSV_META_VERSION_LABEL));
+        /* general metadata */
+        source.addMetaData("header", msg(CSV_META_HEADER_RESULT_LABEL));
+        source.addMetaData("calcMode", results.getCalcModeLabel());
+
+        source.addMetaData("version_label", msg(CSV_META_VERSION_LABEL));
         source.addMetaData("version", FLYS.VERSION);
 
         source.addMetaData("user_label", msg(CSV_META_USER_LABEL));
         source.addMetaData("user", results.getUser());
-        
-        final Locale locale = Resources.getLocale(context.getMeta());
+
+        final Locale locale = Resources.getLocale(this.context.getMeta());
         final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
         source.addMetaData("date_label", msg(CSV_META_CREATION_LABEL));
         source.addMetaData("date", df.format(new Date()));
 
-        source.addMetaData("river_label", msg(CSV_META_RIVER_LABEL) );
+        source.addMetaData("river_label", msg(CSV_META_RIVER_LABEL));
         source.addMetaData("river", river.getName());
 
-        final String rangeValue = String.format( "%s - %s", getKmFormatter().format(results.getFrom() ), getKmFormatter().format( results.getTo()));
+        final String rangeValue = String.format("%s - %s", getKmFormatter().format(results.getFrom()),
+                getKmFormatter().format(results.getTo()));
         source.addMetaData("range_label", msg(CSV_META_RANGE_LABEL));
         source.addMetaData("range", rangeValue);
 
@@ -423,14 +427,15 @@
         source.addMetaData("location_header", msg(CSV_LOCATION_HEADER));
     }
 
-    private void addJRTableData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResult result, final boolean useTkh) {
-    	
-    	final Collection<FlowDepthRow> rows = result.getRows();
+    private void addJRTableData(final MetaAndTableJRDataSource source, final FlowDepthCalculationResult result,
+            final boolean useTkh) {
 
-    	for (final FlowDepthRow row : rows) {
-    		
-    		final String[] formattedRow = formatFlowDepthRow(row, useTkh);
-    		source.addData(formattedRow);
-		}
-	}
-}
\ No newline at end of file
+        final Collection<FlowDepthRow> rows = result.getRows();
+
+        for (final FlowDepthRow row : rows) {
+
+            final String[] formattedRow = formatFlowDepthRow(row, useTkh);
+            source.addData(formattedRow);
+        }
+    }
+}

http://dive4elements.wald.intevation.org