2.1. Accessing Mechanical APDL Binary Files

The BINLIB library is in the dynamic link library \Program Files\ANSYS Inc\V242\ANSYS\custom\misc\<platform>\binlib.dll on Windows systems (where <platform> is a directory that uniquely identifies the hardware platform version) or the shared library /ansys_inc/v242/ansys/customize/misc/<platform>/libbin.so on Linux systems.

2.1.1. Access Routines for Results Files

Demonstration programs that use the BINLIB library for reading and writing Mechanical APDL results files are included on the installation media:

  • ResRdDemo

  • ResWrDemo

  • bintst


Note:  For ResRdDemo.exe to use the Mechanical APDL dynamic link libraries (DLLs), add the following location to the PATH environment variable: Program Files\ANSYS Inc\V242\ANSYS\bin\winx64.


On Windows Systems:

The FORTRAN source for these programs is located in \Program Files\ANSYS Inc\V242\ANSYS\customize\user. The files are named ResRdDemo.F and ResWrDemo.F.

To link these demonstration programs, use the \Program Files\ANSYS Inc\V242\ANSYS\custom\misc\<platform>\RESDEMO.bat procedure file and specify the program that you want to build on the command line. Valid command line options are ResRdDemo, ResWrDemo, and userprog. For example, to build the program to read a results file, type:

\Program Files\ANSYS Inc\V242\ANSYS\custom\misc\<platform>\RESDEMO.bat  ResRdDemo

Appropriate files are then copied from \Program Files\ANSYS Inc\V242\ANSYS\customize\user to your working directory, compiled, and linked. The resulting executable is also placed in your current working directory.

Use the userprog command line option when writing your own customized program, naming the routine userprog.F. The resulting executable is named userprog.exe. When userprog is used, no files are copied from \Program Files\ANSYS Inc\V242\ANSYS\customize\user to your working directory.

These files are loaded onto your system only if you performed a custom installation and chose to install the customization tools.

On Linux systems:

The FORTRAN source for these programs is located in /ansys_inc/v242/ansys/customize/misc. The files are named ResRdDemo.F and ResWrDemo.F.

To link these demonstration programs, use the /ansys_inc/v242/ansys/customize/misc/ResDemo.link procedure file and specify the program that you want to build on the command line. Valid command line options are ResRdDemo, ResWrDemo, and userprog. For example, to build the program to read a results file, type:

/ansys_inc/v242/ansys/customize/misc/ResDemo.link  ResRdDemo

Appropriate files are then copied from /ansys_inc/v242/ansys/customize/misc to your working directory, compiled, and linked. The resulting executable is also placed in your current working directory. Procedure files are available in the /ansys_inc/v242/ansys/bin directory to run these programs, once linked. The procedure files are named ResRdDemo242 and ResWrDemo242.

Use the userprog command line option when writing your own customized program, naming the routine userprog.F. The resulting executable is named userprog.e242. When userprog is used, no files are copied from /ansys_inc/v242/ansys/customize/misc to your working directory. The procedure file is named userprog242.

These files are loaded onto your system only if you performed a custom installation and chose to install the customization tools.

2.1.2. Characteristics of Mechanical APDL Binary Files

Before accessing Mechanical APDL binary files, you need to know certain file characteristics:

  1. A Mechanical APDL binary file is a direct-access, unformatted file. You read or write a record by specifying (as a number) what location to read or write.

  2. Before Mechanical APDL actually writes data to a file on a disk, it uses buffers to store data in memory until those buffers become full. A block number designates these buffers. Most access routines use this block number.

  3. By default, Mechanical APDL files are external files. The standardized "external" format the files use enables you to transport them across different computer systems.

  4. In addition to file names, Mechanical APDL uses file numbers to identify the files. File handles and other information are associated with the file numbers.

  5. Some binary files contain data values that point to the start of certain data (for example, the start of the data steps index table record). Both Mechanical APDL and external binary files access routines use these pointers to locate data on the various binary files.

  6. All data is written out as 32-bit integers. Double-precision data and pointers, therefore, take up two integer words. To create a 64-bit pointer from the two 32-bit integers, use the function largeIntGet.

