Ice Sheet System Model  4.18
Code documentation
PrintArrays.cpp
Go to the documentation of this file.
1 #include "./elements.h"
2 #include "../io/Print/Print.h"
3 #include <iomanip>
4 using namespace std;
5 
6 void printarray(IssmPDouble* array,int lines,int cols){
7  _printf_("\n");
8  for(int i=0;i<lines;i++){
9  _printf_(" [ ");
10  for(int j=0;j<cols;j++) _printf_( " " << setw(11) << setprecision (5) << array[i*cols+j]);
11  _printf_(" ]\n");
12  }
13  _printf_("\n");
14 }
15 #ifdef _HAVE_AD_
16 void printarray(IssmDouble* array,int lines,int cols){
17  _printf_("\n");
18  for(int i=0;i<lines;i++){
19  _printf_(" [ ");
20  for(int j=0;j<cols;j++) _printf_( " " << setw(11) << setprecision (5) << array[i*cols+j]);
21  _printf_(" ]\n");
22  }
23  _printf_("\n");
24 }
25 #endif
26 void printsparsity(IssmPDouble* array,int lines,int cols){
27  int count;
28  _printf_("\n");
29  for(int i=0;i<lines;i++){
30  _printf_(" [ ");
31  count = 0;
32  for(int j=0;j<cols;j++){
33  if(array[i*cols+j]!=0.0){
34  _printf_( " X"); count++;
35  }
36  else
37  _printf_( " .");
38  }
39  _printf_(" ] "<<i<<" => "<<count << "\n");
40  }
41  _printf_("\n");
42 }
43 void printarray(int* array,int lines,int cols){
44  _printf_("\n");
45  for(int i=0;i<lines;i++){
46  _printf_(" [ ");
47  for(int j=0;j<cols;j++) _printf_( " " << setw(11) << setprecision (5) << array[i*cols+j]);
48  _printf_(" ]\n");
49  }
50  _printf_("\n");
51 }
52 void printarray_matlab(const char* filename,int* array,int lines,int cols){
53  FILE *f = fopen(filename,"w");
54  fprintf(f,"%% Matrix of size %ix%i\n",lines,cols);
55  fprintf(f,"\n");
56  fprintf(f,"A=[...\n");
57  for(int i=0;i<lines;i++){
58  for(int j=0;j<cols;j++) fprintf(f," %i",array[i*cols+j]);
59  fprintf(f,"\n");
60  }
61  fprintf(f,"];\n");
62  fclose(f);
63 }
64 void printarray(bool* array,int lines,int cols){
65  _printf_("\n");
66  for(int i=0;i<lines;i++){
67  _printf_(" [ ");
68  for(int j=0;j<cols;j++){
69  if(array[i*cols+j]) _printf_( " 1");
70  else _printf_( " 0");
71  }
72  _printf_(" ]\n");
73  }
74  _printf_("\n");
75 }
76 void printbinary(int n){
77  unsigned int i=1L<<(sizeof(n)*8-1);
78  while (i>0) {
79  if (n&i)
80  _printf_("1");
81  else
82  _printf_("0");
83  i>>=1;
84  }
85 }
printarray
void printarray(IssmPDouble *array, int lines, int cols)
Definition: PrintArrays.cpp:6
IssmDouble
double IssmDouble
Definition: types.h:37
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
elements.h
prototypes for elements.h
printbinary
void printbinary(int n)
Definition: PrintArrays.cpp:76
printsparsity
void printsparsity(IssmPDouble *array, int lines, int cols)
Definition: PrintArrays.cpp:26
printarray_matlab
void printarray_matlab(const char *filename, int *array, int lines, int cols)
Definition: PrintArrays.cpp:52
IssmPDouble
IssmDouble IssmPDouble
Definition: types.h:38