using System;
using Gtk;
using GtkSharp;

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




namespace nist_demo{
   public class Form1{


        public static Window win;
        public static Gtk.ScrolledWindow scrolled_window;

        public static int image_width;
        public static int image_height;
        public static Int32 image_width_64;
        public static Int32 image_height_64;

        public static Int32 number_of_pixels;
        public static Int32 number_of_pixels_x_2;
        public static Int32 number_of_pixels_x_3;
        public static Int32 number_of_pixels_x_4;

        public static Int32 row_input, row_output;
        public static Int32 pixel_number_input;
        public static Int32 pixel_number_output;
        public static Int32 x, y, x_padded;
        public static Int32 image_width_x_4;

        public static byte [] image_pixel_data_original;
        public static byte [] image_pixel_data;
        public static int rowstride;

//        public static Gdk.PixbufDestroyNotify destroy_fn;
        public static Gdk.Pixbuf pixbuf;


        public static Int32 idc_current;
        public static Int32 idc;
        public static int size_of_byte_array;
        public static byte[] byte_array;
        public static IntPtr byte_array_ptr;
        public static String nist_txt_field;
        public static IntPtr ptr_nist_txt_field;
        public static IntPtr nist_binary_field;
        public static Int32 nist_int_field;
        public static Int32 type2_number_of_records;
        public static Int32 type3_number_of_records;
        public static Int32 type4_number_of_records;
        public static Int32 type5_number_of_records;
        public static Int32 type6_number_of_records;
        public static Int32 type7_number_of_records;
        public static Int32 type8_number_of_records;
        public static Int32 type9_number_of_records;
        public static Int32 type10_number_of_records;
        public static Int32 type13_number_of_records;
        public static Int32 type14_number_of_records;
        public static Int32 type15_number_of_records;
        public static Int32 type16_number_of_records;
        public static Int32 type17_number_of_records;
        public static Int32 type99_number_of_records;
        public static FileStream fStream;
        public static BinaryReader br;
        public static BinaryWriter bw;
        public static IntPtr hBitmap;
        public static String program_file_path;
        public static String filedirectory;
        public static String filename;
        public static String input_filename;
        public static String output_message;
        public static System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

        public static FileInfo fInfo;
        public static UTF8Encoding utf8 = new UTF8Encoding();
        public static String image_compression_code;
        public static IntPtr ptr_image_compression_code;


        public static Gtk.FileChooserDialog ofd;


        public static Gtk.Image picture;


        public static IntPtr imageData_byte_array_ptr = IntPtr.Zero; 



        [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);




//int _CreateImageFromRecordBinaryField(int record_type_number, int idc, int* image_width, int* image_height, unsigned char** imageData)

