LOG_KdNeuralNetwork_test.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Short code to test Jamet C. Neural Network Kd inversion.
  3. C coding version :
  4. 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
  5. LOG (Laboratoire d'Oceanoligie et Geoscience)
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <errno.h>
  11. #include <unistd.h>
  12. #include <memory.h>
  13. #include <math.h>
  14. #include "iop_Rrs_neuron.h"
  15. #include "neuron_switch160715.h"
  16. #define PI 3.14159265
  17. #define NBWL 6
  18. #define NBNE 7
  19. /* neuron_kd_1cc.c functions*/
  20. extern void neuron_lect_LUTswitch(int idCap, char *path);
  21. extern float rsupOL_neuron_passe_avant(float x[rsupOL_NE+1]); /* Neural network Kd computation switch SeaWiFS */
  22. extern float rinfOL_neuron_passe_avant(float x[rinfOL_NE]);
  23. // extern float rsupMO_neuron_passe_avant(float x[rsupMO_NE+1]); /* Neural network Kd computation switch MODIS */
  24. // extern float rinfMO_neuron_passe_avant(float x[rinfMO_NE]);
  25. // extern float rsupOL_neuron_passe_avant(float x[rsupOL_NE+1]); /* Neural network Kd computation switch MERIS / OLCI */
  26. // extern float rinfOL_neuron_passe_avant(float input[rinfOL_NE]);
  27. //
  28. float LO[NBWL] = {413.,443.,490.,510.,560.,665.};
  29. int main (argc, argv)
  30. int argc;
  31. char *argv[];
  32. {
  33. FILE *fic, *out;
  34. int i, status;
  35. char nomfic[500];
  36. float RRS[NBNE]; /* inputs */
  37. float KD[NBWL]; /* outputs */
  38. float s2RRS[rinfOL_NE], rap;
  39. if(argc != 3){
  40. printf("launch with arguments : \n");
  41. printf(" - input file name [file with %d columns for SeaWiFS Wave-length : 412.,443.,490.,510.,550.,670.]\n",(int)NBWL);
  42. printf(" - output filename\n");
  43. }
  44. /*## Kd LUTs initialization ##*/
  45. neuron_lect_LUTswitch(idMERIS, "../LUTS");
  46. /* input file */
  47. if( (fic=fopen(argv[1],"r")) == NULL ) {perror(argv[1]); exit(-1);}
  48. fgets(nomfic,500,fic);
  49. /* foutput file */
  50. if( (out=fopen(argv[2],"w")) == NULL ) {perror(argv[3]); exit(-1);}
  51. for(i=0; i<NBLO; i++)
  52. fprintf(out,"Kd%g ",LO[i]);
  53. fprintf(out,"\n");
  54. while( (status = fscanf(fic,"%f",&RRS[0])) == 1){
  55. for(i=1; i<NBWL; i++)
  56. fscanf(fic,"%f",&RRS[i]);
  57. /* Choix du reseau a utiliser en fonction du rapport 490/555 */
  58. rap = RRS[2]/RRS[4];
  59. if( rap >= .85 )
  60. for(i=0; i<rsupOL_NE-1; i++)
  61. s2RRS[i] = RRS[i+1];
  62. else
  63. for(i=0; i<rinfOL_NE-1; i++)
  64. s2RRS[i] = RRS[i+1];
  65. for(i=0; i<NBWL; i++){
  66. if( rap >= .85 ){
  67. s2RRS[rsupOL_NE-1] = LO[i];
  68. KD[i] = rsupOL_neuron_passe_avant(s2RRS);
  69. }
  70. else{
  71. s2RRS[rinfOL_NE-1] = LO[i];
  72. KD[i] = rinfOL_neuron_passe_avant(s2RRS);
  73. }
  74. }
  75. for(i=0; i<NBLO; i++)
  76. fprintf(out,"%g ", KD[i]);
  77. fprintf(out,"\b\n");
  78. }
  79. fclose(fic);
  80. fclose(out);
  81. return(0);
  82. }