[HepData-svn] r1897 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Oct 5 18:30:53 BST 2015


Author: watt
Date: Mon Oct  5 18:30:53 2015
New Revision: 1897

Log:
Fixes to YAML formatter when writing dserrors

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Mon Sep 28 22:07:36 2015	(r1896)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java	Mon Oct  5 18:30:53 2015	(r1897)
@@ -426,7 +426,7 @@
                 name=yax.getHeader().substring(0,yax.getHeader().indexOf(" IN ")).trim();
                 unit=yax.getHeader().substring(yax.getHeader().indexOf(" IN ")+4).trim();
             }
-            s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'");
+	    if (npoints > 0) { s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'"); }
             if(!unit.equals("")){ s.append(", units: '"+unit+"'"); }
             s.append("}\n");
             boolean first=true;
@@ -501,17 +501,17 @@
             }
 
             for(Uncertainty error : ds.getErrors()){
-                if(error.getPlus()==0.0){
+                if(error.getPlus()==0.0 && npoints > 0){
                     s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n");
                 }
             }
             for(Uncertainty error : yax.getErrors()){
-                if(error.getPlus()==0.0){
+                if(error.getPlus()==0.0 && npoints > 0){
                     s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n");
                 }
             }
 
-            s.append(s4+"values:\n");
+            if (npoints > 0) { s.append(s4+"values:\n"); }
 
             for (int ip=1; ip<npoints+1; ip++){
                 Point point = yax.getPoint(ip);
@@ -540,8 +540,12 @@
 			s.append("'");
 		    }
 		    s.append("\n");
+		    if (point.getErrors().size() > 0
+			|| yax.getErrors().size() > 0
+			|| ds.getErrors().size() > 0) {
+			s.append(s4+s4+"errors:\n");
+		    }
 		    if(point.getErrors().size()>0){
-                        s.append(s4+s4+"errors:\n");
                         for(Uncertainty error : point.getErrors()){
 			    s.append(_formatError(error,"point"));
 			}


More information about the HepData-svn mailing list