        [DllImport("NIST_library.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]     
        private static extern int _CreateImageFromRecordBinaryField(
            [In] Int32 record_type_number,
            [In] Int32 idc,
            [MarshalAs(UnmanagedType.I4)] out Int32 width,
            [MarshalAs(UnmanagedType.I4)] out Int32 height,
            out IntPtr imageData_byte_array);

        public static int pCreateImageFromRecordBinaryField(
           [In] Int32 record_type_number,
           [In] Int32 idc,
           out Int32 width,
           out Int32 height,
           out byte[] imageData_byte_array)
           
        {
            int retVal = -1;
			
        //static IntPtr imageData_byte_array_ptr = IntPtr.Zero; 				
			
            imageData_byte_array = new byte[1];
			
            width = height = 0;
		
            try
            {
			
//                retVal = _CreateImageFromRecordBinaryField(record_type_number, idc,
//                    out width, out height, out imageData_byte_array_ptr);
                                       
                retVal = _CreateImageFromRecordBinaryField(record_type_number, idc, out width, out height, out imageData_byte_array_ptr);
									   
                int lenght = (int)(width * height * 3);
                imageData_byte_array = new byte[lenght];
                Marshal.Copy(imageData_byte_array_ptr, imageData_byte_array, 0, lenght);

            }
            catch (Exception ex)
            {
				// string path = @"C:\Users\username\Desktop\out_error.txt";
				// string createText = ex.Message;
                // File.WriteAllText(path, createText);
				
				
//              message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "CreateImageFromRecordBinaryField Exception: " + ex.Message);
              message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "CreateImageFromRecordBinaryField Exception");
              message_box_dialog.Run();
              message_box_dialog.Destroy();
            }
            
            return retVal;
            
        }





        [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);





      private static MessageDialog message_box_dialog;
      private static Button CreateAndInsertButton;
      private static Button ReadAndModifyButton;
      private static Button ReadAndExportButton;
      private static Button ReadSingleFieldButton;
      private static Button DeleteSingleFieldButton;
      private static Button RegisterButton;




      static void onWindowDelete(
         object obj, DeleteEventArgs args){
            Application.Quit();
      }



      static void CenterScrolledWindow()
       {
// https://stackoverflow.com/questions/30607429/gtk3-and-multithreading-replacing-deprecated-functions
// Run the main iteration to update the GUI,
// you need to call these functions even if the GUI wasn't modified,
// in order to get it responsive and treat events from it:
         while (Gtk.Application.EventsPending ())
           Gtk.Application.RunIteration ();

         Gtk.Adjustment h_scroller = scrolled_window.Hadjustment;
         h_scroller.Value = (h_scroller.Upper - h_scroller.PageSize) / 2;

         Gtk.Adjustment v_scroller = scrolled_window.Vadjustment;
         v_scroller.Value = (v_scroller.Upper - v_scroller.PageSize) / 2;

// Update the GUI and treat events from it:
         while (Gtk.Application.EventsPending ())
           Gtk.Application.RunIteration ();
       }



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




        static void CreateAndInsertButton_Click(object sender, EventArgs e)
        {

            CreateAndInsertButton.Sensitive = false;
            ReadAndModifyButton.Sensitive = false;
            ReadAndExportButton.Sensitive = false;
            ReadSingleFieldButton.Sensitive = false;
            DeleteSingleFieldButton.Sensitive = false;
            RegisterButton.Sensitive = false;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);



            //Creates new empty NIST file
            _CreateNewNISTFile();


            //======================================================
            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-1 and Type-2 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();



            //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)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("20081031"));

            //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
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("20081031152345Z"));


            //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 + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar;


            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-4 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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 \96 October 28, 2005
            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-7 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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"));



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-8 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            //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"));




            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-10 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("300"));

            //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("VPS"), 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)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("300"));

            //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("VPS"), 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)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("300"));

