Fix the function when no specific variables have been specified. Also close the NetCDF file so we avoid hitting a limit on the number of open files