Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lut1024f.c 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * LUT 1024 -> FLOAT
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "lut1024.h"
  8. extern int verbosity;
  9. /* ---------------------------------------------------------------- */
  10. int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused)
  11. {
  12. int count, foo;
  13. for(count=0; count<1024; count++) {
  14. foo = fscanf(fp, "%f", &where->vals[foo]);
  15. if (1 != foo) {
  16. fprintf(stderr, "%s: bad read %d\n", __func__, foo);
  17. return -4;
  18. }
  19. }
  20. return 0;
  21. }
  22. /* ---------------------------------------------------------------- */
  23. int load_lut1024f(char *fname, Lut1024f *where, int notused)
  24. {
  25. FILE *fplut;
  26. char firstline[100];
  27. char label[] = "LUT1024F";
  28. int foo;
  29. #if DEBUG_LEVEL
  30. fprintg(stderr, ">>> %s ( '%s' %p %d )\n", __func__,
  31. fname, where, notused);
  32. #endif
  33. if (NULL==(fplut=fopen(fname, "r"))) {
  34. perror(fname);
  35. return -2;
  36. }
  37. fprintf(stderr, "%s: getting first line\n", __func__);
  38. if (NULL==fgets(firstline, 20, fplut)) {
  39. fprintf(stderr, "%s: nothing to read from %s\n",
  40. __func__, fname);
  41. return -3;
  42. }
  43. foo = strncmp(label, firstline, sizeof(label)-1);
  44. if (foo) {
  45. fprintf(stderr, "%s: bad label [%s]\n", __func__, firstline);
  46. exit(5);
  47. }
  48. foo = slurp_lut1024f(fplut, where, 0);
  49. fclose(fplut);
  50. return -1;
  51. }
  52. /* ---------------------------------------------------------------- */