NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

question about opening same file multiple times...

NOTE: The netcdf-hdf mailing list is no longer active. The list archives are made available for historical reasons.

Howdy HDF5 Folk!

I have a question about opening the same file twice. I am finding that
I can open the same file twice, unless I first open it for read-only
access, and the try and open it for read-write access.

The code below demonstrates. Do I have it correctly? Does the same
rule apply for parallel situation? (That is, does the writer always
have to open the file first?)

Thanks!

Ed


   /* Confirm that the same file can be opened twice at the same time,
    * for read only access. */
   if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
   if ((fileid2 = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
   if (H5Fclose(fileid) < 0) ERR;
   if (H5Fclose(fileid2) < 0) ERR;

   /* Once open for read only access, the file can't be opened again
    * for write access. */
   if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
   if ((fileid2 = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) >= 0) ERR;
   if (H5Fclose(fileid) < 0) ERR;

   /* But you can open the file for read/write access, and then open
    * it again for read only access. */
   if ((fileid2 = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
   if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
   if (H5Fclose(fileid) < 0) ERR;
   if (H5Fclose(fileid2) < 0) ERR;



-- 
Ed Hartnett  -- ed@xxxxxxxxxxxxxxxx


  • 2005 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-hdf archives: