int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "data RAW COMPLEX128 1\nENDIAN big\n"; unsigned int i; #ifdef GD_NO_C99_API const double c[] = {1.5, 2.25}; #else const double complex c = 1.5 + _Complex_I * 2.25; #endif unsigned char x[2 * sizeof(double)] = { 0x3F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; unsigned char u[2 * sizeof(double)]; int fd, n, error, r = 0; DIRFILE *D; rmdirfile(); mkdir(filedir, 0777); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); #ifdef GD_NO_C99_API n = gd_putdata(D, "data", 5, 0, 1, 0, GD_COMPLEX128, c); #else n = gd_putdata(D, "data", 5, 0, 1, 0, GD_COMPLEX128, &c); #endif error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY); lseek(fd, 5 * 2 * sizeof(double), SEEK_SET); read(fd, u, 2 * sizeof(double)); close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(error, 0); CHECKI(n, 1); for (i = 0; i < 2 * sizeof(double); ++i) CHECKXi(i, u[i], x[i]); return r; }
int main(void) { #ifndef TEST_GZIP return 77; #else const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data.gz"; const char *format_data = "data RAW UINT8 8\n"; uint8_t c[8], d[8]; int fd, i, m, n, e1, e2, unlink_data, r = 0; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = (uint8_t)(40 + i); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); #ifdef USE_GZIP D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED | GD_VERBOSE); #else D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED); #endif n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); e1 = gd_error(D); m = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, d); e2 = gd_error(D); gd_close(D); unlink_data = unlink(data); unlink(format); rmdir(filedir); #ifdef USE_GZIP CHECKI(unlink_data, 0); CHECKI(e1, GD_E_OK); CHECKI(e2, GD_E_OK); CHECKI(n, 8); CHECKI(m, 8); #else CHECKI(unlink_data, -1); CHECKI(e1, GD_E_UNSUPPORTED); CHECKI(e2, GD_E_UNSUPPORTED); CHECKI(n, 0); CHECKI(m, 0); #endif for (i = 0; i < m; ++i) CHECKIi(i, d[i], c[i]); return r; #endif }
int main(void) { #ifdef SKIP_TEST return 77; #else const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "data RAW UINT8 8\n"; uint8_t c[8], d; struct stat buf; int fd, i, n, error, r = 0; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = (uint8_t)(40 + i); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); error = gd_error(D); gd_close(D); if (stat(data, &buf)) { perror("stat"); r = 1; } else { CHECKI(buf.st_size, 48 * sizeof(uint8_t)); fd = open(data, O_RDONLY | O_BINARY); i = 0; while (read(fd, &d, sizeof(uint8_t))) { if (i < 40 || i > 48) { CHECKIi(i,d,0); } else CHECKIi(i,d,i); i++; } close(fd); } unlink(data); unlink(format); rmdir(filedir); CHECKI(n,8); CHECKI(error, 0); return r; #endif }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data.sie"; const char *format_data = "data RAW UINT8 8\n/ENCODING sie\n/ENDIAN little\n"; unsigned char c[16] = { 0x22, 0x22, 0x22, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34 }; const uint8_t data_data[] = { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32 }; const uint8_t data_out[] = { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32 }; uint8_t check[4 * 9]; DIRFILE *D; int fd, i, n, error, r = 0; rmdirfile(); mkdir(filedir, 0777); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); write(fd, data_data, 3 * 9 * sizeof(unsigned char)); close(fd); D = gd_open(filedir, GD_RDWR | GD_VERBOSE); n = gd_putdata(D, "data", 3, 0, 2, 0, GD_UINT8, c); error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY | O_BINARY); read(fd, check, 4 * 9); close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(error, 0); CHECKI(n, 16); for (i = 0; i < 4 * 9; ++i) CHECKIi(i, check[i], data_out[i]); return r; }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "data RAW UINT8 8\n"; uint8_t c[8], d; int fd, i, n, error; struct stat buf; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = (uint8_t)(40 + i); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); gd_flush(D, NULL); error = gd_error(D); gd_close(D); if (stat(data, &buf)) return 1; if (buf.st_size != 40 + 8 * sizeof(uint8_t)) return 1; fd = open(data, O_RDONLY | O_BINARY); i = 0; while (read(fd, &d, sizeof(uint8_t))) { if (i < 40 || i > 48) { if (d != 0) return 1; } else if (d != i) return 1; i++; } close(fd); unlink(data); unlink(format); rmdir(filedir); if (error) return 1; if (n != 8) return 1; return 0; }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "bit SBIT data 2 3\ndata RAW INT8 8\n"; int8_t c[8]; int8_t d = 0xA5; int fd, i, n, error, r = 0; DIRFILE *D; rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = i; fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); for (i = 0; i < 50; ++i) write(fd, &d, sizeof(int8_t)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "bit", 5, 0, 1, 0, GD_INT8, c); error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY | O_BINARY); i = 0; while (read(fd, &d, sizeof(int8_t))) { if (i < 40 || i >= 48) { CHECKIi(i,d,-91); } else CHECKIi(i,d,(-95 | (i - 40) << 2)); i++; } close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(n,8); CHECKI(error, 0); return r; }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "data RAW FLOAT32 1\nENDIAN little\n"; unsigned int i; const float c = 1.5; unsigned char x[sizeof(float)] = { 0x00, 0x00, 0xC0, 0x3F }; unsigned char u[sizeof(float)]; int fd, n, error, r = 0; DIRFILE *D; rmdirfile(); mkdir(filedir, 0777); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_FLOAT32, &c); error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY); lseek(fd, 5 * sizeof(float), SEEK_SET); read(fd, u, sizeof(float)); close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(error, 0); CHECKI(n, 1); for (i = 0; i < sizeof(float); ++i) CHECKXi(i, u[i], x[i]); return r; }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; char format_data[1000]; uint32_t c = 0x2000001, d = 0; const int big_endian = BigEndian(); int fd, n, error, r = 0; DIRFILE *D; rmdirfile(); mkdir(filedir, 0777); sprintf(format_data, "data RAW UINT32 1\nENDIAN %s\n", (big_endian) ? "little" : "big"); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT32, &c); error = gd_error(D); gd_close(D); fd = open(data, O_RDONLY | O_BINARY); lseek(fd, 5 * sizeof(uint32_t), SEEK_SET); read(fd, &d, sizeof(uint32_t)); close(fd); unlink(data); unlink(format); rmdir(filedir); CHECKI(error,0); CHECKI(n,1); CHECKX(d,0x1000002); return r; }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "polynom POLYNOM data 3.0 2.0 1.0 0.5\ndata RAW INT8 8\n"; int8_t c[8]; struct stat buf; int fd, i, n, error, r = 0; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = (int8_t)(40 + i); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED); n = gd_putdata(D, "polynom", 5, 0, 1, 0, GD_INT8, c); error = gd_error(D); gd_close(D); if (!stat(data, &buf)) { perror("stat"); r = 1; } unlink(format); rmdir(filedir); CHECKI(n,0); CHECKI(error,GD_E_BAD_FIELD_TYPE); return r; }
int main(void) { #ifndef TEST_GZIP return 77; #else const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data_gz = "dirfile/data.gz"; const char *data = "dirfile/data"; const char *format_data = "data RAW UINT8 8\n"; uint8_t c[8]; #ifdef USE_GZIP char command[4096]; uint8_t d; #endif struct stat buf; int fd, i, n, error, stat_data, unlink_data, r = 0; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) c[i] = (uint8_t)(40 + i); fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); #ifdef USE_GZIP D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED | GD_VERBOSE); #else D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED); #endif n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); error = gd_error(D); gd_discard(D); stat_data = stat(data_gz, &buf); #ifdef USE_GZIP if (stat_data) { perror("stat"); } CHECKI(stat_data, 0); #else CHECKI(stat_data, -1); #endif #ifdef USE_GZIP /* uncompress */ snprintf(command, 4096, "%s -f %s > /dev/null", GUNZIP, data); if (gd_system(command)) { r = 1; } else { fd = open(data, O_RDONLY | O_BINARY); if (fd >= 0) { i = 0; while (read(fd, &d, sizeof(uint8_t))) { if (i < 40 || i > 48) { CHECKIi(i, d, 0); } else CHECKIi(i, d, i); i++; } CHECKI(i, 48); close(fd); } } #endif unlink_data = unlink(data); unlink(format); rmdir(filedir); #ifdef USE_GZIP CHECKI(unlink_data, 0); CHECKI(error, GD_E_OK); CHECKI(n, 8); #else CHECKI(unlink_data, -1); CHECKI(error, GD_E_UNSUPPORTED); CHECKI(n, 0); #endif return r; #endif }
int main(void) { const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *format_data = "data RAW COMPLEX128 8\n"; #ifdef GD_NO_C99_API double c[8][2], d[2]; const double zero[] = {0, 0}; #else double complex c[8], d; const double complex zero = 0; #endif int fd, i, n, error, r = 0; struct stat buf; DIRFILE *D; memset(c, 0, 8); rmdirfile(); mkdir(filedir, 0777); for (i = 0; i < 8; ++i) { #ifdef GD_NO_C99_API c[i][0] = 40 + i; c[i][1] = i; #else c[i] = 40 + i * (1 + _Complex_I); #endif } fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); write(fd, format_data, strlen(format_data)); close(fd); D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); n = gd_putdata(D, "data", 5, 0, 1, 0, GD_COMPLEX128, c); error = gd_error(D); gd_close(D); if (stat(data, &buf)) { perror("stat"); r = 1; } CHECKI(buf.st_size, 48 * 2 * sizeof(double)); fd = open(data, O_RDONLY | O_BINARY); if (fd < 0) { perror("open"); r = 1; } else { i = 0; #ifdef GD_NO_C99_API while (read(fd, d, 2 * sizeof(double))) #else while (read(fd, &d, sizeof(double complex))) #endif { if (i < 40 || i > 48) { CHECKCi(i,d,zero); } else { #ifdef GD_NO_C99_API double v[] = {i, i - 40}; #else double complex v = i + _Complex_I * (i - 40); #endif CHECKCi(i,d,v); } i++; } close(fd); } unlink(data); unlink(format); rmdir(filedir); CHECKI(error, 0); CHECKI(n,8); return r; }
int main(int argc, char *argv[]) { char dirfilename[1024]; int i_ch; char fieldlist[255][255]; DIRFILE *df_out; int fp_lnc; int n_read = 0; struct fifoStruct fs; int i_frame = 0; uint8_t c_in; int16_t s_in; uint16_t u_in; int32_t S_in; uint32_t U_in; double x_in; time_t t; fs.i_in = fs.i_out = 0; if (argc!=2) Usage(); if (argv[1][0]=='-') Usage(); strncpy(hostname, argv[1], 250); sprintf(dirfilename, "%s/%lu.l", RAWDIR, time(NULL)); df_out = gd_open(dirfilename, GD_RDWR | GD_UNENCODED | GD_CREAT | GD_TRUNC); /* add fields to dirfile */ for (i_ch =0; slowDLList[i_ch].name[0] != '\0'; i_ch++) { convertToUpper(slowDLList[i_ch].name, fieldlist[i_ch]); if (slowDLList[i_ch].encode == SDL_SCALE) { gd_add_raw(df_out, fieldlist[i_ch], GD_FLOAT64, 1, 0); } else { switch (slowDLList[i_ch].type) { case 'c': gd_add_raw(df_out, fieldlist[i_ch], GD_UINT8, 1, 0); break; case 's': gd_add_raw(df_out, fieldlist[i_ch], GD_INT16, 1, 0); break; case 'u': gd_add_raw(df_out, fieldlist[i_ch], GD_UINT16, 1, 0); break; case 'S': gd_add_raw(df_out, fieldlist[i_ch], GD_INT32, 1, 0); break; case 'U': gd_add_raw(df_out, fieldlist[i_ch], GD_UINT32, 1, 0); break; default: break; // shouldn't be possible } } } gd_flush(df_out, NULL); unlink(LNKFILE); if (symlink(dirfilename, LNKFILE)<0) { fprintf(stderr, "could not create link from `%s' to `%s'", dirfilename, LNKFILE); exit(0); } strncpy(hostname, argv[1], 250); fp_lnc = party_connect(hostname, PORT); while (1) { do { if (nFifo(&fs)<4) { n_read += BlockingRead(4, &fs, fp_lnc, hostname, PORT); } peek(&fs, (char *)&U_in, 4); advance(&fs, 1); } while (U_in != SLOWDLSYNCWORD); advance(&fs, 4-1); for (i_ch =0; slowDLList[i_ch].name[0] != '\0'; i_ch++) { // read the word switch (slowDLList[i_ch].type) { case 'c': if (nFifo(&fs)<1) { n_read += BlockingRead(1, &fs, fp_lnc, hostname, PORT); } pop(&fs, (char *)&c_in, 1); break; case 's': if (nFifo(&fs)<2) { n_read += BlockingRead(2, &fs, fp_lnc, hostname, PORT); } pop(&fs, (char *)&s_in, 2); break; case 'u': if (nFifo(&fs)<2) { n_read += BlockingRead(2, &fs, fp_lnc, hostname, PORT); } pop(&fs, (char *)&u_in, 2); break; case 'S': if (nFifo(&fs)<4) { n_read += BlockingRead(4, &fs, fp_lnc, hostname, PORT); } pop(&fs, (char *)&S_in, 4); break; case 'U': if (nFifo(&fs)<4) { n_read += BlockingRead(4, &fs, fp_lnc, hostname, PORT); } pop(&fs, (char *)&U_in, 4); break; default: break; } // write the word if (slowDLList[i_ch].encode == SDL_SCALE) { switch (slowDLList[i_ch].type) { case 'c': x_in = (double)c_in / (double)0xff; break; case 'u': x_in = (double)u_in / (double)0xffff; break; case 'U': x_in = (double)U_in / (double)0xffff; break; default: // not allowed break; } x_in = slowDLList[i_ch].min + x_in * (slowDLList[i_ch].max - slowDLList[i_ch].min); gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_FLOAT64, &x_in); } else { switch (slowDLList[i_ch].type) { case 'c': gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_UINT8, &c_in); break; case 's': gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_INT16, &s_in); break; case 'u': gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_UINT16, &u_in); break; case 'S': gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_INT32, &S_in); break; case 'U': gd_putdata(df_out, fieldlist[i_ch], i_frame, 0, 1, 0, GD_UINT32, &U_in); break; default: // shouldn't happen break; } } } // next i_ch; t = time(NULL); printf("%s: frame %4d - %s", argv[0], i_frame, ctime(&t)); i_frame++; } return 0; }