Changeset 577 in Sophya for trunk/Poubelle/archTOI.old/nrutil.c
- Timestamp:
- Nov 16, 1999, 2:20:39 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Poubelle/archTOI.old/nrutil.c
r556 r577 18 18 }*/ 19 19 20 float*vector(long nl, long nh)21 /* allocate a floatvector with subscript range v[nl..nh] */22 { 23 float*v;24 25 v=( float *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float)));20 double *vector(long nl, long nh) 21 /* allocate a double vector with subscript range v[nl..nh] */ 22 { 23 double *v; 24 25 v=(double *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(double))); 26 26 if (!v) nrerror("allocation failure in vector()"); 27 27 return v-nl+NR_END; … … 68 68 } 69 69 70 float **matrix(long nrl, long nrh, long ncl, long nch) 71 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */ 72 { 73 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 74 float **m; 75 76 /* allocate pointers to rows */ 77 m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*))); 78 if (!m) nrerror("allocation failure 1 in matrix()"); 79 m += NR_END; 80 m -= nrl; 81 82 /* allocate rows and set pointers to them */ 83 m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float))); 84 if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 85 m[nrl] += NR_END; 86 m[nrl] -= ncl; 87 88 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 89 90 /* return pointer to array of pointers to rows */ 91 return m; 92 } 93 94 double **dmatrix(long nrl, long nrh, long ncl, long nch) 70 double **matrix(long nrl, long nrh, long ncl, long nch) 95 71 /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */ 96 72 { … … 116 92 } 117 93 94 double **dmatrix(long nrl, long nrh, long ncl, long nch) 95 /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */ 96 { 97 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 98 double **m; 99 100 /* allocate pointers to rows */ 101 m=(double **) malloc((size_t)((nrow+NR_END)*sizeof(double*))); 102 if (!m) nrerror("allocation failure 1 in matrix()"); 103 m += NR_END; 104 m -= nrl; 105 106 /* allocate rows and set pointers to them */ 107 m[nrl]=(double *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double))); 108 if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 109 m[nrl] += NR_END; 110 m[nrl] -= ncl; 111 112 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 113 114 /* return pointer to array of pointers to rows */ 115 return m; 116 } 117 118 118 int **imatrix(long nrl, long nrh, long ncl, long nch) 119 119 /* allocate a int matrix with subscript range m[nrl..nrh][ncl..nch] */ … … 141 141 } 142 142 143 float **submatrix(float**a, long oldrl, long oldrh, long oldcl, long oldch,143 double **submatrix(double **a, long oldrl, long oldrh, long oldcl, long oldch, 144 144 long newrl, long newcl) 145 145 /* point a submatrix [newrl..][newcl..] to a[oldrl..oldrh][oldcl..oldch] */ 146 146 { 147 147 long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl; 148 float**m;148 double **m; 149 149 150 150 /* allocate array of pointers to rows */ 151 m=( float **) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));151 m=(double **) malloc((size_t) ((nrow+NR_END)*sizeof(double*))); 152 152 if (!m) nrerror("allocation failure in submatrix()"); 153 153 m += NR_END; … … 161 161 } 162 162 163 float **convert_matrix(float*a, long nrl, long nrh, long ncl, long nch)164 /* allocate a floatmatrix m[nrl..nrh][ncl..nch] that points to the matrix163 double **convert_matrix(double *a, long nrl, long nrh, long ncl, long nch) 164 /* allocate a double matrix m[nrl..nrh][ncl..nch] that points to the matrix 165 165 declared in the standard C manner as a[nrow][ncol], where nrow=nrh-nrl+1 166 166 and ncol=nch-ncl+1. The routine should be called with the address … … 168 168 { 169 169 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1; 170 float**m;171 172 /* allocate pointers to rows */ 173 m=( float **) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));170 double **m; 171 172 /* allocate pointers to rows */ 173 m=(double **) malloc((size_t) ((nrow+NR_END)*sizeof(double*))); 174 174 if (!m) nrerror("allocation failure in convert_matrix()"); 175 175 m += NR_END; … … 183 183 } 184 184 185 float***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)186 /* allocate a float3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */185 double ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh) 186 /* allocate a double 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */ 187 187 { 188 188 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1; 189 float***t;189 double ***t; 190 190 191 191 /* allocate pointers to pointers to rows */ 192 t=( float ***) malloc((size_t)((nrow+NR_END)*sizeof(float**)));192 t=(double ***) malloc((size_t)((nrow+NR_END)*sizeof(double**))); 193 193 if (!t) nrerror("allocation failure 1 in f3tensor()"); 194 194 t += NR_END; … … 196 196 197 197 /* allocate pointers to rows and set pointers to them */ 198 t[nrl]=( float **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float*)));198 t[nrl]=(double **) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double*))); 199 199 if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()"); 200 200 t[nrl] += NR_END; … … 202 202 203 203 /* allocate rows and set pointers to them */ 204 t[nrl][ncl]=( float *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(float)));204 t[nrl][ncl]=(double *) malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(double))); 205 205 if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()"); 206 206 t[nrl][ncl] += NR_END; … … 218 218 } 219 219 220 void free_vector( float*v, long nl, long nh)221 /* free a floatvector allocated with vector() */220 void free_vector(double *v, long nl, long nh) 221 /* free a double vector allocated with vector() */ 222 222 { 223 223 free((FREE_ARG) (v+nl-NR_END)); … … 248 248 } 249 249 250 void free_matrix( float**m, long nrl, long nrh, long ncl, long nch)251 /* free a floatmatrix allocated by matrix() */250 void free_matrix(double **m, long nrl, long nrh, long ncl, long nch) 251 /* free a double matrix allocated by matrix() */ 252 252 { 253 253 free((FREE_ARG) (m[nrl]+ncl-NR_END)); … … 269 269 } 270 270 271 void free_submatrix( float**b, long nrl, long nrh, long ncl, long nch)271 void free_submatrix(double **b, long nrl, long nrh, long ncl, long nch) 272 272 /* free a submatrix allocated by submatrix() */ 273 273 { … … 275 275 } 276 276 277 void free_convert_matrix( float**b, long nrl, long nrh, long ncl, long nch)277 void free_convert_matrix(double **b, long nrl, long nrh, long ncl, long nch) 278 278 /* free a matrix allocated by convert_matrix() */ 279 279 { … … 281 281 } 282 282 283 void free_f3tensor( float***t, long nrl, long nrh, long ncl, long nch,283 void free_f3tensor(double ***t, long nrl, long nrh, long ncl, long nch, 284 284 long ndl, long ndh) 285 /* free a floatf3tensor allocated by f3tensor() */285 /* free a double f3tensor allocated by f3tensor() */ 286 286 { 287 287 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END)); … … 309 309 } 310 310 311 float*vector(nl,nh)312 long nh,nl; 313 /* allocate a floatvector with subscript range v[nl..nh] */314 { 315 float*v;316 317 v=( float *)malloc((unsigned int) ((nh-nl+1+NR_END)*sizeof(float)));311 double *vector(nl,nh) 312 long nh,nl; 313 /* allocate a double vector with subscript range v[nl..nh] */ 314 { 315 double *v; 316 317 v=(double *)malloc((unsigned int) ((nh-nl+1+NR_END)*sizeof(double))); 318 318 if (!v) nrerror("allocation failure in vector()"); 319 319 return v-nl+NR_END; … … 364 364 } 365 365 366 float **matrix(nrl,nrh,ncl,nch) 367 long nch,ncl,nrh,nrl; 368 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */ 369 { 370 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 371 float **m; 372 373 /* allocate pointers to rows */ 374 m=(float **) malloc((unsigned int)((nrow+NR_END)*sizeof(float*))); 375 if (!m) nrerror("allocation failure 1 in matrix()"); 376 m += NR_END; 377 m -= nrl; 378 379 /* allocate rows and set pointers to them */ 380 m[nrl]=(float *) malloc((unsigned int)((nrow*ncol+NR_END)*sizeof(float))); 381 if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 382 m[nrl] += NR_END; 383 m[nrl] -= ncl; 384 385 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 386 387 /* return pointer to array of pointers to rows */ 388 return m; 389 } 390 391 double **dmatrix(nrl,nrh,ncl,nch) 366 double **matrix(nrl,nrh,ncl,nch) 392 367 long nch,ncl,nrh,nrl; 393 368 /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */ … … 414 389 } 415 390 391 double **dmatrix(nrl,nrh,ncl,nch) 392 long nch,ncl,nrh,nrl; 393 /* allocate a double matrix with subscript range m[nrl..nrh][ncl..nch] */ 394 { 395 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 396 double **m; 397 398 /* allocate pointers to rows */ 399 m=(double **) malloc((unsigned int)((nrow+NR_END)*sizeof(double*))); 400 if (!m) nrerror("allocation failure 1 in matrix()"); 401 m += NR_END; 402 m -= nrl; 403 404 /* allocate rows and set pointers to them */ 405 m[nrl]=(double *) malloc((unsigned int)((nrow*ncol+NR_END)*sizeof(double))); 406 if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 407 m[nrl] += NR_END; 408 m[nrl] -= ncl; 409 410 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 411 412 /* return pointer to array of pointers to rows */ 413 return m; 414 } 415 416 416 int **imatrix(nrl,nrh,ncl,nch) 417 417 long nch,ncl,nrh,nrl; … … 440 440 } 441 441 442 float**submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl)443 float**a;442 double **submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl) 443 double **a; 444 444 long newcl,newrl,oldch,oldcl,oldrh,oldrl; 445 445 /* point a submatrix [newrl..][newcl..] to a[oldrl..oldrh][oldcl..oldch] */ 446 446 { 447 447 long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl; 448 float**m;448 double **m; 449 449 450 450 /* allocate array of pointers to rows */ 451 m=( float **) malloc((unsigned int) ((nrow+NR_END)*sizeof(float*)));451 m=(double **) malloc((unsigned int) ((nrow+NR_END)*sizeof(double*))); 452 452 if (!m) nrerror("allocation failure in submatrix()"); 453 453 m += NR_END; … … 461 461 } 462 462 463 float**convert_matrix(a,nrl,nrh,ncl,nch)464 float*a;465 long nch,ncl,nrh,nrl; 466 /* allocate a floatmatrix m[nrl..nrh][ncl..nch] that points to the matrix463 double **convert_matrix(a,nrl,nrh,ncl,nch) 464 double *a; 465 long nch,ncl,nrh,nrl; 466 /* allocate a double matrix m[nrl..nrh][ncl..nch] that points to the matrix 467 467 declared in the standard C manner as a[nrow][ncol], where nrow=nrh-nrl+1 468 468 and ncol=nch-ncl+1. The routine should be called with the address … … 470 470 { 471 471 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1; 472 float**m;473 474 /* allocate pointers to rows */ 475 m=( float **) malloc((unsigned int) ((nrow+NR_END)*sizeof(float*)));472 double **m; 473 474 /* allocate pointers to rows */ 475 m=(double **) malloc((unsigned int) ((nrow+NR_END)*sizeof(double*))); 476 476 if (!m) nrerror("allocation failure in convert_matrix()"); 477 477 m += NR_END; … … 485 485 } 486 486 487 float***f3tensor(nrl,nrh,ncl,nch,ndl,ndh)487 double ***f3tensor(nrl,nrh,ncl,nch,ndl,ndh) 488 488 long nch,ncl,ndh,ndl,nrh,nrl; 489 /* allocate a float3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */489 /* allocate a double 3tensor with range t[nrl..nrh][ncl..nch][ndl..ndh] */ 490 490 { 491 491 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1; 492 float***t;492 double ***t; 493 493 494 494 /* allocate pointers to pointers to rows */ 495 t=( float ***) malloc((unsigned int)((nrow+NR_END)*sizeof(float**)));495 t=(double ***) malloc((unsigned int)((nrow+NR_END)*sizeof(double**))); 496 496 if (!t) nrerror("allocation failure 1 in f3tensor()"); 497 497 t += NR_END; … … 499 499 500 500 /* allocate pointers to rows and set pointers to them */ 501 t[nrl]=( float **) malloc((unsigned int)((nrow*ncol+NR_END)*sizeof(float*)));501 t[nrl]=(double **) malloc((unsigned int)((nrow*ncol+NR_END)*sizeof(double*))); 502 502 if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()"); 503 503 t[nrl] += NR_END; … … 505 505 506 506 /* allocate rows and set pointers to them */ 507 t[nrl][ncl]=( float *) malloc((unsigned int)((nrow*ncol*ndep+NR_END)*sizeof(float)));507 t[nrl][ncl]=(double *) malloc((unsigned int)((nrow*ncol*ndep+NR_END)*sizeof(double))); 508 508 if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()"); 509 509 t[nrl][ncl] += NR_END; … … 522 522 523 523 void free_vector(v,nl,nh) 524 float*v;525 long nh,nl; 526 /* free a floatvector allocated with vector() */524 double *v; 525 long nh,nl; 526 /* free a double vector allocated with vector() */ 527 527 { 528 528 free((FREE_ARG) (v+nl-NR_END)); … … 562 562 563 563 void free_matrix(m,nrl,nrh,ncl,nch) 564 float**m;565 long nch,ncl,nrh,nrl; 566 /* free a floatmatrix allocated by matrix() */564 double **m; 565 long nch,ncl,nrh,nrl; 566 /* free a double matrix allocated by matrix() */ 567 567 { 568 568 free((FREE_ARG) (m[nrl]+ncl-NR_END)); … … 589 589 590 590 void free_submatrix(b,nrl,nrh,ncl,nch) 591 float**b;591 double **b; 592 592 long nch,ncl,nrh,nrl; 593 593 /* free a submatrix allocated by submatrix() */ … … 597 597 598 598 void free_convert_matrix(b,nrl,nrh,ncl,nch) 599 float**b;599 double **b; 600 600 long nch,ncl,nrh,nrl; 601 601 /* free a matrix allocated by convert_matrix() */ … … 605 605 606 606 void free_f3tensor(t,nrl,nrh,ncl,nch,ndl,ndh) 607 float***t;607 double ***t; 608 608 long nch,ncl,ndh,ndl,nrh,nrl; 609 /* free a floatf3tensor allocated by f3tensor() */609 /* free a double f3tensor allocated by f3tensor() */ 610 610 { 611 611 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
Note:
See TracChangeset
for help on using the changeset viewer.