            //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("VPS"), 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



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-13 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("LCD"), utf8.GetBytes("19990707"));

            //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 (HPS)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("197"));

            //Modifies NIST file, inserts/replaces mandatory Type-13 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(13, idc_current, -1, utf8.GetBytes("VPS"), 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"));



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-14 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            //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)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("19990707"));

            //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 (HPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("197"));

            //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("VPS"), 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"));



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-15 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("500"));

            //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("VPS"), 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)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217"));

            //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 (HPS)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("500"));

            //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("VPS"), 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)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("PCD"), utf8.GetBytes("20091217"));

            //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 (HPS)   
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("500"));

            //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(15, idc_current, -1, utf8.GetBytes("VPS"), 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"));



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Inserting/replacing Type-16 records...");
            message_box_dialog.Run();
            message_box_dialog.Destroy();

            //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("HPS"), utf8.GetBytes("500"));

            //Modifies NIST file, inserts/replaces mandatory Type-16 record
            _InsertRecordTxtField(16, idc_current, -1, utf8.GetBytes("VPS"), 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 + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar;
            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }

            filename = filedirectory + "sample_new.nist";


            //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();
                        //==========================
            */


            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "New NIST file was created, modified and saved as\n\".\\output\\sample_new.nist\"\nPlease use \"NIST viewer\" to view\n\"sample_new.nist\" file.");
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);



        }




        static void ReadAndModifyButton_Click(object sender, EventArgs e)
        {

            CreateAndInsertButton.Sensitive = false;
            ReadAndModifyButton.Sensitive = false;
            ReadAndExportButton.Sensitive = false;
            ReadSingleFieldButton.Sensitive = false;
            DeleteSingleFieldButton.Sensitive = false;
            RegisterButton.Sensitive = false;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);


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


             if (!File.Exists(filename))
            {
                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Error: file .\\input\\sample.nist does not exist.");
                message_box_dialog.Run();
                message_box_dialog.Destroy();

                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)
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("DAT"), utf8.GetBytes("20080931"));

            //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
            _InsertRecordTxtField(1, -1, -1, utf8.GetBytes("GMT"), utf8.GetBytes("20080931170316Z"));


            //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 + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar;


            //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)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("300"));

            //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("VPS"), 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)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("PHD"), utf8.GetBytes("20091217"));

            //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 (HPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("300"));

            //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(10, idc_current, -1, utf8.GetBytes("VPS"), 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)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("TCD"), utf8.GetBytes("19990923"));

            //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 (HPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("HPS"), utf8.GetBytes("197"));

            //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
            _InsertRecordTxtField(14, idc_current, -1, utf8.GetBytes("VPS"), 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 + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar;
            if (!Directory.Exists(filedirectory))
            {
                // Create output directory
                Directory.CreateDirectory(filedirectory);
            }

            filename = filedirectory + "sample_modified.nist";


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


            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_modified.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_modified.nist\" file.");
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);


        }




        static void DeleteSingleFieldButton_Click(object sender, EventArgs e)
        {

            CreateAndInsertButton.Sensitive = false;
            ReadAndModifyButton.Sensitive = false;
            ReadAndExportButton.Sensitive = false;
            ReadSingleFieldButton.Sensitive = false;
            DeleteSingleFieldButton.Sensitive = false;
            RegisterButton.Sensitive = false;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);



            //Sets input file name as "sample.nist" which located in "input" subdirectory
            filedirectory = program_file_path + Path.DirectorySeparatorChar + "input" + Path.DirectorySeparatorChar;
            filename = filedirectory + "sample.nist";
            //filename = filedirectory + "Sample Type-1 2 4 10 15.nist";
            //filename = filedirectory + "Sample Type-9 13 14.nist";
            //filename = filedirectory + "Sample Type-14.nist";
            //filename = filedirectory + "Sample Type-16 001.nist";


            if (!File.Exists(filename))
            {
                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Error: file .\\input\\sample.nist does not exist.");
                message_box_dialog.Run();
                message_box_dialog.Destroy();

                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(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)





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


            filename = filedirectory + "sample_of_deletion.nist";


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



            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, filename);
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_of_deletion.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_of_deletion.nist\" file.");
            message_box_dialog.Run();
            message_box_dialog.Destroy();


            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);


        }






        static void ReadAndExportButton_Click(object sender, EventArgs e)
        {


            CreateAndInsertButton.Sensitive = false;
            ReadAndModifyButton.Sensitive = false;
            ReadAndExportButton.Sensitive = false;
            ReadSingleFieldButton.Sensitive = false;
            DeleteSingleFieldButton.Sensitive = false;
            RegisterButton.Sensitive = false;


            if (ofd.Run() == (int)ResponseType.Accept) 
            {
                input_filename = ofd.Filename;
                ofd.Hide();
            }
            else
            {
                ofd.Hide();

            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            //win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);

                return;
            }


            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);



            // Set output directory
            filedirectory = program_file_path + Path.DirectorySeparatorChar + "output" + Path.DirectorySeparatorChar;


            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(input_filename);
            size_of_byte_array = (int)fInfo.Length;
            fStream = new FileStream(input_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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Type-1 record text field was exported to file .\\output\\type1.txt");
                message_box_dialog.Run();
                message_box_dialog.Destroy();
            }//if(_CheckIfRecordTypeExists(1) == 1)


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

                // In type 2 record there might be up to 12 fingerprint images.
                // Reads NIST file and exports all images to separate files.
                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();

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, "Type-2 record text field was exported to file .\\output\\type2_" + idc.ToString() + ".txt");
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    }


                }//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);

                    // Converts NIST file binary field contents into Image.
                    pCreateImageFromRecordBinaryField(4, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();

                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(7, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(8, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(9, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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.";
// In Gtk label ampersand(&) needs to be escaped
                        output_message = output_message + "\nFacial &amp; SMT image was extracted from type 10 record binary field\nof 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 Image.
                    pCreateImageFromRecordBinaryField(10, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(13, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(14, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(15, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

                }//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 Image.
                    pCreateImageFromRecordBinaryField(16, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                            message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                            message_box_dialog.Run();
                            message_box_dialog.Destroy();
                        }//if ((image_width != 0) & (image_height != 0))

                    }

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


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



            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);


        }



        static void ReadSingleFieldButton_Click(object sender, EventArgs e)
        {


            CreateAndInsertButton.Sensitive = false;
            ReadAndModifyButton.Sensitive = false;
            ReadAndExportButton.Sensitive = false;
            ReadSingleFieldButton.Sensitive = false;
            DeleteSingleFieldButton.Sensitive = false;
            RegisterButton.Sensitive = false;


            if (ofd.Run() == (int)ResponseType.Accept) 
            {
                input_filename = ofd.Filename;
                ofd.Hide();
            }
            else
            {
                ofd.Hide();

            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            //win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);

                return;
            }

            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);



            // 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(input_filename);
            size_of_byte_array = (int)fInfo.Length;
            fStream = new FileStream(input_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)
            {

/*
                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++)

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();
*/


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


                //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;

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();
            }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


                // In type 2 record there might be up to 12 fingerprint images.
                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type2_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(2, i);
                    // Returns contents of NIST file data field as text string (char array).

                    //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 Image designation character (IDC) = " + 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 Image designation character (IDC) = " + 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 Image designation character (IDC) = " + nist_txt_field;


                    message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                    message_box_dialog.Run();
                    message_box_dialog.Destroy();
                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


                // 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++)
                {
                    idc = _ReadIDCofRecord(4, i);
                    // Returns contents of NIST file data field as text string (char array).

                    //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 Image.
                    pCreateImageFromRecordBinaryField(4, idc, out image_width_64, out image_height_64, out image_pixel_data_original); 
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();

                    }//if ((image_width != 0) & (image_height != 0))





                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


                // In type 7 record there might be up to 17 fingerprint images.
                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type7_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(7, i);
                    // Returns contents of NIST file data field as text string (char array).

                    //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 Image.
                    pCreateImageFromRecordBinaryField(7, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    }//if ((image_width != 0) & (image_height != 0))




                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


                // In type 8 record there might be up to 18 fingerprint images.
                // Reads NIST file and shows fingerprint images on the screen.
                for (int i = 1; i <= type8_number_of_records; i++)
                {
                    idc = _ReadIDCofRecord(8, i);
                    // Returns contents of NIST file data field as text string (char array).

                    //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 Image.
                    pCreateImageFromRecordBinaryField(8, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    }//if ((image_width != 0) & (image_height != 0))




                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


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

                    idc = _ReadIDCofRecord(9, i);

                    //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 Image.
                    pCreateImageFromRecordBinaryField(9, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    } //if ((image_width != 0) & (image_height != 0))
                    else
                    {
                        output_message = output_message + "\nMinutiae data was extracted from type 9 record binary field\nof NIST file.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    }




                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


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

                    idc = _ReadIDCofRecord(10, i);


                    //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 (HPS)      
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("HPS")));
                    output_message = output_message + "\nType-10 record Horizontal pixel scale (HPS) = ";
                    output_message = output_message + nist_txt_field;

                    //Reads Type-10 record Vertical pixel scale (VPS)     
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(10, idc, -1, utf8.GetBytes("VPS")));
                    output_message = output_message + "\nType-10 record Vertical pixel scale (VPS) = ";
                    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 Image.
                    pCreateImageFromRecordBinaryField(10, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        //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.";
// In Gtk label ampersand(&) needs to be escaped
                        output_message = output_message + "\nFacial &amp; SMT image was extracted from type 10 record binary field\nof NIST file and converted into HBITMAP for showing on form.";


                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    } //if ((image_width != 0) & (image_height != 0))                 


                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();

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

                    idc = _ReadIDCofRecord(13, i);

                    //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 (HPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("HPS")));
                    output_message = output_message + "\nType-13 record Horizontal pixel scale (HPS) = ";
                    output_message = output_message + nist_txt_field;

                    //Reads Type-13 record Vertical pixel scale (VPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(13, idc, -1, utf8.GetBytes("VPS")));
                    output_message = output_message + "\nType-13 record Vertical pixel scale (VPS) = ";
                    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 Image.
                    pCreateImageFromRecordBinaryField(13, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    } //if ((image_width != 0) & (image_height != 0)) 


                }// 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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();

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


                    idc = _ReadIDCofRecord(14, i);

                    //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 (HPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("HPS")));
                    output_message = output_message + "\nType-14 record Horizontal pixel scale (HPS) = ";
                    output_message = output_message + nist_txt_field;

                    //Reads Type-14 record Vertical pixel scale (VPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(14, idc, -1, utf8.GetBytes("VPS")));
                    output_message = output_message + "\nType-14 record Vertical pixel scale (VPS) = ";
                    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 Image.
                    pCreateImageFromRecordBinaryField(14, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    } //if ((image_width != 0) & (image_height != 0))                 


                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


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

                    idc = _ReadIDCofRecord(15, i);

                    //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 (HPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("HPS")));
                    output_message = output_message + "\nType-15 record Horizontal pixel scale (HPS) = ";
                    output_message = output_message + nist_txt_field;

                    //Reads Type-15 record Vertical pixel scale (VPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(15, idc, -1, utf8.GetBytes("VPS")));
                    output_message = output_message + "\nType-15 record Vertical pixel scale (VPS) = ";
                    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 Image.
                    pCreateImageFromRecordBinaryField(15, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();
                    } //if ((image_width != 0) & (image_height != 0))                                



                }//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();

                message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                message_box_dialog.Run();
                message_box_dialog.Destroy();


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

                    idc = _ReadIDCofRecord(16, i);

                    //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 (HPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("HPS")));
                    output_message = output_message + "\nType-16 record Horizontal Pixel Scale (HPS) = ";
                    output_message = output_message + nist_txt_field;

                    //Reads Type-16 record Vertical Pixel Scale (VPS)
                    nist_txt_field = Marshal.PtrToStringAnsi(_ReadRecordTxtField(16, idc, -1, utf8.GetBytes("VPS")));
                    output_message = output_message + "\nType-16 record Vertical Pixel Scale (VPS) = ";
                    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 Image.
                    pCreateImageFromRecordBinaryField(16, idc, out image_width_64, out image_height_64, out image_pixel_data_original);
                    image_width = (int)image_width_64;
                    image_height = (int)image_height_64;

                    if ((image_width != 0) & (image_height != 0))
                    {

                        rowstride = image_width * 4;
                        image_width_x_4 = image_width * 4;
                        number_of_pixels = image_width*image_height;
                        number_of_pixels_x_2 = number_of_pixels*2;
                        number_of_pixels_x_3 = number_of_pixels*3;
                        number_of_pixels_x_4 = number_of_pixels*4;

                        image_pixel_data = new byte[number_of_pixels_x_4];

                        for (y = 0; y < image_height; y++)
                        {
                           x_padded = 0;
                           row_output = image_width_x_4 * y;

                           row_input = image_width * y;

                           for (x = 0;  x < image_width; x++)
                           {
                              pixel_number_input = x + row_input;
                              pixel_number_output = 3*x_padded + row_output;

                              image_pixel_data[pixel_number_output] = image_pixel_data_original[pixel_number_input]; //red
                              image_pixel_data[pixel_number_output+1] = image_pixel_data_original[pixel_number_input+number_of_pixels]; // green
                              image_pixel_data[pixel_number_output+2] = image_pixel_data_original[pixel_number_input+number_of_pixels_x_2]; // blue

                              x_padded++;
                           }//for (x = 0;  x < image_width; x++)


                        }//for (y = 0; y < image_height; y++)

                        pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
                        picture.Pixbuf = pixbuf;

                        CenterScrolledWindow();

                        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.";

                        message_box_dialog = new MessageDialog(win, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, output_message);
                        message_box_dialog.Run();
                        message_box_dialog.Destroy();

                    } //if ((image_width != 0) & (image_height != 0))      


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

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





            CreateAndInsertButton.Sensitive = true;
            ReadAndModifyButton.Sensitive = true;
            ReadAndExportButton.Sensitive = true;
            ReadSingleFieldButton.Sensitive = true;
            DeleteSingleFieldButton.Sensitive = true;
            RegisterButton.Sensitive = true;
            win.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);



        }






      static void Main() {
         Application.Init();

         win = new Gtk.Window("NIST library demo");
         win.DeleteEvent += new DeleteEventHandler(onWindowDelete);

         win.SetDefaultSize (400, 400);
         //win.Resize(640, 480);
         win.WindowPosition = Gtk.WindowPosition.Center;

         VBox vb = new VBox(false, 20);
         vb.Visible = true;
         win.Add(vb);


//---------------
         scrolled_window = new Gtk.ScrolledWindow (null, null);
         scrolled_window.BorderWidth = 5;
//---------------
//BitmapData data = bitmap.LockBits(new Rectangle(0, 0,bitmap.Width, bitmap.Height,PixelFormat.Format24bppRgb);
//IntPtr scan = data.Scan0;
//int size = image_width * image_height * 3;
//byte[] bdata = new byte[size];
//Gdk.Pixbuf pixbuf = null;
//
//unsafe {
//byte* p = (byte*)scan;
//for(int i = 0; i < size; i++)
//bdata[i] = p[i];
////bdata[i] = 0;
//}
//
//pixbuf = new Gdk.Pixbuf(bdata, false, 8, image_width, image_height, data.Stride, null);
//bitmap.UnlockBits(data);


         picture = new Gtk.Image();

         image_width = 100;
         image_height = 100;

         rowstride = image_width*4;
         number_of_pixels = image_width*image_height*4;
         image_pixel_data = new byte[number_of_pixels];

         for (int i = 0; i < number_of_pixels; i++) 
         image_pixel_data[i] = 255;

//      Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, image_width, image_height);
//	Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn)

	 pixbuf = new Gdk.Pixbuf(image_pixel_data, false, 8, image_width, image_height, rowstride, null);
         picture.Pixbuf = pixbuf;

//---------------
        scrolled_window.AddWithViewport(picture);
        scrolled_window.SetPolicy(Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic);
        vb.Add(scrolled_window);
//---------------


/*
         Gtk.Frame frame = new Gtk.Frame ();
         frame.ShadowType = ShadowType.In;

         // The alignment keeps the frame from growing when users resize
         // the window
         Alignment alignment = new Alignment (0.5f, 0.5f, 0f, 0f);
         alignment.Add(frame);
//         vb.PackStart(alignment, false, false, 0);
//         frame.Add(picture);
         scrolled_window.AddWithViewport(alignment);

*/




         HBox hb2 = new HBox(false, 50);
         hb2.Visible = true;
         vb.PackStart(hb2,false,false,0);

         HBox hb3 = new HBox(false, 50);
         hb3.Visible = true;
         vb.PackStart(hb3,false,false,0);

         CreateAndInsertButton = new Button ("Create and Insert");
         CreateAndInsertButton.Clicked += new EventHandler(CreateAndInsertButton_Click);
         hb2.PackStart(CreateAndInsertButton,false,false,0);

         ReadAndModifyButton = new Button ("Read and Modify");
         ReadAndModifyButton.Clicked += new EventHandler(ReadAndModifyButton_Click);
         hb2.PackStart(ReadAndModifyButton,false,false,0);

         ReadAndExportButton = new Button ("Read and Export");
         ReadAndExportButton.Clicked += new EventHandler(ReadAndExportButton_Click);
         hb2.PackStart(ReadAndExportButton,false,false,0);

         ReadSingleFieldButton = new Button ("Read Single Field");
         ReadSingleFieldButton.Clicked += new EventHandler(ReadSingleFieldButton_Click);
         hb3.PackStart(ReadSingleFieldButton,false,false,0);

         DeleteSingleFieldButton = new Button ("Delete Single Field");
         DeleteSingleFieldButton.Clicked += new EventHandler(DeleteSingleFieldButton_Click);
         hb3.PackStart(DeleteSingleFieldButton,false,false,0);

         RegisterButton = new Button ("Register");
         RegisterButton.Clicked += new EventHandler(RegisterButton_Click);
         hb3.PackStart(RegisterButton,false,false,0);


//--------------
         hBitmap = IntPtr.Zero;

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


         ofd = new Gtk.FileChooserDialog("Choose the file to open",
                                    win,
                                    FileChooserAction.Open,
                                    "Cancel",ResponseType.Cancel,
                                    "Open",ResponseType.Accept);


         Gtk.FileFilter filefilter1 = new Gtk.FileFilter();
         filefilter1.Name = "NIST files";
         filefilter1.AddPattern("*.nist");
         ofd.AddFilter(filefilter1);


         Gtk.FileFilter filefilter2 = new Gtk.FileFilter();
         filefilter2.Name = "All files";
         filefilter2.AddPattern("*.*");
         ofd.AddFilter(filefilter2);


         win.ShowAll();
         Application.Run();
      }
   }
}
