/// <summary> /// Retrieves signal information for the specified record, and stores it in siArray. /// numSignals must match the dimension of siArray, and must be equal to or greater than /// the number of signals in the first (and usually, the only) group of the record. /// </summary> /// <param name="record">[path/]name of the desired record.</param> /// <param name="siArray">Storage for signal information to be returned.</param> /// <param name="numSignals">Number of signals in the first (and usually, the only) group of the record.</param> /// <param name="errMsg">Storage for verbose error messages.</param> /// <returns>True if successful, False if an error occurs.</returns> public static bool GetSignalInfo(string record, WFDB_SiginfoArray siArray, int numSignals, ref string errMsg) { int result = 0; errMsg = ""; try { result = Wfdb.wfdb.isigopen(record, siArray.cast(), numSignals); if (result < 1) { // Something failed -- find out what: errMsg = wfdb.wfdberror(); while (errMsg.EndsWith("\n") || errMsg.EndsWith("\r")) { errMsg = errMsg.Substring(0, errMsg.Length - 1); } errMsg = "isigopen(...) error:" + newLine + "\t" + errMsg + newLine; // Append the by-the-numbers error: errMsg += GetErrMsgFromReturnID(result, LastCall.LastCall_SignalInfo) + newLine; return(false); } } catch (Exception isigopenException) { while (isigopenException.InnerException != null) { // Drill down: isigopenException = isigopenException.InnerException; } errMsg = isigopenException.ToString() + newLine; MessageBox.Show("Exception occurred trying isigopen(...): \n" + isigopenException.ToString()); //result = -3; return(false); } return(true); }
/// <summary> /// Initializes and returns a blank SigInfoArray object containing numItems SigInfo objects. /// </summary> /// <param name="numItems">Number of SigInfo objects in SigInfoArray</param> /// <param name="errMsg">Storage for verbose error messages, if any.</param> /// <returns>A blank SigInfoArray object of dimension numItems.</returns> public static WFDB_SiginfoArray GetSigInfoArray(int numItems, ref string errMsg) { WFDB_SiginfoArray siArray; errMsg = ""; // First try opening the array: try { siArray = new WFDB_SiginfoArray(numItems); } catch (Exception siarrayException) { while (siarrayException.InnerException != null) { // Drill down: siarrayException = siarrayException.InnerException; } errMsg = siarrayException.ToString() + newLine; MessageBox.Show("Exception occurred executing 'siArray = new WFDB_Siginfo()': \n" + siarrayException.ToString()); return(null); } // No exceptions -- init the array: for (int i = 0; i < numItems; i++) { WFDB_Siginfo newInfo = new WFDB_Siginfo(); // 1234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890 234567890 // 1 2 3 4 5 6 7 8 9 10 11 12 newInfo.desc = " "; newInfo.fname = " "; newInfo.units = " "; siArray.setitem(i, newInfo); } return(siArray); }
static void Main(string[] argv) { int i, nsig, nsamp = 1000; if (argv.Length < 1) { Console.WriteLine("usage: example6 record"); // Unlike C programs, C# programs do not have any foolproof way // to discover their own names, so the name is given as a constant // above. The command needed to run this program within a VM // is platform-dependent and likely to be more complex. Environment.Exit(1); } if ((nsig = wfdb.isigopen(argv[0], null, 0)) <= 0) Environment.Exit(2); WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig); WFDB_SampleArray vin = new WFDB_SampleArray(nsig); WFDB_SampleArray vout = new WFDB_SampleArray(nsig); if (wfdb.isigopen(argv[0], s.cast(), nsig) != nsig) Environment.Exit(2); if (wfdb.osigopen("8l", s.cast(), (uint)nsig) <= 0) Environment.Exit(3); while (nsamp-- > 0 && wfdb.getvec(vin.cast()) > 0) { for (i = 0; i < nsig; i++) { vout.setitem(i, vout.getitem(i) - vin.getitem(i)); } if (wfdb.putvec(vout.cast()) < 0) break; for (i = 0; i < nsig; i++) { vout.setitem(i, vin.getitem(i)); } } wfdb.newheader("dif"); wfdb.wfdbquit(); }
static void Main(string[] argv) { int btype, i, j, nbeats = 0, nsig, hwindow, window, stoptime = 0; WFDB_Anninfo a = new WFDB_Anninfo(); WFDB_Annotation annot = new WFDB_Annotation(); if (argv.Length < 2) { Console.WriteLine( "usage: example9 annotator record [beat-type from to]"); // Unlike C programs, C# programs do not have any foolproof way // to discover their own names, so the name is given as a constant // above. The command needed to run this program within a VM // is platform-dependent and likely to be more complex. Environment.Exit(1); } a.name = argv[0]; a.stat = wfdb.WFDB_READ; if ((nsig = wfdb.isigopen(argv[1], null, 0)) < 1) Environment.Exit(2); WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig); WFDB_SampleArray v = new WFDB_SampleArray(nsig); WFDB_SampleArray vb = new WFDB_SampleArray(nsig); if (wfdb.wfdbinit(argv[1], a, 1, s.cast(), (uint)nsig) != nsig) Environment.Exit(3); hwindow = wfdb.strtim(".05"); window = 2*hwindow + 1; long[,] sum = new long[nsig,window]; btype = (argv.Length > 2) ? wfdb.strann(argv[2]) : wfdb.NORMAL; if (argv.Length > 3) wfdb.iannsettime(wfdb.strtim(argv[3])); WFDB_Siginfo s_0_ = s.getitem(0); if (argv.Length > 4) { if ((stoptime = wfdb.strtim(argv[4])) < 0) stoptime = -stoptime; if (s_0_.nsamp > 0 && stoptime > s_0_.nsamp) stoptime = s_0_.nsamp; } else stoptime = s_0_.nsamp; if (stoptime > 0) stoptime -= hwindow; while (wfdb.getann(0, annot) == 0 && annot.time < hwindow) ; do { if (annot.anntyp != btype) continue; wfdb.isigsettime(annot.time - hwindow - 1); wfdb.getvec(vb.cast()); for (j = 0; j < window && wfdb.getvec(v.cast()) > 0; j++) for (i = 0; i < nsig; i++) sum[i,j] += v.getitem(i) - vb.getitem(i); nbeats++; } while (wfdb.getann(0, annot) == 0 && (stoptime == 0L || annot.time < stoptime)); if (nbeats < 1) { Console.WriteLine("example9: no `" + wfdb.annstr(btype) + "' beats found"); Environment.Exit(4); } Console.WriteLine("Average of {0} `{1}' beats:", nbeats, wfdb.annstr(btype)); for (j = 0; j < window; j++) for (i = 0; i < nsig; i++) Console.Write( "{0:G6}{1}", (double)sum[i,j]/nbeats, ((i < nsig-1) ? "\t" : "\n")); wfdb.wfdbquit(); }
static void Main(string[] argv) { WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(2); if (wfdb.isigopen("100s", siarray.cast(), 2) < 2) Environment.Exit(1); WFDB_SampleArray v = new WFDB_SampleArray(2); for (int i = 0; i < 10; i++) { if (wfdb.getvec(v.cast()) < 0) break; Console.WriteLine("\t" + v.getitem(0) + "\t" + v.getitem(1)); } }
static void Main(string[] argv) { double[] c; double vv; int i, j, nc = argv.Length - 4, nsig, nsamp, t; if (argv.Length < 3) { Console.WriteLine( "usage: example7 record start duration [ coefficients ... ]"); // Unlike C programs, C# programs do not have any foolproof way // to discover their own names, so the name is given as a constant // above. The command needed to run this program within a VM // is platform-dependent and likely to be more complex. Environment.Exit(1); } if (nc < 1) { nc = 1; c = new double[1]; c[0] = 1.0; } else { c = new double[nc]; } for (i = 0; i < nc; i++) c[i] = Double.Parse(argv[i+3]); if ((nsig = wfdb.isigopen(argv[0], null, 0)) < 1) Environment.Exit(3); WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig); WFDB_SampleArray v = new WFDB_SampleArray(nsig); if (wfdb.isigopen(argv[0], s.cast(), nsig) != nsig) Environment.Exit(3); if (wfdb.isigsettime(wfdb.strtim(argv[1])) < 0) Environment.Exit(4); if ((nsamp = wfdb.strtim(argv[2])) < 1) { Console.WriteLine("example7: inappropriate value for duration"); Environment.Exit(5); } if (wfdb.osigopen("16l", s.cast(), (uint)nsig) != nsig) Environment.Exit(6); wfdb.sample(0, 0); for (t = 0; t < nsamp && wfdb.sample_valid() == 1; t++) { for (j = 0; j < nsig; j++) { for (i = 0, vv = 0.0; i < nc; i++) if (c[i] != 0.0) vv += c[i]*wfdb.sample((uint)j, t+i); v.setitem(j, (int)vv); } if (wfdb.putvec(v.cast()) < 0) break; } wfdb.newheader("out"); wfdb.wfdbquit(); }
/// <summary> /// Retrieves a frame of data for each signal in the group or record. /// </summary> /// <param name="frameData">Data class to be initialized and filled with data.</param> /// <param name="siArray">Signal Information array for the signals being read.</param> /// <param name="numSignals">Number of signals being read (must match the dimension of siArray).</param> /// <param name="errMsg">String where error messages, if any, are written.</param> /// <returns>True if successful, False otherwise. If False, then errMsg contains the explanation why.</returns> public static bool GetSignalFrame( ref WFDB_SampleArray frameData, WFDB_SiginfoArray siArray, int numSignals, ref string errMsg) { int numSamples; numSamples = siArray.getitem(0).spf *numSignals; errMsg = ""; try { frameData = new WFDB_SampleArray(numSamples); int result = wfdb.getframe(frameData.cast()); if (result == -1) { // End of data errMsg = "End of data reached."; return(false); } else if (result == -3) { // Failure: unexpected physical end of file errMsg = "Failure: unexpected physical end of file."; return(false); } else if (result == -4) { // Failure: checksum error (detected only at end of file) errMsg = "Failure: checksum error (detected at end of file)."; return(false); } else if (result < numSignals) { // Something wrong! We didn't get the signals we expect! errMsg = "Failure: requested " + numSignals + " signals, but only received data for " + result + "."; return(false); } // else, it's OK } catch (Exception getframeException) { while (getframeException.InnerException != null) { // Drill down: getframeException = getframeException.InnerException; } errMsg += getframeException.ToString() + newLine; MessageBox.Show("Exception occurred trying getframe(...): \n" + getframeException.ToString() + "\n"); return(false); } // No exception? Success! return(true); }
static void Main(string[] argv) { int i, nsig; if (argv.Length < 1) { Console.WriteLine("usage: example5 record"); // Unlike C programs, Java programs do not have any foolproof way // to discover their own names, so the name is given as a constant // above. The command needed to run this program within a VM // is platform-dependent and likely to be more complex. Environment.Exit(1); } nsig = wfdb.isigopen(argv[0], null, 0); if (nsig < 1) Environment.Exit(2); WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig); if (wfdb.isigopen(argv[0], s.cast(), nsig) != nsig) Environment.Exit(2); Console.WriteLine("Record {0}", argv[0]); Console.WriteLine("Starting time: {0}", wfdb.timstr(0)); Console.WriteLine("Sampling frequency: {0} Hz", wfdb.sampfreq(argv[0])); Console.WriteLine("{0} signals", nsig); for (i = 0; i < nsig; i++) { WFDB_Siginfo s_i_ = s.getitem(i); Console.WriteLine("Group {0}, Signal {1}:", s_i_.group, i); Console.WriteLine(" File: {0}", s_i_.fname); Console.WriteLine(" Description: {0}", s_i_.desc); Console.Write(" Gain: "); if ( s_i_.gain == 0.0 ) Console.Write("uncalibrated; assume {0}", wfdb.WFDB_DEFGAIN); else Console.Write(s_i_.gain); Console.WriteLine(" adu/{0}", (s_i_.units != null ? s_i_.units : "mV")); Console.WriteLine(" Initial value: {0}", s_i_.initval); Console.WriteLine(" Storage format: {0}", s_i_.fmt); Console.Write(" I/O: "); if (s_i_.bsize == 0) Console.WriteLine("can be unbuffered"); else Console.WriteLine("{0}-byte blocks", s_i_.bsize); Console.WriteLine(" ADC resolution: {0} bits", s_i_.adcres); Console.WriteLine(" ADC zero: {0}", s_i_.adczero); if (s_i_.nsamp > 0) { Console.WriteLine(" Length: {0} ({1} sample intervals)", wfdb.timstr(s_i_.nsamp), s_i_.nsamp); Console.WriteLine(" Checksum: {0}", s_i_.cksum); } else Console.WriteLine(" Length undefined"); } wfdb.wfdbquit(); }
static void Main(string[] argv) { string record = null; if (argv.Length < 2) { usage(); Environment.Exit(2); } for (int i = 0; i < argv.Length; i++) { if (argv[i] == "-r") { record = argv[++i]; } else { usage(); } } if (record == null) { usage(); Environment.Exit(2); } int nsig, n=0; nsig = wfdb.isigopen(record, null, 0); if (nsig <= 0) { usage(); Environment.Exit(2); } WFDB_SiginfoArray siarray = new WFDB_SiginfoArray(nsig); wfdb.isigopen(record, siarray.cast(), nsig); WFDB_SampleArray v = new WFDB_SampleArray(nsig); while (wfdb.getvec(v.cast()) > 0) { Console.Write(n); for (int i=0; i < nsig; i++) { Console.Write("\t" + v.getitem(i)); } Console.WriteLine(); n++; } wfdb.wfdbquit(); }
static void Main(string[] argv) { int filter, time=0, slopecrit, sign=1, maxslope=0, nsig, nslope=0, qtime=0, maxtime=0, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, ms160, ms200, s2, scmax, scmin = 0; WFDB_Anninfo a = new WFDB_Anninfo(); WFDB_Annotation annot = new WFDB_Annotation(); if (argv.Length < 1) { Console.WriteLine("usage: example10 record [threshold]"); // Unlike C programs, C# programs do not have any foolproof way // to discover their own names, so the name is given as a constant // above. The command needed to run this program within a VM // is platform-dependent and likely to be more complex. Environment.Exit(1); } a.name = "qrs"; a.stat = wfdb.WFDB_WRITE; if ((nsig = wfdb.isigopen(argv[0], null, 0)) < 1) Environment.Exit(2); WFDB_SiginfoArray s = new WFDB_SiginfoArray(nsig); WFDB_SampleArray v = new WFDB_SampleArray(nsig); if (wfdb.wfdbinit(argv[0], a, 1, s.cast(), (uint)nsig) != nsig) Environment.Exit(2); if (wfdb.sampfreq(null) < 240.0 || wfdb.sampfreq(null) > 260.0) wfdb.setifreq(250.0); if (argv.Length > 1) scmin = wfdb.muvadu(0, Int16.Parse(argv[1])); if (scmin < 1) scmin = wfdb.muvadu(0, 1000); slopecrit = scmax = 10 * scmin; ms160 = wfdb.strtim("0.16"); ms200 = wfdb.strtim("0.2"); s2 = wfdb.strtim("2"); annot.subtyp = 0; annot.chan = 0; annot.num = 0; annot.aux = null; wfdb.getvec(v.cast()); t9 = t8 = t7 = t6 = t5 = t4 = t3 = t2 = t1 = v.getitem(0); do { filter = (t0 = v.getitem(0)) + 4*t1 + 6*t2 + 4*t3 + t4 - t5 - 4*t6 - 6*t7 - 4*t8 - t9; if (time % s2 == 0) { if (nslope == 0) { slopecrit -= slopecrit >> 4; if (slopecrit < scmin) slopecrit = scmin; } else if (nslope >= 5) { slopecrit += slopecrit >> 4; if (slopecrit > scmax) slopecrit = scmax; } } if (nslope == 0 && Math.Abs(filter) > slopecrit) { nslope = 1; maxtime = ms160; sign = (filter > 0) ? 1 : -1; qtime = time; } if (nslope != 0) { if (filter * sign < -slopecrit) { sign = -sign; maxtime = (++nslope > 4) ? ms200 : ms160; } else if (filter * sign > slopecrit && Math.Abs(filter) > maxslope) maxslope = Math.Abs(filter); if (maxtime-- < 0) { if (2 <= nslope && nslope <= 4) { slopecrit += ((maxslope>>2) - slopecrit) >> 3; if (slopecrit < scmin) slopecrit = scmin; else if (slopecrit > scmax) slopecrit = scmax; annot.time = wfdb.strtim("i") - (time - qtime) - 4; annot.anntyp = wfdb.NORMAL; wfdb.putann(0, annot); time = 0; } else if (nslope >= 5) { annot.time = wfdb.strtim("i") - (time - qtime) - 4; annot.anntyp = wfdb.ARFCT; wfdb.putann(0, annot); } nslope = 0; } } t9 = t8; t8 = t7; t7 = t6; t6 = t5; t5 = t4; t4 = t3; t3 = t2; t2 = t1; t1 = t0; time++; } while (wfdb.getvec(v.cast()) > 0); wfdb.wfdbquit(); }