0

Is it possible to load the matrix in PETSc binary format from external file at runtime with use of Octave C++ API? I've found the Doxygen documentation, but I can't find anything useful among so many items.

Usually I use "PetscBinaryRead.m" when I want to load a PETSc matrix to Octave, but now in C++ I'm really completely lost.

Eenoku
  • 2,741
  • 4
  • 32
  • 64

1 Answers1

0

the PetscBinaryRead.m is not part of Octave, we don't know where you got it or even what it does. You can:

  1. reimplement it on C++, C, or Fortran (only you know what it does)
  2. start the Octave interpreter in your C++ and call PetscBinaryRead from there (see the Octave manual on how to create standalone programs or calling Octave Functions from Oct-files
carandraug
  • 12,938
  • 1
  • 26
  • 38
  • Oh, I forgot to mention it - `PetscBinaryRead.m` is the common Octave/MatLab script included in the PETSc package to make loading PETSc binary matrices possible. It takes the name of the matrix file as an argument. So, the second option is probably what I need. But I must admit, that I still don't see the way I can execute this script. Here is the .m script: http://fossies.org/dox/petsc-3.5.3/PetscBinaryRead_8m_source.html – Eenoku Feb 13 '15 at 11:42
  • @MartinBeseda you will need to be more specific on what you don't understand if you need help. There are plenty of other questions about people trying to embed octave code in their applications. Basically, you need to start the interpreter, set up the patch, and then call the function that is on a m file. – carandraug Feb 13 '15 at 14:34
  • Ok, now I have the project with Octave headers and libraries linked. I have Matrix variable declared. And I need to know the function from API which will call the function from m-file (that function will load matrix from the file and I'll assign it to my Matrix variable). Is it more clear? I'm sorry if it isn't :-) – Eenoku Feb 13 '15 at 16:07
  • @MartinBeseda as per the link on the answer, which even has an example, you need to start the interpreter (call `octave_main`), and then call your function `feval`, which will return an octave_value_list. One of the elements of that list will will be your matrix (probably the first). You can get a Matrix type by picking the appropriate method from the `octave_value` class. – carandraug Feb 13 '15 at 17:59
  • Thank you very much. I've written the code which appears correct to me, but I'm getting the error. The problem is, I'm trying to use Octave in [Kaira](http://verif.cs.vsb.cz/kaira/), which is unfinished yet, so the error messages are not very clear. So please, could you look at my code and tell me, if I understood it correctly? My code is [here](http://pastebin.com/NqQv1sST). The error is probably caused by calling the method `matrix_value()` on line 12. – Eenoku Feb 14 '15 at 16:13
  • The method `matrix_value()` I found [here](http://octave.sourceforge.net/doxygen/html/d3/d35/classoctave__value.html#ab1cfa5d1ffd31804b09abdc802b98092). – Eenoku Feb 14 '15 at 17:15