// Logiscope Instrumentation function
// Copyright (c) Kalimetrix 2014

// This file is an example of Intrumentation function
// generated traces in the result<I>.trc file where 
// <I> is number of an unexisting file.

package jv;


import java.io.*  ;
import java.lang.*;
import java.net.*;

public class VlgTrace
{
    static File file;	 
    static OutputStream output;
    static PrintWriter pw = null;
    static VlgTrace me = new VlgTrace();
    	
    // Class creator: 
    public VlgTrace() {
        try {
	    String fileBody= "result";
    	    String fileExt = ".trc";
   	    String fileName;
   	    int count = 0;
	     	
	    do {
		count++;
		fileName = fileBody+String.valueOf(count)+fileExt;
		file = new File(fileName);
	    } while(file.exists());

            output = new FileOutputStream(fileName);
            pw = new PrintWriter(output);
            pw.print('N');
            pw.print('\n');
            pw.flush();
        }
        
        catch (IOException io) {
            output = null;
            pw = null;
            System.out.println("IO Exception");
        }
    }

    // close the stream
    protected synchronized void finalize() throws Throwable {
        if (pw == null) return;

        pw.flush();
        pw.close();
        pw = null;
        try {
            output.close();
        }
        catch ( IOException ie) {
        }
        output = null;
    }

    static public synchronized void ddp1(String name, String date)
    {
        if (pw == null) return;
        pw.print(1);
        pw.print('\n');
        pw.print(name);
        pw.print('\n');
        pw.print(date);
        pw.print('\n');

        pw.flush();
    }
    static public synchronized boolean cond(String name, boolean cond, int ddp_true, int ddp_false)
    {
        if (pw == null) return cond;
        pw.print("X");
        pw.print('\n');
        pw.print(name);
        pw.print('\n');

        if(cond)
           pw.print(ddp_true);
        else
           pw.print(ddp_false);
        pw.print('\n');
        pw.flush();
        return  cond;
    }

    static public synchronized void ddp(String name, int ddp)
    {
        if (pw == null) return;
        pw.print("X");
        pw.print('\n');
        pw.print(name);
        pw.print('\n');
        pw.print(ddp);
        pw.print('\n');
        pw.flush();
    }
}