Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
cdo
Commits
198c1a45
Commit
198c1a45
authored
Oct 20, 2015
by
Uwe Schulzweida
Browse files
replace check of pn by call to percentile_check_number()
parent
9e7ce17d
Changes
17
Hide whitespace changes
Inline
Side-by-side
src/Ensstat.c
View file @
198c1a45
...
...
@@ -55,7 +55,6 @@ void *Ensstat(void *argument)
double
missval
;
double
*
array
;
}
ens_file_t
;
int
pn
=
0
;
cdoInitialize
(
argument
);
...
...
@@ -75,13 +74,13 @@ void *Ensstat(void *argument)
int
argc
=
operatorArgc
();
int
nargc
=
argc
;
double
pn
=
0
;
if
(
operfunc
==
func_pctl
)
{
operatorInputArg
(
"percentile number"
);
pn
=
parameter2int
(
operatorArgv
()[
0
]);
if
(
pn
<
1
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %d is not in the range 1..100!"
,
pn
);
percentile_check_number
(
pn
);
argc
--
;
}
...
...
src/Fldstat.c
View file @
198c1a45
...
...
@@ -96,7 +96,6 @@ void *Fldstat(void *argument)
int
nmiss
;
double
sglval
;
field_t
field
;
int
pn
=
0
;
cdoInitialize
(
argument
);
...
...
@@ -115,13 +114,12 @@ void *Fldstat(void *argument)
int
operfunc
=
cdoOperatorF1
(
operatorID
);
int
needWeights
=
cdoOperatorF2
(
operatorID
);
double
pn
=
0
;
if
(
operfunc
==
func_pctl
)
{
operatorInputArg
(
"percentile number"
);
pn
=
parameter2int
(
operatorArgv
()[
0
]);
if
(
pn
<
1
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %d is not in the range 1..100!"
,
pn
);
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
}
int
useweights
=
TRUE
;
...
...
src/Merstat.c
View file @
198c1a45
...
...
@@ -46,7 +46,6 @@ void *Merstat(void *argument)
int
recID
,
nrecs
;
int
varID
,
levelID
;
int
needWeights
=
FALSE
;
int
pn
=
0
;
char
varname
[
CDI_MAX_NAME
];
cdoInitialize
(
argument
);
...
...
@@ -65,16 +64,13 @@ void *Merstat(void *argument)
int
operatorID
=
cdoOperatorID
();
int
operfunc
=
cdoOperatorF1
(
operatorID
);
/* RQ */
double
pn
=
0
;
if
(
operfunc
==
func_pctl
)
{
operatorInputArg
(
"percentile number"
);
pn
=
parameter2int
(
operatorArgv
()[
0
]);
if
(
pn
<
1
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %d is not in the range 1..100!"
,
pn
);
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
}
/* QR */
if
(
operfunc
==
func_mean
||
operfunc
==
func_avg
||
operfunc
==
func_var
||
operfunc
==
func_std
||
...
...
src/Runpctl.c
View file @
198c1a45
...
...
@@ -51,12 +51,10 @@ void *Runpctl(void *argument)
operatorInputArg
(
"percentile number, number of timesteps"
);
operatorCheckArgc
(
2
);
int
pn
=
parameter2int
(
operatorArgv
()[
0
]);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
int
ndates
=
parameter2int
(
operatorArgv
()[
1
]);
if
(
pn
<
1
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %d is not in the range 1..100!"
,
pn
);
int
streamID1
=
streamOpenRead
(
cdoStreamName
(
0
));
int
vlistID1
=
streamInqVlist
(
streamID1
);
...
...
src/Seaspctl.c
View file @
198c1a45
...
...
@@ -57,9 +57,7 @@ void *Seaspctl(void *argument)
operatorInputArg
(
"percentile number"
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
percentile_check_number
(
pn
);
season_start
=
get_season_start
();
...
...
src/Timpctl.c
View file @
198c1a45
...
...
@@ -54,9 +54,7 @@ void timpctl(int operatorID)
operatorInputArg
(
"percentile number"
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
if
(
!
(
pn
>=
0
&&
pn
<=
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
percentile_check_number
(
pn
);
int
cmplen
=
DATE_LEN
-
cdoOperatorF2
(
operatorID
);
...
...
src/Timselpctl.c
View file @
198c1a45
...
...
@@ -55,14 +55,12 @@ void *Timselpctl(void *argument)
if
(
nargc
<
2
)
cdoAbort
(
"Too few arguments! Need %d found %d."
,
2
,
nargc
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
int
ndates
=
parameter2int
(
operatorArgv
()[
1
]);
int
noffset
=
0
,
nskip
=
0
;
if
(
nargc
>
2
)
noffset
=
parameter2int
(
operatorArgv
()[
2
]);
if
(
nargc
>
3
)
nskip
=
parameter2int
(
operatorArgv
()[
3
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
if
(
cdoVerbose
)
cdoPrint
(
"nsets = %d, noffset = %d, nskip = %d"
,
ndates
,
noffset
,
nskip
);
int
streamID1
=
streamOpenRead
(
cdoStreamName
(
0
));
...
...
src/Ydaypctl.c
View file @
198c1a45
...
...
@@ -54,17 +54,14 @@ void *Ydaypctl(void *argument)
int
vdates2
[
NDAY
],
vtimes2
[
NDAY
];
field_t
**
vars1
[
NDAY
];
field_t
field
;
double
pn
;
HISTOGRAM_SET
*
hsets
[
NDAY
];
cdoInitialize
(
argument
);
cdoOperatorAdd
(
"ydaypctl"
,
func_pctl
,
0
,
NULL
);
operatorInputArg
(
"percentile number"
);
pn
=
parameter2double
(
operatorArgv
()[
0
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
for
(
dayoy
=
0
;
dayoy
<
NDAY
;
dayoy
++
)
{
...
...
src/Ydrunpctl.c
View file @
198c1a45
...
...
@@ -67,10 +67,8 @@ void *Ydrunpctl(void *argument)
operatorInputArg
(
"percentile number, number of timesteps"
);
operatorCheckArgc
(
2
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
int
ndates
=
parameter2int
(
operatorArgv
()[
1
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
for
(
dayoy
=
0
;
dayoy
<
NDAY
;
dayoy
++
)
{
...
...
src/Ymonpctl.c
View file @
198c1a45
...
...
@@ -59,17 +59,14 @@ void *Ymonpctl(void *argument)
int
vdates2
[
NMONTH
];
field_t
**
vars1
[
NMONTH
];
field_t
field
;
double
pn
;
HISTOGRAM_SET
*
hsets
[
NMONTH
];
cdoInitialize
(
argument
);
cdoOperatorAdd
(
"ymonpctl"
,
func_pctl
,
0
,
NULL
);
operatorInputArg
(
"percentile number"
);
pn
=
parameter2double
(
operatorArgv
()[
0
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
for
(
month
=
0
;
month
<
NMONTH
;
month
++
)
{
...
...
src/Yseaspctl.c
View file @
198c1a45
...
...
@@ -61,9 +61,7 @@ void *Yseaspctl(void *argument)
operatorInputArg
(
"percentile number"
);
double
pn
=
parameter2double
(
operatorArgv
()[
0
]);
if
(
!
(
pn
>
0
&&
pn
<
100
)
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
percentile_check_number
(
pn
);
for
(
seas
=
0
;
seas
<
NSEAS
;
seas
++
)
{
...
...
src/Zonstat.c
View file @
198c1a45
...
...
@@ -46,7 +46,6 @@ void *Zonstat(void *argument)
int
index
;
int
recID
,
nrecs
;
int
varID
,
levelID
;
int
pn
=
0
;
cdoInitialize
(
argument
);
...
...
@@ -65,13 +64,12 @@ void *Zonstat(void *argument)
int
operatorID
=
cdoOperatorID
();
int
operfunc
=
cdoOperatorF1
(
operatorID
);
double
pn
=
0
;
if
(
operfunc
==
func_pctl
)
{
operatorInputArg
(
"percentile number"
);
pn
=
parameter2int
(
operatorArgv
()[
0
]);
if
(
pn
<
1
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %d is not in the range 1..100!"
,
pn
);
pn
=
parameter2double
(
operatorArgv
()[
0
]);
percentile_check_number
(
pn
);
}
int
streamID1
=
streamOpenRead
(
cdoStreamName
(
0
));
...
...
src/field.c
View file @
198c1a45
...
...
@@ -532,7 +532,7 @@ void varrms(field_t field, field_t field2, field_t *field3)
}
/* RQ */
double
fldpctl
(
field_t
field
,
const
int
p
)
double
fldpctl
(
field_t
field
,
const
double
p
n
)
{
const
size_t
len
=
field
.
size
;
const
int
nmiss
=
field
.
nmiss
;
...
...
@@ -551,13 +551,13 @@ double fldpctl(field_t field, const int p)
if
(
!
DBL_IS_EQUAL
(
array
[
i
],
missval
)
)
array2
[
j
++
]
=
array
[
i
];
pctl
=
percentile
(
array2
,
j
,
p
);
pctl
=
percentile
(
array2
,
j
,
p
n
);
Free
(
array2
);
}
else
{
pctl
=
percentile
(
array
,
len
,
p
);
pctl
=
percentile
(
array
,
len
,
p
n
);
}
}
...
...
src/field.h
View file @
198c1a45
...
...
@@ -88,7 +88,7 @@ double fldstd(field_t field);
double
fldstd1
(
field_t
field
);
double
fldvar
(
field_t
field
);
double
fldvar1
(
field_t
field
);
double
fldpctl
(
field_t
field
,
const
int
k
);
double
fldpctl
(
field_t
field
,
const
double
pn
);
void
fldunm
(
field_t
*
field
);
int
fldhvs
(
field_t
*
field
,
const
size_t
nlevels
);
...
...
src/percentiles.c
View file @
198c1a45
#include
<math.h>
#include
"util.h"
#include
"percentiles.h"
#include
"nth_element.h"
double
percentile
(
double
*
array
,
unsigned
len
,
double
p
)
double
percentile
(
double
*
array
,
unsigned
len
,
double
pn
)
{
double
percentil
;
percentil
=
nth_element
(
array
,
len
,
(
int
)
ceil
(
len
*
(
p
/
100
.
0
))
-
1
);
int
element
=
(
int
)
ceil
(
len
*
(
pn
/
100
.
0
))
-
1
;
if
(
element
<
0
)
element
=
0
;
if
(
element
>=
len
)
element
=
len
-
1
;
double
percentil
=
nth_element
(
array
,
len
,
element
);
return
percentil
;
}
void
percentile_check_number
(
double
pn
)
{
if
(
pn
<
0
||
pn
>
100
)
cdoAbort
(
"Illegal argument: percentile number %g is not in the range 0..100!"
,
pn
);
}
src/percentiles.h
View file @
198c1a45
#ifndef _PERCENTILES_H
#define _PERCENTILES_H
double
percentile
(
double
*
array
,
unsigned
len
,
double
p
);
double
percentile
(
double
*
array
,
unsigned
len
,
double
pn
);
void
percentile_check_number
(
double
pn
);
#endif
/* _PERCENTILES_H */
src/util.h
View file @
198c1a45
...
...
@@ -18,6 +18,8 @@
#ifndef _UTIL_H
#define _UTIL_H
#include
<stdio.h>
#include
"percentiles.h"
/* dummy use of unused parameters to silence compiler warnings */
#define UNUSED(x) (void)x
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment