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

  • To: arango@xxxxxxxxxxxxxxxxxx
  • Subject: Re: [netcdfgroup] How to inquire if a NetCDF file is already open for reading or writing?
  • From: "Lucas Villa Real" <lucasvr@xxxxxxxxxx>
  • Date: Sat, 23 Jan 2021 03:16:55 +0000
  • Sensitivity:
<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 
&lt;arango@xxxxxxxxxxxxxxxxxx&gt;<br>Sent by: "netcdfgroup" 
&lt;netcdfgroup-bounces@xxxxxxxxxxxxxxxx&gt;<br>To: 
"netcdfgroup@xxxxxxxxxxxxxxxx" 
&lt;netcdfgroup@xxxxxxxxxxxxxxxx&gt;<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>&nbsp;<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>&nbsp;</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?&nbsp;&nbsp; I am trying to avoid open too many 
files.&nbsp;&nbsp; I know that there are ways in Unix to increase the number of 
open files, but that’s not what I am asking.&nbsp;&nbsp; In parallel I/O 
running on lots of processes, there is a need to avoid opening too many 
files.&nbsp;&nbsp; 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&amp;d=DwMGaQ&amp;c=jf_iaSHvJObTbx-siA1ZOg&amp;r=yZCLoPFNF2xM1OIVBISlXxZvERMVKNT1d5PSrOJfnc8&amp;m=QnVlDcV5suiBIhpLT3T5oRt9rSpedaNzD5PPQIaVwoY&amp;s=9fcAm4IjIU6e3FbfD7JzZm28BtCM1zMwV3G7jQ-Bc0A&amp;e=";
 target="_blank" 
>https://e3sm.org/scorpio-parallel-io-library</a>).&nbsp;&nbsp; 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>&nbsp;</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>&nbsp;</o:p></span></p>
<p style="margin: 0px;" ><span style="font-size:14.0pt" 
>&nbsp;&nbsp;&nbsp;&nbsp; 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" 
>&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;</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" >&nbsp;</div>
<div dir="ltr" >Hi Hernan,</div>
<div dir="ltr" >&nbsp;</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" >&nbsp;</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" >&nbsp;</div>
<div dir="ltr" >Best regards,</div>
<div dir="ltr" >Lucas</div></div><BR>

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