Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,728 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,340 people online right now. Registration is fast and FREE... Join Now!




c to matlab

 
Reply to this topicStart new topic

c to matlab

farhad2na2
post 13 Dec, 2006 - 07:32 AM
Post #1


New D.I.C Head

*
Joined: 13 Dec, 2006
Posts: 1


My Contributions


Id like to convert this c code to matlab


CODE

typedef struct _SHAMSIDATE
{
    int iYear;
    int iMonth;
    int iDay;
}SHAMSIDATE;
SHAMSIDATE MiladiToShamsi(int iMiladiMonth,int iMiladiDay,int iMiladiYear)
{

    int  shamsiDay, shamsiMonth, shamsiYear;
    int  dayCount,farvardinDayDiff,deyDayDiff;
    int  sumDayMiladiMonth[] = {0,31,59,90,120,151,181,212,243,273,304,334};
    int  sumDayMiladiMonthLeap[]= {0,31,60,91,121,152,182,213,244,274,305,335};
    SHAMSIDATE  shamsidate;
farvardinDayDiff=79;

if (MiladiIsLeap(iMiladiYear))
{
    dayCount = sumDayMiladiMonthLeap[iMiladiMonth-1] + iMiladiDay;
}
else
{
    dayCount = sumDayMiladiMonth[iMiladiMonth-1] + iMiladiDay;
}
if((MiladiIsLeap(iMiladiYear - 1)))
{
    deyDayDiff = 11;
}
else
{
    deyDayDiff = 10;
}
if (dayCount > farvardinDayDiff)
{
    dayCount = dayCount - farvardinDayDiff;
    if (dayCount <= 186)
     {
      switch (dayCount%31)
       {
        case 0:
         shamsiMonth = dayCount / 31;
         shamsiDay = 31;
        break;
        default:
         shamsiMonth = (dayCount / 31) + 1;
         shamsiDay = (dayCount%31);
        break;
      }
      shamsiYear = iMiladiYear - 621;
     }
   else
     {
    dayCount = dayCount - 186;
    switch (dayCount%30)
      {
       case 0:
        shamsiMonth = (dayCount / 30) + 6;
        shamsiDay = 30;
       break;
     default:
       shamsiMonth = (dayCount / 30) + 7;
       shamsiDay = (dayCount%30);
       break;
     }
      shamsiYear = iMiladiYear - 621;
    }
  }
else
  {
    dayCount = dayCount + deyDayDiff;

    switch (dayCount%30)
    {
    case 0 :
      shamsiMonth = (dayCount / 30) + 9;
      shamsiDay = 30;
     break;
    default:
      shamsiMonth = (dayCount / 30) + 10;
      shamsiDay = (dayCount%30);
     break;
    }
    shamsiYear = iMiladiYear - 622;

  }
    shamsidate.iYear = shamsiYear;
    shamsidate.iMonth = shamsiMonth;
    shamsidate.iDay = shamsiDay;

  return shamsidate;
}
// the function check a miladiyear is leap or not.
BOOL MiladiIsLeap(int miladiYear)
{
if(((miladiYear % 100)!= 0 && (miladiYear % 4) == 0) || ((miladiYear % 100)== 0 && (miladiYear % 400) == 0))
  return TRUE;
else
  return FALSE;
}
User is offlineProfile CardPM

Go to the top of the page

horace
post 13 Dec, 2006 - 07:47 AM
Post #2


D.I.C Addict

Group Icon
Joined: 25 Oct, 2006
Posts: 573



Thanked 4 times

Dream Kudos: 50
My Contributions


as an initial step you could call your C/C++ functions from Matlab as MEX functions, see
http://cnx.org/content/m12348/latest/
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 10:25AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month