Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justinoboyle/674f344996c006e7517139e2daf7b3f2 to your computer and use it in GitHub Desktop.
Save justinoboyle/674f344996c006e7517139e2daf7b3f2 to your computer and use it in GitHub Desktop.

Dimension-Point (.dp)

All 'tokens' are seperated by a single comma ,.

Dimension identification token

The dimension identification specifies how many dimensions are present in the file.

Example: 2 (standard x,y)

You can optionally specify titles for each dimension, by including an @ symbol, followed by the display names separated by ;.

Example: 2@x;y

Data input

Data is comma-separated and is split into sections depending on the dimension identification.

Example:

Points in (x,y):
(1, 2)
(5, 3)
(0.3, 0.9)

Full DP file: 2@x;y,1,2,5,3,0.3,0.9

Sample implementations

JavaScript

function parseDP(inData) {

    if(!inData.includes(','))
        return {};

    let tokens = inData.trim().split(',');
    let labels = [];

    if(tokens.length < 2)
        return {};

    if(tokens[0].includes('@'))
        labels = tokens[0].split('@')[1].split(';');

    if(isNaN(tokens[0].split('@')[0]))
        return {};

    let dimSize = parseInt(tokens[0].split('@')[0]),
        points = [],
        buffer = {},
        tempCount = 0;
        
    for(let i = 1; i < tokens.length; i++) {

        let val = parseFloat(tokens[i]);
    
        let label = typeof(labels[tempCount]) !== 'undefined' ? labels[tempCount] : tempCount;

        buffer[label] = val;
        tempCount++;

       if((tempCount) >= dimSize || (i+1) === tokens.length) {
            points.push(buffer);
            buffer = {};
            tempCount = 0;
        }
    }

    return points;
}

input: 2@x;y,1,2,5,3,0.3,0.9

output: [ { x: 1, y: 2 }, { x: 5, y: 3 }, { x: 0.3, y: 0.9 } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment