static void Main(string[] argv) { WFDB_Anninfo a = new WFDB_Anninfo(); WFDB_Annotation annot = new WFDB_Annotation(); if (argv.Length < 2) { Console.WriteLine( "usage: example3 annotator 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); } a.name = argv[0]; a.stat = wfdb.WFDB_READ; wfdb.sampfreq(argv[1]); if (wfdb.annopen(argv[1], a, 1) < 0) Environment.Exit(2); while (wfdb.getann(0, annot) == 0) Console.WriteLine(wfdb.timstr(-annot.time) + " (" + annot.time + ") " + wfdb.annstr(annot.anntyp) + " "+ annot.subtyp + " " + annot.chan + " " + annot.num + " " + (annot.aux == null ? "" : annot.aux.Substring(1))); 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) { int stat; String record = null, annotator = null; if (argv.Length < 4) { usage(); Environment.Exit(2); } for (int i = 0; i < argv.Length; i++) { if (argv[i] == "-r") { record = argv[++i]; } else if (argv[i] == "-a") { annotator = argv[++i]; } else { usage(); } } if (record == null || annotator == null) { usage(); Environment.Exit(2); } WFDB_AnninfoArray aiarray = new WFDB_AnninfoArray(1); WFDB_Anninfo ai = new WFDB_Anninfo(); WFDB_Annotation annot = new WFDB_Annotation(); ai.name = annotator; ai.stat = wfdb.WFDB_READ; aiarray.setitem(0,ai); stat = wfdb.annopen(record, aiarray.cast(), 1); if (stat < 0) { usage(); Environment.Exit(2); } while (wfdb.getann(0, annot) == 0 ) { Console.WriteLine(wfdb.mstimstr(-annot.time) + "\t" + annot.time + "\t" + wfdb.annstr(annot.anntyp) + "\t" + annot.subtyp + "\t" + annot.chan + "\t" + annot.num + "\t" + // print the aux string, excluding the first // char, which is the length of the string (annot.aux == null ? "" : annot.aux.Substring(1))); } wfdb.wfdbquit(); }
/// <summary> /// Opens a SINGLE annotation (closing any other open annotations), according to /// the passed parameters, and initializing and returning a WFDB_AnninfoArray object. /// </summary> /// <param name="record">Name of the record whose annotation we are opening.</param> /// <param name="aiArray">Annotation Info array (one element), built and populated /// by this method.</param> /// <param name="annotName">Name (i.e., file extension) of the Annotation.</param> /// <param name="openForRead">True to open for reading, False to open for writing.</param> /// <param name="errMsg">Contains any error messages relevant to failed execution.</param> /// <returns>True if successful, False if failed. If failed, the cause is in errMsg.</returns> public static bool OpenAnnotation( string record, ref WFDB_AnninfoArray aiArray, string annotName, bool openForRead, ref string errMsg) { try { aiArray = new WFDB_AnninfoArray(1); WFDB_Anninfo annInfo = new WFDB_Anninfo(); annInfo.name = annotName; if (openForRead) { annInfo.stat = wfdb.WFDB_READ; } else { annInfo.stat = wfdb.WFDB_WRITE; } aiArray.setitem(0, annInfo); wfdb.annopen(record, aiArray.cast(), 1); } catch (Exception annopenException) { while (annopenException.InnerException != null) { // Drill down: annopenException = annopenException.InnerException; } errMsg += annopenException.ToString() + newLine; MessageBox.Show("Exception occurred trying annopen(...): \n" + annopenException.ToString() + "\n"); return(false); } // No exception? Success! return(true); }
static void Main(string[] argv) { int rr, rrmax, t; WFDB_Anninfo a = new WFDB_Anninfo(); WFDB_Annotation annot = new WFDB_Annotation(); if (argv.Length < 2) { Console.WriteLine("usage: example4 annotator record\n"); // 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 (wfdb.annopen(argv[1], a, 1) < 0) Environment.Exit(2); if ((rrmax = (int)(3*wfdb.sampfreq(argv[1]))) <= 0) Environment.Exit(3); int[] rrhist = new int[rrmax+1]; while (wfdb.getann(0, annot) == 0 && wfdb.wfdb_isqrs(annot.anntyp) == 0) // Note that C# cannot cast an int (such as that returned by // isqrs) to a boolean, so omitting the comparison to 0, as in // other translations of this code, does not work in this case. ; t = annot.time; while (wfdb.getann(0, annot) == 0) if (wfdb.wfdb_isqrs(annot.anntyp) != 0) { if ((rr = annot.time - t) > rrmax) rr = rrmax; rrhist[rr]++; t = annot.time; } for (rr = 1; rr < rrmax; rr++) Console.WriteLine("{0,4} {1}", rrhist[rr], wfdb.mstimstr(rr)); Console.WriteLine("{0,4} {1} (or longer)", rrhist[rr], wfdb.mstimstr(rr)); 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(); }