public new int loadStream() { YAPI.TJsonParser json = null; int res = 0; int count = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); string name = null; List <int> coldiv = new List <int>(); List <int> coltype = new List <int>(); List <int> udat = new List <int>(); List <double> date = new List <double>(); List <double> colscl = new List <double>(); List <int> colofs = new List <int>(); List <int> caltyp = new List <int>(); List <YAPI.yCalibrationHandler> calhdl = new List <YAPI.yCalibrationHandler>(); List <List <int> > calpar = new List <List <int> >(); List <List <double> > calraw = new List <List <double> >(); List <List <double> > calref = new List <List <double> >(); int x = 0; int i = 0; int j = 0; res = _dataLogger.getData(_runNo, _timeStamp, ref json); if ((res != YAPI.SUCCESS)) { return(res); } _nRows = 0; _nCols = 0; _columnNames.Clear(); _values = new List <List <double> >(); root = json.GetRootNode(); for (i = 0; i <= root.membercount - 1; i++) { el = root.members[i]; name = el.name; if (name == "time") { _timeStamp = (int)el.ivalue; } else if (name == "UTC") { _utcStamp = (UInt32)el.ivalue; } else if (name == "interval") { _interval = (int)el.ivalue; } else if (name == "nRows") { _nRows = (int)el.ivalue; } else if (name == "keys") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { _columnNames.Add(el.items[j].svalue); } } else if (name == "div") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { coldiv.Add((int)el.items[j].ivalue); } } else if (name == "type") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { coltype.Add((int)el.items[j].ivalue); } } else if (name == "scal") { _nCols = el.itemcount; for (j = 0; j <= _nCols - 1; j++) { colscl.Add(el.items[j].ivalue / 65536.0); if (coltype[j] != 0) { colofs.Add(-32767); } else { colofs.Add(0); } } } else if (name == "cal") { //fixme no calibration } else if (name == "data") { if (colscl.Count <= 0) { for (j = 0; j <= _nCols - 1; j++) { colscl.Add(1.0 / coldiv[j]); if (coltype[j] != 0) { colofs.Add(-32767); } else { colofs.Add(0); } } } udat.Clear(); if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING) { udat = YAPI._decodeWords(el.svalue); } else { count = el.itemcount; for (j = 0; j <= count - 1; j++) { int tmp = (int)(el.items[j].ivalue); udat.Add(tmp); } } _values = new List <List <double> >(); List <double> dat = new List <double>(); foreach (int uval in udat) { double value; if (coltype[x] < 2) { value = (uval + colofs[x]) * colscl[x]; } else { value = YAPI._decimalToDouble(uval - 32767); } if (caltyp[x] > 0 && calhdl[x] != null) { YAPI.yCalibrationHandler handler = calhdl[x]; if (caltyp[x] <= 10) { value = handler((uval + colofs[x]) / coldiv[x], caltyp[x], calpar[x], calraw[x], calref[x]); } else if (caltyp[x] > 20) { value = handler(value, caltyp[x], calpar[x], calraw[x], calref[x]); } } dat.Add(value); x++; if (x == _nCols) { _values.Add(dat); dat.Clear(); x = 0; } } } } json = null; return(YAPI.SUCCESS); }
private int loadStream() { YAPI.TJsonParser json = null; int res = 0; int count = 0; YAPI.TJSONRECORD root = default(YAPI.TJSONRECORD); YAPI.TJSONRECORD el = default(YAPI.TJSONRECORD); string name = null; List <int> coldiv = new List <int>(); List <int> coltype = new List <int>(); List <uint> udat = new List <uint>(); List <double> date = new List <double>(); List <double> colscl = new List <double>(); int x = 0; int y = 0; int i = 0; int j = 0; double value = 0; res = dataLogger.getData(runNo, timeStamp, ref json); if ((res != YAPI.SUCCESS)) { return(res); } nRows = 0; nCols = 0; columnNames.Clear(); values = new double[1, 1]; root = json.GetRootNode(); for (i = 0; i <= root.membercount - 1; i++) { el = root.members[i]; name = el.name; if (name == "time") { timeStamp = el.ivalue; } else if (name == "UTC") { utcStamp = el.ivalue; } else if (name == "interval") { interval = el.ivalue; } else if (name == "nRows") { nRows = el.ivalue; } else if (name == "keys") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { columnNames.Add(el.items[j].svalue); } } else if (name == "div") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { coldiv.Add(el.items[j].ivalue); } } else if (name == "type") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { coltype.Add(el.items[j].ivalue); } } else if (name == "scal") { nCols = el.itemcount; for (j = 0; j <= nCols - 1; j++) { colscl.Add(el.items[j].ivalue / 65536.0); } } else if (name == "data") { if (colscl.Count <= 0) { for (j = 0; j <= nCols - 1; j++) { colscl.Add(1.0 / coldiv[j]); } } udat.Clear(); if (el.recordtype == YAPI.TJSONRECORDTYPE.JSON_STRING) { string sdat = el.svalue; for (int p = 0; p < sdat.Length;) { uint val; uint c = sdat[p++]; if (c >= 'a') { int srcpos = (int)(udat.Count - 1 - (c - 'a')); if (srcpos < 0) { dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format"); return(YAPI.IO_ERROR); } val = udat[srcpos]; } else { if (p + 2 > sdat.Length) { dataLogger.throw_friend(YAPI.IO_ERROR, "Unexpected JSON reply format"); return(YAPI.IO_ERROR); } val = (c - '0'); c = sdat[p++]; val += (c - '0') << 5; c = sdat[p++]; if (c == 'z') { c = '\\'; } val += (c - '0') << 10; } udat.Add(val); } } else { count = el.itemcount; for (j = 0; j <= count - 1; j++) { u32 tmp = (u32)(el.items[j].ivalue); udat.Add(tmp); } } values = new double[nRows, nCols]; foreach (u32 uval in udat) { value = uval; if (coltype[x] == 0) { value = value * colscl[x]; } else { if (coltype[x] == 1) { value = (value - 32767) * colscl[x]; } } values[y, x] = value; x++; if (x == nCols) { x = 0; y++; } } } } json = null; return(YAPI.SUCCESS); }