|
[HepData-svn] r1469 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formatsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Aug 9 11:40:38 BST 2011
Author: whalley Date: Tue Aug 9 11:40:38 2011 New Revision: 1469 Log: updates to bdms formatter Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java Tue Aug 9 11:39:17 2011 (r1468) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java Tue Aug 9 11:40:38 2011 (r1469) @@ -5,6 +5,8 @@ import cedar.hepdata.xml.*; import cedar.hepdata.db.*; +import cedar.hepdata.webapp.components.*; + import java.util.*; import org.antlr.stringtemplate.*; @@ -67,6 +69,12 @@ if(ds.getDsPlabString(n) != null){ h.append(ds.getDsPlabString(n) + "\n"); } else{ break; } } + for (DatasetError de : ds.getErrors()){ + h.append("SE = " + de.getPlus()); + if(de.getNormType().toSymbol().equals("%")){h.append(" PCT");} + h.append(";\n"); + h.append("CSE = " + de.getComment() + ";\n"); + } s.append("\n" + h.toString()); int numpoints = ds.getNumPoints(); @@ -167,19 +175,23 @@ 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){ - s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getFocus()); - 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).getLowValue().equals(ds.getXAxis(nx+1).getBin(i+1).getHighValue())){ + if(ds.getXAxis(nx+1).getBin(i+1).getFocus() != null){ + s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getFocus()); + 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).getLowValue().equals(ds.getXAxis(nx+1).getBin(i+1).getHighValue())){ s.append(" (BIN=" + 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().equals(ds.getXAxis(nx+1).getBin(i+1).getHighValue())){ - s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue()); - } else { - s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue()); + 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()); @@ -189,26 +201,68 @@ 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()); } - s.append(" " + yax.getPoint(i+1).getValue()); + if(yax.getPoint(i+1).getRelation() != Relation.EQUALS){ + s.append(" " + yax.getPoint(i+1).getRelation().toString()); + } + String f_val = yax.getPoint(i+1).getValue().toString(); + 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; + } + 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); + } + if(nerr == 1) { - if(err.isSymmetric()){ s.append(" +- " + err.getPlus() + norm); } - else{s.append(" +" + err.getPlus() + norm + ",-" + err.getMinus() + norm);} + 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) { 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(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(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) { s.append(")");} @@ -226,5 +280,4 @@ return s.toString(); } - }
More information about the HepData-svn mailing list |