[Genabel-commits] r822 - in pkg/GenABEL: R inst/unitTests src/GAlib

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 7 11:29:52 CET 2011


Author: yurii
Date: 2011-12-07 11:29:51 +0100 (Wed, 07 Dec 2011)
New Revision: 822

Modified:
   pkg/GenABEL/R/zzz.R
   pkg/GenABEL/inst/unitTests/runit.polylik.R
   pkg/GenABEL/src/GAlib/export_plink.cpp
   pkg/GenABEL/src/GAlib/gtps_container.cpp
   pkg/GenABEL/src/GAlib/gtps_container.h
   pkg/GenABEL/src/GAlib/gwaa_cpp.cpp
   pkg/GenABEL/src/GAlib/mematri1.h
   pkg/GenABEL/src/GAlib/reg1.h
   pkg/GenABEL/src/GAlib/reg1data.h
Log:
fix memory leak in 'export.plink'; clean-up the code form 'cout's and 'exit's

Modified: pkg/GenABEL/R/zzz.R
===================================================================
--- pkg/GenABEL/R/zzz.R	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/R/zzz.R	2011-12-07 10:29:51 UTC (rev 822)
@@ -1,19 +1,21 @@
 .onLoad <- function(lib, pkg) {
-	pkgDescription <- packageDescription(pkg)
-	pkgVersion <- pkgDescription$Version
-	pkgDate <- pkgDescription$Date
-	welcomeMessage <- paste(pkg," v. ",pkgVersion," (",pkgDate,") loaded\n",sep="")
-	# check if CRAN version is the same as loaded
-	cranVersion <- checkPackageVersionOnCRAN(pkg)
-	if (!is.null(cranVersion)) 
-		if (pkgVersion != cranVersion) {
-			welcomeMessage <- paste(welcomeMessage,
-					"\nInstalled ",pkg," version (",pkgVersion,") is not the same as stable\n",
-					"version available from CRAN (",cranVersion,"). Unless used intentionally,\n",
-					"consider updating to the latest CRAN version. For that, use\n",
-					"'install.packages(\"",pkg,"\")', or ask your system administrator\n",
-					"to update the package.\n\n",sep="")
-		}
+	if (require(utils)) {
+		pkgDescription <- packageDescription(pkg)
+		pkgVersion <- pkgDescription$Version
+		pkgDate <- pkgDescription$Date
+		welcomeMessage <- paste(pkg," v. ",pkgVersion," (",pkgDate,") loaded\n",sep="")
+		# check if CRAN version is the same as loaded
+		cranVersion <- checkPackageVersionOnCRAN(pkg)
+		if (!is.null(cranVersion)) 
+			if (pkgVersion != cranVersion) {
+				welcomeMessage <- paste(welcomeMessage,
+						"\nInstalled ",pkg," version (",pkgVersion,") is not the same as stable\n",
+						"version available from CRAN (",cranVersion,"). Unless used intentionally,\n",
+						"consider updating to the latest CRAN version. For that, use\n",
+						"'install.packages(\"",pkg,"\")', or ask your system administrator\n",
+						"to update the package.\n\n",sep="")
+			}
+	}
 	# check for news
 	address <- c(
 			"http://genabel.r-forge.r-project.org/version_and_news.html",

Modified: pkg/GenABEL/inst/unitTests/runit.polylik.R
===================================================================
--- pkg/GenABEL/inst/unitTests/runit.polylik.R	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/inst/unitTests/runit.polylik.R	2011-12-07 10:29:51 UTC (rev 822)
@@ -20,7 +20,7 @@
 
 ### --- Test functions ---
 
-test.polylik <- function()
+test.polylik <- function(tol = 2*.Machine$double.eps^0.5)
 {
     data(ge03d2.clean)
     df <- ge03d2.clean[1:150,autosomal(ge03d2.clean)]
@@ -41,10 +41,10 @@
     tO; tN; tO/tN;
     print(h2htNew$h2an)
     print(h2htOld$h2an)
-    checkEquals(h2htNew$h2an$est,h2htOld$h2an$est)
-    checkEquals(h2htNew$h2an$min,h2htOld$h2an$min)
-    checkEquals(h2htNew$residualY,h2htOld$residualY)
-    checkEquals(h2htNew$pgresidualY,h2htOld$pgresidualY)
-    checkEquals(h2htNew$InvSigma,h2htOld$InvSigma)
-    checkEquals(h2htNew$measuredIDs,h2htOld$measuredIDs)
+    checkEquals(h2htNew$h2an$est,h2htOld$h2an$est, tolerance = tol)
+    checkEquals(h2htNew$h2an$min,h2htOld$h2an$min, tolerance = tol)
+    checkEquals(h2htNew$residualY,h2htOld$residualY, tolerance = tol)
+    checkEquals(h2htNew$pgresidualY,h2htOld$pgresidualY, tolerance = tol)
+    checkEquals(h2htNew$InvSigma,h2htOld$InvSigma, tolerance = tol)
+    checkEquals(h2htNew$measuredIDs,h2htOld$measuredIDs, tolerance = tol)
 }
\ No newline at end of file

Modified: pkg/GenABEL/src/GAlib/export_plink.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/export_plink.cpp	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/export_plink.cpp	2011-12-07 10:29:51 UTC (rev 822)
@@ -47,13 +47,19 @@
 	bool plink = LOGICAL(Plink)[0];
 	std::string filename = CHAR(STRING_ELT(Pedfilename,0));
 	std::ofstream fileWoA;
-	int gtint[nidsTotal];
 	int ieq1 = 1;
 	char * snpdata = (char *) RAW(Snpdata);
+
+	//	int gtint[nidsTotal];
+	int *gtint = new (std::nothrow) int[nidsTotal];
+
 	//Rprintf("nsnps=%d\n",nsnps);
 	//Rprintf("nids=%d\n",nids);
 
-	char gtMatrix[nids][nsnps];
+	//char gtMatrix[nids][nsnps];
+	char **gtMatrix = new (std::nothrow) char*[nids];
+	for (unsigned int i=0;i<nids;i++) gtMatrix[i] = new (std::nothrow) char[nsnps];
+
 	//Rprintf("1\n");
 	std::string* Genotype;
 	std::string sep="/";
@@ -102,7 +108,9 @@
 	//for (int i=0;i<10;i++) Rprintf("%d ",sex[i]);
 	//Rprintf("oooo!\n" );
 
+	delete [] gtMatrix;
 	delete [] Genotype;
+	delete [] gtint;
 
 	return R_NilValue;
 }
@@ -133,9 +141,12 @@
 	bool exportNumeric = LOGICAL(ExportNumeric)[0];
 	std::string filename = CHAR(STRING_ELT(Pedfilename,0));
 	std::ofstream fileWoA;
-	int gtint[nids];
 	int ieq1 = 1;
 	char * snpdata = (char *) RAW(Snpdata);
+
+	//	int gtint[nids];
+	int *gtint = new (std::nothrow) int[nids];
+
 	//Rprintf("nsnps=%d\n",nsnps);
 	//Rprintf("nids=%d\n",nids);
 
@@ -196,6 +207,7 @@
 	//Rprintf("oooo!\n" );
 
 	delete [] Genotype;
+	delete [] gtint;
 
 	return R_NilValue;
 }

