Design plotting from Fortran

The original notebook from the Python prototype of LFortran has simple plotting as a proof of concept that it can be done. Now it is time to design it properly.

The best approach seems to be the one taken by xeus-cling and it is described here.

Using the same approach for Fortran would be:

  • User will create a custom derived type type(image) (where image is just an example)
  • Function can return it, or a variable of type type(image) is left to "display" it in the interpreter
  • The Fortran kernel looks into the module that defines type(image) and looks for a function mime_bundle_repr. If it exists, it will be called like this: json = mime_bundle_repr(x) where x is of type type(image). The user implements the correct JSON representation for the custom type type(image) in the mime_bundle_repr function.
  • Jupyter shows the correct representation

A sample mime_bundle_repr function in C++ is:

    nlohmann::json mime_bundle_repr(const image& i)
    {
        auto bundle = nlohmann::json::object();
        bundle["image/png"] = xtl::base64encode(i.m_buffer.str());
        return bundle;
    }

The advantage of this approach is that there are no LFortran specific APIs here. This is all completely general and can be implemented by other Fortran compilers also.