using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Runtime.InteropServices; // needed for DllImport and for Marshal.Copy
using System.Text; // needed for StringBuilder Class
using System.IO;
using System.Reflection; //needed for program_file_path


// Please read the included file "important_notes_for_VS2010_and_NET4_users_NIST_library_for_Windows_32-bit.txt"


namespace nist_demo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox picture;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private System.Windows.Forms.Button ReadAndExportButton;
		private System.Windows.Forms.Button RegisterButton;
		private System.Windows.Forms.Button ReadAndModifyButton;
		private System.Windows.Forms.Button ReadSingleFieldButton;
		private System.Windows.Forms.Button DeleteSingleFieldButton;
		private System.Windows.Forms.Button CreateAndInsertButton;


        Int32 idc_current;
        Int32 idc;
        int size_of_byte_array;
        byte[] byte_array;
        IntPtr byte_array_ptr;
        String nist_txt_field;
        IntPtr ptr_nist_txt_field;
        IntPtr nist_binary_field;
        Int32 nist_int_field;
        Int32 type2_number_of_records;
        Int32 type3_number_of_records;
        Int32 type4_number_of_records;
        Int32 type5_number_of_records;
        Int32 type6_number_of_records;
        Int32 type7_number_of_records;
        Int32 type8_number_of_records;
        Int32 type9_number_of_records;
        Int32 type10_number_of_records;
        Int32 type11_number_of_records;
        Int32 type12_number_of_records;
        Int32 type13_number_of_records;
        Int32 type14_number_of_records;
        Int32 type15_number_of_records;
        Int32 type16_number_of_records;
        Int32 type17_number_of_records;
        Int32 type18_number_of_records;
        Int32 type19_number_of_records;
        Int32 type20_number_of_records;
        Int32 type21_number_of_records;
        Int32 type22_number_of_records;
        Int32 type98_number_of_records;
        Int32 type99_number_of_records;
        FileStream fStream;
        BinaryReader br;
        BinaryWriter bw;
        IntPtr hBitmap;
        String program_file_path;
        String filedirectory;
        String filename;
        String output_message;

        Int32 traditional_or_xml_format;

        OpenFileDialog ofd = new OpenFileDialog();
        FileInfo fInfo;
        private UTF8Encoding utf8 = new UTF8Encoding();
        private System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        String image_compression_code;
        IntPtr ptr_image_compression_code;



        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _RegisterNIST();

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _CreateNewNISTFile();

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _WriteNISTToFile(byte[] filename);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadNISTByteArray();

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfNISTByteArray();

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadNISTFromFile(byte[] filename);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadNISTFromMemory(byte[] byte_array, Int32 size_of_byte_array);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _CheckIfRecordTypeExists(Int32 record_type_number);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadNumberOfRecords(Int32 record_type_number);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadIDCofRecord(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadRecordTxtField(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfRecordTxtField(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadRecordTxtFieldName(Int32 record_type_number, Int32 idc, Int32 record_field_number);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfRecordTxtFieldName(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadRecordTxtFieldDescription(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfRecordTxtFieldDescription(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadRecordExportedTxtFields(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfRecordExportedTxtFields(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadRecordBinaryField(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _ReadSizeOfRecordBinaryField(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _CreateHBITMAPfromRecordBinaryField(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _InsertRecordBinaryFieldFromFile(Int32 record_type_number, Int32 idc, byte[] filename);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _InsertRecordBinaryFieldFromMemory(Int32 record_type_number, Int32 idc, byte[] input_byte_array, Int32 sizeofinputbytearray, byte[] CGA, Int32 CGAint, Int32 HLL, Int32 VLL);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _InsertRecordTxtField(Int32 record_type_number, Int32 idc, Int32 record_field_number, byte[] record_field_name, byte[] input_data);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _DeleteRecord(Int32 record_type_number, Int32 idc);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _SetNISTLibErrorReportMode(Int32 nist_error_report_mode);

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr _ReadNISTLibLastErrorMessage();

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _SetNISTLibTryToDecodeBinaryField(Int32 try_to_decode_binary_field);		

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 _SetAnsiNistItlVersion(Int32 version_year, Int32 traditional_or_xml);





		public Form1()
		{
            // Required for Windows Form Designer support
            InitializeComponent();
			
            // TODO: Add any constructor code after InitializeComponent call
            hBitmap = IntPtr.Zero;

            ofd.Filter = "All NIST files|*.nist;*.an2;*.eft;*.xml|NIST files (*.nist)|*.nist|AN2 files (*.an2)|*.an2|EFT files (*.eft)|*.eft|NIEM-conformant XML files (*.xml)|*.xml|All files (*.*)|*.*";


            // Gets full filename of the program
            Assembly mainAssembly = Assembly.GetExecutingAssembly();
            // Set output directory
            program_file_path = Path.GetDirectoryName(mainAssembly.Location);

            traditional_or_xml_format = 0; // traditional format	
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
	if( disposing )
	{
		if (components != null) 
		{
			components.Dispose();
		}
	}
	base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.ReadAndExportButton = new System.Windows.Forms.Button();
			this.RegisterButton = new System.Windows.Forms.Button();
			this.picture = new System.Windows.Forms.PictureBox();
			this.ReadSingleFieldButton = new System.Windows.Forms.Button();
			this.ReadAndModifyButton = new System.Windows.Forms.Button();
			this.DeleteSingleFieldButton = new System.Windows.Forms.Button();
			this.CreateAndInsertButton = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// ReadAndExportButton
			// 
			this.ReadAndExportButton.Location = new System.Drawing.Point(288, 312);
			this.ReadAndExportButton.Name = "ReadAndExportButton";
			this.ReadAndExportButton.Size = new System.Drawing.Size(120, 32);
			this.ReadAndExportButton.TabIndex = 2;
			this.ReadAndExportButton.Text = "Read and Export";
			this.ReadAndExportButton.Click += new System.EventHandler(this.ReadAndExportButton_Click);
			// 
			// RegisterButton
			// 
			this.RegisterButton.Location = new System.Drawing.Point(288, 360);
			this.RegisterButton.Name = "RegisterButton";
			this.RegisterButton.Size = new System.Drawing.Size(120, 32);
			this.RegisterButton.TabIndex = 5;
			this.RegisterButton.Text = "Register";
			this.RegisterButton.Click += new System.EventHandler(this.RegisterButton_Click);
			// 
			// picture
			// 
			this.picture.Location = new System.Drawing.Point(16, 16);
			this.picture.Name = "picture";
			this.picture.TabIndex = 4;
			this.picture.TabStop = false;
			// 
			// ReadSingleFieldButton
			// 
			this.ReadSingleFieldButton.Location = new System.Drawing.Point(16, 360);
			this.ReadSingleFieldButton.Name = "ReadSingleFieldButton";
			this.ReadSingleFieldButton.Size = new System.Drawing.Size(120, 32);
			this.ReadSingleFieldButton.TabIndex = 3;
			this.ReadSingleFieldButton.Text = "Read Single Field";
			this.ReadSingleFieldButton.Click += new System.EventHandler(this.ReadSingleFieldButton_Click);
			// 
			// ReadAndModifyButton
			// 
			this.ReadAndModifyButton.Location = new System.Drawing.Point(152, 312);
			this.ReadAndModifyButton.Name = "ReadAndModifyButton";
			this.ReadAndModifyButton.Size = new System.Drawing.Size(120, 32);
			this.ReadAndModifyButton.TabIndex = 1;
			this.ReadAndModifyButton.Text = "Read and Modify";
			this.ReadAndModifyButton.Click += new System.EventHandler(this.ReadAndModifyButton_Click);
			// 
			// DeleteSingleFieldButton
			// 
			this.DeleteSingleFieldButton.Location = new System.Drawing.Point(152, 360);
			this.DeleteSingleFieldButton.Name = "DeleteSingleFieldButton";
			this.DeleteSingleFieldButton.Size = new System.Drawing.Size(120, 32);
			this.DeleteSingleFieldButton.TabIndex = 4;
			this.DeleteSingleFieldButton.Text = "Delete Single Field";
			this.DeleteSingleFieldButton.Click += new System.EventHandler(this.DeleteSingleFieldButton_Click);
			// 
			// CreateAndInsertButton
			// 
			this.CreateAndInsertButton.Location = new System.Drawing.Point(16, 312);
			this.CreateAndInsertButton.Name = "CreateAndInsertButton";
			this.CreateAndInsertButton.Size = new System.Drawing.Size(120, 32);
			this.CreateAndInsertButton.TabIndex = 0;
			this.CreateAndInsertButton.Text = "Create and Insert";
			this.CreateAndInsertButton.Click += new System.EventHandler(this.CreateAndInsertButton_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(424, 405);
			this.Controls.Add(this.CreateAndInsertButton);
			this.Controls.Add(this.DeleteSingleFieldButton);
			this.Controls.Add(this.ReadAndModifyButton);
			this.Controls.Add(this.ReadSingleFieldButton);
			this.Controls.Add(this.RegisterButton);
			this.Controls.Add(this.ReadAndExportButton);
			this.Controls.Add(this.picture);
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "NIST Library Demo";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
	Application.Run(new Form1());
		}




        private void RegisterButton_Click(object sender, EventArgs e)
        {
            _RegisterNIST();
        }



        private void CreateAndInsertButton_Click(object sender, EventArgs e)
        {

            CreateAndInsertButton.Enabled = false;
            ReadAndModifyButton.Enabled = false;
            ReadAndExportButton.Enabled = false;
            ReadSingleFieldButton.Enabled = false;
            DeleteSingleFieldButton.Enabled = false;
            RegisterButton.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;


            // In function _SetAnsiNistItlVersion(int version_year, int traditional_or_xml)
            // first argument denotes version year of ANSI/NIST-ITL standard, possible values: 1986, 1993, 1997, 2000, 2007, 2009, 2011, 2013, 2015
            // second argument denotes nist file format. 0 denotes traditional format, 1 denotes NIEM-conformant XML format.

            traditional_or_xml_format = 0; // traditional format
            // traditional_or_xml_format = 1; // NIEM-conformant XML format
            _SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format


            // Creates new empty NIST file
            _CreateNewNISTFile();


            // ======================================================
            MessageBox.Show("Inserting/replacing Type-1 and Type-2 records...");

            // Type-1 record Logical record length (LEN) field is handled automatically
            // and the value of the utf8.GetBytes("LEN") field cannot be changed manually.
            // _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("LEN"), "100");

            // You can modify value of Type-1 record Version number (VER) field, however please keep in mind that
            // the entry in utf8.GetBytes("VER") field for ANSI/NIST-ITL 1-2000 approved standard must be "0300".
            // _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("VER"), "0300");
            // or
            // _InsertRecordTxtField(1, -1, 2, utf8.GetBytes(""), "0300");


            // Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TOT"), utf8.GetBytes("IMG"));

            // Modifies NIST file, inserts/replaces Type-1 record date (DAT)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("20081031")); }
            else
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("2008-10-31")); }

            // Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
            // The length of Priority (PRY) field must be equal to 1 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("PRY"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAI"), utf8.GetBytes("Central Police Station"));

            // Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("ORI"), utf8.GetBytes("Local Police Station"));

            // Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TCN"), utf8.GetBytes("000045321"));

            // Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TCR"), utf8.GetBytes("0000078901"));

            // Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
            // The length of Native scanning resolution(NSR) field must be equal to 5 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("NSR"), utf8.GetBytes("19.69"));

            // Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
            // The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("NTR"), utf8.GetBytes("19.69"));

            // Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DOM"), utf8.GetBytes("NORAM"));

            // Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
            // The length of Greenwich mean time (GMT) field must be equal to 15 bytes
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("20081031152345Z")); }
            else
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("2008-10-31T15:23:45Z")); }


            // Modifies NIST file, inserts three Type-2 records,
            // if these records already exist then they are overwritten and replaced

            // Inserts first Type-2 record
            idc_current = _InsertRecordTxtField(2, -1, 30, utf8.GetBytes(""), utf8.GetBytes("James Clerk"));
            _InsertRecordTxtField(2, idc_current, 31, utf8.GetBytes(""), utf8.GetBytes("Maxwell"));
            _InsertRecordTxtField(2, idc_current, 32, utf8.GetBytes(""), utf8.GetBytes("Berlin, Germany"));

            // Inserts second Type-2 record
            idc_current = _InsertRecordTxtField(2, -1, 30, utf8.GetBytes(""), utf8.GetBytes("John Smith"));
            _InsertRecordTxtField(2, idc_current, 31, utf8.GetBytes(""), utf8.GetBytes("Watson"));
            _InsertRecordTxtField(2, idc_current, 32, utf8.GetBytes(""), utf8.GetBytes("London, UK"));

            // Inserts third Type-2 record
            idc_current = _InsertRecordTxtField(2, -1, 30, utf8.GetBytes(""), utf8.GetBytes("Alphonse Gabriel"));
            _InsertRecordTxtField(2, idc_current, 31, utf8.GetBytes(""), utf8.GetBytes("Al Capone"));
            _InsertRecordTxtField(2, idc_current, 32, utf8.GetBytes(""), utf8.GetBytes("New York, USA"));



            // Sets input directory as "input" subdirectory of the program location
            filedirectory = program_file_path + "\\input\\";


            MessageBox.Show("Inserting/replacing Type-4 records...");

            // Modifies NIST file, inserts 14 Type-4 records (inserts 14 fingerprint WSQ images).
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type4_01.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("10"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));



            filename = filedirectory + "type4_02.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("9"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_03.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("8"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_04.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("7"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_05.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("6"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_06.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("5"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_07.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("4"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));



            filename = filedirectory + "type4_08.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("3"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_09.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("2"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_10.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("1"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_11.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("14"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_12.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("13"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_13.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("12"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_14.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, -1, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("11"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));   




            // Fields of the Type-7 logical record are user-defined.
            // Individual fields required for a given transaction, such as field description,
            // size, and content shall conform to the specifications set forth by the agency
            // to whom the transmission is being sent.
            // "NIST library" uses Interpol Implementation of the Type-7 logical record,
            // prepared by The Interpol AFIS Expert Group, version No. 4.22b – October 28, 2005
            MessageBox.Show("Inserting/replacing Type-7 records...");

            // Modifies NIST file, inserts Type-7 records.    
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type7_01.jpg";
            idc_current = _InsertRecordBinaryFieldFromFile(7, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("1"));
            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMD"), utf8.GetBytes("25"));
            // PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "PCN", "0000000000");
            // IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "IMR", "00000000000");
            // HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "GCA", utf8.GetBytes("3"));

            filename = filedirectory + "type7_02.jpg";
            idc_current = _InsertRecordBinaryFieldFromFile(7, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("1"));
            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMD"), utf8.GetBytes("26"));
            // PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "PCN", "0000000000");
            // IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "IMR", "00000000000");
            // HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "GCA", utf8.GetBytes("3"));

            filename = filedirectory + "type7_03.jpg";
            idc_current = _InsertRecordBinaryFieldFromFile(7, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("1"));
            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMD"), utf8.GetBytes("21"));
            // PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "PCN", "0000000000");
            // IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "IMR", "00000000000");
            // HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "GCA", utf8.GetBytes("3"));


            filename = filedirectory + "type7_04.jpg";
            idc_current = _InsertRecordBinaryFieldFromFile(7, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("1"));
            _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("IMD"), utf8.GetBytes("22"));
            // PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "PCN", "0000000000");
            // IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "IMR", "00000000000");
            // HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(7, idc_current, -1, "GCA", utf8.GetBytes("3"));



            MessageBox.Show("Inserting/replacing Type-8 records...");

            // Modifies NIST file, inserts Type-8 records.    
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type8_01.bin";
            idc_current = _InsertRecordBinaryFieldFromFile(8, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("SIG"), utf8.GetBytes("0"));
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("SRT"), utf8.GetBytes("0"));
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("HLL"), utf8.GetBytes("1000"));
            // VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("VLL"), utf8.GetBytes("500"));


            filename = filedirectory + "type8_02.bin";
            idc_current = _InsertRecordBinaryFieldFromFile(8, -1, utf8.GetBytes(filename));

            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("SIG"), utf8.GetBytes("1"));
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("SRT"), utf8.GetBytes("0"));
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("HLL"), utf8.GetBytes("1000"));
            // VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
            _InsertRecordTxtField(8, idc_current, -1, utf8.GetBytes("VLL"), utf8.GetBytes("500"));




            MessageBox.Show("Inserting/replacing Type-10 records...");

            // Modifies NIST file, inserts Type-10 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced


            filename = filedirectory + "type10_01.jpg";
            // filename = filedirectory + "type10_01.png";
            // filename = filedirectory + "type10_01.jp2";   

            idc_current = _InsertRecordBinaryFieldFromFile(10, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("FACE"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("300"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("300"));

            // "NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CGA"), "JPEGB");

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)   
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("RGB"));
            // _InsertRecordTxtField(10, idc_current, 12, utf8.GetBytes(""), utf8.GetBytes("RGB"));

            // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("POS"), utf8.GetBytes("F"));  // Full Face Frontal


            // filename = filedirectory + "type10_02.jpg";
            filename = filedirectory + "type10_02.png";
            // filename = filedirectory + "type10_02.jp2";

            idc_current = _InsertRecordBinaryFieldFromFile(10, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("FACE"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("300"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("300"));

            // "NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CGA"), "PNG");

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)   
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("RGB"));
            // _InsertRecordTxtField(10, idc_current, 12, utf8.GetBytes(""), utf8.GetBytes("RGB"));

            // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("POS"), utf8.GetBytes("R"));  // Right Profile


            // filename = filedirectory + "type10_03.jpg";
            // filename = filedirectory + "type10_03.png";
            filename = filedirectory + "type10_03.jp2";


            idc_current = _InsertRecordBinaryFieldFromFile(10, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("FACE"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("300"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("300"));

            // "NIST library" inserts CGA value "JP2" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CGA"), "JP2");

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)   
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("RGB"));
            // _InsertRecordTxtField(10, idc_current, 12, utf8.GetBytes(""), utf8.GetBytes("RGB"));

            // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("POS"), utf8.GetBytes("A"));  // Angled Pose



            MessageBox.Show("Inserting/replacing Type-13 records...");

            // Modifies NIST file, inserts Type-13 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type13_01.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(13, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Impression type (IMP)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("6"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Source agency / ORI (SRC)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("MDNISTVIP"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Latent capture date (LCD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("LCD"), utf8.GetBytes("19990707")); }
            else
            { _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("LCD"), utf8.GetBytes("1999-07-07")); }

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Scale units (SLC)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("2"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-13 record, based on filename *.wsq extension, here you can overwrite it with new value if needed   
            // _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("CGA") , "WSQ20");

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Bits per pixel (BPX)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-13 record Finger / palm position (FGP)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("FGP"), utf8.GetBytes("8"));



            MessageBox.Show("Inserting/replacing Type-14 records...");

            // Modifies NIST file, inserts Type-14 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type14_01.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(14, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("MDNISTVIP"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("19990707")); }
            else
            { _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("1999-07-07")); }

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("2"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-14 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("CGA") , "WSQ20");

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("FGP"), utf8.GetBytes("8"));



            MessageBox.Show("Inserting/replacing Type-15 records...");

            // Modifies NIST file, inserts Type-15 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced   


            filename = filedirectory + "type15_01.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(15, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("10"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value utf8.GetBytes("WSQ")
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("CGA"), utf8.GetBytes("WSQ"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PLP"), utf8.GetBytes("24"));



            filename = filedirectory + "type15_02.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(15, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("10"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)   
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value utf8.GetBytes("WSQ")   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("CGA"), utf8.GetBytes("WSQ"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PLP"), utf8.GetBytes("25"));


            filename = filedirectory + "type15_03.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(15, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("10"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value utf8.GetBytes("WSQ")   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("CGA"), utf8.GetBytes("WSQ"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PLP"), utf8.GetBytes("27"));



            MessageBox.Show("Inserting/replacing Type-16 records...");

            // Modifies NIST file, inserts Type-16 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type16_01.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(16, -1, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("500"));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-16 record, based on filename *.wsq extension, here you overwrite it with new value utf8.GetBytes("WSQ")   
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("CGA"), utf8.GetBytes("WSQ"));

            // Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("A01"));

            // ======================================================



            // Sets output file name as "sample_new.nist" (in "output" subdirectory)
            filedirectory = program_file_path + "\\output\\";
            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }

            if (traditional_or_xml_format == 0)
            { filename = filedirectory + "sample_new.nist"; }
            else
            { filename = filedirectory + "sample_new.xml"; }


            // Saves NIST into the file "sample_new.nist" (in "output" subdirectory)
            _WriteNISTToFile(utf8.GetBytes(filename));

            /*
                        // Instead function _WriteNISTToFile you can use function _ReadNISTByteArray and save NIST byte array manually (the code bellow)
                        // ==========================
                        byte_array_ptr = _ReadNISTByteArray();
                        size_of_byte_array = _ReadSizeOfNISTByteArray();

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(byte_array_ptr, byte_array, 0, size_of_byte_array);

                        FileStream fStream = new FileStream(filename, FileMode.Create);
                        BinaryWriter bw = new BinaryWriter(fStream);

                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();
                        // ==========================
            */

            if (traditional_or_xml_format == 0)
            { MessageBox.Show("New NIST file was created, modified and saved as\n\".\\output\\sample_new.nist\"\n\nPlease use \"NIST viewer\" to view\n\"sample_new.nist\" file."); }
            else
            { MessageBox.Show("New NIST file was created, modified and saved as\n\".\\output\\sample_new.xml\"\n\nPlease use \"NIST viewer\" to view\n\"sample_new.xml\" file."); }



            CreateAndInsertButton.Enabled = true;
            ReadAndModifyButton.Enabled = true;
            ReadAndExportButton.Enabled = true;
            ReadSingleFieldButton.Enabled = true;
            DeleteSingleFieldButton.Enabled = true;
            RegisterButton.Enabled = true;
            Cursor.Current = Cursors.Default;

        }

        private void ReadAndModifyButton_Click(object sender, EventArgs e)
        {

            CreateAndInsertButton.Enabled = false;
            ReadAndModifyButton.Enabled = false;
            ReadAndExportButton.Enabled = false;
            ReadSingleFieldButton.Enabled = false;
            DeleteSingleFieldButton.Enabled = false;
            RegisterButton.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;


            traditional_or_xml_format = 0; // traditional format
             // traditional_or_xml_format = 1; // NIEM-conformant XML format
            _SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format


            // Sets input file name as "sample.nist" which located in "input" subdirectory
            filedirectory = program_file_path + "\\input\\";

            if (traditional_or_xml_format == 0)
            { filename = filedirectory + "sample.nist"; }
            else
            { filename = filedirectory + "sample_NIEM_conformant_XML.xml"; }

            if (!File.Exists(filename))
            {
                if (traditional_or_xml_format == 0)
                { MessageBox.Show("Error: file .\\input\\sample.nist does not exist."); }
                else
                { MessageBox.Show("Error: file .\\input\\sample_NIEM_conformant_XML.xml does not exist."); }
                return;
            }


            // Reads NIST file
            _ReadNISTFromFile(utf8.GetBytes(filename));


            // Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TOT"), utf8.GetBytes("WSQ"));

            // Modifies NIST file, inserts/replaces Type-1 record Date (DAT)
            if (traditional_or_xml_format == 0)
            {_InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("20080931"));}
            else
            {_InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("2008-09-31"));}		

            // Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
            // The length of Priority (PRY) field must be equal to 1 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("PRY"), utf8.GetBytes("2"));

            // Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAI"), utf8.GetBytes("Central Intelligence Agency"));

            // Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("ORI"), utf8.GetBytes("Police Station"));

            // Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TCN"), utf8.GetBytes("000000123"));

            // Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("TCR"), utf8.GetBytes("000000987"));

            // Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
            // The length of Native scanning resolution(NSR) field must be equal to 5 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("NSR"), utf8.GetBytes("21.33"));

            // Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
            // The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("NTR"), utf8.GetBytes("21.33"));

            // Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DOM"), utf8.GetBytes("NORAM"));

            // Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
            // The length of Greenwich mean time (GMT) field must be equal to 15 bytes

            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("20080931170316Z")); } 
            else
            { _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("2008-09-31T17:03:16Z")); }


            // Modifies NIST file, inserts two Type-2 records,
            // if these records already exist then they are overwritten and replaced
            idc = 0;
            _InsertRecordTxtField(2, idc, 30, utf8.GetBytes(""), utf8.GetBytes("William Thompson"));
            _InsertRecordTxtField(2, idc, 31, utf8.GetBytes(""), utf8.GetBytes("Kelvin"));



            // Sets input directory as "input" subdirectory of the program location
            filedirectory = program_file_path + "\\input\\";


            // Modifies NIST file, inserts Type-4 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type4_left_thumb.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, 7, utf8.GetBytes(filename));


            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("6"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));


            filename = filedirectory + "type4_right_thumb.wsq";
            idc_current = _InsertRecordBinaryFieldFromFile(4, 12, utf8.GetBytes(filename));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("3"));
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP1"), utf8.GetBytes("1"));
            // FGP2 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP2"), "255");
            // FGP3 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP3"), "255");
            // FGP4 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP4"), "255");
            // FGP5 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP5"), "255");
            // FGP6 value of "255" was already inserted by default when creating Type-4 record
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("FGP6"), "255");
            _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("ISR"), utf8.GetBytes("1"));
            // HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("HLL"), "0");
            // VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, utf8.GetBytes("VLL"), "0");
            // "NIST library" inserts GCA value utf8.GetBytes("1") automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(4, idc_current, -1, "GCA", utf8.GetBytes("1"));



            // Modifies NIST file, inserts Type-10 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type10_Charles_Luciano_frontal.jpg";


            idc_current = _InsertRecordBinaryFieldFromFile(10, 23, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("FACE"));
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("SCAR"));


            // Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("300"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("300"));

            // "NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CGA"), "JPEGB");

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)   
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("RGB"));
            // _InsertRecordTxtField(10, idc_current, 12, utf8.GetBytes(""), utf8.GetBytes("RGB"));

            // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("POS"), utf8.GetBytes("F"));  // Full Face Frontal




            filename = filedirectory + "type10_Charles_Luciano_profile.jpg";

            idc_current = _InsertRecordBinaryFieldFromFile(10, 24, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("IMT"), utf8.GetBytes("FACE"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217")); }
            else
            { _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("2009-12-17")); }

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("1"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("300"));

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("300"));

            // "NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CGA"), "JPG");

            // Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)   
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("CSP"), utf8.GetBytes("RGB"));
            // _InsertRecordTxtField(10, idc_current, 12, utf8.GetBytes(""), utf8.GetBytes("RGB"));

            // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("POS"), utf8.GetBytes("R"));  // Right Profile


            // Modifies NIST file, inserts Type-14 records.
            // If the record with specified IDC number already exists in *.nist file,
            // then existing old record is overwritten and replaced

            filename = filedirectory + "type14_replace_01.wsq";

            idc_current = _InsertRecordBinaryFieldFromFile(14, 27, utf8.GetBytes(filename));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("IMP"), utf8.GetBytes("0"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("SRC"), utf8.GetBytes("Cognaxon"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
            if (traditional_or_xml_format == 0)
            { _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("19990923")); }
            else
            { _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("1999-09-23")); }

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("SLC"), utf8.GetBytes("2"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (THPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("THPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (TVPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TVPS"), utf8.GetBytes("197"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
            // "NIST library" inserts CGA value "WSQ20" automatically when creating Type-14 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
            // _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("CGA") ,"WSQ20");

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("BPX"), utf8.GetBytes("8"));

            // Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("FGP"), utf8.GetBytes("14"));





            // Sets output file name as "sample_modified.nist" (in "output" subdirectory)
            filedirectory = program_file_path + "\\output\\";
            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }

            if (traditional_or_xml_format == 0)
            { filename = filedirectory + "sample_modified.nist"; }
            else
            { filename = filedirectory + "sample_modified.xml"; }


            // Saves NIST into the file "sample_modified.nist" (in "output" subdirectory)
            _WriteNISTToFile(utf8.GetBytes(filename));

            if (traditional_or_xml_format == 0)
            { MessageBox.Show("NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_modified.nist\"\n\nPlease use \"NIST viewer\" to see changes in\n\"sample_modified.nist\" file."); }
            else
            { MessageBox.Show("NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_modified.xml\"\n\nPlease use \"NIST viewer\" to see changes in\n\"sample_modified.xml\" file."); }



            CreateAndInsertButton.Enabled = true;
            ReadAndModifyButton.Enabled = true;
            ReadAndExportButton.Enabled = true;
            ReadSingleFieldButton.Enabled = true;
            DeleteSingleFieldButton.Enabled = true;
            RegisterButton.Enabled = true;
            Cursor.Current = Cursors.Default;

        }

        private void ReadAndExportButton_Click(object sender, EventArgs e)
        {


            ofd.FilterIndex = 1;

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            CreateAndInsertButton.Enabled = false;
            ReadAndModifyButton.Enabled = false;
            ReadAndExportButton.Enabled = false;
            ReadSingleFieldButton.Enabled = false;
            DeleteSingleFieldButton.Enabled = false;
            RegisterButton.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;


            // Set output directory
            filedirectory = program_file_path + "\\output\\";


            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }



            // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
            // usable format. This function must be called at the beginning (one time only) before
            // any further processing of NIST file.
            // 	    _ReadNISTFromFile(ofd.utf8.GetBytes(filename));

            // Instead function ReadNISTFile you can use function _ReadNISTFromMemory (the code bellow)
            // ==========================

            fInfo = new FileInfo(ofd.FileName);
            size_of_byte_array = (int)fInfo.Length;
            fStream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
            br = new BinaryReader(fStream);
            byte_array = br.ReadBytes(size_of_byte_array);
            br.Close();
            fStream.Close();

            // Loads NIST file contents from memory and decodes NIST file data into
            // usable format. This function must be called at the beginning (one time only) before
            // any further processing of NIST file.     
            _ReadNISTFromMemory(byte_array, size_of_byte_array);
            // ==========================



            if (_CheckIfRecordTypeExists(1) == 1)
            {
                // Returns size_of_byte_array of text NIST field.
                size_of_byte_array = (int)(int)_ReadSizeOfRecordExportedTxtFields(1, 0);
                // Returns contents of NIST file data field as text string (char array).     
                ptr_nist_txt_field = _ReadRecordExportedTxtFields(1, 0);
                nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                // Sets filename for saving exported data of text field from type 1 record
                filename = filedirectory + "type1.txt";
                if (File.Exists(filename)) { File.Delete(filename); };
                fStream = new FileStream(filename, FileMode.CreateNew);
                bw = new BinaryWriter(fStream);
                // Writes exported data of text field from type 1 record to the file
                bw.Write(encoding.GetBytes(nist_txt_field));
                bw.Close();
                fStream.Close();
                MessageBox.Show("Type-1 record text field was exported to file .\\output\\type1.txt");
            } // if(_CheckIfRecordTypeExists(1) == 1)


            if (_CheckIfRecordTypeExists(2) == 1)
            {
                type2_number_of_records = _ReadNumberOfRecords(2);

                for (int i = 1; i <= type2_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(2, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(2, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(2, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 2 record
                        filename = filedirectory + "type2_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 2 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                        MessageBox.Show("Type-2 record text field was exported to file .\\output\\type2_" + idc.ToString() + ".txt");
                    }


                } // for(int i = 1; i <= type2_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(2) == 1)


            if (_CheckIfRecordTypeExists(4) == 1)
            {
                type4_number_of_records = _ReadNumberOfRecords(4);

                // In type 4 record there might be up to 14 fingerprint images.
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type4_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(4, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(4, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(4, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 4 record
                        filename = filedirectory + "type4_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 4 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(4, idc);

                    if (size_of_byte_array != 0)
                    {

                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(4, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 4 record
                        ptr_image_compression_code = _ReadRecordTxtField(4, idc, -1, utf8.GetBytes("GCA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type4_" + idc.ToString();
                        output_message = "Type-4 record text field was exported to file .\\output\\type4_" + idc.ToString() + ".txt.\n\nType-4 record binary field was exported to file .\\output\\type4_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nHigh-resolution grayscale fingerprint image was extracted from Type-4 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 4 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(4, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type4_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(4) == 1)


            if (_CheckIfRecordTypeExists(7) == 1)
            {
                type7_number_of_records = _ReadNumberOfRecords(7);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type7_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(7, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(7, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(7, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 7 record
                        filename = filedirectory + "type7_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 7 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(7, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(7, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 7 record
                        ptr_image_compression_code = _ReadRecordTxtField(7, idc, -1, utf8.GetBytes("GCA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type7_" + idc.ToString();
                        output_message = "Type-7 record text field was exported to file .\\output\\type7_" + idc.ToString() + ".txt.\n\nType-7 record binary field was exported to file .\\output\\type7_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nUser-defined image was extracted from Type-7 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 7 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(7, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type7_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(7) == 1)


            if (_CheckIfRecordTypeExists(8) == 1)
            {
                type8_number_of_records = _ReadNumberOfRecords(8);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type8_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(8, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(8, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(8, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 8 record
                        filename = filedirectory + "type8_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 8 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(8, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(8, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 8 record
                        filename = filedirectory + "type8_" + idc.ToString() + ".bin";

                        // Sets filename for saving exported data of text field from type 8 record
                        // ptr_image_compression_code = _ReadRecordTxtField(8, idc, -1, utf8.GetBytes("GCA"));
                        // image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        // filename = filedirectory + "type8_" + idc.ToString();
                        output_message = "Type-8 record text field was exported to file .\\output\\type8_" + idc.ToString() + ".txt.\n\nType-8 record binary field was exported to file .\\output\\type8_" + idc.ToString() + ".bin";

                        // if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        // { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        // else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        // { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        // else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        // { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        // else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        // { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        // else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        // { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nSignature image was extracted from Type-8 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";



                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 8 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(8, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type8_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(8) == 1)


            if (_CheckIfRecordTypeExists(9) == 1)
            {
                type9_number_of_records = _ReadNumberOfRecords(9);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type9_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(9, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(9, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(9, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 9 record
                        filename = filedirectory + "type9_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 9 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(9, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(9, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 9 record
                        filename = filedirectory + "type9_" + idc.ToString() + ".wsq";

                        // ptr_image_compression_code = _ReadRecordTxtField(9, idc, -1, utf8.GetBytes("CGA"));
                        // image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        // filename = filedirectory + "type9_" + idc.ToString();
                        output_message = "Type-9 record text field was exported to file .\\output\\type9_" + idc.ToString() + ".txt.\n\nType-9 record binary field was exported to file .\\output\\type9_";

                        // if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        // { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        // else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        // { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        // else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        // { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        // else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        // { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        // else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        // { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nMinutiae data was extracted from Type-9 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 9 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(9, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type9_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(9) == 1)

            if (_CheckIfRecordTypeExists(10) == 1)
            {
                type10_number_of_records = _ReadNumberOfRecords(10);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type10_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(10, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(10, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(10, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 10 record
                        filename = filedirectory + "type10_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 10 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(10, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(10, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 10 record
                        ptr_image_compression_code = _ReadRecordTxtField(10, idc, -1, utf8.GetBytes("CGA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type10_" + idc.ToString();
                        output_message = "Type-10 record text field was exported to file .\\output\\type10_" + idc.ToString() + ".txt.\n\nType-10 record binary field was exported to file .\\output\\type10_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nFacial & SMT image was extracted from Type-10 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 10 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(10, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type10_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(10) == 1)

            if (_CheckIfRecordTypeExists(13) == 1)
            {
                type13_number_of_records = _ReadNumberOfRecords(13);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type13_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(13, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(13, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(13, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 13 record
                        filename = filedirectory + "type13_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 13 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(13, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(13, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 13 record
                        ptr_image_compression_code = _ReadRecordTxtField(13, idc, -1, utf8.GetBytes("CGA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type13_" + idc.ToString();
                        output_message = "Type-13 record text field was exported to file .\\output\\type13_" + idc.ToString() + ".txt.\n\nType-13 record binary field was exported to file .\\output\\type13_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nVariable-resolution latent image was extracted from Type-13 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 13 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(13, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type13_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(13) == 1)

            if (_CheckIfRecordTypeExists(14) == 1)
            {
                type14_number_of_records = _ReadNumberOfRecords(14);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type14_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(14, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(14, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(14, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 14 record
                        filename = filedirectory + "type14_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 14 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(14, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(14, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 14 record
                        ptr_image_compression_code = _ReadRecordTxtField(14, idc, -1, utf8.GetBytes("CGA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type14_" + idc.ToString();
                        output_message = "Type-14 record text field was exported to file .\\output\\type14_" + idc.ToString() + ".txt.\n\nType-14 record binary field was exported to file .\\output\\type14_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nVariable-resolution fingerprint image was extracted from Type-14 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";


                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 14 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(14, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type14_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(14) == 1)

            if (_CheckIfRecordTypeExists(15) == 1)
            {
                type15_number_of_records = _ReadNumberOfRecords(15);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type15_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(15, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(15, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(15, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 15 record
                        filename = filedirectory + "type15_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 15 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(15, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(15, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 15 record
                        ptr_image_compression_code = _ReadRecordTxtField(15, idc, -1, utf8.GetBytes("CGA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type15_" + idc.ToString();
                        output_message = "Type-15 record text field was exported to file .\\output\\type15_" + idc.ToString() + ".txt.\n\nType-15 record binary field was exported to file .\\output\\type15_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nVariable-resolution palmprint image was extracted from Type-15 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 15 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(15, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type15_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(15) == 1)


            if (_CheckIfRecordTypeExists(16) == 1)
            {
                type16_number_of_records = _ReadNumberOfRecords(16);
                // Reads NIST file and exports all images to separate files.
                for (int i = 1; i <= type16_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(16, i);

                    // Returns size_of_byte_array of text NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordExportedTxtFields(16, idc);
                    // Returns contents of NIST file data field as text string (char array).
                    ptr_nist_txt_field = _ReadRecordExportedTxtFields(16, idc);
                    nist_txt_field = Marshal.PtrToStringAnsi(ptr_nist_txt_field);

                    if (size_of_byte_array != 0)
                    {
                        // Sets filename for saving exported data of text field from type 16 record
                        filename = filedirectory + "type16_" + idc.ToString() + ".txt";
                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of text field from type 16 record to the file
                        bw.Write(encoding.GetBytes(nist_txt_field));
                        bw.Close();
                        fStream.Close();
                    }

                    // Returns size_of_byte_array of binary NIST field.
                    size_of_byte_array = (int)_ReadSizeOfRecordBinaryField(16, idc);

                    if (size_of_byte_array != 0)
                    {
                        // Returns contents of NIST file binary field as byte array if successful,
                        // returns NULL otherwise.
                        nist_binary_field = _ReadRecordBinaryField(16, idc);

                        byte_array = new byte[size_of_byte_array];
                        Marshal.Copy(nist_binary_field, byte_array, 0, size_of_byte_array);

                        // Sets filename for saving exported data of text field from type 16 record
                        ptr_image_compression_code = _ReadRecordTxtField(16, idc, -1, utf8.GetBytes("CGA"));
                        image_compression_code = Marshal.PtrToStringAnsi(ptr_image_compression_code);

                        filename = filedirectory + "type16_" + idc.ToString();
                        output_message = "Type-16 record text field was exported to file .\\output\\type16_" + idc.ToString() + ".txt.\n\nType-16 record binary field was exported to file .\\output\\type16_" + idc.ToString();

                        if ((image_compression_code == "0") | (image_compression_code == "NONE"))
                        { filename = filename + ".bin"; output_message = output_message + ".bin."; }
                        else if ((image_compression_code == "1") | (image_compression_code == "WSQ20") | (image_compression_code == "WSQ"))
                        { filename = filename + ".wsq"; output_message = output_message + ".wsq."; }
                        else if ((image_compression_code == "2") | (image_compression_code == "JPEGB") | (image_compression_code == "3") | (image_compression_code == "JPEGL"))
                        { filename = filename + ".jpg"; output_message = output_message + ".jpg."; }
                        else if ((image_compression_code == "4") | (image_compression_code == "JP2") | (image_compression_code == "5") | (image_compression_code == "JP2L"))
                        { filename = filename + ".jp2"; output_message = output_message + ".jp2."; }
                        else if ((image_compression_code == "6") | (image_compression_code == "PNG"))
                        { filename = filename + ".png"; output_message = output_message + ".png."; }

                        output_message = output_message + "\n\nVariable-resolution user-defined testing image was extracted from Type-16 record\nbinary field of NIST file and converted into HBITMAP for showing on form.";

                        if (File.Exists(filename)) { File.Delete(filename); };
                        fStream = new FileStream(filename, FileMode.CreateNew);
                        bw = new BinaryWriter(fStream);
                        // Writes exported data of binary field from type 16 record to the file
                        bw.Write(byte_array);
                        bw.Close();
                        fStream.Close();

                        // Converts NIST file binary field contents into HBITMAP image.
                        // Returns image in HBITMAP format if successful, returns NULL otherwise.
                        hBitmap = _CreateHBITMAPfromRecordBinaryField(16, idc);

                        if (hBitmap != IntPtr.Zero)
                        {
                            picture.Image = Image.FromHbitmap(hBitmap);
                            picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                            Invalidate();
                            MessageBox.Show(output_message);
                        } // if ( hBitmap )

                    }

                } // for(int i = 1; i <= type16_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(16) == 1)



            CreateAndInsertButton.Enabled = true;
            ReadAndModifyButton.Enabled = true;
            ReadAndExportButton.Enabled = true;
            ReadSingleFieldButton.Enabled = true;
            DeleteSingleFieldButton.Enabled = true;
            RegisterButton.Enabled = true;
            Cursor.Current = Cursors.Default;

        }

        private void ReadSingleFieldButton_Click(object sender, EventArgs e)
        {


            ofd.FilterIndex = 1;

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }



            CreateAndInsertButton.Enabled = false;
            ReadAndModifyButton.Enabled = false;
            ReadAndExportButton.Enabled = false;
            ReadSingleFieldButton.Enabled = false;
            DeleteSingleFieldButton.Enabled = false;
            RegisterButton.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;




            // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
            // usable format. This function must be called at the beginning (one time only) before
            // any further processing of NIST file.
            // 	    _ReadNISTFromFile(ofd.utf8.GetBytes(filename));

            // Instead function ReadNISTFile you can use function _ReadNISTFromMemory (the code bellow)
            // ==========================

            fInfo = new FileInfo(ofd.FileName);
            size_of_byte_array = (int)fInfo.Length;
            fStream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
            br = new BinaryReader(fStream);
            byte_array = br.ReadBytes(size_of_byte_array);
            br.Close();
            fStream.Close();

            // Loads NIST file contents from memory and decodes NIST file data into
            // usable format. This function must be called at the beginning (one time only) before
            // any further processing of NIST file.     
            _ReadNISTFromMemory(byte_array, size_of_byte_array);
            // ==========================


            if ((Path.GetExtension(ofd.FileName)).ToLower() == ".xml")
            { traditional_or_xml_format = 1; } // NIEM - conformant XML format
            else
            { traditional_or_xml_format = 0; } // traditional format        


            if (_CheckIfRecordTypeExists(1) == 1)
            {

                output_message = "Type-1 record field values were read in cycle using field number\n\n";

                for (Int32 i = 1; i <= 15; i++)
                {
                    output_message = output_message + "Type-1 record ";
                    // Reads Type-1 record i Field Description
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtFieldDescription(1, -1, i, utf8.GetBytes("")));
                    output_message = output_message + nist_txt_field + " (";
                    // Reads Type-1 record i Field Name     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtFieldName(1, -1, i));
                    output_message = output_message + nist_txt_field + ") = ";
                    // Reads Type-1 record i Field Value            
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, i, utf8.GetBytes("")));
                    output_message = output_message + nist_txt_field + "\n";
                } // (Int32 i = 1; i <= 15; i++)
                MessageBox.Show(output_message);


                output_message = "Type-1 record field values were read using field names\n\n";

                if (traditional_or_xml_format == 0)
                {
                // Reads Type-1 record Logical record length (LEN)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("LEN")));
                output_message = output_message + "Type-1 record Logical record length (LEN) = ";
                output_message = output_message + nist_txt_field;
                }

                // Reads Type-1 record Version number (VER) of the standard implemented by the software or system creating the file
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("VER")));
                output_message = output_message + "\nType-1 record Version number (VER) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record File content (CNT)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("CNT")));
                output_message = output_message + "\nType-1 record File content (CNT) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Type of transaction (TOT)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("TOT")));
                output_message = output_message + "\nType-1 record Type of transaction (TOT) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Date (DAT)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("DAT")));
                output_message = output_message + "\nType-1 record Date (DAT) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Priority RY)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("PRY")));
                output_message = output_message + "\nType-1 record Priority (PRY) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Destination agency identifier (DAI)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("DAI")));
                output_message = output_message + "\nType-1 record Destination agency identifier (DAI) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Originating agency identifier (ORI)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("ORI")));
                output_message = output_message + "\nType-1 record Originating agency identifier (ORI) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Transaction control number (TCN)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("TCN")));
                output_message = output_message + "\nType-1 record Transaction control number (TCN) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Transaction control reference (TCR)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("TCR")));
                output_message = output_message + "\nType-1 record Transaction control reference (TCR) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Native scanning resolution(NSR)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("NSR")));
                output_message = output_message + "\nType-1 record Native scanning resolution (NSR) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Nominal transmitting resolution (NTR)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("NTR")));
                output_message = output_message + "\nType-1 record Nominal transmitting resolution (NTR) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Domain name (DOM)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("DOM")));
                output_message = output_message + "\nType-1 record Domain name (DOM) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Greenwich mean time (GMT)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("GMT")));
                output_message = output_message + "\nType-1 record Greenwich mean time (GMT) = ";
                output_message = output_message + nist_txt_field;

                // Reads Type-1 record Directory of character sets (DCS)
                nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(1, -1, -1, utf8.GetBytes("DCS")));
                output_message = output_message + "\nType-1 record Directory of character sets (DCS) = ";
                output_message = output_message + nist_txt_field;

                MessageBox.Show(output_message);
            } // if(_CheckIfRecordTypeExists(1) == 1)


            if (_CheckIfRecordTypeExists(2) == 1)
            {
                type2_number_of_records = _ReadNumberOfRecords(2);
                output_message = "Type-2 number of records = " + type2_number_of_records.ToString();

                MessageBox.Show(output_message);


                for (int i = 1; i <= type2_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(2, i);
                    // Returns contents of NIST file data field as text string (char array).

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-2 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(2, idc, 1, utf8.GetBytes("")));
                        output_message = "Type-2 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                    }

                    // Reads Type-2 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(2, idc, 2, utf8.GetBytes("")));
                    output_message = output_message + "\nType-2 (" + idc.ToString() + ") record Image designation character (IDC) = " + nist_txt_field;


                    // Reads Type-2 record User-defined field #30
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(2, idc, 30, utf8.GetBytes("")));
                    output_message = output_message + "\nType-2 (" + idc.ToString() + ") record User-defined field #30 = " + nist_txt_field;


                    // Reads Type-2 record User-defined field #31
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(2, idc, 31, utf8.GetBytes("")));
                    output_message = output_message + "\nType-2 (" + idc.ToString() + ") record User-defined field #31 = " + nist_txt_field;

                    // Reads Type-2 record User-defined field #32
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(2, idc, 32, utf8.GetBytes("")));
                    output_message = output_message + "\nType-2 (" + idc.ToString() + ") record User-defined field #32 = " + nist_txt_field;


                    MessageBox.Show(output_message);
                } // for(int i = 1; i <= type2_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(2) == 1)



            if (_CheckIfRecordTypeExists(4) == 1)
            {
                type4_number_of_records = _ReadNumberOfRecords(4);
                output_message = "Type-4 number of records = " + type4_number_of_records.ToString();

                MessageBox.Show(output_message);


                // In type 4 record there might be up to 14 fingerprint images.
                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type4_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(4, i);
                    // Returns contents of NIST file data field as text string (char array).

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-4 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-4 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                    }

                    // Reads Type-4 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Image designation character (IDC) = " + nist_txt_field;

                    // Reads Type-4 record Impression type (IMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("IMP")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Impression type (IMP) = " + nist_txt_field;

                    // Reads Type-4 record Known or most probable Finger position (FGP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Known or most probable Finger position (FGP) = " + nist_txt_field;

                    // Reads Type-4 record Known or most probable Finger position (FGP1)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP1")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Known or most probable Finger position (FGP1) = " + nist_txt_field;

                    // Reads Type-4 record Second possible Finger position (FGP2)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP2")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Second possible Finger position (FGP2) = " + nist_txt_field;

                    // Reads Type-4 record Third possible Finger position (FGP3)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP3")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Third possible Finger position (FGP3) = " + nist_txt_field;

                    // Reads Type-4 record Fourth possible Finger position (FGP4)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP4")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Fourth possible Finger position (FGP4) = " + nist_txt_field;

                    // Reads Type-4 record Fifth possible Finger position (FGP5)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP5")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Fifth possible Finger position (FGP5) = " + nist_txt_field;

                    // Reads Type-4 record Sixth possible Finger position (FGP6)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("FGP6")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Sixth possible Finger position (FGP6) = " + nist_txt_field;

                    // Reads Type-4 record Image scanning resolution (ISR)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("ISR")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Image scanning resolution (ISR) = " + nist_txt_field;

                    // Reads Type-4 record Horizontal line length (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Horizontal line length (HLL) = " + nist_txt_field;

                    // Reads Type-4 record Vertical line length (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Vertical line length (VLL) = " + nist_txt_field;

                    // Reads Type-4 record Grayscale compression algorithm (GCA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(4, idc, -1, utf8.GetBytes("GCA")));
                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Grayscale compression algorithm (GCA) = " + nist_txt_field;


                    // Returns Type-4 record Size of binary field.
                    nist_int_field = (int)_ReadSizeOfRecordBinaryField(4, idc);

                    output_message = output_message + "\nType-4 (" + idc.ToString() + ") record Size of binary field = " + nist_int_field.ToString();


                    // Returns contents of NIST file binary field as byte array if successful,
                    // returns NULL otherwise.
                    // nist_binary_field = ReadType4RecordBinaryField(1, idc);


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(4, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nHigh-resolution grayscale fingerprint image was extracted from type 4 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if ( hBitmap )




                } // for(int i = 1; i <= type4_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(4) == 1)



            if (_CheckIfRecordTypeExists(7) == 1)
            {
                type7_number_of_records = _ReadNumberOfRecords(7);
                output_message = "Type-7 number of records = " + type7_number_of_records.ToString();

                MessageBox.Show(output_message);


                for (int i = 1; i <= type7_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(7, i);
                    // Returns contents of NIST file data field as text string (char array).

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-7 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-7 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                    }

                    // Reads Type-7 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Image designation character (IDC) = " + nist_txt_field;

                    // Reads Type-7 record Image type (IMT)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("IMT")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Image type (IMT) = " + nist_txt_field;

                    // Reads Type-7 record Image description (IMD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("IMD")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Image description (IMD) = " + nist_txt_field;

                    // Reads Type-7 record Pattern classification (PCN)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("PCN")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Pattern classification (PCN) = " + nist_txt_field;

                    // Reads Type-7 record Image capture resolution (IMR)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("IMR")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Image capture resolution (IMR) = " + nist_txt_field;

                    // Reads Type-7 record Horizontal line length (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Horizontal line length (HLL) = " + nist_txt_field;

                    // Reads Type-7 record Horizontal line length (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Vertical line length (VLL) = " + nist_txt_field;

                    // Reads Type-7 record Gray-scale compression algorithm (GCA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(7, idc, -1, utf8.GetBytes("GCA")));
                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Gray-scale compression algorithm (GCA) = " + nist_txt_field;






                    // Returns Type-7 record Size of binary field.
                    nist_int_field = (int)_ReadSizeOfRecordBinaryField(7, idc);

                    output_message = output_message + "\nType-7 (" + idc.ToString() + ") record Size of binary field = " + nist_int_field.ToString();


                    // Returns contents of NIST file binary field as byte array if successful,
                    // returns NULL otherwise.
                    // nist_binary_field = ReadType7RecordBinaryField(1, idc);


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(7, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nUser-defined image was extracted from type 7 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if ( hBitmap )




                } // for(int i = 1; i <= type7_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(7) == 1)


            if (_CheckIfRecordTypeExists(8) == 1)
            {
                type8_number_of_records = _ReadNumberOfRecords(8);
                output_message = "Type-8 number of records = " + type8_number_of_records.ToString();

                MessageBox.Show(output_message);


                // Reads NIST file and shows signature images on the screen.
                for (int i = 1; i <= type8_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(8, i);
                    // Returns contents of NIST file data field as text string (char array).

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-8 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-8 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                    }

                    // Reads Type-8 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Image designation character (IDC) = " + nist_txt_field;

                    // Reads Type-8 record Signature type (SIG)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("SIG")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Signature type (SIG) = " + nist_txt_field;

                    // Reads Type-8 record Signature representation type (SRT)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("SRT")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Signature representation type (SRT) = " + nist_txt_field;

                    // Reads Type-8 record Image scanning resolution (ISR)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("ISR")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Image scanning resolution (ISR) = " + nist_txt_field;

                    // Reads Type-8 record Horizontal line length (HLL)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Horizontal line length (HLL) = " + nist_txt_field;

                    // Reads Type-8 record Vertical line length (VLL)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(8, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Vertical line length (VLL) = " + nist_txt_field;




                    // Returns Type-8 record Size of binary field.
                    nist_int_field = (int)_ReadSizeOfRecordBinaryField(8, idc);

                    output_message = output_message + "\nType-8 (" + idc.ToString() + ") record Size of binary field = " + nist_int_field.ToString();


                    // Returns contents of NIST file binary field as byte array if successful,
                    // returns NULL otherwise.
                    // nist_binary_field = ReadType8RecordBinaryField(1, idc);


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(8, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nSignature image was extracted from type 8 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if ( hBitmap )




                } // for(int i = 1; i <= type8_number_of_records; i++)


            } // if(_CheckIfRecordTypeExists(8) == 1)


            if (_CheckIfRecordTypeExists(9) == 1)
            {

                type9_number_of_records = _ReadNumberOfRecords(9);
                output_message = "Type-9 number of records = " + type9_number_of_records.ToString();

                MessageBox.Show(output_message);


                // Reads NIST file and shows minutiae data images on the screen.
                for (int i = 1; i <= type9_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(9, i);

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-9 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-9 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-9 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-2 record Image designation character (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-9 record Impression type (IMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("IMP")));
                    output_message = "Type-9 record Impression type (IMP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-9 record Minutiae format (FMT)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("FMT")));
                    output_message = "Type-9 record Minutiae format (FMT) = ";
                    output_message = output_message + nist_txt_field;

                    if (nist_txt_field == "S")
                    {

                        // Reads Type-9 record Originating fingerprint reading system (OFR)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("OFR")));
                        output_message = "Type-9 record Originating fingerprint reading system (OFR) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Finger position (FGP)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("FGP")));
                        output_message = "Type-9 record Finger position (FGP) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Fingerprint pattern classification (FPC)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("FPC")));
                        output_message = "Type-9 record Fingerprint pattern classification (FPC) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Core position (CRP)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("CRP")));
                        output_message = "Type-9 record Core position (CRP) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Delta(s) position (DLT)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("DLT")));
                        output_message = "Type-9 record Delta(s) position (DLT) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Number of minutiae (MIN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("MIN")));
                        output_message = "Type-9 record Number of minutiae (MIN) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Number of minutiae (RDG)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("RDG")));
                        output_message = "Type-9 record Minutiae ridge count indicator (RDG) = ";
                        output_message = output_message + nist_txt_field;

                        // Reads Type-9 record Number of minutiae (MRC)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(9, idc, -1, utf8.GetBytes("MRC")));
                        output_message = "Type-9 record Minutiae and ridge count data (MRC) = ";
                        output_message = output_message + nist_txt_field;

                    } // if(nist_txt_field == "S")


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(9, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nMinutiae data was extracted from type 9 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap );
                    else
                    {
                        output_message = output_message + "\nMinutiae data was extracted from type 9 record binary field\nof NIST file.";
                        MessageBox.Show(output_message);
                    }




                } // for(int i = 1; i <= type9_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(9) == 1) 



            if (_CheckIfRecordTypeExists(10) == 1)
            {

                type10_number_of_records = _ReadNumberOfRecords(10);
                output_message = "Type-10 number of records = " + type10_number_of_records.ToString();

                MessageBox.Show(output_message);


                // Reads NIST file and shows facial and SMT images on the screen.
                for (int i = 1; i <= type10_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(10, i);


                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-10 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-10 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-10 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-10 record Image designation character (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Image type (IMT)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("IMT")));
                    output_message = output_message + "\nType-10 record Image type (IMT) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Source agency / ORI (SRC)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SRC")));
                    output_message = output_message + "\nType-10 record Source agency / ORI (SRC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Photo date (PHD)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("PHD")));
                    output_message = output_message + "\nType-10 record Photo date (PHD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Horizontal line length (HLL)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-10 record Horizontal line length (HLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Vertical line length (VLL)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-10 record Vertical line length (VLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Scale units (SLC)      
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SLC")));
                    output_message = output_message + "\nType-10 record Scale units (SLC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Horizontal pixel scale (THPS)      
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("THPS")));
                    output_message = output_message + "\nType-10 record Horizontal pixel scale (THPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Vertical pixel scale (TVPS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("TVPS")));
                    output_message = output_message + "\nType-10 record Vertical pixel scale (TVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Compression algorithm (CGA)          
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("CGA")));
                    output_message = output_message + "\nType-10 record Compression algorithm (CGA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Colorspace (CSP)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("CSP")));
                    output_message = output_message + "\nType-10 record Colorspace (CSP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject acquisition profile (SAP)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SAP")));
                    output_message = output_message + "\nType-10 record Subject acquisition profile (SAP) = ";
                    output_message = output_message + nist_txt_field;


                    // Reads Type-10 record Subject pose (POS)      
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("POS")));
                    output_message = output_message + "\nType-10 record Subject pose (POS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Pose offset angle (POA)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("POA")));
                    output_message = output_message + "\nType-10 record Pose offset angle (POA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Photo description (PXS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("PXS")));
                    output_message = output_message + "\nType-10 record Photo description (PXS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Photo acquisition source (PAS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("PAS")));
                    output_message = output_message + "\nType-10 record Photo acquisition source (PAS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject quality score (SQS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SQS")));
                    output_message = output_message + "\nType-10 record Subject quality score (SQS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject pose angles (SPA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SPA")));
                    output_message = output_message + "\nType-10 record Subject pose angles (SPA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject facial description (SXS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SXS")));
                    output_message = output_message + "\nType-10 record Subject facial description (SXS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject eye color (SEC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SEC")));
                    output_message = output_message + "\nType-10 record Subject eye color (SEC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Subject hair color (SHC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SHC")));
                    output_message = output_message + "\nType-10 record Subject hair color (SHC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Facial feature points (FFP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("FFP")));
                    output_message = output_message + "\nType-10 record Facial feature points (FFP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Device monitoring mode (DMM)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("DMM")));
                    output_message = output_message + "\nType-10 record Device monitoring mode (DMM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record NCIC designation code (SMT)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SMT")));
                    output_message = output_message + "\nType-10 record NCIC designation code (SMT) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record SMT size (SMS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SMS")));
                    output_message = output_message + "\nType-10 record SMT size (SMS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record SMT descriptors (SMD)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("SMD")));
                    output_message = output_message + "\nType-10 record SMT descriptors (SMD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-10 record Color (COL)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("COL")));
                    output_message = output_message + "\nType-10 record Color (COL) = ";
                    output_message = output_message + nist_txt_field;
                    // Application->MessageBox( output_message, "NIST library", MBOK );


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(10, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nFacial & SMT image was extracted from type 10 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap );                 


                } // for(int i = 1; i <= type10_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(10) == 1)



            if (_CheckIfRecordTypeExists(13) == 1)
            {

                type13_number_of_records = _ReadNumberOfRecords(13);
                output_message = "Type-13 number of records = " + type13_number_of_records.ToString();

                MessageBox.Show(output_message);

                // Reads NIST file and shows latent images on the screen.
                for (int i = 1; i <= type13_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(13, i);

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-13 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-13 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-13 record Image Designation Character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-13 record Logical record length (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Impression Type (IMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("IMP")));
                    output_message = output_message + "\nType-13 record Logical record length (IMP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Source agency / ORI (SRC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("SRC")));
                    output_message = output_message + "\nType-13 record Source agency / ORI (SRC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Latent capture date (LCD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("LCD")));
                    output_message = output_message + "\nType-13 record Latent capture date (LCD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Latent capture date (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-13 record Horizontal line length (HLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Latent capture date (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-13 record Vertical line length (VLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Scale units (SLC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("SLC")));
                    output_message = output_message + "\nType-13 record Scale units (SLC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Horizontal pixel scale (THPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("THPS")));
                    output_message = output_message + "\nType-13 record Horizontal pixel scale (THPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Vertical pixel scale (TVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("TVPS")));
                    output_message = output_message + "\nType-13 record Vertical pixel scale (TVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Compression algorithm (CGA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("CGA")));
                    output_message = output_message + "\nType-13 record Compression algorithm (CGA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Bits per pixel (BPX)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("BPX")));
                    output_message = output_message + "\nType-13 record Bits per pixel (BPX) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Finger / palm position (FGP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("FGP")));
                    output_message = output_message + "\nType-13 record Finger / palm position (FGP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Search position descriptors (SPD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("SPD")));
                    output_message = output_message + "\nType-13 record Search position descriptors (SPD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Print position coordinates (PPC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("PPC")));
                    output_message = output_message + "\nType-13 record Print position coordinates (PPC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Scanned horizontal pixel scale (SHPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("SHPS")));
                    output_message = output_message + "\nType-13 record Scanned horizontal pixel scale (SHPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Scanned vertical pixel scale (SVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("SVPS")));
                    output_message = output_message + "\nType-13 record Scanned vertical pixel scale (SVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-13 record Comment (COM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("COM")));
                    output_message = output_message + "\nType-13 record Comment (COM) = ";
                    output_message = output_message + nist_txt_field;


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(13, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nVariable-resolution latent image was extracted from type 13 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap ); 


                } // for(int i = 1; i <= type13_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(13) == 1)


            if (_CheckIfRecordTypeExists(14) == 1)
            {

                type14_number_of_records = _ReadNumberOfRecords(14);
                output_message = "Type-14 number of records = " + type14_number_of_records.ToString();

                MessageBox.Show(output_message);

                // Reads NIST file and shows tenprint images images on the screen.
                for (int i = 1; i <= type14_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(14, i);

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-14 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-14 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-14 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-14 record Image designation character (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Impression type (IMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("IMP")));
                    output_message = output_message + "\nType-14 record Impression type (IMP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Source agency / ORI (SRC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SRC")));
                    output_message = output_message + "\nType-14 record Source agency / ORI (SRC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Tenprint capture date (TCD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("TCD")));
                    output_message = output_message + "\nType-14 record Tenprint capture date (TCD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Horizontal line length (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-14 record Horizontal line length (HLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Vertical line length (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-14 record Vertical line length (VLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Scale units (SLC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SLC")));
                    output_message = output_message + "\nType-14 record Scale units (SLC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Horizontal pixel scale (THPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("THPS")));
                    output_message = output_message + "\nType-14 record Horizontal pixel scale (THPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Vertical pixel scale (TVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("TVPS")));
                    output_message = output_message + "\nType-14 record Vertical pixel scale (TVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Compression algorithm (CGA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("CGA")));
                    output_message = output_message + "\nType-14 record Compression algorithm (CGA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Bits per pixel (BPX)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("BPX")));
                    output_message = output_message + "\nType-14 record Bits per pixel (BPX) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Finger position (FGP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("FGP")));
                    output_message = output_message + "\nType-14 record Finger position (FGP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Print position descriptors (PPD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("PPD")));
                    output_message = output_message + "\nType-14 record Print position descriptors (PPD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Print position coordinates (PPC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("PPC")));
                    output_message = output_message + "\nType-14 record Print position coordinates (PPC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Scanned horizontal pixel scale (SHPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SHPS")));
                    output_message = output_message + "\nType-14 record Scanned horizontal pixel scale (SHPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Scanned vertical pixel scale (SVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SVPS")));
                    output_message = output_message + "\nType-14 record Scanned vertical pixel scale (SVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Amputated or bandaged (AMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("AMP")));
                    output_message = output_message + "\nType-14 record Amputated or bandaged (AMP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Comment (COM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("COM")));
                    output_message = output_message + "\nType-14 record Comment (COM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Finger segment position(s) (SEG)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SEG")));
                    output_message = output_message + "\nType-14 record Finger segment position(s) (SEG) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record NIST quality metric (NQM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("NQM")));
                    output_message = output_message + "\nType-14 record NIST quality metric (NQM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Segmentation quality metric (SQM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("SQM")));
                    output_message = output_message + "\nType-14 record Segmentation quality metric (SQM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Fingerprint quality metric (FQM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("FQM")));
                    output_message = output_message + "\nType-14 record Fingerprint quality metric (FQM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Alternate finger segment position(s) (ASEG)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("ASEG")));
                    output_message = output_message + "\nType-14 record Alternate finger segment position(s) (ASEG) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-14 record Device monitoring mode (DMM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("DMM")));
                    output_message = output_message + "\nType-14 record Device monitoring mode (DMM) = ";
                    output_message = output_message + nist_txt_field;


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(14, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nVariable-resolution fingerprint image was extracted from type 14 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap );                 


                } // for(int i = 1; i <= type14_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(14) == 1)



            if (_CheckIfRecordTypeExists(15) == 1)
            {

                type15_number_of_records = _ReadNumberOfRecords(15);
                output_message = "Type-15 number of records = " + type15_number_of_records.ToString();

                MessageBox.Show(output_message);


                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type15_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(15, i);

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-15 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-15 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-15 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-15 record Image designation character (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Impression type (IMP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("IMP")));
                    output_message = output_message + "\nType-15 record Impression type (IMP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Source agency/ORI (SRC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("SRC")));
                    output_message = output_message + "\nType-15 record Source agency/ORI (SRC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Palmprint capture date (PCD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("PCD")));
                    output_message = output_message + "\nType-15 record Palmprint capture date (PCD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Horizontal line length (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-15 record Horizontal line length (HLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Vertical line length (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-15 record Vertical line length (VLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Scale units (SLC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("SLC")));
                    output_message = output_message + "\nType-15 record Scale units (SLC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Horizontal pixel scale (THPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("THPS")));
                    output_message = output_message + "\nType-15 record Horizontal pixel scale (THPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Vertical pixel scale (TVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("TVPS")));
                    output_message = output_message + "\nType-15 record Vertical pixel scale (TVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Compression algorithm (CGA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("CGA")));
                    output_message = output_message + "\nType-15 record Compression algorithm (CGA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Bits per pixel (BPX)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("BPX")));
                    output_message = output_message + "\nType-15 record Bits per pixel (BPX) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Palmprint position (PLP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("PLP")));
                    output_message = output_message + "\nType-15 record Palmprint position (PLP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Scanned horizontal pixel scale (SHPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("SHPS")));
                    output_message = output_message + "\nType-15 record Scanned horizontal pixel scale (SHPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Scanned vertical pixel scale (SVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("SVPS")));
                    output_message = output_message + "\nType-15 record Scanned vertical pixel scale (SVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Comment (COM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("COM")));
                    output_message = output_message + "\nType-15 record Comment (COM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Palmprint quality metric (PQM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("PQM")));
                    output_message = output_message + "\nType-15 record Palmprint quality metric (PQM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-15 record Device monitoring mode (DMM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("DMM")));
                    output_message = output_message + "\nType-15 record Device monitoring mode (DMM) = ";
                    output_message = output_message + nist_txt_field;


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(15, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nVariable-resolution palmprint image was extracted from type 15 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap );                                



                } // for(int i = 1; i <= type15_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(15) == 1)


            if (_CheckIfRecordTypeExists(16) == 1)
            {

                type16_number_of_records = _ReadNumberOfRecords(16);
                output_message = "Type-16 number of records = " + type16_number_of_records.ToString();

                MessageBox.Show(output_message);


                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type16_number_of_records; i++)
                {

                    output_message = "";

                    idc = _ReadIDCofRecord(16, i);

                    if (traditional_or_xml_format == 0)
                    {
                        // Reads Type-16 record Logical record length (LEN)
                        nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("LEN")));
                        output_message = "Type-16 (" + idc.ToString() + ") record Logical record length (LEN) = " + nist_txt_field;
                        output_message = output_message + nist_txt_field;
                    }

                    // Reads Type-16 record Image designation character (IDC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("IDC")));
                    output_message = output_message + "\nType-16 record Image designation character (IDC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record User-Defined Image (UDI)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("UDI")));
                    output_message = output_message + "\nType-16 record User-Defined Image (UDI) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Source Agency / ORI (SRC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("SRC")));
                    output_message = output_message + "\nType-16 record Source Agency / ORI (SRC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record User-Defined Testing Date (UTD)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("UTD")));
                    output_message = output_message + "\nType-16 record User-Defined Testing Date (UTD) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Horizontal Line Length (HLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("HLL")));
                    output_message = output_message + "\nType-16 record Horizontal Line Length (HLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Vertical Line Length (VLL)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("VLL")));
                    output_message = output_message + "\nType-16 record Vertical Line Length (VLL) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Scale Units (SLC)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("SLC")));
                    output_message = output_message + "\nType-16 record Scale Units (SLC) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Horizontal Pixel Scale (THPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("THPS")));
                    output_message = output_message + "\nType-16 record Horizontal Pixel Scale (THPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Vertical Pixel Scale (TVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("TVPS")));
                    output_message = output_message + "\nType-16 record Vertical Pixel Scale (TVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Compression Algorithm (CGA)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("CGA")));
                    output_message = output_message + "\nType-16 record Compression Algorithm (CGA) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Bits Per Pixel (BPX)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("BPX")));
                    output_message = output_message + "\nType-16 record Bits Per Pixel (BPX) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Color Space (CSP)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("CSP")));
                    output_message = output_message + "\nType-16 record Color Space (CSP) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Scanned Horizontal Pixel Scale (SHPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("SHPS")));
                    output_message = output_message + "\nType-16 record Scanned Horizontal Pixel Scale (SHPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Scanned Vertical Pixel Scale (SVPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("SVPS")));
                    output_message = output_message + "\nType-16 record Scanned Vertical Pixel Scale (SVPS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Comment (COM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("COM")));
                    output_message = output_message + "\nType-16 record Comment (COM) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record User-Defined Testing Image Quality Score (UQS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("UQS")));
                    output_message = output_message + "\nType-16 record User-Defined Testing Image Quality Score (UQS) = ";
                    output_message = output_message + nist_txt_field;

                    // Reads Type-16 record Device Monitoring Mode (DMM)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("DMM")));
                    output_message = output_message + "\nType-16 record Device Monitoring Mode (DMM) = ";
                    output_message = output_message + nist_txt_field;


                    // Converts NIST file binary field contents into HBITMAP image.
                    // Returns image in HBITMAP format if successful, returns NULL otherwise.
                    hBitmap = _CreateHBITMAPfromRecordBinaryField(16, idc);

                    if (hBitmap != IntPtr.Zero)
                    {
                        picture.Image = Image.FromHbitmap(hBitmap);
                        picture.SetBounds(0, 0, picture.Image.Width, picture.Image.Height);
                        Invalidate();
                        output_message = output_message + "\nVariable-resolution user-defined testing image was extracted from type 16 record binary field\nof NIST file and converted into HBITMAP for showing on form.";
                        MessageBox.Show(output_message);
                    } // if( hBitmap );      


                } // for(int i = 1; i <= type16_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(16) == 1)





            CreateAndInsertButton.Enabled = true;
            ReadAndModifyButton.Enabled = true;
            ReadAndExportButton.Enabled = true;
            ReadSingleFieldButton.Enabled = true;
            DeleteSingleFieldButton.Enabled = true;
            RegisterButton.Enabled = true;
            Cursor.Current = Cursors.Default;

        }

        private void DeleteSingleFieldButton_Click(object sender, EventArgs e)
        {


            CreateAndInsertButton.Enabled = false;
            ReadAndModifyButton.Enabled = false;
            ReadAndExportButton.Enabled = false;
            ReadSingleFieldButton.Enabled = false;
            DeleteSingleFieldButton.Enabled = false;
            RegisterButton.Enabled = false;
            Cursor.Current = Cursors.WaitCursor;


            traditional_or_xml_format = 0; // traditional format
             // traditional_or_xml_format = 1; // NIEM-conformant XML format
            _SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format



            // Sets input file name as "sample.nist" which located in "input" subdirectory
            filedirectory = program_file_path + "\\input\\";

            if (traditional_or_xml_format == 0)
            { filename = filedirectory + "sample.nist"; }
            else
            { filename = filedirectory + "sample_NIEM_conformant_XML.xml"; }



            if (!File.Exists(filename))
            {
                if (traditional_or_xml_format == 0)
                { MessageBox.Show("Error: file .\\input\\sample.nist does not exist."); }
                else
                { MessageBox.Show("Error: file .\\input\\sample_NIEM_conformant_XML.xml does not exist."); }
                return;
            }



            // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
            // usable format. This function must be called at the beginning (one time only) before
            // any further processing of NIST file.
            _ReadNISTFromFile(utf8.GetBytes(filename));






            if (_CheckIfRecordTypeExists(2) == 1)
            {

                // Modifies NIST file, Deletes all Type-2 records
                type2_number_of_records = _ReadNumberOfRecords(2);

                for (int i = 1; i <= type2_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(2, 1); // selects the first Type-2 record
                    // idc = _ReadIDCofRecord(2, (type2_number_of_records - i + 1)); // selects the last Type-2 record
                    _DeleteRecord(2, idc);
                } // for(int i = 1; i <= type2_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(2) == 1)



            if (_CheckIfRecordTypeExists(4) == 1)
            {

                // Modifies NIST file, Deletes all Type-4 records
                type4_number_of_records = _ReadNumberOfRecords(4);

                for (int i = 1; i <= type4_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(4, 1); // selects the first Type-4 record
                    // idc = _ReadIDCofRecord(4, (type4_number_of_records - i + 1)); // selects the last Type-4 record
                    _DeleteRecord(4, idc);
                } // for(int i = 1; i <= type4_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(4) == 1)


            if (_CheckIfRecordTypeExists(7) == 1)
            {

                // Modifies NIST file, Deletes all Type-7 records
                type7_number_of_records = _ReadNumberOfRecords(7);

                for (int i = 1; i <= type7_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(7, 1); // selects the first Type-7 record
                    // idc = _ReadIDCofRecord(7, (type7_number_of_records - i + 1)); // selects the last Type-7 record
                    _DeleteRecord(7, idc);
                } // for(int i = 1; i <= type7_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(7) == 1)


            if (_CheckIfRecordTypeExists(8) == 1)
            {

                // Modifies NIST file, Deletes all Type-8 records
                type8_number_of_records = _ReadNumberOfRecords(8);

                for (int i = 1; i <= type8_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(8, 1); // selects the first Type-8 record
                    // idc = _ReadIDCofRecord(8, (type8_number_of_records - i + 1)); // selects the last Type-8 record
                    _DeleteRecord(8, idc);
                } // for(int i = 1; i <= type8_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(8) == 1)


            if (_CheckIfRecordTypeExists(9) == 1)
            {

                // Modifies NIST file, Deletes all Type-9 records
                type9_number_of_records = _ReadNumberOfRecords(9);

                for (int i = 1; i <= type9_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(9, 1); // selects the first Type-9 record
                    // ShowMessage(idc);
                    // idc = _ReadIDCofRecord(9, (type9_number_of_records - i + 1)); // selects the last Type-9 record
                    _DeleteRecord(9, idc);
                } // for(int i = 1; i <= type9_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(9) == 1)



            if (_CheckIfRecordTypeExists(10) == 1)
            {

                // Modifies NIST file, Deletes all Type-10 records
                type10_number_of_records = _ReadNumberOfRecords(10);

                for (int i = 1; i <= type10_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(10, 1); // selects the first Type-10 record
                    // idc = _ReadIDCofRecord(10, (type10_number_of_records - i + 1)); // selects the last Type-10 record
                    _DeleteRecord(10, idc);
                } // for(int i = 1; i <= type10_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(10) == 1)


            if (_CheckIfRecordTypeExists(11) == 1)
            {

                // Modifies NIST file, Deletes all Type-11 records
                type11_number_of_records = _ReadNumberOfRecords(11);

                for (int i = 1; i <= type11_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(11, 1); // selects the first Type-11 record
                    // idc = _ReadIDCofRecord(11, (type11_number_of_records - i + 1)); // selects the last Type-11 record
                    _DeleteRecord(11, idc);
                } // for(int i = 1; i <= type11_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(11) == 1)


            if (_CheckIfRecordTypeExists(12) == 1)
            {

                // Modifies NIST file, Deletes all Type-12 records
                type12_number_of_records = _ReadNumberOfRecords(12);

                for (int i = 1; i <= type12_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(12, 1); // selects the first Type-12 record
                    // idc = _ReadIDCofRecord(12, (type12_number_of_records - i + 1)); // selects the last Type-12 record
                    _DeleteRecord(12, idc);
                } // for(int i = 1; i <= type12_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(12) == 1)


            if (_CheckIfRecordTypeExists(13) == 1)
            {

                // Modifies NIST file, Deletes all Type-13 records
                type13_number_of_records = _ReadNumberOfRecords(13);

                for (int i = 1; i <= type13_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(13, 1); // selects the first Type-13 record
                    // idc = _ReadIDCofRecord(13, (type13_number_of_records - i + 1)); // selects the last Type-13 record
                    _DeleteRecord(13, idc);
                } // for(int i = 1; i <= type13_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(13) == 1)



            if (_CheckIfRecordTypeExists(14) == 1)
            {

                // Modifies NIST file, Deletes all Type-14 records
                type14_number_of_records = _ReadNumberOfRecords(14);


                for (int i = 1; i <= type14_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(14, 1); // selects the first Type-14 record
                    // idc = _ReadIDCofRecord(14, (type14_number_of_records - i + 1)); // selects the last Type-14 record
                    _DeleteRecord(14, idc);
                } // for(int i = 1; i <= type14_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(14) == 1)


            if (_CheckIfRecordTypeExists(15) == 1)
            {
                // Modifies NIST file, Deletes all Type-15 records
                type15_number_of_records = _ReadNumberOfRecords(15);

                for (int i = 1; i <= type15_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(15, 1); // selects the first Type-15 record
                    // idc = _ReadIDCofRecord(15, (type15_number_of_records - i + 1)); // selects the last Type-15 record
                    _DeleteRecord(15, idc);
                } // for(int i = 1; i <= type15_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(15) == 1)


            if (_CheckIfRecordTypeExists(16) == 1)
            {
                // Modifies NIST file, Deletes all Type-16 records
                type16_number_of_records = _ReadNumberOfRecords(16);

                for (int i = 1; i <= type16_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(16, 1); // selects the first Type-16 record
                    // idc = _ReadIDCofRecord(16, (type16_number_of_records - i + 1)); // selects the last Type-16 record
                    _DeleteRecord(16, idc);
                } // for(int i = 1; i <= type16_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(16) == 1)


            if (_CheckIfRecordTypeExists(17) == 1)
            {

                // Modifies NIST file, Deletes all Type-17 records
                type17_number_of_records = _ReadNumberOfRecords(17);

                for (int i = 1; i <= type17_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(17, 1); // selects the first Type-17 record
                    // idc = _ReadIDCofRecord(17, (type17_number_of_records - i + 1)); // selects the last Type-17 record
                    _DeleteRecord(17, idc);
                } // for(int i = 1; i <= type17_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(17) == 1)


            if (_CheckIfRecordTypeExists(18) == 1)
            {

                // Modifies NIST file, Deletes all Type-18 records
                type18_number_of_records = _ReadNumberOfRecords(18);

                for (int i = 1; i <= type18_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(18, 1); // selects the first Type-18 record
                    // idc = _ReadIDCofRecord(18, (type18_number_of_records - i + 1)); // selects the last Type-18 record
                    _DeleteRecord(18, idc);
                } // for(int i = 1; i <= type18_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(18) == 1)


            if (_CheckIfRecordTypeExists(19) == 1)
            {

                // Modifies NIST file, Deletes all Type-19 records
                type19_number_of_records = _ReadNumberOfRecords(19);

                for (int i = 1; i <= type19_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(19, 1); // selects the first Type-19 record
                    // idc = _ReadIDCofRecord(19, (type19_number_of_records - i + 1)); // selects the last Type-19 record
                    _DeleteRecord(19, idc);
                } // for(int i = 1; i <= type19_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(19) == 1)


            if (_CheckIfRecordTypeExists(20) == 1)
            {

                // Modifies NIST file, Deletes all Type-20 records
                type20_number_of_records = _ReadNumberOfRecords(20);

                for (int i = 1; i <= type20_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(20, 1); // selects the first Type-20 record
                    // idc = _ReadIDCofRecord(20, (type20_number_of_records - i + 1)); // selects the last Type-20 record
                    _DeleteRecord(20, idc);
                } // for(int i = 1; i <= type20_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(20) == 1)



            if (_CheckIfRecordTypeExists(21) == 1)
            {

                // Modifies NIST file, Deletes all Type-21 records
                type21_number_of_records = _ReadNumberOfRecords(21);

                for (int i = 1; i <= type21_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(21, 1); // selects the first Type-21 record
                    // idc = _ReadIDCofRecord(21, (type21_number_of_records - i + 1)); // selects the last Type-21 record
                    _DeleteRecord(21, idc);
                } // for(int i = 1; i <= type21_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(21) == 1)


            if (_CheckIfRecordTypeExists(22) == 1)
            {

                // Modifies NIST file, Deletes all Type-22 records
                type22_number_of_records = _ReadNumberOfRecords(22);

                for (int i = 1; i <= type22_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(22, 1); // selects the first Type-22 record
                    // idc = _ReadIDCofRecord(22, (type22_number_of_records - i + 1)); // selects the last Type-22 record
                    _DeleteRecord(22, idc);
                } // for(int i = 1; i <= type22_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(22) == 1)



            if (_CheckIfRecordTypeExists(98) == 1)
            {

                // Modifies NIST file, Deletes all Type-98 records
                type98_number_of_records = _ReadNumberOfRecords(98);

                for (int i = 1; i <= type98_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(98, 1); // selects the first Type-98 record
                    // idc = _ReadIDCofRecord(98, (type98_number_of_records - i + 1)); // selects the last Type-98 record
                    _DeleteRecord(98, idc);
                } // for(int i = 1; i <= type98_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(98) == 1)


            if (_CheckIfRecordTypeExists(99) == 1)
            {

                // Modifies NIST file, Deletes all Type-99 records
                type99_number_of_records = _ReadNumberOfRecords(99);

                for (int i = 1; i <= type99_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(99, 1); // selects the first Type-99 record
                    // idc = _ReadIDCofRecord(99, (type99_number_of_records - i + 1)); // selects the last Type-99 record
                    _DeleteRecord(99, idc);
                } // for(int i = 1; i <= type99_number_of_records; i++)

            } // if(_CheckIfRecordTypeExists(99) == 1)


            // Sets output file name as "sample_of_deletion.nist" (in "output" subdirectory)
            filedirectory = program_file_path + "\\output\\";
            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }

            if (traditional_or_xml_format == 0)
            { filename = filedirectory + "sample_of_deletion.nist"; }
            else
            { filename = filedirectory + "sample_of_deletion.xml"; }


            // Saves NIST into the file "sample_of_deletion.nist" (in "output" subdirectory)
            _WriteNISTToFile(utf8.GetBytes(filename));

            if (traditional_or_xml_format == 0)
            { MessageBox.Show("NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_of_deletion.nist\"\n\nPlease use \"NIST viewer\" to see changes in\n\"sample_of_deletion.nist\" file."); }
            else
            { MessageBox.Show("NIST file \".\\input\\sample_NIEM_conformant_XML.xml\" was read, modified\nand saved as \".\\output\\sample_of_deletion.xml\"\n\nPlease use \"NIST viewer\" to see changes in\n\"sample_of_deletion.xml\" file."); }



            CreateAndInsertButton.Enabled = true;
            ReadAndModifyButton.Enabled = true;
            ReadAndExportButton.Enabled = true;
            ReadSingleFieldButton.Enabled = true;
            DeleteSingleFieldButton.Enabled = true;
            RegisterButton.Enabled = true;
            Cursor.Current = Cursors.Default;

        }
    }
}