2.1.3. Viewing Binary File Contents

To view the contents of certain Mechanical APDL binary files, issue the command /AUX2 or choose menu path Utility Menu>File>List>Binary Files or Utility Menu>List>File>Binary Files. (You can do so only at the Begin level.) Mechanical APDL then enters its binary file dumping processor, AUX2, and dumps the binary file record by record.

In AUX2, you can use either the record number (DUMP command) or the record pointer (PTR command). If the file was written in parallel (-NP>1 on the command line), the DUMP command may not work as expected. In that case, only the PTR command may be used.

As an alternative to AUX2, the *XPL command enables you to explore the contents of a Mechanical APDL file and extract data from it. For more information and examples, see Using APDL to List File Structure and Content in the Ansys Parametric Design Language Guide.

2.1.4. Abbreviations

The input and output for the routines discussed in this chapter are described with the following abbreviations:

  • Type of variable is one of the following:

    int - integer (4-byte)
    long - integer (8-byte)
    dp - double-precision
    log - logical (true or false)
    char - character
    comp - double precision complex
  • Size of variable is one of the following:

    sc - scalar variable
    ar(n) - array size n
    func - functional return value
  • Intent of variable is one of the following:

    in - input only
    out - output only
    inout - both an input and an output variable

2.1.5. binini (Initializing Buffered Binary I/O Systems)

*deck,binini
      subroutine binini (iott)
c *** primary function: initialize buffered binary i/o system
c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c     iott      (int,sc,in)       - output unit number for error output

c  output arguments:   none


2.1.6. Function sysiqr (Retrieving the Status of a File)

*deck,sysiqr
      function sysiqr (nunit,fname,lname_in,inqr_in)

c *** primary function: do a file system inquire (system dependent)

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c    variable (typ,siz,intent)    description
c    nunit    (int,sc,in)       - fortran unit number (used only for inqr='O')
c    fname    (chr,sc,in)       - name of file
c    lname_in (int,sc,in)       - length of file name (characters, max=50)
c    inqr_in  (chr,sc,in)       - character key for information requested
c                                 = 'E' - return whether file exists
c                                     sysiqr = 1 - file exists
c                                            = 0 - file does not exist
c                                            < 0 - error occured
c                                 = 'O' - return whether file is open
c                                     sysiqr = 1 - file is open
c                                            = 0 - file is closed
c                                            < 0 - error occured
c                                 = 'N' - return unit number of file
c                                     sysiqr > 0 - unit number for file
c                                            = 0 - file not assigned to a unit
c                                            < 0 - error occured

c  output arguments:
c    sysiqr   (int,func,out)    - the returned value of sysiqr is based on 
c                                       setting of inqr


2.1.7. Function biniqr8 (Retrieving System-Dependent Parameters)

*deck,biniqr8
      function biniqr8 (nblk,key)
c *** primary function: get data about a block i/o buffer
c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c     nblk      (int,sc,in)       - the block number for the inquiry
c                                   or zero (see below)
c     key       (int,sc,in)       - key for information requested
c                      nblk = 0 - return information about system/file
c                               key = 1 - return system block size
c                                   = 2 - return number of integers per dp
c                                   = 3 - return filename length
c                                     5 = return integers per LONG
c                      nblk > 0 - return information about this block
c                               key = 1 - return fortran unit number
c                                   = 2 - return number of pages in file
c                                   = 3 - return length of page (32 bit words)
c                                   = 4 - return open status
c                                         0 - file close
c                                         1 - file open
c                                   = 5 - return file format
c                                         0 - internal format
c                                         1 - external format
c                                   = 6 - return read/write status
c                                         0 - both read & write
c                                         1 - read
c                                         2 - write
c                                   = 7 - return current position on file
c                                   = 8 - return maximum length of file
c                                           (in words)
c                                   = 9 - return starting word for this page
c                                           in buffer
c                                   =10 - return base location
c                                   =11 - return debug key
c                                   =12 - return absolute (non-base) key
c                                   =15 - return max record written
c                                   =16 - return swap and record header key
c                                   =17 - return precision key

