39 #define FREE_ARG char*
43 static int nfloat=0, nint=0, cumnfloat=0, cumnint=0, locnint, locnfloat;
47 if(locnint > 1000 || locnfloat > 1000)
48 printf(
"Memory used real %d %d %d int %d %d %d\n",
49 nfloat,cumnfloat,locnfloat,nint,cumnint,locnint);
50 locnfloat = locnint = 0;
58 fprintf(stderr,
"run-time error...\n");
59 fprintf(stderr,
"%s\n",error_text);
60 fprintf(stderr,
"...now exiting to system...\n");
71 v = (
float*)malloc((
size_t) (nh-nl+1+1)*
sizeof(
float));
72 if (!v)
nrerror(
"allocation failure in vector()");
83 v=(
int*) malloc((
size_t) (nh-nl+1+1)*
sizeof(
int));
84 if (!v)
nrerror(
"allocation failure in ivector()");
87 locnint = (nh-nl+1+1);
102 v=(
unsigned char *)malloc((
size_t) (nh-nl+1+1)*
sizeof(
unsigned char));
103 if (!v)
nrerror(
"allocation failure in cvector()");
113 v=(
unsigned long *)malloc((
size_t) (nh-nl+1+1)*
sizeof(
unsigned long));
114 if (!v)
nrerror(
"allocation failure in lvector()");
125 v=(
double *)malloc((
size_t) (nh-nl+1+1)*
sizeof(
double));
126 if (!v)
nrerror(
"allocation failure in dvector()");
129 locnfloat = nh-nl+1+1;
131 cumnfloat += locnfloat;
141 float **
matrix(
int nrl,
int nrh,
int ncl,
int nch)
144 int i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
148 m=(
float **) malloc((
size_t) (nrow+1)*
sizeof(
float*));
149 if (!m)
nrerror(
"allocation failure 1 in matrix()");
154 m[nrl]=(
float *) malloc((
size_t)((nrow*ncol+1)*
sizeof(
float)));
155 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
159 for(i=nrl+1;i<=nrh;i++)
166 double **
dmatrix(
int nrl,
int nrh,
int ncl,
int nch)
169 int i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
173 m=(
double **) malloc((
size_t) (nrow+1)*
sizeof(
double*));
174 if (!m)
nrerror(
"allocation failure 1 in dmatrix()");
180 m[nrl]=(
double *) malloc((
size_t)((nrow*ncol+1)*
sizeof(
double)));
181 if (!m[nrl])
nrerror(
"allocation failure 2 in dmatrix()");
185 for(i=nrl+1;i<=nrh;i++)
189 locnfloat = (nrow+1 + (nrow*ncol+1));
191 cumnfloat += locnfloat;
199 int **
imatrix(
int nrl,
int nrh,
int ncl,
int nch)
202 int i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
206 m=(
int **) malloc((
size_t) (nrow+1)*
sizeof(
int*));
207 if (!m)
nrerror(
"allocation failure 1 in imatrix()");
212 m[nrl]=(
int *) malloc((
size_t)((nrow*ncol+1)*
sizeof(
int)));
213 if (!m[nrl])
nrerror(
"allocation failure 2 in imatrix()");
217 for(i=nrl+1;i<=nrh;i++)
221 locnint = (nrow+1 + (nrow*ncol+1));
241 cumnint -= (nh-nl+1+1);
261 cumnfloat -= (nh-nl+1+1);
278 cumnfloat -= (nrow+1 + (nrow*ncol+1));
290 cumnint -= (nrow+1 + (nrow*ncol+1));
300 fprintf(stderr,
"The program encountered a major error...\n");
301 fprintf(stderr,
"%s\n",error_text);
302 fprintf(stderr,
"...now exiting to system...\n");
309 fprintf(stderr,
"The program encountered a minor error...\n");
310 fprintf(stderr,
"%s\n",error_text);
311 fprintf(stderr,
"...we'll try to continue...\n");
321 if((in = fopen(filename,
"r")) == NULL)
337 for(i=first+1;i<=last;i++)
338 if(min>vector[i]) min=vector[i];
351 for(i=first+1;i<=last;i++)
353 min=vector[(mini=i)];
366 for(i=first+1;i<=last;i++)
367 if(max<vector[i]) max=vector[i];
380 for(i=first+1;i<=last;i++)
382 max=vector[(maxi=i)];
399 strcpy(fname2,fname1);
404 ptr1 = strchr(fname2,
'.');
405 if (ptr1) *ptr1 =
'\0';
407 strcat(fname2,newext);
419 int i,cnt,totlen,finish;
420 char *ptr1 = (
char *)buf, *ptr2;
423 totlen = strlen(buf);
427 if (!buf[0])
return 0;
430 ptr2 = strchr(ptr1,separator);
433 args[cnt][i] = ptr1[i];
434 if(ptr1 + i >= ptr2)
break;
441 if(ptr1 + i >= buf+totlen)
break;
442 args[cnt][i] = ptr1[i];
449 }
while (cnt < maxcnt && !finish);
465 char *ptr1 = (
char *)buf, *ptr2;
467 if (!buf[0])
return 0;
469 ptr2 = strchr(ptr1,separator);
470 if (ptr2) ptr2[0] =
'\0';
471 dest[cnt++] = atof(ptr1);
472 if (ptr2) ptr1 = ptr2+1;
473 }
while (cnt < maxcnt && ptr2 != NULL);
482 char *ptr1 = (
char *)buf, *ptr2;
484 if (!buf[0])
return 0;
486 ptr2 = strchr(ptr1,separator);
487 if (ptr2) ptr2[0] =
'\0';
488 dest[cnt++] = atoi(ptr1);
489 if (ptr2) ptr1 = ptr2+1;
490 }
while (cnt < maxcnt && ptr2 != NULL);
501 i = strtol(*start,&end,10);
512 r = strtod(*start,&end);
521 #define SWAPI(a,b) itemp=(a);(a)=(b);(b)=itemp;
527 int i,indxt,
ir,itemp,j,
k,l;
541 for(j=l+1;j<=
ir;j++) {
544 for(i=j-1;i>=1;i--) {
545 if(arr[indx[i]] <= a)
break;
550 if(jstack == 0)
break;
551 ir = istack[jstack--];
552 l = istack[jstack--];
556 SWAPI(indx[k],indx[l+1]);
557 if(arr[indx[l+1]] > arr[indx[ir]]) {
558 SWAPI(indx[l+1],indx[ir]);
560 if(arr[indx[l]] > arr[indx[ir]]) {
561 SWAPI(indx[l],indx[ir]);
563 if(arr[indx[l+1]] > arr[indx[l]]) {
564 SWAPI(indx[l+1],indx[l]);
571 do i++;
while(arr[indx[i]] < a);
572 do j--;
while(arr[indx[j]] > a);
574 SWAPI(indx[i],indx[j]);
579 if(jstack >
NSTACK)
printf(
"NSTACK too small in SortIndex.");
582 istack[jstack-1] = i;
585 istack[jstack] = j-1;
586 istack[jstack-1] = l;