fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define MAX_INDEX 1604
  4.  
  5. /* Prototype of functions */
  6. double Red(double, double, double);
  7. double Green(double, double, double);
  8. double Blue(double, double, double);
  9.  
  10.  
  11. int main()
  12. {
  13.  
  14.  
  15. FILE *fpX, *fpY, *fpZ;
  16. fpX = fopen("tabrefX.dat","r");
  17. fpY = fopen("tabrefY.dat","r");
  18. fpZ = fopen("tabrefZ.dat","r");
  19. double tabrefX[MAX_INDEX];
  20. double tabrefY[MAX_INDEX];
  21. double tabrefZ[MAX_INDEX];
  22. int i;
  23. double resultR[MAX_INDEX];
  24. double resultG[MAX_INDEX];
  25. double resultB[MAX_INDEX];
  26.  
  27.  
  28. /* We read all values from files tabrefX.dat, tabrefY.dat and tabrefZ.dat */
  29. /* and ze fill up tabrefX, tabrefY and tabrefZ */
  30.  
  31. i = 0;
  32. if (fpX != NULL)
  33. {
  34. while(fscanf(fpX, "%lg\n", &(tabrefX[i])) != EOF)
  35. i++;
  36.  
  37. printf("Complete File");
  38. fclose(fpX);
  39. }
  40. else {
  41. printf("error in file tabrefX.dat \n");
  42. return 0;
  43. }
  44.  
  45. i = 0;
  46. if (fpY != NULL)
  47. {
  48. while(fscanf(fpY, "%lg\n", &(tabrefY[i])) != EOF)
  49. i++;
  50.  
  51. printf("Complete File");
  52. fclose(fpY);
  53. }
  54. else {
  55. printf("error in file tabrefY.dat \n");
  56. return 0;
  57. }
  58.  
  59. i = 0;
  60. if (fpZ != NULL)
  61. {
  62. while(fscanf(fpZ, "%lg\n", &(tabrefZ[i])) != EOF)
  63. i++;
  64.  
  65. printf("Complete File");
  66. fclose(fpZ);
  67. }
  68. else {
  69. printf("error in file tabrefZ.dat \n");
  70. return 0;
  71. }
  72. return 0;
  73. }
  74.  
  75.  
  76. double CIE_L(double Y)
  77. {
  78. double var_Y ;
  79. double val_l ;
  80. var_Y = Y/100.000;
  81. {
  82. if (var_Y>0.008856)
  83. {
  84. var_Y = pow(var_Y,1/3);
  85. }
  86. else
  87. {
  88. var_Y = (7.787*var_Y) + (16/116);
  89. }
  90. }
  91. val_l = (116*var_Y) - 16;
  92. return val_l;
  93. }
  94.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
error in file tabrefX.dat