/* Open and close the SSL module. These routines are called once in the lifetime of the application and initialize and clean up the library respectively. */ int32 matrixSslOpen(void) { /* Use copyright to avoid compiler warning about it being unused */ if (*copyright != 'C') { return PS_FAILURE; } if (psCoreOpen() < 0) { psError("pscore open failure\n"); return PS_FAILURE; } psInitPrng(&gMatrixsslPrng); #ifdef USE_SERVER_SIDE_SSL memset(sessionTable, 0x0, sizeof(sslSessionEntry_t) * SSL_SESSION_TABLE_SIZE); #ifdef USE_MULTITHREADING psCreateMutex(&sessionTableLock); psCreateMutex(&prngLock); #endif /* USE_MULTITHREADING */ #endif /* USE_SERVER_SIDE_SSL */ return PS_SUCCESS; }
int *glitch_one_detector_simple( actData *mydat, ///< Data vector to filter. Modified and returned. int n, ///< Length of the input data vector mydat. bool do_smooth, ///< Whether to replace the entire data vector with its smoothed value. bool apply_glitch, ///< Whether to replace data exceeding the cut threshold with its smoothed value. bool do_cuts, ///< Whether to build the cutvec of data failing the cut threshhold test. actData nsig, ///< The cut threshold is this factor times the median abs deviation of smooths. actData t_glitch, ///< The width (Gaussian sigma) of the glitch time actData t_smooth, ///< The width (Gaussian sigma) of the smoothing time actData dt, ///< Time between data samples. int filt_type) ///< Select filter type (currently only Gaussian filters are implemented). { // If we have both set to true, we don't know what to put in mydat #ifdef HAVE_PSERR if(do_smooth && apply_glitch) psError(MB_ERR_BAD_VALUE, true, "Cannot both smooth and deglitch (=not smooth) data in glitch_one_detector\n"); #endif actComplex *tmpfft=act_fftw_malloc(sizeof(actComplex)*n); actData *tmpvec=psAlloc(n*sizeof(actData)); actData *tmpclean=psAlloc(n*sizeof(actData)); actData *filtvec=calculate_glitch_filterC(t_glitch,t_smooth,dt,n,1); int *cutvec=psAlloc(n*sizeof(int)); act_fftw_plan p_forward; act_fftw_plan p_back; #if !defined(MB_SKIP_OMP) #pragma omp critical #endif { p_forward =act_fftw_plan_dft_r2c_1d(n,tmpvec,tmpfft,FFTW_ESTIMATE); p_back =act_fftw_plan_dft_c2r_1d(n,tmpfft,tmpvec,FFTW_ESTIMATE); } glitch_one_detector(mydat,filtvec, tmpfft,tmpvec,tmpclean,cutvec,n, p_forward, p_back,do_smooth, apply_glitch, do_cuts,nsig); #if !defined(MB_SKIP_OMP) #pragma omp critical #endif { act_fftw_destroy_plan(p_forward); act_fftw_destroy_plan(p_back); } psFree(tmpvec); psFree(tmpclean); psFree(filtvec); act_fftw_free(tmpfft); if (do_cuts) return cutvec; else { psFree(cutvec); return NULL; } }
/* Allocate a new psPubKey_t and memset empty */ psPubKey_t * psNewPubKey(psPool_t *pool) { psPubKey_t *ret; ret = psMalloc(pool, sizeof(psPubKey_t)); if (ret == NULL) { psError("Memory allocation error in psNewPubKey\n"); return NULL; } memset(ret, 0x0, sizeof(psPubKey_t)); ret->key = psMalloc(pool, sizeof(pubKeyUnion_t)); if (ret->key == NULL) { psFree(ret); psError("Memory allocation error in psNewPubKey\n"); return NULL; } memset(ret->key, 0x0, sizeof(pubKeyUnion_t)); return ret; }
static void glitch_one_detector( actData *mydat, ///< Data vector to filter. Modified and returned. const actData *filt, ///< The pre-calculated smoothing filter to use. actComplex *tmpfft, ///< Pre-allocated vector of length n. Returns DFT of smoothed data.. actData *tmpvec, ///< Pre-allocated vector of length n. Returns unmodified input. actData *tmpclean, ///< Pre-allocated vector of length n. Returns abs(raw-smooth). int *cutvec, ///< Pre-allocated vector of length n. Returns cut list if (do_cuts). int n, ///< Length of the input data vector mydat. //fftwf_plan p_forward, ///< The FFTW plan for going to the frequency domain. //fftwf_plan p_back, ///< The FFTW plan for going back to the time domain. act_fftw_plan p_forward, ///< The FFTW plan for going to the frequency domain. act_fftw_plan p_back, ///< The FFTW plan for going back to the time domain. bool do_smooth, ///< Whether to replace the entire data vector with its smoothed value. bool apply_glitch, ///< Whether to replace data exceeding the cut threshold with its smoothed value. bool do_cuts, ///< Whether to build the cutvec of data failing the cut threshhold test. actData nsig) ///< The cut threshold is this factor times the median abs deviation of smooths. { // If we have both set to true, we don't know what to put in mydat #ifdef HAVE_PSERR if(do_smooth && apply_glitch) psError(MB_ERR_BAD_VALUE, true, "Cannot both smooth and deglitch (=not smooth) data in glitch_one_detector\n"); #endif // User hasn't requested any action! if (! (do_smooth || apply_glitch || do_cuts)) return; // Save a copy of the input data, then apply the smoothing filter only. memcpy(tmpvec,mydat,n*sizeof(actData)); filter_one_tod(mydat, filt, tmpfft,p_forward,p_back,n); // Joe mystified by this rescaling. #if 1 const actData nf=n; for (int i=0;i<n;i++) mydat[i]/=nf; #endif // If we don't need to know nor apply the cuts, then we're done. if (do_smooth & (!do_cuts)) return; // tmpclean is the absolute difference between smooth and raw vectors. Find its median (for use in cuts). for (int j=0;j<n;j++) tmpclean[j]=fabs(mydat[j]-tmpvec[j]); actData thresh=sselect(n/2,n,tmpclean-1)*nsig; if (do_cuts) { memset(cutvec,0,sizeof(int)*n); for (int j=0;j<n;j++) { if (fabs(mydat[j]-tmpvec[j])>thresh) cutvec[j]=1; } } if (do_smooth) return; // By this point, we know the user didn't want smooth data. Copy data back to the input vector. // If apply_glitch, then mostly this will be the raw data, but we leave the smoothed data there // during all glitches. Otherwise, we want the entire raw data set back (and presumably called // this function only to get the cuts). if (apply_glitch) { for (int j=0;j<n;j++) if (fabs(mydat[j]-tmpvec[j])<thresh) mydat[j]=tmpvec[j]; } else memcpy(mydat,tmpvec,sizeof(actData)*n); }
CShader_GBuffer::CShader_GBuffer(std::string vs_path, std::string ps_path) { GLuint vsID = glCreateShader(GL_VERTEX_SHADER); GLuint psID = glCreateShader(GL_FRAGMENT_SHADER); std::string vsCode; std::ifstream vsStream(vs_path.c_str(), std::ios::in); if (vsStream.is_open()) { std::string line = ""; while (getline(vsStream, line)) { vsCode += "\n" + line; } vsStream.close(); } std::string psCode; std::ifstream psStream(ps_path.c_str(), std::ios::in); if (psStream.is_open()) { std::string line = ""; while (getline(psStream, line)) { psCode += "\n" + line; } psStream.close(); } GLint result = GL_FALSE; int logLength; // Compile vertex shader log(LOG_TYPE_DEFAULT, "Compiling Shader: " + vs_path + ".."); const char* vsPointer = vsCode.c_str(); glShaderSource(vsID, 1, &vsPointer, NULL); glCompileShader(vsID); // Check shader status glGetShaderiv(vsID, GL_COMPILE_STATUS, &result); if (!result) { glGetShaderiv(vsID, GL_INFO_LOG_LENGTH, &logLength); std::vector<char> vsError(logLength); glGetShaderInfoLog(vsID, logLength, NULL, &vsError[0]); if (vsError.size() - 1 >= 0) { vsError[vsError.size() - 1] = '\0'; } log(LOG_TYPE_ERROR, std::string((char*)&vsError[0])); } // Compile pixel shader log(LOG_TYPE_DEFAULT, "Compiling Shader: " + ps_path + ".."); const char* psPointer = psCode.c_str(); glShaderSource(psID, 1, &psPointer, NULL); glCompileShader(psID); // Check shader status glGetShaderiv(psID, GL_COMPILE_STATUS, &result); if (!result) { glGetShaderiv(psID, GL_INFO_LOG_LENGTH, &logLength); std::vector<char> psError(logLength); glGetShaderInfoLog(psID, logLength, NULL, &psError[0]); if (psError.size() - 1 >= 0) { psError[psError.size() - 1] = '\0'; } log(LOG_TYPE_ERROR, std::string((char*)&psError[0])); } // Link shader log(LOG_TYPE_DEFAULT, "Linking shader .."); GLuint shaderID = glCreateProgram(); glAttachShader(shaderID, vsID); glAttachShader(shaderID, psID); glLinkProgram(shaderID); // Check final shader glGetProgramiv(shaderID, GL_LINK_STATUS, &result); if (!result) { glGetProgramiv(shaderID, GL_INFO_LOG_LENGTH, &logLength); std::vector<char> shaderError(logLength); glGetProgramInfoLog(shaderID, logLength, NULL, &shaderError[0]); if (shaderError.size() - 1 >= 0) { shaderError[shaderError.size() - 1] = '\0'; } log(LOG_TYPE_ERROR, std::string((char*)&shaderError[0])); } // Clean up glDeleteShader(vsID); glDeleteShader(psID); // Save the ID m_Id = shaderID; }