sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

Run headless #81

Closed brodock closed 5 years ago

brodock commented 5 years ago

I was trying to figure out how to run with the C API in "headless" mode. I want to use it only to output image files, not to render to the screen.

So far what I managed to do is run the compiled code with :

export GKS_WSTYPE=5

Is there a way to open/close something in C that will set this with code?

the gr_openws() seems to be the most obvious place but documentation is not clear how to use it.

jheinen commented 5 years ago

This example would create a PDF file:

/*
   cc ex-gr.c -I/usr/local/gr/include -L/usr/local/gr/lib/ -lGR \
      -Wl,-rpath,/usr/local/gr/lib
 */
#include <gr.h>

int main(void) {
    double x[] = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
    double y[] = {0.3, 0.5, 0.4, 0.2, 0.6, 0.7};
    gr_opengks();
    gr_openws(1, "ex-gr.pdf", 102);
    gr_activatews(1);
    gr_polyline(6, x, y);
    gr_axes(gr_tick(0, 1), gr_tick(0, 1), 0, 0, 1, 1, -0.01);
    gr_updatews();
    gr_emergencyclosegks();
    return 0;
}
brodock commented 5 years ago

I tried changing from 102 to 322 in order to output a PNG file, but got an error about lacking of Ghostscript support:

GKS: Ghostscript support not compiled in

That doesn't happen when I just use the gr_beginprint("file.png");.

Am I missing some step here?

jheinen commented 5 years ago

Please use 140 (corresponds to a PNG created thru CairoGraphics) - the workstation types are described here.

brodock commented 5 years ago

that worded fine, thanks :)