/* Authors Martin Schlather, martin.schlather@cu.lu library for simulation of random fields -- init part and error messages Copyright (C) 2001 -- 2004 Martin Schlather This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include "RFsimu.h" #include "RFCovFcts.h" #include "MPPFcts.h" #include initfct init_method[SimulationTypeLength]; do_comp_fct do_compatiblemethod[SimulationTypeLength]; do_incomp_fct do_incompatiblemethod[SimulationTypeLength]; key_type KEY[MAXKEYS]; //static key_type KEY[MAXKEYS]; Real ZERO[MAXDIM], UNIT[MAXDIM]; cov_fct *CovList=NULL; int currentNrCov=-1; char GENERAL_PCH[2]="#"; /* character printed after each simulation just for entertainment of the user */ int GENERAL_STORING=true; /* true: intermediate results are stored: might be rather memory consuming, but the simulation can (depending on the method chosen) be much faster when done the second time with exactly the same parameters do not forget to call DeleteAllKeys when all the simulation are done. false: intermediate results are not stored if SimulateRF is called or stored only until DoSimulateRF is called. minimum memory consumption, but might be rather slow if many simulations are performed with exactly the same parameters to be safe call DeleteAllKeys when all the simulations are done Warning! init_foo may depend on GENERAL_STORING! This may cause problems if GENERAL_STORING is changed between init_foo and do_foo from false to true and if do_foo is called more than once! (SimulateRF is safe in this case) indifferent behaviour for the simulation methods if parameters are changed after each simulation. In case, only MAXKEYS different parameter sets are used, but after each step the parameter set is changed, use different keynr for each parametere set, and STORING==true, to get fast simulation */ int GENERAL_PRINTLEVEL=1; /* 0:no messages; 1:error messages; 2: hints when algorithm is at a forcation; >=3: more and more debugging information */ int GENERAL_NATURALSCALING=0; /* is called PracticalRange in R (see Chiles&Delfiner?!) Note: RFparameters() allows only 0 and 1 as values! has an effect only if cov (and not only cov.local, e.g. Brownian Motion) is defined 0 : using the covariance function as defined 1 : rescaling of cov fctn such that cov(1)~=0.05, if rescaling function does not exist then failure, e.g. for Bessel model 2 : exact or approximate value (e.g. expPLUScirc) 3 : MLE (special needs taken into account, long memory covariance functions have too long tails, which are shortened (so threshold 0.05 is changed to higher values in this case)) +10: if any of the above fails : numerical evaluation! else : using rescaling if rescaling function exists, otherwise without rescaling */ char ERRORSTRING_OK[MAXERRORSTRING],ERRORSTRING_WRONG[MAXERRORSTRING]; char METHODNAMES[][METHODMAXCHAR]={"circulant embedding", "local CE", "TBM2 (2dim. turning bands)", "TBM3", "spectral TBM (2dim)", "direct matrix decomposition", "nugget", "add.MPP", "hyperplanes (not implem.)", "other methods(not implem.)", "nothing", "max.MPP", "forbidden"}; char DISTRNAMES[DISTRNR][DISTRMAXCHAR]={"Gauss", "Poisson", "MaxStable"}; void ErrorMessage(SimulationType m, int error) { char MS[50], EM[100+2*MAXERRORSTRING]; switch(m) { case CircEmbed : strcpy(MS,"circulant embedding"); break; case CircEmbedLocal : strcpy(MS,"local circulant embedding"); break; case TBM2 : strcpy(MS,"2-dim. TBM"); break; case TBM3: strcpy(MS,"3-dim. TBM"); break; case SpectralTBM: strcpy(MS,"spectral TBM"); break; case Direct : strcpy(MS,"direct Gaussian (decomposition of cov. matrix)"); break; case Nugget: strcpy(MS,"nugget effect modelling"); break; case AdditiveMpp: strcpy(MS,"additive MPP (random coins)"); break; case Hyperplane : strcpy(MS,"hyperplane tessellation"); break; case Special: strcpy(MS,"special procedure"); break; case Nothing: if (error>0) strcpy(MS,"Error"); else strcpy(MS,"Message"); break; case MaxMpp: strcpy(MS,"max. MPP (Boolean functions)"); break; case Forbidden: strcpy(MS,"forbidden"); break; default : PRINTF("m=%d \n",m); assert(false); } switch (error) { case USEOLDINIT : strcpy(EM,"Using stored initialization"); break; case NOERROR : strcpy(EM,"fine"); break; case NOERROR_REPEAT : strcpy(EM,"none; repeat.");break; case NOERROR_ENDOFLIST : strcpy(EM,"end of list");break; case ERRORDUMMY : strcpy(EM,"none"); break; case ERRORNOTDEFINED : strcpy(EM,"undefined for this model");break; case ERRORMETHODNOTALLOWED : strcpy(EM,"not allowed for the specified parameters or points");break; case ERRORNOTPROGRAMMED : strcpy(EM,"not programmed yet. Sorry"); break; case ERRORCOVNOTALLOWED : strcpy(EM,"model not allowed for specified dimension");break; case ERRORFAILED: strcpy(EM,"algorithm failed");break; case ERRORMEMORYALLOCATION: strcpy(EM,"memory allocation error");break; case ERRORNOTINITIALIZED: strcpy(EM,"not initialized or RFparameters()$Storing==FALSE");break; case ERRORKEYNROUTOFRANGE: strcpy(EM,"wrong key number");break; case ERRORDECOMPOSITION: strcpy(EM,"matrix decomposition failed");break; case ERRORPRECISION: strcpy(EM,"required precision not attained");break; case ERRORRESCALING: strcpy(EM,"rescaling not defined");break; case ERRORFOURIER: strcpy(EM,"fft factorization failed");break; case ERRORCOVFAILED: sprintf(EM, "model and method only valid for %s. Got %s", ERRORSTRING_OK,ERRORSTRING_WRONG); break; case ERRORREGISTER: sprintf(EM,"Register number out of [0,%d]",MAXKEYS-1);break; case ERRORCOORDINATES: strcpy(EM,"coordinates are not given or invalid grid specification"); break; case ERRORNEGATIVEVAR: strcpy(EM,"Variance or nugget non-positive");break; case ERRORPARAMNUMBER: strcpy(EM,"number of parameters not correct");break; case ERRORDIM: sprintf(EM,"dimension specification not in [1,%d]",MAXDIM);break; case ERRORNEGATIVESCALE : strcpy(EM,"scale parameter must be positive");break; case ERRORWAVING : strcpy(EM,"Rescaling not possible (waving)");break; case ERRORWRONGINIT: strcpy(EM,"Wrong initialisation");break; case ERRORNN: strcpy(EM,"The number of points on the line is too large. Check your parameters and make sure that none of the locations are given twice");break; case ERRORANISOTROPIC: strcpy(EM,"anisotropic function not allowed"); break; case ERRORMETHODMIX: strcpy(EM,"for multiplicative covariance functions the method must be identical"); break; case ERRORTIMENOTANISO: strcpy(EM,"time component only allowed for anisotropic fields"); break; case ERRORNOMULTIPLICATION: strcpy(EM,"multiplicative covariance functions/variograms not allowed"); break; case ERRORANISOMIX: strcpy(EM,"for multiplicative covariance functions and TBM \ the anisotropies must be identical"); break; case ERRORISOTROPICMETHOD: strcpy(EM,"method (TBM) only allows for spatially isotropic functions in certain dimensions"); break; case ERRORTIMESEPARATE: strcpy(EM,"method (TBM) does not allow the time component being mixed up with spatial components"); break; case ERRORUNKNOWNMETHOD: strcpy(EM,"Unknown method in this context or unallowed mixture of methods"); break; case ERRORWITHOUTTIME: strcpy(EM,"spatially isotropic covariance fcts that are not fully isotropic must be called with a time component"); break; case ERRORCOVNROUTOFRANGE: strcpy(EM,"wrong covnr number");break; case ERRORWRONGDIM: strcpy(EM,"wrong dimension"); break; case ERRORNOTANISO: strcpy(EM,"model definition must use list-notation with anisotropy"); break; case ERRORDIMMISMATCH: strcpy(EM,"logical dimension does not match physical dimension"); break; case ERRORTOOMANYPOINTS: strcpy(EM, "two many points to determine smallest distance between the points"); break; case ERRORTIMENOTALLOWED: strcpy(EM, "time component not allowed for the specified method"); break; // case ERRORISOTROPIC: // strcpy(EM,"isotropic function not allowed"); break; // // extremes: case ERRORSILLNULL : strcpy(EM,"Vanishing sill not allowed");break; // case : strcpy(EM,"");break; // // Poisson: case ERRORVARMEAN : strcpy(EM,"Variance differs from mean");break; case ERRORTRIVIAL : strcpy(EM,"confused about trivial parameter specification");break; case ERRORUNSPECIFIED : strcpy(EM,"(unspecified)");break; default : PRINTF(" m=%d error=%d\n",m,error); assert(false); } if (m!=Nothing) PRINTF("Method"); PRINTF(" %s: %s.\n",MS,EM); } void InitModelList() { int i,d,v, nr; for (i=0; i