void PairCopulaInvVfun_Rotated_Obs(int family, int rotation, const double *theta, double *U, double *V, double *u, unsigned int n)
{     
    unsigned int i;
    
    switch(rotation){
        case 0:
        {
            PairCopulaInvVfun(family, theta, U, V, u, n);
            break;
        }
        case 90:
        {
            PairCopulaInvHfun(family, theta, V, U, u, n);
            break;
        }
        case 180:
        {
            PairCopulaInvVfun(family, theta, U, V, u, n);
            for (i=0;i<n;i++) u[i]=1-u[i];
            break;
        }
        case 270:
        {
            PairCopulaInvHfun(family, theta, V, U, u, n);
            for (i=0;i<n;i++) u[i]=1-u[i];
            break;
        }
    }
    
    return;
    
}
// FunctionID 7: PCInvVfun
void PCInvVfun(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//declare variables
    double *U, *V, *theta, *u, *Rotation;
    double *Family;
    int family, rotation;
    unsigned int n, N;
    
//figure out dimensions
    n = (unsigned int)mxGetM(prhs[2]);
    N = (unsigned int)mxGetM(prhs[4]);
    
//associate inputs
    Family = mxGetPr(prhs[1]);
    family = (int) *Family;
    theta = mxGetPr(prhs[4]);
    
//associate outputs
    plhs[0] = mxCreateDoubleMatrix(n,1,mxREAL);
    u = mxGetPr(plhs[0]);
    
    if (N == n)
    {
        if (nrhs==6 && !mxIsEmpty(prhs[5]))
        {
            mxArray *U_in, *V_in;
            U_in = mxDuplicateArray(prhs[2]);
            V_in = mxDuplicateArray(prhs[3]);
            U = mxGetPr(U_in);
            V = mxGetPr(V_in);
            Rotation = mxGetPr(prhs[5]);
            rotation = (int) *Rotation;
            
            PairCopulaInvVfun_VecPar(family,rotation,theta,U,V,u,n);
            
        }
        else
        {
            U = mxGetPr(prhs[2]);
            V = mxGetPr(prhs[3]);
            
            PairCopulaInvVfun_VecPar(family,theta,U,V,u,n);
        }
    }
    else
    {
        if (nrhs==6 && !mxIsEmpty(prhs[5]))
        {
            mxArray *U_in, *V_in;
            U_in = mxDuplicateArray(prhs[2]);
            V_in = mxDuplicateArray(prhs[3]);
            U = mxGetPr(U_in);
            V = mxGetPr(V_in);
            Rotation = mxGetPr(prhs[5]);
            rotation = (int) *Rotation;
            
            PairCopulaInvVfun(family,rotation,theta,U,V,u,n);
            
        }
        else
        {
            U = mxGetPr(prhs[2]);
            V = mxGetPr(prhs[3]);
            
            PairCopulaInvVfun(family,theta,U,V,u,n);
        }
    }
    
    
    return;
    
}