File Handling   

<<< Introduction to the Frustrum Chapters File Header Structure >>>

Contents

[back to top]


2.1 Introduction

Parts modelled in Parasolid are saved to external storage using functions in your application’s Frustrum. Parasolid part files ( transmit or XT files) are intended to fit into an archiving system within your application. This could take the form of a controlled directory structure on the host computer, or some kind of database.

Parasolid also requires facilities to save and retrieve large amounts of data in order to support such operations as saving and restoring snapshots and journalling.

Whilst such facilities could be implemented in a number of ways, they are described here in terms of an implementation based on the use of files provided by the host operating system.

2.1.1 Key names vs. file names

A distinction is made between the name of a key, which is passed by Parasolid as an argument to FFOPRD and FFOPWR (or UCOPRD and UCOPWR for Unicode keys) and the name of a file (which is used internally to identify the Frustrum files to the operating system).

The name of the key which is passed to the Frustrum by Parasolid is exactly the same as the name which has been given in the relevant PK call (PK_PART_transmit, PK_SESSION_transmit, PK_SESSION_start etc.), except in the case of schema files where the key has been generated by Parasolid.

The file name depends entirely on the particular implementation of the Frustrum, but typically this might include the key plus directory prefixes and file extensions as appropriate.

2.1.2 Filename extensions

The following filename extensions are recommended for the Frustrum to generate and use.

 

 

FAT

UNIX/NTFS

part

.X_T

.xmt_txt

mesh

.M_T

.xmm_txt

schema

.S_T

.sch_txt

journal

.J_T

.jnl_txt

snapshot

.N_T

.snp_txt

partition

.P_T

.xmp_txt

delta

.D_T

.xmd_txt

binary

.*_B

.***_bin

debug report

*.xml

*.xml

The Frustrum should test whether a file resides on a DOS style FAT device or a long name NTFS type device before opening the file, and act accordingly. Files can simply be renamed when transferring between the different systems.

Note that the 3 character extensions are shown in the table in upper case for clarity, though the case is ignored.

2.1.3 File guises

Parasolid requires the Frustrum to support different types (or guises) of file, represented by six-character integer mnemonic codes.

The following guises are opened for reading by FFOPRD and UCOPRD. The file should already exist, and its contents can be read sequentially by FFREAD.

The following guises are opened for writing by FFOPWR and UCOPWR. A new file is created, and it can be written to sequentially by FFWRIT:

When all of a new file has been written or sufficient of an existing file has been read, the file is closed with FFCLOS. In the case of new files, the call specifies whether or not the new file is to be retained.

2.1.4 File header

There is a standard format for a Frustrum file header, which is described in Chapter 3, “File Header Structure”.

2.1.5 Number of files open concurrently

In normal operation, Parasolid only has a journal file open, which is open for writing.

For short periods, Parasolid may need to have up to two more files open. These are either a snapshot file or a transmit file, possibly with its associated schema file.

The Frustrum implementation must therefore allow for three files to be open at the same time for each Parasolid process.

[back to top]


2.2 Unicode filenames

Parasolid supports the use of 16-bit Unicode filenames in your application, as well as the native character set. This is achieved by using the following frustrum functions instead of FFOPRD and FFOPWR:

 

Function

Description

UCOPRD

Open various guises of part file for reading. The part file has a filename encoded in Unicode format.

UCOPWR

Open various guises of part file for writing. The part file has a filename encoded in Unicode format.

To use these functions, you must call PK_SESSION_set_unicode before registering the frustrum. Once called, you must then supply valid UCOPRD and UCOPWR functions instead of FFOPRD and FFOPWR functions when registering the frustrum. For more information about registering the frustrum, see Chapter 5, “Registering the Frustrum”.

To find out whether Unicode keys are enabled within a given session, call PK_SESSION_ask_unicode.

[back to top]


2.3 File formats

Parasolid regards a file as being simply a stream of bytes, which is written or read sequentially. It is assumed that the stream of bytes obtained when reading is identical to that which was written (except in the case of a file ported between systems, when the character set may change).

2.3.1 Text and binary

Parasolid distinguishes between binary files and text files:

When writing certain files via the Frustrum, the application needs to specify whether they are to be in text or binary format. A file must be written and read in the same format (thus is Frustrum dependent). When deciding which format to use, consider the following factors:

 

Note: We recommend that your Frustrum creates text files as stream, i.e. LF terminated, rather than using the DOS default (CR and LF terminated). Implementation details can be found in the Example Frustrum.

2.3.2 Application I/O

