<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial, Helvetica,
sans-serif;font-size:10pt" ><blockquote data-history-content-modified="1"
data-history-expanded="1" dir="ltr" style="border-left:solid #aaaaaa 2px;
margin-left:5px; padding-left:5px; direction:ltr; margin-right:0px" >-----
Original message -----<br>From: Hernan Arango
<arango@xxxxxxxxxxxxxxxxxx><br>Sent by: "netcdfgroup"
<netcdfgroup-bounces@xxxxxxxxxxxxxxxx><br>To:
"netcdfgroup@xxxxxxxxxxxxxxxx"
<netcdfgroup@xxxxxxxxxxxxxxxx><br>Cc:<br>Subject: [EXTERNAL]
[netcdfgroup] How to inquire if a NetCDF file is already open for reading or
writing?<br>Date: Fri, Jan 22, 2021 6:01 PM<br> <br><!--
BaNnErBlUrFlE-HeAdEr-start --> <!-- BaNnErBlUrFlE-HeAdEr-end --> <!--Notes ACF
<meta http-equiv="Content-Type" content="text/html; charset=utf8" >--> <!--
BaNnErBlUrFlE-BoDy-start --> <!-- Preheader Text : BEGIN --> <!-- Preheader
Text : END --> <!-- Email Banner : BEGIN -->
<!-- Email Banner : END --> <!-- BaNnErBlUrFlE-BoDy-end -->
<div><p style="margin: 0px;" ><span style="font-size:14.0pt"
>Hello,<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
><o:p> </o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt" >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 (<a
href="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="
target="_blank"
>https://e3sm.org/scorpio-parallel-io-library</a>). Therefore, I
have integer file ID (ncid) and file descriptors of TYPE
(file_desc_t).<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
><o:p> </o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt" >I am looking for
something like:<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
><o:p> </o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
> ncid=is_nc_open(‘my_file.nc’)<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
>or<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
> fileDesc=is_pio_open(iosystem,
my_paralle_file.nc’)<o:p></o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt"
><o:p> </o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt" >Thank you,
H<o:p></o:p></span></p></div></blockquote>
<div dir="ltr" > </div>
<div dir="ltr" >Hi Hernan,</div>
<div dir="ltr" > </div>
<div dir="ltr" >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.</div>
<div dir="ltr" > </div>
<div dir="ltr" >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 <a
href="https://support.hdfgroup.org/HDF5/doc/RM/RM_H5F.html#File-GetObjCount"
>https://support.hdfgroup.org/HDF5/doc/RM/RM_H5F.html#File-GetObjCount</a> for
more details on that API.</div>
<div dir="ltr" > </div>
<div dir="ltr" >Best regards,</div>
<div dir="ltr" >Lucas</div></div><BR>