18#include "fasp_functs.h"
24static void put_byte (FILE *fp,
const int c);
25static void put_word (FILE *fp,
const int w);
26static void put_dword (FILE *fp,
const int d);
27static int write_bmp16 (
const char *fname,
int m,
int n,
const char map[]);
65 if ( size>minmn ) size = minmn;
68 printf(
"Writing matrix pattern to `%s'...\n",filename);
70 memset((
void *)map, 0x0F, size * size);
72 for (i = 0; i < size; ++i) {
73 for (j = A->
IA[i]; j < A->IA[i+1]; ++j) {
75 k = size*i + A->
JA[j];
78 else if (A->
val[j] > 1e-20)
80 else if (A->
val[j] < -1e-20)
88 write_bmp16(filename, size, size, map);
121 INT offset, bmsize, i, j, b;
129 size = ( (n+7)/8 )*8;
133 memset(map, 0x0F, size);
135 if (!(1 <= m && m <= 32767))
136 printf(
"### ERROR: Invalid num of rows %d! [%s]\n", m, __FUNCTION__);
138 if (!(1 <= n && n <= 32767))
139 printf(
"### ERROR: Invalid num of cols %d! [%s]\n", n, __FUNCTION__);
141 fp = fopen(fname,
"wb");
143 printf(
"### ERROR: Unable to create `%s'! [%s]\n", fname, __FUNCTION__);
147 offset = 14 + 40 + 16 * 4;
148 bmsize = (4 * n + 31) / 32;
150 put_byte(fp,
'B'); put_byte(fp,
'M');
151 put_dword(fp, offset + bmsize * 4);
154 put_dword(fp, offset);
163 put_dword(fp, 2953 );
164 put_dword(fp, 2953 );
169 put_dword(fp, 0x000000);
170 put_dword(fp, 0x000080);
171 put_dword(fp, 0x008000);
172 put_dword(fp, 0x008080);
173 put_dword(fp, 0x800000);
174 put_dword(fp, 0x800080);
175 put_dword(fp, 0x808000);
176 put_dword(fp, 0xC0C0C0);
177 put_dword(fp, 0x808080);
178 put_dword(fp, 0x0000FF);
179 put_dword(fp, 0x00FF00);
180 put_dword(fp, 0x00FFFF);
181 put_dword(fp, 0xFF0000);
182 put_dword(fp, 0xFF00FF);
183 put_dword(fp, 0xFFFF00);
184 put_dword(fp, 0xFFFFFF);
199 for ( i = A->
row-1; i >=0; i-- ) {
200 memset(map, 0x0F, size);
202 for ( j = A->
IA[i]; j < A->IA[i+1]; j++ ) {
205 if (map[col] != 0x0F)
207 else if ( val > 1e-20)
209 else if ( val < -1e-20)
217 for (j = 0; j < size; ++j) {
219 b |= (j < n ? map[j] & 15 : 0);
220 if (j & 1) put_byte(fp, b);
226 printf(
"### ERROR: Write error on `%s'! [%s]\n", fname, __FUNCTION__);
229FINISH:
if (fp != NULL) fclose(fp);
260 const char *filename,
268 INT row, col, i, j, k, l, minmn=nb*
MIN(m,n);
272 if (size>minmn) size=minmn;
274 printf(
"Writing matrix pattern to `%s'...\n",filename);
278 memset((
void *)map, 0x0F, size * size);
280 for ( i = 0; i < size/nb; i++ ) {
282 for ( j = A->
IA[i]; j < A->IA[i+1]; j++ ) {
283 for ( k = 0; k < A->
nb; k++ ) {
284 for ( l = 0; l < A->
nb; l++ ) {
287 col = A->
JA[j]*nb + l;
288 val = A->
val[ A->
JA[j]*nb2 + k*nb + l];
292 offset = size*row + col;
294 if (map[offset] != 0x0F)
296 else if ( val > 1e-20)
298 else if ( val < -1e-20)
310 write_bmp16(filename, size, size, map);
343 INT offset, bmsize, i, j, b;
352 size = ( (n+7)/8 )*8;
356 memset((
void *)map, 0x0F, size);
358 if (!(1 <= m && m <= 32767))
359 printf(
"### ERROR: Invalid num of rows %d! [%s]\n", m, __FUNCTION__);
361 if (!(1 <= n && n <= 32767))
362 printf(
"### ERROR: Invalid num of cols %d! [%s]\n", n, __FUNCTION__);
364 fp = fopen(fname,
"wb");
366 printf(
"### ERROR: Unable to create `%s'! [%s]\n", fname, __FUNCTION__);
370 offset = 14 + 40 + 16 * 4;
371 bmsize = (4 * n + 31) / 32;
373 put_byte(fp,
'B'); put_byte(fp,
'M');
374 put_dword(fp, offset + bmsize * 4);
377 put_dword(fp, offset);
386 put_dword(fp, 2953 );
387 put_dword(fp, 2953 );
392 put_dword(fp, 0x000000);
393 put_dword(fp, 0x000080);
394 put_dword(fp, 0x008000);
395 put_dword(fp, 0x008080);
396 put_dword(fp, 0x800000);
397 put_dword(fp, 0x800080);
398 put_dword(fp, 0x808000);
399 put_dword(fp, 0xC0C0C0);
400 put_dword(fp, 0x808080);
401 put_dword(fp, 0x0000FF);
402 put_dword(fp, 0x00FF00);
403 put_dword(fp, 0x00FFFF);
404 put_dword(fp, 0xFF0000);
405 put_dword(fp, 0xFF00FF);
406 put_dword(fp, 0xFFFF00);
407 put_dword(fp, 0xFFFFFF);
422 for ( i = A->
ROW-1; i >=0; i-- ) {
424 for ( k = A->
nb-1; k >=0; k-- ) {
426 memset(map, 0x0F, size);
428 for ( j = A->
IA[i]; j < A->IA[i+1]; j++ ) {
429 for ( l = 0; l < A->
nb; l++ ) {
431 col = A->
JA[j]*nb + l;
432 val = A->
val[ A->
JA[j]*nb2 + k*nb + l];
434 if (map[col] != 0x0F)
436 else if ( val > 1e-20)
438 else if ( val < -1e-20)
448 for (j = 0; j < size; ++j) {
450 b |= (j < n ? map[j] & 15 : 0);
451 if (j & 1) put_byte(fp, b);
459 printf(
"### ERROR: Write error on `%s'! [%s]\n", fname, __FUNCTION__);
462FINISH:
if (fp != NULL) fclose(fp);
484 REAL xmid,ymid,xc,yc;
486 sprintf(buf,
"Grid_ref_level%d.eps",level);
487 datei = fopen(buf,
"w");
489 printf(
"Opening file %s fails!\n", buf);
493 fprintf(datei,
"%%!PS-Adobe-2.0-2.0 EPSF-2.0\n");
494 fprintf(datei,
"%%%%BoundingBox: 0 0 550 550\n");
495 fprintf(datei,
"25 dup translate\n");
496 fprintf(datei,
"%f setlinewidth\n",0.2);
497 fprintf(datei,
"/Helvetica findfont %f scalefont setfont\n",64.0*pow(0.5,level));
498 fprintf(datei,
"/b{0 setgray} def\n");
499 fprintf(datei,
"/r{1.0 0.6 0.6 setrgbcolor} def\n");
500 fprintf(datei,
"/u{0.1 0.7 0.1 setrgbcolor} def\n");
501 fprintf(datei,
"/d{0.1 0.1 1.0 setrgbcolor} def\n");
502 fprintf(datei,
"/cs{closepath stroke} def\n");
503 fprintf(datei,
"/m{moveto} def\n");
504 fprintf(datei,
"/l{lineto} def\n");
506 fprintf(datei,
"b\n");
508 xc = (pg->
p[pg->
t[i][0]][0]+pg->
p[pg->
t[i][1]][0]+pg->
p[pg->
t[i][2]][0])*150.0;
509 yc = (pg->
p[pg->
t[i][0]][1]+pg->
p[pg->
t[i][1]][1]+pg->
p[pg->
t[i][2]][1])*150.0;
511 xmid = pg->
p[pg->
t[i][0]][0]*450.0;
512 ymid = pg->
p[pg->
t[i][0]][1]*450.0;
513 fprintf(datei,
"%.1f %.1f m ",0.9*xmid+0.1*xc,0.9*ymid+0.1*yc);
514 xmid = pg->
p[pg->
t[i][1]][0]*450.0;
515 ymid = pg->
p[pg->
t[i][1]][1]*450.0;
516 fprintf(datei,
"%.1f %.1f l ",0.9*xmid+0.1*xc,0.9*ymid+0.1*yc);
517 xmid = pg->
p[pg->
t[i][2]][0]*450.0;
518 ymid = pg->
p[pg->
t[i][2]][1]*450.0;
519 fprintf(datei,
"%.1f %.1f l ",0.9*xmid+0.1*xc,0.9*ymid+0.1*yc);
520 fprintf(datei,
"cs\n");
522 fprintf(datei,
"r\n");
524 xmid = pg->
p[i][0]*450.0;
525 ymid = pg->
p[i][1]*450.0;
526 fprintf(datei,
"%.1f %.1f m ",xmid,ymid);
527 fprintf(datei,
"(%d) show\n ",i);
529 fprintf(datei,
"u\n");
530 for(i=0; i<pg->
edges; ++i) {
531 xmid = 0.5*(pg->
p[pg->
e[i][0]][0]+pg->
p[pg->
e[i][1]][0])*450.0;
532 ymid = 0.5*(pg->
p[pg->
e[i][0]][1]+pg->
p[pg->
e[i][1]][1])*450.0;
533 fprintf(datei,
"%.1f %.1f m ",xmid,ymid);
534 fprintf(datei,
"(%d) show\n ",i);
536 xmid = pg->
p[pg->
e[i][0]][0]*450.0;
537 ymid = pg->
p[pg->
e[i][0]][1]*450.0;
538 fprintf(datei,
"%.1f %.1f m ",xmid,ymid);
539 xmid = pg->
p[pg->
e[i][1]][0]*450.0;
540 ymid = pg->
p[pg->
e[i][1]][1]*450.0;
541 fprintf(datei,
"%.1f %.1f l ",xmid,ymid);
542 fprintf(datei,
"cs\n");
544 fprintf(datei,
"d\n");
546 xmid = (pg->
p[pg->
t[i][0]][0]+pg->
p[pg->
t[i][1]][0]+pg->
p[pg->
t[i][2]][0])*150.0;
547 ymid = (pg->
p[pg->
t[i][0]][1]+pg->
p[pg->
t[i][1]][1]+pg->
p[pg->
t[i][2]][1])*150.0;
548 fprintf(datei,
"%.1f %.1f m ",xmid,ymid);
549 fprintf(datei,
"(%d) show\n ",i);
551 fprintf(datei,
"showpage\n");
568static void put_byte (FILE *fp,
584static void put_word (FILE *fp,
588 put_byte(fp, w >> 8);
601static void put_dword (FILE *fp,
605 put_word(fp, d >> 16);
674static int write_bmp16 (
const char *fname,
680 int offset, bmsize, i, j, b, ret = 1;
682 if (!(1 <= m && m <= 32767))
683 printf(
"### ERROR: %s invalid height %d\n", __FUNCTION__, m);
685 if (!(1 <= n && n <= 32767))
686 printf(
"### ERROR: %s invalid width %d\n", __FUNCTION__, n);
688 fp = fopen(fname,
"wb");
690 printf(
"### ERROR: %s unable to create `%s'\n", __FUNCTION__, fname);
694 offset = 14 + 40 + 16 * 4;
695 bmsize = (4 * n + 31) / 32;
697 put_byte(fp,
'B'); put_byte(fp,
'M');
698 put_dword(fp, offset + bmsize * 4);
701 put_dword(fp, offset);
710 put_dword(fp, 2953 );
711 put_dword(fp, 2953 );
716 put_dword(fp, 0x000000);
717 put_dword(fp, 0x000080);
718 put_dword(fp, 0x008000);
719 put_dword(fp, 0x008080);
720 put_dword(fp, 0x800000);
721 put_dword(fp, 0x800080);
722 put_dword(fp, 0x808000);
723 put_dword(fp, 0xC0C0C0);
724 put_dword(fp, 0x808080);
725 put_dword(fp, 0x0000FF);
726 put_dword(fp, 0x00FF00);
727 put_dword(fp, 0x00FFFF);
728 put_dword(fp, 0xFF0000);
729 put_dword(fp, 0xFF00FF);
730 put_dword(fp, 0xFFFF00);
731 put_dword(fp, 0xFFFFFF);
734 for (i = m - 1; i >= 0; i--) {
735 for (j = 0; j < ((n + 7) / 8) * 8; ++j) {
737 b |= (j < n ? map[i * n + j] & 15 : 0);
738 if (j & 1) put_byte(fp, b);
744 printf(
"### ERROR: %s write error on `%s'\n", __FUNCTION__, fname);
748FINISH:
if (fp != NULL) fclose(fp);
void fasp_dbsr_subplot(const dBSRmat *A, const char *filename, int size)
Write sparse matrix pattern in BMP file format.
void fasp_grid2d_plot(pgrid2d pg, int level)
Output grid to a EPS file.
void fasp_dcsr_subplot(const dCSRmat *A, const char *filename, int size)
Write sparse matrix pattern in BMP file format.
void fasp_dcsr_plot(const dCSRmat *A, const char *fname)
Write dCSR sparse matrix pattern in BMP file format.
void fasp_dbsr_plot(const dBSRmat *A, const char *fname)
Write dBSR sparse matrix pattern in BMP file format.
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
Main header file for the FASP project.
Header file for FASP grid.
Block sparse row storage matrix of REAL type.
INT COL
number of cols of sub-blocks in matrix A, N
INT nb
dimension of each sub-block
INT * IA
integer array of row pointers, the size is ROW+1
INT ROW
number of rows of sub-blocks in matrix A, M
Sparse matrix of REAL type in CSR format.
INT col
column of matrix A, n
REAL * val
nonzero entries of A
INT row
row number of matrix A, m
INT * IA
integer array of row pointers, the size is m+1
INT * JA
integer array of column indexes, the size is nnz
Two dimensional grid data structure.