Changeset 16060
- Timestamp:
- Jan 14, 2008, 1:50:46 PM (18 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 15 edited
-
libohana/include/ohana.h (modified) (1 diff)
-
libohana/src/IOBufferOps.c (modified) (1 diff)
-
libohana/src/gaussj.c (modified) (1 diff)
-
relastro/include/relastro.h (modified) (1 diff)
-
relastro/src/ConfigInit.c (modified) (1 diff)
-
relastro/src/FitPM.c (modified) (1 diff)
-
relastro/src/FitPMandPar.c (modified) (1 diff)
-
relastro/src/FitPar.c (modified) (2 diffs)
-
relastro/src/ImageOps.c (modified) (1 diff)
-
relastro/src/MosaicOps.c (modified) (1 diff)
-
relastro/src/UpdateObjects.c (modified) (1 diff)
-
relastro/src/fitpoly.c (modified) (1 diff)
-
relastro/src/mkpolyterm.c (modified) (1 diff)
-
relastro/src/plotstuff.c (modified) (1 diff)
-
relastro/src/relastro.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana.h
r16040 r16060 184 184 char *ohana_version PROTO(()); 185 185 186 int dgaussj PROTO((double **a, int n, double **b, int m));187 int fgaussj PROTO((float **a, int n, float **b, int m));186 int dgaussjordan PROTO((double **A, double **B, int N, int M)); 187 int fgaussjordan PROTO((float **A, float **B, int n, int m)); 188 188 189 189 /* in time.c */ -
trunk/Ohana/src/libohana/src/IOBufferOps.c
r15851 r16060 45 45 46 46 Nread = read (fd, &buffer[0].buffer[buffer[0].Nbuffer], buffer[0].Nblock); 47 if (DEBUG) fprintf (stderr, "read IO buffer: (% x) %d from %d\n",buffer, Nread, buffer[0].Nblock);47 if (DEBUG) fprintf (stderr, "read IO buffer: (%lx) %d from %d\n", (unsigned long) buffer, Nread, buffer[0].Nblock); 48 48 49 49 /* on success, increase the block size for the next read */ -
trunk/Ohana/src/libohana/src/gaussj.c
r8301 r16060 1 1 # include <ohana.h> 2 2 3 int dgaussj (double **a, int n, double **b, int m) { 3 // Gauss-Jordan elimination using full pivots based on Press et al's description. Major 4 // modifications to conform to C indexing, use a boolean to track the completed pivot rows 5 // and catch the singular matrix early on. Also, much cleaner control loops than their 6 // implementation. XXX this really needs to check on round-off errors (see version by 7 // William Kahan 8 int dgaussjordan (double **A, double **B, int N, int M) { 4 9 5 int * indexCol;6 int * indexRow;10 int *colIndex; 11 int *rowIndex; 7 12 int *pivot; 8 int i, col, row, j, k, l, ll;9 double big, temp;13 int maxcol, maxrow; 14 double maxval, tmpval; 10 15 11 ALLOCATE (indexCol, int, n); 12 ALLOCATE (indexRow, int, n); 13 ALLOCATE (pivot, int, n); 14 for (j = 0; j < n; j++) pivot[j] = 0; 16 int diag, col, row; 15 17 16 row = col = 0; 17 big = fabs(a[0][0]); 18 ALLOCATE (colIndex, int, N); 19 ALLOCATE (rowIndex, int, N); 20 ALLOCATE (pivot, int, N); 21 memset (pivot, 0, N*sizeof(int)); 18 22 19 for (i = 0; i < n; i++) { 20 big = 0.0; 21 for (j = 0; j < n; j++) { 22 if (!finite(a[i][j])) goto escape; 23 if (pivot[j] != 1) { 24 for (k = 0; k < n; k++) { 25 if (pivot[k] == 0) { 26 if (fabs (a[j][k]) >= big) { 27 big = fabs (a[j][k]); 28 row = j; 29 col = k; 30 } 31 } else { 32 if (pivot[k] > 1) goto escape; 33 } 34 } 23 // init these so gcc does not complain 24 maxval = 0.0; 25 maxrow = maxcol = 0; 26 27 // we loop along the matrix diagonal, but we do not operate on the diagonal elements in 28 // order instead, we are looking for the current max element and operating on that 29 // diagonal element. this is effectively column pivoting. row pivoting is perfomed 30 // explicitly 31 32 for (diag = 0; diag < N; diag++) { 33 34 maxval = 0.0; 35 36 // search for the next pivot 37 for (row = 0; row < N; row++) { 38 if (!finite(A[row][diag])) goto escape; 39 40 // if we have already operated on this row (pivot[row] is true), skip it 41 if (pivot[row]) continue; 42 43 // if we have not yet operated on this row (pivot[row] is false), look for pivot for this row 44 for (col = 0; col < N; col++) { 45 if (pivot[col]) continue; 46 if (fabs (A[row][col]) < maxval) continue; 47 maxval = fabs (A[row][col]); 48 maxrow = row; 49 maxcol = col; 35 50 } 36 51 } 37 pivot[col]++; 38 if (row != col) { 39 for (l = 0; l < n; l++) SWAP (a[row][l], a[col][l]); 40 for (l = 0; l < m; l++) SWAP (b[row][l], b[col][l]); 52 53 // if pivot[maxcol] is set, we have already done this row: this implies a singular matrix 54 if (pivot[maxcol]) goto escape; 55 pivot[maxcol] = TRUE; 56 57 // if the selected pivot is off the diagonal, do a row swap 58 if (maxrow != maxcol) { 59 for (col = 0; col < N; col++) SWAP (A[maxrow][col], A[maxcol][col]); 60 for (col = 0; col < M; col++) SWAP (B[maxrow][col], B[maxcol][col]); 41 61 } 42 indexRow[i] =row;43 indexCol[i] =col;44 if ( a[col][col] == 0.0) goto escape;62 rowIndex[diag] = maxrow; 63 colIndex[diag] = maxcol; 64 if (A[maxcol][maxcol] == 0.0) goto escape; 45 65 46 66 /* rescale by pivot reciprocal */ 47 t emp = 1.0 / a[col][col];48 a[col][col] = 1.0;49 for ( l = 0; l < n; l++) a[col][l] *= temp;50 for ( l = 0; l < m; l++) b[col][l] *= temp;67 tmpval = 1.0 / A[maxcol][maxcol]; 68 A[maxcol][maxcol] = 1.0; 69 for (col = 0; col < N; col++) A[maxcol][col] *= tmpval; 70 for (col = 0; col < M; col++) B[maxcol][col] *= tmpval; 51 71 52 72 /* adjust the elements above the pivot */ 53 for (ll = 0; ll < n; ll++) { 54 if (ll != col) { 55 temp = a[ll][col]; 56 a[ll][col] = 0.0; 57 for (l = 0; l < n; l++) a[ll][l] -= a[col][l]*temp; 58 for (l = 0; l < m; l++) b[ll][l] -= b[col][l]*temp; 59 } 73 for (row = 0; row < N; row++) { 74 if (row == maxcol) continue; 75 tmpval = A[row][maxcol]; 76 A[row][maxcol] = 0.0; 77 for (col = 0; col < N; col++) A[row][col] -= A[maxcol][col]*tmpval; 78 for (col = 0; col < M; col++) B[row][col] -= B[maxcol][col]*tmpval; 60 79 } 61 80 } 62 81 63 for (l = n - 1; l >= 0; l--) { 64 if (indexRow[l] != indexCol[l]) { 65 for (k = 0; k < n; k++) SWAP (a[k][indexRow[l]], a[k][indexCol[l]]); 82 // swap back the inverse matrix based on the row swaps above 83 for (col = N - 1; col >= 0; col--) { 84 if (rowIndex[col] != colIndex[col]) { 85 for (row = 0; row < N; row++) SWAP (A[row][rowIndex[col]], A[row][colIndex[col]]); 66 86 } 67 87 } 88 68 89 free (pivot); 69 free ( indexRow);70 free ( indexCol);90 free (rowIndex); 91 free (colIndex); 71 92 return (TRUE); 72 93 73 94 escape: 74 95 free (pivot); 75 free ( indexRow);76 free ( indexCol);96 free (rowIndex); 97 free (colIndex); 77 98 return (FALSE); 78 99 } 79 100 80 int fgaussj (float **a, int n, float **b, int m) {101 int fgaussjordan (float **A, float **B, int N, int M) { 81 102 82 int * indexCol;83 int * indexRow;103 int *colIndex; 104 int *rowIndex; 84 105 int *pivot; 85 int i, col, row, j, k, l, ll;86 float big, temp;106 int maxcol, maxrow; 107 float maxval, tmpval; 87 108 88 ALLOCATE (indexCol, int, n); 89 ALLOCATE (indexRow, int, n); 90 ALLOCATE (pivot, int, n); 91 for (j = 0; j < n; j++) pivot[j] = 0; 109 int diag, col, row; 92 110 93 row = col = 0; 94 big = fabs(a[0][0]); 111 ALLOCATE (colIndex, int, N); 112 ALLOCATE (rowIndex, int, N); 113 ALLOCATE (pivot, int, N); 114 memset (pivot, 0, N*sizeof(int)); 95 115 96 for (i = 0; i < n; i++) { 97 big = 0.0; 98 for (j = 0; j < n; j++) { 99 if (!finite(a[i][j])) goto escape; 100 if (pivot[j] != 1) { 101 for (k = 0; k < n; k++) { 102 if (pivot[k] == 0) { 103 if (fabs (a[j][k]) >= big) { 104 big = fabs (a[j][k]); 105 row = j; 106 col = k; 107 } 108 } else { 109 if (pivot[k] > 1) goto escape; 110 } 111 } 116 // init these so gcc does not complain 117 maxval = 0.0; 118 maxrow = maxcol = 0; 119 120 // we loop along the matrix diagonal, but we do not operate on the diagonal elements in 121 // order instead, we are looking for the current max element and operating on that 122 // diagonal element. this is effectively column pivoting. row pivoting is perfomed 123 // explicitly 124 125 for (diag = 0; diag < N; diag++) { 126 127 maxval = 0.0; 128 129 // search for the next pivot 130 for (row = 0; row < N; row++) { 131 if (!finite(A[row][diag])) goto escape; 132 133 // if we have already operated on this row (pivot[row] is true), skip it 134 if (pivot[row]) continue; 135 136 // if we have not yet operated on this row (pivot[row] is false), look for pivot for this row 137 for (col = 0; col < N; col++) { 138 if (pivot[col]) continue; 139 if (fabs (A[row][col]) < maxval) continue; 140 maxval = fabs (A[row][col]); 141 maxrow = row; 142 maxcol = col; 112 143 } 113 144 } 114 pivot[col]++; 115 if (row != col) { 116 for (l = 0; l < n; l++) SWAP (a[row][l], a[col][l]); 117 for (l = 0; l < m; l++) SWAP (b[row][l], b[col][l]); 145 146 // if pivot[maxcol] is set, we have already done this row: this implies a singular matrix 147 if (pivot[maxcol]) goto escape; 148 pivot[maxcol] = TRUE; 149 150 // if the selected pivot is off the diagonal, do a row swap 151 if (maxrow != maxcol) { 152 for (col = 0; col < N; col++) SWAP (A[maxrow][col], A[maxcol][col]); 153 for (col = 0; col < M; col++) SWAP (B[maxrow][col], B[maxcol][col]); 118 154 } 119 indexRow[i] =row;120 indexCol[i] =col;121 if ( a[col][col] == 0.0) goto escape;155 rowIndex[diag] = maxrow; 156 colIndex[diag] = maxcol; 157 if (A[maxcol][maxcol] == 0.0) goto escape; 122 158 123 159 /* rescale by pivot reciprocal */ 124 t emp = 1.0 / a[col][col];125 a[col][col] = 1.0;126 for ( l = 0; l < n; l++) a[col][l] *= temp;127 for ( l = 0; l < m; l++) b[col][l] *= temp;128 160 tmpval = 1.0 / A[maxcol][maxcol]; 161 A[maxcol][maxcol] = 1.0; 162 for (col = 0; col < N; col++) A[maxcol][col] *= tmpval; 163 for (col = 0; col < M; col++) B[maxcol][col] *= tmpval; 164 129 165 /* adjust the elements above the pivot */ 130 for (ll = 0; ll < n; ll++) { 131 if (ll != col) { 132 temp = a[ll][col]; 133 a[ll][col] = 0.0; 134 for (l = 0; l < n; l++) a[ll][l] -= a[col][l]*temp; 135 for (l = 0; l < m; l++) b[ll][l] -= b[col][l]*temp; 136 } 166 for (row = 0; row < N; row++) { 167 if (row == maxcol) continue; 168 tmpval = A[row][maxcol]; 169 A[row][maxcol] = 0.0; 170 for (col = 0; col < N; col++) A[row][col] -= A[maxcol][col]*tmpval; 171 for (col = 0; col < M; col++) B[row][col] -= B[maxcol][col]*tmpval; 137 172 } 138 173 } 139 174 140 for (l = n - 1; l >= 0; l--) { 141 if (indexRow[l] != indexCol[l]) { 142 for (k = 0; k < n; k++) SWAP (a[k][indexRow[l]], a[k][indexCol[l]]); 175 // swap back the inverse matrix based on the row swaps above 176 for (col = N - 1; col >= 0; col--) { 177 if (rowIndex[col] != colIndex[col]) { 178 for (row = 0; row < N; row++) SWAP (A[row][rowIndex[col]], A[row][colIndex[col]]); 143 179 } 144 180 } 181 145 182 free (pivot); 146 free ( indexRow);147 free ( indexCol);183 free (rowIndex); 184 free (colIndex); 148 185 return (TRUE); 149 186 150 187 escape: 151 188 free (pivot); 152 free ( indexRow);153 free ( indexCol);189 free (rowIndex); 190 free (colIndex); 154 191 return (FALSE); 155 192 } -
trunk/Ohana/src/relastro/include/relastro.h
r15600 r16060 207 207 void unlock_image_db (FITS_DB *db); 208 208 void create_image_db (FITS_DB *db); 209 void save_catalogs (Catalog *catalog, int Ncatalog); 209 210 210 211 int main PROTO((int argc, char **argv)); -
trunk/Ohana/src/relastro/src/ConfigInit.c
r15579 r16060 3 3 void ConfigInit (int *argc, char **argv) { 4 4 5 double ZERO_POINT;6 5 char *config, *file; 7 6 char CatdirPhotcodeFile[256]; -
trunk/Ohana/src/relastro/src/FitPM.c
r12731 r16060 53 53 B[3][0] = YT; 54 54 55 dgaussj (A, 4, B, 1);55 dgaussjordan (A, B, 4, 1); 56 56 57 57 fit[0].Ro = B[0][0]; -
trunk/Ohana/src/relastro/src/FitPMandPar.c
r12731 r16060 76 76 B[4][0] = PRX + PDY; 77 77 78 dgaussj (A, 5, B, 1);78 dgaussjordan (A, B, 5, 1); 79 79 80 80 fit[0].Ro = B[0][0]; -
trunk/Ohana/src/relastro/src/FitPar.c
r15600 r16060 7 7 8 8 double **A, **B; 9 double wx, wy, Wx, Wy, Tx, Ty, Tx2, Ty2, Xs, Ys, XT, YT;10 double PR, PD, PR T, PDT, PRX, PDY, PR2, PD2;9 double wx, wy, Wx, Wy, Xs, Ys; 10 double PR, PD, PRX, PDY, PR2, PD2; 11 11 12 12 A = array_init (3, 3); … … 50 50 B[2][0] = PRX + PDY; 51 51 52 dgaussj (A, 3, B, 1);52 dgaussjordan (A, B, 3, 1); 53 53 54 54 fit[0].Ro = B[0][0]; -
trunk/Ohana/src/relastro/src/ImageOps.c
r15600 r16060 289 289 LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, &image[im].coords); 290 290 break; 291 default: 292 fprintf (stderr, "invalid case"); 293 abort(); 291 294 } 292 295 } -
trunk/Ohana/src/relastro/src/MosaicOps.c
r15600 r16060 22 22 void initMosaics (Image *image, int Nimage) { 23 23 24 int i, j, status, found, NMOSAIC, *NIMLIST;24 int i, j, found, NMOSAIC; 25 25 unsigned int start, stop; 26 char *pname;27 26 28 27 Nmosaic = 0; -
trunk/Ohana/src/relastro/src/UpdateObjects.c
r15694 r16060 179 179 180 180 default: 181 fprintf (stderr, "programming error at %s, % s", __FILE__, __LINE__);181 fprintf (stderr, "programming error at %s, %d", __FILE__, __LINE__); 182 182 exit (2); 183 183 } -
trunk/Ohana/src/relastro/src/fitpoly.c
r15590 r16060 137 137 } 138 138 139 dgaussj (matrix, fit[0].Nelems, vector, 2);139 dgaussjordan (matrix, vector, fit[0].Nelems, 2); 140 140 141 141 for (i = 0; i < fit[0].Nelems; i++) { -
trunk/Ohana/src/relastro/src/mkpolyterm.c
r15590 r16060 61 61 beta[1][0] = poly2d_eval (yfit, Nx, Ny, Xo, Yo); 62 62 63 dgaussj (alpha, 2, beta, 1);63 dgaussjordan (alpha, beta, 2, 1); 64 64 65 65 Xo -= beta[0][0]; -
trunk/Ohana/src/relastro/src/plotstuff.c
r13479 r16060 79 79 80 80 float *values; 81 int i , Nbytes;81 int i; 82 82 83 83 if (Npts < 1) return; -
trunk/Ohana/src/relastro/src/relastro.c
r15600 r16060 55 55 56 56 default: 57 fprintf (stderr, "programming error at %s:% s", __FILE__, __LINE__);57 fprintf (stderr, "programming error at %s:%d", __FILE__, __LINE__); 58 58 exit (2); 59 59 }
Note:
See TracChangeset
for help on using the changeset viewer.
