{"version":3,"file":"spc-parser.min.js","sources":["../lib-esm/types.js","../lib-esm/utility/headerUtils.js","../lib-esm/fileHeader.js","../lib-esm/utility/getDataShape.js","../lib-esm/utility/guessSpectraType.js","../node_modules/iobuffer/lib-esm/text.js","../node_modules/iobuffer/lib-esm/IOBuffer.js","../node_modules/ml-spectra-processing/lib-esm/utils/createFromToArray.js","../lib-esm/dataBlock/shared.js","../lib-esm/dataBlock/utility/ensureIncreasingXValues.js","../lib-esm/dataBlock/newDataBlock.js","../lib-esm/dataBlock/oldDataBlock.js","../lib-esm/parse.js","../lib-esm/logBlock.js"],"sourcesContent":["/**\n * Gives meaning to type codes.\n * @param  xzwType x, z or w type code.\n * @return  String corresponding to the code.\n */\nexport function xzwTypes(xzwType) {\n    switch (xzwType) {\n        case 1:\n            return 'Wavenumber (cm-1)';\n        case 2:\n            return 'Micrometers (um)';\n        case 3:\n            return 'Nanometers (nm)';\n        case 4:\n            return 'Seconds';\n        case 5:\n            return 'Minutes';\n        case 6:\n            return 'Hertz (Hz)';\n        case 7:\n            return 'Kilohertz (KHz)';\n        case 8:\n            return 'Megahertz (MHz)';\n        case 9:\n            return 'Mass (M/z)';\n        case 10:\n            return 'Parts per million (PPM)';\n        case 11:\n            return 'Days';\n        case 12:\n            return 'Years';\n        case 13:\n            return 'Raman Shift (cm-1)';\n        case 14:\n            return 'eV';\n        case 15:\n            return 0;\n        case 16:\n            return 'Diode Number';\n        case 17:\n            return 'Channel ';\n        case 18:\n            return 'Degrees';\n        case 19:\n            return 'Temperature (F)';\n        case 20:\n            return 'Temperature (C)';\n        case 21:\n            return 'Temperature (K)';\n        case 22:\n            return 'Data Points';\n        case 23:\n            return 'Milliseconds (mSec)';\n        case 24:\n            return 'Microseconds (uSec)';\n        case 25:\n            return 'Nanoseconds (nSec)';\n        case 26:\n            return 'Gigahertz (GHz)';\n        case 27:\n            return 'Centimeters (cm)';\n        case 28:\n            return 'Meters (m)';\n        case 29:\n            return 'Millimeters (mm)';\n        case 30:\n            return 'Hours';\n        case 255:\n            return 'Double interferogram';\n        default:\n            return 'Arbitrary';\n    }\n}\n/**\n * Gives meaning to y type codes\n * @param  yType y type code\n * @return  String corresponding to the code\n */\nexport function yTypes(yType) {\n    switch (yType) {\n        case 0:\n            return 'Arbitrary Intensity';\n        case 1:\n            return 'Interferogram';\n        case 2:\n            return 'Absorbance';\n        case 3:\n            return 'Kubelka-Monk';\n        case 4:\n            return 'Counts';\n        case 5:\n            return 'Volts';\n        case 6:\n            return 'Degrees';\n        case 7:\n            return 'Milliamps';\n        case 8:\n            return 'Millimeters';\n        case 9:\n            return 'Millivolts';\n        case 10:\n            return 'Log(1/R)';\n        case 11:\n            return 'Percent';\n        case 12:\n            return 'Intensity';\n        case 13:\n            return 'Relative Intensity';\n        case 14:\n            return 'Energy';\n        case 16:\n            return 'Decibel';\n        case 19:\n            return 'Temperature (F)';\n        case 20:\n            return 'Temperature (C)';\n        case 21:\n            return 'Temperature (K)';\n        case 22:\n            return 'Index of Refraction [N]';\n        case 23:\n            return 'Extinction Coeff. [K]';\n        case 24:\n            return 'Real';\n        case 25:\n            return 'Imaginary';\n        case 26:\n            return 'Complex';\n        case 128:\n            return 'Transmission';\n        case 129:\n            return 'Reflectance';\n        case 130:\n            return 'Arbitrary or Single Beam with Valley Peaks';\n        case 131:\n            return 'Emission';\n        default:\n            return 'Reference Arbitrary Energy';\n    }\n}\n/**\n * Convert code to experiment type\n * @param code\n * @returns type of experiment carried out.\n */\nexport function experimentSettings(code) {\n    switch (code) {\n        case 1:\n            return 'Gas Chromatogram';\n        case 2:\n            return 'General Chromatogram (same as SPCGEN with TCGRAM)';\n        case 3:\n            return 'HPLC Chromatogram';\n        case 4:\n            return 'FT-IR, FT-NIR, FT-Raman Spectrum or Igram (Can also be used for scanning IR.)';\n        case 5:\n            return 'NIR Spectrum (Usually multi-spectral data sets for calibration.)';\n        case 7:\n            return 'UV-VIS Spectrum (Can be used for single scanning UV-VIS-NIR.)';\n        case 8:\n            return 'X-ray Diffraction Spectrum';\n        case 9:\n            return 'Mass Spectrum  (Can be single, GC-MS, Continuum, Centroid or TOF.)';\n        case 10:\n            return 'NMR Spectrum or FID';\n        case 11:\n            return 'Raman Spectrum (Usually Diode Array, CCD, etc. use SPCFTIR for FT-Raman.)';\n        case 12:\n            return 'Fluorescence Spectrum';\n        case 13:\n            return 'Atomic Spectrum';\n        case 14:\n            return 'Chromatography Diode Array Spectra';\n        default:\n            return 'General SPC (could be anything)';\n    }\n}\n//# sourceMappingURL=types.js.map","/**\n * Gets the parameter in each bit of the flag\n *\n * @param  flag First byte of the main header.\n * @returns  The parameters.\n */\nexport class FlagParameters {\n    constructor(flag) {\n        this.y16BitPrecision = (flag & 1) !== 0; //Y values are 16 bits instead of 32\n        this.useExperimentExtension = (flag & 2) !== 0; //Enable experiment mode\n        this.multiFile = (flag & 4) !== 0; //Multiple spectra (multifile)\n        this.zValuesRandom = (flag & 8) !== 0; //Z values in random order if multiFile\n        this.zValuesUneven = (flag & 16) !== 0; //Z values ordered but unevenly spaced if multi\n        this.customAxisLabels = (flag & 32) !== 0; //Custom labels\n        this.xyxy = (flag & 64) !== 0; //One X array per subfile, for discontinuous curves\n        this.xy = (flag & 128) !== 0; // Non-evenly spaced X, X before Y\n    }\n}\n/**\n * Gets the date encoded in binary in a long number.\n * @param  long Binary date.\n * @return  Date formatted to ISO 8601:2019 convention.\n */\nexport function longToDate(long) {\n    if (long === 0) {\n        return '0000-00-00T00:00:00.00Z';\n    }\n    const date = new Date();\n    date.setUTCFullYear(long >> 20);\n    date.setUTCMonth(((long >> 16) & 0x0f) - 1);\n    date.setUTCDate((long >> 11) & 0x1f);\n    date.setUTCHours((long >> 6) & 0x1f);\n    date.setUTCMinutes(long & 0x3f);\n    date.setUTCSeconds(0);\n    date.setUTCMilliseconds(0);\n    return date.toISOString();\n}\n//# sourceMappingURL=headerUtils.js.map","import { xzwTypes, yTypes, experimentSettings } from './types';\nimport { FlagParameters, longToDate } from './utility/headerUtils';\n/**\n * Old-format File-header parsing.\n * @param buffer spc buffer.\n * @param  prev `{parameters,fileversion}`\n * @return  file metadata\n */\nexport class TheOldHeader {\n    constructor(buffer, prev) {\n        this.fileVersion = prev.fileVersion; //Each bit contains a parameter\n        this.parameters = prev.parameters; //4B => New format; 4D => LabCalc format\n        this.exponentY = buffer.readInt16(); //Word (16 bits) instead of byte\n        this.numberPoints = buffer.readFloat32();\n        this.startingX = buffer.readFloat32();\n        this.endingX = buffer.readFloat32();\n        this.xUnitsType = xzwTypes(buffer.readUint8());\n        this.yUnitsType = yTypes(buffer.readUint8());\n        const date = new Date();\n        const zTypeYear = buffer.readUint16(); //Unrelated to Z axis\n        date.setUTCFullYear(zTypeYear % 4096); // TODO: might be wrong\n        date.setUTCMonth(Math.max(buffer.readUint8() - 1, 0));\n        date.setUTCDate(buffer.readUint8());\n        date.setUTCHours(buffer.readUint8());\n        date.setUTCMinutes(buffer.readUint8());\n        this.date = date.toISOString();\n        this.resolutionDescription = buffer\n            .readChars(8)\n            .replace(/\\x00/g, '')\n            .trim();\n        this.peakPointNumber = buffer.readUint16();\n        this.scans = buffer.readUint16();\n        this.spare = [];\n        for (let i = 0; i < 7; i++) {\n            this.spare.push(buffer.readFloat32());\n        }\n        this.memo = buffer.readChars(130).replace(/\\x00/g, '').trim();\n        this.xyzLabels = buffer.readChars(30).replace(/\\x00/g, '').trim();\n    }\n}\n/**\n * New format file-header parsing.\n * @param buffer spc buffer.\n * @param  prev `{parameters,fileversion}`\n * @return  file metadata\n */\nexport class TheNewHeader {\n    constructor(buffer, prev) {\n        this.fileVersion = prev.fileVersion; //Each bit contains a parameter\n        this.parameters = prev.parameters; //4B => New format; 4D => LabCalc format\n        this.experimentType = experimentSettings(buffer.readUint8()); //Experiment type code (See SPC.h)\n        this.exponentY = buffer.readInt8(); //Exponent for Y values (80h = floating point): FloatY = (2^Exp)*IntY/(2^32) 32-bit; FloatY = (2^Exp)*IntY/(2^16) 32-bit\n        this.numberPoints = buffer.readUint32(); //Number of points (if not XYXY)\n        this.startingX = buffer.readFloat64(); //First X coordinate\n        this.endingX = buffer.readFloat64(); //Last X coordinate\n        this.spectra = buffer.readUint32(); //Number of spectrums\n        this.xUnitsType = xzwTypes(buffer.readUint8()); //X Units type code (See types.js)\n        this.yUnitsType = yTypes(buffer.readUint8()); //Y \"\"\n        this.zUnitsType = xzwTypes(buffer.readUint8()); //Z \"\"\n        this.postingDisposition = buffer.readUint8(); //Posting disposition (See GRAMSDDE.H)\n        this.date = longToDate(buffer.readUint32()); //Date: minutes = first 6 bits, hours = 5 next bits, days = 5 next, months = 4 next, years = 12 last\n        this.resolutionDescription = buffer\n            .readChars(9)\n            .replace(/\\x00/g, '')\n            .trim(); //Resolution description text\n        this.sourceInstrumentDescription = buffer\n            .readChars(9)\n            .replace(/\\x00/g, '')\n            .trim(); // Source Instrument description text\n        this.peakPointNumber = buffer.readUint16(); //Peak point number for interferograms\n        this.spare = [];\n        for (let i = 0; i < 8; i++) {\n            this.spare.push(buffer.readFloat32());\n        }\n        if (this.fileVersion === 0x4c) {\n            //Untested case because no test files\n            this.spare.reverse();\n        }\n        this.memo = buffer.readChars(130).replace(/\\x00/g, '').trim();\n        this.xyzLabels = buffer.readChars(30).replace(/\\x00/g, '').trim();\n        this.logOffset = buffer.readUint32(); //Byte offset to Log Block\n        this.modifiedFlag = buffer.readUint32(); //File modification flag (See values in SPC.H)\n        this.processingCode = buffer.readUint8(); //Processing code (See GRAMSDDE.H)\n        this.calibrationLevel = buffer.readUint8(); //Calibration level + 1\n        this.subMethodSampleInjectionNumber = buffer.readUint16(); //Sub-method sample injection number\n        this.concentrationFactor = buffer.readFloat32(); //Floating data multiplier concentration factor\n        this.methodFile = buffer.readChars(48).replace(/\\x00/g, '').trim(); //Method file\n        this.zSubIncrement = buffer.readFloat32(); //Z subfile increment for even Z Multifiles\n        this.wPlanes = buffer.readUint32();\n        this.wPlaneIncrement = buffer.readFloat32();\n        this.wAxisUnits = xzwTypes(buffer.readUint8()); //W axis units code\n        this.reserved = buffer.readChars(187).replace(/\\x00/g, '').trim(); //Reserved space (Must be zero)\n        if (this.xUnitsType === 0) {\n            this.xUnitsType = this.xyzLabels.substring(0, 10);\n        }\n        if (this.zUnitsType === 0) {\n            this.zUnitsType = this.xyzLabels.substring(20, 30);\n        }\n    }\n}\n/**\n * File-header parsing - First 512/256 bytes (new/old format).\n * @param buffer SPC buffer.\n * @return File-header object\n */\nexport function fileHeader(buffer) {\n    const parameters = new FlagParameters(buffer.readUint8()); //Each bit contains a parameter\n    const fileVersion = buffer.readUint8(); //4B => New format; 4D => LabCalc format\n    const headerOpts = { parameters, fileVersion };\n    switch (fileVersion) {\n        case 0x4b: // new format\n            break;\n        case 0x4c:\n            buffer.setBigEndian();\n            break;\n        case 0x4d: {\n            // old LabCalc format\n            return new TheOldHeader(buffer, headerOpts);\n        }\n        default:\n            throw new Error('Unrecognized file format: byte 01 must be either 4B, 4C or 4D');\n    }\n    return new TheNewHeader(buffer, headerOpts);\n}\n//# sourceMappingURL=fileHeader.js.map","/** Get how the data was stored\n * @param multiFile - whether there are multiple spectra (subfiles) or not.\n * @param xy - uneven x values\n * @param xyxy - multifile with separate x axis\n * @return the shape of the data as a string\n */\nexport function getDataShape({ multiFile, xy, xyxy, }) {\n    /* single file */\n    if (!multiFile) {\n        // Y or XY,\n        return !xy ? 'Y' : xyxy ? 'exception' : 'XY';\n    }\n    /* then multifile */\n    if (!xy) {\n        /* even X - equidistant */\n        return 'YY';\n    }\n    else {\n        // uneven x\n        return !xyxy ? 'XYY' : 'XYXY';\n    }\n}\n//# sourceMappingURL=getDataShape.js.map","import { TheNewHeader } from '../fileHeader';\nimport { getDataShape } from './getDataShape';\n/**\n * Inspects properties and tries to classify the spectra\n * For the most common spectra types\n * @param data the parsed data\n * @returns string describing the type of spectra ([[`SpectraType`]]) or \"General\" if unsure.\n */\nexport function guessSpectraType(meta) {\n    //function tested with the `fileHeader.test.ts`\n    const { xUnitsType: xU, yUnitsType: yU } = meta;\n    // for the new file header they define a \"experiment type\"\n    if (meta instanceof TheNewHeader) {\n        // \"General SPC\" does not give any information\n        if (!meta.experimentType.startsWith('General SPC')) {\n            const id = meta.experimentType.split(' ')[0];\n            switch (id //find all possible ids in `types.ts` file\n            ) {\n                case 'FT-IR,':\n                    return 'ir';\n                case 'NIR':\n                    return 'ir';\n                case 'UV-VIS':\n                    return 'uv';\n                case 'Mass':\n                    return 'mass';\n                case 'Raman':\n                    return 'raman';\n                default:\n                    return 'other';\n            }\n        }\n    }\n    // for old header or General SPC\n    switch (xU) {\n        case 'Mass (M/z)':\n            return 'mass';\n        case 'Raman Shift (cm-1)':\n            return 'raman';\n        case 'Micrometers (um)':\n            return uvOrIR(meta, 'micrometer');\n        case 'Wavenumber (cm-1)': {\n            return uvOrIR(meta, 'wavenumber');\n        }\n        case 'Nanometers (nm)':\n            if ([/*'Kubelka-Monk'*/ 'Absorbance', 'Log(1/R)', 'Transmission'].includes(yU)) {\n                return uvOrIR(meta, 'nanometer');\n            }\n            return 'other';\n        default:\n            return 'other';\n    }\n}\n/**\n * Further classify an X axis that is using \"wavenumber\" as uv or ir.\n * @param data - the parsed file (a jsonlike object)\n * @returns\n */\nexport function uvOrIR(meta, xUnit) {\n    //tested in \"parse\" because of the input\n    const dataShape = getDataShape(meta.parameters);\n    //xyxy and exception won't normally get here anyways (raman or ms normally.)\n    const analyze = ['Y', 'YY', 'XY', 'XYY'].includes(dataShape);\n    if (analyze) {\n        let sX = meta.startingX;\n        let eX = meta.endingX;\n        if (xUnit !== 'nanometer') {\n            sX = unitToNano(sX, xUnit);\n            eX = unitToNano(eX, xUnit);\n        }\n        const lowerBound = sX <= eX ? sX : eX;\n        return getRegion(lowerBound);\n    }\n    return 'other';\n}\n/**\n * @param lb -  lower boundary in _nanometers_\n * @return type of spectra\n */\nexport function getRegion(lb) {\n    return lb < 150 ? 'other' : lb < 700 ? 'uv' : 'ir';\n}\n/**\n * Converts micrometers or wavenumber units to nanometers\n * This allows a unique way to determine the spectra region (using nanometers).\n * @param x - value\n * @param from - input unit to convert\n * @return equivalent in nanometers\n */\nexport function unitToNano(x, from) {\n    return from === 'micrometer' ? x * 1000 : (1 / x) * 10 ** 7;\n}\n//# sourceMappingURL=guessSpectraType.js.map","import { TextDecoder, TextEncoder } from 'util';\nexport function decode(bytes, encoding = 'utf8') {\n    const decoder = new TextDecoder(encoding);\n    return decoder.decode(bytes);\n}\nconst encoder = new TextEncoder();\nexport function encode(str) {\n    return encoder.encode(str);\n}\n//# sourceMappingURL=text.js.map","import { decode, encode } from './text';\nconst defaultByteLength = 1024 * 8;\nexport class IOBuffer {\n    /**\n     * @param data - The data to construct the IOBuffer with.\n     * If data is a number, it will be the new buffer's length<br>\n     * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>\n     * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,\n     * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.\n     * @param options\n     */\n    constructor(data = defaultByteLength, options = {}) {\n        let dataIsGiven = false;\n        if (typeof data === 'number') {\n            data = new ArrayBuffer(data);\n        }\n        else {\n            dataIsGiven = true;\n            this.lastWrittenByte = data.byteLength;\n        }\n        const offset = options.offset ? options.offset >>> 0 : 0;\n        const byteLength = data.byteLength - offset;\n        let dvOffset = offset;\n        if (ArrayBuffer.isView(data) || data instanceof IOBuffer) {\n            if (data.byteLength !== data.buffer.byteLength) {\n                dvOffset = data.byteOffset + offset;\n            }\n            data = data.buffer;\n        }\n        if (dataIsGiven) {\n            this.lastWrittenByte = byteLength;\n        }\n        else {\n            this.lastWrittenByte = 0;\n        }\n        this.buffer = data;\n        this.length = byteLength;\n        this.byteLength = byteLength;\n        this.byteOffset = dvOffset;\n        this.offset = 0;\n        this.littleEndian = true;\n        this._data = new DataView(this.buffer, dvOffset, byteLength);\n        this._mark = 0;\n        this._marks = [];\n    }\n    /**\n     * Checks if the memory allocated to the buffer is sufficient to store more\n     * bytes after the offset.\n     * @param byteLength - The needed memory in bytes.\n     * @returns `true` if there is sufficient space and `false` otherwise.\n     */\n    available(byteLength = 1) {\n        return this.offset + byteLength <= this.length;\n    }\n    /**\n     * Check if little-endian mode is used for reading and writing multi-byte\n     * values.\n     * @returns `true` if little-endian mode is used, `false` otherwise.\n     */\n    isLittleEndian() {\n        return this.littleEndian;\n    }\n    /**\n     * Set little-endian mode for reading and writing multi-byte values.\n     */\n    setLittleEndian() {\n        this.littleEndian = true;\n        return this;\n    }\n    /**\n     * Check if big-endian mode is used for reading and writing multi-byte values.\n     * @returns `true` if big-endian mode is used, `false` otherwise.\n     */\n    isBigEndian() {\n        return !this.littleEndian;\n    }\n    /**\n     * Switches to big-endian mode for reading and writing multi-byte values.\n     */\n    setBigEndian() {\n        this.littleEndian = false;\n        return this;\n    }\n    /**\n     * Move the pointer n bytes forward.\n     * @param n - Number of bytes to skip.\n     */\n    skip(n = 1) {\n        this.offset += n;\n        return this;\n    }\n    /**\n     * Move the pointer n bytes backward.\n     * @param n - Number of bytes to move back.\n     */\n    back(n = 1) {\n        this.offset -= n;\n        return this;\n    }\n    /**\n     * Move the pointer to the given offset.\n     * @param offset\n     */\n    seek(offset) {\n        this.offset = offset;\n        return this;\n    }\n    /**\n     * Store the current pointer offset.\n     * @see {@link IOBuffer#reset}\n     */\n    mark() {\n        this._mark = this.offset;\n        return this;\n    }\n    /**\n     * Move the pointer back to the last pointer offset set by mark.\n     * @see {@link IOBuffer#mark}\n     */\n    reset() {\n        this.offset = this._mark;\n        return this;\n    }\n    /**\n     * Push the current pointer offset to the mark stack.\n     * @see {@link IOBuffer#popMark}\n     */\n    pushMark() {\n        this._marks.push(this.offset);\n        return this;\n    }\n    /**\n     * Pop the last pointer offset from the mark stack, and set the current\n     * pointer offset to the popped value.\n     * @see {@link IOBuffer#pushMark}\n     */\n    popMark() {\n        const offset = this._marks.pop();\n        if (offset === undefined) {\n            throw new Error('Mark stack empty');\n        }\n        this.seek(offset);\n        return this;\n    }\n    /**\n     * Move the pointer offset back to 0.\n     */\n    rewind() {\n        this.offset = 0;\n        return this;\n    }\n    /**\n     * Make sure the buffer has sufficient memory to write a given byteLength at\n     * the current pointer offset.\n     * If the buffer's memory is insufficient, this method will create a new\n     * buffer (a copy) with a length that is twice (byteLength + current offset).\n     * @param byteLength\n     */\n    ensureAvailable(byteLength = 1) {\n        if (!this.available(byteLength)) {\n            const lengthNeeded = this.offset + byteLength;\n            const newLength = lengthNeeded * 2;\n            const newArray = new Uint8Array(newLength);\n            newArray.set(new Uint8Array(this.buffer));\n            this.buffer = newArray.buffer;\n            this.length = this.byteLength = newLength;\n            this._data = new DataView(this.buffer);\n        }\n        return this;\n    }\n    /**\n     * Read a byte and return false if the byte's value is 0, or true otherwise.\n     * Moves pointer forward by one byte.\n     */\n    readBoolean() {\n        return this.readUint8() !== 0;\n    }\n    /**\n     * Read a signed 8-bit integer and move pointer forward by 1 byte.\n     */\n    readInt8() {\n        return this._data.getInt8(this.offset++);\n    }\n    /**\n     * Read an unsigned 8-bit integer and move pointer forward by 1 byte.\n     */\n    readUint8() {\n        return this._data.getUint8(this.offset++);\n    }\n    /**\n     * Alias for {@link IOBuffer#readUint8}.\n     */\n    readByte() {\n        return this.readUint8();\n    }\n    /**\n     * Read `n` bytes and move pointer forward by `n` bytes.\n     */\n    readBytes(n = 1) {\n        const bytes = new Uint8Array(n);\n        for (let i = 0; i < n; i++) {\n            bytes[i] = this.readByte();\n        }\n        return bytes;\n    }\n    /**\n     * Read a 16-bit signed integer and move pointer forward by 2 bytes.\n     */\n    readInt16() {\n        const value = this._data.getInt16(this.offset, this.littleEndian);\n        this.offset += 2;\n        return value;\n    }\n    /**\n     * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.\n     */\n    readUint16() {\n        const value = this._data.getUint16(this.offset, this.littleEndian);\n        this.offset += 2;\n        return value;\n    }\n    /**\n     * Read a 32-bit signed integer and move pointer forward by 4 bytes.\n     */\n    readInt32() {\n        const value = this._data.getInt32(this.offset, this.littleEndian);\n        this.offset += 4;\n        return value;\n    }\n    /**\n     * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.\n     */\n    readUint32() {\n        const value = this._data.getUint32(this.offset, this.littleEndian);\n        this.offset += 4;\n        return value;\n    }\n    /**\n     * Read a 32-bit floating number and move pointer forward by 4 bytes.\n     */\n    readFloat32() {\n        const value = this._data.getFloat32(this.offset, this.littleEndian);\n        this.offset += 4;\n        return value;\n    }\n    /**\n     * Read a 64-bit floating number and move pointer forward by 8 bytes.\n     */\n    readFloat64() {\n        const value = this._data.getFloat64(this.offset, this.littleEndian);\n        this.offset += 8;\n        return value;\n    }\n    /**\n     * Read a 64-bit signed integer number and move pointer forward by 8 bytes.\n     */\n    readBigInt64() {\n        const value = this._data.getBigInt64(this.offset, this.littleEndian);\n        this.offset += 8;\n        return value;\n    }\n    /**\n     * Read a 64-bit unsigned integer number and move pointer forward by 8 bytes.\n     */\n    readBigUint64() {\n        const value = this._data.getBigUint64(this.offset, this.littleEndian);\n        this.offset += 8;\n        return value;\n    }\n    /**\n     * Read a 1-byte ASCII character and move pointer forward by 1 byte.\n     */\n    readChar() {\n        return String.fromCharCode(this.readInt8());\n    }\n    /**\n     * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.\n     */\n    readChars(n = 1) {\n        let result = '';\n        for (let i = 0; i < n; i++) {\n            result += this.readChar();\n        }\n        return result;\n    }\n    /**\n     * Read the next `n` bytes, return a UTF-8 decoded string and move pointer\n     * forward by `n` bytes.\n     */\n    readUtf8(n = 1) {\n        return decode(this.readBytes(n));\n    }\n    /**\n     * Read the next `n` bytes, return a string decoded with `encoding` and move pointer\n     * forward by `n` bytes.\n     * If no encoding is passed, the function is equivalent to @see {@link IOBuffer#readUtf8}\n     */\n    decodeText(n = 1, encoding = 'utf-8') {\n        return decode(this.readBytes(n), encoding);\n    }\n    /**\n     * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer\n     * forward by 1 byte.\n     */\n    writeBoolean(value) {\n        this.writeUint8(value ? 0xff : 0x00);\n        return this;\n    }\n    /**\n     * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.\n     */\n    writeInt8(value) {\n        this.ensureAvailable(1);\n        this._data.setInt8(this.offset++, value);\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as an 8-bit unsigned integer and move pointer forward by 1\n     * byte.\n     */\n    writeUint8(value) {\n        this.ensureAvailable(1);\n        this._data.setUint8(this.offset++, value);\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * An alias for {@link IOBuffer#writeUint8}.\n     */\n    writeByte(value) {\n        return this.writeUint8(value);\n    }\n    /**\n     * Write all elements of `bytes` as uint8 values and move pointer forward by\n     * `bytes.length` bytes.\n     */\n    writeBytes(bytes) {\n        this.ensureAvailable(bytes.length);\n        for (let i = 0; i < bytes.length; i++) {\n            this._data.setUint8(this.offset++, bytes[i]);\n        }\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 16-bit signed integer and move pointer forward by 2\n     * bytes.\n     */\n    writeInt16(value) {\n        this.ensureAvailable(2);\n        this._data.setInt16(this.offset, value, this.littleEndian);\n        this.offset += 2;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 16-bit unsigned integer and move pointer forward by 2\n     * bytes.\n     */\n    writeUint16(value) {\n        this.ensureAvailable(2);\n        this._data.setUint16(this.offset, value, this.littleEndian);\n        this.offset += 2;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 32-bit signed integer and move pointer forward by 4\n     * bytes.\n     */\n    writeInt32(value) {\n        this.ensureAvailable(4);\n        this._data.setInt32(this.offset, value, this.littleEndian);\n        this.offset += 4;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 32-bit unsigned integer and move pointer forward by 4\n     * bytes.\n     */\n    writeUint32(value) {\n        this.ensureAvailable(4);\n        this._data.setUint32(this.offset, value, this.littleEndian);\n        this.offset += 4;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 32-bit floating number and move pointer forward by 4\n     * bytes.\n     */\n    writeFloat32(value) {\n        this.ensureAvailable(4);\n        this._data.setFloat32(this.offset, value, this.littleEndian);\n        this.offset += 4;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 64-bit floating number and move pointer forward by 8\n     * bytes.\n     */\n    writeFloat64(value) {\n        this.ensureAvailable(8);\n        this._data.setFloat64(this.offset, value, this.littleEndian);\n        this.offset += 8;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 64-bit signed bigint and move pointer forward by 8\n     * bytes.\n     */\n    writeBigInt64(value) {\n        this.ensureAvailable(8);\n        this._data.setBigInt64(this.offset, value, this.littleEndian);\n        this.offset += 8;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write `value` as a 64-bit unsigned bigint and move pointer forward by 8\n     * bytes.\n     */\n    writeBigUint64(value) {\n        this.ensureAvailable(8);\n        this._data.setBigUint64(this.offset, value, this.littleEndian);\n        this.offset += 8;\n        this._updateLastWrittenByte();\n        return this;\n    }\n    /**\n     * Write the charCode of `str`'s first character as an 8-bit unsigned integer\n     * and move pointer forward by 1 byte.\n     */\n    writeChar(str) {\n        return this.writeUint8(str.charCodeAt(0));\n    }\n    /**\n     * Write the charCodes of all `str`'s characters as 8-bit unsigned integers\n     * and move pointer forward by `str.length` bytes.\n     */\n    writeChars(str) {\n        for (let i = 0; i < str.length; i++) {\n            this.writeUint8(str.charCodeAt(i));\n        }\n        return this;\n    }\n    /**\n     * UTF-8 encode and write `str` to the current pointer offset and move pointer\n     * forward according to the encoded length.\n     */\n    writeUtf8(str) {\n        return this.writeBytes(encode(str));\n    }\n    /**\n     * Export a Uint8Array view of the internal buffer.\n     * The view starts at the byte offset and its length\n     * is calculated to stop at the last written byte or the original length.\n     */\n    toArray() {\n        return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);\n    }\n    /**\n     * Update the last written byte offset\n     * @private\n     */\n    _updateLastWrittenByte() {\n        if (this.offset > this.lastWrittenByte) {\n            this.lastWrittenByte = this.offset;\n        }\n    }\n}\n//# sourceMappingURL=IOBuffer.js.map","/**\n * Create an array with numbers between \"from\" and \"to\" of length \"length\"\n *\n * @param options - options\n * @return - array of distributed numbers between \"from\" and \"to\"\n */\nexport function createFromToArray(options = {}) {\n    let { from = 0, to = 1, length = 1000, includeFrom = true, includeTo = true, distribution = 'uniform', } = options;\n    const array = new Float64Array(length);\n    let div = length;\n    if (includeFrom && includeTo) {\n        div = length - 1;\n    }\n    else if ((!includeFrom && includeTo) || (includeFrom && !includeTo)) {\n        div = length;\n    }\n    else if (!includeFrom && !includeTo) {\n        div = length + 1;\n    }\n    let delta = (to - from) / div;\n    if (distribution === 'uniform') {\n        if (includeFrom) {\n            let index = 0;\n            while (index < length) {\n                array[index] = from + delta * index;\n                index++;\n            }\n        }\n        else {\n            let index = 0;\n            while (index < length) {\n                array[index] = from + delta * (index + 1);\n                index++;\n            }\n        }\n    }\n    else if (distribution === 'log') {\n        let base = (to / from) ** (1 / div);\n        let firstExponent = Math.log(from) / Math.log(base);\n        if (includeFrom) {\n            let index = 0;\n            while (index < length) {\n                array[index] = base ** (firstExponent + index);\n                index++;\n            }\n        }\n        else {\n            let index = 0;\n            while (index < length) {\n                array[index] = base ** (firstExponent + index + 1);\n                index++;\n            }\n        }\n    }\n    else {\n        throw new Error('Please choose for the distribution either uniform or log. By default the distribution chosen is uniform.');\n    }\n    return array;\n}\n//# sourceMappingURL=createFromToArray.js.map","import { ensureIncreasingXValues } from './utility/ensureIncreasingXValues';\n/**\n * Gets the Subfile flags.\n *\n * @param  flag First byte of the subheader.\n * @return The parameters.\n */\nexport class SubFlagParameters {\n    constructor(flag) {\n        this.changed = (flag & 1) !== 0;\n        this.noPeakTable = (flag & 8) !== 0;\n        this.modifiedArithmetic = (flag & 128) !== 0;\n    }\n}\n/**\n * Parses the subheader (header of the subfile)\n *\n * @param buffer SPC buffer.\n * @return subheader object\n */\nexport class SubHeader {\n    constructor(buffer) {\n        this.parameters = new SubFlagParameters(buffer.readUint8());\n        this.exponentY = buffer.readInt8();\n        this.indexNumber = buffer.readUint16();\n        this.startingZ = buffer.readFloat32();\n        this.endingZ = buffer.readFloat32();\n        this.noiseValue = buffer.readFloat32();\n        this.numberPoints = buffer.readUint32();\n        this.numberCoAddedScans = buffer.readUint32();\n        this.wAxisValue = buffer.readFloat32();\n        this.reserved = buffer.readChars(4).replace(/\\x00/g, '').trim();\n    }\n}\n/**\n * Set the X and Y axis (object with labels, values etc.)\n * @param x\n * @param y\n * @param fileHeader\n * @return object with x and y as axis.\n */\nexport function setXYAxis(x, y, fileHeader) {\n    var _a, _b, _c, _d;\n    const xAxis = /(?<label>.*?) ?[([](?<units>.*)[)\\]]/.exec(fileHeader.xUnitsType);\n    const yAxis = /(?<label>.*?) ?[([](?<units>.*)[)\\]]/.exec(fileHeader.yUnitsType);\n    const [oX, oY] = ensureIncreasingXValues(x, y);\n    const variables = {\n        x: {\n            symbol: 'x',\n            label: ((_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.groups) === null || _a === void 0 ? void 0 : _a.label) || fileHeader.xUnitsType,\n            units: ((_b = xAxis === null || xAxis === void 0 ? void 0 : xAxis.groups) === null || _b === void 0 ? void 0 : _b.units) || '',\n            data: oX,\n            isDependent: false,\n        },\n        y: {\n            symbol: 'y',\n            label: ((_c = yAxis === null || yAxis === void 0 ? void 0 : yAxis.groups) === null || _c === void 0 ? void 0 : _c.label) || fileHeader.yUnitsType,\n            units: ((_d = yAxis === null || yAxis === void 0 ? void 0 : yAxis.groups) === null || _d === void 0 ? void 0 : _d.units) || '',\n            data: oY,\n            isDependent: true,\n        },\n    };\n    return variables;\n}\n//# sourceMappingURL=shared.js.map","/** Ensures x-values are increasing in magnitude. It reverses y if x was reversed.\n *\n * * Does not mutate arrays\n * * Assumes that X is either increasing or decreasing, not any random order.\n * * Expects x and y to be the same length\n * @param x - array of x values\n * @param y - array of y values\n * @returns [x,y] tuple\n */\nexport function ensureIncreasingXValues(x, y) {\n    const xL = x.length;\n    if (xL !== 0) {\n        if (y.length !== xL) {\n            //wouldn't really make sense for x and y to be !==\n            throw new RangeError('x and y length must be the same');\n        }\n        const firstX = x[0];\n        const lastX = x[x.length - 1];\n        if (firstX > lastX) {\n            //apparently slice(0) faster than slice()\n            return [x.slice(0).reverse(), y.slice(0).reverse()];\n        }\n    }\n    return [x, y];\n}\n//# sourceMappingURL=ensureIncreasingXValues.js.map","import { createFromToArray } from 'ml-spectra-processing';\nimport { getDataShape } from '../utility/getDataShape';\nimport { SubHeader, setXYAxis } from './shared';\n/**\n * Reads the data block of the SPC file.\n *\n * @param buffer spc buffer.\n * @param fileHeader main header.\n * @return Array containing the spectra.\n */\nexport function newDataBlock(buffer, fileHeader) {\n    let x;\n    let spectra = [];\n    const dataShape = getDataShape(fileHeader.parameters);\n    if (dataShape === 'XY' || dataShape === 'XYY') {\n        //for these ones, X axis comes before subheader !!\n        x = new Float64Array(fileHeader.numberPoints);\n        for (let i = 0; i < fileHeader.numberPoints; i++) {\n            x[i] = buffer.readFloat32();\n        }\n    }\n    else if (dataShape === 'YY' || dataShape === 'Y') {\n        //for these ones, no X axis, we create it as we have all parameters\n        x = createFromToArray({\n            from: fileHeader.startingX,\n            to: fileHeader.endingX,\n            length: fileHeader.numberPoints,\n        });\n    }\n    for (let i = 0; i < fileHeader.spectra; i++) {\n        // here Y is set (runs only once for a single spectra.)\n        const subFileHeader = new SubHeader(buffer);\n        // set X for the remaining cases if neccesary\n        if (dataShape === 'XYXY' || dataShape === 'exception') {\n            x = new Float64Array(subFileHeader.numberPoints);\n            for (let j = 0; j < x.length; j++) {\n                x[j] = buffer.readFloat32();\n            }\n        }\n        const y = getNewY(new Float64Array(x.length), subFileHeader, fileHeader, buffer);\n        const variables = setXYAxis(x, y, fileHeader);\n        spectra.push({ meta: subFileHeader, variables });\n    }\n    return spectra;\n}\nexport function getNewY(y, subHeader, fileHeader, buffer) {\n    const { exponentY, parameters: { y16BitPrecision }, } = fileHeader;\n    if (subHeader.exponentY === 0) {\n        subHeader.exponentY = exponentY;\n    }\n    const yFactor = Math.pow(2, subHeader.exponentY - (y16BitPrecision ? 16 : 32));\n    if (y16BitPrecision) {\n        for (let j = 0; j < y.length; j++) {\n            y[j] = buffer.readInt16() * yFactor;\n        }\n    }\n    else {\n        for (let j = 0; j < y.length; j++) {\n            if (subHeader.exponentY !== -128) {\n                y[j] = buffer.readInt32() * yFactor;\n            }\n            else {\n                y[j] = buffer.readFloat32();\n            }\n        }\n    }\n    return y;\n}\n//# sourceMappingURL=newDataBlock.js.map","import { createFromToArray } from 'ml-spectra-processing';\nimport { SubHeader, setXYAxis } from './shared';\n/**\n * Reads a file's data block (old SPC format)\n *\n * @param buffer spc buffer.\n * @param fileHeader header.\n * @return Array containing the spectra.\n */\nexport function oldDataBlock(buffer, fileHeader) {\n    // either Y or YY fall on the for loop\n    let spectra = [];\n    // old format uses always equidistant arrays\n    const x = createFromToArray({\n        from: fileHeader.startingX,\n        to: fileHeader.endingX,\n        length: fileHeader.numberPoints,\n    });\n    for (let i = 0; buffer.offset + fileHeader.numberPoints < buffer.length; i++) {\n        const subFileHeader = new SubHeader(buffer);\n        const y = getOldY(new Float64Array(x.length), subFileHeader, fileHeader, buffer);\n        const variables = setXYAxis(x, y, fileHeader);\n        spectra.push({ meta: subFileHeader, variables });\n    }\n    return spectra;\n}\n/**\n *\n *\n * @export\n * @param {Float64Array} y\n * @param {SubHeader} subHeader\n * @param {TheOldHeader} fileHeader\n * @param {IOBuffer} buffer\n * @return {*}\n */\nexport function getOldY(y, subHeader, fileHeader, buffer) {\n    const { fileVersion, exponentY, parameters: { y16BitPrecision }, } = fileHeader;\n    if (subHeader.exponentY === 0) {\n        subHeader.exponentY = exponentY;\n    }\n    const yFactor = Math.pow(2, subHeader.exponentY - (y16BitPrecision ? 16 : 32));\n    if (y16BitPrecision) {\n        for (let j = 0; j < y.length; j++) {\n            y[j] = buffer.readInt16() * yFactor;\n        }\n    }\n    else {\n        for (let j = 0; j < y.length; j++) {\n            if (fileVersion === 0x4d) {\n                y[j] =\n                    ((buffer.readUint8() << 16) +\n                        (buffer.readInt8() << 24) +\n                        (buffer.readUint8() << 0) +\n                        (buffer.readUint8() << 8)) *\n                        yFactor;\n            }\n        }\n    }\n    return y;\n}\n//# sourceMappingURL=oldDataBlock.js.map","import { IOBuffer } from 'iobuffer';\nimport { newDataBlock } from './dataBlock/newDataBlock';\nimport { oldDataBlock } from './dataBlock/oldDataBlock';\nimport { fileHeader, TheNewHeader } from './fileHeader';\nimport { readLogBlock } from './logBlock';\n/**\n * Parses an SPC file.\n *\n * @param  buffer SPC file buffer.\n * @return JSON-like object with information contained in the SPC file.\n */\nexport function parse(buffer) {\n    const ioBuffer = new IOBuffer(buffer);\n    const meta = fileHeader(ioBuffer);\n    if (meta instanceof TheNewHeader) {\n        //new format\n        const spectra = newDataBlock(ioBuffer, meta);\n        const logs = meta.logOffset !== 0 ? readLogBlock(ioBuffer, meta.logOffset) : null;\n        return { meta, spectra, logs };\n    }\n    else {\n        //old format\n        return {\n            meta,\n            spectra: oldDataBlock(ioBuffer, meta),\n        };\n    }\n}\n//# sourceMappingURL=parse.js.map","/**\n *\n * @param  buffer SPC buffer.\n * @param  logOffset Offset of the log (from mainHeader).\n * @return  Object containing log meta, data and text.\n */\nexport function readLogBlock(buffer, logOffset) {\n    let logHeader = {\n        size: buffer.readUint32(),\n        memorySize: buffer.readUint32(),\n        textOffset: buffer.readUint32(),\n        binarySize: buffer.readUint32(),\n        diskArea: buffer.readUint32(),\n        reserved: buffer.readChars(44).trim().replace(/\\x00/g, ''), //Reserved space\n    };\n    const logData = buffer.readChars(logHeader.binarySize);\n    buffer.offset = logOffset + logHeader.textOffset;\n    const logASCII = buffer\n        .readChars(logHeader.size - logHeader.textOffset)\n        .trim()\n        .replace(/\\x00/g, '');\n    return { meta: logHeader, data: logData, text: logASCII };\n}\n//# sourceMappingURL=logBlock.js.map"],"names":["xzwTypes","xzwType","yTypes","yType","FlagParameters","constructor","flag","this","y16BitPrecision","useExperimentExtension","multiFile","zValuesRandom","zValuesUneven","customAxisLabels","xyxy","xy","TheOldHeader","buffer","prev","fileVersion","parameters","exponentY","readInt16","numberPoints","readFloat32","startingX","endingX","xUnitsType","readUint8","yUnitsType","date","Date","zTypeYear","readUint16","setUTCFullYear","setUTCMonth","Math","max","setUTCDate","setUTCHours","setUTCMinutes","toISOString","resolutionDescription","readChars","replace","trim","peakPointNumber","scans","spare","i","push","memo","xyzLabels","TheNewHeader","experimentType","code","experimentSettings","readInt8","readUint32","readFloat64","spectra","zUnitsType","postingDisposition","long","setUTCSeconds","setUTCMilliseconds","longToDate","sourceInstrumentDescription","reverse","logOffset","modifiedFlag","processingCode","calibrationLevel","subMethodSampleInjectionNumber","concentrationFactor","methodFile","zSubIncrement","wPlanes","wPlaneIncrement","wAxisUnits","reserved","substring","getDataShape","_ref","uvOrIR","meta","xUnit","dataShape","includes","sX","eX","unitToNano","lb","x","from","decode","bytes","encoding","decoder","TextDecoder","encoder","TextEncoder","IOBuffer","data","options","dataIsGiven","ArrayBuffer","lastWrittenByte","byteLength","offset","dvOffset","isView","byteOffset","length","littleEndian","_data","DataView","_mark","_marks","available","isLittleEndian","setLittleEndian","isBigEndian","setBigEndian","skip","n","back","seek","mark","reset","pushMark","popMark","pop","undefined","Error","rewind","ensureAvailable","newLength","newArray","Uint8Array","set","readBoolean","getInt8","getUint8","readByte","readBytes","value","getInt16","getUint16","readInt32","getInt32","getUint32","getFloat32","getFloat64","readBigInt64","getBigInt64","readBigUint64","getBigUint64","readChar","String","fromCharCode","result","readUtf8","decodeText","writeBoolean","writeUint8","writeInt8","setInt8","_updateLastWrittenByte","setUint8","writeByte","writeBytes","writeInt16","setInt16","writeUint16","setUint16","writeInt32","setInt32","writeUint32","setUint32","writeFloat32","setFloat32","writeFloat64","setFloat64","writeBigInt64","setBigInt64","writeBigUint64","setBigUint64","writeChar","str","charCodeAt","writeChars","writeUtf8","encode","toArray","createFromToArray","to","includeFrom","includeTo","distribution","array","Float64Array","div","delta","index","base","firstExponent","log","SubFlagParameters","changed","noPeakTable","modifiedArithmetic","SubHeader","indexNumber","startingZ","endingZ","noiseValue","numberCoAddedScans","wAxisValue","setXYAxis","y","fileHeader","xAxis","exec","yAxis","oX","oY","xL","RangeError","slice","ensureIncreasingXValues","symbol","label","groups","_a","units","_b","isDependent","_c","_d","getNewY","subHeader","yFactor","pow","j","oldDataBlock","subFileHeader","variables","getOldY","xU","yU","startsWith","split","ioBuffer","headerOpts","newDataBlock","logs","logHeader","size","memorySize","textOffset","binarySize","diskArea","logData","text","readLogBlock"],"mappings":"iRAKM,SAAUA,EAASC,GACvB,OAAQA,GACN,KAAK,EACH,MAAO,oBACT,KAAK,EACH,MAAO,mBACT,KAAK,EACH,MAAO,kBACT,KAAK,EACH,MAAO,UACT,KAAK,EACH,MAAO,UACT,KAAK,EACH,MAAO,aACT,KAAK,EACH,MAAO,kBACT,KAAK,EACH,MAAO,kBACT,KAAK,EACH,MAAO,aACT,KAAK,GACH,MAAO,0BACT,KAAK,GACH,MAAO,OACT,KAAK,GACH,MAAO,QACT,KAAK,GACH,MAAO,qBACT,KAAK,GACH,MAAO,KACT,KAAK,GACH,OAAO,EACT,KAAK,GACH,MAAO,eACT,KAAK,GACH,MAAO,WACT,KAAK,GACH,MAAO,UACT,KAAK,GACH,MAAO,kBACT,KAAK,GACH,MAAO,kBACT,KAAK,GACH,MAAO,kBACT,KAAK,GACH,MAAO,cACT,KAAK,GACH,MAAO,sBACT,KAAK,GACH,MAAO,sBACT,KAAK,GACH,MAAO,qBACT,KAAK,GACH,MAAO,kBACT,KAAK,GACH,MAAO,mBACT,KAAK,GACH,MAAO,aACT,KAAK,GACH,MAAO,mBACT,KAAK,GACH,MAAO,QACT,KAAK,IACH,MAAO,uBACT,QACE,MAAO,YAEZ,CAMK,SAAUC,EAAOC,GACrB,OAAQA,GACN,KAAK,EACH,MAAO,sB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