Re: 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.

Hi Ed,

> 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?)

    Yes.  Since the library uses only one system call to open the file, it can't
"upgrade" a read-only file to one that permits writing.

    Quincey

> 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: