<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Dear petsc-expert!</p>
    <p>I am having trouble loading the contents of my hdf5 dataset -
      "Vp" - into the Mat object Vp using MatLoad. When I try to do
      this, I get the error message displayed below. </p>
    <p><img src="cid:part1.cTVrYius.Q79lgTOY@mek.dtu.dk" alt=""></p>
    <p>The hdf5 file I am trying to read, was originally created in
      Matlab with their built in function h5write. I am wondering
      whether this is the source of the problem? Nonetheless, a
      screendump of the file's structure can be seen here:</p>
    <p><img src="cid:part2.WgT0H30T.vpWTkorx@mek.dtu.dk" alt=""></p>
    <p>I have tried following a few of your examples as inspiration,
      however there may of course still be a problem in my code. I have
      appended the code below here (it is a short program, so I hope it
      is ok! - and please disregard the red error-squiggles - these are
      not true).</p>
    <p>I hope you are able to help with my problem.</p>
    <p>Best regards,</p>
    <p>Martin</p>
    <div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #569cd6;">static</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">help</span><span style="color: #569cd6;">[]</span><span style="color: #d4d4d4;"> = </span><span style="color: #ce9178;">"Reads a HDF5 into a PETSC matrix.</span><span style="color: #d7ba7d;">\n\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">;</span></div>
<div><span style="color: #c586c0;">#include</span><span style="color: #569cd6;"> </span><span style="color: #ce9178;">"../../petsc/include/petscsys.h"</span></div><div><span style="color: #c586c0;">#include</span><span style="color: #569cd6;"> </span><span style="color: #ce9178;">"../../petsc/include/petscmat.h"</span></div><div><span style="color: #c586c0;">#include</span><span style="color: #569cd6;"> </span><span style="color: #ce9178;">"../../petsc/include/petscviewerhdf5.h"</span></div>
<div><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">main</span><span style="color: #d4d4d4;"> (</span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">argc</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> **</span><span style="color: #9cdcfe;">argv</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">{</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #9cdcfe;">Mat</span><span style="color: #d4d4d4;"> Vp;</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #569cd6;">PetscViewer</span><span style="color: #d4d4d4;"> viewer;</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">[</span><span style="color: #569cd6;">PETSC_MAX_PATH_LEN</span><span style="color: #d4d4d4;">]=</span><span style="color: #ce9178;">"../../Desktop/OnewaySimulations/Realization_1.h5"</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">Vp_name</span><span style="color: #d4d4d4;">[</span><span style="color: #b5cea8;">128</span><span style="color: #d4d4d4;">]=</span><span style="color: #ce9178;">"Vp"</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #569cd6;">PetscBool</span><span style="color: #d4d4d4;"> flg;</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscInitialize</span><span style="color: #d4d4d4;">(&</span><span style="color: #9cdcfe;">argc</span><span style="color: #d4d4d4;">, &</span><span style="color: #9cdcfe;">argv</span><span style="color: #d4d4d4;">, (</span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;">*)</span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">help</span><span style="color: #d4d4d4;">);</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #6a9955;">// Determine from which file we read the matrix</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscOptionsGetString</span><span style="color: #d4d4d4;">(</span><span style="color: #569cd6;">NULL</span><span style="color: #d4d4d4;">,</span><span style="color: #569cd6;">NULL</span><span style="color: #d4d4d4;">,</span><span style="color: #ce9178;">"-f"</span><span style="color: #d4d4d4;">,</span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">,</span><span style="color: #569cd6;">sizeof</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">),&flg);</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #6a9955;">// Read </span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscViewerHDF5Open</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">PETSC_COMM_WORLD</span><span style="color: #d4d4d4;">,</span><span style="color: #9cdcfe;">file</span><span style="color: #d4d4d4;">,</span><span style="color: #4fc1ff;">FILE_MODE_READ</span><span style="color: #d4d4d4;">,&viewer);</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #6a9955;">// Load matrix</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">MatCreate</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">PETSC_COMM_WORLD</span><span style="color: #d4d4d4;">, &Vp);</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscObjectSetName</span><span style="color: #d4d4d4;">((</span><span style="color: #569cd6;">PetscObject</span><span style="color: #d4d4d4;">)Vp, </span><span style="color: #9cdcfe;">Vp_name</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">MatSetFromOptions</span><span style="color: #d4d4d4;">(Vp);</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">MatLoad</span><span style="color: #d4d4d4;">(Vp,viewer);</span></div>
<div><span style="color: #d4d4d4;">    </span><span style="color: #6a9955;">// Destroy</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscViewerDestroy</span><span style="color: #d4d4d4;">(&viewer);</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">MatDestroy</span><span style="color: #d4d4d4;">(&Vp);</span></div><div><span style="color: #d4d4d4;">    </span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #dcdcaa;">PetscFinalize</span><span style="color: #d4d4d4;">();</span></div><div><span style="color: #d4d4d4;">    </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;">}</span></div></div>
  </body>
</html>