source:
issm/oecreview/Archive/12281-12300/ISSM-12291-12292.diff@
12325
Last change on this file since 12325 was 12325, checked in by , 13 years ago | |
---|---|
File size: 15.2 KB |
-
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/Container/Options.h
21 21 Option* GetOption(const char* name); 22 22 void Get(double* pvalue,const char* name); 23 23 void Get(double* pvalue,const char* name,double default_value); 24 void Get(int* pvalue,const char* name); 25 void Get(int* pvalue,const char* name,int default_value); 24 26 void Get(bool* pvalue,const char* name); 25 27 void Get(bool* pvalue,const char* name,bool default_value); 26 28 void Get(char** pvalue,const char* name); -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/Container/Observations.cpp
93 93 94 94 /*Methods*/ 95 95 /*FUNCTION Observations::ObservationList{{{*/ 96 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double ra nge){96 void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata){ 97 97 98 98 /*Output and Intermediaries*/ 99 int nobs,i,index; 99 bool stop; 100 int nobs,i,j,k,n,counter; 101 double h2,radius2; 102 int *indices = NULL; 103 double *dists = NULL; 100 104 double *x = NULL; 101 105 double *y = NULL; 102 106 double *obs = NULL; 103 107 Observation *observation = NULL; 104 int *indices = NULL;105 108 106 /*Treat range*/ 107 if(range==0){ 108 range=this->quadtree->root->length; 109 } 109 /*Compute radius square*/ 110 if(radius==0) radius=this->quadtree->root->length; 111 radius2 = radius*radius; 110 112 111 /*Find all observations that are in range*/ 112 nobs=0; 113 while(nobs==0){ 114 xfree((void**)&indices); 115 this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range); 116 if(!nobs){ 117 /*No observation found, double range*/ 118 range=2*range; 113 /*Find all observations that are in radius*/ 114 indices = (int*)xmalloc(this->Size()*sizeof(int)); 115 dists = (double*)xmalloc(this->Size()*sizeof(double)); 116 nobs = 0; 117 118 for (i=0;i<this->Size();i++){ 119 observation=(Observation*)this->GetObjectByOffset(i); 120 h2 = (observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp); 121 122 if(nobs==maxdata && h2>radius2) continue; 123 if(nobs<=maxdata){ 124 indices[nobs] = i; 125 dists[nobs] = h2; 126 nobs++; 119 127 } 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 //} 128 if(nobs==1) continue; 127 129 128 if(!nobs) _error_("Unexpected error: no observation within current range and more than 50 observations if doubling range"); 130 /*Sort all dists up to now*/ 131 n=nobs-1; 132 stop = false; 133 for(k=0;k<n-1;k++){ 134 if(h2<dists[k]){ 135 counter=1; 136 for(int jj=k;jj<n;jj++){ 137 j = n-counter; 138 dists[j+1] = dists[j]; 139 indices[j+1] = indices[j]; 140 counter++; 141 } 142 dists[k] = h2; 143 indices[k] = i; 144 stop = true; 145 break; 146 } 147 if(stop) break; 148 } 149 } 150 xfree((void**)&dists); 129 151 130 /*Allocate vectors*/ 131 x = (double*)xmalloc(nobs*sizeof(double)); 132 y = (double*)xmalloc(nobs*sizeof(double)); 133 obs = (double*)xmalloc(nobs*sizeof(double)); 152 if(nobs){ 153 /*Allocate vectors*/ 154 x = (double*)xmalloc(nobs*sizeof(double)); 155 y = (double*)xmalloc(nobs*sizeof(double)); 156 obs = (double*)xmalloc(nobs*sizeof(double)); 134 157 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]); 158 /*Loop over all observations and fill in x, y and obs*/ 159 for (i=0;i<nobs;i++){ 160 observation=(Observation*)this->GetObjectByOffset(indices[i]); 161 observation->WriteXYObs(&x[i],&y[i],&obs[i]); 162 } 139 163 } 140 164 141 165 /*Assign output pointer*/ -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/Container/Observations.h
22 22 ~Observations(); 23 23 24 24 /*Methods*/ 25 void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double ra nge);25 void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata); 26 26 void QuadtreeColoring(double* A,double *x,double *y,int n); 27 27 void Variomap(double* gamma,double *x,int n); 28 28 -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/Container/Options.cpp
66 66 return 1; 67 67 } 68 68 /*}}}*/ 69 /*FUNCTION Options::Get(int* pvalue, char* name){{{1*/ 70 void Options::Get(int* pvalue,const char* name){ 71 72 vector<Object*>::iterator object; 73 Option* option=NULL; 74 75 /*Get option*/ 76 option=GetOption(name); 77 78 /*If the pointer is not NULL, the option has been found*/ 79 if(option){ 80 option->Get(pvalue); 81 } 82 /*Else, the Option does not exist, no default provided*/ 83 else{ 84 _error_("option of name \"%s\" not found, and no default value has been provided",name); 85 } 86 } 87 /*}}}*/ 88 /*FUNCTION Options::Get(int* pvalue, char* name,int default_value){{{1*/ 89 void Options::Get(int* pvalue,const char* name,int default_value){ 90 91 vector<Object*>::iterator object; 92 Option* option=NULL; 93 94 /*Get option*/ 95 option=GetOption(name); 96 97 /*If the pointer is not NULL, the option has been found*/ 98 if(option){ 99 option->Get(pvalue); 100 } 101 /*Else, the Option does not exist, a default is provided here*/ 102 else{ 103 *pvalue=default_value; 104 } 105 } 106 /*}}}*/ 69 107 /*FUNCTION Options::Get(double* pvalue, char* name){{{1*/ 70 108 void Options::Get(double* pvalue,const char* name){ 71 109 -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/shared/Threads/LaunchThread.cpp
66 66 67 67 function((void*)&handle); 68 68 #endif 69 70 69 } -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
23 23 double *error = NULL; 24 24 25 25 /*Intermediaries*/ 26 double range; 26 int mindata,maxdata; 27 double radius; 27 28 char *output = NULL; 28 29 Variogram *variogram = NULL; 29 30 Observations *observations = NULL; … … 37 38 38 39 /*Get Variogram from Options*/ 39 40 ProcessVariogram(&variogram,options); 40 options->Get(&range,"searchrange",0.); 41 options->Get(&radius,"searchradius",0.); 42 options->Get(&mindata,"mindata",1); 43 options->Get(&maxdata,"maxdata",50); 41 44 42 45 /*Process observation dataset*/ 43 46 observations=new Observations(obs_list,obs_x,obs_y,obs_length,options); … … 61 64 gate.n_interp = n_interp; 62 65 gate.x_interp = x_interp; 63 66 gate.y_interp = y_interp; 64 gate.range = range; 67 gate.radius = radius; 68 gate.mindata = mindata; 69 gate.maxdata = maxdata; 65 70 gate.variogram = variogram; 66 71 gate.observations = observations; 67 72 gate.predictions = predictions; … … 105 110 int n_interp = gate->n_interp; 106 111 double *x_interp = gate->x_interp; 107 112 double *y_interp = gate->y_interp; 108 double range = gate->range; 113 double radius = gate->radius; 114 int mindata = gate->mindata; 115 int maxdata = gate->maxdata; 109 116 Variogram *variogram = gate->variogram; 110 117 Observations *observations = gate->observations; 111 118 double *predictions = gate->predictions; … … 136 143 printf("\r interpolation progress: %5.2lf%%",localpercent); 137 144 138 145 /*Get list of observations for current point*/ 139 observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],ra nge);140 if(n_obs ==0){141 predictions[idx] = -999. ;142 error[idx] = -999. ;146 observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],radius,maxdata); 147 if(n_obs<mindata){ 148 predictions[idx] = -999.0; 149 error[idx] = -999.0; 143 150 continue; 144 151 } 145 152 -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/modules/Krigingx/Krigingx.h
20 20 int n_interp; 21 21 double *x_interp; 22 22 double *y_interp; 23 double range; 23 double radius; 24 int mindata; 25 int maxdata; 24 26 Variogram *variogram; 25 27 Observations *observations; 26 28 double *predictions; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionStruct.h
38 38 int NumEl(); 39 39 int NDims(); 40 40 int* Size(); 41 void Get(int* pvalue){_error_("An OptionStruct object cannot return a int");}; 41 42 void Get(double* pvalue){_error_("An OptionStruct object cannot return a double");}; 42 43 void Get(bool* pvalue){ _error_("An OptionStruct object cannot return a bool");}; 43 44 void Get(char** pvalue){ _error_("An OptionStruct object cannot return a string");}; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionDouble.cpp
119 119 return(Option::Size()); 120 120 } 121 121 /*}}}*/ 122 /*FUNCTION OptionDouble::Get(int* pvalue) {{{1*/ 123 void OptionDouble::Get(int* pvalue){ 124 125 /*We should first check that the size is one*/ 126 if(this->NumEl()!=1){ 127 _error_("option \"%s\" has %i elements and cannot return a single int",this->name,this->NumEl()); 128 } 129 130 /*Assign output pointer*/ 131 *pvalue=(int)this->values[0]; 132 } 133 /*}}}*/ 122 134 /*FUNCTION OptionDouble::Get(double* pvalue) {{{1*/ 123 135 void OptionDouble::Get(double* pvalue){ 124 136 -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionDouble.h
38 38 int NumEl(); 39 39 int NDims(); 40 40 int* Size(); 41 void Get(int* pvalue); 41 42 void Get(double* pvalue); 42 43 void Get(bool* pvalue){ _error_("An OptionDouble object cannot return a bool");}; 43 44 void Get(char** pvalue){ _error_("An OptionDouble object cannot return a string");}; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionLogical.h
38 38 int NumEl(); 39 39 int NDims(); 40 40 int* Size(); 41 void Get(int* pvalue){_error_("An OptionLogical object cannot return a int");}; 41 42 void Get(double* pvalue){_error_("An OptionLogical object cannot return a double");}; 42 43 void Get(bool* pvalue); 43 44 void Get(char** pvalue){ _error_("An OptionLogical object cannot return a string");}; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionChar.h
38 38 int NumEl(); 39 39 int NDims(); 40 40 int* Size(); 41 void Get(int* pvalue){_error_("An OptionChar object cannot return a int");}; 41 42 void Get(double* pvalue){_error_("An OptionChar object cannot return a double");}; 42 43 void Get(bool* pvalue){ _error_("An OptionChar object cannot return a bool");}; 43 44 void Get(char** pvalue); -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/Option.h
41 41 virtual int NumEl()=0; 42 42 virtual int NDims()=0; 43 43 virtual int* Size()=0; 44 virtual void Get(int* pvalue)=0; 44 45 virtual void Get(double* pvalue)=0; 45 46 virtual void Get(bool* pvalue)=0; 46 47 virtual void Get(char** pvalue)=0; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Options/OptionCell.h
38 38 int NumEl(); 39 39 int NDims(); 40 40 int* Size(); 41 void Get(int* pvalue){_error_("An OptionCell object cannot return a int");}; 41 42 void Get(double* pvalue){_error_("An OptionCell object cannot return a double");}; 42 43 void Get(bool* pvalue){ _error_("An OptionCell object cannot return a bool");}; 43 44 void Get(char** pvalue){ _error_("An OptionCell object cannot return a string");}; -
proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp
74 74 a = 1./3.; 75 75 cova = (sill-nugget)*exp(-h2/(a*range*range)); 76 76 77 //if(h2<0.0000001) cova = sill;77 if(h2<0.0000001) cova = sill; 78 78 79 79 return cova; 80 80 }
Note:
See TracBrowser
for help on using the repository browser.