<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 22, 2014 at 1:55 PM, Likun Tan <span dir="ltr"><<a href="mailto:likunt@caltech.edu" target="_blank">likunt@caltech.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto"><div>Hi Matt,</div><div><br></div><div>I am not using PetscBinaryRead. I wrote a binary file from Petsc and use Matlab's function to read it, I.e.</div>
<div><br></div><div>fileID = fopen('result.bin', 'w');</div><div>data = fread(fileID, 'double');<br><br>But this gives me unreasonable values of data. I checked this example</div><div><br></div><div>
<a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex54f.F.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex54f.F.html</a></div><div><br></div>
<div>which is exactly what I need for my problem. Do you have a C version of it ? Many thanks.</div></div></blockquote><div><br></div><div>Why would you rewrite this?</div><div><br></div><div>  <a href="https://bitbucket.org/petsc/petsc/src/2c43c009db31f079231059c9efed501d4deca8bf/bin/matlab/PetscBinaryRead.m?at=master">https://bitbucket.org/petsc/petsc/src/2c43c009db31f079231059c9efed501d4deca8bf/bin/matlab/PetscBinaryRead.m?at=master</a></div>
<div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto">
<div>On May 22, 2014, at 12:26 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote">On Thu, May 22, 2014 at 11:20 AM, Likun Tan <span dir="ltr"><<a href="mailto:likunt@caltech.edu" target="_blank">likunt@caltech.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I am using VecView to output the vec in a binary file and tried to open it in Matlab. I define the precision to be double, but Matlab does not give reasonable values of my vec (almost extremely large or small or NaN values). Here is my code<br>

</blockquote><div><br></div><div>Are you using PetscBinaryRead.m in Matlab? If so, send the code snippet for a small vector, all the output, and the binary file.</div><div><br></div><div>  Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


========================================<br>
PetscViewerBinaryOpen(PETSC_COMM_WORLD, NAME, FILE_MODE_WRITE, & view);<br>
for(step=0; step<STEP; step++)<br>
{<br>
       //compute M at current step<br>
       VecView(M, view);<br>
}<br>
PetscViewerDestroy(&view);<br>
=======================================<br>
<br>
I am not sure if there is any problem of my Petsc code. Your comment is well appreciated.<br>
<br>
> On May 22, 2014, at 11:07 AM, Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> wrote:<br>
><br>
> Likun Tan <<a href="mailto:likunt@caltech.edu" target="_blank">likunt@caltech.edu</a>> writes:<br>
><br>
>> Thanks for your suggestion.<br>
>> Using VecView or PetscViewerBinaryWrite will print the vec vertically, i.e.<br>
>> m1<br>
>> m2<br>
>> m3<br>
>> m4<br>
>> m5<br>
>> m6<br>
><br>
> The binary viewer writes a *binary* file.  No formatting or line breaks.<br>
><br>
>> But I prefer the form<br>
>><br>
>> m1 m2 m3<br>
>> m4 m5 m6<br>
>><br>
>> Since in the end I will have about 1e+7 elements in the vec. If there is no way to output the vec in the second form, I will simply use VecView. Thanks.<br>
><br>
> Use VecView to write a binary (not ASCII) file.  See<br>
> PetscViewerBinaryOpen().  You can look at it with python, matlab/octave,<br>
> etc.<br>
</blockquote></div><br><br clear="all"><span class=""><font color="#888888"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>

-- Norbert Wiener
</font></span></div></div>
</div></blockquote></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>