Commit 0b29aafe authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added parameter2intlist to check parameter lists

parent 985da679
......@@ -147,5 +147,7 @@ char *expand_filename(const char *string);
double parameter2double(const char *string);
int parameter2int(const char *string);
int parameter2intlist(const char *string);
#endif /* _CDO_INT_H */
......@@ -19,6 +19,7 @@
#include <string.h>
#include <ctype.h>
#include <float.h>
#include "cdo_int.h"
#include "dmemory.h"
#include "list.h"
......@@ -128,10 +129,9 @@ int get_ival(const char *intstr, int idefault, int istart, int iend, int *ilast)
if ( ! (isdigit(intstr[i]) || intstr[i] == '-') )
{
if ( intstr[i] == '/' )
ival = atoi(intstr+i+1);
ival = parameter2intlist(intstr+i+1);
else
fprintf(stderr, "Syntax error in >%.*s<! Character %c not allowed.\n",
iend, intstr, intstr[i]);
fprintf(stderr, "Syntax error in >%.*s<! Character %c not allowed.\n", iend, intstr, intstr[i]);
break;
}
}
......@@ -148,7 +148,7 @@ void split_intstring(const char *intstr, int *first, int *last, int *inc)
int istrlen;
istrlen = strlen(intstr);
*first = atoi(intstr);
*first = parameter2intlist(intstr);
*last = *first;
*inc = 1;
......@@ -214,7 +214,7 @@ int args2fltlist(int argc, char **argv, LIST *list)
tmp_val = -DBL_MAX;
else
*/
tmp_val = atof(argv[iarg]);
tmp_val = parameter2double(argv[iarg]);
listSetFlt(list, nint++, tmp_val);
}
......
......@@ -389,6 +389,20 @@ int parameter2int(const char *string)
}
int parameter2intlist(const char *string)
{
char *endptr = NULL;
int ival = (int) strtol(string, &endptr, 10);
if ( *endptr != 0 && *endptr != '/' && (endptr - string) == 0 )
cdoAbort("Integer parameter >%s< contains invalid character at position %d!",
string, (int)(endptr-string+1));
return (ival);
}
const char *seas_name_dec[4] = {"DJF", "MAM", "JJA", "SON"};
const char *seas_name_jan[4] = {"JFM", "AMJ", "JAS", "OND"};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment