Hi Lucas,
Thank you for your answer. However, what I am specifically asking is: Given
ONLY the NetCDF dataset filename, is there a function that can be used in a
Fortran code (or a C-binding routine) to inquire if the filename is open (with
a logical true or false result). If true, return the one or more identifiers
(vector) associated with the opening of that specific filename. Notice that
It is possible that such filename has been opened more than once and not closed.
I assume that this is a very difficult question because I don’t have an idea
how to code such function. Maybe the developers of NetCDF can tell us if it is
possible or not.
Cheers, Hernan
From: Lucas Villa Real <lucasvr@xxxxxxxxxx>
Date: Friday, January 22, 2021 at 10:17 PM
To: Hernan Arango <arango@xxxxxxxxxxxxxxxxxx>
Cc: "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
Subject: Re: [netcdfgroup] How to inquire if a NetCDF file is already open for
reading or writing?
----- Original message -----
From: Hernan Arango <arango@xxxxxxxxxxxxxxxxxx>
Sent by: "netcdfgroup" <netcdfgroup-bounces@xxxxxxxxxxxxxxxx>
To: "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
Cc:
Subject: [EXTERNAL] [netcdfgroup] How to inquire if a NetCDF file is already
open for reading or writing?
Date: Fri, Jan 22, 2021 6:01 PM
Hello,
I am wondering if there is a function to determine if a NetCDF is already open
for reading or writing based on the filename? I am trying to avoid open too
many files. I know that there are ways in Unix to increase the number of open
files, but that’s not what I am asking. In parallel I/O running on lots of
processes, there is a need to avoid opening too many files. I am using both
the standard NetCDF library and the PIO library that is the basis of the
SCORPIO library
(https://e3sm.org/scorpio-parallel-io-library<https://urldefense.proofpoint.com/v2/url?u=https-3A__e3sm.org_scorpio-2Dparallel-2Dio-2Dlibrary&d=DwMGaQ&c=jf_iaSHvJObTbx-siA1ZOg&r=yZCLoPFNF2xM1OIVBISlXxZvERMVKNT1d5PSrOJfnc8&m=QnVlDcV5suiBIhpLT3T5oRt9rSpedaNzD5PPQIaVwoY&s=9fcAm4IjIU6e3FbfD7JzZm28BtCM1zMwV3G7jQ-Bc0A&e=>).
Therefore, I have integer file ID (ncid) and file descriptors of TYPE
(file_desc_t).
I am looking for something like:
ncid=is_nc_open(‘my_file.nc’)
or
fileDesc=is_pio_open(iosystem, my_paralle_file.nc’)
Thank you, H
Hi Hernan,
If you're on Linux, then one option is to scan the symlinks under /proc/self/fd
looking for a target whose name matches the file name you're looking for.
I'm not sure if ncids have a 1:1 correspondence with HDF5 file ids; if they do,
then perhaps you could also look into H5Fget_obj_count(ncid, H5F_OBJ_FILE)
and/or H5Fget_obj_count(H5F_OBJ_ALL, H5F_OBJ_FILE). See
https://support.hdfgroup.org/HDF5/doc/RM/RM_H5F.html#File-GetObjCount for more
details on that API.
Best regards,
Lucas