TheBoussinesqModel  3.2.1
 All Data Structures Files Functions Variables Typedefs Macros Pages
additional_read_functions.c
Go to the documentation of this file.
1 
2 /* KeyPalette MANAGES THE I/O FILES OF A MODEL
3 KeyPalette Version 0.9375 KMackenzie
4 
5 file additional_read_functions.c
6 
7 Copyright, 2009 Emanuele Cordano and Riccardo Rigon
8 
9 This file is part of KeyPalette.
10  KeyPalette is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  KeyPalette is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 
25 
26 #include <stdio.h>
27 //#include "read_command_line.h"
28 #include "turtle.h"
30 #include <stddef.h>
31 #include <string.h>
32 
33 
34 
35 DOUBLEVECTOR *read_doublearray_from_string(char *argument,char *delimiters,int max_numbers,short print){
36  /*
37  *
38  * \author Emanuele Cordano
39  * \date September 2008
40  *
41  *\param (char *) - argument string from which read the values
42  *\param (char *) - delimiters charcters between two values
43  *\param (char *) - maximum numbers of vales which can be read
44  *
45  *\returns (DOUBLEVECTOR *) - a vector containing the read values (double)
46  *
47  */
48  int s,l,i;
49  DOUBLEVECTOR *vect;
50  DOUBLEVECTOR *vect1;
51  double value;
52  char *cp,*token;
53 
54  vect1=new_doublevector(max_numbers);
55  l=0;
56  value=-999.0;
57  // printf("\n cc\n ");
58  cp=strdup(argument);
59  token=strtok(cp,delimiters);
60  do{
61  l++;
62  value=-999.0;
63 
64  /* see http://www.gnu.org/software/libtool/manual/libc/Finding-Tokens-in-a-String.html
65  * */
66  s=0;
67  s=sscanf(token,"%lf",&value);
68  if (s==1) {
69  vect1->element[l]=value;
70  } else if (s==0 && print==1) {
71  printf("\nWARNING: No real value found for %s option, no value is set at location %d ",token,l);
72  }
73  token=strtok(NULL,delimiters);
74  } while ((s==1) && (l<=max_numbers) );
75 
76  l=l-1;
77  vect=new_doublevector(l);
78 
79  for(i=vect->nl;i<=vect->nh;i++){
80 
81  vect->element[i]=vect1->element[i];
82  }
83 
84  free_doublevector(vect1);
85 
86  return vect;
87 
88 }
89 
90 /* */
91 
92 
93 LONGVECTOR *read_longarray_from_string(char *argument,char *delimiters,int max_numbers,short print){
94  /*
95  *
96  * \author Emanuele Cordano
97  * \date November 2008
98  *
99  *\param (char *) - argument string from which read the values
100  *\param (char *) - delimiters charcters between two values
101  *\param (char *) - maximum numbers of vales which can be read
102  *
103  *\returns (LONGVECTOR *) - a vector containing the long integer values (long)
104  *
105  */
106  int s,l,i;
107  LONGVECTOR *vect;
108  LONGVECTOR *vect1;
109  long value;
110  char *cp,*token;
111 
112  vect1=new_longvector(max_numbers);
113  l=0;
114  value=-999;
115 
116  cp=strdup(argument);
117  token=strtok(cp,delimiters);
118  do{
119  l++;
120  value=-999;
121 
122  /* see http://www.gnu.org/software/libtool/manual/libc/Finding-Tokens-in-a-String.html
123  * */
124  s=0;
125  s=sscanf(token,"%ld",&value);
126  if (s==1) {
127  vect1->element[l]=value;
128  } else if (s==0 && print==1) {
129  printf("\nWARNING: No integer value found for %s option, no value is set at location %d ",token,l);
130  }
131  token=strtok(NULL,delimiters);
132  } while ((s==1) && (l<=max_numbers) );
133 
134  l=l-1;
135  vect=new_longvector(l);
136 
137  for(i=vect->nl;i<=vect->nh;i++){
138 
139  vect->element[i]=vect1->element[i];
140  }
141 
142  free_longvector(vect1);
143 
144  return vect;
145 
146 }
147