about summary refs log tree commit diff
path: root/src/bslmmdap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bslmmdap.cpp')
-rw-r--r--src/bslmmdap.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/bslmmdap.cpp b/src/bslmmdap.cpp
index 7aac1d4..e9900e3 100644
--- a/src/bslmmdap.cpp
+++ b/src/bslmmdap.cpp
@@ -116,16 +116,16 @@ void ReadFile_hyb(const string &file_hyp, vector<double> &vec_sa2,
   getline(infile, line);
 
   while (!safeGetline(infile, line).eof()) {
-    ch_ptr = strtok((char *)line.c_str(), " , \t");
-    ch_ptr = strtok(NULL, " , \t");
+    ch_ptr = strtok_safe((char *)line.c_str(), " , \t");
+    ch_ptr = strtok_safe(NULL, " , \t");
 
-    ch_ptr = strtok(NULL, " , \t");
+    ch_ptr = strtok_safe(NULL, " , \t");
     vec_sa2.push_back(atof(ch_ptr));
 
-    ch_ptr = strtok(NULL, " , \t");
+    ch_ptr = strtok_safe(NULL, " , \t");
     vec_sb2.push_back(atof(ch_ptr));
 
-    ch_ptr = strtok(NULL, " , \t");
+    ch_ptr = strtok_safe(NULL, " , \t");
     vec_wab.push_back(atof(ch_ptr));
   }
 
@@ -152,7 +152,7 @@ void ReadFile_bf(const string &file_bf, vector<string> &vec_rs,
   vector<vector<double>> mat_bf;
   char *ch_ptr;
 
-  size_t bf_size, flag_block;
+  size_t bf_size = 0, flag_block;
 
   getline(infile, line);
 
@@ -160,11 +160,11 @@ void ReadFile_bf(const string &file_bf, vector<string> &vec_rs,
   while (!safeGetline(infile, line).eof()) {
     flag_block = 0;
 
-    ch_ptr = strtok((char *)line.c_str(), " , \t");
+    ch_ptr = strtok_safe((char *)line.c_str(), " , \t");
     rs = ch_ptr;
     vec_rs.push_back(rs);
 
-    ch_ptr = strtok(NULL, " , \t");
+    ch_ptr = strtok_safe(NULL, " , \t");
     if (t == 0) {
       block = ch_ptr;
     } else {
@@ -223,7 +223,7 @@ void ReadFile_cat(const string &file_cat, const vector<string> &vec_rs,
 
   // Read header.
   HEADER header;
-  !safeGetline(infile, line).eof();
+  safeGetline(infile, line).eof();
   ReadHeader_io(line, header);
 
   // Use the header to determine the number of categories.
@@ -238,7 +238,7 @@ void ReadFile_cat(const string &file_cat, const vector<string> &vec_rs,
 
   // Read the following lines to record mapRS2cat.
   while (!safeGetline(infile, line).eof()) {
-    ch_ptr = strtok((char *)line.c_str(), " , \t");
+    ch_ptr = strtok_safe((char *)line.c_str(), " , \t");
 
     if (header.rs_col == 0) {
       rs = chr + ":" + pos;
@@ -248,6 +248,7 @@ void ReadFile_cat(const string &file_cat, const vector<string> &vec_rs,
     catd.clear();
 
     for (size_t i = 0; i < header.coln; i++) {
+      enforce(ch_ptr);
       if (header.rs_col != 0 && header.rs_col == i + 1) {
         rs = ch_ptr;
       } else if (header.chr_col != 0 && header.chr_col == i + 1) {
@@ -658,13 +659,13 @@ void single_ct_regression(const gsl_matrix_int *Xd,
     sum_pip[i] = sum[i] = 0;
   }
 
-  for (int i = 0; i < Xd->size1; i++) {
+  for (size_t i = 0; i < Xd->size1; i++) {
     int cat = gsl_matrix_int_get(Xd, i, 0);
     sum_pip[cat] += gsl_vector_get(pip_vec, i);
     sum[cat] += 1;
   }
 
-  for (int i = 0; i < Xd->size1; i++) {
+  for (size_t i = 0; i < Xd->size1; i++) {
     int cat = gsl_matrix_int_get(Xd, i, 0);
     gsl_vector_set(prior_vec, i, sum_pip[cat] / sum[cat]);
   }
@@ -683,10 +684,10 @@ void BSLMMDAP::DAP_EstimateHyper(
     const vector<double> &vec_sa2, const vector<double> &vec_sb2,
     const vector<double> &wab, const vector<vector<vector<double>>> &BF,
     gsl_matrix *Ac, gsl_matrix_int *Ad, gsl_vector_int *dlevel) {
-  clock_t time_start;
+  // clock_t time_start;
 
   // Set up BF.
-  double h, rho, sigma_a2, sigma_b2, d, s, logm, logm_save;
+  double h, rho, sigma_a2, sigma_b2, d, s, logm, logm_save = nan("");
   size_t t1, t2;
   size_t n_grid = wab.size(), ns_test = vec_rs.size();