正在加载图片...
1.2 Some C Conventions for Scientific Computing 23 Incidentally,you can use submatrix()for matrices of any type whose sizeof() is the same as sizeof(float)(often true for int,e.g.);just cast the first argument to type float *and cast the result to the desired type,e.g.,int ** The function void free_submatrix(float **b,long nrl,long nrh,long ncl,long nch) frees the array of row-pointers allocated by submatrix().Note that it does not free the memory allocated to the data in the submatrix,since that space still lies within the memory allocation of some original matrix. 81 Finally,if you have a standard C matrix declared as a[nrow][ncol],and you want to convert it into a matrix declared in our pointer-to-row-of-pointers manner, the following function does the trick: float **convert_matrix(float *a,long nrl,long nrh,long ncl,long nch) Allocate a float matrix m[nrl..nrh][ncl..nch]that points to the matrix declared in the standard C manner as a[nrow][ncol],where nrow=nrh-nr1+1 and ncol-nch-ncl+1.The routine should be called with the address &a[o][o]as the first argument. 令 (You can use this function when you want to make use of C's initializer syntax 造 Press. to set values for a matrix,but then be able to pass the matrix to programs in this book.)The function void free_convert_matrix(float **b,long nrl,long nrh,long ncl,long nch) Free a matrix allocated by convert_matrix() SCIENTIFIC 6 frees the allocation,without affecting the original matrix a. The only examples of allocating a three-dimensional array as a pointer-to- pointer-to-pointer structure in this book are found in the routines rlft3 in 812.5 and sfroid in $17.4.The necessary allocation and deallocation functions are Numerical Recipes 10-621 float ***f3tensor(long nrl,long nrh,long ncl,long nch,long ndl,long ndh) Allocate a float 3-dimensional array with subscript range [nrl..nrh][ncl..nch][ndl..ndh]. uction 43106 void free_f3tensor(float ***t,long nrl,long nrh,long ncl,long nch, long ndl,long ndh) (outside Free a float 3-dimensional array allocated by f3tensor(). Software. Complex Arithmetic C does not have complex data types,or predefined arithmetic operations on complex numbers.That omission is easily remedied with the set of functions in the file complex.c which is printed in full in Appendix C at the back of the book. A synopsis is as follows:1.2 Some C Conventions for Scientific Computing 23 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Incidentally, you can use submatrix() for matrices of any type whose sizeof() is the same as sizeof(float) (often true for int, e.g.); just cast the first argument to type float ** and cast the result to the desired type, e.g., int **. The function void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch) frees the array of row-pointers allocated by submatrix(). Note that it does not free the memory allocated to the data in the submatrix, since that space still lies within the memory allocation of some original matrix. Finally, if you have a standard C matrix declared as a[nrow][ncol], and you want to convert it into a matrix declared in our pointer-to-row-of-pointers manner, the following function does the trick: float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch) Allocate a float matrix m[nrl..nrh][ncl..nch] that points to the matrix declared in the standard C manner as a[nrow][ncol], where nrow=nrh-nrl+1 and ncol=nch-ncl+1. The routine should be called with the address &a[0][0] as the first argument. (You can use this function when you want to make use of C’s initializer syntax to set values for a matrix, but then be able to pass the matrix to programs in this book.) The function void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch) Free a matrix allocated by convert_matrix(). frees the allocation, without affecting the original matrix a. The only examples of allocating a three-dimensional array as a pointer-to￾pointer-to-pointer structure in this book are found in the routines rlft3 in §12.5 and sfroid in §17.4. The necessary allocation and deallocation functions are float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh) Allocate a float 3-dimensional array with subscript range [nrl..nrh][ncl..nch][ndl..ndh]. void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh) Free a float 3-dimensional array allocated by f3tensor(). Complex Arithmetic C does not have complex data types, or predefined arithmetic operations on complex numbers. That omission is easily remedied with the set of functions in the file complex.c which is printed in full in Appendix C at the back of the book. A synopsis is as follows:
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有