int main(void) { int i, N, L,method; double *inp; int p; double *phi; double *xpred, *amse; ar_object obj; p = 0; L = 5; phi = (double*)malloc(sizeof(double)* p); xpred = (double*)malloc(sizeof(double)* L); amse = (double*)malloc(sizeof(double)* L); FILE *ifp; double temp[2000]; ifp = fopen("seriesA.txt", "r"); i = 0; if (!ifp) { printf("Cannot Open File"); exit(100); } while (!feof(ifp)) { fscanf(ifp, "%lf \n", &temp[i]); i++; } N = i; inp = (double*)malloc(sizeof(double)* N); //wmean = mean(temp, N); for (i = 0; i < N; ++i) { inp[i] = temp[i]; //printf("%g \n",inp[i]); } method = 0; // method 0 - Yule Walker, Method 1 - Burg, Method 2, MLE (Box-Jenkins) obj = ar_init(method, N); ar_exec(obj, inp); ar_summary(obj); // Predict the next 5 values using the obtained ARIMA model ar_predict(obj, inp, L, xpred, amse); printf("\n"); printf("Predicted Values : "); for (i = 0; i < L; ++i) { printf("%g ", xpred[i]); } printf("\n"); printf("Standard Errors : "); for (i = 0; i < L; ++i) { printf("%g ", sqrt(amse[i])); } printf("\n"); ar_free(obj); //ar_estimate(inp, N, 2); free(inp); free(phi); free(xpred); free(amse); return 0; }
/* * ar_close() * closes archive device, increments volume number, and prints i/o summary */ void ar_close(void) { int status; if (arfd < 0) { did_io = io_ok = flcnt = 0; return; } /* * Close archive file. This may take a LONG while on tapes (we may be * forced to wait for the rewind to complete) so tell the user what is * going on (this avoids the user hitting control-c thinking pax is * broken). */ if ((vflag || Vflag) && (artyp == ISTAPE)) { if (vfpart) (void)putc('\n', listf); (void)fprintf(listf, "%s: Waiting for tape drive close to complete...", argv0); (void)fflush(listf); } /* * if nothing was written to the archive (and we created it), we remove * it */ if (can_unlnk && (fstat(arfd, &arsb) == 0) && (S_ISREG(arsb.st_mode)) && (arsb.st_size == 0)) { (void)unlink(arcname); can_unlnk = 0; } /* * for a quick extract/list, pax frequently exits before the child * process is done */ if ((act == LIST || act == EXTRACT) && nflag && zpid > 0) kill(zpid, SIGINT); #ifdef SUPPORT_RMT if (artyp == ISRMT) (void)rmtclose(arfd); else #endif /* SUPPORT_RMT */ (void)close(arfd); /* Do not exit before child to ensure data integrity */ if (zpid > 0) waitpid(zpid, &status, 0); if ((vflag || Vflag) && (artyp == ISTAPE)) { (void)fputs("done.\n", listf); vfpart = 0; (void)fflush(listf); } arfd = -1; if (!io_ok && !did_io) { flcnt = 0; return; } did_io = io_ok = 0; /* * The volume number is only increased when the last device has data * and we have already determined the archive format. */ if (frmt != NULL) ++arvol; if (!vflag && !Vflag) { flcnt = 0; return; } /* * Print out a summary of I/O for this archive volume. */ if (vfpart) { (void)putc('\n', listf); vfpart = 0; } /* mimic cpio's block count first */ if (frmt && strcmp(NM_CPIO, argv0) == 0) { (void)fprintf(listf, OFFT_F " blocks\n", (rdcnt ? rdcnt : wrcnt) / 5120); } ar_summary(0); (void)fflush(listf); flcnt = 0; }