private static int[] g2HA(int yg, int mg, int dg){
	        int[] out = new int[4];
	    	int yh1 = 0, mh1 = 0, dh1 = 0;
	        int yh2, mh2, dh2;
	        int yg1 = 0, mg1 = 0, dg1 = 0;
	        int yg2 = 0, mg2 = 0, dg2 = 0;
	        int found;
	        int flag;
	        long J;
	        double GJD;
	        GJD = gCalendarToJD(yg, mg, dg + 0.5);
	        /* find JD of Gdate */
	        int[] jDToHC = jDToHCalendar(GJD);
	        yh1 = jDToHC[0];
	        mh1 = jDToHC[1];
	        dh1 = jDToHC[2];
	        /* estimate the Hdate that correspond to the Gdate */
	        found = 0;
	        flag = 1;
	        while ((!(found == 1)) && (flag == 1))
	        {
	            /* start searching for the exact Hdate */
		        int[] result = h2GA(new int[]{yh1, mh1, dh1, yg1, mg1, dg1, out[3]});
	            yh1 = result[0];
	            mh1 = result[1];
	            dh1 = result[2];
	            yg1 = result[3];
	            mg1 = result[4];
	            dg1 = result[5];
	            out[3] = result[6];
	            /* compute the exact correponding Gdate for the dh1-mh1-yh1 */
	            if (yg1 > yg)
	            {
	                dh1--;
	                if (dh1 < 1)
	                {
	                    dh1 = 29 + dh1;
	                    mh1--;
	                }
	                 
	            }
	             
	            if (yg1 < yg)
	            {
	                dh1++;
	                if (dh1 > 30)
	                {
	                    dh1 = dh1 - 30;
	                    mh1++;
	                }
	                 
	                if (dh1 == 30)
	                {
	                    dh2 = 1;
	                    mh2 = mh1 + 1;
	                    yh2 = yh1;
	                    if (mh2 > 12)
	                    {
	                        yh2++;
	                        mh2 = mh2 - 12;
	                    }
	                     
	                    int[] result2 = h2GA(new int[]{yh2, mh2, dh2, yg2, mg2, dg2, out[3]});
	                    yh2 = result2[0];
	    	            mh2 = result2[1];
	    	            dh2 = result2[2];
	    	            yg2 = result2[3];
	    	            mg2 = result2[4];
	    	            dg2 = result2[5];
	    	            out[3] = result2[6];
	                    if (dg2 == dg)
	                    {
	                        mh1++;
	                        dh1 = 1;
	                    }
	                     
	                }
	                 
	            }
	             
	            /* check to see that if 30 is actually 1st of next month */
	            if (yg1 == yg)
	            {
	                if (mg1 > mg)
	                {
	                    dh1--;
	                    if (dh1 < 1)
	                    {
	                        dh1 = 29 + dh1;
	                        mh1--;
	                    }
	                     
	                }
	                 
	                if (mg1 < mg)
	                {
	                    dh1++;
	                    if (dh1 > 30)
	                    {
	                        dh1 = dh1 - 30;
	                        mh1++;
	                    }
	                     
	                    if (dh1 == 30)
	                    {
	                        dh2 = 1;
	                        mh2 = mh1 + 1;
	                        yh2 = yh1;
	                        if (mh2 > 12)
	                        {
	                            yh2++;
	                            mh2 = mh2 - 12;
	                        }
	                         
	                        int[] result2 = h2GA(new int[]{yh2, mh2, dh2, yg2, mg2, dg2, out[3]});
		                    yh2 = result2[0];
		    	            mh2 = result2[1];
		    	            dh2 = result2[2];
		    	            yg2 = result2[3];
		    	            mg2 = result2[4];
		    	            dg2 = result2[5];
		    	            out[3] = result2[6];
	                        if (dg2 == dg)
	                        {
	                            mh1++;
	                            dh1 = 1;
	                        }
	                         
	                    }
	                     
	                }
	                 
	                /* check to see that if 30 is actually 1st of next month */
	                if (mg1 == mg && yg1 == yg)
	                {
	                    /* if the months are equal than adjust the days */
	                    found = 1;
	                    if (dg1 > dg)
	                    {
	                        dh1 = dh1 - (dg1 - dg);
	                        found = 0;
	                    }
	                     
	                    if (dg1 < dg)
	                    {
	                        dh1 = dh1 - (dg1 - dg);
	                        found = 0;
	                    }
	                     
	                    if (dh1 < 1)
	                    {
	                        dh1 = 29 + dh1;
	                        mh1--;
	                    }
	                     
	                    if (dh1 > 30)
	                    {
	                        dh1 = dh1 - 30;
	                        mh1++;
	                    }
	                     
	                    if (dh1 == 30)
	                    {
	                        dh2 = 1;
	                        mh2 = mh1 + 1;
	                        yh2 = yh1;
	                        if (mh2 > 12)
	                        {
	                            yh2++;
	                            mh2 = mh2 - 12;
	                        }
	                         
	                        int[] result2 = h2GA(new int[]{yh2, mh2, dh2, yg2, mg2, dg2, out[3]});
		                    yh2 = result2[0];
		    	            mh2 = result2[1];
		    	            dh2 = result2[2];
		    	            yg2 = result2[3];
		    	            mg2 = result2[4];
		    	            dg2 = result2[5];
		    	            out[3] = result2[6];
	                        if (dg2 == dg)
	                        {
	                            mh1++;
	                            dh1 = 1;
	                        }
	                         
	                    }
	                     
	                }
	                 
	            }
	             
	            /* check to see that if 30 is actually 1st of next month */
	            if (mh1 < 1)
	            {
	                yh1--;
	                mh1 = 12 + mh1;
	            }
	             
	            if (mh1 > 12)
	            {
	                yh1++;
	                mh1 = mh1 - 12;
	            }
	             
	        }
	        Double doubleHolder = gCalendarToJD(yg, mg, dg) + 2;
	        J = doubleHolder.longValue();
	        Long longHolder = J % 7;
	        out[3] = longHolder.intValue();
	        out[0] = yh1;
	        out[1] = mh1;
	        out[2] = dh1;
	        return out;
	    }