2 * This file is part of TISEAN
4 * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6 * TISEAN is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * TISEAN is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with TISEAN; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /*Author: Rainer Hegger Last modified: Sep 3, 1999 */
21 /*Note: Keep in mind that the first index runs the dimension,
22 the second the time series index */
28 #include "tisean_cec.h"
30 #define SIZE_STEP 1000
31 extern void check_alloc(void*);
33 double **get_multi_series(char *name,unsigned long *l,unsigned long ex,
34 unsigned int *col,char *which,char colfix,
35 unsigned int verbosity)
39 unsigned int *hcol,maxcol=0,colcount=0;
40 unsigned long count,max_size=SIZE_STEP,hl,allcount;
41 int input_size=INPUT_SIZE;
45 if (strlen(which) > 0) {
47 for (i=0;i<strlen(which)-1;i++) {
48 if (!isdigit((unsigned int)which[i]) && (which[i] != ',')) {
49 fprintf(stderr,"Wrong format in the column string."
50 " Has to be num,num,num,...,num\n");
51 exit(GET_MULTI_SERIES_WRONG_TYPE_OF_C);
53 if (which[i] == ',') {
58 if (!isdigit((unsigned int)which[strlen(which)-1])) {
59 fprintf(stderr,"Wrong format in the column string."
60 " Has to be num,num,num,...,num\n");
61 exit(GET_MULTI_SERIES_WRONG_TYPE_OF_C);
64 if (!colfix && (*col < colcount))
67 check_alloc(input=(char*)calloc((size_t)input_size,(size_t)1));
68 check_alloc(hcol=(unsigned int*)malloc(sizeof(unsigned int)* *col));
69 while ((int)(*which) && isspace((unsigned int)(*which)))
72 for (i=0;i< *col-1;i++) {
73 sscanf(which,"%u",&hcol[i]);
76 while ((int)(*which) && !isspace((unsigned int)(*which)))
78 while ((int)(*which) && isspace((unsigned int)(*which)))
87 sscanf(which,"%u",&hcol[i]);
89 for (j=i+1;j< *col;j++)
92 if (verbosity&VER_INPUT) {
93 fprintf(stderr,"Using columns: ");
95 fprintf(stderr,"%d ",hcol[i]);
99 check_alloc(format=(char**)malloc(sizeof(char*)* *col));
100 for (i=0;i< *col;i++) {
101 check_alloc(format[i]=(char*)calloc((size_t)(4*hcol[i]),(size_t)1));
102 strcpy(format[i],"");
103 for (j=1;j<hcol[i];j++)
104 strcat(format[i],"%*lf");
105 strcat(format[i],"%lf");
109 check_alloc(x=(double**)malloc(sizeof(double*)* *col));
110 for (i=0;i< *col;i++)
111 check_alloc(x[i]=(double*)malloc(sizeof(double)*max_size));
118 if ((input=myfgets(input,&input_size,stdin,verbosity)) == NULL)
120 while ((count < hl) &&
121 ((input=myfgets(input,&input_size,stdin,verbosity)) != NULL)) {
122 if (count == max_size) {
123 max_size += SIZE_STEP;
124 for (i=0;i< *col;i++)
125 check_alloc(x[i]=(double*)realloc(x[i],sizeof(double)*max_size));
128 for (i=0;i< *col;i++)
129 if (sscanf(input,format[i],&x[i][count]) != 1) {
130 if (verbosity&VER_INPUT)
131 fprintf(stderr,"Line %lu ignored: %s",allcount,input);
141 if ((input=myfgets(input,&input_size,fin,verbosity)) == NULL)
143 while ((count < hl) &&
144 ((input=myfgets(input,&input_size,fin,verbosity)) != NULL)) {
145 if (count == max_size) {
146 max_size += SIZE_STEP;
147 for (i=0;i< *col;i++)
148 check_alloc(x[i]=(double*)realloc(x[i],sizeof(double)*max_size));
151 for (i=0;i< *col;i++)
152 if (sscanf(input,format[i],&x[i][count]) != 1) {
153 if (verbosity&VER_INPUT)
154 fprintf(stderr,"Line %lu ignored: %s",allcount,input);
157 if ((count == 0) && (i == *col) && (verbosity&VER_FIRST_LINE)) {
158 fprintf(stderr,"get_multi_series: first data item(s) used:\n");
159 for (i=0;i< *col;i++)
160 fprintf(stderr,"%lf ",x[i][0]);
161 fprintf(stderr,"\n");
169 for (i=0;i< *col;i++)
176 fprintf(stderr,"0 lines read. It makes no sense to continue. Exiting!\n");
177 exit(GET_MULTI_SERIES_NO_LINES);
180 if (verbosity&VER_INPUT)
181 fprintf(stderr,"Use %lu lines.\n",*l);
184 if (max_size > count)
185 for (i=0;i< *col;i++)
186 check_alloc(x[i]=(double*)realloc(x[i],sizeof(double)*count));