Ejemplo n.º 1
0
/* gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
{
    double *in_array;                              /* input array */
    mwSize number_of_dimensions;                   /* number of dimensions of arrays*/
    const mwSize *dimensions;                      /* array of dimension sizes */
    size_t number_of_elements;                     /* number of array elements */
    double *out_array0, *out_array1, *out_array2;  /* output arrays */
    
    /* check for proper number of arguments */
    if(nrhs!=1) {
        mexErrMsgIdAndTxt("MyToolbox:cmb_velocity:nrhs",
                          "Only accepts one input array.");
    }
    if(nlhs!=3) {
        mexErrMsgIdAndTxt("MyToolbox:cmb_velocity:nlhs",
                          "Returns three output arrays.");
    }
    
    /* make sure the input argument is type double */
    if( !mxIsDouble(prhs[0]) || 
         mxIsComplex(prhs[0])) {
        mexErrMsgIdAndTxt("MyToolbox:cmb_velocity:notDouble",
                          "Input array must be type double.");
    }
    
    /* create a pointer to the real data in the input array  */
    in_array = mxGetPr(prhs[0]);
    
    /* get number of dimensions of the input array */
    number_of_dimensions = mxGetNumberOfDimensions(prhs[0]);
    
    /* get dimensions of the input array */
    dimensions = mxGetDimensions(prhs[0]);
    
    /* get number of elements in input array */
    number_of_elements = mxGetNumberOfElements(prhs[0]);
    
    /* create the output arrays */
    plhs[0] = mxCreateNumericArray(number_of_dimensions,dimensions,
                                   mxDOUBLE_CLASS,mxREAL);
    plhs[1] = mxCreateNumericArray(number_of_dimensions,dimensions,
                                   mxDOUBLE_CLASS,mxREAL);
    plhs[2] = mxCreateNumericArray(number_of_dimensions,dimensions,
                                   mxDOUBLE_CLASS,mxREAL);

    /* get a pointer to the real data in the output arrays */
    out_array0 = mxGetPr(plhs[0]);
    out_array1 = mxGetPr(plhs[1]);
    out_array2 = mxGetPr(plhs[2]);

    /* call the computational routine */
    moon_position(in_array,number_of_elements,
                  out_array0,out_array1,out_array2);
}
Ejemplo n.º 2
0
double moon_phase(int year, int month, int day, double hour) {
    double j  = julian(year, month, (double)day+(hour/24.0))-2444238.5;
    double ls = sun_position(j);
    double lm = moon_position(j, ls);
    double t = lm - ls;

    if (t < 0) {
        t += 360;
    }
//    *ip = (int)((t + 22.5)/45) & 0x7;
    
    return (1.0 - cos((t)*RAD))/2;
}