c  output arguments:
c     biniqr8   (LONG,func,out)   - the returned value of biniqr is based on
c                                       setting of nblk and key


2.1.8. Function binset (Opening a Blocked Binary File or Initializing Paging Space)

*deck,binset
      function binset (nblk,nunit,ikeyrw,istart,paglen,npage,pname,
     x                 nchar,kext,Buffer4)

c *** primary function: initialize paging space for a blocked binary file.
c                       binset should be used to open a blocked file
c                       before binrd8 or binwrt8 are used.  binclo should
c                       be used to close the file.
c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c     nblk      (int,sc,in)       - block number (1 to BIO_MAXFILES max)
c     nunit      (int,sc,in)      - fortran unit number for the file
c                                   (if 0, bit bucket)
c     ikeyrw    (int,sc,in)       - read/write flag
c                                   =  0 - both read & write
c                                   =  1 - read
c                                   =  2 - write
c                                   =  9 - read only
c       NOTE: 0 may write, but the file length may not be extended and
c               the file may or may not exist
c             1 reads only, but the file protection must set set to "rw"
c             2 may extend the file length and the file is a new file
c             9 reads only, but the file protection may be "r" only
c     istart    (int,sc,in)       - starting location in buffer array
c                                   usually 1 for nblk=1, paglen*npage+1
c                                   for nblk=2,etc.
c     paglen    (int,sc,in)       - page length in integer*4 words for external
c                                   files
c                                   paglen should always be a multiple of
c                                   512 words for efficiency
c     npage     (int,sc,in)       - number of pages (1 to BIO_MAXBLOCKS max)
c     pname     (chr,ar(*),in)    - name of the file
c     nchar     (int,sc,in)       - number of characters in the file name (not
c                                   used)
c     kext      (int,sc,in)       - no longer used, always external format
c     Buffer4   (i4, ar(*),inout) - work array for paging, should be
c                                   dimensioned to paglen*npage*nblk (max)

c  output arguments:
c     binset    (int,func,out)    - error status
c                                   = 0 - no error
c                                   <>0 - error occurred
c     Buffer4   (i4, ar(*),inout) - work array for paging


2.1.9. Subroutine bintfo (Defining Data for a Standard Mechanical APDL File Header)

*deck,bintfo
      subroutine bintfo (title,jobnam,units,code)
c *** primary function:    set information necessary for binhed8
c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c
c *** Notice - This file contains ANSYS Confidential information ***
c
c     typ=int,dp,log,chr,dcp   siz=sc,ar(n)   intent=in,out,inout
c
c  input arguments:
c     variable (typ,siz,intent)    description
c     title    (chr*80,ar(2),in) - main title and 1st subtitle
c     jobnam   (chr*8,sc,in)     - jobname
c     units    (int,sc,in)       - units 
c                                   = 0 - user defined units
c                                   = 1 - SI
c                                   = 2 - CSG
c                                   = 3 - U.S. Customary, using feet
c                                   = 4 - U.S. Customary, using inches
c                                   = 5 - MKS
c                                   = 6 - MPA
c                                   = 7 - uMKS
c     code     (int,sc,in)       - code defining 3rd party vendor
c                                  (contact ANSYS, Inc. for code assignment)
c
c  output arguments:
c     none
c

2.1.10. Subroutine binhed8 (Writing the Standard Mechanical APDL File Header)

*deck,binhed8
      subroutine binhed8 (nblk,nunit,filposL,Buffer4)
c *** primary function:    put standard header on a binary file, all
c                          permanent binary files should have this header
c *** secondary functions: return the first data position

c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c     nblk     (int,sc,in)        - block number of open binary file
c                                   (as defined with subroutine binset)
c     nunit    (int,sc,in)        - the unit number for this file
c     Buffer4  (int,ar(*),inout)  - work array for paging, should be the
c                                   same array as used in binset

c  output arguments:
c     filposL  (LONG,sc,out)      - the position after the header
c     Buffer4  (int,ar(*),inout)  - work array for paging

