Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

cfit.c

Go to the documentation of this file.
00001 
00002 /*
00003  * Copyright (c) 1986,1987,1988,1989,1990,1991,1992,1993,
00004  * by Steve McMillan, Drexel University, Philadelphia, PA.
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms are permitted
00009  * provided that the above copyright notice and this paragraph are
00010  * duplicated in all such forms and that any documentation,
00011  * advertising materials, and other materials related to such
00012  * distribution and use acknowledge that the software was developed
00013  * by the author named above.
00014  *
00015  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00017  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00018  */
00019 
00020 /*
00021         CFIT: Intermediate storage allocation routine for SVD fitting.
00022 */
00023 
00024 #define NULL (void*)0
00025 
00026 void cfit(x, y, z, n, a, m, poly, nw, chisq, status)
00027 float *x, *y, *z, *a, *chisq;
00028 int *n, *m, *nw, *status;
00029 void (*poly)();
00030 {
00031     float *sig, *u, *v, *w, *b;
00032     int i, usize;
00033 
00034     /* First dimension of U must actually be MAX(m, n) */
00035 
00036     usize = (*n > *m ? *n : *m);
00037 
00038     if ( (sig = (float *) malloc((*n)*sizeof(float))) == NULL) {
00039         printf("Can't allocate workspace for SIG...\n");
00040         *status = 1;
00041         return;
00042     }
00043 
00044     if ( (u = (float *) malloc(usize*(*m)*sizeof(float))) == NULL) {
00045         printf("Can't allocate workspace for U...\n");
00046         *status = 1;
00047         return;
00048     }
00049 
00050     if ( (v = (float *) malloc((*m)*(*m)*sizeof(float))) == NULL) {
00051         printf("Can't allocate workspace for V...\n");
00052         *status = 1;
00053         return;
00054     }
00055 
00056     if ( (w = (float *) malloc((*m)*sizeof(float))) == NULL) {
00057         printf("Can't allocate workspace for W...\n");
00058         *status = 1;
00059         return;
00060     }
00061 
00062     if ( (b = (float *) malloc(usize*sizeof(float))) == NULL) {
00063         printf("Can't allocate workspace for B...\n");
00064         *status = 1;
00065         return;
00066     }
00067 
00068     /* Set up weighting for NR routine. */
00069 
00070     if ( *nw <= 1)
00071         for (i = 0; i < *n; i++) sig[i] = 1.0;
00072     else
00073         for (i = 0; i < *n; i++) sig[i] = 1.0/z[i];
00074 
00075     /* Call the FORTRAN routine */
00076 
00077 #ifdef FORTRAN_TRAILING_UNDERSCORE
00078     svdfit_(x, y, sig, n, a, m, u, v, w, b, &usize, m, chisq, poly);
00079 #else
00080     svdfit(x, y, sig, n, a, m, u, v, w, b, &usize, m, chisq, poly);
00081 #endif
00082 
00083     free(sig);
00084     free(u);
00085     free(v);
00086     free(w);
00087 
00088     *status = 0;
00089 }
00090 
00091 void cfit_(x, y, z, n, a, m, poly, nw, chisq, status)
00092 float *x, *y, *z, *a, *chisq;
00093 int *n, *m, *nw, *status;
00094 void (*poly)();
00095 {
00096   cfit(x, y, z, n, a, m, poly, nw, chisq, status);
00097 }

Generated at Sun Feb 24 09:56:55 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001