There is also a transmit file format called application i/o, or applio. When this transmit_format is selected in PK_PART_transmit and PK_PARTITION_transmit, transmit files are written and read using a suite of functions provided by the application. Using these functions enables the application to do further processing of the output data before storing it.

The applio function interfaces are defined in Appendix E, “Application I/O Functions”.

2.3.3 Indexed I/O

There is also a transmit file format called indexed i/o, or indexio. When this transmit_format is selected in PK_PART_transmit and PK_PARTITION_transmit, transmit files are written using a suite of functions provided by the application. Using these functions enables your application to subsequently receive only specified faces from the parts contained in the transmitted files.

The indexio function interfaces are defined in Appendix F, “Indexed I/O Functions”.

2.3.4 Portability

It is clearly desirable that Parasolid files be portable between different machines and between different systems which use Parasolid (which have different Frustrum implementations). In practice, machine specific binary files cannot be ported from one type of machine to another, so the best that can be achieved is:

In order that files be portable between different Frustrum implementations, it is necessary to standardize the internal format of the file. For this reason, we recommend that all Frustrum implementations should generate files in the same format as is generated by the appropriate C runtime library functions on the appropriate machine. In the case of text files, this includes correct handling of newline ( \n ) characters.

To ensure portability of text files between different machine types, we require that:

It is also necessary that, when a text file is ported to a different type of machine, it is converted to the local character set and C format for the the target machine.

If a Frustrum implementation does not follow the above recommendations it may prove impossible to read files which have been created by other systems or to forward its own files to other systems (such as when making a fault reporting). Problems of this sort may be revealed by running the Frustrum validation tests, but note that these tests cannot verify that the file format is consistent with the C runtime library, so some additional check is required to confirm that this is the case.

[back to top]


2.4 Characteristics of different file guises

2.4.1 FFCSNP

Snapshot files are created by PK_SESSION_transmit. The data within the snapshot files is schema dependent and Parasolid needs to have access to the corresponding schema file in order to interpret it.

2.4.2 FFCJNL

Journal files are created as a result of calling PK_SESSION_start with journalling switched on. They are always created in text format. The files are used to record the values of arguments which have been passed to and received from PK and KI functions.

Journal files are reasonably portable between machines, except where the arguments specify such machine dependent features as file names or database keys or where they refer to parts which were created in an earlier session.

2.4.3 FFCXMT

Transmit files containing parts, created by PK_PART_transmit. The data within the transmit files is schema dependent and Parasolid needs to have access to the corresponding schema file in order to interpret it.

2.4.4 FFCSCH

Schema files are created by Parasolid to have names of the form sch_ n (where n represents an integer value).

The integer value is used internally by Parasolid to identify any changes which have been made to the Parasolid schema.

The schema describes the internal data structure which is used to represent part data within the Parasolid model, such as the ordering of geometric data and the relationships between edges and faces.

The Frustrum should store schema files in a separate directory. The KID Frustrum stores them in a directory which is referenced by the P_SCHEMA environment variable.

Note that the Parasolid release includes a set of schema files for all previous versions of Parasolid and for the current version of the Parasolid modeller. This ensures upgrade compatibility of old part files.

Application writers should include a full set of schema files with their product release, including one for the current version of the Parasolid modeller.

In operating systems which have case specific file names the KID Frustrum chooses to write and read the schema archive file in lower case. Any old schema files that are supplied with a release have lower case file names.

2.4.5 FFCLNC

Licence files may be used in subsequent versions to check that Parasolid is being used in accordance with the licencing agreement. The validation tests for Frustrum implementations require this guise of file to be supported by FFOPRD & FFOPWR, so that the licence checking capability can be introduced in a later release of Parasolid, without the need to alter the Frustrum interface further.

It is intended that licence files are created in text format; consisting of a standard file header followed by one or more lines of licence checking data.

2.4.6 FFCXMP

Transmit files containing a partition, created by PK_PARTITION_transmit and read by PK_PARTITION_receive.

2.4.7 FFCXMD

Transmit files containing deltas, created by PK_PARTITION_transmit if the option to transmit deltas is selected. During the transmit, the partition's deltas are opened, read and output to the transmit file (using the delta handling functions registered with PK_DELTA_register_callbacks).

Delta files can only be received in the version they were transmitted in. They are read by PK_PARTITION_receive_deltas_2, if the option to receive deltas later was selected when the relevant partition was read in by PK_PARTITION_receive.

2.4.8 FFCDBG

