55 #if defined(__STDC__) || defined(ANSI) || defined(NRANSI)
57 #include <flames_newmatrix.h>
61 #include <flames_midas_def.h>
62 #include <flames_uves.h>
63 #include <uves_error.h>
65 #define FREE_ARG char*
71 void nrerror(
const char* error_text)
84 SCTPUT(
"Numerical Recipes run-time error...\n");
85 sprintf(output,
"%s\n", error_text);
87 SCTPUT(
"...now exiting to system...\n");
96 float *vector(int32_t nl, int32_t nh)
101 v=(
float *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(
float));
102 if (!v) nrerror(
"allocation failure in vector()");
106 int *ivector(int32_t nl, int32_t nh)
111 v=(
int *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(
int));
112 if (!v) nrerror(
"allocation failure in ivector()");
116 unsigned int *uivector(int32_t nl, int32_t nh)
121 v=(
unsigned int *) calloc((
size_t) (nh-nl+1+NR_END),
122 sizeof(
unsigned int));
123 if (!v) nrerror(
"allocation failure in uivector()");
127 char *cvector(int32_t nl, int32_t nh)
132 v=(
char *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(
char));
133 if (!v) nrerror(
"allocation failure in cvector()");
137 unsigned char *ucvector(int32_t nl, int32_t nh)
142 v=(
unsigned char *) calloc((
size_t) (nh-nl+1+NR_END),
143 sizeof(
unsigned char));
144 if (!v) nrerror(
"allocation failure in ucvector()");
148 int32_t *lvector(int32_t nl, int32_t nh)
153 v=(int32_t *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(int32_t));
154 if (!v) nrerror(
"allocation failure in lvector()");
158 uint32_t *ulvector(int32_t nl, int32_t nh)
163 v=(uint32_t *) calloc((
size_t) (nh-nl+1+NR_END),
165 if (!v) nrerror(
"allocation failure in ulvector()");
169 double *dvector(int32_t nl, int32_t nh)
174 v=(
double *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(
double));
175 if (!v) nrerror(
"allocation failure in dvector()");
179 frame_data *fdvector(int32_t nl, int32_t nh)
184 v=(frame_data *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(frame_data));
185 if (!v) nrerror(
"allocation failure in fdvector()");
189 frame_mask *fmvector(int32_t nl, int32_t nh)
194 v=(frame_mask *) calloc((
size_t) (nh-nl+1+NR_END),
sizeof(frame_mask));
195 if (!v) nrerror(
"allocation failure in fdvector()");
199 char **cmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
202 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
206 m=(
char **) calloc((
size_t)(nrow+NR_END),
sizeof(
char*));
207 if (!m) nrerror(
"allocation failure 1 in cmatrix()");
212 m[nrl]=(
char *) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
char));
213 if (!m[nrl]) nrerror(
"allocation failure 2 in cmatrix()");
217 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
223 float **matrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
226 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
230 m=(
float **) calloc((
size_t)(nrow+NR_END),
sizeof(
float*));
231 if (!m) nrerror(
"allocation failure 1 in matrix()");
236 m[nrl]=(
float *) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
float));
237 if (!m[nrl]) nrerror(
"allocation failure 2 in matrix()");
241 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
247 double **dmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
250 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
254 m=(
double **) calloc((
size_t)(nrow+NR_END),
sizeof(
double*));
255 if (!m) nrerror(
"allocation failure 1 in dmatrix()");
265 m[nrl]=(
double *) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
double));
268 if (!m[nrl]) nrerror(
"allocation failure 2 in dmatrix()");
272 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
277 int **imatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
280 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
284 m=(
int **) calloc((
size_t)(nrow+NR_END),
sizeof(
int*));
285 if (!m) nrerror(
"allocation failure 1 in imatrix()");
291 m[nrl]=(
int *) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
int));
292 if (!m[nrl]) nrerror(
"allocation failure 2 in imatrix()");
296 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
302 uint32_t **ulmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
305 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
309 m=(uint32_t **) calloc((
size_t)(nrow+NR_END),
311 if (!m) nrerror(
"allocation failure 1 in ulmatrix()");
317 m[nrl]=(uint32_t *) calloc((
size_t)(nrow*ncol+NR_END),
319 if (!m[nrl]) nrerror(
"allocation failure 2 in ulmatrix()");
323 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
329 int32_t **lmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
332 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
336 m=(int32_t **) calloc((
size_t)(nrow+NR_END),
sizeof(int32_t*));
337 if (!m) nrerror(
"allocation failure 1 in lmatrix()");
343 m[nrl]=(int32_t *) calloc((
size_t)(nrow*ncol+NR_END),
345 if (!m[nrl]) nrerror(
"allocation failure 2 in lmatrix()");
349 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
355 frame_data **fdmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
358 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
362 m=(frame_data **) calloc((
size_t)(nrow+NR_END),
sizeof(frame_data*));
363 if (!m) nrerror(
"allocation failure 1 in fdmatrix()");
369 m[nrl]=(frame_data *) calloc((
size_t)(nrow*ncol+NR_END),
371 if (!m[nrl]) nrerror(
"allocation failure 2 in fdmatrix()");
375 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
381 frame_mask **fmmatrix(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
384 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
388 m=(frame_mask **) calloc((
size_t)(nrow+NR_END),
sizeof(frame_mask*));
389 if (!m) nrerror(
"allocation failure 1 in fmmatrix()");
395 m[nrl]=(frame_mask *) calloc((
size_t)(nrow*ncol+NR_END),
397 if (!m[nrl]) nrerror(
"allocation failure 2 in fmmatrix()");
401 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
407 float **submatrix(
float **a, int32_t oldrl, int32_t oldrh, int32_t oldcl,
408 int32_t newrl, int32_t newcl)
411 int32_t i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
415 m=(
float **) calloc((
size_t) (nrow+NR_END),
sizeof(
float*));
416 if (!m) nrerror(
"allocation failure in submatrix()");
421 for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
427 float **convert_matrix(
float *a, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
433 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
437 m=(
float **) calloc((
size_t) (nrow+NR_END),
sizeof(
float*));
438 if (!m) nrerror(
"allocation failure in convert_matrix()");
444 for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
449 float ***f3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
452 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
456 t=(
float ***) calloc((
size_t)(nrow+NR_END),
sizeof(
float**));
457 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
462 t[nrl]=(
float **) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
float*));
463 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
468 t[nrl][ncl]=(
float *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
470 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
471 t[nrl][ncl] += NR_END;
474 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
475 for(i=nrl+1;i<=nrh;i++) {
477 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
478 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
485 double ***d3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
488 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
492 t=(
double ***) calloc((
size_t)(nrow+NR_END),
sizeof(
double**));
493 if (!t) nrerror(
"allocation failure 1 in d3tensor()");
498 t[nrl]=(
double **) calloc((
size_t)(nrow*ncol+NR_END),
sizeof(
double*));
499 if (!t[nrl]) nrerror(
"allocation failure 2 in d3tensor()");
504 t[nrl][ncl]=(
double *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
506 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in d3tensor()");
507 t[nrl][ncl] += NR_END;
510 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
511 for(i=nrl+1;i<=nrh;i++) {
513 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
514 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
521 frame_data ***fd3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
524 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
528 t=(frame_data ***) calloc((
size_t)(nrow+NR_END),
sizeof(frame_data**));
529 if (!t) nrerror(
"allocation failure 1 in fd3tensor()");
534 t[nrl]=(frame_data **) calloc((
size_t)(nrow*ncol+NR_END),
535 sizeof(frame_data*));
536 if (!t[nrl]) nrerror(
"allocation failure 2 in fd3tensor()");
541 t[nrl][ncl]=(frame_data *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
543 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in fd3tensor()");
544 t[nrl][ncl] += NR_END;
547 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
548 for(i=nrl+1;i<=nrh;i++) {
550 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
551 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
558 frame_mask ***fm3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
561 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
565 t=(frame_mask ***) calloc((
size_t)(nrow+NR_END),
sizeof(frame_mask**));
566 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
571 t[nrl]=(frame_mask **) calloc((
size_t)(nrow*ncol+NR_END),
572 sizeof(frame_mask*));
573 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
578 t[nrl][ncl]=(frame_mask *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
580 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
581 t[nrl][ncl] += NR_END;
584 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
585 for(i=nrl+1;i<=nrh;i++) {
587 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
588 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
595 uint32_t ***ul3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
598 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
602 t=(uint32_t ***) calloc((
size_t)(nrow+NR_END),
604 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
609 t[nrl]=(uint32_t **) calloc((
size_t)(nrow*ncol+NR_END),
611 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
617 (uint32_t *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
619 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
620 t[nrl][ncl] += NR_END;
623 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
624 for(i=nrl+1;i<=nrh;i++) {
626 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
627 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
634 int32_t ***l3tensor(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
637 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
641 t=(int32_t ***) calloc((
size_t)(nrow+NR_END),
sizeof(int32_t**));
642 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
647 t[nrl]=(int32_t **) calloc((
size_t)(nrow*ncol+NR_END),
649 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
654 t[nrl][ncl]=(int32_t *) calloc((
size_t)(nrow*ncol*ndep+NR_END),
656 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
657 t[nrl][ncl] += NR_END;
660 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
661 for(i=nrl+1;i<=nrh;i++) {
663 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
664 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
671 int32_t ****l4tensor(int32_t nal, int32_t nah, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
674 int32_t i,j,k,na=nah-nal+1,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
678 t=(int32_t ****) calloc((
size_t)(na+NR_END),
sizeof(int32_t***));
679 if (!t) nrerror(
"allocation failure 1 in l4tensor()");
684 t[nal]=(int32_t ***) calloc((
size_t)(na*nrow+NR_END),
686 if (!t[nal]) nrerror(
"allocation failure 2 in f3tensor()");
691 t[nal][nrl]=(int32_t **) calloc((
size_t)(na*nrow*ncol+NR_END),
693 if (!t[nal][nrl]) nrerror(
"allocation failure 3 in f3tensor()");
694 t[nal][nrl] += NR_END;
699 (int32_t *) calloc((
size_t)(na*nrow*ncol*ndep+NR_END),
701 if (!t[nal][nrl][ncl]) nrerror(
"allocation failure 4 in f3tensor()");
702 t[nal][nrl][ncl] += NR_END;
703 t[nal][nrl][ncl] -= ndl;
705 for(k=ncl+1;k<=nch;k++) t[nal][nrl][k]=t[nal][nrl][k-1]+ndep;
706 for(j=nrl+1;j<=nrh;j++) {
707 t[nal][j] = t[nal][j-1]+ncol;
708 t[nal][j][ncl] = t[nal][j-1][ncl]+ncol*ndep;
709 for(k=ncl+1;k<=nch;k++) t[nal][j][k]=t[nal][j][k-1]+ndep;
711 for(i=nal+1;i<=nah;i++) {
713 t[i][nrl] = t[i-1][nrl]+nrow*ncol;
714 t[i][nrl][ncl] = t[i-1][nrl][ncl]+nrow*ncol*ndep;
715 for(k=ncl+1;k<=nch;k++) t[i][nrl][k]=t[i][nrl][k-1]+ndep;
716 for(j=nrl+1;j<=nrh;j++) {
717 t[i][j] = t[i][j-1]+ncol;
718 t[i][j][ncl] = t[i][j-1][ncl]+ncol*ndep;
719 for(k=ncl+1;k<=nch;k++) t[i][j][k]=t[i][j][k-1]+ndep;
727 void free_vector(
float *v, int32_t nl, int32_t nh)
732 free((FREE_ARG) (v+nl-NR_END));
735 void free_ivector(
int *v, int32_t nl, int32_t nh)
740 free((FREE_ARG) (v+nl-NR_END));
743 void free_uivector(
unsigned int *v, int32_t nl, int32_t nh)
748 free((FREE_ARG) (v+nl-NR_END));
751 void free_cvector(
char *v, int32_t nl, int32_t nh)
756 free((FREE_ARG) (v+nl-NR_END));
759 void free_ucvector(
unsigned char *v, int32_t nl, int32_t nh)
764 free((FREE_ARG) (v+nl-NR_END));
767 void free_lvector(int32_t *v, int32_t nl, int32_t nh)
772 free((FREE_ARG) (v+nl-NR_END));
775 void free_ulvector(uint32_t *v, int32_t nl, int32_t nh)
780 free((FREE_ARG) (v+nl-NR_END));
783 void free_dvector(
double *v, int32_t nl, int32_t nh)
788 free((FREE_ARG) (v+nl-NR_END));
791 void free_fdvector(frame_data *v, int32_t nl, int32_t nh)
796 free((FREE_ARG) (v+nl-NR_END));
799 void free_fmvector(frame_mask *v, int32_t nl, int32_t nh)
804 free((FREE_ARG) (v+nl-NR_END));
807 void free_matrix(
float **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
814 free((FREE_ARG) (m[nrl]+ncl-NR_END));
815 free((FREE_ARG) (m+nrl-NR_END));
818 void free_cmatrix(
char **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
825 free((FREE_ARG) (m[nrl]+ncl-NR_END));
826 free((FREE_ARG) (m+nrl-NR_END));
829 void free_dmatrix(
double **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
836 free((FREE_ARG) (m[nrl]+ncl-NR_END));
837 free((FREE_ARG) (m+nrl-NR_END));
840 void free_imatrix(
int **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
847 free((FREE_ARG) (m[nrl]+ncl-NR_END));
848 free((FREE_ARG) (m+nrl-NR_END));
851 void free_ulmatrix(uint32_t **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
858 free((FREE_ARG) (m[nrl]+ncl-NR_END));
859 free((FREE_ARG) (m+nrl-NR_END));
862 void free_lmatrix(int32_t **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
869 free((FREE_ARG) (m[nrl]+ncl-NR_END));
870 free((FREE_ARG) (m+nrl-NR_END));
873 void free_fdmatrix(frame_data **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
880 free((FREE_ARG) (m[nrl]+ncl-NR_END));
881 free((FREE_ARG) (m+nrl-NR_END));
884 void free_fmmatrix(frame_mask **m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
891 free((FREE_ARG) (m[nrl]+ncl-NR_END));
892 free((FREE_ARG) (m+nrl-NR_END));
895 void free_submatrix(
float **b, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
905 free((FREE_ARG) (b+nrl-NR_END));
908 void free_convert_matrix(
float **b, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)
917 free((FREE_ARG) (b+nrl-NR_END));
920 void free_f3tensor(
float ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
921 int32_t ndl, int32_t ndh)
931 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
932 free((FREE_ARG) (t[nrl]+ncl-NR_END));
933 free((FREE_ARG) (t+nrl-NR_END));
936 void free_d3tensor(
double ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
937 int32_t ndl, int32_t ndh)
947 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
948 free((FREE_ARG) (t[nrl]+ncl-NR_END));
949 free((FREE_ARG) (t+nrl-NR_END));
952 void free_fd3tensor(frame_data ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
953 int32_t ndl, int32_t ndh)
962 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
963 free((FREE_ARG) (t[nrl]+ncl-NR_END));
964 free((FREE_ARG) (t+nrl-NR_END));
967 void free_fm3tensor(frame_mask ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
968 int32_t ndl, int32_t ndh)
977 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
978 free((FREE_ARG) (t[nrl]+ncl-NR_END));
979 free((FREE_ARG) (t+nrl-NR_END));
982 void free_ul3tensor(uint32_t ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
983 int32_t ndl, int32_t ndh)
993 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
994 free((FREE_ARG) (t[nrl]+ncl-NR_END));
995 free((FREE_ARG) (t+nrl-NR_END));
998 void free_l3tensor(int32_t ***t, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch,
999 int32_t ndl, int32_t ndh)
1008 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
1009 free((FREE_ARG) (t[nrl]+ncl-NR_END));
1010 free((FREE_ARG) (t+nrl-NR_END));
1013 void free_l4tensor(int32_t ****t, int32_t nal, int32_t nah, int32_t nrl, int32_t nrh,
1014 int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh)
1026 free((FREE_ARG) (t[nal][nrl][ncl]+ndl-NR_END));
1027 free((FREE_ARG) (t[nal][nrl]+ncl-NR_END));
1028 free((FREE_ARG) (t[nal]+nrl-NR_END));
1029 free((FREE_ARG) (t+nal-NR_END));
1032 void matrix_product(
double **A,
double **B,
double **C,
int ra,
int ca,
int cb)
1038 C=dmatrix(1,ra,1,cb);
1041 SCTPUT(
"Error in matrix product");
1044 for (j=1; j<=ra; j++)
1046 for (k=1; k<=cb; k++)
1052 for (j=1; j<=ra; j++)
1054 for (k=1; k<=cb; k++)
1056 for (m=1; m<=ca; m++)
1058 C[j][k] += A[j][m]*B[m][k];
1064 void matrix_sum(
double **A,
double **B,
int ra,
int ca)
1070 for (j=1; j<=ra; j++)
1072 for (k=1; k<=ca; k++)
1086 #include <flames_uves.h>
1088 #define FREE_ARG char*
1090 void nrerror(error_text)
1104 SCTPUT(
"Numerical Recipes run-time error...\n");
1105 sprintf(output,
"%s\n", error_text);
1107 SCTPUT(
"...now exiting to system...\n");
1109 return flames_midas_fail();
1112 float *vector(nl,nh)
1118 v=(
float *) calloc((
unsigned int) (nh-nl+1+NR_END),
sizeof(
float));
1119 if (!v) nrerror(
"allocation failure in vector()");
1129 v=(
int *) calloc((
unsigned int) (nh-nl+1+NR_END),
sizeof(
int));
1130 if (!v) nrerror(
"allocation failure in ivector()");
1134 unsigned int *uivector(nl,nh)
1140 v=(
unsigned int *) calloc((
unsigned int) (nh-nl+1+NR_END),
1141 sizeof(
unsigned int));
1142 if (!v) nrerror(
"allocation failure in uivector()");
1146 char *cvector(nl,nh)
1152 v=(
char *) calloc((
unsigned int) (nh-nl+1+NR_END),
sizeof(
char));
1153 if (!v) nrerror(
"allocation failure in cvector()");
1157 char *ucvector(nl,nh)
1163 v=(
unsigned char *) calloc((
unsigned int) (nh-nl+1+NR_END),
1164 sizeof(
unsigned char));
1165 if (!v) nrerror(
"allocation failure in ucvector()");
1169 int32_t *lvector(nl,nh)
1175 v=(int32_t *) calloc((
unsigned int) (nh-nl+1+NR_END),
1177 if (!v) nrerror(
"allocation failure in lvector()");
1181 uint32_t *ulvector(nl,nh)
1187 v=(uint32_t*) calloc((
unsigned int) (nh-nl+1+NR_END),
1189 if (!v) nrerror(
"allocation failure in ulvector()");
1193 double *dvector(nl,nh)
1199 v=(
double *) calloc((
unsigned int) (nh-nl+1+NR_END),
sizeof(
double));
1200 if (!v) nrerror(
"allocation failure in dvector()");
1204 double *fdvector(nl,nh)
1210 v=(frame_data *) calloc((
unsigned int) (nh-nl+1+NR_END),
1211 sizeof(frame_data));
1212 if (!v) nrerror(
"allocation failure in dvector()");
1216 double *fmvector(nl,nh)
1222 v=(frame_mask *) calloc((
unsigned int) (nh-nl+1+NR_END),
1223 sizeof(frame_mask));
1224 if (!v) nrerror(
"allocation failure in dvector()");
1228 float **matrix(nrl,nrh,ncl,nch)
1229 int32_t nch,ncl,nrh,nrl;
1232 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1236 m=(
float **) calloc((
unsigned int)(nrow+NR_END),
sizeof(
float*));
1237 if (!m) nrerror(
"allocation failure 1 in matrix()");
1242 m[nrl]=(
float *) calloc((
unsigned int)(nrow*ncol+NR_END),
1244 if (!m[nrl]) nrerror(
"allocation failure 2 in matrix()");
1248 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1254 char **cmatrix(nrl,nrh,ncl,nch)
1255 int32_t nch,ncl,nrh,nrl;
1258 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1262 m=(
char **) calloc((
unsigned int)(nrow+NR_END),
sizeof(
char*));
1263 if (!m) nrerror(
"allocation failure 1 in cmatrix()");
1268 m[nrl]=(
char *) calloc((
unsigned int)(nrow*ncol+NR_END),
1270 if (!m[nrl]) nrerror(
"allocation failure 2 in cmatrix()");
1274 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1280 double **dmatrix(nrl,nrh,ncl,nch)
1281 int32_t nch,ncl,nrh,nrl;
1284 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1288 m=(
double **) calloc((
unsigned int)(nrow+NR_END),
sizeof(
double*));
1289 if (!m) nrerror(
"allocation failure 1 in dmatrix()");
1294 m[nrl]=(
double *) calloc((
unsigned int)(nrow*ncol+NR_END),
1296 if (!m[nrl]) nrerror(
"allocation failure 2 in dmatrix()");
1300 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1306 int **imatrix(nrl,nrh,ncl,nch)
1307 int32_t nch,ncl,nrh,nrl;
1310 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1314 m=(
int **) calloc((
unsigned int)(nrow+NR_END),
sizeof(
int*));
1315 if (!m) nrerror(
"allocation failure 1 in imatrix()");
1321 m[nrl]=(
int *) calloc((
unsigned int)(nrow*ncol+NR_END),
sizeof(
int));
1322 if (!m[nrl]) nrerror(
"allocation failure 2 in imatrix()");
1326 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1332 uint32_t **ulmatrix(nrl,nrh,ncl,nch)
1333 int32_t nch,ncl,nrh,nrl;
1336 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1340 m=(uint32_t **) calloc((
unsigned int)(nrow+NR_END),
1342 if (!m) nrerror(
"allocation failure 1 in ulmatrix()");
1348 m[nrl]=(uint32_t *) calloc((
unsigned int)(nrow*ncol+NR_END),
1350 if (!m[nrl]) nrerror(
"allocation failure 2 in ulmatrix()");
1354 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1360 int32_t **lmatrix(nrl,nrh,ncl,nch)
1361 int32_t nch,ncl,nrh,nrl;
1364 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1368 m=(int32_t **) calloc((
unsigned int)(nrow+NR_END),
sizeof(int32_t*));
1369 if (!m) nrerror(
"allocation failure 1 in lmatrix()");
1375 m[nrl]=(int32_t *) calloc((
unsigned int)(nrow*ncol+NR_END),
1377 if (!m[nrl]) nrerror(
"allocation failure 2 in lmatrix()");
1381 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1387 frame_data **fdmatrix(nrl,nrh,ncl,nch)
1388 int32_t nch,ncl,nrh,nrl;
1391 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1395 m=(frame_data **) calloc((
unsigned int)(nrow+NR_END),
1396 sizeof(frame_data*));
1397 if (!m) nrerror(
"allocation failure 1 in fdmatrix()");
1403 m[nrl]=(frame_data *) calloc((
unsigned int)(nrow*ncol+NR_END),
1404 sizeof(frame_data));
1405 if (!m[nrl]) nrerror(
"allocation failure 2 in fdmatrix()");
1409 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1415 frame_mask **fmmatrix(nrl,nrh,ncl,nch)
1416 int32_t nch,ncl,nrh,nrl;
1419 int32_t i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
1423 m=(frame_mask **) calloc((
unsigned int)(nrow+NR_END),
1424 sizeof(frame_mask*));
1425 if (!m) nrerror(
"allocation failure 1 in fmmatrix()");
1431 m[nrl]=(frame_mask *) calloc((
unsigned int)(nrow*ncol+NR_END),
1432 sizeof(frame_mask));
1433 if (!m[nrl]) nrerror(
"allocation failure 2 in fmmatrix()");
1437 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
1443 float **submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl)
1445 int32_t newcl,newrl,oldch,oldcl,oldrh,oldrl;
1448 int32_t i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
1452 m=(
float **) calloc((
unsigned int) (nrow+NR_END),
sizeof(
float*));
1453 if (!m) nrerror(
"allocation failure in submatrix()");
1458 for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
1464 float **convert_matrix(a,nrl,nrh,ncl,nch)
1466 int32_t nch,ncl,nrh,nrl;
1472 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
1476 m=(
float **) calloc((
unsigned int) (nrow+NR_END),
sizeof(
float*));
1477 if (!m) nrerror(
"allocation failure in convert_matrix()");
1483 for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
1488 float ***f3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1489 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1492 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1496 t=(
float ***) calloc((
unsigned int)(nrow+NR_END),
sizeof(
float**));
1497 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
1502 t[nrl]=(
float **) calloc((
unsigned int)(nrow*ncol+NR_END),
1504 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
1509 t[nrl][ncl]=(
float *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1511 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
1512 t[nrl][ncl] += NR_END;
1515 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1516 for(i=nrl+1;i<=nrh;i++) {
1518 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1519 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1526 frame_data ***fd3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1527 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1530 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1534 t=(frame_data ***) calloc((
unsigned int)(nrow+NR_END),
1535 sizeof(frame_data**));
1536 if (!t) nrerror(
"allocation failure 1 in fd3tensor()");
1541 t[nrl]=(frame_data **) calloc((
unsigned int)(nrow*ncol+NR_END),
1542 sizeof(frame_data*));
1543 if (!t[nrl]) nrerror(
"allocation failure 2 in fd3tensor()");
1549 (frame_data *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1550 sizeof(frame_data));
1551 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in fd3tensor()");
1552 t[nrl][ncl] += NR_END;
1555 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1556 for(i=nrl+1;i<=nrh;i++) {
1558 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1559 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1566 double ***d3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1567 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1570 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1574 t=(
double ***) calloc((
unsigned int)(nrow+NR_END),
sizeof(
double**));
1575 if (!t) nrerror(
"allocation failure 1 in d3tensor()");
1580 t[nrl]=(
double **) calloc((
unsigned int)(nrow*ncol+NR_END),
1582 if (!t[nrl]) nrerror(
"allocation failure 2 in d3tensor()");
1587 t[nrl][ncl]=(
double *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1589 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in d3tensor()");
1590 t[nrl][ncl] += NR_END;
1593 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1594 for(i=nrl+1;i<=nrh;i++) {
1596 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1597 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1604 frame_data ***fd3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1605 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1608 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1612 t=(frame_data ***) calloc((
unsigned int)(nrow+NR_END),
1613 sizeof(frame_data**));
1614 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
1619 t[nrl]=(frame_data **) calloc((
unsigned int)(nrow*ncol+NR_END),
1620 sizeof(frame_data*));
1621 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
1627 (frame_data *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1628 sizeof(frame_data));
1629 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
1630 t[nrl][ncl] += NR_END;
1633 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1634 for(i=nrl+1;i<=nrh;i++) {
1636 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1637 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1644 frame_mask ***fm3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1645 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1648 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1652 t=(frame_mask ***) calloc((
unsigned int)(nrow+NR_END),
1653 sizeof(frame_mask**));
1654 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
1659 t[nrl]=(frame_mask **) calloc((
unsigned int)(nrow*ncol+NR_END),
1660 sizeof(frame_mask*));
1661 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
1667 (frame_mask *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1668 sizeof(frame_mask));
1669 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
1670 t[nrl][ncl] += NR_END;
1673 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1674 for(i=nrl+1;i<=nrh;i++) {
1676 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1677 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1684 uint32_t ***ul3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1685 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1688 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1692 t=(uint32_t ***) calloc((
unsigned int)(nrow+NR_END),
1693 sizeof(uint32_t**));
1694 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
1699 t[nrl]=(uint32_t **) calloc((
unsigned int)(nrow*ncol+NR_END),
1701 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
1707 (uint32_t *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1709 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
1710 t[nrl][ncl] += NR_END;
1713 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1714 for(i=nrl+1;i<=nrh;i++) {
1716 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1717 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1724 int32_t ***l3tensor(nrl,nrh,ncl,nch,ndl,ndh)
1725 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1728 int32_t i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1732 t=(int32_t ***) calloc((
unsigned int)(nrow+NR_END),
1734 if (!t) nrerror(
"allocation failure 1 in f3tensor()");
1739 t[nrl]=(int32_t **) calloc((
unsigned int)(nrow*ncol+NR_END),
1741 if (!t[nrl]) nrerror(
"allocation failure 2 in f3tensor()");
1746 t[nrl][ncl]=(int32_t *) calloc((
unsigned int)(nrow*ncol*ndep+NR_END),
1748 if (!t[nrl][ncl]) nrerror(
"allocation failure 3 in f3tensor()");
1749 t[nrl][ncl] += NR_END;
1752 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
1753 for(i=nrl+1;i<=nrh;i++) {
1755 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
1756 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
1763 int32_t ***l4tensor(nal,nah,nrl,nrh,ncl,nch,ndl,ndh)
1764 int32_t nch,ncl,ndh,ndl,nrh,nrl,nah,nal;
1768 int32_t i,j,k,na=nah-nal+1,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
1772 t=(int32_t ****) calloc((
unsigned int)(na+NR_END),
1773 sizeof(int32_t***));
1774 if (!t) nrerror(
"allocation failure 1 in l4tensor()");
1779 t[nal]=(int32_t ***) calloc((
unsigned int)(na*nrow+NR_END),
1781 if (!t[nrl]) nrerror(
"allocation failure 2 in l4tensor()");
1786 t[nal][nrl]=(int32_t **) calloc((
unsigned int)(na*nrow*ncol+NR_END),
1788 if (!t[nal][nrl]) nrerror(
"allocation failure 3 in l4tensor()");
1789 t[nal][nrl] += NR_END;
1794 (int32_t *) calloc((
unsigned int)(na*nrow*ncol*ndep+NR_END),
1796 if (!t[nal][nrl][ncl]) nrerror(
"allocation failure 4 in l4tensor()");
1797 t[nal][nrl][ncl] += NR_END;
1798 t[nal][nrl][ncl] -= ndl;
1800 for(k=ncl+1;k<=nch;k++) t[nal][nrl][k]=t[nal][nrl][k-1]+ndep;
1801 for(j=nrl+1;j<=nrh;j++) {
1802 t[nal][j] = t[nal][j-1]+ncol;
1803 t[nal][j][ncl] = t[nal][j-1][ncl]+ncol*ndep;
1804 for(k=ncl+1;k<=nch;k++) t[nal][j][k]=t[nal][j][k-1]+ndep;
1806 for(i=nal+1;i<=nah;i++) {
1808 t[i][nrl] = t[i-1][nrl]+nrow*ncol;
1809 t[i][nrl][ncl] = t[i-1][nrl][ncl]+nrow*ncol*ndep;
1810 for(k=ncl+1;k<=nch;k++) t[i][nrl][k]=t[i][nrl][k-1]+ndep;
1811 for(j=nrl+1;j<=nrh;j++) {
1812 t[i][j] = t[i][j-1]+ncol;
1813 t[i][j][ncl] = t[i][j-1][ncl]+ncol*ndep;
1814 for(k=ncl+1;k<=nch;k++) t[i][j][k]=t[i][j][k-1]+ndep;
1822 void free_vector(v,nl,nh)
1827 free((FREE_ARG) (v+nl-NR_END));
1830 void free_ivector(v,nl,nh)
1835 free((FREE_ARG) (v+nl-NR_END));
1838 void free_uivector(v,nl,nh)
1843 free((FREE_ARG) (v+nl-NR_END));
1846 void free_cvector(v,nl,nh)
1851 free((FREE_ARG) (v+nl-NR_END));
1854 void free_ucvector(v,nl,nh)
1859 free((FREE_ARG) (v+nl-NR_END));
1862 void free_lvector(v,nl,nh)
1867 free((FREE_ARG) (v+nl-NR_END));
1870 void free_ulvector(v,nl,nh)
1875 free((FREE_ARG) (v+nl-NR_END));
1878 void free_dvector(v,nl,nh)
1883 free((FREE_ARG) (v+nl-NR_END));
1886 void free_fdvector(v,nl,nh)
1891 free((FREE_ARG) (v+nl-NR_END));
1894 void free_fmvector(v,nl,nh)
1899 free((FREE_ARG) (v+nl-NR_END));
1902 void free_matrix(m,nrl,nrh,ncl,nch)
1904 int32_t nch,ncl,nrh,nrl;
1907 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1908 free((FREE_ARG) (m+nrl-NR_END));
1911 void free_cmatrix(m,nrl,nrh,ncl,nch)
1913 int32_t nch,ncl,nrh,nrl;
1916 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1917 free((FREE_ARG) (m+nrl-NR_END));
1920 void free_dmatrix(m,nrl,nrh,ncl,nch)
1922 int32_t nch,ncl,nrh,nrl;
1925 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1926 free((FREE_ARG) (m+nrl-NR_END));
1929 void free_ulmatrix(m,nrl,nrh,ncl,nch)
1931 int32_t nch,ncl,nrh,nrl;
1934 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1935 free((FREE_ARG) (m+nrl-NR_END));
1938 void free_lmatrix(m,nrl,nrh,ncl,nch)
1940 int32_t nch,ncl,nrh,nrl;
1943 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1944 free((FREE_ARG) (m+nrl-NR_END));
1947 void free_imatrix(m,nrl,nrh,ncl,nch)
1949 int32_t nch,ncl,nrh,nrl;
1952 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1953 free((FREE_ARG) (m+nrl-NR_END));
1956 void free_fdmatrix(m,nrl,nrh,ncl,nch)
1958 int32_t nch,ncl,nrh,nrl;
1961 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1962 free((FREE_ARG) (m+nrl-NR_END));
1965 void free_fmmatrix(m,nrl,nrh,ncl,nch)
1967 int32_t nch,ncl,nrh,nrl;
1970 free((FREE_ARG) (m[nrl]+ncl-NR_END));
1971 free((FREE_ARG) (m+nrl-NR_END));
1974 void free_submatrix(b,nrl,nrh,ncl,nch)
1976 int32_t nch,ncl,nrh,nrl;
1979 free((FREE_ARG) (b+nrl-NR_END));
1982 void free_convert_matrix(b,nrl,nrh,ncl,nch)
1984 int32_t nch,ncl,nrh,nrl;
1987 free((FREE_ARG) (b+nrl-NR_END));
1990 void free_f3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
1992 int32_t nch,ncl,ndh,ndl,nrh,nrl;
1995 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
1996 free((FREE_ARG) (t[nrl]+ncl-NR_END));
1997 free((FREE_ARG) (t+nrl-NR_END));
2000 void free_d3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
2002 int32_t nch,ncl,ndh,ndl,nrh,nrl;
2005 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
2006 free((FREE_ARG) (t[nrl]+ncl-NR_END));
2007 free((FREE_ARG) (t+nrl-NR_END));
2010 void free_fd3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
2012 int32_t nch,ncl,ndh,ndl,nrh,nrl;
2015 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
2016 free((FREE_ARG) (t[nrl]+ncl-NR_END));
2017 free((FREE_ARG) (t+nrl-NR_END));
2020 void free_fm3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
2022 int32_t nch,ncl,ndh,ndl,nrh,nrl;
2025 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
2026 free((FREE_ARG) (t[nrl]+ncl-NR_END));
2027 free((FREE_ARG) (t+nrl-NR_END));
2030 void free_ul3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
2032 int32_t nch,ncl,ndh,ndl,nrh,nrl;
2035 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
2036 free((FREE_ARG) (t[nrl]+ncl-NR_END));
2037 free((FREE_ARG) (t+nrl-NR_END));
2040 void free_l3tensor(t,nrl,nrh,ncl,nch,ndl,ndh)
2042 int32_t nch,ncl,ndh,ndl,nrh,nrl;
2045 free((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
2046 free((FREE_ARG) (t[nrl]+ncl-NR_END));
2047 free((FREE_ARG) (t+nrl-NR_END));
2050 void free_l4tensor(t,nal,nah,nrl,nrh,ncl,nch,ndl,ndh)
2052 int32_t nch,ncl,ndh,ndl,nrh,nrl,nah,nal;
2055 free((FREE_ARG) (t[nal][nrl][ncl]+ndl-NR_END));
2056 free((FREE_ARG) (t[nal][nrl]+ncl-NR_END));
2057 free((FREE_ARG) (t[nal]+nrl-NR_END));
2058 free((FREE_ARG) (t+nal-NR_END));
2063 matrix_product(
double** A,
double** B,
double** C,
int ra,
int ca,
int cb)
2070 C=dmatrix(1,ra,1,cb);
2073 for (j=1; j<=ra; j++)
2075 for (k=1; k<=cb; k++)
2081 for (j=1; j<=ra; j++)
2083 for (k=1; k<=cb; k++)
2085 for (m=1; m<=ca; m++)
2087 C[j][k] += A[j][m]*B[m][k];
2095 matrix_sum(
double** A,
double** B,
int ra,
int ca)
2100 for (j=1; j<=ra; j++)
2102 for (k=1; k<=ca; k++)