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 */
25 #include "tisean_cec.h"
27 #define SIZE_STEP 1000
28 extern void check_alloc(void*);
30 double *get_series(char *name,unsigned long *l,unsigned long ex,
31 unsigned int col,unsigned int verbosity)
35 unsigned long count,allcount,max_size=SIZE_STEP,hl;
36 int input_size=INPUT_SIZE;
40 check_alloc(input=(char*)calloc((size_t)input_size,(size_t)1));
41 check_alloc(format=(char*)calloc((size_t)(4*col),(size_t)1));
44 strcat(format,"%*lf");
47 check_alloc(x=(double*)malloc(sizeof(double)*max_size));
54 if ((input=myfgets(input,&input_size,stdin,verbosity)) == NULL)
56 while ((count < hl) &&
57 ((input=myfgets(input,&input_size,stdin,verbosity)) != NULL)) {
58 if (count == max_size) {
59 max_size += SIZE_STEP;
60 check_alloc(x=(double*)realloc(x,sizeof(double)*max_size));
63 if (sscanf(input,format,&x[count]) != 1) {
64 if (verbosity&VER_INPUT)
65 fprintf(stderr,"Line %lu ignored: %s",allcount,input);
69 if ((verbosity&VER_FIRST_LINE) && (count == 0))
70 fprintf(stderr,"get_series: first data item used:\n%lf\n",x[0]);
76 if ((input=myfgets(input,&input_size,fin,verbosity)) == NULL)
78 while ((count < hl) &&
79 ((input=myfgets(input,&input_size,fin,verbosity)) != NULL)) {
80 if (count == max_size) {
81 max_size += SIZE_STEP;
82 check_alloc(x=(double*)realloc(x,sizeof(double)*max_size));
85 if (sscanf(input,format,&x[count]) != 1) {
86 if (verbosity&VER_INPUT)
87 fprintf(stderr,"Line %lu ignored: %s",allcount,input);
98 fprintf(stderr,"0 lines read. It makes no sense to continue. Exiting!\n");
99 exit(GET_SERIES_NO_LINES);
102 if (verbosity&VER_INPUT)
103 fprintf(stderr,"Use %lu lines.\n",*l);
105 if (max_size > count)
106 check_alloc(x=(double*)realloc(x,sizeof(double)*count));