BUG: close intermediate file descriptor right after it is used in netcdf.py

netcdf opens intermediate file descriptors and they are closed when the main file descriptor is closed.  But this causes a too many open files error when the number of intermediate descriptors are too many.  This patch closes the intermediate file descriptor right after it is used.