Changeset 12282


Ignore:
Timestamp:
05/24/12 09:31:58 (13 years ago)
Author:
Mathieu Morlighem
Message:

minor: better deal with nobs=0

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Container/Observations.cpp

    r12273 r12282  
    110110
    111111        /*Find all observations that are in range*/
    112         this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range);
    113 
    114         if(nobs==0){
    115                 /*No observation found, double range*/
    116                 //printf("No observation found within range, doubling range\n");
     112        nobs=0;
     113        while(nobs==0){
    117114                xfree((void**)&indices);
    118                 this->ObservationList(&x,&y,&obs,&nobs,x_interp,y_interp,range*2);
    119         }
    120         else{
    121                 //if(nobs>1000) printf("Taking more than 1000 observations\n");
    122                 /*Allocate vectors*/
    123                 x   = (double*)xmalloc(nobs*sizeof(double));
    124                 y   = (double*)xmalloc(nobs*sizeof(double));
    125                 obs = (double*)xmalloc(nobs*sizeof(double));
    126 
    127                 /*Loop over all observations and fill in x, y and obs*/
    128                 for (i=0;i<nobs;i++){
    129                         observation=(Observation*)this->GetObjectByOffset(indices[i]);
    130                         observation->WriteXYObs(&x[i],&y[i],&obs[i]);
    131                 }
     115                this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range);
     116                if(!nobs){
     117                        /*No observation found, double range*/
     118                        range=2*range;
     119                }
     120        }
     121        /*Check that we do not have more than 50 observations*/
     122        //while(nobs>50){
     123        //      range=range/2;
     124        //      xfree((void**)&indices);
     125        //      this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range);
     126        //}
     127
     128        if(!nobs) _error_("Unexpected error: no observation within current range and more than 50 observations if doubling range");
     129
     130        /*Allocate vectors*/
     131        x   = (double*)xmalloc(nobs*sizeof(double));
     132        y   = (double*)xmalloc(nobs*sizeof(double));
     133        obs = (double*)xmalloc(nobs*sizeof(double));
     134
     135        /*Loop over all observations and fill in x, y and obs*/
     136        for (i=0;i<nobs;i++){
     137                observation=(Observation*)this->GetObjectByOffset(indices[i]);
     138                observation->WriteXYObs(&x[i],&y[i],&obs[i]);
    132139        }
    133140
  • issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp

    r12200 r12282  
    6969        /*return semi-variogram*/
    7070        a     = 1./3.;
    71         gamma = (sill-nugget)*(1-exp(-h2/(a*pow(range,2.)))) + nugget;
     71        gamma = (sill-nugget)*(1.-exp(-h2/(a*range*range))) + nugget;
    7272        return gamma;
    7373}
Note: See TracChangeset for help on using the changeset viewer.