[Picante-commits] r149 - branches/gsoc/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 23 06:23:19 CEST 2008


Author: skembel
Date: 2008-07-23 06:23:19 +0200 (Wed, 23 Jul 2008)
New Revision: 149

Modified:
   branches/gsoc/src/picante.c
Log:
Format picante.c to fix indent ugliness and add include R.h to eliminate implicit declaration warnings

Modified: branches/gsoc/src/picante.c
===================================================================
--- branches/gsoc/src/picante.c	2008-07-23 03:58:00 UTC (rev 148)
+++ branches/gsoc/src/picante.c	2008-07-23 04:23:19 UTC (rev 149)
@@ -1,75 +1,76 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <R.h>
 #include <Rmath.h>
 
 int intrand(int n) {
-  double u;
-  u = unif_rand();
-  return((int)(u*n));
+    double u;
+    u = unif_rand();
+    return((int)(u*n));
 }
 
 /* inefficient but probably not important;
  * allocate and copy in vector to matrix */
 double **vectomat(double *v,int row,int column) {
-  int i,j;
-  double **m;
-
-  m = (double **)R_alloc(row,sizeof(double *));
-  for (i=0; i<row; i++) {
-    m[i] = (double *)R_alloc(column,sizeof(double));
-    for (j=0; j<column; j++) {
-      m[i][j] = v[row*j+i];  /* R uses column-first ordering */
+    int i,j;
+    double **m;
+    
+    m = (double **)R_alloc(row,sizeof(double *));
+    for (i=0; i<row; i++) {
+        m[i] = (double *)R_alloc(column,sizeof(double));
+        for (j=0; j<column; j++) {
+            m[i][j] = v[row*j+i];  /* R uses column-first ordering */
+        }
     }
-  }
-  return(m);
+    return(m);
 }
 
 /* copy matrix back into vector */
 void mattovec(double *v,double **m,int row,int column) {
-  int i,j,k;
-  k=0;
-  for (j=0; j<column; j++) {
-    for (i=0; i<row; i++) {
-      v[k++] = m[i][j];
-    } 
-  }
+    int i,j,k;
+    k=0;
+    for (j=0; j<column; j++) {
+        for (i=0; i<row; i++) {
+            v[k++] = m[i][j];
+        } 
+    }
 }
 
 
 void trialswap(double *v, int *pintervals, int * prow, int * pcolumn) {
-  long int trial;
-  int i,j,k,l;
-  int row, column;
-  int intervals;
+    long int trial;
+    int i,j,k,l;
+    int row, column;
+    int intervals;
 	double tmp;
-  double **m;
-
-  row = *prow;
-  column = *pcolumn;
-  intervals = *pintervals;
-
-  m = vectomat(v,row,column);
-
-  GetRNGstate();
-  for(trial=0;trial<intervals;trial++)
+    double **m;
+    
+    row = *prow;
+    column = *pcolumn;
+    intervals = *pintervals;
+    
+    m = vectomat(v,row,column);
+    
+    GetRNGstate();
+    for(trial=0;trial<intervals;trial++)
     {
-      i=intrand(row);
-      while((j=intrand(row))==i);
-      k=intrand(column);
-      while((l=intrand(column))==k);
-      if((m[i][k]>0.0 && m[j][l]>0.0 && m[i][l]+m[j][k]==0.0)||(m[i][k]+m[j][l]==0.0 && m[i][l]>0.0 && m[j][k]>0.0))
+        i=intrand(row);
+        while((j=intrand(row))==i);
+        k=intrand(column);
+        while((l=intrand(column))==k);
+        if((m[i][k]>0.0 && m[j][l]>0.0 && m[i][l]+m[j][k]==0.0)||(m[i][k]+m[j][l]==0.0 && m[i][l]>0.0 && m[j][k]>0.0))
 		{
 			//currently swaps abundances within columns (=species)
 			//should have a switch to swap abundances within rows, columns, or random
-		  tmp = m[i][k];
-		  m[i][k] = m[j][k];
-		  m[j][k] = tmp;
-		  tmp = m[i][l];
-		  m[i][l] = m[j][l];
-		  m[j][l] = tmp;
+			tmp = m[i][k];
+			m[i][k] = m[j][k];
+			m[j][k] = tmp;
+			tmp = m[i][l];
+			m[i][l] = m[j][l];
+			m[j][l] = tmp;
 		}
     }
-  mattovec(v,m,row,column);
-  PutRNGstate();
+    mattovec(v,m,row,column);
+    PutRNGstate();
 }



More information about the Picante-commits mailing list