Changeset 12436


Ignore:
Timestamp:
06/15/12 17:02:02 (13 years ago)
Author:
Mathieu Morlighem
Message:

changing xmalloc to xNew and xfree to xDelete

Location:
issm/trunk-jpl/src/c/shared
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/shared/Alloc/alloc.cpp

    r12011 r12436  
    8484}
    8585
    86 
    8786void* xrealloc( void* pv, int size){
    8887       
  • issm/trunk-jpl/src/c/shared/Numerics/GaussPoints.cpp

    r12424 r12436  
    5252
    5353        //      _printf_(true,"Gauss-Legendre recurrence coefficients ngaus=%d\n",ngaus);
    54         *pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
    55         *pxwgt  = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
     54        *pxgaus =xNew<IssmPDouble>(ngaus);
     55        *pxwgt  =xNew<IssmPDouble>(ngaus);
    5656
    5757        /*  check to see if Gauss points need to be calculated  */
     
    7070
    7171                /*  calculate the Gauss points using recurrence relations  */
    72                 alpha=(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
    73                 beta =(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
     72                alpha=xNew<IssmPDouble>(ngaus);
     73                beta =xNew<IssmPDouble>(ngaus);
    7474
    7575                /*  calculate the Legendre recurrence coefficients  */
     
    8484                /*  calculate the Gauss points  */
    8585                GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta );
    86                 xfree((void **)&beta );
    87                 xfree((void **)&alpha);
     86                xDelete<IssmPDouble>(beta);
     87                xDelete<IssmPDouble>(alpha);
    8888        }
    8989}/*}}}*/
     
    11501150                *pngaus=np[iord-1];
    11511151
    1152                 *pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1153                 *pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1154                 *pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1155                 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
     1152                *pl1  =xNew<IssmPDouble>(*pngaus);
     1153                *pl2  =xNew<IssmPDouble>(*pngaus);
     1154                *pl3  =xNew<IssmPDouble>(*pngaus);
     1155                *pwgt =xNew<IssmPDouble>(*pngaus);
    11561156
    11571157                for (i=0; i<*pngaus; i++) {
     
    11681168                *pngaus=nigaus*nigaus;
    11691169
    1170                 *pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1171                 *pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1172                 *pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1173                 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
     1170                *pl1  =xNew<IssmPDouble>(*pngaus);
     1171                *pl2  =xNew<IssmPDouble>(*pngaus);
     1172                *pl3  =xNew<IssmPDouble>(*pngaus);
     1173                *pwgt =xNew<IssmPDouble>(*pngaus);
    11741174
    11751175                /*  get the gauss points in each direction  */
     
    11951195                        }
    11961196                }
    1197                 xfree((void **)&xwgt );
    1198                 xfree((void **)&xgaus);
     1197                xDelete<IssmPDouble>(xwgt );
     1198                xDelete<IssmPDouble>(xgaus);
    11991199        }
    12001200
     
    14101410                *pngaus=np[iord-1];
    14111411
    1412                 *pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1413                 *pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1414                 *pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1415                 *pl4  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1416                 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
     1412                *pl1  =xNew<IssmPDouble>(*pngaus);
     1413                *pl2  =xNew<IssmPDouble>(*pngaus);
     1414                *pl3  =xNew<IssmPDouble>(*pngaus);
     1415                *pl4  =xNew<IssmPDouble>(*pngaus);
     1416                *pwgt =xNew<IssmPDouble>(*pngaus);
    14171417
    14181418                for (i=0; i<*pngaus; i++) {
     
    14301430                *pngaus=nigaus*nigaus*nigaus;
    14311431
    1432                 *pl1  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1433                 *pl2  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1434                 *pl3  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1435                 *pl4  = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
    1436                 *pwgt = (IssmPDouble *) xmalloc(*pngaus*sizeof(IssmPDouble));
     1432                *pl1  =xNew<IssmPDouble>(*pngaus);
     1433                *pl2  =xNew<IssmPDouble>(*pngaus);
     1434                *pl3  =xNew<IssmPDouble>(*pngaus);
     1435                *pl4  =xNew<IssmPDouble>(*pngaus);
     1436                *pwgt =xNew<IssmPDouble>(*pngaus);
    14371437
    14381438                /*  get the gauss points in each direction  */
     
    14671467                        }
    14681468                }
    1469                 xfree((void **)&xwgt );
    1470                 xfree((void **)&xgaus);
     1469                xDelete<IssmPDouble>(xwgt );
     1470                xDelete<IssmPDouble>(xgaus);
    14711471        }
    14721472}/*}}}*/
     
    15221522
    15231523        //      _printf_(true,"Gauss-Lobatto recurrence coefficients ngaus=%d\n",ngaus);
    1524         *pxgaus = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
    1525         *pxwgt  = (IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
     1524        *pxgaus =xNew<IssmPDouble>(ngaus);
     1525        *pxwgt  =xNew<IssmPDouble>(ngaus);
    15261526
    15271527        /*  check to see if Gauss points need to be calculated  */
     
    15391539
    15401540                /*  calculate the Gauss points using recurrence relations  */
    1541                 alpha=(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
    1542                 beta =(IssmPDouble *) xmalloc(ngaus*sizeof(IssmPDouble));
     1541                alpha=xNew<IssmPDouble>(ngaus);
     1542                beta =xNew<IssmPDouble>(ngaus);
    15431543
    15441544                /*  calculate the Legendre recurrence coefficients  */
     
    15751575                /*  calculate the Gauss points  */
    15761576                GaussRecur(*pxgaus, *pxwgt, ngaus, alpha, beta );
    1577                 xfree((void **)&beta );
    1578                 xfree((void **)&alpha);
     1577                xDelete<IssmPDouble>(beta );
     1578                xDelete<IssmPDouble>(alpha);
    15791579        }
    15801580
     
    15981598        }
    15991599
    1600         work=(IssmPDouble*)xmalloc(n*sizeof(IssmPDouble));
     1600        work=xNew<IssmPDouble>(n);
    16011601
    16021602        zero[0]  =alpha[0];
     
    16691669                } while (iter < MAX_GAUS_ITER);
    16701670                if (iter >= MAX_GAUS_ITER) {
    1671                         xfree((void **)&work);
     1671                        xDelete<IssmPDouble>(work);
    16721672                        _error_("%s%i"," Max iterations exceeded for l=",MAX_GAUS_ITER);
    16731673                }
     
    16981698
    16991699        /*Cleanup*/
    1700         xfree((void **)&work);
     1700        xDelete<IssmPDouble>(work);
    17011701
    17021702}/*}}}*/
  • issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp

    r12086 r12436  
    77#include "./trimesh.h"
    88#include "../Exceptions/exceptions.h"
     9#include "../Alloc/xNewDelete.h"
    910#include "../Alloc/alloc.h"
    1011#include "../../include/include.h"
     
    5354        current_size=max_number_elements;
    5455        NumGridElements=0;
    55         GridElements=(int*)xmalloc(max_number_elements*sizeof(int));
     56        GridElements=xNew<int>(max_number_elements);
    5657
    5758        for (i=0;i<nel;i++){
     
    8182        cleanup_and_return:
    8283        if(!noerr){
    83                 xfree((void**)&GridElements);
     84                xDelete<int>(GridElements);
    8485        }
    8586        /*Allocate return pointers: */
     
    165166
    166167        /*Compress riftsegments_uncompressed:*/
    167         riftsegments=(int*)xmalloc(nriftsegs*4*sizeof(int));
     168        riftsegments=xNew<int>(nriftsegs*4);
    168169        counter=0;
    169170        for (i=0;i<nsegs;i++){
     
    177178        }
    178179
    179         xfree((void**)&riftsegments_uncompressed);
     180        xDelete<int>(riftsegments_uncompressed);
    180181       
    181182        /*Assign output pointers: */
     
    202203        /*Figure out the list of elements  that are on the same side of the rift. To do so, we start from one
    203204         * side of the rift and keep rotating in the same direction:*/
    204         GridElementListOnOneSideOfRift=(int*)xmalloc(NumGridElements*sizeof(int));
     205        GridElementListOnOneSideOfRift=xNew<int>(NumGridElements);
    205206        //bootstrap the GridElementListOnOneSideOfRift by filling elements from riftsegments: */
    206207        GridElementListOnOneSideOfRift[0]=*(riftsegments+4*segmentnumber+0); /*this one does not belong to the same side, but is just there
     
    241242
    242243        /*Free ressources: */
    243         xfree((void**)&GridElements);
     244        xDelete<int>(GridElements);
    244245        /*Assign output pointers: */
    245246        *pNumGridElementListOnOneSideOfRift=NumGridElementListOnOneSideOfRift;
     
    380381
    381382        /*input: */
    382         double* segments=NULL;
    383         double* segmentmarkerlist=NULL;
     383        double *segments          = NULL;
     384        double *segmentmarkerlist = NULL;
    384385        int numsegs;
    385386       
    386387        /*output: */
    387         int* riftsnumsegs=NULL;
    388         double** riftssegments=NULL;
    389         int new_numsegs;
    390         double* new_segments=NULL;
    391         double* new_segmentmarkers=NULL;
     388        int      new_numsegs;
     389        int     *riftsnumsegs       = NULL;
     390        double **riftssegments      = NULL;
     391        double  *new_segments       = NULL;
     392        double  *new_segmentmarkers = NULL;
    392393
    393394        /*intermediary: */
     
    406407        /*Allocate new segments: */
    407408        new_numsegs=counter;
    408         new_segments=(double*)xmalloc(new_numsegs*3*sizeof(double));
    409         new_segmentmarkers=(double*)xmalloc(new_numsegs*sizeof(double));
     409        new_segments=xNew<double>(new_numsegs*3);
     410        new_segmentmarkers=xNew<double>(new_numsegs);
    410411
    411412        /*Copy new segments info : */
     
    422423
    423424        /*Now deal with rift segments: */
    424         riftsnumsegs=(int*)xmalloc(numrifts*sizeof(int));
    425         riftssegments=(double**)xmalloc(numrifts*sizeof(double*));
     425        riftsnumsegs=xNew<int>(numrifts);
     426        riftssegments=xNew<double*>(numrifts);
    426427        for (i=0;i<numrifts;i++){
    427428                /*Figure out how many segments for rift i: */
     
    431432                }
    432433                riftsnumsegs[i]=counter;
    433                 riftsegment=(double*)xmalloc(counter*3*sizeof(double));
     434                riftsegment=xNew<double>(counter*3);
    434435                /*Copy new segments info :*/
    435436                counter=0;
     
    446447
    447448        /*Free ressources: */
    448         xfree((void**)&segments);
     449        xDelete<double>(segments);
    449450
    450451        /*Assign output pointers: */
     
    465466
    466467        /*output: */
    467         int* riftsnumpairs=NULL;
    468         double** riftspairs=NULL;
     468        int     *riftsnumpairs = NULL;
     469        double **riftspairs    = NULL;
    469470
    470471        /*intermediary :*/
     
    474475        int     node1,node2,node3,node4;
    475476
    476         riftsnumpairs=(int*)xmalloc(numrifts*sizeof(int));
    477         riftspairs=(double**)xmalloc(numrifts*sizeof(double*));
     477        riftsnumpairs=xNew<int>(numrifts);
     478        riftspairs=xNew<double*>(numrifts);
    478479        for (i=0;i<numrifts;i++){
    479480                segments=riftssegments[i];
    480481                numsegs=riftsnumsegments[i];
    481482                riftsnumpairs[i]=numsegs;
    482                 pairs=(double*)xmalloc(2*numsegs*sizeof(double));
     483                pairs=xNew<double>(2*numsegs);
    483484                for (j=0;j<numsegs;j++){
    484485                        *(pairs+2*j+0)=*(segments+3*j+2); //retrieve element to which this segment belongs.
     
    500501        }
    501502
    502 
    503503        /*Assign output pointers: */
    504504        *priftsnumpairs=riftsnumpairs;
    505505        *priftspairs=riftspairs;
    506 
    507506        return noerr;
    508507}/*}}}*/
     
    522521
    523522        /*intermediary: */
    524         double* riftsegments=NULL;
    525         double* riftpairs=NULL;
     523        double *riftsegments = NULL;
     524        double *riftpairs    = NULL;
    526525        int     node1,node2,node3,node4,temp_node;
    527526        double  el2;
    528527        int     newnods; //temporary # node counter.
    529528        double  xmin,ymin;
    530         double* xreal=NULL;
    531         double* yreal=NULL;
    532         int* nodes=NULL;
    533         int* mergingnodes=NULL;
     529        double *xreal        = NULL;
     530        double *yreal        = NULL;
     531        int    *nodes        = NULL;
     532        int    *mergingnodes = NULL;
    534533        int     max_size;
    535534        int     redundant;
    536 
    537535
    538536        /*Recover input: */
     
    562560                max_size+=rifts1numsegs[i];
    563561        }
    564         nodes=(int*)xmalloc(max_size*sizeof(int));
    565         mergingnodes=(int*)xmalloc(max_size*sizeof(int));
     562        nodes=xNew<int>(max_size);
     563        mergingnodes=xNew<int>(max_size);
    566564
    567565        /*Go through the rifts segments, and identify which node we are going to merge with its counterpart on the other side
     
    678676                }
    679677        }
    680         xfree((void**)&x); x=xreal;
    681         xfree((void**)&y); y=yreal;
     678        xDelete<double>(x); x=xreal;
     679        xDelete<double>(y); y=yreal;
    682680
    683681        /*Assign output pointers:*/
     
    688686        *psegments=segments;
    689687        *pnumsegs=numsegs;
    690 
    691688        return noerr;
    692689}/*}}}*/
     
    716713        *priftflag=riftflag;
    717714        *pnumrifts=numrifts;
    718 
    719715        return noerr;
    720716}/*}}}*/
     
    726722
    727723        /*intermediary: */
    728         double* riftsegments=NULL;
    729         double* riftpairs=NULL;
     724        double *riftsegments = NULL;
     725        double *riftpairs    = NULL;
    730726        int numsegs;
    731727
    732728        /*ordering and copy: */
    733         int*    order=NULL;
    734         double* riftsegments_copy=NULL;
    735         double* riftpairs_copy=NULL;
     729        int    *order             = NULL;
     730        double *riftsegments_copy = NULL;
     731        double *riftpairs_copy    = NULL;
    736732
    737733        /*node and element manipulation: */
     
    744740
    745741        /*Allocate byproduct of this routine, riftstips: */
    746         riftstips=(double*)xmalloc(numrifts*2*sizeof(double));
     742        riftstips=xNew<double>(numrifts*2);
    747743
    748744        /*Go through all rifts: */
     
    754750                /*Allocate copy of riftsegments and riftpairs,
    755751                 *as well as ordering vector: */
    756                 riftsegments_copy=(double*)xmalloc(numsegs*3*sizeof(double));
    757                 riftpairs_copy=(double*)xmalloc(numsegs*2*sizeof(double));
    758                 order=(int*)xmalloc(numsegs*sizeof(int));
     752                riftsegments_copy=xNew<double>(numsegs*3);
     753                riftpairs_copy=xNew<double>(numsegs*2);
     754                order=xNew<int>(numsegs);
    759755
    760756                /*First find the tips, using the pairs. If a pair of elements has one node in common, this node is a rift tip: */
     
    814810                *(riftstips+2*i+0)=(double)tip1;
    815811                *(riftstips+2*i+1)=(double)tip2;
    816 
    817812
    818813                /*We have the two tips for this rift.  Go from tip1 to tip2, and figure out the order in which segments are sequential.
     
    865860                }
    866861
    867                 xfree((void**)&order);
    868                 xfree((void**)&riftsegments_copy);
    869                 xfree((void**)&riftpairs_copy);
     862                xDelete<int>(order);
     863                xDelete<double>(riftsegments_copy);
     864                xDelete<double>(riftpairs_copy);
    870865
    871866        }
     
    887882
    888883        /*output: */
    889         double** riftspenaltypairs=NULL;
    890         double*  riftpenaltypairs=NULL;
    891         int*     riftsnumpenaltypairs=NULL;
     884        double **riftspenaltypairs    = NULL;
     885        double  *riftpenaltypairs     = NULL;
     886        int     *riftsnumpenaltypairs = NULL;
    892887
    893888        /*intermediary: */
     
    901896
    902897        /*Allocate: */
    903         riftspenaltypairs=(double**)xmalloc(numrifts*sizeof(double*));
    904         riftsnumpenaltypairs=(int*)xmalloc(numrifts*sizeof(int));
     898        riftspenaltypairs=xNew<double*>(numrifts);
     899        riftsnumpenaltypairs=xNew<int>(numrifts);
    905900
    906901        for(i=0;i<numrifts;i++){
     
    910905
    911906                /*allocate riftpenaltypairs, and riftnumpenaltypairs: */
    912                 if((numsegs/2-1)!=0)riftpenaltypairs=(double*)xcalloc((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,sizeof(double));
     907                if((numsegs/2-1)!=0)riftpenaltypairs=xNewInit<double>((numsegs/2-1)*RIFTPENALTYPAIRSWIDTH,0.0);
    913908               
    914909                /*Go through only one flank of the rifts, not counting the tips: */
     
    10061001                riftsnumpenaltypairs[i]=(numsegs/2-1);
    10071002        }
    1008                        
    1009 
    10101003
    10111004        /*Assign output pointers: */
    10121005        *priftspenaltypairs=riftspenaltypairs;
    10131006        *priftsnumpenaltypairs=riftsnumpenaltypairs;
    1014 
    10151007        return noerr;
    10161008}
     
    11431135        *py=y;
    11441136        *pnods=nods;
    1145 
    11461137        return noerr;
    11471138}
Note: See TracChangeset for help on using the changeset viewer.