GDBOpen -- Open Generic Database File

GDBOpen() is used to open a GDB supported image data file. It will try each available file type in turn till it succeeds or all have failed.

See Also: GDBRegister(), GDBReopen(), ALLRegister(), GDBTestOpen(), GDBGetFormatInfo(), fp2type(), Writing GDB Formats, GDB Vector Introduction

CALL SEQUENCE

FILE    *GDBOpen( filename, access );
const char *filename;
           Name of database file to open.
const char *access;
           Access level to open file with.  One of "r" for 
           read or "r+" for read/write.
A FILE * will be returned if the open is successful. If it is necessary to determine what type of database has been opened fp2type() may be used. Note that any database types which are to be supported should be registered before GDBOpen() is called. ie. ALLRegister().

If the file format is not supported, or something is improper about the file when attempting to open it, a fatal IMP error will be generated. If trapped using IMPFatal(FALSE), then GDBOpen() will return NULL.

Special Considerations

FILE HANDLE REUSE:

In selected circumstances GDBOpen() will return the FILE * of an existing open dataset, and automatically increment the file reference count on that file using fpReference(), rather than actually open a new file handle. This is done to reduce use of system file handle resources (limited on most systems), and to ensure that a consistant state is maintained for the file relative to this program.

Reuse of an existing file handle will occur if:

Note that GDBClose() also understands reference counting on files.

PATH MUNGING:

In selected circumstances the GDBOpen() function will use IMPMunge() and IMPSearchFile() to replace environment variables, convert the filename to local path conventions and tweek case sensitivity problems. This can be useful so that paths stored in files, and under other conditions can be - automatically massaged when switching platforms (ie. Unix to Windows), and so that paths may be relative to movable trees (ie. $PCIHOME). This is done in the following circumstances:

If after IMPMunging() the file is not found with DKCheck(), then IMPSearchFile() is given an opportunity to find the file with different case (upper/lower case letters).

Note this doesn't actually affect the string passed into GDBOpen(), but it does affect the filename recorded by GDBOpen() and returned with fp2filename(). Also note that DKStat(), and DKCheck() do not do this path munging, so if you DKCheck() for the existance of a file before opening it then mungable files won't be found.

DKOpen() performs similar filename munging at it's level.

See Also: IMPFileSearch(), IMPMunge()

EXAMPLE

Open a file, and if successful report the number of pixels, lines and channels. Then close it.

         bOldFatal = IMPFatal( FALSE );
         fpCurrent = GDBOpen( filename, "r" );
         IMPFatal( bOldFatal );

         if( fpCurrent == NULL )
         {
             ... no such file, or not a supported format, or corrupt file ...
             return;
         }

         printf( "File Size: %dx%d with %d channels.\n",
                 GDBChanXSize(fpCurrent), GDBChanYSize(fpCurrent),
                 GDBChanNum(fpCurrent) );

         GDBClose(fpCurrent);

@filename{gdblistfilemask}
@title{GDBListFileMask}{retrive the file mask of registered GDB formats}

Retrieve the file mask of registered GDB formats. This list is used
to pass the SGL file selector.

See Also: GDBOpen

1      CALL SEQUENCE

char            *GDBListFileMask(nSegment, nMode, bAddAllFiles, pszAdditionalTypes)

int             nSegment;
                    Segment type to list. Valid options.
                    LAYER_FILE for list of all files
                    LAYER_IMAGE for list of images
                    SEG_VEC for list of vector layers

int             nMode
                   Mode to access files. To get a list of files which 
                   can be exported to use GDB_WRITE else use GDB_READ

   TBool   bAddAllFiles
        Should the file type All Files (*,*) be added to the list.
        If TRUE All Files is added to the front of the list.

   char    *pszAdditionalTypes
        Additional file types which are added to the list. They are 
        added to the front but after the optional All Files type.
        Additional types should be in the form: 
        MyType Files (.xxx) *.xxx|
        pszAdditionalTypes can be NULL.

Returns a string with the file extensions.

1      EXAMPLE

Get a list of writable vectors

char *pszList;

pszList = GDBListFileMask(SEG_VEC, GDB_WRITE, TRUE, NULL);

About PCI Help Gateway