import xarray as xr

netcdf_file_path = '/share/grpeta/dsk001/dist/users/jorge/LA/Eta20_2025061300_prec.nc'

try:
    # Use xarray to open the NetCDF file
    ds = xr.open_dataset(netcdf_file_path)

    print(f"Successfully opened NetCDF file: {netcdf_file_path}")
    print("\nDataset Information:")
    print(ds)

    # You can now access variables, dimensions, etc.
    # For example, to see the 'prec' variable:
    if 'prec' in ds.data_vars:
        prec_data = ds['prec']
        print(f"\nInformation about 'prec' variable:\n{prec_data}")
        # To load data into memory (if not already loaded lazily)
        # prec_values = prec_data.values

    ds.close() # Always good practice to close the dataset when done
    print("\nDataset closed.")

except FileNotFoundError:
    print(f"Error: NetCDF file not found at {netcdf_file_path}")
except Exception as e:
    print(f"An error occurred while opening the NetCDF file: {e}")
