!9999999999999999999999999999
character*4096 program_file_path
character*4096 filename_incomplete
!character*4096 filename
character*1024 output_message
integer*4 size
integer*4, pointer:: nist_txt_field_ptr(:)
character, target  :: nist_txt_field
character nist_binary_field
!character byte_array
integer size_of_byte_array
character i_string

BYTE, POINTER :: byte_array(:)


character, pointer  :: pp1 
character, target :: p1, p2 


INTEGER*4::         iSt, hData
CHARACTER::       sText(*); POINTER(pText, sText)
!9999999999999999999999999999


=================================







     ! Instead function ReadNISTFile you can use function ReadNISTFromMemory (the code bellow)
!==========================

 !    OPEN(UNIT=9, FILE=filename, FORM='unformatted', STATUS='old')
!     CALL readin(9, byte_array)
!	 size_of_byte_array = SIZE(byte_array)
!     WRITE(*,*)'array of ', size_of_byte_array, ' points:'
!     WRITE(*,*) byte_array


     ! 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.     
!     i = ReadNISTFromMemory(byte_array, %VAL(size_of_byte_array))

     ! Here you need to free memory resources.
     ! byte_array is no longer needed after it has been read and decoded into usable format. 
!     DEALLOCATE(byte_array)
!==========================



     ! Sets the current pointer to specified record and data field for further processing.
     ret = SetPointerToNISTRecord(%VAL(1), %VAL(0))
     ! Returns size of text NIST field.
     size = ReadSizeOfTxtNISTField()

!     ALLOCATE(nist_txt_field_ptr(size))
!	 ALLOCATE(pText(size))
	 

     ! Returns contents of NIST file data field as text string (char array).     
!     nist_txt_field = ReadTxtNISTField()
!     nist_txt_field_ptr => nist_txt_field


      !(pText , ReadTxtNISTField() )



!nist_txt_field_ptr => nist_txt_field




     !pp1 => %VAL(ReadTxtNISTField())
! now dereference pp1 
!p2 = pp1


!nist_txt_field_ptr = nist_txt_field

!     ALLOCATE(nist_txt_field_ptr(size))
!nist_txt_field = "valio"


     ! Sets filename for saving exported data of text field from type 1 record
     filename = "C:\NIST\NIST_Compaq_Fortran\type1.txt"  
!     strcpy(filename, program_file_path);
!     strcat(filename, "type1.txt");

     ! Writes exported data of text field from type 1 record to the file
     OPEN(UNIT=1, FILE=filename, STATUS="REPLACE")
     WRITE(1,"(a)") i_string
     CLOSE(UNIT=1)



     ret = MessageBox (ghwndMain, & 
           "Type 1 record text field was exported to file .\\output\\type1.txt"C, &  
           "NIST Library Demo"C, MB_OK) 

return


     ! Sets the current pointer to specified record and data field for further processing.
     ret = SetPointerToNISTRecord(%VAL(2), %VAL(0))
     ! Returns size of text NIST field.
     size = ReadSizeOfTxtNISTField()
     ! Returns contents of NIST file data field as text string (char array).     
!     nist_txt_field = ReadTxtNISTField();




     ret = MessageBox (ghwndMain, & 
           "Type 2 record text field was exported to file .\\output\\type2.txt"C, &  
           "NIST Library Demo"C, MB_OK) 


===============================
===============================



       WRITE(output_message,"(a,i4,a,i4,a)") "Type 4 record text field was exported to file .\output\type4_",i,".txt"// CHAR(13)// &
       "Type 4 record binary field was exported to file .\output\type4_",i,".wsq"//CHAR(13)// &
       "WSQ image was extracted from type 4 record binary field"//CHAR(13)// &
       "of NIST file and converted into HBITMAP for showing on form"//CHAR(0)


        ret = MessageBox (ghwndMain, & 
              output_message, &  
              "NIST Library Demo"C, MB_OK) 




