Re: [netcdfgroup] How to inquire if a NetCDF file is already open for reading or writing?

  • To: Lucas Villa Real <lucasvr@xxxxxxxxxx>
  • Subject: Re: [netcdfgroup] How to inquire if a NetCDF file is already open for reading or writing?
  • From: Hernan Arango <arango@xxxxxxxxxxxxxxxxxx>
  • Date: Sat, 23 Jan 2021 03:35:28 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marine.rutgers.edu; dmarc=pass action=none header.from=marine.rutgers.edu; dkim=pass header.d=marine.rutgers.edu; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Wu2y44B27Npz8AZo2yQdryYG66HKvqvDjUO4BGQvXnA=; b=BbjGhrFbRygee1vusq410Z0uW18e3INm+ASQ2v9qZ6EISEo2EBFQLJS+gL76IKEBOZupUyEHtV85AkkGP90ysyAVK0lovjAJTcXvi99K16hicsM01wR1g1wD5eKzIGYzwozUdsSdBh5PFBDouLB3Wy2HENk2mOSBxbOVmAx3F7/Au4HOPIG6ZOoJlYoCad/ecxwPkpdheg3/jXdwPd6yx4DFZLa+HTjomP1mp33rrb4/v3qULMytehQL0xqZrhIVborK/kjqEnSWLfeQqiW1bpfYX1yUOf+RZlcqUdAl0jewCx8NJ4Q+ANZjzZ1zIbd+fH2oELQ6CXsadRMDIYjb/A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=obVu3gQDeVF1Z3lH3EiSonMhqW7SVUQBbkIF2xQnZXq0zUWtcUi+5MPK/iJicc4NeV29vKCkuYywVBRU7BobGMhC46qPzQQhfhp6Pkascw17g2IYydEDIuweeZthnoRDeIUoWYeJqFY0Gdt7ye3fPaPKaZ8lRaQ1nXnr4BZvxtT/d1jXPon1Nx1J/bR0AZbBKo6ff6Q1PXsQzXjf8iEHkrkAdrcXMCT7Q7gXVg9DDoRHX8EH/zx60KyJDhc8hs8+mYzyYzHjAXxJXeHluuC14EtDH+d/Eba9efdSB+8uItiIp4ve6OPvTcnEGnHmPxV4/DNTFrG4TEw1FB23fzvWLg==
  • Authentication-results: br.ibm.com; dkim=none (message not signed) header.d=none;br.ibm.com; dmarc=none action=none header.from=marine.rutgers.edu;
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


  • 2021 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: