3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROningen Mixture of Alchemy and Childrens' Stories
46 #include "gmx_fatal.h"
52 #define round(a) (int)(a+0.5)
54 static const char mapper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+{}|;:',<.>/?";
55 #define NMAP (long int)strlen(mapper)
57 #define MAX_XPM_LINELENGTH 4096
59 real **mk_matrix(int nx, int ny, gmx_bool b1D)
70 for (i = 0; (i < nx); i++)
85 void done_matrix(int nx, real ***m)
89 for (i = 0; (i < nx); i++)
97 void clear_matrix(int nx, int ny, real **m)
101 for (x = 0; x < nx; x++)
103 for (y = 0; y < ny; y++)
110 gmx_bool matelmt_cmp(t_xpmelmt e1, t_xpmelmt e2)
112 return (e1.c1 == e2.c1) && (e1.c2 == e2.c2);
115 t_matelmt searchcmap(int n, t_mapping map[], t_xpmelmt c)
119 for (i = 0; (i < n); i++)
121 if (matelmt_cmp(map[i].code, c))
130 int getcmap(FILE *in, const char *fn, t_mapping **map)
134 char code[STRLEN], desc[STRLEN];
138 if (fgets2(line, STRLEN-1, in) == NULL)
140 gmx_fatal(FARGS, "Not enough lines in colormap file %s"
141 "(just wanted to read number of entries)", fn);
143 sscanf(line, "%d", &n);
145 for (i = 0; (i < n); i++)
147 if (fgets2(line, STRLEN-1, in) == NULL)
149 gmx_fatal(FARGS, "Not enough lines in colormap file %s"
150 "(should be %d, found only %d)", fn, n+1, i);
152 sscanf(line, "%s%s%lf%lf%lf", code, desc, &r, &g, &b);
153 m[i].code.c1 = code[0];
155 m[i].desc = strdup(desc);
165 int readcmap(const char *fn, t_mapping **map)
171 n = getcmap(in, fn, map);
177 void printcmap(FILE *out, int n, t_mapping map[])
181 fprintf(out, "%d\n", n);
182 for (i = 0; (i < n); i++)
184 fprintf(out, "%c%c %20s %10g %10g %10g\n",
185 map[i].code.c1 ? map[i].code.c1 : ' ',
186 map[i].code.c2 ? map[i].code.c2 : ' ',
187 map[i].desc, map[i].rgb.r, map[i].rgb.g, map[i].rgb.b);
191 void writecmap(const char *fn, int n, t_mapping map[])
195 out = gmx_fio_fopen(fn, "w");
196 printcmap(out, n, map);
200 static char *fgetline(char **line, int llmax, int *llalloc, FILE *in)
204 if (llmax > *llalloc)
206 srenew(*line, llmax+1);
209 fg = fgets(*line, llmax, in);
215 void skipstr(char *line)
221 while ((line[c] != ' ') && (line[c] != '\0'))
226 while (line[c] != '\0')
234 char *line2string(char **line)
240 while (((*line)[0] != '\"' ) && ( (*line)[0] != '\0' ))
245 if ((*line)[0] != '\"')
252 while (( (*line)[i] != '\"' ) && ( (*line)[i] != '\0' ))
257 if ((*line)[i] != '\"')
270 void parsestring(char *line, const char *label, char *string)
272 if (strstr(line, label))
274 if (strstr(line, label) < strchr(line, '\"'))
277 strcpy(string, line);
282 void read_xpm_entry(FILE *in, t_matrix *mm)
285 char *line_buf = NULL, *line = NULL, *str, buf[256] = {0};
286 int i, m, col_len, nch, n_axis_x, n_axis_y, llmax;
288 unsigned int r, g, b;
290 gmx_bool bGetOnWithIt, bSetLine;
301 mm->bDiscrete = FALSE;
305 while ((NULL != fgetline(&line_buf, llmax, &llalloc, in)) &&
306 (strncmp(line_buf, "static", 6) != 0))
309 parsestring(line, "title", (mm->title));
310 parsestring(line, "legend", (mm->legend));
311 parsestring(line, "x-label", (mm->label_x));
312 parsestring(line, "y-label", (mm->label_y));
313 parsestring(line, "type", buf);
316 if (!line || strncmp(line, "static", 6) != 0)
318 gmx_input("Invalid XPixMap");
321 if (buf[0] && (gmx_strcasecmp(buf, "Discrete") == 0))
323 mm->bDiscrete = TRUE;
328 fprintf(debug, "%s %s %s %s\n",
329 mm->title, mm->legend, mm->label_x, mm->label_y);
333 bGetOnWithIt = FALSE;
334 while (!bGetOnWithIt && (NULL != fgetline(&line_buf, llmax, &llalloc, in)))
337 while (( line[0] != '\"' ) && ( line[0] != '\0' ))
345 sscanf(line, "%d %d %d %d", &(mm->nx), &(mm->ny), &(mm->nmap), &nch);
348 gmx_fatal(FARGS, "Sorry can only read xpm's with at most 2 caracters per pixel\n");
350 if (mm->nx <= 0 || mm->ny <= 0)
352 gmx_fatal(FARGS, "Dimensions of xpm-file have to be larger than 0\n");
354 llmax = max(STRLEN, mm->nx+10);
360 fprintf(debug, "mm->nx %d mm->ny %d mm->nmap %d nch %d\n",
361 mm->nx, mm->ny, mm->nmap, nch);
367 while ((m < mm->nmap) && (NULL != fgetline(&line_buf, llmax, &llalloc, in)))
369 line = strchr(line_buf, '\"');
373 /* Read xpm color map entry */
374 map[m].code.c1 = line[0];
381 map[m].code.c2 = line[1];
384 str = strchr(line, '#');
389 while (isxdigit(str[col_len]))
395 sscanf(line, "%*s #%2x%2x%2x", &r, &g, &b);
396 map[m].rgb.r = r/255.0;
397 map[m].rgb.g = g/255.0;
398 map[m].rgb.b = b/255.0;
400 else if (col_len == 12)
402 sscanf(line, "%*s #%4x%4x%4x", &r, &g, &b);
403 map[m].rgb.r = r/65535.0;
404 map[m].rgb.g = g/65535.0;
405 map[m].rgb.b = b/65535.0;
409 gmx_file("Unsupported or invalid colormap in X PixMap");
414 str = strchr(line, 'c');
421 gmx_file("Unsupported or invalid colormap in X PixMap");
423 fprintf(stderr, "Using white for color \"%s", str);
428 line = strchr(line, '\"');
431 map[m].desc = strdup(line);
437 gmx_fatal(FARGS, "Number of read colors map entries (%d) does not match the number in the header (%d)", m, mm->nmap);
441 /* Read axes, if there are any */
444 bGetOnWithIt = FALSE;
453 if (strstr(line, "x-axis"))
455 line = strstr(line, "x-axis");
457 if (mm->axis_x == NULL)
459 snew(mm->axis_x, mm->nx + 1);
461 while (sscanf(line, "%lf", &u) == 1)
463 if (n_axis_x > mm->nx)
465 gmx_fatal(FARGS, "Too many x-axis labels in xpm (max %d)", mm->nx);
467 else if (n_axis_x == mm->nx)
469 mm->flags |= MAT_SPATIAL_X;
471 mm->axis_x[n_axis_x] = u;
476 else if (strstr(line, "y-axis"))
478 line = strstr(line, "y-axis");
480 if (mm->axis_y == NULL)
482 snew(mm->axis_y, mm->ny + 1);
484 while (sscanf(line, "%lf", &u) == 1)
486 if (n_axis_y > mm->ny)
488 gmx_file("Too many y-axis labels in xpm");
490 else if (n_axis_y == mm->ny)
492 mm->flags |= MAT_SPATIAL_Y;
494 mm->axis_y[n_axis_y] = u;
500 while ((line[0] != '\"') && (NULL != fgetline(&line_buf, llmax, &llalloc, in)));
503 snew(mm->matrix, mm->nx);
504 for (i = 0; i < mm->nx; i++)
506 snew(mm->matrix[i], mm->ny);
517 if (m%(1+mm->ny/100) == 0)
519 fprintf(stderr, "%3d%%\b\b\b\b", (100*(mm->ny-m))/mm->ny);
521 while ((line[0] != '\"') && (line[0] != '\0'))
527 gmx_fatal(FARGS, "Not enough caracters in row %d of the matrix\n", m+1);
532 for (i = 0; i < mm->nx; i++)
541 c.c2 = line[nch*i+1];
543 mm->matrix[i][m] = searchcmap(mm->nmap, mm->map, c);
548 while ((m >= 0) && (NULL != fgetline(&line_buf, llmax, &llalloc, in)));
551 gmx_incons("Not enough rows in the matrix");
557 int read_xpm_matrix(const char *fnm, t_matrix **matrix)
564 in = gmx_fio_fopen(fnm, "r");
567 while (NULL != fgetline(&line, STRLEN, &llalloc, in))
569 if (strstr(line, "/* XPM */"))
571 srenew(*matrix, nmat+1);
572 read_xpm_entry(in, &(*matrix)[nmat]);
580 gmx_file("Invalid XPixMap");
588 real **matrix2real(t_matrix *matrix, real **mat)
599 for (i = 0; i < nmap; i++)
601 if ((map[i].desc == NULL) || (sscanf(map[i].desc, "%lf", &tmp) != 1))
603 fprintf(stderr, "Could not convert matrix to reals,\n"
604 "color map entry %d has a non-real description: \"%s\"\n",
614 snew(mat, matrix->nx);
615 for (i = 0; i < matrix->nx; i++)
617 snew(mat[i], matrix->ny);
620 for (i = 0; i < matrix->nx; i++)
622 for (j = 0; j < matrix->ny; j++)
624 mat[i][j] = rmap[matrix->matrix[i][j]];
630 fprintf(stderr, "Converted a %dx%d matrix with %d levels to reals\n",
631 matrix->nx, matrix->ny, nmap);
636 void write_xpm_header(FILE *out,
637 const char *title, const char *legend,
638 const char *label_x, const char *label_y,
641 fprintf(out, "/* XPM */\n");
642 fprintf(out, "/* Generated by %s */\n", Program());
643 fprintf(out, "/* This file can be converted to EPS by the GROMACS program xpm2ps */\n");
644 fprintf(out, "/* title: \"%s\" */\n", title);
645 fprintf(out, "/* legend: \"%s\" */\n", legend);
646 fprintf(out, "/* x-label: \"%s\" */\n", label_x);
647 fprintf(out, "/* y-label: \"%s\" */\n", label_y);
650 fprintf(out, "/* type: \"Discrete\" */\n");
654 fprintf(out, "/* type: \"Continuous\" */\n");
658 static int calc_nmid(int nlevels, real lo, real mid, real hi)
660 /* Take care that we have at least 1 entry in the mid to hi range
662 return min(max(0, ((mid-lo)/(hi-lo))*(nlevels-1)), nlevels-1);
665 void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels,
666 real lo, real mid, real hi,
667 t_rgb rlo, t_rgb rmid, t_rgb rhi)
670 real r, g, b, clev_lo, clev_hi;
672 if (*nlevels > NMAP*NMAP)
674 fprintf(stderr, "Warning, too many levels (%d) in matrix, using %d only\n",
675 *nlevels, (int)(NMAP*NMAP));
676 *nlevels = NMAP*NMAP;
678 else if (*nlevels < 2)
680 fprintf(stderr, "Warning, too few levels (%d) in matrix, using 2 instead\n",
684 if (!((mid >= lo) && (mid < hi)))
686 gmx_fatal(FARGS, "Lo: %f, Mid: %f, Hi: %f\n", lo, mid, hi);
689 fprintf(out, "static char *gromacs_xpm[] = {\n");
690 fprintf(out, "\"%d %d %d %d\",\n",
691 n_x, n_y, *nlevels, (*nlevels <= NMAP) ? 1 : 2);
693 nmid = calc_nmid(*nlevels, lo, mid, hi);
695 clev_hi = (*nlevels - 1 - nmid);
696 for (i = 0; (i < nmid); i++)
698 r = rlo.r+(i*(rmid.r-rlo.r)/clev_lo);
699 g = rlo.g+(i*(rmid.g-rlo.g)/clev_lo);
700 b = rlo.b+(i*(rmid.b-rlo.b)/clev_lo);
701 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
703 (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
704 (unsigned int)round(255*r),
705 (unsigned int)round(255*g),
706 (unsigned int)round(255*b),
707 ((nmid - i)*lo + i*mid)/clev_lo);
709 for (i = 0; (i < (*nlevels-nmid)); i++)
711 r = rmid.r+(i*(rhi.r-rmid.r)/clev_hi);
712 g = rmid.g+(i*(rhi.g-rmid.g)/clev_hi);
713 b = rmid.b+(i*(rhi.b-rmid.b)/clev_hi);
714 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
715 mapper[(i+nmid) % NMAP],
716 (*nlevels <= NMAP) ? ' ' : mapper[(i+nmid)/NMAP],
717 (unsigned int)round(255*r),
718 (unsigned int)round(255*g),
719 (unsigned int)round(255*b),
720 ((*nlevels - 1 - nmid - i)*mid + i*hi)/clev_hi);
724 static void pr_simple_cmap(FILE *out, real lo, real hi, int nlevel, t_rgb rlo,
730 for (i = 0; (i < nlevel); i++)
732 fac = (i+1.0)/(nlevel);
733 r = rlo.r+fac*(rhi.r-rlo.r);
734 g = rlo.g+fac*(rhi.g-rlo.g);
735 b = rlo.b+fac*(rhi.b-rlo.b);
736 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
737 mapper[(i+i0) % NMAP],
738 (nlevel <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
739 (unsigned int)round(255*r),
740 (unsigned int)round(255*g),
741 (unsigned int)round(255*b),
746 static void pr_discrete_cmap(FILE *out, int *nlevel, int i0)
749 { 1.0, 1.0, 1.0 }, /* white */
750 { 1.0, 0.0, 0.0 }, /* red */
751 { 1.0, 1.0, 0.0 }, /* yellow */
752 { 0.0, 0.0, 1.0 }, /* blue */
753 { 0.0, 1.0, 0.0 }, /* green */
754 { 1.0, 0.0, 1.0 }, /* purple */
755 { 1.0, 0.4, 0.0 }, /* orange */
756 { 0.0, 1.0, 1.0 }, /* cyan */
757 { 1.0, 0.4, 0.4 }, /* pink */
758 { 1.0, 1.0, 0.0 }, /* yellow */
759 { 0.4, 0.4, 1.0 }, /* lightblue */
760 { 0.4, 1.0, 0.4 }, /* lightgreen */
761 { 1.0, 0.4, 1.0 }, /* lightpurple */
762 { 1.0, 0.7, 0.4 }, /* lightorange */
763 { 0.4, 1.0, 1.0 }, /* lightcyan */
764 { 0.0, 0.0, 0.0 } /* black */
769 *nlevel = min(16, *nlevel);
771 for (i = 0; (i < n); i++)
773 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%3d\" */,\n",
774 mapper[(i+i0) % NMAP],
775 (n <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
776 (unsigned int)round(255*rgbd[i].r),
777 (unsigned int)round(255*rgbd[i].g),
778 (unsigned int)round(255*rgbd[i].b),
785 void write_xpm_map_split(FILE *out, int n_x, int n_y,
786 int *nlevel_top, real lo_top, real hi_top,
787 t_rgb rlo_top, t_rgb rhi_top,
788 gmx_bool bDiscreteColor,
789 int *nlevel_bot, real lo_bot, real hi_bot,
790 t_rgb rlo_bot, t_rgb rhi_bot)
795 ntot = *nlevel_top + *nlevel_bot;
798 gmx_fatal(FARGS, "Warning, too many levels (%d) in matrix", ntot);
801 fprintf(out, "static char *gromacs_xpm[] = {\n");
802 fprintf(out, "\"%d %d %d %d\",\n", n_x, n_y, ntot, 1);
806 pr_discrete_cmap(out, nlevel_bot, 0);
810 pr_simple_cmap(out, lo_bot, hi_bot, *nlevel_bot, rlo_bot, rhi_bot, 0);
813 pr_simple_cmap(out, lo_top, hi_top, *nlevel_top, rlo_top, rhi_top, *nlevel_bot);
817 void write_xpm_map(FILE *out, int n_x, int n_y, int *nlevels, real lo, real hi,
818 t_rgb rlo, t_rgb rhi)
821 real invlevel, r, g, b;
823 if (*nlevels > NMAP*NMAP)
825 fprintf(stderr, "Warning, too many levels (%d) in matrix, using %d only\n",
826 *nlevels, (int)(NMAP*NMAP));
827 *nlevels = NMAP*NMAP;
829 else if (*nlevels < 2)
831 fprintf(stderr, "Warning, too few levels (%d) in matrix, using 2 instead\n", *nlevels);
835 fprintf(out, "static char *gromacs_xpm[] = {\n");
836 fprintf(out, "\"%d %d %d %d\",\n",
837 n_x, n_y, *nlevels, (*nlevels <= NMAP) ? 1 : 2);
839 invlevel = 1.0/(*nlevels-1);
840 for (i = 0; (i < *nlevels); i++)
843 r = (nlo*rlo.r+i*rhi.r)*invlevel;
844 g = (nlo*rlo.g+i*rhi.g)*invlevel;
845 b = (nlo*rlo.b+i*rhi.b)*invlevel;
846 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
847 mapper[i % NMAP], (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
848 (unsigned int)round(255*r),
849 (unsigned int)round(255*g),
850 (unsigned int)round(255*b),
851 (nlo*lo+i*hi)*invlevel);
855 void write_xpm_axis(FILE *out, const char *axis, gmx_bool bSpatial, int n,
862 for (i = 0; i < (bSpatial ? n+1 : n); i++)
868 fprintf(out, "*/\n");
870 fprintf(out, "/* %s-axis: ", axis);
872 fprintf(out, "%g ", label[i]);
874 fprintf(out, "*/\n");
878 void write_xpm_data(FILE *out, int n_x, int n_y, real **matrix,
879 real lo, real hi, int nlevels)
884 invlevel = (nlevels-1)/(hi-lo);
885 for (j = n_y-1; (j >= 0); j--)
887 if (j%(1+n_y/100) == 0)
889 fprintf(stderr, "%3d%%\b\b\b\b", (100*(n_y-j))/n_y);
892 for (i = 0; (i < n_x); i++)
894 c = gmx_nint((matrix[i][j]-lo)*invlevel);
905 fprintf(out, "%c", mapper[c]);
909 fprintf(out, "%c%c", mapper[c % NMAP], mapper[c / NMAP]);
914 fprintf(out, "\",\n");
918 fprintf(out, "\"\n");
923 void write_xpm_data3(FILE *out, int n_x, int n_y, real **matrix,
924 real lo, real mid, real hi, int nlevels)
926 int i, j, c = 0, nmid;
927 real invlev_lo, invlev_hi;
929 nmid = calc_nmid(nlevels, lo, mid, hi);
930 invlev_hi = (nlevels-1-nmid)/(hi-mid);
931 invlev_lo = (nmid)/(mid-lo);
933 for (j = n_y-1; (j >= 0); j--)
935 if (j%(1+n_y/100) == 0)
937 fprintf(stderr, "%3d%%\b\b\b\b", (100*(n_y-j))/n_y);
940 for (i = 0; (i < n_x); i++)
942 if (matrix[i][j] >= mid)
944 c = nmid+gmx_nint((matrix[i][j]-mid)*invlev_hi);
946 else if (matrix[i][j] >= lo)
948 c = gmx_nint((matrix[i][j]-lo)*invlev_lo);
965 fprintf(out, "%c", mapper[c]);
969 fprintf(out, "%c%c", mapper[c % NMAP], mapper[c / NMAP]);
974 fprintf(out, "\",\n");
978 fprintf(out, "\"\n");
983 void write_xpm_data_split(FILE *out, int n_x, int n_y, real **matrix,
984 real lo_top, real hi_top, int nlevel_top,
985 real lo_bot, real hi_bot, int nlevel_bot)
988 real invlev_top, invlev_bot;
990 invlev_top = (nlevel_top-1)/(hi_top-lo_top);
991 invlev_bot = (nlevel_bot-1)/(hi_bot-lo_bot);
993 for (j = n_y-1; (j >= 0); j--)
995 if (j % (1+n_y/100) == 0)
997 fprintf(stderr, "%3d%%\b\b\b\b", (100*(n_y-j))/n_y);
1000 for (i = 0; (i < n_x); i++)
1004 c = nlevel_bot+round((matrix[i][j]-lo_top)*invlev_top);
1005 if ((c < nlevel_bot) || (c >= nlevel_bot+nlevel_top))
1007 gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, matrix[i][j]);
1012 c = round((matrix[i][j]-lo_bot)*invlev_bot);
1013 if ((c < 0) || (c >= nlevel_bot+nlevel_bot))
1015 gmx_fatal(FARGS, "Range checking i = %d, j = %d, c = %d, bot = %d, top = %d matrix[i,j] = %f", i, j, c, nlevel_bot, nlevel_top, matrix[i][j]);
1023 fprintf(out, "%c", mapper[c]);
1027 fprintf(out, "\",\n");
1031 fprintf(out, "\"\n");
1036 void write_xpm_m(FILE *out, t_matrix m)
1038 /* Writes a t_matrix struct to .xpm file */
1044 bOneChar = (m.map[0].code.c2 == 0);
1045 write_xpm_header(out, m.title, m.legend, m.label_x, m.label_y,
1047 fprintf(out, "static char *gromacs_xpm[] = {\n");
1048 fprintf(out, "\"%d %d %d %d\",\n", m.nx, m.ny, m.nmap, bOneChar ? 1 : 2);
1049 for (i = 0; (i < m.nmap); i++)
1051 fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%s\" */,\n",
1053 bOneChar ? ' ' : m.map[i].code.c2,
1054 (unsigned int)round(m.map[i].rgb.r*255),
1055 (unsigned int)round(m.map[i].rgb.g*255),
1056 (unsigned int)round(m.map[i].rgb.b*255), m.map[i].desc);
1058 write_xpm_axis(out, "x", m.flags & MAT_SPATIAL_X, m.nx, m.axis_x);
1059 write_xpm_axis(out, "y", m.flags & MAT_SPATIAL_Y, m.ny, m.axis_y);
1060 for (j = m.ny-1; (j >= 0); j--)
1062 if (j%(1+m.ny/100) == 0)
1064 fprintf(stderr, "%3d%%\b\b\b\b", (100*(m.ny-j))/m.ny);
1069 for (i = 0; (i < m.nx); i++)
1071 fprintf(out, "%c", m.map[m.matrix[i][j]].code.c1);
1076 for (i = 0; (i < m.nx); i++)
1078 c = m.map[m.matrix[i][j]].code;
1079 fprintf(out, "%c%c", c.c1, c.c2);
1084 fprintf(out, "\",\n");
1088 fprintf(out, "\"\n");
1093 void write_xpm3(FILE *out, unsigned int flags,
1094 const char *title, const char *legend,
1095 const char *label_x, const char *label_y,
1096 int n_x, int n_y, real axis_x[], real axis_y[],
1097 real *matrix[], real lo, real mid, real hi,
1098 t_rgb rlo, t_rgb rmid, t_rgb rhi, int *nlevels)
1101 * Writes a colormap varying as rlo -> rmid -> rhi.
1106 gmx_fatal(FARGS, "hi (%g) <= lo (%g)", hi, lo);
1109 write_xpm_header(out, title, legend, label_x, label_y, FALSE);
1110 write_xpm_map3(out, n_x, n_y, nlevels, lo, mid, hi, rlo, rmid, rhi);
1111 write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x);
1112 write_xpm_axis(out, "y", flags & MAT_SPATIAL_Y, n_y, axis_y);
1113 write_xpm_data3(out, n_x, n_y, matrix, lo, mid, hi, *nlevels);
1116 void write_xpm_split(FILE *out, unsigned int flags,
1117 const char *title, const char *legend,
1118 const char *label_x, const char *label_y,
1119 int n_x, int n_y, real axis_x[], real axis_y[],
1121 real lo_top, real hi_top, int *nlevel_top,
1122 t_rgb rlo_top, t_rgb rhi_top,
1123 real lo_bot, real hi_bot, int *nlevel_bot,
1124 gmx_bool bDiscreteColor,
1125 t_rgb rlo_bot, t_rgb rhi_bot)
1128 * Writes a colormap varying as rlo -> rmid -> rhi.
1131 if (hi_top <= lo_top)
1133 gmx_fatal(FARGS, "hi_top (%g) <= lo_top (%g)", hi_top, lo_top);
1135 if (hi_bot <= lo_bot)
1137 gmx_fatal(FARGS, "hi_bot (%g) <= lo_bot (%g)", hi_bot, lo_bot);
1139 if (bDiscreteColor && (*nlevel_bot >= 16))
1141 gmx_impl("Can not plot more than 16 discrete colors");
1144 write_xpm_header(out, title, legend, label_x, label_y, FALSE);
1145 write_xpm_map_split(out, n_x, n_y, nlevel_top, lo_top, hi_top, rlo_top, rhi_top,
1146 bDiscreteColor, nlevel_bot, lo_bot, hi_bot, rlo_bot, rhi_bot);
1147 write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x);
1148 write_xpm_axis(out, "y", flags & MAT_SPATIAL_Y, n_y, axis_y);
1149 write_xpm_data_split(out, n_x, n_y, matrix, lo_top, hi_top, *nlevel_top,
1150 lo_bot, hi_bot, *nlevel_bot);
1153 void write_xpm(FILE *out, unsigned int flags,
1154 const char *title, const char *legend,
1155 const char *label_x, const char *label_y,
1156 int n_x, int n_y, real axis_x[], real axis_y[],
1157 real *matrix[], real lo, real hi,
1158 t_rgb rlo, t_rgb rhi, int *nlevels)
1161 * title matrix title
1162 * legend label for the continuous legend
1163 * label_x label for the x-axis
1164 * label_y label for the y-axis
1165 * n_x, n_y size of the matrix
1166 * axis_x[] the x-ticklabels
1167 * axis_y[] the y-ticklables
1168 * *matrix[] element x,y is matrix[x][y]
1169 * lo output lower than lo is set to lo
1170 * hi output higher than hi is set to hi
1171 * rlo rgb value for level lo
1172 * rhi rgb value for level hi
1173 * nlevels number of color levels for the output
1178 gmx_fatal(FARGS, "hi (%f) <= lo (%f)", hi, lo);
1181 write_xpm_header(out, title, legend, label_x, label_y, FALSE);
1182 write_xpm_map(out, n_x, n_y, nlevels, lo, hi, rlo, rhi);
1183 write_xpm_axis(out, "x", flags & MAT_SPATIAL_X, n_x, axis_x);
1184 write_xpm_axis(out, "y", flags & MAT_SPATIAL_Y, n_y, axis_y);
1185 write_xpm_data(out, n_x, n_y, matrix, lo, hi, *nlevels);