[sac-user] filename string not passed through to writePNG(..)

Rob Stewart R.Stewart at hw.ac.uk
Wed Feb 17 00:53:48 CET 2016


I have some code that:

use PNG: {writePNG};

And

call writePNG("foo.png", anArray);

When I compile and run this, I am getting the runtime error:

*** SAC runtime error
*** SAC_PNG_array2png: Failed to open image file '': No such file or directory

My "foo.png" doesn't look to be carried through correctly to
writePNG(..).

In the stdlib/src/world/stdio/PNG.sac

--8<---------------cut here---------------start------------->8---
external void writePNG( string NAME, color[.,.] array);
    #pragma effect FileSystem::TheFileSystem
    #pragma linkobj "src/PNG/array2png.o"
    #pragma linkname "SAC_PNG_array2png"
    #pragma linkwith "png"
    #pragma linkwith "z"
    #pragma refcounting[1]
--8<---------------cut here---------------end--------------->8---

And in stdlib/src/world/stdio/src/PNG/array2png.c I get this far:

--8<---------------cut here---------------start------------->8---
void SAC_PNG_array2png(SAC_ND_PARAM_out_nodesc(res_nt, int),
                       SAC_ND_PARAM_in_nodesc(string_nt, string),
                       SAC_ND_PARAM_in(ar_nt, int))
{
  FILE *fp;
  png_structp png_ptr;
  png_infop info_ptr;
  png_bytep *row_pointers;
  png_bytep img_data;
  int x, y;
  int height = SAC_ND_A_DESC_SHAPE(ar_nt, 0);
  int width = SAC_ND_A_DESC_SHAPE(ar_nt, 1);
  int *arr_data = SAC_ND_A_FIELD(ar_nt);

  fp = fopen(NT_NAME(string_nt), "wb");
  if (fp == NULL)
  {
    SAC_RuntimeError("SAC_PNG_array2png: Failed to open image file '%s': %s",
                     NT_NAME(string_nt), strerror(errno));
    return;
  }
 --8<---------------cut here---------------end--------------->8---


Why does NT_NAME(string_nt) return an empty string, and what can I do
about it? Or am I missing something completely obvious?

Thanks,

--
Rob


More information about the sac-user mailing list