Modified: pkg/GenABEL/src/GAlib/gtps_container.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/gtps_container.cpp	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/gtps_container.cpp	2011-12-07 10:29:51 UTC (rev 822)
@@ -105,7 +105,7 @@
 {
 get_our_byte_number_and_local_person_number(id_position, snp_position); //calculate our_byte_number value
 
-char our_byte_vallue = gtps_array[our_byte_number-1];
+//char our_byte_vallue = gtps_array[our_byte_number-1];
 
 
 
@@ -124,12 +124,12 @@
 char* gtps_for_one_snp = new char(nbytes_for_one_snp);
 get_our_byte_number_and_local_person_number(1, snp_position); //calculate our_byte_number value
 
-std::cout<<"gtps_container::get_gtps_array_for_snp:  our_byte_number="<<our_byte_number<<"\n";
-std::cout<<"gtps_container::get_gtps_array_for_snp:  nbytes_for_one_snp="<<nbytes_for_one_snp<<"\n";
+//std::cout<<"gtps_container::get_gtps_array_for_snp:  our_byte_number="<<our_byte_number<<"\n";
+//std::cout<<"gtps_container::get_gtps_array_for_snp:  nbytes_for_one_snp="<<nbytes_for_one_snp<<"\n";
 	
-std::cout<<"gtps_array[0]="<<int(gtps_array[0])<<"\n";
+//std::cout<<"gtps_array[0]="<<int(gtps_array[0])<<"\n";
 
-for(int i=0 ; i<nbytes_for_one_snp; i++)
+for(unsigned int i=0 ; i<nbytes_for_one_snp; i++)
 	{
 	gtps_for_one_snp[i]=gtps_array[our_byte_number-1+i];
 	}
@@ -150,16 +150,22 @@
 char gtps_container::get_strand(unsigned snp_position)
 {
 if(do_we_have_strand_and_codding_arrays) return strand_array[snp_position-1]; 
-else std::cout<<"gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)\n";
+else {
+	//std::cout<<"gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)\n";
+	error("gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)");
 }
+}
 
 
 
 char gtps_container::get_coding(unsigned snp_position)
 {
 if(do_we_have_strand_and_codding_arrays) return coding_array[snp_position-1]; 
-else std::cout<<"gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)\n";
+else {
+	//std::cout<<"gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)\n";
+	error("gtps_container::get_strand: You can not get strand since you create object with constructor gtps_container(char * gtps_array_raw, unsigned id_numbers, unsigned snp_numbers)");
 }
+}
 
 
 //------------------------------------------------------------------

Modified: pkg/GenABEL/src/GAlib/gtps_container.h
===================================================================
--- pkg/GenABEL/src/GAlib/gtps_container.h	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/gtps_container.h	2011-12-07 10:29:51 UTC (rev 822)
@@ -18,8 +18,8 @@
 #ifndef SMV_GTPS_CONTAINER_H
 #define SMV_GTPS_CONTAINER_H
 
+#include <R.h>
 
-
 #include<iostream>
 #include<vector>
 #include<memory>

Modified: pkg/GenABEL/src/GAlib/gwaa_cpp.cpp
===================================================================
--- pkg/GenABEL/src/GAlib/gwaa_cpp.cpp	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/gwaa_cpp.cpp	2011-12-07 10:29:51 UTC (rev 822)
@@ -16,14 +16,14 @@
 //
 // Written by Jan Wigginton
 	 */
-
 	double SNPHWE(int obs_hets, int obs_hom1, int obs_hom2)
 	{
 		if (obs_hom1 < 0 || obs_hom2 < 0 || obs_hets < 0)
 		{
-			printf("FATAL ERROR - SNP-HWE: Current genotype configuration (%d  %d %d ) includes a"
-					" negative count", obs_hets, obs_hom1, obs_hom2);
-			exit(EXIT_FAILURE);
+			//printf("FATAL ERROR - SNP-HWE: Current genotype configuration (%d  %d %d ) includes a"
+			//		" negative count", obs_hets, obs_hom1, obs_hom2);
+			//exit(EXIT_FAILURE);
+			error("FATAL ERROR - SNP-HWE: Current genotype configuration includes a negative count");
 		}
 
 		int obs_homc = obs_hom1 < obs_hom2 ? obs_hom2 : obs_hom1;
@@ -35,18 +35,19 @@
 		double * het_probs = (double *) malloc((size_t) (rare_copies + 1) * sizeof(double));
 		if (het_probs == NULL)
 		{
-			printf("FATAL ERROR - SNP-HWE: Unable to allocate array for heterozygote probabilities" );
-			exit(EXIT_FAILURE);
+			//printf("FATAL ERROR - SNP-HWE: Unable to allocate array for heterozygote probabilities" );
+			//exit(EXIT_FAILURE);
+			error("FATAL ERROR - SNP-HWE: Unable to allocate array for heterozygote probabilities");
 		}
 
 		int i;
 		for (i = 0; i <= rare_copies; i++)
 			het_probs[i] = 0.0;
 
-		/* start at midpoint */
+		// start at midpoint
 		int mid = rare_copies * (2 * genotypes - rare_copies) / (2 * genotypes);
 
-		/* check to ensure that midpoint and rare alleles have same parity */
+		// check to ensure that midpoint and rare alleles have same parity
 		if ((rare_copies & 1) ^ (mid & 1))
 			mid++;
 
@@ -62,7 +63,7 @@
                             				   / (4.0 * (curr_homr + 1.0) * (curr_homc + 1.0));
 			sum += het_probs[curr_hets - 2];
 
-			/* 2 fewer heterozygotes for next iteration -> add one rare, one common homozygote */
+			// 2 fewer heterozygotes for next iteration -> add one rare, one common homozygote
 			curr_homr++;
 			curr_homc++;
 		}
@@ -76,7 +77,7 @@
 					/((curr_hets + 2.0) * (curr_hets + 1.0));
 			sum += het_probs[curr_hets + 2];
 
-			/* add 2 heterozygotes for next iteration -> subtract one rare, one common homozygote */
+			// add 2 heterozygotes for next iteration -> subtract one rare, one common homozygote
 			curr_homr--;
 			curr_homc--;
 		}
