Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/control/oldikor/UTILS/nrutil.c

Go to the documentation of this file.
00001 
00002 #include <malloc.h>
00003 #include <stdio.h>
00004 
00005 void nrerror(error_text)
00006 char error_text[];
00007 {
00008         void exit();
00009 
00010         fprintf(stderr,"Numerical Recipes run-time error...\n");
00011         fprintf(stderr,"%s\n",error_text);
00012         fprintf(stderr,"...now exiting to system...\n");
00013         exit(1);
00014 }
00015 
00016 
00017 
00018 float *vector(nl,nh)
00019 int nl,nh;
00020 {
00021         float *v;
00022 
00023         v=(float *)malloc((unsigned) (nh-nl+1)*sizeof(float));
00024         if (!v) nrerror("allocation failure in vector()");
00025         return v-nl;
00026 }
00027 
00028 int *ivector(nl,nh)
00029 int nl,nh;
00030 {
00031         int *v;
00032 
00033         v=(int *)malloc((unsigned) (nh-nl+1)*sizeof(int));
00034         if (!v) nrerror("allocation failure in ivector()");
00035         return v-nl;
00036 }
00037 
00038 double *dvector(nl,nh)
00039 int nl,nh;
00040 {
00041         double *v;
00042 
00043         v=(double *)malloc((unsigned) (nh-nl+1)*sizeof(double));
00044         if (!v) nrerror("allocation failure in dvector()");
00045         return v-nl;
00046 }
00047 
00048 
00049 
00050 float **matrix(nrl,nrh,ncl,nch)
00051 int nrl,nrh,ncl,nch;
00052 {
00053         int i;
00054         float **m;
00055 
00056         m=(float **) malloc((unsigned) (nrh-nrl+1)*sizeof(float*));
00057         if (!m) nrerror("allocation failure 1 in matrix()");
00058         m -= nrl;
00059 
00060         for(i=nrl;i<=nrh;i++) {
00061                 m[i]=(float *) malloc((unsigned) (nch-ncl+1)*sizeof(float));
00062                 if (!m[i]) nrerror("allocation failure 2 in matrix()");
00063                 m[i] -= ncl;
00064         }
00065         return m;
00066 }
00067 
00068 double **dmatrix(nrl,nrh,ncl,nch)
00069 int nrl,nrh,ncl,nch;
00070 {
00071         int i;
00072         double **m;
00073 
00074         m=(double **) malloc((unsigned) (nrh-nrl+1)*sizeof(double*));
00075         if (!m) nrerror("allocation failure 1 in dmatrix()");
00076         m -= nrl;
00077 
00078         for(i=nrl;i<=nrh;i++) {
00079                 m[i]=(double *) malloc((unsigned) (nch-ncl+1)*sizeof(double));
00080                 if (!m[i]) nrerror("allocation failure 2 in dmatrix()");
00081                 m[i] -= ncl;
00082         }
00083         return m;
00084 }
00085 
00086 int **imatrix(nrl,nrh,ncl,nch)
00087 int nrl,nrh,ncl,nch;
00088 {
00089         int i,**m;
00090 
00091         m=(int **)malloc((unsigned) (nrh-nrl+1)*sizeof(int*));
00092         if (!m) nrerror("allocation failure 1 in imatrix()");
00093         m -= nrl;
00094 
00095         for(i=nrl;i<=nrh;i++) {
00096                 m[i]=(int *)malloc((unsigned) (nch-ncl+1)*sizeof(int));
00097                 if (!m[i]) nrerror("allocation failure 2 in imatrix()");
00098                 m[i] -= ncl;
00099         }
00100         return m;
00101 }
00102 
00103 
00104 
00105 float **submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl)
00106 float **a;
00107 int oldrl,oldrh,oldcl,oldch,newrl,newcl;
00108 {
00109         int i,j;
00110         float **m;
00111 
00112         m=(float **) malloc((unsigned) (oldrh-oldrl+1)*sizeof(float*));
00113         if (!m) nrerror("allocation failure in submatrix()");
00114         m -= newrl;
00115 
00116         for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+oldcl-newcl;
00117 
00118         return m;
00119 }
00120 
00121 
00122 
00123 void free_vector(v,nl,nh)
00124 float *v;
00125 int nl,nh;
00126 {
00127         free((char*) (v+nl));
00128 }
00129 
00130 void free_ivector(v,nl,nh)
00131 int *v,nl,nh;
00132 {
00133         free((char*) (v+nl));
00134 }
00135 
00136 void free_dvector(v,nl,nh)
00137 double *v;
00138 int nl,nh;
00139 {
00140         free((char*) (v+nl));
00141 }
00142 
00143 
00144 
00145 void free_matrix(m,nrl,nrh,ncl,nch)
00146 float **m;
00147 int nrl,nrh,ncl,nch;
00148 {
00149         int i;
00150 
00151         for(i=nrh;i>=nrl;i--) free((char*) (m[i]+ncl));
00152         free((char*) (m+nrl));
00153 }
00154 
00155 void free_dmatrix(m,nrl,nrh,ncl,nch)
00156 double **m;
00157 int nrl,nrh,ncl,nch;
00158 {
00159         int i;
00160 
00161         for(i=nrh;i>=nrl;i--) free((char*) (m[i]+ncl));
00162         free((char*) (m+nrl));
00163 }
00164 
00165 void free_imatrix(m,nrl,nrh,ncl,nch)
00166 int **m;
00167 int nrl,nrh,ncl,nch;
00168 {
00169         int i;
00170 
00171         for(i=nrh;i>=nrl;i--) free((char*) (m[i]+ncl));
00172         free((char*) (m+nrl));
00173 }
00174 
00175 
00176 
00177 void free_submatrix(b,nrl,nrh,ncl,nch)
00178 float **b;
00179 int nrl,nrh,ncl,nch;
00180 {
00181         free((char*) (b+nrl));
00182 }
00183 
00184 
00185 
00186 float **convert_matrix(a,nrl,nrh,ncl,nch)
00187 float *a;
00188 int nrl,nrh,ncl,nch;
00189 {
00190         int i,j,nrow,ncol;
00191         float **m;
00192 
00193         nrow=nrh-nrl+1;
00194         ncol=nch-ncl+1;
00195         m = (float **) malloc((unsigned) (nrow)*sizeof(float*));
00196         if (!m) nrerror("allocation failure in convert_matrix()");
00197         m -= nrl;
00198         for(i=0,j=nrl;i<=nrow-1;i++,j++) m[j]=a+ncol*i-ncl;
00199         return m;
00200 }
00201 
00202 
00203 
00204 void free_convert_matrix(b,nrl,nrh,ncl,nch)
00205 float **b;
00206 int nrl,nrh,ncl,nch;
00207 {
00208         free((char*) (b+nrl));
00209 }

Generated on Thu Jul 29 15:56:36 2004 for OpenSim by doxygen 1.3.6