Debug report files are created as a result of calling PK_DEBUG_report_start. They are always created in XML format. These files are used to record information such as the values of arguments passed to and returned by Parasolid functions, as well as embedding relevant part files.

2.4.9 FFCXMM

Transmit files containing Persistent Mesh (PSM) mesh data.

[back to top]


2.5 Open modes

There are the basic modes in which files are used by Parasolid.

2.5.1 open_read

This mode is characteristic of receiving a Parasolid transmit file, receiving a snapshot file or reading an archived schema file.

A test is made first for whether there is any header data and whether the ‘skip header’ flag is set. If so, the header data is read and checked as deemed necessary by the implementation. If there is no header data or if the header data is to be left (for checking by the Frustrum validation tests), the file pointer is repositioned back to the start of the file.

The file is read sequentially until sufficient data has been read or until the end of file is reached. The file is then closed (and it is retained).

2.5.2 open_new

This mode is characteristic of recording a new journal or debug report file.

The file is opened for writing and the header data are written to it. Parasolid then writes sequentially to the file, journalling the arguments to each interface function. The new file is closed and is retained.

If the system crashes while the journal or debug report file is still open, the system is left with a (possibly incomplete) file. Even in its incomplete form, this file can be useful for debugging a session.

2.5.3 open_protected

This mode is used for creating new transmit, schema and snapshot files.

The difference between the open_protected and the open_new modes is that the Frustrum helps to prevent Parasolid from accessing incomplete or otherwise erroneous files. If an error is detected by Parasolid when writing to a new file, the call to FFCLOS is made with the status code FFABOR, meaning that the file must be deleted when the strid is closed down.

However, if new files are not closed explicitly (as could occur after a system crash), it is possible that a newly created file is not complete.

The Frustrum can protect Parasolid from incomplete files by creating new transmit, schema and snapshot files with scratch names, only giving them their correct identity after the files have been closed explicitly by a call to FFCLOS.

2.5.4 Summary of open modes

The three basic methods of using files are summarized in the following table:

 

 

 

open_read

open_new

open_protected

open mode

FFOPRD

Y

 

 

FFOPWR

 

Y

Y

UCOPRD

Y

 

 

UCOPWR

 

 

Y

file guise

FFCSCH

Y

 

Y

FFCXMT

Y

 

Y

FFCSNP

Y

 

Y

FFCJNL

 

Y

 

FFCLNC

Y

 

 

FFCDBG

 

Y

 

operation

FFREAD

Y

 

 

FFWRIT

 

Y

Y

close mode

FFCLOS with action normal

Y

Y

Y

FFCLOS with action abort

 

 

Y

An entry Y denotes that Parasolid calls the given function in the way which is described by the comment above the column. The file guises XMP and XMD (transmit files containing partition and delta data) use the same methods as XMT (part transmit) files.

[back to top]


2.6 Explanation of the special characters in a journal file

Journal files contain the following markup characters to assist with interpretation of the contents.

2.6.1 Record and element symbols

 

Symbol

Description

:

The first and last lines are comment records, which start with a ‘:’ character.

<

The ‘<’ character at the beginning of each journal record is followed by the name of a PK function. This is followed by a sequence of lexical items, being tags, text strings, integers, doubles and punctuation symbols. These are separated by one or more spaces.

  • when journal records are written over more than one line, the continuation lines start with a space
  • nested PK calls are shown with one angle bracket for each nesting depth; if there is an error, and PK_SESSION_tidy is called, the level is reset back to 0

#

A tag is represented by a ‘#’ character, followed by digits.

“ ”

A string is enclosed in quotation marks (two successive quotation marks imply that the string itself contains a quotation mark).

(-)nnn

Integer values are represented by an (optional) sign, followed by digits.

(-)nn.nnn
5.6e07
-5.6e-07

Double values are represented by an (optional) sign, followed by a floating point representation (with a decimal point) or an exponent and mantissa representation (with an ‘e’ character).

@

Function pointers are journalled as addresses.

2.6.2 Punctuation symbols

 

Symbol

Description

;

the semi-colon separates received arguments from returned arguments

&

the ampersand concatenates adjacent text strings (the journalling system sometimes needs to split a long text string when writing it to file)

[ ]

square brackets enclose an array of some type (all elements of the array have the same type); if an array or pointer argument is supplied as NULL, this is journalled as the address value @0

( )

round brackets enclose a list of doubles (e.g. vectors)

{ }

curly brackets enclose a list of structure members, e.g. a standard form

 

[back to top]

<<< Introduction to the Frustrum Chapters File Header Structure >>>