c   **********  ANSYS standard header data description (100 words)  **********
c  loc   no. words   contents
c   1       1        fortran unit number
c   2       2        file format
c                    = 0 - old internal format
c                    = -1 - external IEEE format 
c                    = 1  old external format
c   3       1        time in compact form (ie 130619 is 13:06:19)
c   4       1        date in compact form (ie 20051023 is 10/23/2005)
c   5       1        units 
c                    = 0 - user defined units
c                    = 1 - SI
c                    = 2 - CSG
c                    = 3 - U.S. Customary, using feet
c                    = 4 - U.S. Customary, using inches
c                    = 5 - MKS
c                    = 6 - MPA
c                    = 7 - uMKS
c   6       1        User_Linked
c  10       1        revision in text format '10.0' (inexc4)
c  11       1        date of revision release for this version
c  12       3        machine identifier - 3 4-character strings
c  15       2        (obsolete - see below) jobname - 2 4-character strings 
c  17       2        product name - 2 4-character strings
c  19       1        special version label - 1 4-character string
c  20       3        user name - 3 4-character strings
c  23       3        machine identifier - 3 4-character strings
c  26       1        system record size at file write
c  27       1        maximum file length
c  28       1        maximum record number
c  31       8        jobname - 8 4-character strings
c  41      20        main title - 20 4-character strings
c  61      20        first subtitle - 20 4-character strings
c  81       1        file compression level
c  82       1        file sparsification key
c  95       1        split point of file
c                     NOTE: Split files are not support by binlib!
c  96       1        reserved for future use
c 97-98     2        LONGINT of file size at write


A version of binhed8 exists without the "8" suffix (binhed.F) that takes a regular integer for the third argument. This subroutine, therefore, cannot address large files where the file position exceeds 2**31. Use the binhed8.F version for any new program.

2.1.11. Subroutine binrd8 (Reading Data from a Buffered File)

*deck,binrd8
      subroutine binrd8 (nblk,LongLocL,leng,ivect,kbfint,Buffer4)

c **********  buffer read routine  **********

c --- This routine is intended to be used in standalone programs.
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c   nblk    (int,sc,in)      - block number.  see fd___(i.e. fdresu for results
c                              file, etc.) include decks for more information.
c   LongLocL(LONG,sc,inout)  - location in integer*4 words of the startin
c                              position on the file.
c   leng    (int,sc,inout)   - number of words to read into ivect. (must be 
c                              less or equal to dimension given to ivect in 
c                              the calling routine).  if ivect is to be used
c                              as integers, use as is.  if ivect is to be
c                              used for double precision numbers, it must be
c                              increased by multiplying it by INTPDP.  
c                              if negative, skip record and do not return 
c                              data(results).
c   Buffer4 (i4,ar(*),inout) - work array for paging, should be the
c                              same array as used in binset

c  output arguments:
c   LongLocL(LONG,sc,inout)  - location in integer*4 words of the current 
c                              position on the file.  It is updated after 
c                              each read operation
c   leng    (int,sc,inout)   - tells you how many items it actually read(in
c                              integer words). 
c                              if zero, end of file(error case)
c   ivect   (int,ar(*),out)  - results (can be either integer or double 
c                              precision in the calling routine)
c   kbfint  (int,sc,out)     - key for type(used only for AUX2 dump)
c                              = 0  double precision data
c                              > 0  integer data(usually the same as leng)
c   Buffer4 (i4,ar(*),inout) - work array for paging


Versions of binrd8/binwrt8 exist without the "8" suffix (binrd/binwrt) that take a regular integer for the second argument. These subroutines, therefore, cannot address large files where the file position exceeds 2**31. Use the binrd8/binwrt8 versions for any new programs.

2.1.12. Subroutine binwrt8 (Writing Data to a Buffered File)

*deck,binwrt8
      subroutine binwrt8 (nblk,LongLocL,leng,ivect,kbfint,Buffer4)

c *** primary function: buffer write routine

