for C version
The R version of detecting CNE