jcampconverter
Advanced tools
Comparing version 2.3.0 to 2.4.3
{ | ||
"name": "jcampconverter", | ||
"version": "2.3.0", | ||
"version": "2.4.3", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "dist/jcampconverter.js", |
{ | ||
"name": "jcampconverter", | ||
"version": "2.3.0", | ||
"version": "2.4.3", | ||
"description": "Parse and convert JCAMP data", | ||
@@ -13,3 +13,5 @@ "main": "./src/index.js", | ||
"build": "cheminfo build --root JcampConverter", | ||
"benchmark": "node benchmark/benchmark.js" | ||
"benchmark": "node benchmark/benchmark.js", | ||
"deopt": "node --trace-opt --trace-deopt --code-comments debug/deoptimize.js > deopt.log", | ||
"hydra": "node --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces --redirect-code-traces-to=code.asm debug/deoptimize.js" | ||
}, | ||
@@ -31,3 +33,3 @@ "repository": { | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"benchmark": "^2.1.0", | ||
"cheminfo-tools": "^1.0.2", | ||
@@ -34,0 +36,0 @@ "mocha": "^2.2.5", |
486
src/index.js
'use strict'; | ||
var parseXYDataRegExp=require('./parseXYData.js'); | ||
function getConverter() { | ||
// the following RegExp can only be used for XYdata, some peakTables have values with a "E-5" ... | ||
var xyDataSplitRegExp = /[,\t \+-]*(?=[^\d,\t \.])|[ \t]+(?=[\d+\.-])/; | ||
var removeCommentRegExp = /\$\$.*/; | ||
var peakTableSplitRegExp = /[,\t ]+/; | ||
var ntuplesSeparator = /[, \t]{1,}/; | ||
var DEBUG = false; | ||
@@ -35,3 +34,3 @@ var GC_MS_FIELDS = ['TIC', '.RIC', 'SCANNUMBER']; | ||
var start = new Date(); | ||
var start = Date.now(); | ||
@@ -56,7 +55,7 @@ var ntuples = {}, | ||
if (result.profiling) result.profiling.push({action: 'Before split to LDRS', time: new Date() - start}); | ||
if (result.profiling) result.profiling.push({action: 'Before split to LDRS', time: Date.now() - start}); | ||
ldrs = jcamp.split(/[\r\n]+##/); | ||
if (result.profiling) result.profiling.push({action: 'Split to LDRS', time: new Date() - start}); | ||
if (result.profiling) result.profiling.push({action: 'Split to LDRS', time: Date.now() - start}); | ||
@@ -221,3 +220,10 @@ if (ldrs[0]) ldrs[0] = ldrs[0].replace(/^[\r\n ]*##/, ''); | ||
if (dataValue.match(/.*\+\+.*/)) { | ||
parseXYData(spectrum, dataValue, result); | ||
if (options.fastParse===false) { | ||
parseXYDataRegExp(spectrum, dataValue, result); | ||
} else { | ||
if (!spectrum.deltaX) { | ||
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1); | ||
} | ||
fastParseXYData(spectrum, dataValue, result); | ||
} | ||
} else { | ||
@@ -244,3 +250,3 @@ parsePeakTable(spectrum, dataValue, result); | ||
if (result.profiling) result.profiling.push({action: 'Finished parsing', time: new Date() - start}); | ||
if (result.profiling) result.profiling.push({action: 'Finished parsing', time: Date.now() - start}); | ||
@@ -265,3 +271,3 @@ if (Object.keys(ntuples).length>0) { | ||
action: 'Finished countour plot calculation', | ||
time: new Date() - start | ||
time: Date.now() - start | ||
}); | ||
@@ -308,3 +314,3 @@ if (!options.keepSpectra) { | ||
action: 'Finished GCMS calculation', | ||
time: new Date() - start | ||
time: Date.now() - start | ||
}); | ||
@@ -314,3 +320,3 @@ } | ||
if (result.profiling) { | ||
result.profiling.push({action: 'Total time', time: new Date() - start}); | ||
result.profiling.push({action: 'Total time', time: Date.now() - start}); | ||
} | ||
@@ -418,151 +424,4 @@ | ||
function parsePeakTable(spectrum, value, result) { | ||
spectrum.isPeaktable=true; | ||
var i, ii, j, jj, values; | ||
var currentData = []; | ||
spectrum.data = [currentData]; | ||
// counts for around 20% of the time | ||
var lines = value.split(/,? *,?[;\r\n]+ */); | ||
var k = 0; | ||
for (i = 1, ii = lines.length; i < ii; i++) { | ||
values = lines[i].trim().replace(removeCommentRegExp, '').split(peakTableSplitRegExp); | ||
if (values.length % 2 === 0) { | ||
for (j = 0, jj = values.length; j < jj; j = j + 2) { | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of parseFloat | ||
currentData[k++] = (parseFloat(values[j]) * spectrum.xFactor); | ||
currentData[k++] = (parseFloat(values[j + 1]) * spectrum.yFactor); | ||
} | ||
} else { | ||
result.logs.push('Format error: ' + values); | ||
} | ||
} | ||
} | ||
function parseXYData(spectrum, value, result) { | ||
// we check if deltaX is defined otherwise we calculate it | ||
if (!spectrum.deltaX) { | ||
spectrum.deltaX = (spectrum.lastX - spectrum.firstX) / (spectrum.nbPoints - 1); | ||
} | ||
spectrum.isXYdata=true; | ||
var currentData = []; | ||
spectrum.data = [currentData]; | ||
var currentX = spectrum.firstX; | ||
var currentY = spectrum.firstY; | ||
var lines = value.split(/[\r\n]+/); | ||
var lastDif, values, ascii, expectedY; | ||
values = []; | ||
for (var i = 1, ii = lines.length; i < ii; i++) { | ||
//var previousValues=JSON.parse(JSON.stringify(values)); | ||
values = lines[i].trim().replace(removeCommentRegExp, '').split(xyDataSplitRegExp); | ||
if (values.length > 0) { | ||
if (DEBUG) { | ||
if (!spectrum.firstPoint) { | ||
spectrum.firstPoint = parseFloat(values[0]); | ||
} | ||
var expectedCurrentX = parseFloat(values[0] - spectrum.firstPoint) * spectrum.xFactor + spectrum.firstX; | ||
if ((lastDif || lastDif === 0)) { | ||
expectedCurrentX += spectrum.deltaX; | ||
} | ||
result.logs.push('Checking X value: currentX: ' + currentX + ' - expectedCurrentX: ' + expectedCurrentX); | ||
} | ||
for (var j = 1, jj = values.length; j < jj; j++) { | ||
if (j === 1 && (lastDif || lastDif === 0)) { | ||
lastDif = null; // at the beginning of each line there should be the full value X / Y so the diff is always undefined | ||
// we could check if we have the expected Y value | ||
ascii = values[j].charCodeAt(0); | ||
if (false) { // this code is just to check the jcamp DIFDUP and the next line repeat of Y value | ||
// + - . 0 1 2 3 4 5 6 7 8 9 | ||
if ((ascii === 43) || (ascii === 45) || (ascii === 46) || ((ascii > 47) && (ascii < 58))) { | ||
expectedY = parseFloat(values[j]); | ||
} else | ||
// positive SQZ digits @ A B C D E F G H I (ascii 64-73) | ||
if ((ascii > 63) && (ascii < 74)) { | ||
// we could use parseInt but parseFloat is faster at least in Chrome | ||
expectedY = parseFloat(String.fromCharCode(ascii - 16) + values[j].substring(1)); | ||
} else | ||
// negative SQZ digits a b c d e f g h i (ascii 97-105) | ||
if ((ascii > 96) && (ascii < 106)) { | ||
// we could use parseInt but parseFloat is faster at least in Chrome | ||
expectedY = -parseFloat(String.fromCharCode(ascii - 48) + values[j].substring(1)); | ||
} | ||
if (expectedY !== currentY) { | ||
result.logs.push('Y value check error: Found: ' + expectedY + ' - Current: ' + currentY); | ||
result.logs.push('Previous values: ' + previousValues.length); | ||
result.logs.push(previousValues); | ||
} | ||
} | ||
} else { | ||
if (values[j].length > 0) { | ||
ascii = values[j].charCodeAt(0); | ||
// + - . 0 1 2 3 4 5 6 7 8 9 | ||
if ((ascii === 43) || (ascii === 45) || (ascii === 46) || ((ascii > 47) && (ascii < 58))) { | ||
lastDif = null; | ||
currentY = parseFloat(values[j]); | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} else | ||
// positive SQZ digits @ A B C D E F G H I (ascii 64-73) | ||
if ((ascii > 63) && (ascii < 74)) { | ||
lastDif = null; | ||
currentY = parseFloat(String.fromCharCode(ascii - 16) + values[j].substring(1)); | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} else | ||
// negative SQZ digits a b c d e f g h i (ascii 97-105) | ||
if ((ascii > 96) && (ascii < 106)) { | ||
lastDif = null; | ||
currentY = -parseFloat(String.fromCharCode(ascii - 48) + values[j].substring(1)); | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} else | ||
// DUP digits S T U V W X Y Z s (ascii 83-90, 115) | ||
if (((ascii > 82) && (ascii < 91)) || (ascii === 115)) { | ||
var dup = parseFloat(String.fromCharCode(ascii - 34) + values[j].substring(1)) - 1; | ||
if (ascii === 115) { | ||
dup = parseFloat('9' + values[j].substring(1)) - 1; | ||
} | ||
for (var l = 0; l < dup; l++) { | ||
if (lastDif) { | ||
currentY = currentY + lastDif; | ||
} | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} | ||
} else | ||
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82) | ||
if (ascii === 37) { | ||
lastDif = parseFloat('0' + values[j].substring(1)); | ||
currentY += lastDif; | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} else if ((ascii > 73) && (ascii < 83)) { | ||
lastDif = parseFloat(String.fromCharCode(ascii - 25) + values[j].substring(1)); | ||
currentY += lastDif; | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} else | ||
// negative DIF digits j k l m n o p q r (ascii 106-114) | ||
if ((ascii > 105) && (ascii < 115)) { | ||
lastDif = -parseFloat(String.fromCharCode(ascii - 57) + values[j].substring(1)); | ||
currentY += lastDif; | ||
currentData.push(currentX, currentY * spectrum.yFactor);; | ||
currentX += spectrum.deltaX; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function convertTo3DZ(spectra) { | ||
@@ -577,8 +436,10 @@ var noise = 0; | ||
z[i] = new Array(xSize); | ||
var xVector=spectra[i].data[0]; | ||
for (var j = 0; j < xSize; j++) { | ||
z[i][j] = spectra[i].data[0][j * 2 + 1]; | ||
if (z[i][j] < minZ) minZ = spectra[i].data[0][j * 2 + 1]; | ||
if (z[i][j] > maxZ) maxZ = spectra[i].data[0][j * 2 + 1]; | ||
var value = xVector[j * 2 + 1]; | ||
z[i][j] = value; | ||
if (value < minZ) minZ = value; | ||
if (value > maxZ) maxZ = value; | ||
if (i !== 0 && j !== 0) { | ||
noise += Math.abs(z[i][j] - z[i][j - 1]) + Math.abs(z[i][j] - z[i - 1][j]); | ||
noise += Math.abs(value - z[i][j - 1]) + Math.abs(value - z[i - 1][j]); | ||
} | ||
@@ -590,3 +451,3 @@ } | ||
minX: spectra[0].data[0][0], | ||
maxX: spectra[0].data[0][spectra[0].data[0].length - 2], | ||
maxX: spectra[0].data[0][spectra[0].data[0].length - 2], // has to be -2 because it is a 1D array [x,y,x,y,...] | ||
minY: spectra[0].pageValue, | ||
@@ -610,3 +471,3 @@ maxY: spectra[ySize - 1].pageValue, | ||
function generateContourLines(zData, options) { | ||
//console.time('generateContourLines'); | ||
// console.time('generateContourLines'); | ||
var noise = zData.noise; | ||
@@ -616,4 +477,4 @@ var z = zData.z; | ||
var nbLevels = 7; | ||
var povarHeight = new Float32Array(4); | ||
var isOver = []; | ||
var povarHeight0, povarHeight1, povarHeight2, povarHeight3; | ||
var isOver0, isOver1, isOver2, isOver3; | ||
var nbSubSpectra = z.length; | ||
@@ -646,3 +507,3 @@ var nbPovars = z[0].length; | ||
var contourLevel = {}; | ||
contourLevels.push(contourLevel); | ||
contourLevels[level]=contourLevel; | ||
var side = level % 2; | ||
@@ -661,52 +522,56 @@ if (side === 0) { | ||
for (var iSubSpectra = 0; iSubSpectra < nbSubSpectra - 1; iSubSpectra++) { | ||
var subSpectra = z[iSubSpectra]; | ||
var subSpectraAfter = z[iSubSpectra + 1]; | ||
for (var povar = 0; povar < nbPovars - 1; povar++) { | ||
povarHeight[0] = z[iSubSpectra][povar]; | ||
povarHeight[1] = z[iSubSpectra][povar + 1]; | ||
povarHeight[2] = z[(iSubSpectra + 1)][povar]; | ||
povarHeight[3] = z[(iSubSpectra + 1)][(povar + 1)]; | ||
for (var i = 0; i < 4; i++) { | ||
isOver[i] = (povarHeight[i] > lineZValue); | ||
} | ||
povarHeight0 = subSpectra[povar]; | ||
povarHeight1 = subSpectra[povar + 1]; | ||
povarHeight2 = subSpectraAfter[povar]; | ||
povarHeight3 = subSpectraAfter[povar + 1]; | ||
isOver0 = (povarHeight0 > lineZValue); | ||
isOver1 = (povarHeight1 > lineZValue); | ||
isOver2 = (povarHeight2 > lineZValue); | ||
isOver3 = (povarHeight3 > lineZValue); | ||
// Example povar0 is over the plane and povar1 and | ||
// povar2 are below, we find the varersections and add | ||
// the segment | ||
if (isOver[0] !== isOver[1] && isOver[0] !== isOver[2]) { | ||
pAx = povar + (lineZValue - povarHeight[0]) / (povarHeight[1] - povarHeight[0]); | ||
if (isOver0 !== isOver1 && isOver0 !== isOver2) { | ||
pAx = povar + (lineZValue - povarHeight0) / (povarHeight1 - povarHeight0); | ||
pAy = iSubSpectra; | ||
pBx = povar; | ||
pBy = iSubSpectra + (lineZValue - povarHeight[0]) / (povarHeight[2] - povarHeight[0]); | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
pBy = iSubSpectra + (lineZValue - povarHeight0) / (povarHeight2 - povarHeight0); | ||
lines.push(pAx * dx + x0); lines.push(pAy * dy + y0); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
if (isOver[3] !== isOver[1] && isOver[3] !== isOver[2]) { | ||
// remove push does not help !!!! | ||
if (isOver3 !== isOver1 && isOver3 !== isOver2) { | ||
pAx = povar + 1; | ||
pAy = iSubSpectra + 1 - (lineZValue - povarHeight[3]) / (povarHeight[1] - povarHeight[3]); | ||
pBx = povar + 1 - (lineZValue - povarHeight[3]) / (povarHeight[2] - povarHeight[3]); | ||
pAy = iSubSpectra + 1 - (lineZValue - povarHeight3) / (povarHeight1 - povarHeight3); | ||
pBx = povar + 1 - (lineZValue - povarHeight3) / (povarHeight2 - povarHeight3); | ||
pBy = iSubSpectra + 1; | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
lines.push(pAx * dx + x0); lines.push(pAy * dy + y0); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
// test around the diagonal | ||
if (isOver[1] !== isOver[2]) { | ||
pAx = povar + 1 - (lineZValue - povarHeight[1]) / (povarHeight[2] - povarHeight[1]); | ||
pAy = iSubSpectra + (lineZValue - povarHeight[1]) / (povarHeight[2] - povarHeight[1]); | ||
if (isOver[1] !== isOver[0]) { | ||
pBx = povar + 1 - (lineZValue - povarHeight[1]) / (povarHeight[0] - povarHeight[1]); | ||
if (isOver1 !== isOver2) { | ||
pAx = (povar + 1 - (lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) * dx + x0; | ||
pAy = (iSubSpectra + (lineZValue - povarHeight1) / (povarHeight2 - povarHeight1)) * dy + y0; | ||
if (isOver1 !== isOver0) { | ||
pBx = povar + 1 - (lineZValue - povarHeight1) / (povarHeight0 - povarHeight1); | ||
pBy = iSubSpectra; | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
lines.push(pAx); lines.push(pAy); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
if (isOver[2] !== isOver[0]) { | ||
if (isOver2 !== isOver0) { | ||
pBx = povar; | ||
pBy = iSubSpectra + 1 - (lineZValue - povarHeight[2]) / (povarHeight[0] - povarHeight[2]); | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
pBy = iSubSpectra + 1 - (lineZValue - povarHeight2) / (povarHeight0 - povarHeight2); | ||
lines.push(pAx); lines.push(pAy); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
if (isOver[1] !== isOver[3]) { | ||
if (isOver1 !== isOver3) { | ||
pBx = povar + 1; | ||
pBy = iSubSpectra + (lineZValue - povarHeight[1]) / (povarHeight[3] - povarHeight[1]); | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
pBy = iSubSpectra + (lineZValue - povarHeight1) / (povarHeight3 - povarHeight1); | ||
lines.push(pAx); lines.push(pAy); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
if (isOver[2] !== isOver[3]) { | ||
pBx = povar + (lineZValue - povarHeight[2]) / (povarHeight[3] - povarHeight[2]); | ||
if (isOver2 !== isOver3) { | ||
pBx = povar + (lineZValue - povarHeight2) / (povarHeight3 - povarHeight2); | ||
pBy = iSubSpectra + 1; | ||
lines.push(pAx * dx + x0, pAy * dy + y0, pBx * dx + x0, pBy * dy + y0); | ||
lines.push(pAx); lines.push(pAy); lines.push(pBx * dx + x0); lines.push(pBy * dy + y0); | ||
} | ||
@@ -759,2 +624,214 @@ } | ||
function fastParseXYData(spectrum, value) { | ||
// TODO need to deal with result | ||
// console.log(value); | ||
// we check if deltaX is defined otherwise we calculate it | ||
var yFactor = spectrum.yFactor; | ||
var deltaX = spectrum.deltaX; | ||
spectrum.isXYdata = true; | ||
// TODO to be improved using 2 array {x:[], y:[]} | ||
var currentData = []; | ||
var currentPosition = 0; | ||
spectrum.data = [currentData]; | ||
var currentX = spectrum.firstX; | ||
var currentY = spectrum.firstY; | ||
// we skip the first line | ||
// | ||
var endLine = false; | ||
for (var i = 0; i < value.length; i++) { | ||
var ascii = value.charCodeAt(i); | ||
if (ascii === 13 || ascii === 10) { | ||
endLine = true; | ||
} else { | ||
if (endLine) break; | ||
} | ||
} | ||
// we proceed taking the i after the first line | ||
var newLine = true; | ||
var isDifference=false; | ||
var isLastDifference=false; | ||
var lastDifference=0; | ||
var isDuplicate=false; | ||
var inComment = false; | ||
var currentValue = 0; | ||
var isNegative = false; | ||
var inValue=false; | ||
var skipFirstValue=false; | ||
var decimalPosition = 0; | ||
var ascii; | ||
for (; i <= value.length; i++) { | ||
if (i===value.length) ascii=13; | ||
else ascii = value.charCodeAt(i); | ||
if (inComment) { | ||
// we should ignore the text if we are after $$ | ||
if (ascii === 13 || ascii === 10) { | ||
newLine = true; | ||
inComment = false; | ||
} | ||
} else { | ||
// when is it a new value ? | ||
// when it is not a digit, . or comma | ||
// it is a number that is either new or we continue | ||
if ( ascii <= 57 && ascii >= 48) { // a number | ||
inValue=true; | ||
if (decimalPosition > 0) { | ||
currentValue += (ascii - 48) / Math.pow(10, decimalPosition++); | ||
} else { | ||
currentValue *= 10; | ||
currentValue += ascii - 48; | ||
} | ||
} else if (ascii === 44 || ascii === 46) { // a "," or "." | ||
inValue=true; | ||
decimalPosition++; | ||
} else { | ||
if (inValue) { | ||
// need to process the previous value | ||
if (newLine) { | ||
newLine = false; // we don't check the X value | ||
// console.log("NEW LINE",isDifference, lastDifference); | ||
// if new line and lastDifference, the first value is just a check ! | ||
// that we don't check ... | ||
if (isLastDifference) skipFirstValue=true; | ||
} else { | ||
// need to deal with duplicate and differences | ||
if (skipFirstValue) { | ||
skipFirstValue=false; | ||
} else { | ||
if (isDifference) { | ||
if (currentValue===0) lastDifference=0; | ||
else lastDifference=isNegative ? -currentValue : currentValue; | ||
isLastDifference=true; | ||
isDifference=false; | ||
} | ||
var duplicate=isDuplicate ? currentValue - 1 : 1; | ||
for (var j=0; j<duplicate; j++) { | ||
if (isLastDifference) { | ||
currentY += lastDifference; | ||
} else { | ||
if (currentValue===0) currentY=0; | ||
else currentY = isNegative ? -currentValue : currentValue; | ||
} | ||
// console.log("Separator",isNegative ? | ||
// -currentValue : currentValue, | ||
// "isDiff", isDifference, "isDup", isDuplicate, | ||
// "lastDif", lastDifference, "dup:", duplicate, "y", currentY); | ||
// push is slightly slower ... (we loose 10%) | ||
currentData[currentPosition++]=currentX; | ||
currentData[currentPosition++]=currentY * yFactor; | ||
currentX += deltaX; | ||
} | ||
} | ||
} | ||
isNegative=false; | ||
currentValue=0; | ||
decimalPosition=0; | ||
inValue=false; | ||
isDuplicate=false; | ||
} | ||
// positive SQZ digits @ A B C D E F G H I (ascii 64-73) | ||
if ((ascii < 74) && (ascii > 63)) { | ||
inValue=true; | ||
isLastDifference=false; | ||
currentValue=ascii-64; | ||
} else | ||
// negative SQZ digits a b c d e f g h i (ascii 97-105) | ||
if ((ascii > 96) && (ascii < 106)) { | ||
inValue=true; | ||
isLastDifference=false; | ||
currentValue=ascii-96; | ||
isNegative=true; | ||
} else | ||
// DUP digits S T U V W X Y Z s (ascii 83-90, 115) | ||
if (ascii===115) { | ||
inValue=true; | ||
isDuplicate=true; | ||
currentValue=9; | ||
} else if ((ascii > 82) && (ascii < 91)) { | ||
inValue=true; | ||
isDuplicate=true; | ||
currentValue=ascii-82; | ||
} else | ||
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82) | ||
if ((ascii > 73) && (ascii < 83)) { | ||
inValue=true; | ||
isDifference=true; | ||
currentValue=ascii-73; | ||
} else | ||
// negative DIF digits j k l m n o p q r (ascii 106-114) | ||
if ((ascii > 105) && (ascii < 115)) { | ||
inValue=true; | ||
isDifference=true; | ||
currentValue=ascii-105; | ||
isNegative=true; | ||
} else | ||
// $ sign, we need to check the next one | ||
if (ascii === 36 && value.charCodeAt(i + 1) === 36) { | ||
inValue=true; | ||
inComment = true; | ||
} else | ||
// positive DIF digits % J K L M N O P Q R (ascii 37, 74-82) | ||
if (ascii === 37) { | ||
inValue=true; | ||
isDifference=true; | ||
currentValue=0; | ||
isNegative=false; | ||
} else | ||
if (ascii === 45) { // a "-" | ||
// check if after there is a number, decimal or comma | ||
var ascii2=value.charCodeAt(i+1); | ||
if ((ascii2 >= 48 && ascii2 <= 57) || ascii2 === 44 || ascii2 === 46) { | ||
inValue=true; | ||
isLastDifference=false; | ||
isNegative = true; | ||
} | ||
} else if (ascii === 13 || ascii === 10) { | ||
newLine = true; | ||
inComment = false; | ||
} | ||
// and now analyse the details ... space or tabulation | ||
// if "+" we just don't care | ||
} | ||
} | ||
} | ||
} | ||
function parsePeakTable(spectrum, value, result) { | ||
var removeCommentRegExp = /\$\$.*/; | ||
var peakTableSplitRegExp = /[,\t ]+/; | ||
spectrum.isPeaktable=true; | ||
var i, ii, j, jj, values; | ||
var currentData = []; | ||
spectrum.data = [currentData]; | ||
// counts for around 20% of the time | ||
var lines = value.split(/,? *,?[;\r\n]+ */); | ||
var k = 0; | ||
for (i = 1, ii = lines.length; i < ii; i++) { | ||
values = lines[i].trim().replace(removeCommentRegExp, '').split(peakTableSplitRegExp); | ||
if (values.length % 2 === 0) { | ||
for (j = 0, jj = values.length; j < jj; j = j + 2) { | ||
// takes around 40% of the time to add and parse the 2 values nearly exclusively because of parseFloat | ||
currentData[k++] = (parseFloat(values[j]) * spectrum.xFactor); | ||
currentData[k++] = (parseFloat(values[j + 1]) * spectrum.yFactor); | ||
} | ||
} else { | ||
result.logs.push('Format error: ' + values); | ||
} | ||
} | ||
} | ||
return convert; | ||
@@ -788,3 +865,3 @@ | ||
stamps[stamp] = resolve; | ||
worker.postMessage({stamp: stamp, input: input, options: options}); | ||
worker.postMessage(JSON.stringify({stamp: stamp, input: input, options: options})); | ||
}); | ||
@@ -795,3 +872,3 @@ } | ||
var workerURL = URL.createObjectURL(new Blob([ | ||
'var getConverter =' + getConverter.toString() + ';var convert = getConverter(); onmessage = function (event) { postMessage({stamp: event.data.stamp, output: convert(event.data.input, event.data.options)}); };' | ||
'var getConverter =' + getConverter.toString() + ';var convert = getConverter(); onmessage = function (event) { var data = JSON.parse(event.data); postMessage(JSON.stringify({stamp: event.data.stamp, output: convert(data.input, data.options)})); };' | ||
], {type: 'application/javascript'})); | ||
@@ -801,5 +878,6 @@ worker = new Worker(workerURL); | ||
worker.addEventListener('message', function (event) { | ||
var stamp = event.data.stamp; | ||
var data = JSON.parse(event.data); | ||
var stamp = data.stamp; | ||
if (stamps[stamp]) { | ||
stamps[stamp](event.data.output); | ||
stamps[stamp](data.output); | ||
} | ||
@@ -806,0 +884,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57504
14
1189
2