JWS-112 Bumping version of Mafft to version 7.310.
[jabaws.git] / binaries / src / mafft / core / mtxutl.c
index d88e79f..263176d 100644 (file)
@@ -129,11 +129,11 @@ void FreeCharMtx( char **mtx )
        free( mtx );
 }
 
-float *AllocateFloatVec( int l1 )
+double *AllocateFloatVec( int l1 )
 {
-       float *vec;
+       double *vec;
 
-       vec = (float *)calloc( (unsigned int)l1, sizeof( float ) );
+       vec = (double *)calloc( (unsigned int)l1, sizeof( double ) );
        if( vec == NULL )
        {
                fprintf( stderr, "Allocation error ( %d fload vec )\n", l1 );
@@ -142,17 +142,17 @@ float *AllocateFloatVec( int l1 )
        return( vec );
 }
 
-void FreeFloatVec( float *vec )
+void FreeFloatVec( double *vec )
 {
        free( (char *)vec );
 }
 
-float **AllocateFloatHalfMtx( int ll1 )
+double **AllocateFloatHalfMtx( int ll1 )
 {
-       float **mtx;
+       double **mtx;
        int i;
 
-       mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       mtx = (double **)calloc( (unsigned int)ll1+1, sizeof( double * ) );
        if( mtx == NULL )
        {
                fprintf( stderr, "Allocation error ( %d fload halfmtx )\n", ll1 );
@@ -160,10 +160,10 @@ float **AllocateFloatHalfMtx( int ll1 )
        }
        for( i=0; i<ll1; i++ )
        {
-               mtx[i] = (float *)calloc( ll1-i, sizeof( float ) );
+               mtx[i] = (double *)calloc( ll1-i, sizeof( double ) );
                if( !mtx[i] )
                {
-                       fprintf( stderr, "Allocation error( %d floathalfmtx )\n", ll1 );
+                       fprintf( stderr, "Allocation error( %d doublehalfmtx )\n", ll1 );
                        exit( 1 );
                }
        }
@@ -171,12 +171,12 @@ float **AllocateFloatHalfMtx( int ll1 )
        return( mtx );
 }
 
-float **AllocateFloatMtx( int ll1, int ll2 )
+double **AllocateFloatMtx( int ll1, int ll2 )
 {
-       float **mtx;
+       double **mtx;
        int i;
 
-       mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       mtx = (double **)calloc( (unsigned int)ll1+1, sizeof( double * ) );
        if( mtx == NULL )
        {
                fprintf( stderr, "Allocation error ( %d x %d fload mtx )\n", ll1, ll2 );
@@ -186,10 +186,10 @@ float **AllocateFloatMtx( int ll1, int ll2 )
        {
                for( i=0; i<ll1; i++ )
                {
-                       mtx[i] = (float *)calloc( ll2, sizeof( float ) );
+                       mtx[i] = (double *)calloc( ll2, sizeof( double ) );
                        if( !mtx[i] )
                        {
-                               fprintf( stderr, "Allocation error( %d x %d floatmtx )\n", ll1, ll2 );
+                               fprintf( stderr, "Allocation error( %d x %d doublemtx )\n", ll1, ll2 );
                                exit( 1 );
                        }
                }
@@ -198,27 +198,40 @@ float **AllocateFloatMtx( int ll1, int ll2 )
        return( mtx );
 }
 
-void FreeFloatHalfMtx( float **mtx, int n )
+void FreeFloatHalfMtx( double **mtx, int n )
 {
        int i;
 
        for( i=0; i<n; i++ ) 
        {
-               if( mtx[i] ) FreeFloatVec( mtx[i] );
+               if( mtx[i] ) FreeFloatVec( mtx[i] ); mtx[i] = NULL;
        }
        free( mtx );
 }
-void FreeFloatMtx( float **mtx )
+void FreeFloatMtx( double **mtx )
 {
        int i;
 
        for( i=0; mtx[i]; i++ ) 
        {
-               FreeFloatVec( mtx[i] );
+               if( mtx[i] ) FreeFloatVec( mtx[i] ); mtx[i] = NULL;
        }
        free( mtx );
 }
 
+int *AllocateIntVecLarge( unsigned long long ll1 )
+{
+       int *vec;
+
+       vec = (int *)calloc( ll1, sizeof( int ) );
+       if( vec == NULL )
+       {       
+               fprintf( stderr, "Allocation error( %lld int vec )\n", ll1 );
+               exit( 1 );
+       }
+       return( vec );
+}      
+
 int *AllocateIntVec( int ll1 )
 {
        int *vec;
@@ -237,15 +250,15 @@ void FreeIntVec( int *vec )
        free( (char *)vec );
 }
 
-float **AllocateFloatTri( int ll1 )
+double **AllocateFloatTri( int ll1 )
 {
-       float **tri;
+       double **tri;
        int i;
 
-       tri = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       tri = (double **)calloc( (unsigned int)ll1+1, sizeof( double * ) );
        if( !tri )
        {
-               fprintf( stderr, "Allocation error ( float tri )\n" );
+               fprintf( stderr, "Allocation error ( double tri )\n" );
                exit( 1 );
        }
        for( i=0; i<ll1; i++ ) 
@@ -257,10 +270,10 @@ float **AllocateFloatTri( int ll1 )
        return( tri );
 }
 
-void FreeFloatTri( float **tri )
+void FreeFloatTri( double **tri )
 {
 /*
-       float **x;
+       double **x;
        x = tri;
        while( *tri != NULL ) free( *tri++ );
        free( x );
@@ -284,10 +297,34 @@ int **AllocateIntMtx( int ll1, int ll2 )
        }
        if( ll2 )
        {
-               for( i=0; i<ll1; i++ ) 
-               {
-                       mtx[i] = AllocateIntVec( ll2 );
-               }
+               for( i=0; i<ll1; i++ ) mtx[i] = AllocateIntVec( ll2 );
+       }
+       else
+       {
+               for( i=0; i<ll1; i++ ) mtx[i] = NULL;
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
+int **AllocateIntMtxLarge( unsigned long long ll1, unsigned long long ll2 )
+{
+       unsigned long long i;
+       int **mtx;
+
+       mtx = (int **)calloc( ll1+1, sizeof( int * ) );
+       if( !mtx )
+       {
+               fprintf( stderr, "Allocation error( %lld x %lld int mtx )\n", ll1, ll2 );
+               exit( 1 );
+       }
+       if( ll2 )
+       {
+               for( i=0; i<ll1; i++ ) mtx[i] = AllocateIntVecLarge( ll2 );
+       }
+       else
+       {
+               for( i=0; i<ll1; i++ ) mtx[i] = NULL;
        }
        mtx[ll1] = NULL;
        return( mtx );
@@ -342,12 +379,11 @@ void FreeCharCub( char ***cub )
        free( cub );
 }
 
-void freeintmtx( int **mtx, int ll1, int ll2 )
+void freeintmtx( int **mtx, int ll1 )
 {
     int i;
 
-    for( i=0; i<ll1; i++ ) 
-        free( (char *)mtx[i] );
+    for( i=0; i<ll1; i++ ) free( (char *)mtx[i] );
     free( (char *)mtx );
 }
       
@@ -356,7 +392,9 @@ void FreeIntMtx( int **mtx )
        int i;
 
        for( i=0; mtx[i]; i++ ) 
-               free( (char *)mtx[i] );
+       {
+               if( mtx[i] ) free( (char *)mtx[i] ); mtx[i] = NULL;
+       }
        free( (char *)mtx );
 }
 
@@ -387,7 +425,7 @@ double *AllocateDoubleVec( int ll1 )
 {
        double *vec;
 
-       vec = (double *)calloc( ll1, sizeof( double ) );
+       vec = (double *)calloc( ll1, sizeof( double ) ); // filled with 0.0
        return( vec );
 }
 
@@ -419,11 +457,35 @@ void FreeIntCub( int ***cub )
        int i;
        for( i=0; cub[i]; i++ ) 
        {
-               FreeIntMtx( cub[i] );
+               if( cub[i] ) FreeIntMtx( cub[i] ); cub[i] = NULL;
        }
        free( cub );
 }
 
+double **AllocateDoubleHalfMtx( int ll1 )
+{
+       double **mtx;
+       int i;
+
+       mtx = (double **)calloc( (unsigned int)ll1+1, sizeof( double * ) );
+       if( mtx == NULL )
+       {
+               fprintf( stderr, "Allocation error ( %d double halfmtx )\n", ll1 );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ )
+       {
+               mtx[i] = (double *)calloc( ll1-i, sizeof( double ) );
+               if( !mtx[i] )
+               {
+                       fprintf( stderr, "Allocation error( %d double halfmtx )\n", ll1 );
+                       exit( 1 );
+               }
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
 double **AllocateDoubleMtx( int ll1, int ll2 )
 {
        int i;
@@ -444,6 +506,16 @@ double **AllocateDoubleMtx( int ll1, int ll2 )
        return mtx;
 }
 
+void FreeDoubleHalfMtx( double **mtx, int n )
+{
+       int i;
+
+       for( i=0; i<n; i++ ) 
+       {
+               if( mtx[i] ) FreeFloatVec( mtx[i] ); mtx[i] = NULL;
+       }
+       free( mtx );
+}
 void FreeDoubleMtx( double **mtx )
 {
        int i;
@@ -452,15 +524,15 @@ void FreeDoubleMtx( double **mtx )
        free( mtx );
 }
 
-float ***AllocateFloatCub( int ll1, int ll2, int  ll3 )
+double ***AllocateFloatCub( int ll1, int ll2, int  ll3 )
 {
        int i;
-       float ***cub;
+       double ***cub;
 
-       cub = (float ***)calloc( ll1+1, sizeof( float ** ) );
+       cub = (double ***)calloc( ll1+1, sizeof( double ** ) );
        if( !cub ) 
        {
-               fprintf( stderr, "cannot allocate float cube.\n" );
+               fprintf( stderr, "cannot allocate double cube.\n" );
                exit( 1 );
        }
        for( i=0; i<ll1; i++ ) 
@@ -471,7 +543,7 @@ float ***AllocateFloatCub( int ll1, int ll2, int  ll3 )
        return( cub );
 }
 
-void FreeFloatCub( float ***cub )
+void FreeFloatCub( double ***cub )
 {
        int i;