| Functions | Modes |
|---|---|
| ier = cg_open(char *filename, int mode, int *fn); | r w m |
| ier = cg_version(int fn, float *version); | r w m |
| ier = cg_close(int fn); | r w m |
| call cg_open_f(filename, mode, fn, ier) | r w m |
| call cg_version_f(fn, version, ier) | r w m |
| call cg_close_f(fn, ier) | r w m |
| filename | Name of the CGNS file, including path name if necessary. There is no limit on the length of this character variable. | ||
| mode | Mode used for opening the file. The modes currently supported are MODE_READ, MODE_WRITE, and MODE_MODIFY. | ||
| fn | CGNS file index number. | ||
| version | CGNS version number. | ||
| ier | Error status. |
The function cg_open must always be the first one called. It opens a CGNS file for reading and/or writing and returns an index number fn. The index number serves to identify the CGNS file in subsequent function calls. Several CGNS files can be opened simultaneously. The current limit on the number of files opened at once depends on the platform. On an SGI workstation, this limit is set at 100 (parameter FOPEN_MAX in stdio.h).
The file can be opened in one of the following modes:
| MODE_READ | Read only mode. | ||
| MODE_WRITE | Write only mode. | ||
| MODE_MODIFY | Reading and/or writing is allowed. |
When the file is opened, if no CGNSLibraryVersion_t node is found, a default value of 1.05 is assumed for the CGNS version number. Note that this corresponds to an old version of the CGNS standard, that doesn't include many data structures supported by the current standard.
The function cg_close must always be the last one called. It closes the CGNS file designated by the index number fn and frees the memory where the CGNS data was kept. When a file is opened for writing, cg_close writes all the CGNS data in memory onto disk prior to closing the file. Consequently, if is omitted, the CGNS file is not written properly.
In order to reduce memory usage and improve execution speed, large arrays such as grid coordinates or flow solutions are not actually stored in memory. Instead, only their ADF (or HDF) ID numbers are kept in memory for future reference. When a CGNS file is open in writing mode, large arrays passed to the library are immediately written into the CGNS file, directly under the root node. When the file is closed, these arrays are moved to their appropriate location in the CGNS tree.