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

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

 ViewVC Help Powered by ViewVC 1.1.26