Revision: 20159 http://sourceforge.net/p/jmol/code/20159 Author: hansonr Date: 2014-12-09 13:05:53 +0000 (Tue, 09 Dec 2014) Log Message: ----------- Jmol.___JmolVersion="14.3.11_2014.12.09"
bug fix: array.add("\t",array) broken 2014.12.04 bug fix: array.split("",true) doesn't handle CSV with new lines in quotes Modified Paths: -------------- trunk/Jmol/src/javajs/util/PT.java trunk/Jmol/src/org/jmol/script/ScriptEval.java trunk/Jmol/src/org/jmol/scriptext/CmdExt.java trunk/Jmol/src/org/jmol/scriptext/MathExt.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/javajs/util/PT.java =================================================================== --- trunk/Jmol/src/javajs/util/PT.java 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/javajs/util/PT.java 2014-12-09 13:05:53 UTC (rev 20159) @@ -573,6 +573,7 @@ * * @param line * @param next int[2] filled with [ptrQuote1, ptrAfterQuote2] + * next[1] will be -1 if unmatched quotes are found (continuation on next line) * @return unescaped string or null */ public static String getCSVString(String line, int[] next) { @@ -590,8 +591,10 @@ haveEscape = true; i++; } - if (i >= len) + if (i >= len) { + next[1] = -1; return null; // unmatched + } next[1] = i + 1; String s = line.substring(pt + 1, i); return (haveEscape ? rep(rep(s, "\"\"", "\0"), "\0","\"") : s); Modified: trunk/Jmol/src/org/jmol/script/ScriptEval.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEval.java 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/org/jmol/script/ScriptEval.java 2014-12-09 13:05:53 UTC (rev 20159) @@ -5028,6 +5028,8 @@ } boolean isPlay = false; boolean isRange = false; + String propName = null; + Object prop = null; boolean isAll = false; boolean isHyphen = false; int[] frameList = new int[] { -1, -1 }; @@ -5105,6 +5107,11 @@ case T.range: isRange = true; break; + case T.property: + propName = stringParameter(3); + prop = (isArrayParameter(4) ? stringParameterSet(4) : paramAsStr(4)); + i = slen; + break; default: frameControl(offset); return; @@ -5131,6 +5138,7 @@ frameList[i] %= 1000000; int modelIndex = vwr.ms.getModelNumberIndex(frameList[0], useModelNumber, false); + int modelIndex2 = -1; if (haveFileSet && modelIndex < 0 && frameList[0] != 0) { // may have frame 2.0 or frame 2 meaning the range of models in file 2 @@ -5166,6 +5174,11 @@ } } + if (propName != null) { + if (modelIndex < 0) + return; + vwr.ms.setInfo(modelIndex, propName, prop); + } if (!isPlay && !isRange || modelIndex >= 0) vwr.setCurrentModelIndexClear(modelIndex, false); if (isPlay && nFrames == 2 || isRange || isHyphen) { Modified: trunk/Jmol/src/org/jmol/scriptext/CmdExt.java =================================================================== --- trunk/Jmol/src/org/jmol/scriptext/CmdExt.java 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/org/jmol/scriptext/CmdExt.java 2014-12-09 13:05:53 UTC (rev 20159) @@ -96,8 +96,6 @@ protected T[] st; protected int slen; - private Object[] lastData; - final static int ERROR_invalidArgument = 22; public CmdExt() { @@ -1619,7 +1617,7 @@ dataString.trim()); return; } - Object[] d = lastData = new Object[4]; + Object[] d = new Object[4]; // not saving this data in the state? if (dataType.equals("element_vdw")) { // vdw for now @@ -3600,7 +3598,6 @@ } break; case T.symop: - String type; int iop = 0; P3 pt1 = null, pt2 = null; @@ -3611,7 +3608,7 @@ // show symop 3 "fmatrix" iop = (tokAt(2) == T.integer ? intParameter(2) : 0); } - type = (tokAt(eval.iToken + 1) == T.string ? stringParameter(++eval.iToken) + String type = (tokAt(eval.iToken + 1) == T.string ? stringParameter(++eval.iToken) : null); checkLength(len = ++eval.iToken); if (!chk) @@ -3826,9 +3823,9 @@ msg = vwr.stm.getSavedStructure(shape); break; case T.data: - type = ((len = slen) == 3 ? paramAsStr(2) : null); + String dtype = ((len = slen) == 3 ? paramAsStr(2) : null); if (!chk) { - Object[] data = (type == null ? this.lastData : vwr.getData(type)); + Object[] data = vwr.getData(dtype); msg = (data == null ? "no data" : Escape.encapsulateData( (String) data[0], data[1], ((Integer) data[3]).intValue())); } Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java =================================================================== --- trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2014-12-09 13:05:53 UTC (rev 20159) @@ -153,7 +153,7 @@ return evaluateFind(mp, args); case T.format: case T.label: - return evaluateFormat(mp, op.intValue, args, tok == T.format); + return evaluateFormat(mp, op.intValue, args, tok == T.label); case T.function: return evaluateUserFunction(mp, (String) op.value, args, op.intValue, op.tok == T.propselector); @@ -1122,19 +1122,27 @@ asArray)); } - /** - * array.add(x) array.add(sep, x) array.sub(x) array.mul(x) array.mul3(x) - * array.div(x) array.push() array.pop() array.split("") - * array.split("\t",true) - * - * @param mp - * @param tok - * @param args - * @return T/F - * @throws ScriptException - */ private boolean evaluateList(ScriptMathProcessor mp, int tok, SV[] args) throws ScriptException { + // array.add(x) + // array.add(sep, x) + // array.sub(x) + // array.mul(x) + // array.mul3(x) + // array.div(x) + // array.push() + // array.pop() + + // array.join() + // array.join(sep) + // array.join(sep,true) + // array.join("",true) (CSV) + + // array.split() + // array.split(sep) + // array.split("\t",true) + // array.split("",true) (CSV) + int len = args.length; SV x1 = mp.getX(); boolean isArray1 = (x1.tok == T.varray); @@ -1160,94 +1168,103 @@ String[] sList1 = null, sList2 = null, sList3 = null; if (len == 2) { - // [...].add("\t", [...]) - // [...].split("\t", true) [split individual elements as strings] - // [...].split("", true) [CSV split] - // [...][...].join("x", true) [2D-array line join] - // [...][...].join("", true) [CSV join] - int itab = (args[0].tok == T.string ? 0 : 1); - String tab = SV.sValue(args[itab]); - if (len == 2) { - Lst<SV> l = x1.getList(); - boolean isCSV = (tab.length() == 0); - if (isCSV) - tab = ","; - if (tok == T.join) { - SV[] s2 = new SV[l.size()]; - for (int i = l.size(); --i >= 0;) { - Lst<SV> a = l.get(i).getList(); - if (a == null) - s2[i] = l.get(i); - else { - SB sb = new SB(); - for (int j = 0, n = a.size(); j < n; j++) { - if (j > 0) - sb.append(tab); - SV sv = a.get(j); - sb.append(isCSV && sv.tok == T.string ? "\"" + PT.rep( - (String) sv.value, "\"", "\"\"") + "\"" - : "" + sv.asString()); - } - s2[i] = SV.newS(sb.toString()); + // special add, join, split + String tab = SV.sValue(args[0]); + x2 = args[1]; + if (tok == T.add) { + // [...].add("\t", [...]) + sList1 = (isArray1 ? SV.strListValue(x1) : PT + .split(SV.sValue(x1), "\n")); + sList2 = (x2.tok == T.varray ? SV.strListValue(x2) : PT.split( + SV.sValue(x2), "\n")); + sList3 = new String[len = Math.max(sList1.length, sList2.length)]; + for (int i = 0; i < len; i++) + sList3[i] = (i >= sList1.length ? "" : sList1[i]) + tab + + (i >= sList2.length ? "" : sList2[i]); + return mp.addXAS(sList3); + } + if (x2.tok != T.on) + return false; // second parameter must be "true" for now. + Lst<SV> l = x1.getList(); + boolean isCSV = (tab.length() == 0); + if (isCSV) + tab = ","; + if (tok == T.join) { + // [...][...].join(sep, true) [2D-array line join] + // [...][...].join("", true) [CSV join] + SV[] s2 = new SV[l.size()]; + for (int i = l.size(); --i >= 0;) { + Lst<SV> a = l.get(i).getList(); + if (a == null) + s2[i] = l.get(i); + else { + SB sb = new SB(); + for (int j = 0, n = a.size(); j < n; j++) { + if (j > 0) + sb.append(tab); + SV sv = a.get(j); + sb.append(isCSV && sv.tok == T.string ? "\"" + + PT.rep((String) sv.value, "\"", "\"\"") + "\"" : "" + + sv.asString()); } + s2[i] = SV.newS(sb.toString()); } - return mp.addXAV(s2); } - SV[] sa = new SV[l.size()]; - if (isCSV) - tab = "\0"; - int[] next = new int[2]; - for (int i = l.size(); --i >= 0;) { - String line = l.get(i).asString(); - if (isCSV) { - next[1] = 0; - next[0] = 0; - int last = 0; - while (true) { - String s = PT.getCSVString(line, next); - if (s == null) { - line = line.substring(0, last) - + line.substring(last).replace(',', '\0'); - break; + return mp.addXAV(s2); + } + // [...].split(sep, true) [split individual elements as strings] + // [...].split("", true) [CSV split] + Lst<SV> sa = new Lst<SV>(); + if (isCSV) + tab = "\0"; + int[] next = new int[2]; + for (int i = 0, nl = l.size(); i < nl; i++) { + String line = l.get(i).asString(); + if (isCSV) { + next[1] = 0; + next[0] = 0; + int last = 0; + while (true) { + String s = PT.getCSVString(line, next); + if (s == null) { + if (next[1] == -1) { + // unmatched -- continue with next line if present + // or just close quotes gracefully + line += (++i < nl ? "\n" + l.get(i).asString() : "\""); + next[1] = last; + continue; } line = line.substring(0, last) - + line.substring(last, next[0]).replace(',', '\0') + s - + line.substring(next[1]); - next[1] = last = next[0] + s.length(); + + line.substring(last).replace(',', '\0'); + break; } + line = line.substring(0, last) + + line.substring(last, next[0]).replace(',', '\0') + s + + line.substring(next[1]); + next[1] = last = next[0] + s.length(); } - String[] linaa = line.split(tab); - Lst<SV> la = new Lst<SV>(); - for (int j = 0, n = linaa.length; j < n; j++) { - String s = linaa[j]; - if (s.indexOf(".") < 0) - try { - la.addLast(SV.newI(Integer.parseInt(s))); - continue; - } catch (Exception e) { - } - else - try { - la.addLast(SV.getVariable(Float.valueOf(Float.parseFloat(s)))); - continue; - } catch (Exception ee) { - } - la.addLast(SV.newS(s)); - } - sa[i] = SV.getVariableList(la); } - return mp.addXObj(SV.getVariable(sa)); + String[] linaa = line.split(tab); + Lst<SV> la = new Lst<SV>(); + for (int j = 0, n = linaa.length; j < n; j++) { + String s = linaa[j]; + if (s.indexOf(".") < 0) + try { + la.addLast(SV.newI(Integer.parseInt(s))); + continue; + } catch (Exception e) { + } + else + try { + la.addLast(SV.getVariable(Float.valueOf(Float.parseFloat(s)))); + continue; + } catch (Exception ee) { + } + la.addLast(SV.newS(s)); + } + sa.addLast(SV.getVariableList(la)); } - - sList1 = (isArray1 ? SV.strListValue(x1) : PT.split(SV.sValue(x1), "\n")); - x2 = args[1 - itab]; - sList2 = (x2.tok == T.varray ? SV.strListValue(x2) : PT.split( - SV.sValue(x2), "\n")); - sList3 = new String[len = Math.max(sList1.length, sList2.length)]; - for (int i = 0; i < len; i++) - sList3[i] = (i >= sList1.length ? "" : sList1[i]) + tab - + (i >= sList2.length ? "" : sList2[i]); - return mp.addXAS(sList3); + return mp.addXObj(SV.getVariableList(sa)); } x2 = (len == 0 ? SV.newV(T.all, "all") : args[0]); boolean isAll = (x2.tok == T.all); Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2014-12-09 13:05:53 UTC (rev 20159) @@ -15,8 +15,31 @@ TODO: design and implement sidechain mutation -- MUTATE command ? TODO: remove HTML5 dependency on synchronous file loading (check SCRIPT command for problems) -Jmol.___JmolVersion="14.3.11_2014.12.04" +Jmol.___JmolVersion="14.3.11_2014.12.09" + +bug fix: array.add("\t",array) broken 2014.12.04 +bug fix: array.split("",true) doesn't handle CSV with new lines in quotes + +JmolVersion="14.3.11_2014.12.06" + +new feature: MODEL 1 PROPERTY "xxx" @x + -- adds property to model's auxilliaryInfo + -- if x is an array, then these become atom data accessible via %{...} + -- for example: + x = "1\n2\n3\n".lines + model 1 property "mydata" @x + {model=1}.property_n = {*}.label("%{mydata}") // converts to numbers + + data "myd @x" // similar, but not model-based + label %{myd} + + +bug fix: format() function broken +bug fix: SHOW DATA should be cleared when a file is loaded + +JmolVersion="14.3.11_2014.12.04" + new feature: "....".split("",true) // CSV split of string to array of arrays new feature: [...].split("",true) // CSV split of array to array of arrays new feature: "...".split("\t",true) // tab split of string to array of arrays @@ -33,7 +56,7 @@ x = load("test.csv").split("",true).col(3) //3rd column from CSV -Jmol.___JmolVersion="14.3.11_2014.12.02" +JmolVersion="14.3.11_2014.12.02" bug fix: for (x in yUpperCase) fails bug fix: draw SYMOP fails for incommensurate space groups Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2014-12-05 04:21:46 UTC (rev 20158) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2014-12-09 13:05:53 UTC (rev 20159) @@ -2685,6 +2685,7 @@ chainList.clear(); cm.clear(); definedAtomSets.clear(); + lastData = null; if (dm != null) dm.clear(); setBooleanProperty("legacyjavafloat", false); @@ -3208,15 +3209,17 @@ cm.setPropertyColorRangeData(data, bs); } + private Object[] lastData; + public void setData(String type, Object[] data, int arrayCount, int matchField, int matchFieldColumnCount, int field, int fieldColumnCount) { - getDataManager().setData(type, data, arrayCount, getAtomCount(), matchField, + getDataManager().setData(type, lastData = data, arrayCount, getAtomCount(), matchField, matchFieldColumnCount, field, fieldColumnCount); } public Object[] getData(String type) { - return getDataManager().getData(type); + return (type == null ? lastData : getDataManager().getData(type)); } public float[] getDataFloat(String label) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits