// File: example1.java       I. Henry    February 18 2005
//			Last revised:	 11 March 2006 (GBM)
// Java translation of example1.c from the WFDB Programmer's Guide
//
// Copyright (C) 2005 Isaac C. Henry (ihenry@physionet.org)

import java.io.*;
import wfdb.*;

public class example1 {
	
    static {
	System.loadLibrary("wfdbjava"); 
    }
    
    public static void main(String argv[]) {
		
	WFDB_AnninfoArray an = new WFDB_AnninfoArray(2);
	String record = null, iann = null, oann = null;
	WFDB_Annotation annot =  new WFDB_Annotation();
	BufferedReader stdin =
	    new BufferedReader(new InputStreamReader(System.in));

	try {
	    System.out.print("Type record name: ");
	    record = stdin.readLine();
	    System.out.print("Type input annotator name: ");
	    iann = stdin.readLine();
	    System.out.print("Type output annotator name: ");
	    oann =  stdin.readLine();
	} catch(IOException e) {
	    System.out.println("IO Exception");
	}

	WFDB_Anninfo a = an.getitem(0);
	a.setName(iann); a.setStat(wfdb.WFDB_READ);
	an.setitem(0,a);
	a = an.getitem(1);
	a.setName(oann); a.setStat(wfdb.WFDB_WRITE);
	an.setitem(1,a);
	
	if ( wfdb.annopen(record, an.cast(), 2) < 0 ) System.exit(1);
	while (wfdb.getann(0, annot) == 0)
	    if (wfdb.wfdb_isqrs(annot.getAnntyp()) != 0) {
		annot.setAnntyp(wfdb.NORMAL);
		if (wfdb.putann(0, annot) < 0) break;
	    }

	wfdb.wfdbquit();
    }
}
