<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>hi Matt,<br>
    </p>
    <div class="moz-cite-prefix">On 10/11/21 11:59 AM, Matthew Knepley
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAMYG4G=8FOTHkBwUd5C0KHHcuv7rDdY7HZviQxw55Hwj=z0WYQ@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Sun, Oct 10, 2021 at 6:51 PM Adrian Croucher
          <<a href="mailto:a.croucher@auckland.ac.nz" moz-do-not-send="true">a.croucher@auckland.ac.nz</a>>
          wrote:<br>
        </div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">hi<br>
            <br>
            Is there any way to query the PETSc HDF5 viewer to find the
            number of <br>
            time steps in the file?<br>
            <br>
            A common use case I have is that an HDF5 file from a
            previous simulation <br>
            is used to get initial conditions for a subsequent run. The
            most common <br>
            thing you want to do is restart from the last set of results
            in the <br>
            previous output. To do that you need to know how many time
            steps there <br>
            are, so you can set the output index to be the last one.<br>
            <br>
            I thought maybe I could just query the size of the "time"
            dataset, but I <br>
            can't even see any obvious way to do that using the viewer
            functions.<br>
          </blockquote>
          <div><br>
          </div>
          <div>There is nothing in there that does it right now. Do you
            know how to do it in HDF5?</div>
          <div>If so, I can put it in. Otherwise, I will have to learn
            more HDF5 :)</div>
        </div>
      </div>
    </blockquote>
    <br>
    <p>I haven't actually tried this myself but it looks like what you
      do is:</p>
    <p>1) get the dataspace for the dataset (in our case the "time"
      dataset):</p>
    <p>hid_t dspace = H5Dget_space(dset);</p>
    <p>2) Get the dimensions of the dataspace:<br>
    </p>
    <p>const int ndims = 1;<br>
    </p>
    <p>hsize_t dims[ndims];<br>
      H5Sget_simple_extent_dims(dspace, dims, NULL);</p>
    <p>The first element of dims should be the number of time steps.
      Here I've assumed the number of dimensions of the time dataset is
      1. In general you can instead query the rank of the dataspace
      using H5Sget_simple_extent_ndims() to get the rank ndims.</p>
    <p>Regards, Adrian<br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Dr Adrian Croucher
Senior Research Fellow
Department of Engineering Science
University of Auckland, New Zealand
email: <a class="moz-txt-link-abbreviated" href="mailto:a.croucher@auckland.ac.nz">a.croucher@auckland.ac.nz</a>
tel: +64 (0)9 923 4611</pre>
  </body>
</html>