Close open netcdf files
3 次查看(过去 30 天)
显示 更早的评论
Short question:
Is there a way to explicitly close all open netcdf files, similar to
fclose('all')
for open binary files?
Longer explanation:
I'm currently running a series of simulations where data is saved time slice by time slice to netcdf files as the model integrates forward over time. Opening and closing files before and after each write is way too time-consuming, so I open all the files at the beginning of the simulation and close them at the end. No issues if everything runs smoothly, but if a simulation crashes mid-integration (which happens a few times per 100 simulations, due to numerical issues that are difficult to prevent) I'm left with a few hundred open file handles.
I currently deal with this via a lot of try/catch blocks in various parts of my code, and an onCleanup object, but I still once in a blue moon end up with some orphaned open files with no accessible NetCDF ID to use to close them (running a few hundred simulations in parallel, so it can be difficult to track down why these few instances escape my traps). At that point, the only way to solve the issue is a
clear all
which of course clears away much more than necessary (and also isn't really documented). Doing so leads to a warning message
Warning: Closing open netCDF file handles.
which seems to imply that there is a way, under the hood of clear, to recognize the presence of open file handles, and close them. Is that available without the accompanying wiping out of everything else in the workspace?
6 个评论
David Ahrens
2017-10-5
编辑:David Ahrens
2017-10-5
Found that
clear mex
Works at closing left over file handles from netcdf calls.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!