[12377] | 1 | /*!\file: kriging.cpp
|
---|
| 2 | * \brief: kriging main parallel program
|
---|
[25836] | 3 | */
|
---|
[12377] | 4 |
|
---|
[14919] | 5 | #include "./issm.h"
|
---|
[12377] | 6 |
|
---|
| 7 | /*Local prototypes*/
|
---|
[13277] | 8 | void ProcessArguments2(char** pbinfilename,char** poutbinfilename,char** plockfilename,char** prootpath,int argc,char **argv);
|
---|
[25836] | 9 | void ProcessInputfile(double **px,double **py,double **pdata,int *pnobs,double **px_interp,double **py_interp,int *pninterp,Options **poptions,FILE* fid);
|
---|
[12377] | 10 |
|
---|
| 11 | int main(int argc,char **argv){
|
---|
| 12 |
|
---|
| 13 | /*I/O: */
|
---|
| 14 | FILE *output_fid = NULL;
|
---|
| 15 | FILE *input_fid = NULL;
|
---|
| 16 |
|
---|
| 17 | /*File names*/
|
---|
| 18 | char *lockfilename = NULL;
|
---|
| 19 | char *binfilename = NULL;
|
---|
| 20 | char *outbinfilename = NULL;
|
---|
[13277] | 21 | char *rootpath = NULL;
|
---|
[12377] | 22 |
|
---|
| 23 | /*Input*/
|
---|
[13267] | 24 | int ninterp,nobs;
|
---|
[25836] | 25 | double *x = NULL;
|
---|
| 26 | double *y = NULL;
|
---|
| 27 | double *data = NULL;
|
---|
| 28 | double *x_interp = NULL;
|
---|
| 29 | double *y_interp = NULL;
|
---|
[13267] | 30 | Options *options = NULL;
|
---|
[12377] | 31 |
|
---|
| 32 | /*Output*/
|
---|
[25836] | 33 | double *predictions = NULL;
|
---|
| 34 | double *error = NULL;
|
---|
[12377] | 35 |
|
---|
[13531] | 36 | /*Initialize exception trapping: */
|
---|
| 37 | ExceptionTrapBegin();
|
---|
[12377] | 38 |
|
---|
[13531] | 39 | /*Initialize environment (MPI, PETSC, MUMPS, etc ...)*/
|
---|
[16137] | 40 | ISSM_MPI_Comm comm=EnvironmentInit(argc,argv);
|
---|
[14330] | 41 | IssmComm::SetComm(comm);
|
---|
[12377] | 42 |
|
---|
[13277] | 43 | ProcessArguments2(&binfilename,&outbinfilename,&lockfilename,&rootpath,argc,argv);
|
---|
[12377] | 44 |
|
---|
| 45 | /*Process input files*/
|
---|
| 46 | input_fid=pfopen(binfilename,"rb");
|
---|
| 47 | ProcessInputfile(&x,&y,&data,&nobs,&x_interp,&y_interp,&ninterp,&options,input_fid);
|
---|
| 48 | pfclose(input_fid,binfilename);
|
---|
| 49 |
|
---|
[15104] | 50 | _printf0_("call computational core:\n");
|
---|
[12377] | 51 | pKrigingx(&predictions,&error,x,y,data,nobs,x_interp,y_interp,ninterp,options);
|
---|
| 52 |
|
---|
[15104] | 53 | _printf0_("write results to disk:\n");
|
---|
[12377] | 54 | Results *results = new Results();
|
---|
[14330] | 55 | if(IssmComm::GetRank()==0){
|
---|
[16137] | 56 | output_fid=pfopen0(outbinfilename,"wb");
|
---|
[21341] | 57 | results->AddObject(new GenericExternalResult<double*>(results->Size()+1,"predictions",predictions,ninterp,1,1,0));
|
---|
| 58 | results->AddObject(new GenericExternalResult<double*>(results->Size()+1,"error",error,ninterp,1,1,0));
|
---|
[25836] | 59 | for(Object* & object :results->objects){
|
---|
| 60 | ExternalResult* result=xDynamicCast<ExternalResult*>(object);
|
---|
[12381] | 61 | result->WriteData(output_fid,1);
|
---|
| 62 | }
|
---|
| 63 | pfclose(output_fid,outbinfilename);
|
---|
[12377] | 64 | }
|
---|
| 65 |
|
---|
[14624] | 66 | /*Close output and toolkits options file and write lock file if requested*/
|
---|
[15104] | 67 | _printf0_("write lock file:\n");
|
---|
[12377] | 68 | WriteLockFile(lockfilename);
|
---|
| 69 |
|
---|
[27232] | 70 | /*Free resources: */
|
---|
[12439] | 71 | xDelete<char>(lockfilename);
|
---|
| 72 | xDelete<char>(binfilename);
|
---|
| 73 | xDelete<char>(outbinfilename);
|
---|
[13277] | 74 | xDelete<char>(rootpath);
|
---|
[25836] | 75 | xDelete<double>(x);
|
---|
| 76 | xDelete<double>(y);
|
---|
| 77 | xDelete<double>(data);
|
---|
| 78 | xDelete<double>(x_interp);
|
---|
| 79 | xDelete<double>(y_interp);
|
---|
| 80 | xDelete<double>(predictions);
|
---|
| 81 | xDelete<double>(error);
|
---|
[12377] | 82 | delete options;
|
---|
| 83 | delete results;
|
---|
| 84 |
|
---|
[13534] | 85 | /*Finalize environment:*/
|
---|
| 86 | EnvironmentFinalize();
|
---|
[12377] | 87 |
|
---|
[13531] | 88 | /*Finalize exception trapping: */
|
---|
| 89 | ExceptionTrapEnd();
|
---|
[12377] | 90 |
|
---|
| 91 | return 0; //unix success return;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[13277] | 94 | void ProcessArguments2(char** pbinfilename,char** poutbinfilename,char** plockfilename,char** prootpath,int argc,char **argv){
|
---|
[12377] | 95 | char *modelname = NULL;
|
---|
| 96 | char *binfilename = NULL;
|
---|
| 97 | char *outbinfilename = NULL;
|
---|
| 98 | char *lockfilename = NULL;
|
---|
[13277] | 99 | char *rootpatharg = NULL;
|
---|
| 100 | char *rootpath = NULL;
|
---|
[12377] | 101 |
|
---|
[13277] | 102 | if(argc<1)_error_("Usage error: no execution path provided");
|
---|
[13056] | 103 | if(argc<2)_error_("Usage error: missing model name");
|
---|
[13277] | 104 |
|
---|
| 105 | rootpatharg=argv[1];
|
---|
[25836] | 106 | if(strcmp(strstr(rootpatharg,"/"),"/")!=0){
|
---|
[13277] | 107 | rootpath = xNew<char>(strlen(rootpatharg)+2); sprintf(rootpath,"%s/",rootpatharg);
|
---|
[25836] | 108 | }
|
---|
[13277] | 109 | else{
|
---|
| 110 | rootpath = xNew<char>(strlen(rootpatharg)+1); sprintf(rootpath,"%s",rootpatharg);
|
---|
[25836] | 111 | }
|
---|
[13277] | 112 |
|
---|
[12377] | 113 | modelname=argv[2];
|
---|
[13277] | 114 | if(strstr(modelname,rootpath)==NULL){
|
---|
| 115 | binfilename = xNew<char>(strlen(rootpath)+strlen(modelname)+strlen(".bin") +1); sprintf(binfilename, "%s%s%s",rootpath,modelname,".bin");
|
---|
| 116 | outbinfilename = xNew<char>(strlen(rootpath)+strlen(modelname)+strlen(".outbin")+1); sprintf(outbinfilename,"%s%s%s",rootpath,modelname,".outbin");
|
---|
| 117 | lockfilename = xNew<char>(strlen(rootpath)+strlen(modelname)+strlen(".lock") +1); sprintf(lockfilename, "%s%s%s",rootpath,modelname,".lock");
|
---|
| 118 | }
|
---|
| 119 | else{
|
---|
| 120 | binfilename = xNew<char>(strlen(modelname)+strlen(".bin") +1); sprintf(binfilename, "%s%s",modelname,".bin");
|
---|
| 121 | outbinfilename = xNew<char>(strlen(modelname)+strlen(".outbin")+1); sprintf(outbinfilename,"%s%s",modelname,".outbin");
|
---|
| 122 | lockfilename = xNew<char>(strlen(modelname)+strlen(".lock") +1); sprintf(lockfilename, "%s%s",modelname,".lock");
|
---|
| 123 | }
|
---|
[12377] | 124 |
|
---|
| 125 | /*Clean up and assign output pointer*/
|
---|
| 126 | *pbinfilename=binfilename;
|
---|
| 127 | *poutbinfilename=outbinfilename;
|
---|
| 128 | *plockfilename=lockfilename;
|
---|
[13277] | 129 | *prootpath=rootpath;
|
---|
[12377] | 130 | }
|
---|
| 131 |
|
---|
[25836] | 132 | void ProcessInputfile(double **px,double **py,double **pdata,int *pnobs,double **px_interp,double **py_interp,int *pninterp,Options **poptions,FILE* fid){
|
---|
[12377] | 133 |
|
---|
[25836] | 134 | int ninterp,nobs;
|
---|
| 135 | double *x = NULL;
|
---|
| 136 | double *y = NULL;
|
---|
| 137 | double *data = NULL;
|
---|
| 138 | double *x_interp = NULL;
|
---|
| 139 | double *y_interp = NULL;
|
---|
[21341] | 140 | Options *options = NULL;
|
---|
[12377] | 141 |
|
---|
[13764] | 142 | int M,N;
|
---|
[12377] | 143 | IoModel* iomodel = new IoModel();
|
---|
| 144 | iomodel->fid=fid;
|
---|
[21341] | 145 | iomodel->CheckFile();
|
---|
[25836] | 146 | iomodel->FetchData(&x,&M,&N,"md.x"); nobs=M*N;
|
---|
| 147 | iomodel->FetchData(&y,&M,&N,"md.y"); _assert_(M*N==nobs);
|
---|
| 148 | iomodel->FetchData(&data,&M,&N,"md.data"); _assert_(M*N==nobs);
|
---|
[21341] | 149 | iomodel->FetchData(&x_interp,&M,&N,"md.x_interp"); ninterp=M*N;
|
---|
| 150 | iomodel->FetchData(&y_interp,&M,&N,"md.y_interp"); _assert_(M*N==ninterp);
|
---|
[12377] | 151 |
|
---|
| 152 | /*Read options*/
|
---|
| 153 | options = new Options();
|
---|
[21341] | 154 | iomodel->FetchData(options,"md.y_interp");
|
---|
[12377] | 155 |
|
---|
| 156 | /*Assign output pointer*/
|
---|
| 157 | *px = x;
|
---|
| 158 | *py = y;
|
---|
| 159 | *pdata = data;
|
---|
| 160 | *pnobs = nobs;
|
---|
| 161 | *px_interp = x_interp;
|
---|
| 162 | *py_interp = y_interp;
|
---|
| 163 | *pninterp = ninterp;
|
---|
| 164 | *poptions = options;
|
---|
| 165 | delete iomodel;
|
---|
| 166 | }
|
---|