00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
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     
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     
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     
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 }