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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed May 7 15:29:46 BST 2014


Author: whalley
Date: Wed May  7 15:29:46 2014
New Revision: 1796

Log:
fix to input formatter to output spicifc tables only

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

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java	Tue Apr 29 14:33:27 2014	(r1795)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/InputFormatter.java	Wed May  7 15:29:46 2014	(r1796)
@@ -14,335 +14,321 @@
 
 
 public class InputFormatter {
+    public static String format(Collection<Dataset> ds, Paper p) {
+         StringBuffer s = new StringBuffer();
+         if(p!=null){	    
+             s.append("*author: " + p.getAuthors().first() + "\n");
+             for (Reference ref : p.getReferences()){
+                  s.append("*reference: "+ref.getDescription()+" : "+ref.getDate()+"\n");
+            }
+	
+	        if (p.getDOI() != null) {
+	            s.append("*doi: "+p.getDOI()+"\n");
+	        }
 
-    public static String format(Paper p) {
-        if(p == null) return null;
-	StringBuffer s = new StringBuffer();
-	s.append("*author: " + p.getAuthors().first() + "\n");
+            for (Modification mod : p.getModifications()){
+                s.append("*status: Encoded "+mod.getComment()+" by "+mod.getModifier()+"\n");
+            }
 
-        for (Reference ref : p.getReferences()){
-            s.append("*reference: "+ref.getDescription()+" : "+ref.getDate()+"\n");
-        }
-	
-	if (p.getDOI() != null) {
-	    s.append("*doi: "+p.getDOI()+"\n");
-	}
+            for (Experiment exp : p.getExperiments()){
+               s.append("*experiment: "+exp.getName()+"\n");
+               s.append("*detector: "+exp.getInformalName()+"\n");
+            }
+            if(p.getSpiresId()!=null) s.append("*spiresId: " + p.getSpiresId() + "\n");
+            if(p.getInspireId()!=null) s.append("*inspireId: " + p.getInspireId() + "\n");
+	        if(p.getCdsId()!=null) s.append("*cdsId: " + p.getCdsId() + "\n");
+            if(p.getRedId()!=null) s.append("*durhamId: " + p.getRedId() + "\n");
 
-        for (Modification mod : p.getModifications()){
-            s.append("*status: Encoded "+mod.getComment()+" by "+mod.getModifier()+"\n");
+            if(p.getTitle()!=null) {
+	            s.append("*title: "+p.getTitle()+"\n");
+            }
+            for (String comment : p.getComments()){
+                comment=comment.replaceAll("\\\\n","\\\\\\\\n");
+                s.append("*comment: "+comment+"\n");
+             }
+         }
+         for (Dataset d : ds) {
+            String dstr = InputFormatter.format(d);
+            if (dstr != null) s.append(dstr);
         }
+        return s.toString();
+    }
 
-        for (Experiment exp : p.getExperiments()){
-            s.append("*experiment: "+exp.getName()+"\n");
-            s.append("*detector: "+exp.getInformalName()+"\n");
+    public static String format(Dataset ds) {
+	    StringBuffer s = new StringBuffer();
+        s.append("\n*dataset:"+"\n");
+        if(ds.getTfpString() != null){ 
+            s.append(ds.getTfpString().replace("TFP = L","*l").replace(";","").replace(": ",": ") + "\n"); 
         }
-        if(p.getSpiresId()!=null) s.append("*spiresId: " + p.getSpiresId() + "\n");
-        if(p.getInspireId()!=null) s.append("*inspireId: " + p.getInspireId() + "\n");
-	if(p.getCdsId()!=null) s.append("*cdsId: " + p.getCdsId() + "\n");
-        if(p.getRedId()!=null) s.append("*durhamId: " + p.getRedId() + "\n");
-
-        if(p.getTitle()!=null) {
-	    s.append("*title: "+p.getTitle()+"\n");
+        for (String comment : ds.getComments()){
+            if(!comment.startsWith("Location")){
+                comment=comment.replaceAll("\\\\n","\\\\\\\\n");
+                s.append("*dscomment: "+comment+"\n");
+            }    
         }
-        for (String comment : p.getComments()){
-            comment=comment.replaceAll("\\\\n","\\\\\\\\n");
-           s.append("*comment: "+comment+"\n");
+        for (String re : ds.getDsReactions()){
+            s.append("*reackey: "+re+"\n");
+        }
+        for (String obs : ds.getDsObservables()){
+            s.append("*obskey: "+obs+"\n");
+        }
+        for (String plab : ds.getDsPlabs()){
+            s.append("*plabkey: "+plab+"\n");
+        }
+        for (DatasetError de : ds.getErrors()){
+            s.append("*dserror: " + de.getPlus());
+            if(de.getNormType().toSymbol().equals("%")){s.append(" PCT");}
+            s.append(" : " + de.getComment());
+		    s.append("\n");
         }
-
-
-
-        for (Dataset ds : p.getDatasets()){
-        
-            s.append("\n*dataset:"+"\n");
-            if(ds.getTfpString() != null){ 
-                s.append(ds.getTfpString().replace("TFP = L","*l").replace(";","").replace(": ",": ") + "\n"); 
-            }
-            for (String comment : ds.getComments()){
-                if(!comment.startsWith("Location")){
-                    comment=comment.replaceAll("\\\\n","\\\\\\\\n");
-                    s.append("*dscomment: "+comment+"\n");
-                }    
-            }
-            for (String re : ds.getDsReactions()){
-                s.append("*reackey: "+re+"\n");
-            }
-            for (String obs : ds.getDsObservables()){
-                s.append("*obskey: "+obs+"\n");
-            }
-            for (String plab : ds.getDsPlabs()){
-                s.append("*plabkey: "+plab+"\n");
-            }
-        
-            // for (DatasetError de : ds.getErrors()){
-            //     s.append("*Error: " + de.getPlus());
-            //     if(de.getNormType().toSymbol().equals("%")){s.append(" PCT");}
-            //     s.append(";\n");
-            //     s.append("ErrorComment: " + de.getComment() + ";\n");
-            // }
-            for (DatasetError de : ds.getErrors()){
-                s.append("*dserror: " + de.getPlus());
-                if(de.getNormType().toSymbol().equals("%")){s.append(" PCT");}
-                s.append(" : " + de.getComment());
-		s.append("\n");
-            }
        
 
-            int numpoints = ds.getNumPoints(); 
-            int idmax = ds.getMaxPointId();             
-            int nyax = ds.getYAxes().size();
-            int nxax = ds.getXAxes().size();
-            
-	    //   s.append("\nThis dataset has "+nxax+" x axes and "+nyax+" y axes with "+numpoints+" points\n");
-            if(nyax > 0 && nxax > 0) {
-                int nycomm = ds.getYAxis(1).getComments().size();
-                int nyprop = ds.getYAxis(1).getProperties().size();;
+        int numpoints = ds.getNumPoints(); 
+        int idmax = ds.getMaxPointId();             
+        int nyax = ds.getYAxes().size();
+        int nxax = ds.getXAxes().size();
+
+        if(nyax > 0 && nxax > 0) {
+            int nycomm = ds.getYAxis(1).getComments().size();
+            int nyprop = ds.getYAxis(1).getProperties().size();;
 
-                for ( Property prop : ds.getYAxis(1).getProperties()){
-                    if(prop.getName().startsWith("sqrts")){ nyprop--; }
-                }
+            for ( Property prop : ds.getYAxis(1).getProperties()){
+                if(prop.getName().startsWith("sqrts")){ nyprop--; }
+            }
                 
                
-                for (Property prop : ds.getProperties()){
-                    s.append("*dsqual: "+prop.getName()+" :");
-                    if(prop.getLowValue().equals(prop.getHighValue())){
-                        s.append(" "+prop.getLowValue());  
-                    } else{
-                        s.append(" "+prop.getLowValue()+" - "+prop.getHighValue());
-                    }
-                    if(!prop.getUnit().toString().equals("")){
-                        s.append(" : "+prop.getUnit().toString());
-                    } 
-                    s.append("\n");
+            for (Property prop : ds.getProperties()){
+                s.append("*dsqual: "+prop.getName()+" :");
+                if(prop.getLowValue().equals(prop.getHighValue())){
+                    s.append(" "+prop.getLowValue());  
+                } else{
+                    s.append(" "+prop.getLowValue()+" - "+prop.getHighValue());
+                }
+                if(!prop.getUnit().toString().equals("")){
+                    s.append(" : "+prop.getUnit().toString());
                 } 
-                String[][] store = new String[nyax][nycomm+nyprop+1];
-                int nyhead=0;
-                for (int n=0; n<nyax; n++){
-                    List <String> storelist = new ArrayList();
+                s.append("\n");
+            } 
+            String[][] store = new String[nyax][nycomm+nyprop+1];
+            int nyhead=0;
+            for (int n=0; n<nyax; n++){
+                List <String> storelist = new ArrayList();
                     
-                    YAxis yax = ds.getYAxis(n+1);
-                    String yheader = "";
-                    if(yax.getHeader() != null){ 
-                        yheader = yax.getHeader(); 
-                        storelist.add("*yheader: " + yheader);
-                        nyhead=1;
-                    }
+                YAxis yax = ds.getYAxis(n+1);
+                String yheader = "";
+                if(yax.getHeader() != null){ 
+                    yheader = yax.getHeader(); 
+                    storelist.add("*yheader: " + yheader);
+                    nyhead=1;
+                }
                 
-		    for (String comm : yax.getComments()){
-			if(comm.contains(":")){
-			    StringBuffer tempbuff = new StringBuffer();
-			    String left = comm.split("\\s*:\\s*")[0];
-			    String right = comm.split("\\s*:\\s*")[1];
-			    tempbuff.append("*qual: " + left + " : " + right);
-			    storelist.add(tempbuff.toString());
-			} else{
-			    nycomm =- 1;
-			}
-                    }
-                    for (Property prop : yax.getProperties()){
-                        if(!prop.getName().startsWith("sqrts")){
-                     	    StringBuffer tempbuff = new StringBuffer();
-                            tempbuff.append("*qual: " + prop.getName().trim());
-                            if(!prop.getUnit().toString().equals("num")) { tempbuff.append(" IN " + prop.getUnit().toString().toUpperCase()); } 
-                            if(prop.getLowValue().equals(prop.getHighValue())){
-                                tempbuff.append(" : " + prop.getLowValue());
-                            } else{
-                                tempbuff.append(" : " + prop.getLowValue() + " TO " + prop.getHighValue());
-                            } 
-                            storelist.add(tempbuff.toString());
-                        }    
-                    }
-                    Collections.sort(storelist);
-                    for (int i=0; i<storelist.size(); i++){
-                        store[n][i]=storelist.get(i);
-                    }
+    		    for (String comm : yax.getComments()){
+	        		if(comm.contains(":")){
+			            StringBuffer tempbuff = new StringBuffer();
+			            String left = comm.split("\\s*:\\s*")[0];
+			            String right = comm.split("\\s*:\\s*")[1];
+			            tempbuff.append("*qual: " + left + " : " + right);
+			            storelist.add(tempbuff.toString());
+			       } else{
+			           nycomm =- 1;
+			       }
+               }
+               for (Property prop : yax.getProperties()){
+                   if(!prop.getName().startsWith("sqrts")){
+                       StringBuffer tempbuff = new StringBuffer();
+                       tempbuff.append("*qual: " + prop.getName().trim());
+                       if(!prop.getUnit().toString().equals("num")) { tempbuff.append(" IN " + prop.getUnit().toString().toUpperCase()); } 
+                       if(prop.getLowValue().equals(prop.getHighValue())){
+                           tempbuff.append(" : " + prop.getLowValue());
+                       } else{
+                           tempbuff.append(" : " + prop.getLowValue() + " TO " + prop.getHighValue());
+                       } 
+                       storelist.add(tempbuff.toString());
+                   }    
+               }
+               Collections.sort(storelist);
+               for (int i=0; i<storelist.size(); i++){
+                   store[n][i]=storelist.get(i);
                 }
+            }
 		//                 // now check each property etc. for repetition across yaxes (very simple case first)
-                for (int i=0; i<nyprop+nycomm+nyhead; i++){
-                    Boolean same = true;
-                    if(nyax > 1){
-                        for (int ny=0; ny<nyax-1; ny++){
-			    if(!store[ny][i].equals(store[ny+1][i])) { same = false; }
-                        }
+            for (int i=0; i<nyprop+nycomm+nyhead; i++){
+                Boolean same = true;
+                if(nyax > 1){
+                    for (int ny=0; ny<nyax-1; ny++){
+			            if(!store[ny][i].equals(store[ny+1][i])) { same = false; }
                     }
-                    if(same) { 
-                        s.append(store[0][i]+"\n"); 
-                    }
-                    else{
-                        s.append(store[0][i]);
-                        for(int ny=1; ny<nyax; ny++){
-			    String right = store[ny][i].split("\\s*\\:\\s")[1];
-			    if(!store[0][i].startsWith("*yheader")) {right = store[ny][i].split("\\s*\\:\\s")[2];}
-                            s.append(" : "+right);
-                        }
-                        s.append("\n");
+                }
+                if(same) { 
+                    s.append(store[0][i]+"\n"); 
+                }
+                else{
+                    s.append(store[0][i]);
+                    for(int ny=1; ny<nyax; ny++){
+			            String right = store[ny][i].split("\\s*\\:\\s")[1];
+			            if(!store[0][i].startsWith("*yheader")) {right = store[ny][i].split("\\s*\\:\\s")[2];}
+                        s.append(" : "+right);
                     }
+                    s.append("\n");
                 }
+            }
                 
                              
-                s.append("*xheader");
-                for(XAxis xax : ds.getXAxes()){
-                    s.append(": " + xax.getHeader() + " ");
-                }
-                s.append("\n");
-                s.append("*data");
-                for(XAxis xax : ds.getXAxes()){
-		    s.append(": x ");
-                }
-                for(YAxis yx : ds.getYAxes()){
-		    s.append(": y ");
-                }     
-                s.append("\n");
+            s.append("*xheader");
+            for(XAxis xax : ds.getXAxes()){
+                s.append(": " + xax.getHeader() + " ");
+            }
+            s.append("\n");
+            s.append("*data");
+            for(XAxis xax : ds.getXAxes()){
+		        s.append(": x ");
+            }
+            for(YAxis yx : ds.getYAxes()){
+		        s.append(": y ");
+            }     
+            s.append("\n");
                 
-                for (int i=0; i<numpoints; i++){
+            for (int i=0; i<numpoints; i++){
 		    ///////////////////////// x axes/////////////////////////////////
-                    for( int nx=0;  nx<ds.getXAxes().size(); nx++){
-                        try{
-                            if(ds.getXAxis(nx+1).getBin(i+1).getRelation() != Relation.EQUALS){ 
-                                s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getRelation().toString()); 
-                            }
-                            if(ds.getXAxis(nx+1).getBin(i+1).getFocus() != null){
-				SignificantFigures focusx = new SignificantFigures(ds.getXAxis(nx+1).getBin(i+1).getFocus());
-				int lsd = focusx.getLSD();
-				int msd = focusx.getMSD();
-				if(msd == 0) msd = 1;                                    
-				if(ds.getXAxis(nx+1).getBin(i+1).getFocusLength() != null){
-				    lsd = -ds.getXAxis(nx+1).getBin(i+1).getFocusLength();
-				}  
-				String foc = Formats.forms(ds.getXAxis(nx+1).getBin(i+1).getFocus(),msd,-lsd);
-				boolean asymmfocus = false;
-				if (ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null && ds.getXAxis(nx+1).getBin(i+1).getFocus() != null) {
-				    double diff = ds.getXAxis(nx+1).getBin(i+1).getFocus() - (ds.getXAxis(nx+1).getBin(i+1).getLowValue() + ds.getXAxis(nx+1).getBin(i+1).getHighValue()) / 2.0;
-				    if (Math.abs(diff/ds.getXAxis(nx+1).getBin(i+1).getFocus()) > 1E-6) {
-					asymmfocus = true;
-				    }
-				}
-				boolean haswidth = false;
-				if (ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null) {
-				    double diff = ds.getXAxis(nx+1).getBin(i+1).getHighValue() - ds.getXAxis(nx+1).getBin(i+1).getLowValue();
-				    double mean = (ds.getXAxis(nx+1).getBin(i+1).getLowValue() + ds.getXAxis(nx+1).getBin(i+1).getHighValue()) / 2.0;
-				    if((Math.abs(diff/mean) > 1E-6) || (mean == 0.0 && Math.abs(diff) > 1E-6)){
-					haswidth = true;
-				    }
-				}
-				if (asymmfocus && haswidth) {
-				    s.append(" " + foc + " (BIN=" + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue() + ")");
-				} else if (!haswidth || ds.getXAxis(nx+1).getBin(i+1).getLowValue() == null || ds.getXAxis(nx+1).getBin(i+1).getHighValue() == null) {
-				    s.append(" " + foc);
-			        } else {
-				    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue());
-				}
-                            } else {
-                                if(ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue()==null){
-                                    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue());                   
-                                }
-                                else if(ds.getXAxis(nx+1).getBin(i+1).getLowValue() == null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null){
-                                    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getHighValue());                   
-                                }
-                                else{
-                                    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
-                                }
-			    }
-                        } catch(Exception e){
-			    s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
+                for( int nx=0;  nx<ds.getXAxes().size(); nx++){
+                    try{
+                        if(ds.getXAxis(nx+1).getBin(i+1).getRelation() != Relation.EQUALS){ 
+                            s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getRelation().toString()); 
                         }
-                        s.append(";");                   
+                        if(ds.getXAxis(nx+1).getBin(i+1).getFocus() != null){
+				            SignificantFigures focusx = new SignificantFigures(ds.getXAxis(nx+1).getBin(i+1).getFocus());
+				            int lsd = focusx.getLSD();
+				            int msd = focusx.getMSD();
+				            if(msd == 0) msd = 1;                                    
+				            if(ds.getXAxis(nx+1).getBin(i+1).getFocusLength() != null){
+				                lsd = -ds.getXAxis(nx+1).getBin(i+1).getFocusLength();
+				            }  
+				            String foc = Formats.forms(ds.getXAxis(nx+1).getBin(i+1).getFocus(),msd,-lsd);
+				            boolean asymmfocus = false;
+				            if (ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null && ds.getXAxis(nx+1).getBin(i+1).getFocus() != null) {
+				                double diff = ds.getXAxis(nx+1).getBin(i+1).getFocus() - (ds.getXAxis(nx+1).getBin(i+1).getLowValue() + ds.getXAxis(nx+1).getBin(i+1).getHighValue()) / 2.0;
+				                if (Math.abs(diff/ds.getXAxis(nx+1).getBin(i+1).getFocus()) > 1E-6) {
+					                asymmfocus = true;
+				                }               
+			                }
+				            boolean haswidth = false;
+				            if (ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null) {
+				                double diff = ds.getXAxis(nx+1).getBin(i+1).getHighValue() - ds.getXAxis(nx+1).getBin(i+1).getLowValue();
+				                double mean = (ds.getXAxis(nx+1).getBin(i+1).getLowValue() + ds.getXAxis(nx+1).getBin(i+1).getHighValue()) / 2.0;
+				                if((Math.abs(diff/mean) > 1E-6) || (mean == 0.0 && Math.abs(diff) > 1E-6)){
+					                haswidth = true;
+				                }
+				            }
+				            if (asymmfocus && haswidth) {
+				                s.append(" " + foc + " (BIN=" + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue() + ")");
+				            } else if (!haswidth || ds.getXAxis(nx+1).getBin(i+1).getLowValue() == null || ds.getXAxis(nx+1).getBin(i+1).getHighValue() == null) {
+				                s.append(" " + foc);
+			                } else {
+				                s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue());
+				            }
+                        } else {
+                            if(ds.getXAxis(nx+1).getBin(i+1).getLowValue() != null && ds.getXAxis(nx+1).getBin(i+1).getHighValue()==null){
+                                s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue());                   
+                            }
+                            else if(ds.getXAxis(nx+1).getBin(i+1).getLowValue() == null && ds.getXAxis(nx+1).getBin(i+1).getHighValue() != null){
+                                s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getHighValue());                   
+                            }
+                            else{
+                                s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
+                            }
+			            }
+                    } catch(Exception e){
+			            s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription());
                     }
+                    s.append(";");                   
+                }
 		    ////////////////////////////y-axes///////////////////////////////////////////
-                    for (int n=0; n<nyax; n++){
-                        YAxis yax = ds.getYAxis(n+1);
-                        try{
-			    if(yax.getPoint(i+1).getRelation() != Relation.EQUALS){ 
-				s.append(" " + yax.getPoint(i+1).getRelation().toString()); 
-			    }
-			    String f_desc = yax.getPoint(i+1).getDescription();
-			    String f_val = yax.getPoint(i+1).getValue().toString();
-			    if (f_desc != null) {
-				s.append(" " + f_desc);
-			    }
-			    else {
-				if(yax.getPoint(i+1).getValueLength() != null) {
-				    int lsd = yax.getPoint(i+1).getValueLength();
-				    int msd = 0;
-				    if(lsd > 0){
-					msd = f_val.indexOf(".");
-				    }  else{
-					msd = f_val.length() - 2;
-				    }
-				    if (yax.getPoint(i+1).getValue() < 0) { msd -= 1; }
-				    f_val = Formats.forms(yax.getPoint(i+1).getValue(),msd,lsd);
-				}
-				if(f_val.contains("E-")){
-				    int lsd = Integer.parseInt(f_val.substring(f_val.indexOf("E")+2));
-				    int ldiff = f_val.length() + lsd;
-				    f_val = Formats.forms(yax.getPoint(i+1).getValue(),1,ldiff-5);
-				}
-				s.append(" " + f_val);
-				// s.append(" " + yax.getPoint(i+1).getValue());
-			    }
-                            int nerr=0;
-                            for(Uncertainty err : yax.getPoint(i+1).getErrors()){
-                                nerr++;
-                                String norm = "";
-                                if(err.getNormType() == ErrorNorm.PCT){  norm = " PCT"; } 
-                                String f_plus = err.getPlus().toString();
-                                if(f_plus.contains("E-")){
-                                    int lsd = Integer.parseInt(f_plus.substring(f_plus.indexOf("E")+2));
-                                    int ldiff = f_plus.length() + lsd;
-                                    f_plus = Formats.forms(err.getPlus(),1,ldiff-5);
-				}
-                                String f_minus = err.getMinus().toString();
-                                if(f_minus.contains("E-")){
-                                    int lsd = Integer.parseInt(f_minus.substring(f_minus.indexOf("E")+2));
-                                    int ldiff = f_minus.length() + lsd;
-                                    f_minus = Formats.forms(err.getMinus(),1,ldiff-5);
-				}
+                for (int n=0; n<nyax; n++){
+                    YAxis yax = ds.getYAxis(n+1);
+                    try{
+			            if(yax.getPoint(i+1).getRelation() != Relation.EQUALS){ 
+				            s.append(" " + yax.getPoint(i+1).getRelation().toString()); 
+			            }
+			            String f_desc = yax.getPoint(i+1).getDescription();
+			            String f_val = yax.getPoint(i+1).getValue().toString();
+			            if (f_desc != null) {
+				            s.append(" " + f_desc);
+			            }
+			            else {
+				            if(yax.getPoint(i+1).getValueLength() != null) {
+				                int lsd = yax.getPoint(i+1).getValueLength();
+				                int msd = 0;
+				                if(lsd > 0){
+					                 msd = f_val.indexOf(".");
+				                }  else{
+					                msd = f_val.length() - 2;
+				                }
+				                if (yax.getPoint(i+1).getValue() < 0) { msd -= 1; }
+				                f_val = Formats.forms(yax.getPoint(i+1).getValue(),msd,lsd);
+				           }
+				           if(f_val.contains("E-")){
+				              int lsd = Integer.parseInt(f_val.substring(f_val.indexOf("E")+2));
+				              int ldiff = f_val.length() + lsd;
+				              f_val = Formats.forms(yax.getPoint(i+1).getValue(),1,ldiff-5);
+				           }
+				           s.append(" " + f_val);
+			            }
+                        int nerr=0;
+                        for(Uncertainty err : yax.getPoint(i+1).getErrors()){
+                            nerr++;
+                            String norm = "";
+                            if(err.getNormType() == ErrorNorm.PCT){  norm = " PCT"; } 
+                            String f_plus = err.getPlus().toString();
+                            if(f_plus.contains("E-")){
+                                int lsd = Integer.parseInt(f_plus.substring(f_plus.indexOf("E")+2));
+                                int ldiff = f_plus.length() + lsd;
+                                f_plus = Formats.forms(err.getPlus(),1,ldiff-5);
+				            }
+                            String f_minus = err.getMinus().toString();
+                            if(f_minus.contains("E-")){
+                                int lsd = Integer.parseInt(f_minus.substring(f_minus.indexOf("E")+2));
+                                int ldiff = f_minus.length() + lsd;
+                                f_minus = Formats.forms(err.getMinus(),1,ldiff-5);
+				            }
                                 
-                                if(nerr == 1) {
-                                    if(err.isSymmetric()){ 
-					//                                        s.append(" +- " + err.getPlus() + norm); 
-                                        s.append(" +- " + f_plus + norm); 
-                                    }
-                                    else{
-					//                                        s.append(" +" + err.getPlus() + norm + ",-" + err.getMinus() + norm);
-                                        s.append(" +" + f_plus + norm + ",-" + f_minus + norm);
-                                    }
-                                }
-                                else if(nerr == 2) {
-				    if (err.getSourceType() == ErrorSource.STAT) {
-					s.append(" (STAT=");
-				    }
-				    else {
-					s.append(" (DSYS=");
-				    }
-				    //                                    if(err.isSymmetric()) {s.append(err.getPlus() + norm);}
-				    //                                    else{s.append("+" + err.getPlus() + norm + ",-" + err.getMinus() + norm);}
-                                    if(err.isSymmetric()) {s.append(f_plus + norm);}
-                                    else{s.append("+" + f_plus + norm + ",-" + f_minus + norm);}
-                                } 
-                                else { 
-                                    s.append(",DSYS=");
-				    //                                    if(err.isSymmetric()) {s.append(err.getPlus() + norm);}
-				    //                                    else{s.append("+" + err.getPlus() + norm + ",-" + err.getMinus() + norm);}
-                                    if(err.isSymmetric()) {s.append(f_plus + norm);}
-                                    else{s.append("+" + f_plus + norm + ",-" + f_minus + norm);}
+                            if(nerr == 1) {
+                                if(err.isSymmetric()){ 
+                                    s.append(" +- " + f_plus + norm); 
                                 }
-                                if(err.getComment() != null && !err.getComment().equals("")) {
-                                    s.append(":" + err.getComment());
+                                else{
+                                    s.append(" +" + f_plus + norm + ",-" + f_minus + norm);
                                 }
                             }
-                            if(nerr > 1) { s.append(")");}
+                            else if(nerr == 2) {
+				                if (err.getSourceType() == ErrorSource.STAT) {
+				                	s.append(" (STAT=");
+				                }
+				                else {
+				                	s.append(" (DSYS=");
+				                }
+                                if(err.isSymmetric()) {s.append(f_plus + norm);}
+                                else{s.append("+" + f_plus + norm + ",-" + f_minus + norm);}
+                            } 
+                            else { 
+                                s.append(",DSYS=");
+                                if(err.isSymmetric()) {s.append(f_plus + norm);}
+                                else{s.append("+" + f_plus + norm + ",-" + f_minus + norm);}
+                            }
+                            if(err.getComment() != null && !err.getComment().equals("")) {
+                               s.append(":" + err.getComment());
+                            }
                         }
-                        catch(Exception e){ s.append(" - "); }
-                        s.append(";");
+                        if(nerr > 1) { s.append(")");}
                     }
-                    s.append("\n");
+                    catch(Exception e){ s.append(" - "); }
+                    s.append(";");
                 }
-                s.append("*dataend:\n");
+                    s.append("\n");
             }
-    	} 
-
-        s.append("*E\n");
+            s.append("*dataend:\n");
+        }
         return s.toString();
+ 
     }
 
 }


More information about the HepData-svn mailing list