# Contents of /trunk/paso/src/SparseMatrix_saveHB.c

Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 11 months ago) by ksteube
File MIME type: text/plain
File size: 6191 byte(s)
```Copyright updated in all files

```
 1 2 /******************************************************* 3 * 4 * Copyright (c) 2003-2008 by University of Queensland 5 * Earth Systems Science Computational Center (ESSCC) 6 * http://www.uq.edu.au/esscc 7 * 8 * Primary Business: Queensland, Australia 9 * Licensed under the Open Software License version 3.0 10 * http://www.opensource.org/licenses/osl-3.0.php 11 * 12 *******************************************************/ 13 14 15 /**************************************************************/ 16 17 /* Paso: SparseMatrix is saved to Harwell-Boeing format */ 18 19 /**************************************************************/ 20 21 /* Copyright: ACcESS Australia 2005 */ 22 /* Author: imran@esscc.uq.edu.au */ 23 24 /**************************************************************/ 25 26 #include "Paso.h" 27 #include "SparseMatrix.h" 28 29 /* TODO: Refactor the stuff in here into hbio, just like mmio! */ 30 31 static dim_t M, N, nz; 32 33 static int calc_digits( int ); 34 static void fmt_str( int, int, int*, int*, int*, char*, char* ); 35 static void print_data( FILE*, int, int, int, char*, void*, int, int ); 36 static void generate_HB( FILE*, dim_t*, dim_t*, double* ); 37 38 /* function to get number of digits in an integer */ 39 int calc_digits( int var ) 40 { 41 int digits = 1; 42 while( (var/=10) ) 43 digits++; 44 45 return digits; 46 } 47 48 /* function to generate the format string. 49 * 50 * use maxlen to determine no. of entries per line 51 * use nvalues to determine no. of lines 52 */ 53 void fmt_str( int nvalues, int integer, int *width, int *nlines, int *nperline, char *pfmt, char *fmt ) 54 { 55 int per_line; 56 int maxlen = *width; 57 58 if( integer && maxlen < 10 ) 59 maxlen = 10; 60 else 61 maxlen = 13; 62 63 per_line = 80 / maxlen; 64 *nlines = nvalues / per_line; 65 if( nvalues % per_line ) 66 (*nlines)++; 67 68 *nperline = per_line; 69 if( integer ) 70 { 71 sprintf( pfmt, "(%dI%d)", per_line, maxlen ); 72 sprintf( fmt, "%%%dd", maxlen ); 73 } 74 else 75 { 76 sprintf( pfmt, "(1P%dE%d.6)", per_line, maxlen ); 77 sprintf( fmt, "%%%d.6E", maxlen ); 78 } 79 *width = maxlen; 80 } 81 82 /* function to print the actual data in the right format */ 83 void print_data( FILE *fp, int n_perline, int width, int nval, char *fmt, void *ptr, int integer, int adjust ) 84 { 85 double *data = ptr; 86 int entries_done = 0; 87 int padding, i; 88 char pad_fmt[10]; 89 90 padding = 80 - n_perline*width; 91 sprintf( pad_fmt, "%%%dc", padding ); 92 93 if( adjust != 1 ) 94 adjust = 0; 95 96 if( integer ) 97 { 98 dim_t *data = ptr; 99 for(i=0; itype & MATRIX_FORMAT_OFFSET1 ? 1:0); 183 dim_t *row_ind=NULL, *col_ind = NULL, *col_ptr=NULL; 184 int nz = A_p->len; 185 186 if (A_p->val == NULL) { 187 Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_saveHB_CSC: unsupported format detected.\n"); 188 return; 189 } 190 191 if( A_p->row_block_size == 1 && A_p->col_block_size == 1 ) { 192 M = A_p->numRows; 193 N = A_p->numCols; 194 generate_HB( fileHandle_p, A_p->pattern->ptr, A_p->pattern->index, A_p->val ); 195 } else { 196 M = A_p->numRows*A_p->row_block_size; 197 N = A_p->numCols*A_p->col_block_size; 198 199 row_ind = MEMALLOC( nz, dim_t ); 200 col_ind = MEMALLOC( nz, dim_t ); 201 202 i = 0; 203 for( iCol=0; iColpattern->numOutput; iCol++ ) 204 for( ic=0; iccol_block_size; ic++) 205 for( iPtr=A_p->pattern->ptr[iCol]-index_offset; iPtrpattern->ptr[iCol+1]-index_offset; iPtr++) 206 for( ir=0; irrow_block_size; ir++ ) { 207 row_ind[i] = (A_p->pattern->index[iPtr]-index_offset)*A_p->row_block_size+ir+1; 208 col_ind[i] = iCol*A_p->col_block_size+ic+1; 209 i++; 210 } 211 /* get the col_ptr */ 212 col_ptr = MEMALLOC( (N+1), dim_t ); 213 214 curr_col = 0; 215 for(j=0; (jval ); 224 225 /* free the allocated memory */ 226 MEMFREE( col_ptr ); 227 MEMFREE( col_ind ); 228 MEMFREE( row_ind ); 229 } 230 return; 231 }

 ViewVC Help Powered by ViewVC 1.1.26