title: Edit the amount of colors available in a picture plotting program. It's written in C with Xlib
body: <p>I'm a fortran programmer working with a program written in C (which I have Little to no experience with).</p>
  
  <p>I have a program written in fortan that creates an image in the form of a multidimentional array of pixels with their X value, Y value, and RGB values (0-4 for each color). It then passes the array, the size of the array in the x and y dimensions, the color map containing all the colors arranged in a spectrum, and the number of colors in the spectrum to a program written in C that is supposed to plot the image using Xlib.</p>
  
  <p>The program works when I pass a particular one color map with 125 colors (5 values for red/green/blue) but when I try to increase the amount of colors I pass to the C program I exceed some sort of limit and the program shuts down. How do I raise the limit in the C source code?</p>
  
  <p>Here is the program:</p>
  
  <pre><code>    #define USEPIXMAP  /* sets drawing into background pixmap of window */
  
      #include "putras.h"
      #include &lt;stdlib.h&gt;
      static unsigned def_map[256];
  
      void putras_(int *pixel_values, int *arrayx, int *arrayy,
                  int *colormap_entries, int *colormap_size)
      {
        extern Colormap       cmap;
        extern Window         window;
        extern Display        *dpy;
        extern XColor         color;
        extern XWindowAttributes  window_attr;
        extern GC             gc;
        extern XGCValues      gcv;
        extern Pixmap         pixmap;
  
        static int call_flag = 0;
        char           *display_name=NULL;
        char           *dummy;
        unsigned            pixel;
        int            i, j;
        XPoint         *pointarray[256];
        unsigned            arraylen[256];
        unsigned            maxlen[256];
        int            remain_len;
  
        if(call_flag == 0) {
  
          /* THis only gets done on the first call to putras */
  
          call_flag = 1;
          if( (dpy = XOpenDisplay(display_name) ) == NULL){
            fprintf(stderr,"Error: Couldn't open display\n");
            exit(1);
          }
          XGetWindowAttributes(dpy, RootWindow(dpy,DefaultScreen(dpy)),
                               &amp;window_attr);
          window=XCreateSimpleWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0,
                                   *arrayx, *arrayy,window_attr.border_width,
                                   BlackPixel(dpy, DefaultScreen(dpy)),
                                   WhitePixel(dpy, DefaultScreen(dpy)));
  
      #ifdef USEPIXMAP
          pixmap=XCreatePixmap(dpy, window, *arrayx, *arrayy,
                               DefaultDepth(dpy,DefaultScreen(dpy)) );
          XMapWindow(dpy, window);
          XClearWindow(dpy, window);
          XCopyArea(dpy, window, pixmap, DefaultGC(dpy, DefaultScreen(dpy)),
                    0,0,*arrayx, *arrayy, 0,0);
          XFlush(dpy);
      #else
          XMapWindow(dpy, window);
      #endif
  
          cmap=DefaultColormap(dpy,DefaultScreen(dpy));
  
          color.flags=DoRed|DoBlue|DoGreen;
          for (i=0;i&lt;(*colormap_size);i++){
            color.pixel= colormap_entries[4*i];
            j = color.pixel;
            color.red=colormap_entries[4*i+1];
            color.green=colormap_entries[4*i+2];
            color.blue=colormap_entries[4*i+3];
            XAllocColor(dpy, cmap, &amp;color);
            def_map[j] = color.pixel;
          }
  
          gc = XCreateGC(dpy, window, 0, NULL);
  
        } /* Endif - first time through */
  
        /* The following gets done on each call */
        for (i=0; i&lt;256; i++){
  
            pointarray[i]=(XPoint *)malloc((*arrayx)*(*arrayy)/128*sizeof(XPoint));
            maxlen[i]=(*arrayx)*(*arrayy)/128 -1;
            arraylen[i]=0;
        }
          for (j=0; j&lt;(*arrayy); j++) {
           for (i=0; i&lt;(*arrayx); i++) {
             /*pixel = def_map[pixel_values[j * (*arrayx) + i]];*/
             pixel=pixel_values[j*(*arrayx)+i];
             /*pixel=1;*/
  
              if (arraylen[pixel]==maxlen[pixel]) {
                pointarray[pixel]= (XPoint *)realloc(pointarray[pixel],
                                                     2*maxlen[pixel]*sizeof(XPoint));
                maxlen[pixel]=2*maxlen[pixel];
            }
  
                pointarray[pixel][arraylen[pixel]].x=i;
             pointarray[pixel][(arraylen[pixel])++].y=j;
           } /* end for loop*/
          } /* end for loop*/
  
        for (i=0; i&lt;256; i++) {
          XSetForeground(dpy, gc, def_map[i]);/*dpy,gc,i);*/
           if (arraylen[i]&gt;=MAXPOINT) { 
              for (j=0; j&lt;=(arraylen[i]/MAXPOINT); j++) {
                 remain_len=(arraylen[i]-MAXPOINT*j);
      #ifdef USEPIXMAP
                 XDrawPoints(dpy, pixmap, gc,(pointarray[i]+j*MAXPOINT),
                            ((remain_len&lt;MAXPOINT)?remain_len:MAXPOINT),
                            CoordModeOrigin);
      #else
                 XDrawPoints(dpy, window, gc,(pointarray[i]+j*MAXPOINT),
                            ((remain_len&lt;MAXPOINT)?remain_len:MAXPOINT),
                            CoordModeOrigin);
      #endif
  
              } /* end for loop */
           } else {
  
      #ifdef USEPIXMAP
               XDrawPoints(dpy, pixmap, gc, pointarray[i], arraylen[i],
                           CoordModeOrigin);
      #else
               XDrawPoints(dpy, window, gc, pointarray[i], arraylen[i],
                           CoordModeOrigin);
      #endif
            } /*  end if */
        } /* end for loop 256 */
  
      #ifdef USEPIXMAP
        XSetWindowBackgroundPixmap(dpy, window, pixmap);
        XClearWindow(dpy, window);
      #endif
  
        XFlush(dpy);
        for (i=0; i&lt;256;i++)
          free(pointarray[i]);
  
        return;
      }
  
  
      void unmap(void)
      {
      /*  extern Pixmap pmap; */
  
        extern Window window;
        extern Display *dpy;
  
      /*  int width, height; */
  
        XUnmapWindow(dpy, window);
        XFlush(dpy);
        return;
      }
  
      void remap(void)
      {
        extern Window window;
        extern Display *dpy;
  
        XMapRaised(dpy, window);
        XFlush(dpy);
        return;
      }
  </code></pre>