@@ -84,21 +85,21 @@
 		for (i = 0; i <= rare_copies; i++)
 			het_probs[i] /= sum;
 
-		/* alternate p-value calculation for p_hi/p_lo
-   double p_hi = het_probs[obs_hets];
-   for (i = obs_hets + 1; i <= rare_copies; i++)
-     p_hi += het_probs[i];
+		// alternate p-value calculation for p_hi/p_lo
+   //double p_hi = het_probs[obs_hets];
+   //for (i = obs_hets + 1; i <= rare_copies; i++)
+   //  p_hi += het_probs[i];
 
-   double p_lo = het_probs[obs_hets];
-   for (i = obs_hets - 1; i >= 0; i--)
-      p_lo += het_probs[i];
+   //double p_lo = het_probs[obs_hets];
+   //for (i = obs_hets - 1; i >= 0; i--)
+   //   p_lo += het_probs[i];
 
 
-   double p_hi_lo = p_hi < p_lo ? 2.0 * p_hi : 2.0 * p_lo;
-		 */
+   //double p_hi_lo = p_hi < p_lo ? 2.0 * p_hi : 2.0 * p_lo;
 
+
 		double p_hwe = 0.0;
-		/*  p-value calculation for p_hwe  */
+		//  p-value calculation for p_hwe
 		for (i = 0; i <= rare_copies; i++)
 		{
 			if (het_probs[i] > het_probs[obs_hets])

Modified: pkg/GenABEL/src/GAlib/mematri1.h
===================================================================
--- pkg/GenABEL/src/GAlib/mematri1.h	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/mematri1.h	2011-12-07 10:29:51 UTC (rev 822)
@@ -6,13 +6,13 @@
 {
 	if (nr<=0)
 	{
-		fprintf(stderr,"mematrix(): nr <= 0\n");
-		exit(1);
+		//fprintf(stderr,"mematrix(): nr <= 0\n");
+		error("mematrix(): nr <= 0");
 	}
 	if (nc<=0)
 	{
-		fprintf(stderr,"mematrix(): nc <= 0\n");
-		exit(1);
+		//fprintf(stderr,"mematrix(): nc <= 0\n");
+		error("mematrix(): nc <= 0");
 	}
 	nrow = nr;
 	ncol = nc;
@@ -20,8 +20,8 @@
 	data = new (nothrow) DT [ncol*nrow];
 	if (!data) 
 	{
-		fprintf(stderr,"mematrix(nr,nc): cannot allocate memory (%d,%d)\n",nrow,ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix(nr,nc): cannot allocate memory (%d,%d)\n",nrow,ncol);
+		error("mematrix(nr,nc): cannot allocate memory");
 	}
 //	fprintf(stderr,"mematrix(nr,nc): can allocate memory (%d,%d)\n",nrow,ncol);
 }
@@ -34,8 +34,8 @@
 	data = new (nothrow) DT [M.ncol*M.nrow];
 	if (!data)
 	{
-		fprintf(stderr,"mematrix const(mematrix): cannot allocate memory (%d,%d)\n",M.nrow,M.ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix const(mematrix): cannot allocate memory (%d,%d)\n",M.nrow,M.ncol);
+		error("mematrix const(mematrix): cannot allocate memory");
 	}
 //	fprintf(stderr,"mematrix const(mematrix): can allocate memory (%d,%d)\n",M.nrow,M.ncol);
 	for(int i=0 ; i<M.ncol*M.nrow;i++) data[i] = M.data[i];
@@ -52,9 +52,9 @@
 		data = new (nothrow) DT [M.ncol*M.nrow];
 		if (!data) 
 		{
-			fprintf(stderr,"mematrix=: cannot allocate memory (%d,%d)\n",M.nrow,M.ncol);
+			//fprintf(stderr,"mematrix=: cannot allocate memory (%d,%d)\n",M.nrow,M.ncol);
 			delete [] data;
-			exit(1);
+			error("mematrix=: cannot allocate memory");
 		}
 		ncol = M.ncol;
 		nrow = M.nrow;
@@ -69,8 +69,8 @@
 {
 	if (i<0 || i>=(ncol*nrow)) 
 	{
-		fprintf(stderr,"mematrix[]: %d out of bounds (0,%d)\n",i,nrow*ncol-1);
-		exit(1);
+		//fprintf(stderr,"mematrix[]: %d out of bounds (0,%d)\n",i,nrow*ncol-1);
+		error("mematrix[]: out of bounds");
 	}
 	return data[i];
 }
@@ -86,8 +86,8 @@
 {
 	if (ncol != M.ncol || nrow != M.nrow)
 	{
-		fprintf(stderr,"mematrix+: matrices not equal in size (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix+: matrices not equal in size (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
+		error("mematrix+: matrices not equal in size");
 	}
 	mematrix<DT> temp(nrow,ncol);
 	for (int i=0;i<nelements;i++) temp.data[i] = data[i] + M.data[i];
@@ -105,8 +105,8 @@
 {
 	if (ncol != M.ncol || nrow != M.nrow)
 	{
-		fprintf(stderr,"mematrix-: matrices not equal in size (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix-: matrices not equal in size (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
+		error("mematrix-: matrices not equal in size");
 	}
 	mematrix<DT> temp(nrow,ncol);
 	for (int i=0;i<nelements;i++) temp.data[i] = data[i] - M.data[i];
@@ -124,8 +124,8 @@
 {
 	if (ncol != M.nrow)
 	{
-		fprintf(stderr,"mematrix*: ncol != nrow (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix*: ncol != nrow (%d,%d) and (%d,%d)",nrow,ncol,M.nrow,M.ncol);
+		error("mematrix*: ncol != nrow");
 	}
 	mematrix<DT> temp(nrow,M.ncol);
 	for (int j=0;j<temp.nrow;j++)
@@ -150,13 +150,13 @@
 	if (nelements>0) delete [] data;
 	if (nr<=0)
 	{
-		fprintf(stderr,"mematrix(): nr <= 0\n");
-		exit(1);
+		//fprintf(stderr,"mematrix(): nr <= 0\n");
+		error("mematrix(): nr <= 0");
 	}
 	if (nc<=0)
 	{
-		fprintf(stderr,"mematrix(): nc <= 0\n");
-		exit(1);
+		//fprintf(stderr,"mematrix(): nc <= 0\n");
+		error("mematrix(): nc <= 0");
 	}
 	nrow = nr;
 	ncol = nc;
@@ -164,8 +164,8 @@
 	data = new (nothrow) DT [ncol*nrow];
 	if (!data) 
 	{
-		fprintf(stderr,"mematrix(nr,nc): cannot allocate memory (%d,%d)\n",nrow,ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix(nr,nc): cannot allocate memory (%d,%d)\n",nrow,ncol);
+		error("mematrix(nr,nc): cannot allocate memory");
 	}
 }
 template <class DT> 
@@ -173,13 +173,13 @@
 {
 	if (nc<0 || nc>ncol) 
 	{
-		fprintf(stderr,"mematrix::get: column out of range: %d not in (0,%d)\n",nc,ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix::get: column out of range: %d not in (0,%d)\n",nc,ncol);
+		error("mematrix::get: column out of range");
 	}
 	if (nr <0 || nr>nrow) 
 	{
-		printf("mematrix::get: row out of range: %d not in (0,%d)\n",nr,nrow);
-		exit(1);
+		//printf("mematrix::get: row out of range: %d not in (0,%d)\n",nr,nrow);
+		error("mematrix::get: row out of range");
 	}
 	DT temp = data[nr*ncol+nc];
 	return temp;
@@ -189,13 +189,13 @@
 {
 	if (nc<0 || nc>ncol) 
 	{
-		fprintf(stderr,"mematrix::put: column out of range: %d not in (0,%d)\n",nc,ncol);
-		exit(1);
+		//fprintf(stderr,"mematrix::put: column out of range: %d not in (0,%d)\n",nc,ncol);
+		error("mematrix::put: column out of range");
 	}
 	if (nr <0 || nr>nrow) 
 	{
-		printf("mematrix::put: row out of range: %d not in (0,%d)\n",nr,nrow);
-		exit(1);
+		//printf("mematrix::put: row out of range: %d not in (0,%d)\n",nr,nrow);
+		error("mematrix::put: row out of range");
 	}
 	data[nr*ncol+nc] = value;
 }
@@ -204,8 +204,8 @@
 {
 	if (nc>= ncol || nc <0)
 	{
-		fprintf(stderr,"colmM bad column\n");
-		exit(1);
+		//fprintf(stderr,"colmM bad column\n");
+		error("colmM bad column");
 	}
 	DT out = 0.0;
 	for (int i =0;i<nrow;i++) out+= DT(data[i*ncol+nc]);
@@ -215,6 +215,7 @@
 template <class DT> 
 void mematrix<DT>::print(void)
 {
+	/**
 	cout << "nrow=" << nrow << "; ncol=" << ncol << "; nelements=" << nelements << "\n";
 	for (int i=0;i<nrow;i++) {
 		cout << "nr=" << i << ":\t";
@@ -222,14 +223,16 @@
 			cout << data[i*ncol+j] << "\t";
 		cout << "\n";
 	}
+	**/
+	Rprintf("mematrix::print called... but not defined :(\n");
 }
 template <class DT> 
 void mematrix<DT>::delete_column(int delcol)
 {
 	if (delcol > ncol || delcol < 0) 
 	{
-		fprintf(stderr,"mematrix::delete_column: column out of range\n");
-		exit(1);
+		//fprintf(stderr,"mematrix::delete_column: column out of range\n");
+		error("mematrix::delete_column: column out of range");
 	}
 	mematrix<DT> temp = *this;
 	if (nelements>0) delete [] data;
@@ -238,9 +241,9 @@
 	data = new (nothrow) DT [ncol*nrow];
 	if (!data) 
 	{
-		fprintf(stderr,"mematrix::delete_column: cannot allocate memory (%d,%d)\n",nrow,ncol);
+		//fprintf(stderr,"mematrix::delete_column: cannot allocate memory (%d,%d)\n",nrow,ncol);
 		delete [] data;
-		exit(1);
+		error("mematrix::delete_column: cannot allocate memory");
 	}
 	int newcol=0;
 	for (int nr=0;nr<temp.nrow;nr++) {
@@ -255,8 +258,8 @@
 {
 	if (delrow > nrow || delrow < 0) 
 	{
-		fprintf(stderr,"mematrix::delete_row: row out of range\n");
-		exit(1);
+		//fprintf(stderr,"mematrix::delete_row: row out of range\n");
+		error("mematrix::delete_row: row out of range");
 	}
 	mematrix<DT> temp = *this;
 	if (nelements>0) delete [] data;
@@ -265,9 +268,9 @@
 	data = new (nothrow) DT [ncol*nrow];
 	if (!data) 
 	{
-		fprintf(stderr,"mematrix::delete_row: cannot allocate memory (%d,%d)\n",nrow,ncol);
+		//fprintf(stderr,"mematrix::delete_row: cannot allocate memory (%d,%d)\n",nrow,ncol);
 		delete [] data;
-		exit(1);
+		error("mematrix::delete_row: cannot allocate memory ");
 	}
 	int newrow=0;
 	for (int nc=0;nc<temp.ncol;nc++) {
@@ -296,8 +299,8 @@
 {
 	if (M.nrow != order.nrow)
 	{
-		fprintf(stderr,"reorder: M & order have differet # of rows\n");
-		exit(1);
+		//fprintf(stderr,"reorder: M & order have differet # of rows\n");
+		error("reorder: M & order have differet # of rows");
 	}
 	mematrix<DT> temp(M.nrow,M.ncol);
 	for (int i=0;i<temp.nrow;i++)
@@ -311,8 +314,8 @@
 {
 	if (M.ncol != D.nrow)
 	{
-		fprintf(stderr,"productMatrDiag: wrong dimenstions");
-		exit(1);
+		//fprintf(stderr,"productMatrDiag: wrong dimenstions");
+		error("productMatrDiag: wrong dimenstions");
 	}
 	mematrix<DT> temp(M.nrow,M.ncol);
 	for (int i=0;i<temp.nrow;i++)
@@ -338,8 +341,8 @@
   {
 	if (M.ncol != M.nrow) 
 	{
-		fprintf(stderr,"invert: only suare matrices possible\n");
-		exit(1);
+		//fprintf(stderr,"invert: only square matrices possible\n");
+		error("invert: only square matrices possible");
 	}
 	if (M.ncol == 1) 
 	{
@@ -349,8 +352,8 @@
 	for (int i=0;i<M.ncol;i++) 
 		if (M.data[i*M.ncol+i]==0) 
 		{
-			fprintf(stderr,"invert: zero elements in diagonal\n");
-			exit(1);
+			//fprintf(stderr,"invert: zero elements in diagonal\n");
+			error("invert: zero elements in diagonal");
 		}
 	int actualsize = M.ncol;
 	int maxsize = M.ncol;

Modified: pkg/GenABEL/src/GAlib/reg1.h
===================================================================
--- pkg/GenABEL/src/GAlib/reg1.h	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/reg1.h	2011-12-07 10:29:51 UTC (rev 822)
@@ -78,8 +78,8 @@
 		double prev = (rdata.Y).column_mean(0);
 		if (prev>=1. || prev <=0.)
 		{
-			fprintf(stderr,"prevalence not within (0,1)\n");
-			exit(1);
+			//fprintf(stderr,"prevalence not within (0,1)\n");
+			error("prevalence not within (0,1)");
 		}
 		for (int i = 0;i<length_beta;i++) beta.put(0.,i,0);
 		beta.put(log(prev/(1.-prev)),0,0);
@@ -164,7 +164,10 @@
 		mematrix<double> u(cdata.X.nrow,1);
 		mematrix<double> imat(cdata.X.nrow,cdata.X.nrow);
 		double * work = new (nothrow) double[cdata.X.ncol*2+2*(cdata.X.nrow)*(cdata.X.nrow)+3*(cdata.X.nrow)];
-		if (!work) {perror("can not allocate work matrix");exit(1);}
+		if (!work) {
+			//perror("can not allocate work matrix");exit(1);
+			error("can not allocate work matrix");
+		}
 		double loglik[2];
 		int flag;
 		double sctest=1.0;

Modified: pkg/GenABEL/src/GAlib/reg1data.h
===================================================================
--- pkg/GenABEL/src/GAlib/reg1data.h	2011-12-07 10:10:37 UTC (rev 821)
+++ pkg/GenABEL/src/GAlib/reg1data.h	2011-12-07 10:29:51 UTC (rev 822)
@@ -86,8 +86,8 @@
 		ncov = regdat.ncov;
 		if (regdat.noutcomes != 2)
 		{
-			fprintf(stderr,"coxph_data: number of outcomes should be 2 (now: %d)\n",regdat.noutcomes);
-			exit(1);
+			//fprintf(stderr,"coxph_data: number of outcomes should be 2 (now: %d)\n",regdat.noutcomes);
+			error("coxph_data: number of outcomes should be 2");
 		}
 		X.reinit(nids,ncov);		
 		stime.reinit(nids,1);
@@ -102,8 +102,8 @@
 			sstat[i] = int((regdat.Y).get(i,1));
 			if (sstat[i] != 1 & sstat[i]!=0) 
 			{
-				fprintf(stderr,"coxph_data: status not 0/1 (right order: id, fuptime, status ...)\n");
-				exit(1);
+				//fprintf(stderr,"coxph_data: status not 0/1 (right order: id, fuptime, status ...)\n");
+				error("coxph_data: status not 0/1 (right order: id, fuptime, status ...)");
 			}
 		}
 		for (int j=0;j<ncov;j++) 
@@ -135,8 +135,8 @@
 				}
 			if (passed != 1) 
 			{
-				fprintf(stderr,"can not recover element %d\n",i);
-				exit(1);
+				//fprintf(stderr,"can not recover element %d\n",i);
+				error("can not recover element");
 			}
 		}
 		delete [] tmptime;



More information about the Genabel-commits mailing list