c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c   nblk    (int,sc,in)       - block number.  see fd___(i.e. fdresu for results
c                               file, etc.) include decks for more information.
c   LongLocL(LONG,sc,inout)   - location in integer words of the starting
c                               position on the file.
c   leng    (int,sc,in)       - number of words to read from ivect. (must be 
c                               less or equal to dimension given to ivect in 
c                               the calling routine).  if ivect is to be used
c                               as integers, use as is.  if ivect is to be
c                               used for double precision numbers, it must be
c                               increased by multiplying it by INTPDP.
c   ivect   (int,ar(*),in)    - data to be written onto the file(can be either
c                               integer or double precision in the calling
c                               routine)
c   kbfint  (int,sc,in)       - key for type(used only for AUX2 dump)
c                               = 0  double precision data
c                               > 0  integer data(usually the same as leng)
c   Buffer4 (int,ar(*),inout) - work array for paging, should be the
c                               same array as used in binset on this block

c  output arguments:
c   LongLocL(LONG,sc,inout)   - location in integer words of the current
c                               position on the file.  It is updated after 
c                               each write operation
c   ivect   (int,ar(*),out)   - vector containing record to be written
c   Buffer4 (int,ar(*),inout) - work array for paging


Versions of binrd8/binwrt8 exist without the "8" suffix (binrd/binwrt) that take a regular integer for the second argument. These subroutines, therefore, cannot address large files where the file position exceeds 2**31. Use the binrd8/binwrt8 versions for any new programs.

2.1.13. Subroutine exinc4 (Decoding an Integer String into a Character String)

*deck,exinc4
      subroutine exinc4 (ichext,chin,n)
c primary function: decode externally formatted integer versions of 4-character
c                   strings to plain 4-character strings (used to convert data
c                   from externally formatted files to data for interally
c                   formatted files)
c
c *** Notice - This file contains ANSYS Confidential information ***
c
c  input arguments:
c     ichext   (int,ar(n),in)    - externally formatted integer form of
c                                  4-character strings
c     n        (int,sc,in)       - number of strings to convert
c
c  output arguments:
c     chin     (char,ar(n),out)  - strings in character form


2.1.14. Subroutine inexc4 (Coding a Character String into an Integer String)

*deck,inexc4
      subroutine inexc4 (chin,ichext,n)
c primary function: encode plain 4-character strings into externally formatted
c                   integer versions of 4-character strings (used to convert 
c                   data from internally formatted files to data for 
c                   externally formatted files)
c
c *** Notice - This file contains ANSYS Confidential information ***
c
c  input arguments:
c     chin      (char,ar(n),in)   - strings in character form
c     n         (int,sc,in)       - number of strings to convert
c
c  output arguments:
c     ichext    (int,ar(n),out)   - externally formatted integer form of 
c                                   4-character strings


2.1.15. Subroutine binclo (Closing or Deleting a Blocked Binary File)

*deck,binclo
      subroutine binclo (nblk,pstat,Buffer4)
c *** primary function: close a blocked file, every block/file opened with
c                       binset should be closed with binclo
c *** secondary function: the file can be deleted by specifying 'D' in pstat
c --- This routine is intended to be used in standalone programs. 
c --- This routine should not be linked into the ANSYS program.

c *** Notice - This file contains ANSYS Confidential information ***

c  input arguments:
c     nblk      (int,sc,in)       - the block number to close
c                                   (as defined with subroutine binset)
c     pstat     (chr,sc,in)       - keep or delete flag
c                                   = 'K' - keep file
c                                   = 'D' - delete file
c     Buffer4   (int,ar(*),inout) - work array for paging, should be the
c                                   same array as used in binset

c  output arguments:
c     Buffer4   (int,ar(*),inout) - work array for paging


2.1.16. Subroutine largeIntGet (Converting Two Integers into a Pointer)

*deck,largeIntGet
      function largeIntGet (small,large)

c primary function:    Convert two short integers into a long integer

c object/library:  res
                                       
c *** Notice - This file contains ANSYS Confidential information ***
                                                                 
c  input arguments:
c     small        (int,sc,in)       - least significant part
c     large        (int,sc,in)       - most significant part
                                             
c  output arguments:
c     largeIntGet  (LONGINT,sc,out)  - 64 bit integer