From: Chris Siebern on
Abstract:
Creating multiple memmapfile object in a single binary file. Can read the first one no issues, reading the second errors out,"file being used by another process." How can I map discontinuous sections of a file? Yes i verified I have closed the file with fclose(fid);.

Detailed:
I have written a function that creates 2 memmapfile objects from the same source file. The binary file has 3 distinct sections. Header, variable length record, and the data. I need map the header and the data.

The first memmapfile object is the file header which is 227 bytes long. The second memmap object skips the variable length record using the offset to the data from the header to get to the necessary data section and maps the data structure.

I can read the header without issues. However when I read from the second memmapfile object to get query the data, I get the following error:

EDU>> LasData.Data
??? Error using ==> hMapFile
Cannot map file "C:\Documents and Settings\csiebern\My Documents\Purdue\CE597 GIS\CE597 Term Project\000007.las": The process
cannot access the file because it is being used by another process.

Error in ==> memmapfile.memmapfile>memmapfile.hCreateMap at 273
hMapFile(mapfileInputStruct);

Error in ==> memmapfile.memmapfile>memmapfile.subsref at 623
hCreateMap(obj);
The diagram in the help documentation suggests that multiple memmap objects can exist for the same file. I'm not sure what my issue is.
From: Walter Roberson on
Chris Siebern wrote:
> Abstract: Creating multiple memmapfile object in a single binary file.
> Can read the first one no issues, reading the second errors out,"file
> being used by another process." How can I map discontinuous sections of
> a file? Yes i verified I have closed the file with fclose(fid);.

I see from your detailed description that you are using a Windows PC. With
Windows, you will very likely run into this problem if the Writable attribute
is set for either of the maps. I don't mean to imply that setting Writable
false (the default) is certain to cure the problem, but rather that Windows
does not like sharing files if any of the accesses are for writing.

This sort of a thing is not usually a problem for unix style systems (though
some unix style systems can be configured to force it to be a problem --
something that can be beneficial if you have multiple processes updating the
same file and you wish to enforce file coherency.)

If your accesses are already read-only... sorry, I do not know a good
solution. One of the regulars sometimes posts reference to an executable that
will force Windows to unlock files so that they can be written to.
From: Chris Siebern on
Thanks Walt, that was the issue. I'll have to address changes programatically later. Windows can be frustrating!!!!

"Chris Siebern" <csiebern(a)purdue.edu> wrote in message <hor7pe$9qv$1(a)fred.mathworks.com>...
> Abstract:
> Creating multiple memmapfile object in a single binary file. Can read the first one no issues, reading the second errors out,"file being used by another process." How can I map discontinuous sections of a file? Yes i verified I have closed the file with fclose(fid);.
>
> Detailed:
> I have written a function that creates 2 memmapfile objects from the same source file. The binary file has 3 distinct sections. Header, variable length record, and the data. I need map the header and the data.
>
> The first memmapfile object is the file header which is 227 bytes long. The second memmap object skips the variable length record using the offset to the data from the header to get to the necessary data section and maps the data structure.
>
> I can read the header without issues. However when I read from the second memmapfile object to get query the data, I get the following error:
>
> EDU>> LasData.Data
> ??? Error using ==> hMapFile
> Cannot map file "C:\Documents and Settings\csiebern\My Documents\Purdue\CE597 GIS\CE597 Term Project\000007.las": The process
> cannot access the file because it is being used by another process.
>
> Error in ==> memmapfile.memmapfile>memmapfile.hCreateMap at 273
> hMapFile(mapfileInputStruct);
>
> Error in ==> memmapfile.memmapfile>memmapfile.subsref at 623
> hCreateMap(obj);
> The diagram in the help documentation suggests that multiple memmap objects can exist for the same file. I'm not sure what my issue is.