home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / CYCMOV.C < prev    next >
Encoding:
Text File  |  1984-08-13  |  1.8 KB  |  89 lines

  1.    cycmov(a,n,l,kda,b,c,temp,ph)
  2.  
  3.       /*if monthly data is supplied, seasonal index and cyclical move-  */
  4.       /*ment are computed, otherwise only cyclical movement is computed.*/
  5.  
  6.       int kda,l,n;
  7.       float a[],b[],c[],temp[],ph[];
  8.  
  9.    {
  10.       int i,il,j,kk,nd,nst;
  11.       float d[12],count[12],sum;
  12.  
  13.       nd = n;
  14.       moveav(a,nd,l,b);
  15.       if((kda-1) == 0)
  16.       {
  17.        for(i = 0; i <= n-1; i++)
  18.        {
  19.         if(b[i] == 0.) c[i] = 0.;
  20.          else c[i] = a[i]/b[i]*100.;
  21.        }
  22.        for(i = 0; i <= n-1; i++)
  23.        {
  24.         temp[i] = 0.;
  25.         ph[i] = c[i] - 100.;
  26.         if (c[i] == 0.) ph[i] = 0.;
  27.        }
  28.        return;
  29.       }
  30.  
  31.       for(i = 0; i <= n-1; i++)
  32.       {
  33.        if(b[i] == 0.) c[i] = 0.;
  34.         else c[i] = a[i]/b[i] * 100.;
  35.       }
  36.       nst = 7;
  37.       nd = n -nst + 1;
  38.  
  39.       for(i = 1; i <= 12; i++)
  40.       {
  41.        count[i-1] = 0.;
  42.        d[i-1] = 0.;
  43.  
  44.        for(j = nst; j <= nd; j++)
  45.        {
  46.         kk = (j/12) * 12;
  47.         if((j-kk-i) == 0)
  48.         {
  49.          d[i-1] = d[i-1] + c[j-1];
  50.          count[i-1] = count[i-1] + 1.;
  51.         }
  52.         else
  53.         {
  54.          if ((j-kk) == 0)
  55.          {
  56.           if((i - 12) == 0)
  57.           {
  58.            d[i-1] = d[i-1] + c[j-1];
  59.            count[i-1] = count[i-1] + 1.;
  60.           }
  61.          }
  62.         }
  63.        }
  64.       }
  65.       sum = 0.;
  66.  
  67.       for(i = 0; i <= 11; i++)
  68.       {
  69.        d[i] = d[i]/count[i];
  70.        sum = sum + d[i];
  71.       }
  72.  
  73.       for(i = 0; i <= 11; i++)
  74.        d[i] = d[i]/sum * 12. * 100.;
  75.  
  76.       for(j = 1; j <= n; j++)
  77.       {
  78.        il = (j/12) * 12;
  79.        i = j - il;
  80.        if(i == 0) i = 12;
  81.        if(i >= 0)
  82.         {
  83.          ph[j-1] = c[j-1] - d[i-1];
  84.          if (c[j-1] == 0.) ph[j-1] = 0.;
  85.          temp[j-1] = d[i-1];
  86.         }
  87.       }
  88.    }
  89.