#include "stdio.h" #include "stdlib.h" #include "flatfile.h" #include "astring.h" /* --------------------------------------------------------------------------- ffclose - closes the header and data files. --------------------------------------------------------------------------- */ int ffclose(int unit) { int error, i; char line[80], ch; long pos; FILE *fp; error = 0; if (!ff_pointer_h[unit]) { printf("Header file is not opened - can not close file.\n"); error = 1; } else { if ((ff_readwrite[unit]) && (ff_rows[unit] > 0)) { fp = ff_pointer_h[unit]; rewind(fp); for (i=0;i<4;i++) { fgets(line,80,fp); } for (i=0;i<40;i++) { getc(fp); } pos = ftell(fp); fseek(fp, pos, SEEK_SET); fputs(c_long_str(ff_rows[unit],10),fp); fseek(fp, 0, SEEK_SET); for (i=0;i<9+ff_ncol[unit]+3;i++) { fgets(line,80,fp); } for (i=0;i<14;i++) { ch = getc(fp); } pos = ftell(fp); fseek(fp, pos, SEEK_SET); if (ff_rows[unit] == 0) { ff_stime[unit] = 0.0; } fputs(c_r_to_s(ff_stime[unit]),fp); fseek(fp, 0, SEEK_SET); for (i=0;i<10+ff_ncol[unit]+3;i++) { fgets(line,80,fp); } for (i=0;i<14;i++) { ch = getc(fp); } pos = ftell(fp); fseek(fp, pos, SEEK_SET); if (ff_rows[unit] == 0) { ff_etime[unit] = 0.0; } fputs(c_r_to_s(ff_etime[unit]),fp); } fclose(ff_pointer_h[unit]); fclose(ff_pointer[unit]); ff_pointer_h[unit] = NULL; ff_pointer[unit] = NULL; ff_opened--; } return error; }