Default Seadas User 8 年之前
當前提交
acc034bd92

+ 195 - 0
class_KdJamet.py

@@ -0,0 +1,195 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import numpy as np
+import sys
+import os
+
+Sensor = {'idSEAWIFS' = 0, 'idMODIS' = 1, 'idMERIS' = 2}
+
+class Kd_Jamet:
+  def __init__(self, idSensor):
+    try:
+      self.lutpath = os.getenv('KD_LUT_PATH')
+    except:
+      print "KD_LUT_PATH not set, add it to your environement variables"
+      sys.exit()
+      
+    if Sensor.has_key(idSensor):
+      self.init_variables(Sensor[idSensor])
+      try:
+        self.read_LUTs_Kd(Sensor[idSensor])
+      except:
+        print "Failed to read %s LUTs" % (idSensor)
+        sys.exit()
+  
+  # -
+  # Perceptron parameters setting and array initialization for each Sensor
+  # -
+  def init_variables(self, idSensor):
+    # =======================================================================================================
+    # MERIS / OLCI 
+    # =======================================================================================================
+    if idSensor == Sensor['idMERIS']:
+      # Variables definiton for network Rrs490/Rrs555 >= .85 -------------------------------------------------
+      # hidden layer number 
+      self.rsup_NC 2
+      # input data number
+      self.rsup_NE 5
+      # number of neuron in the first hidden layer 
+      self.rsup_NC1 7
+      # number of neuron in the second hidden layer
+      self.rsup_NC2 4
+      # nb output
+      self.rsup_NS 1
+      # nb input + nb output*/
+      self.rsup_NES 6
+      # LUTs file names 
+      self.rsup_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_7_4_switch_110416.sn"
+      self.rsupLUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rsup_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+
+      # Variables definiton for network Variables definiton for network < .85 -----------------------------------
+      # nombre de couches cachees - hidden layer number
+      self.rinf_NC 2
+      # input data number*/
+      self.rinf_NE 6
+      # number of neuron in the first hidden layer
+      self.rinf_NC1 5
+      # number of neuron in the second hidden layer
+      self.rinf_NC2 5
+      # nb output
+      self.rinf_NS 1
+      # nb input + nb output
+      self.rinf_NES 7
+      #LUTs file names
+      self.rinf_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_5_switch_110416.sn"
+      self.rinf_LUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+      self.rinf_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+
+    #LUTs arrays definition
+    self.rsup_b1 = np.zeros((rsup_NC1), dtype=np.float32) 
+    self.rsup_b2 = np.zeros((rsup_NC2), dtype=np.float32) 
+    self.rsup_b3 = 0.
+    self.rsup_w1 = np.zeros((rsup_NE,rsup_NC1), dtype=np.float32)
+    self.rsup_w2 = np.zeros((rsup_NC1,rsup_NC2), dtype=np.float32)
+    self.rsup_w3 = np.zeros((rsup_NC2), dtype=np.float32)
+    self.rsup_moy = np.zeros((rsup_NES), dtype=np.float32)
+    self.rsup_ecart = np.zeros((rsup_NES), dtype=np.float32)
+
+    self.rinf_b1 = np.zeros((rinf_NC1), dtype=np.float32)
+    self.rinf_b2 = np.zeros((rinf_NC2), dtype=np.float32)
+    self.rinf_b3 = 0.
+    self.rinf_w1 = np.zeros((rinf_NE,rinf_NC1), dtype=np.float32)
+    self.rinf_w2 = np.zeros((rinf_NC1,rinf_NC2), dtype=np.float32)
+    self.rinf_w3 = np.zeros((rinf_NC2), dtype=np.float32)
+    self.rinf_moy = np.zeros((rinf_NES), dtype=np.float32)
+    self.rinf_ecart = np.zeros((rinf_NES), dtype=np.float32)
+  
+  # -
+  # perceptron weights LUT reading
+  # -
+  def read_LUTs_Kd(self):
+    # ----------------------------------------------------------------------------------
+    #  < .85 weights settings
+    weights = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_POIDS), skiprows=1)
+    base = 0
+    self.rinf_b1 = weights[base:base+self.rinf_NC1,2]
+    base = base+self.rinf_NC1
+    self.rsup_b2 = weights[base:base+self.rinf_NC2,2]
+    base = base+self.rinf_NC2
+    self.rsup_b3 = weights[base:base+self.rinf_NS,2]
+    base = base+self.rinf_NS
+    for i in range(self.rinf_NE):
+      self.rinf_w1[i,:] = weights[base:base+self.rinf_NC1,2]
+      base = base+self.rinf_NC1
+    for i in range(self.rinf_NC1):
+      self.rinf_w2[i,:] = weights[base:base+self.rinf_NC2,2]
+      base = base+self.rinf_NC2
+    self.rinf_w3 = weights[base:base+self.rinf_NC3,2]
+    
+    usedData = np.array([1,2,3,4,5,6,8])
+    if idSensor == Sensor['idMODIS']:
+      usedData = np.array([1,2,3,4,6,7,9])
+    moy = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_MOY))
+    self.rinf_moy = moy[usedData]
+    ecart = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rinf_LUT_ECART))
+    self.rinf_ecart = ecart[usedData]
+    
+    # ----------------------------------------------------------------------------------
+    #  >= .85 weights settings
+    weights = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_POIDS), skiprows=1)
+    base = 0
+    self.rsup_b1 = weights[base:base+self.rsup_NC1,2]
+    base = base+self.rsup_NC1
+    self.rsup_b2 = weights[base:base+self.rsup_NC2,2]
+    base = base+self.rsup_NC2
+    self.rsup_b3 = weights[base:base+self.rsup_NS,2]
+    base = base+self.rsup_NS
+    for i in range(self.rsup_NE):
+      self.rsup_w1[i,:] = weights[base:base+self.rsup_NC1,2]
+      base = base+self.rsup_NC1
+    for i in range(self.rsup_NC1):
+      self.rsup_w2[i,:] = weights[base:base+self.rsup_NC2,2]
+      base = base+self.rsup_NC2
+    self.rsup_w3 = weights[base:base+self.rsup_NC3,2]
+    
+    usedData = np.array([1,2,3,4,6,8])
+    if idSensor == Sensor['idMODIS']:
+      usedData = np.array([1,2,3,4,7,9])
+    moy = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_MOY))
+    self.rsup_moy = moy[usedData]
+    ecart = numpy.loadtxt( "%s/%s" % (self.lutpath, self.rsup_LUT_ECART))
+    self.rsup_ecart = ecart[usedData]
+    
+  # -
+  # Kd computing   < .85
+  # input = nRrs + output Lambda
+  # -
+  def passe_avant_sup(self, indata):
+    # Normalization
+    x = ((2/3.) * indata[:] - self.rsup_moy[:]) / self.rsup_ecart[:]
+    
+    a = np.zeros(self.rsup_NC1,dtype=np.float32)
+    for i in range(self.rsup_NC1):
+      for j in range(self.rsup_NE):
+        a[i] = a[i] + x[j] * self.rsup_w1[j][i]
+    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rsupSW_b1[:]))
+
+    b = np.zeros[self.rsup_NC2,dtype=np.float32]
+    for i in range(self.rsup_NC2):
+      for j in range(self.rsup_NC1):
+        b[i] = b[i] + a[j] * self.rsup_w2[j][i]
+    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rsupSW_b2[:]))
+    
+    y = np.sum(b[:] * self.rsupSW_w3[:])
+    # Denormalisation 
+    y = 1.5*(y + self.rsupSW_b3)*self.rsupSW_ecart[self.rsupSW_NES-1] + self.rsupSW_moy[self.rsupSW_NES-1]
+    y = 10.**y
+    return(y)
+  
+  # -
+  # Kd computing  >= .85 
+  # input = nRrs + output Lambda
+  # -
+  def passe_avant_inf(self, indata):
+    # Normalization
+    x = ((2/3.) * indata[:] - self.rinf_moy[:]) / self.rinf_ecart[:]
+    
+    a = np.zeros(self.rinf_NC1,dtype=np.float32)
+    for i in range(self.rinf_NC1):
+      for j in range(self.rinf_NE):
+        a[i] = a[i] + x[j] * self.rinf_w1[j][i]
+    a[:] = 1.715905*np.tanh((2./3.)*(a[:] + self.rinfSW_b1[:]))
+
+    b = np.zeros[self.rinf_NC2,dtype=np.float32]
+    for i in range(self.rinf_NC2):
+      for j in range(self.rinf_NC1):
+        b[i] = b[i] + a[j] * self.rinf_w2[j][i]
+    b[:] = 1.715905*np.tanh((2./3.)*(b[:] + self.rinfSW_b2[:]))
+    
+    y = np.sum(b[:] * self.rinfSW_w3[:])
+    # Denormalisation 
+    y = 1.5*(y + self.rinfSW_b3)*self.rinfSW_ecart[self.rinfSW_NES-1] + self.rinfSW_moy[self.rinfSW_NES-1]
+    y = 10.**y
+    return(y)

+ 22 - 0
neuron_difKd1cc_22.h

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+/* nombre de couches cachees - hidden layer number */
+#define DNC 1
+/* nombre de donnees d entree - input data number*/
+#define DNE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define DNC1 22
+/* nombre de donnees de sortie - nb output*/
+#define DNS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define DNES 6
+
+/* LUTs file names */
+#define LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_ascii_6x1_hh_22_publi_150114.sn"
+#define LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+#define LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+
+/* LUTs parameters definition */
+float b1[DNC1], b2;
+float w1[DNE][DNC1], w2[DNC1];
+float moy[DNES], ecart[DNES];

+ 22 - 0
neuron_difKd1cc_26.h

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+/* nombre de couches cachees - hidden layer number */
+#define DNC 1
+/* nombre de donnees d entree - input data number*/
+#define DNE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define DNC1 26
+/* nombre de donnees de sortie - nb output*/
+#define DNS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define DNES 6
+
+/* LUTs file names */
+#define LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_ascii_6x1_hh_26_publi_150114.sn"
+#define LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+#define LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+
+/* LUTs parameters definition */
+float b1[DNC1], b2;
+float w1[DNE][DNC1], w2[DNC1];
+float moy[DNES], ecart[DNES];

+ 22 - 0
neuron_difKd1cc_6.h

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+/* nombre de couches cachees - hidden layer number */
+#define DNC 1
+/* nombre de donnees d entree - input data number*/
+#define DNE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define DNC1 6
+/* nombre de donnees de sortie - nb output*/
+#define DNS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define DNES 6
+
+/* LUTs file names */
+#define dif_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_ascii_6x1_hh_6_publi_150114.sn"
+#define dif_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+#define dif_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+
+/* LUTs parameters definition */
+float dif_b1[DNC1], dif_b2;
+float dif_w1[DNE][DNC1], dif_w2[DNC1];
+float dif_moy[DNES], dif_ecart[DNES];

+ 22 - 0
neuron_difKd2cc_6x4.h

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+/* nombre de couches cachees */
+#define DNC 2
+/* nombre de donnees d entree*/
+#define DNE 5
+/* nombre de neurones de la premiere couche cachee */
+#define DNC1 6
+/* nombre de neurones de la deuxieme couche cachee */
+#define DNC2 4
+/* nombre de donnees de sortie */
+#define DNS 1
+/* nombre de neurones d'entree + sortie  */
+#define DNES 6
+
+#define LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_ascii_6x1_hh_6_4_publi_150114.sn"
+#define LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+#define LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+
+float b1[DNC1], b2[DNC2], b3;
+float w1[DNE][DNC1], w2[DNC1][DNC2], w3[DNC2];
+float moy[DNES], ecart[DNES];

+ 22 - 0
neuron_difKd2cc_7x5.h

@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+/* nombre de couches cachees */
+#define DNC 2
+/* nombre de donnees d entree*/
+#define DNE 5
+/* nombre de neurones de la premiere couche cachee */
+#define DNC1 7
+/* nombre de neurones de la deuxieme couche cachee */
+#define DNC2 5
+/* nombre de donnees de sortie */
+#define DNS 1
+/* nombre de neurones d'entree + sortie  */
+#define DNES 6
+
+#define LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_ascii_6x1_hh_7_5_publi_150114.sn"
+#define LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+#define LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114.dat"
+
+float b1[DNC1], b2[DNC2], b3;
+float w1[DNE][DNC1], w2[DNC1][DNC2], w3[DNC2];
+float moy[DNES], ecart[DNES];

+ 94 - 0
neuron_difKd_1cc_22.c

@@ -0,0 +1,94 @@
+/*
+ Kd estimation references :
+ Jamet, C., H. Loisel, and D. Dessailly (2012), Retrieval of the spectral diffuse attenuation coefficient Kd(l) in open and coastal ocean waters using a neural network inversion, J. Geophys. Res., 117, C10023, doi:10.1029/2012JC008076.
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Estimation of the diffuse attenuation coefficient Kd(lambda) with a neural network,  Proceedings of IGARSS '11
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Empirical nonlinear determination of the diffuse attenuation coefficient Kd(490) in coastal waters from ocean color image,  Proceedings of SPIE-Asia-Pacific Remote Sensing, DOI: 10.1117/12.869730
+
+ C coding version :
+ 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
+
+ Laboratoire d'Oceanoligie et Geoscience (LOG)
+*/
+
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_difKd1cc_22.h"
+
+/* -------------------------------------------------------------------------------
+  Lecture des differentes Look Up Tables  -  LUTs reading
+   - Files names and path define in neuron1cc.h
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs_dif()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<DNC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b2);
+  for(j=0; j<DNE; j++){
+   for(i=0; i<DNC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<DNC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w2[j]);
+  fclose(fic);
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&moy[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&moy[DNES-1]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&ecart[DNES-1]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids  -  Kd computing from NN weights
+ - Input:
+  input[DNE] = Rrs[412 443 490 510 555 670], WaveLenght (for desired output Kd)
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant_dif(float input[DNE])
+{
+  float a[DNC1], y=0.0, x[DNE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<DNE; i++){
+    x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
+  }
+
+  for(i=0;i<DNC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<DNE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+
+  for(j=0;j<DNC1;j++){
+    y += (a[j] * w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b2)*ecart[DNES-1] + moy[DNES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}

+ 94 - 0
neuron_difKd_1cc_26.c

@@ -0,0 +1,94 @@
+/*
+ Kd estimation references :
+ Jamet, C., H. Loisel, and D. Dessailly (2012), Retrieval of the spectral diffuse attenuation coefficient Kd(l) in open and coastal ocean waters using a neural network inversion, J. Geophys. Res., 117, C10023, doi:10.1029/2012JC008076.
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Estimation of the diffuse attenuation coefficient Kd(lambda) with a neural network,  Proceedings of IGARSS '11
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Empirical nonlinear determination of the diffuse attenuation coefficient Kd(490) in coastal waters from ocean color image,  Proceedings of SPIE-Asia-Pacific Remote Sensing, DOI: 10.1117/12.869730
+
+ C coding version :
+ 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
+
+ Laboratoire d'Oceanoligie et Geoscience (LOG)
+*/
+
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_difKd1cc_26.h"
+
+/* -------------------------------------------------------------------------------
+  Lecture des differentes Look Up Tables  -  LUTs reading
+   - Files names and path define in neuron1cc.h
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs_dif()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<DNC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b2);
+  for(j=0; j<DNE; j++){
+   for(i=0; i<DNC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<DNC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w2[j]);
+  fclose(fic);
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&moy[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&moy[DNES-1]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&ecart[DNES-1]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids  -  Kd computing from NN weights
+ - Input:
+  input[DNE] = Rrs[412 443 490 510 555 670], WaveLenght (for desired output Kd)
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant_dif(float input[DNE])
+{
+  float a[DNC1], y=0.0, x[DNE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<DNE; i++){
+    x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
+  }
+
+  for(i=0;i<DNC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<DNE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+
+  for(j=0;j<DNC1;j++){
+    y += (a[j] * w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b2)*ecart[DNES-1] + moy[DNES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}

+ 97 - 0
neuron_difKd_1cc_6.c

@@ -0,0 +1,97 @@
+/*
+ Kd estimation references :
+ Jamet, C., H. Loisel, and D. Dessailly (2012), Retrieval of the spectral diffuse attenuation coefficient Kd(l) in open and coastal ocean waters using a neural network inversion, J. Geophys. Res., 117, C10023, doi:10.1029/2012JC008076.
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Estimation of the diffuse attenuation coefficient Kd(lambda) with a neural network,  Proceedings of IGARSS '11
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Empirical nonlinear determination of the diffuse attenuation coefficient Kd(490) in coastal waters from ocean color image,  Proceedings of SPIE-Asia-Pacific Remote Sensing, DOI: 10.1117/12.869730
+
+ C coding version :
+ 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
+
+ Laboratoire d'Oceanoligie et Geoscience (LOG)
+*/
+
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_difKd1cc_6.h"
+
+/* -------------------------------------------------------------------------------
+  Lecture des differentes Look Up Tables  -  LUTs reading
+   - Files names and path define in neuron1cc.h
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs_dif(char LUT_PATH[])
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150), nomfic[500];
+  float fpoub;
+
+  sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_POIDS);
+  if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<DNC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&dif_b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&dif_b2);
+  for(j=0; j<DNE; j++){
+   for(i=0; i<DNC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&dif_w1[j][i]);
+  }
+  for(j=0; j<DNC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&dif_w2[j]);
+  fclose(fic);
+
+  sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_MOY);
+  if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&dif_moy[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&dif_moy[DNES-1]);
+  fclose(fic);
+  sprintf(nomfic,"%s/%s",LUT_PATH,dif_LUT_ECART);
+  if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&dif_ecart[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&dif_ecart[DNES-1]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids  -  Kd computing from NN weights
+ - Input:
+  input[DNE] = Rrs[412 443 490 510 555], WaveLenght (for desired output Kd)
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant_dif(float input[DNE])
+{
+  float a[DNC1], y=0.0, x[DNE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<DNE; i++){
+    x[i] = ((2./3.)*(input[i]-dif_moy[i]))/dif_ecart[i];
+  }
+
+  for(i=0;i<DNC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<DNE;j++){
+      a[i] += (x[j]*dif_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + dif_b1[i]));
+  }
+
+  for(j=0;j<DNC1;j++){
+    y += (a[j] * dif_w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + dif_b2)*dif_ecart[DNES-1] + dif_moy[DNES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}

+ 136 - 0
neuron_difKd_2cc_6x4.c

@@ -0,0 +1,136 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_difKd2cc_6x4.h"
+
+/* -------------------------------------------------------------------------------
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs_dif()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<DNC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  for(i=0; i<DNC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b2[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b3);
+  for(j=0; j<DNE; j++){
+   for(i=0; i<DNC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<DNC1; j++){
+    for(i=0; i<DNC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&w2[j][i]);
+  }
+  for(i=0; i<DNC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w3[i]);
+  fclose(fic);
+
+/*  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNES; i++)
+    fscanf(fic,"%f",&moy[i]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNES; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  fclose(fic);*/
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&moy[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&moy[DNES-1]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&ecart[DNES-1]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[DNE] = Rrs (412) 443 490 510 555 670 ASOL
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant_dif(float input[DNE])
+{
+  float a[DNC1], b[DNC2], y=0.0, x[DNE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<DNE; i++){
+    x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
+  }
+
+  for(i=0;i<DNC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<DNE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+  for(i=0;i<DNC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<DNC1;j++){
+      b[i] += (a[j]*w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + b2[i]));
+  }
+  for(j=0;j<DNC2;j++){
+    y += (b[j]*w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b3)*ecart[DNES-1] + moy[DNES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*
+int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[DNE],result_in,result_out,res_norm, sum_rms=0., sum_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_Kd_lambda_merge_seuil_15_diff_publi_150114_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs_dif();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<DNE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    res_norm = ((2./3.)*(result_in-moy[DNES-1]))/ecart[DNES-1];
+    result_out = neuron_passe_avant_dif(data_in);
+    result_in = 1.5*res_norm*ecart[DNES-1] + moy[DNES-1];
+    result_in = (float)pow(10.,result_in);
+
+    sum_rms += (float)pow((double)(result_in-result_out),2.);
+    sum_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f\n",result_in,result_out);
+    nb++;
+  }
+  printf("rmse = %f, rel err= %f   nb = %d\n",(float)sqrt((double)sum_rms/nb),sum_rel/nb,nb);
+  fclose(fic);
+  exit(1);
+}
+*/

+ 125 - 0
neuron_difKd_2cc_7x5.c

@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_difKd2cc_7x5.h"
+
+/* -------------------------------------------------------------------------------
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs_dif()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<DNC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  for(i=0; i<DNC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b2[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b3);
+  for(j=0; j<DNE; j++){
+   for(i=0; i<DNC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<DNC1; j++){
+    for(i=0; i<DNC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&w2[j][i]);
+  }
+  for(i=0; i<DNC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w3[i]);
+  fclose(fic);
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&moy[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&moy[DNES-1]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<DNE; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  for(i=0; i<3; i++)
+    fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&ecart[DNES-1]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[DNE] = Rrs (412) 443 490 510 555 670 ASOL
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant_dif(float input[DNE+1])
+{
+  float a[DNC1], b[DNC2], y=0.0, x[DNE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<DNE; i++){
+    x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
+  }
+
+  for(i=0;i<DNC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<DNE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+  for(i=0;i<DNC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<DNC1;j++){
+      b[i] += (a[j]*w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + b2[i]));
+  }
+  for(j=0;j<DNC2;j++){
+    y += (b[j]*w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b3)*ecart[DNES-1] + moy[DNES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*
+int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[DNE],result_in,result_out,res_norm, sum_rms=0., sum_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("LUTS/base_Kd490_IOCCG_NOMAD_all_log_Kd_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<DNE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    res_norm = ((2./3.)*(result_in-moy[DNES-1]))/ecart[DNES-1];
+    result_out = passe_avant(data_in);
+    result_in = 1.5*res_norm*ecart[DNES-1] + moy[DNES-1];
+    result_out = (float)pow(10.,result_out);
+    result_in = (float)pow(10.,result_in);
+
+    sum_rms += (float)pow((double)(result_in-result_out),2.);
+    sum_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f\n",result_in,result_out);
+    nb++;
+  }
+  printf("rmse = %f, rel err= %f   nb = %d\n",(float)sqrt((double)sum_rms/nb),sum_rel/nb,nb);
+  fclose(fic);
+  exit(1);
+}*/

+ 86 - 0
neuron_kd_1cc.c

@@ -0,0 +1,86 @@
+/*
+ Kd estimation references :
+ Jamet, C., H. Loisel, and D. Dessailly (2012), Retrieval of the spectral diffuse attenuation coefficient Kd(l) in open and coastal ocean waters using a neural network inversion, J. Geophys. Res., 117, C10023, doi:10.1029/2012JC008076.
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Estimation of the diffuse attenuation coefficient Kd(lambda) with a neural network,  Proceedings of IGARSS '11
+ Jamet, C., H., Loisel and D., Dessailly, 2010. Empirical nonlinear determination of the diffuse attenuation coefficient Kd(490) in coastal waters from ocean color image,  Proceedings of SPIE-Asia-Pacific Remote Sensing, DOI: 10.1117/12.869730
+
+ C coding version :
+ 2012-03-15 D. Dessailly david.dessailly@univ-littoral.fr
+
+ Laboratoire d'Oceanoligie et Geoscience (LOG)
+*/
+
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron1cc.h"
+
+/* -------------------------------------------------------------------------------
+  Lecture des differentes Look Up Tables  -  LUTs reading
+   - Files names and path define in neuron1cc.h
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b2);
+  for(j=0; j<NE; j++){
+   for(i=0; i<NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<NC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w2[j]);
+  fclose(fic);
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  for(i=0; i<NES; i++)
+    fscanf(fic,"%f",&moy[i]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  for(i=0; i<NES; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids  -  Kd computing from NN weights
+ - Input:
+  input[NE] = Rrs[412 443 490 510 555 670], WaveLenght (for desired output Kd)
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant(float input[NE])
+{
+  float a[NC1], y=0.0, x[NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<NE; i++){
+    x[i] = ((2./3.)*(input[i]-moy[i]))/ecart[i];
+  }
+
+  for(i=0;i<NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<NE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+
+  for(j=0;j<NC1;j++){
+    y += (a[j] * w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b2)*ecart[NES-1] + moy[NES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}

+ 119 - 0
neuron_kd_2cc.c

@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron2cc.h"
+
+/* -------------------------------------------------------------------------------
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTs()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  if( (fic=fopen(LUT_POIDS,"r")) == NULL) {perror(LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b1[i]);
+  for(i=0; i<NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&b2[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&b3);
+  for(j=0; j<NE; j++){
+   for(i=0; i<NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&w1[j][i]);
+  }
+  for(j=0; j<NC1; j++){
+    for(i=0; i<NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&w2[j][i]);
+  }
+  for(i=0; i<NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&w3[i]);
+  fclose(fic);
+
+  if( (fic=fopen(LUT_MOY,"r")) == NULL) {perror(LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<NES; i++)
+    fscanf(fic,"%f",&moy[i]);
+  fclose(fic);
+  if( (fic=fopen(LUT_ECART,"r")) == NULL) {perror(LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<NES; i++)
+    fscanf(fic,"%f",&ecart[i]);
+  fclose(fic);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs (412) 443 490 510 555 670 ASOL
+ ------------------------------------------------------------------------------- */
+float neuron_passe_avant(float input[NE+1])
+{
+  float a[NC1], b[NC2], y=0.0, x[NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=1; i<=NE; i++){
+    x[i-1] = ((2./3.)*(input[i]-moy[i-1]))/ecart[i-1];
+  }
+
+  for(i=0;i<NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<NE;j++){
+      a[i] += (x[j]*w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + b1[i]));
+  }
+  for(i=0;i<NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<NC1;j++){
+      b[i] += (a[j]*w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + b2[i]));
+  }
+  for(j=0;j<NC2;j++){
+    y += (b[j]*w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + b3)*ecart[NES-1] + moy[NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*
+int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[NE],result_in,result_out,res_norm, sum_rms=0., sum_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("LUTS/base_Kd490_IOCCG_NOMAD_all_log_Kd_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    res_norm = ((2./3.)*(result_in-moy[NES-1]))/ecart[NES-1];
+    result_out = passe_avant(data_in);
+    result_in = 1.5*res_norm*ecart[NES-1] + moy[NES-1];
+    result_out = (float)pow(10.,result_out);
+    result_in = (float)pow(10.,result_in);
+
+    sum_rms += (float)pow((double)(result_in-result_out),2.);
+    sum_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f\n",result_in,result_out);
+    nb++;
+  }
+  printf("rmse = %f, rel err= %f   nb = %d\n",(float)sqrt((double)sum_rms/nb),sum_rel/nb,nb);
+  fclose(fic);
+  exit(1);
+}*/

+ 205 - 0
neuron_kd_switch.c

@@ -0,0 +1,205 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_switch.h"
+
+/* -------------------------------------------------------------------------------
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTswitch()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  /* ----- LUTs for Rrs490/Rrs555 > 1.5 ------ */
+  if( (fic=fopen(rsup_LUT_POIDS,"r")) == NULL) {perror(rsup_LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<rsup_NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsup_b1[i]);
+  for(i=0; i<rsup_NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsup_b2[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&rsup_b3);
+  for(j=0; j<rsup_NE; j++){
+   for(i=0; i<rsup_NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&rsup_w1[j][i]);
+  }
+  for(j=0; j<rsup_NC1; j++){
+    for(i=0; i<rsup_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsup_w2[j][i]);
+  }
+  for(i=0; i<rsup_NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsup_w3[i]);
+  fclose(fic);
+
+  if( (fic=fopen(rsup_LUT_MOY,"r")) == NULL) {perror(rsup_LUT_MOY); exit(-1);}
+  for(i=0; i<rsup_NE-1; i++)
+    fscanf(fic,"%f",&rsup_moy[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup_moy[rsup_NES-2]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup_moy[rsup_NES-1]);
+  fclose(fic);
+  if( (fic=fopen(rsup_LUT_ECART,"r")) == NULL) {perror(rsup_LUT_ECART); exit(-1);}
+  for(i=0; i<rsup_NE-1; i++)
+    fscanf(fic,"%f",&rsup_ecart[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup_ecart[rsup_NES-2]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup_ecart[rsup_NES-1]);
+  fclose(fic);
+
+
+/* ----- LUTs for Rrs490/Rrs555 <= 1.5 ------ */
+  if( (fic=fopen(rinf_LUT_POIDS,"r")) == NULL) {perror(rinf_LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<rinf_NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinf_b1[i]);
+  for(i=0; i<rinf_NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinf_b2[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&rinf_b3);
+  for(j=0; j<rinf_NE; j++){
+   for(i=0; i<rinf_NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&rinf_w1[j][i]);
+  }
+  for(j=0; j<rinf_NC1; j++){
+    for(i=0; i<rinf_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinf_w2[j][i]);
+  }
+  for(i=0; i<rinf_NC2; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinf_w3[i]);
+  fclose(fic);
+
+  if( (fic=fopen(rinf_LUT_MOY,"r")) == NULL) {perror(rinf_LUT_MOY); exit(-1);}
+  for(i=0; i<rinf_NES-1; i++)
+    fscanf(fic,"%f",&rinf_moy[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rinf_moy[rinf_NES-1]);
+  fclose(fic);
+  if( (fic=fopen(rinf_LUT_ECART,"r")) == NULL) {perror(rinf_LUT_ECART); exit(-1);}
+  for(i=0; i<rinf_NES-1; i++)
+    fscanf(fic,"%f",&rinf_ecart[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rinf_ecart[rinf_NES-1]);
+  fclose(fic);
+
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 412 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsup_neuron_passe_avant(float input[rsup_NE+1])
+{
+  float a[rsup_NC1], b[rsup_NC2], y=0.0, x[rsup_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsup_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsup_moy[i]))/rsup_ecart[i];
+  }
+
+  for(i=0;i<rsup_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsup_NE;j++){
+      a[i] += (x[j]*rsup_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsup_b1[i]));
+  }
+  for(i=0;i<rsup_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsup_NC1;j++){
+      b[i] += (a[j]*rsup_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsup_b2[i]));
+  }
+  for(j=0;j<rsup_NC2;j++){
+    y += (b[j]*rsup_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsup_b3)*rsup_ecart[rsup_NES-1] + rsup_moy[rsup_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 412 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinf_neuron_passe_avant(float input[rinf_NE])
+{
+  float a[rinf_NC1], b[rinf_NC2], y=0.0, x[rinf_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinf_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinf_moy[i]))/rinf_ecart[i];
+  }
+
+  for(i=0;i<rinf_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinf_NE;j++){
+      a[i] += (x[j]*rinf_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinf_b1[i]));
+  }
+  for(i=0;i<rinf_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinf_NC1;j++){
+      b[i] += (a[j]*rinf_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinf_b2[i]));
+  }
+  for(j=0;j<rinf_NC2;j++){
+    y += (b[j]*rinf_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinf_b3)*rinf_ecart[rinf_NES-1] + rinf_moy[rinf_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[rinf_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<rinf_NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    result_out = rinf_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f",result_in,result_out);
+
+    data_in[5] = data_in[6];
+    result_out = rsup_neuron_passe_avant(data_in);
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf(" %f\n",result_out);
+    nb++;
+  }
+  printf("rmseInf = %f, rel errInf= %f,  rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, (float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+
+
+
+  fclose(fic);
+  exit(1);
+}*/
+

+ 640 - 0
neuron_kd_switch160715.c

@@ -0,0 +1,640 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_switch160715.h"
+#include "iop_Rrs_neuron.h"
+
+/* ------------------------------------------------------------------------------- 
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTswitch(int idSensor, char *lutpath)
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150), nomfic[1000];
+  float fpoub;
+
+  if( (poub = strcmp(lutpath, "None")) == 0){
+    if( (lutpath = getenv("IOP_LUTS_PATH")) == NULL) {perror("IOP_LUTS_PATH"); exit(-1);}
+  }
+  /* ===================================== SeaWiFS ===================================== */
+  if( idSensor == idSEAWIFS ){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b1[i]);
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b3);
+    for(j=0; j<rsupSW_NE; j++){
+      for(i=0; i<rsupSW_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w1[j][i]);
+    }
+    for(j=0; j<rsupSW_NC1; j++){
+      for(i=0; i<rsupSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w2[j][i]);
+    }
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b1[i]);
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b3);
+    for(j=0; j<rinfSW_NE; j++){
+      for(i=0; i<rinfSW_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w1[j][i]);
+    }
+    for(j=0; j<rinfSW_NC1; j++){
+      for(i=0; i<rinfSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w2[j][i]);
+    }
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_moy[rinfSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_ecart[rinfSW_NES-1]);
+    fclose(fic);
+  }
+  
+  /* =====================================  MODIS  ===================================== */
+  if( idSensor == idMODIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b1[i]);
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b3);
+    for(j=0; j<rsupMO_NE; j++){
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w1[j][i]);
+    }
+    for(j=0; j<rsupMO_NC1; j++){
+      for(i=0; i<rsupMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w2[j][i]);
+    }
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rsupMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b1[i]);
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b3);
+    for(j=0; j<rinfMO_NE; j++){
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w1[j][i]);
+    }
+    for(j=0; j<rinfMO_NC1; j++){
+      for(i=0; i<rinfMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w2[j][i]);
+    }
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rinfMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_moy[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_ecart[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NES-1]);
+    fclose(fic);
+  }    
+  
+  /* =====================================  MERIS / OLCI  ===================================== */
+  if( idSensor == idMERIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupOL_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b1[i]);
+    for(i=0; i<rsupOL_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_b3);
+    for(j=0; j<rsupOL_NE; j++){
+      for(i=0; i<rsupOL_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w1[j][i]);
+    }
+    for(j=0; j<rsupOL_NC1; j++){
+      for(i=0; i<rsupOL_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w2[j][i]);
+    }
+    for(i=0; i<rsupOL_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupOL_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rsupOL_moy[0]); /*443*/
+    fscanf(fic,"%f",&rsupOL_moy[1]); /*490*/
+    fscanf(fic,"%f",&rsupOL_moy[2]); /*510*/
+    fscanf(fic,"%f",&rsupOL_moy[3]); /*560*/
+    fscanf(fic,"%f",&fpoub); /*665*/
+    fscanf(fic,"%f",&rsupOL_moy[rsupOL_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupOL_moy[rsupOL_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupOL_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupOL_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rsupOL_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rsupOL_ecart[2]); /*510*/
+    fscanf(fic,"%f",&rsupOL_ecart[3]); /*560*/
+    fscanf(fic,"%f",&fpoub); /*665*/
+    fscanf(fic,"%f",&rsupOL_ecart[rsupOL_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupOL_ecart[rsupOL_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfOL_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b1[i]);
+    for(i=0; i<rinfOL_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_b3);
+    for(j=0; j<rinfOL_NE; j++){
+      for(i=0; i<rinfOL_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w1[j][i]);
+    }
+    for(j=0; j<rinfOL_NC1; j++){
+      for(i=0; i<rinfOL_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w2[j][i]);
+    }
+    for(i=0; i<rinfOL_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfOL_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rinfOL_moy[0]); /*443*/
+    fscanf(fic,"%f",&rinfOL_moy[1]); /*490*/
+    fscanf(fic,"%f",&rinfOL_moy[2]); /*510*/
+    fscanf(fic,"%f",&rinfOL_moy[3]); /*560*/
+    fscanf(fic,"%f",&rinfOL_moy[4]); /*665*/
+    fscanf(fic,"%f",&rinfOL_moy[rinfOL_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfOL_moy[rinfOL_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfOL_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub); /*412*/
+    fscanf(fic,"%f",&rinfOL_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rinfOL_ecart[1]); /*490*/
+    fscanf(fic,"%f",&rinfOL_ecart[2]); /*510*/
+    fscanf(fic,"%f",&rinfOL_ecart[3]); /*560*/
+    fscanf(fic,"%f",&rinfOL_ecart[4]); /*665*/
+    fscanf(fic,"%f",&rinfOL_ecart[rinfOL_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfOL_ecart[rinfOL_NES-1]);
+    fclose(fic);
+  }    
+}
+
+/* ===============================================  SEAWIFS  =============================================== */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupSW_neuron_passe_avant(float input[rsupSW_NE+1])
+{
+  float a[rsupSW_NC1], b[rsupSW_NC2], y=0.0, x[rsupSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupSW_moy[i]))/rsupSW_ecart[i];
+  }
+
+  for(i=0;i<rsupSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupSW_NE;j++){
+      a[i] += (x[j]*rsupSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupSW_b1[i]));
+  }
+  for(i=0;i<rsupSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupSW_NC1;j++){
+      b[i] += (a[j]*rsupSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupSW_b2[i]));
+  }
+  for(j=0;j<rsupSW_NC2;j++){
+    y += (b[j]*rsupSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupSW_b3)*rsupSW_ecart[rsupSW_NES-1] + rsupSW_moy[rsupSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfSW_neuron_passe_avant(float input[rinfSW_NE])
+{
+  float a[rinfSW_NC1], b[rinfSW_NC2], y=0.0, x[rinfSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfSW_moy[i]))/rinfSW_ecart[i];
+  }
+
+  for(i=0;i<rinfSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfSW_NE;j++){
+      a[i] += (x[j]*rinfSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfSW_b1[i]));
+  }
+  for(i=0;i<rinfSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfSW_NC1;j++){
+      b[i] += (a[j]*rinfSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfSW_b2[i]));
+  }
+  for(j=0;j<rinfSW_NC2;j++){
+    y += (b[j]*rinfSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfSW_b3)*rinfSW_ecart[rinfSW_NES-1] + rinfSW_moy[rinfSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/* ===============================================  MODIS  ================================================ */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupMO_neuron_passe_avant(float input[rsupMO_NE+1])
+{
+  float a[rsupMO_NC1], b[rsupMO_NC2], y=0.0, x[rsupMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupMO_moy[i]))/rsupMO_ecart[i];
+  }
+
+  for(i=0;i<rsupMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupMO_NE;j++){
+      a[i] += (x[j]*rsupMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupMO_b1[i]));
+  }
+  for(i=0;i<rsupMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupMO_NC1;j++){
+      b[i] += (a[j]*rsupMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupMO_b2[i]));
+  }
+  for(j=0;j<rsupMO_NC2;j++){
+    y += (b[j]*rsupMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupMO_b3)*rsupMO_ecart[rsupMO_NES-1] + rsupMO_moy[rsupMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfMO_neuron_passe_avant(float input[rinfMO_NE])
+{
+  float a[rinfMO_NC1], b[rinfMO_NC2], y=0.0, x[rinfMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfMO_moy[i]))/rinfMO_ecart[i];
+  }
+
+  for(i=0;i<rinfMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfMO_NE;j++){
+      a[i] += (x[j]*rinfMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfMO_b1[i]));
+  }
+  for(i=0;i<rinfMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfMO_NC1;j++){
+      b[i] += (a[j]*rinfMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfMO_b2[i]));
+  }
+  for(j=0;j<rinfMO_NC2;j++){
+    y += (b[j]*rinfMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfMO_b3)*rinfMO_ecart[rinfMO_NES-1] + rinfMO_moy[rinfMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/* ===============================================  MERIS /OLCI  ================================================ */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 560 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupOL_neuron_passe_avant(float input[rsupOL_NE+1])
+{
+  float a[rsupOL_NC1], b[rsupOL_NC2], y=0.0, x[rsupOL_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupOL_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupOL_moy[i]))/rsupOL_ecart[i];
+  }
+
+  for(i=0;i<rsupOL_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupOL_NE;j++){
+      a[i] += (x[j]*rsupOL_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupOL_b1[i]));
+  }
+  for(i=0;i<rsupOL_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupOL_NC1;j++){
+      b[i] += (a[j]*rsupOL_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupOL_b2[i]));
+  }
+  for(j=0;j<rsupOL_NC2;j++){
+    y += (b[j]*rsupOL_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupOL_b3)*rsupOL_ecart[rsupOL_NES-1] + rsupOL_moy[rsupOL_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 560 665 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfOL_neuron_passe_avant(float input[rinfOL_NE])
+{
+  float a[rinfOL_NC1], b[rinfOL_NC2], y=0.0, x[rinfOL_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfOL_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfOL_moy[i]))/rinfOL_ecart[i];
+  }
+
+  for(i=0;i<rinfOL_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfOL_NE;j++){
+      a[i] += (x[j]*rinfOL_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfOL_b1[i]));
+  }
+  for(i=0;i<rinfOL_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfOL_NC1;j++){
+      b[i] += (a[j]*rinfOL_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfOL_b2[i]));
+  }
+  for(j=0;j<rinfOL_NC2;j++){
+    y += (b[j]*rinfOL_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfOL_b3)*rinfOL_ecart[rinfOL_NES-1] + rinfOL_moy[rinfOL_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*
+int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[rinfSW_NE],result_in,result_out, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0., fpoub;
+  int i,nbinf, nbsup, nb,lu;
+
+//   if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_sup_180515_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+
+  neuron_lect_LUTswitch(0, "None");
+
+  nb = nbsup = nbinf = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    result_in = (float)pow(10.,result_in);
+    printf("%f ",result_in);
+    if(data_in[1]/data_in[3] < .85){
+      result_out = rinfSW_neuron_passe_avant(data_in);
+      sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+      sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+      nbinf++;
+    }
+    else {
+      data_in[5] = data_in[6];
+      result_out = rsupSW_neuron_passe_avant(data_in);
+      sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+      sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+      nbsup++;
+    }
+    printf(" %f\n",result_out);
+    nb++;
+  }
+  printf("rmseInf = %f, rel errInf= %f,  rmseSup = %f, rel errSup= %f    nbinf = %d nbsup = %d\n",(float)sqrt((double)sumInf_rms/nbinf),sumInf_rel/nbinf, (float)sqrt((double)sumSup_rms/nbsup),sumSup_rel/nbsup, nbinf, nbsup);
+
+
+  fclose(fic);
+  exit(1);
+}
+*/
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float fpoub, data_in[rinfSW_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  printf(" -- SUP --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_sup_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTswitch(idMODIS);
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rsupMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[4] == 488 ){
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+  fclose(fic);
+  
+  printf(" -- INF --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_inf_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&data_in[5]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rinfMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[5] == 488 ){
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseInf = %f, rel errInf= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, nb);
+  
+  
+  exit(1);
+}*/
+

+ 465 - 0
neuron_kd_switch180515.c

@@ -0,0 +1,465 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_switch180515.h"
+#include "iop_Rrs_neuron.h"
+
+/* ------------------------------------------------------------------------------- 
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTswitch(int idSensor, char *lutpath)
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150), nomfic[1000];
+  float fpoub;
+
+  if( (poub = strcmp(lutpath, "None")) == 0){
+    if( (lutpath = getenv("IOP_LUTS_PATH")) == NULL) {perror("IOP_LUTS_PATH"); exit(-1);}
+  }
+  /* ===================================== SeaWiFS ===================================== */
+  if( idSensor == idSEAWIFS || idSensor == idMERIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b1[i]);
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b3);
+    for(j=0; j<rsupSW_NE; j++){
+      for(i=0; i<rsupSW_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w1[j][i]);
+    }
+    for(j=0; j<rsupSW_NC1; j++){
+      for(i=0; i<rsupSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w2[j][i]);
+    }
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b1[i]);
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b3);
+    for(j=0; j<rinfSW_NE; j++){
+      for(i=0; i<rinfSW_NC1; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w1[j][i]);
+    }
+    for(j=0; j<rinfSW_NC1; j++){
+      for(i=0; i<rinfSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w2[j][i]);
+    }
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_moy[rinfSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_ecart[rinfSW_NES-1]);
+    fclose(fic);
+  }
+  
+  /* =====================================  MODIS  ===================================== */
+  if( idSensor == idMODIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b1[i]);
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b3);
+    for(j=0; j<rsupMO_NE; j++){
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w1[j][i]);
+    }
+    for(j=0; j<rsupMO_NC1; j++){
+      for(i=0; i<rsupMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w2[j][i]);
+    }
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rsupMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b1[i]);
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b3);
+    for(j=0; j<rinfMO_NE; j++){
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w1[j][i]);
+    }
+    for(j=0; j<rinfMO_NC1; j++){
+      for(i=0; i<rinfMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w2[j][i]);
+    }
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rinfMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_moy[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_ecart[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NES-1]);
+    fclose(fic);
+  }    
+}
+
+/* ===============================================  SEAWIFS  =============================================== */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupSW_neuron_passe_avant(float input[rsupSW_NE+1])
+{
+  float a[rsupSW_NC1], b[rsupSW_NC2], y=0.0, x[rsupSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupSW_moy[i]))/rsupSW_ecart[i];
+  }
+
+  for(i=0;i<rsupSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupSW_NE;j++){
+      a[i] += (x[j]*rsupSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupSW_b1[i]));
+  }
+  for(i=0;i<rsupSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupSW_NC1;j++){
+      b[i] += (a[j]*rsupSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupSW_b2[i]));
+  }
+  for(j=0;j<rsupSW_NC2;j++){
+    y += (b[j]*rsupSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupSW_b3)*rsupSW_ecart[rsupSW_NES-1] + rsupSW_moy[rsupSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfSW_neuron_passe_avant(float input[rinfSW_NE])
+{
+  float a[rinfSW_NC1], b[rinfSW_NC2], y=0.0, x[rinfSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfSW_moy[i]))/rinfSW_ecart[i];
+  }
+
+  for(i=0;i<rinfSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfSW_NE;j++){
+      a[i] += (x[j]*rinfSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfSW_b1[i]));
+  }
+  for(i=0;i<rinfSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfSW_NC1;j++){
+      b[i] += (a[j]*rinfSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfSW_b2[i]));
+  }
+  for(j=0;j<rinfSW_NC2;j++){
+    y += (b[j]*rinfSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfSW_b3)*rinfSW_ecart[rinfSW_NES-1] + rinfSW_moy[rinfSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/* ===============================================  MODIS  ================================================ */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupMO_neuron_passe_avant(float input[rsupMO_NE+1])
+{
+  float a[rsupMO_NC1], b[rsupMO_NC2], y=0.0, x[rsupMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupMO_moy[i]))/rsupMO_ecart[i];
+  }
+
+  for(i=0;i<rsupMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupMO_NE;j++){
+      a[i] += (x[j]*rsupMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupMO_b1[i]));
+  }
+  for(i=0;i<rsupMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupMO_NC1;j++){
+      b[i] += (a[j]*rsupMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupMO_b2[i]));
+  }
+  for(j=0;j<rsupMO_NC2;j++){
+    y += (b[j]*rsupMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupMO_b3)*rsupMO_ecart[rsupMO_NES-1] + rsupMO_moy[rsupMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfMO_neuron_passe_avant(float input[rinfMO_NE])
+{
+  float a[rinfMO_NC1], b[rinfMO_NC2], y=0.0, x[rinfMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfMO_moy[i]))/rinfMO_ecart[i];
+  }
+
+  for(i=0;i<rinfMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfMO_NE;j++){
+      a[i] += (x[j]*rinfMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfMO_b1[i]));
+  }
+  for(i=0;i<rinfMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfMO_NC1;j++){
+      b[i] += (a[j]*rinfMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfMO_b2[i]));
+  }
+  for(j=0;j<rinfMO_NC2;j++){
+    y += (b[j]*rinfMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfMO_b3)*rinfMO_ecart[rinfMO_NES-1] + rinfMO_moy[rinfMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*
+int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[rinfSW_NE],result_in,result_out, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0., fpoub;
+  int i,nbinf, nbsup, nb,lu;
+
+//   if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_sup_180515_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+
+  neuron_lect_LUTswitch(0, "None");
+
+  nb = nbsup = nbinf = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    result_in = (float)pow(10.,result_in);
+    printf("%f ",result_in);
+    if(data_in[1]/data_in[3] < .85){
+      result_out = rinfSW_neuron_passe_avant(data_in);
+      sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+      sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+      nbinf++;
+    }
+    else {
+      data_in[5] = data_in[6];
+      result_out = rsupSW_neuron_passe_avant(data_in);
+      sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+      sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+      nbsup++;
+    }
+    printf(" %f\n",result_out);
+    nb++;
+  }
+  printf("rmseInf = %f, rel errInf= %f,  rmseSup = %f, rel errSup= %f    nbinf = %d nbsup = %d\n",(float)sqrt((double)sumInf_rms/nbinf),sumInf_rel/nbinf, (float)sqrt((double)sumSup_rms/nbsup),sumSup_rel/nbsup, nbinf, nbsup);
+
+
+  fclose(fic);
+  exit(1);
+}
+*/
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float fpoub, data_in[rinfSW_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  printf(" -- SUP --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_sup_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTswitch(idMODIS);
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rsupMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[4] == 488 ){
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+  fclose(fic);
+  
+  printf(" -- INF --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_inf_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&data_in[5]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rinfMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[5] == 488 ){
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseInf = %f, rel errInf= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, nb);
+  
+  
+  exit(1);
+}*/
+

+ 185 - 0
neuron_kd_switch2.c

@@ -0,0 +1,185 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_switch2.h"
+
+/* -------------------------------------------------------------------------------
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTswitch2()
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150);
+  float fpoub;
+
+  /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+  if( (fic=fopen(rsup2_LUT_POIDS,"r")) == NULL) {perror(rsup2_LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<rsup2_NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsup2_b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&rsup2_b2);
+  for(j=0; j<rsup2_NE; j++){
+   for(i=0; i<rsup2_NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&rsup2_w1[j][i]);
+  }
+  for(j=0; j<rsup2_NC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsup2_w2[j]);
+  fclose(fic);
+
+  if( (fic=fopen(rsup2_LUT_MOY,"r")) == NULL) {perror(rsup2_LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<rsup2_NE-1; i++)
+    fscanf(fic,"%f",&rsup2_moy[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup2_moy[rsup2_NE-1]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup2_moy[rsup2_NES-1]);
+  fclose(fic);
+  if( (fic=fopen(rsup2_LUT_ECART,"r")) == NULL) {perror(rsup2_LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<rsup2_NE-1; i++)
+    fscanf(fic,"%f",&rsup2_ecart[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup2_ecart[rsup2_NE-1]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rsup2_ecart[rsup2_NES-1]);
+  fclose(fic);
+
+
+/* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+  if( (fic=fopen(rinf2_LUT_POIDS,"r")) == NULL) {perror(rinf2_LUT_POIDS); exit(-1);}
+  fgets(ligne,150,fic);
+  for(i=0; i<rinf2_NC1; i++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinf2_b1[i]);
+  fscanf(fic,"%d %d %f",&poub,&poub,&rinf2_b2);
+  for(j=0; j<rinf2_NE; j++){
+   for(i=0; i<rinf2_NC1; i++)
+     fscanf(fic,"%d %d %f",&poub,&poub,&rinf2_w1[j][i]);
+  }
+  for(j=0; j<rinf2_NC1; j++)
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinf2_w2[j]);
+  fclose(fic);
+
+  if( (fic=fopen(rinf2_LUT_MOY,"r")) == NULL) {perror(rinf2_LUT_MOY); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<rinf2_NE; i++)
+    fscanf(fic,"%f",&rinf2_moy[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rinf2_moy[rinf2_NES-1]);
+  fclose(fic);
+  if( (fic=fopen(rinf2_LUT_ECART,"r")) == NULL) {perror(rinf2_LUT_ECART); exit(-1);}
+  fscanf(fic,"%f",&fpoub);
+  for(i=0; i<rinf2_NE; i++)
+    fscanf(fic,"%f",&rinf2_ecart[i]);
+  fscanf(fic,"%f",&fpoub);
+  fscanf(fic,"%f",&rinf2_ecart[rinf2_NES-1]);
+  fclose(fic);
+
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsup2_neuron_passe_avant(float input[rsup2_NE])
+{
+  float a[rsup2_NC1], y=0.0, x[rsup2_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsup2_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsup2_moy[i]))/rsup2_ecart[i];
+  }
+
+  for(i=0;i<rsup2_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsup2_NE;j++){
+      a[i] += (x[j]*rsup2_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsup2_b1[i]));
+  }
+
+  for(j=0;j<rsup2_NC1;j++){
+    y += (a[j]*rsup2_w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsup2_b2)*rsup2_ecart[rsup2_NES-1] + rsup2_moy[rsup2_NES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinf2_neuron_passe_avant(float input[rinf2_NE])
+{
+  float a[rinf2_NC1], y=0.0, x[rinf2_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinf2_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinf2_moy[i]))/rinf2_ecart[i];
+  }
+
+  for(i=0;i<rinf2_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinf2_NE;j++){
+      a[i] += (x[j]*rinf2_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinf2_b1[i]));
+  }
+
+  for(j=0;j<rinf2_NC1;j++){
+    y += (a[j]*rinf2_w2[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinf2_b2)*rinf2_ecart[rinf2_NES-1] + rinf2_moy[rinf2_NES-1];
+  y = (float)pow(10.,(double)y);
+  return(y);
+}
+
+
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[rinf2_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<rinf2_NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    result_out = rinf2_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f",result_in,result_out);
+
+    data_in[5] = data_in[6];
+    result_out = rsup2_neuron_passe_avant(data_in);
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf(" %f\n",result_out);
+    nb++;
+  }
+  printf("rmseInf = %f, rel errInf= %f,  rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, (float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+
+
+
+  fclose(fic);
+  exit(1);
+}*/
+

+ 457 - 0
neuron_kd_switch3.c

@@ -0,0 +1,457 @@
+#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <memory.h>
+#include "neuron_switch3.h"
+#include "iop_Rrs_neuron.h"
+
+/* ------------------------------------------------------------------------------- 
+ Lecture des differrentes Look Up Tables
+ -------------------------------------------------------------------------------  */
+void neuron_lect_LUTswitch(int idSensor, char *lutpath)
+{
+  FILE *fic;
+  int i,j,poub;
+  char *ligne=malloc(sizeof(char)*150), nomfic[1000];
+  float fpoub;
+
+  if( (poub = strcmp(lutpath, "None")) == 0){
+    if( (lutpath = getenv("IOP_LUTS_PATH")) == NULL) {perror("IOP_LUTS_PATH"); exit(-1);}
+  }
+  /* ===================================== SeaWiFS ===================================== */
+  if( idSensor == idSEAWIFS || idSensor == idMERIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b1[i]);
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_b3);
+    for(j=0; j<rsupSW_NE; j++){
+    for(i=0; i<rsupSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w1[j][i]);
+    }
+    for(j=0; j<rsupSW_NC1; j++){
+      for(i=0; i<rsupSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w2[j][i]);
+    }
+    for(i=0; i<rsupSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_moy[rsupSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rsupSW_NE-1; i++)
+      fscanf(fic,"%f",&rsupSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupSW_ecart[rsupSW_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b1[i]);
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_b3);
+    for(j=0; j<rinfSW_NE; j++){
+    for(i=0; i<rinfSW_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w1[j][i]);
+    }
+    for(j=0; j<rinfSW_NC1; j++){
+      for(i=0; i<rinfSW_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w2[j][i]);
+    }
+    for(i=0; i<rinfSW_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfSW_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_moy[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_moy[rinfSW_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfSW_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    for(i=0; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&rinfSW_ecart[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfSW_ecart[rinfSW_NES-1]);
+    fclose(fic);
+  }
+  
+  /* =====================================  MODIS  ===================================== */
+  if( idSensor == idMODIS){
+    /* ----- LUTs for Rrs490/Rrs555 >= .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b1[i]);
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_b3);
+    for(j=0; j<rsupMO_NE; j++){
+    for(i=0; i<rsupMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w1[j][i]);
+    }
+    for(j=0; j<rsupMO_NC1; j++){
+      for(i=0; i<rsupMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w2[j][i]);
+    }
+    for(i=0; i<rsupMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rsupMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rsupMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_moy[rsupMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rsupMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rsupMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rsupMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rsupMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&fpoub); /*667*/
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rsupMO_ecart[rsupMO_NES-1]);
+    fclose(fic);
+
+  /* ----- LUTs for Rrs490/Rrs555 < .85 ------ */
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_POIDS);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fgets(ligne,150,fic);
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b1[i]);
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b2[i]);
+    fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_b3);
+    for(j=0; j<rinfMO_NE; j++){
+    for(i=0; i<rinfMO_NC1; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w1[j][i]);
+    }
+    for(j=0; j<rinfMO_NC1; j++){
+      for(i=0; i<rinfMO_NC2; i++)
+        fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w2[j][i]);
+    }
+    for(i=0; i<rinfMO_NC2; i++)
+      fscanf(fic,"%d %d %f",&poub,&poub,&rinfMO_w3[i]);
+    fclose(fic);
+
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_MOY);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);/*412*/
+    fscanf(fic,"%f",&rinfMO_moy[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_moy[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_moy[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_moy[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_moy[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_moy[rinfMO_NES-1]);
+    fclose(fic);
+    sprintf(nomfic,"%s/%s", lutpath, rinfMO_LUT_ECART);
+    if( (fic=fopen(nomfic,"r")) == NULL) {perror(nomfic); exit(-1);}
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[0]); /*443*/
+    fscanf(fic,"%f",&rinfMO_ecart[1]); /*488*/
+    fscanf(fic,"%f",&rinfMO_ecart[2]); /*531*/
+    fscanf(fic,"%f",&rinfMO_ecart[3]); /*547*/
+    fscanf(fic,"%f",&fpoub); /*620*/
+    fscanf(fic,"%f",&rinfMO_ecart[4]); /*667*/
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NE-1]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&rinfMO_ecart[rinfMO_NES-1]);
+    fclose(fic);
+  }    
+}
+
+/* ===============================================  SEAWIFS  =============================================== */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupSW_neuron_passe_avant(float input[rsupSW_NE+1])
+{
+  float a[rsupSW_NC1], b[rsupSW_NC2], y=0.0, x[rsupSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupSW_moy[i]))/rsupSW_ecart[i];
+  }
+
+  for(i=0;i<rsupSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupSW_NE;j++){
+      a[i] += (x[j]*rsupSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupSW_b1[i]));
+  }
+  for(i=0;i<rsupSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupSW_NC1;j++){
+      b[i] += (a[j]*rsupSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupSW_b2[i]));
+  }
+  for(j=0;j<rsupSW_NC2;j++){
+    y += (b[j]*rsupSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupSW_b3)*rsupSW_ecart[rsupSW_NES-1] + rsupSW_moy[rsupSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfSW_neuron_passe_avant(float input[rinfSW_NE])
+{
+  float a[rinfSW_NC1], b[rinfSW_NC2], y=0.0, x[rinfSW_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfSW_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfSW_moy[i]))/rinfSW_ecart[i];
+  }
+
+  for(i=0;i<rinfSW_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfSW_NE;j++){
+      a[i] += (x[j]*rinfSW_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfSW_b1[i]));
+  }
+  for(i=0;i<rinfSW_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfSW_NC1;j++){
+      b[i] += (a[j]*rinfSW_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfSW_b2[i]));
+  }
+  for(j=0;j<rinfSW_NC2;j++){
+    y += (b[j]*rinfSW_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfSW_b3)*rinfSW_ecart[rinfSW_NES-1] + rinfSW_moy[rinfSW_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/* ===============================================  MODIS  ================================================ */
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 Lambda
+ ------------------------------------------------------------------------------- */
+float rsupMO_neuron_passe_avant(float input[rsupMO_NE+1])
+{
+  float a[rsupMO_NC1], b[rsupMO_NC2], y=0.0, x[rsupMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rsupMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rsupMO_moy[i]))/rsupMO_ecart[i];
+  }
+
+  for(i=0;i<rsupMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rsupMO_NE;j++){
+      a[i] += (x[j]*rsupMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rsupMO_b1[i]));
+  }
+  for(i=0;i<rsupMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rsupMO_NC1;j++){
+      b[i] += (a[j]*rsupMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rsupMO_b2[i]));
+  }
+  for(j=0;j<rsupMO_NC2;j++){
+    y += (b[j]*rsupMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rsupMO_b3)*rsupMO_ecart[rsupMO_NES-1] + rsupMO_moy[rsupMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+/* -------------------------------------------------------------------------------
+ Calcul du Kd a partir des poids
+ - Input:
+  input[NE] = Rrs 443 490 510 555 670 Lambda
+ ------------------------------------------------------------------------------- */
+float rinfMO_neuron_passe_avant(float input[rinfMO_NE])
+{
+  float a[rinfMO_NC1], b[rinfMO_NC2], y=0.0, x[rinfMO_NE];
+  int i,j;
+
+  /* Normalisation */
+  for(i=0; i<rinfMO_NE; i++){
+    x[i] = ((2./3.)*(input[i]-rinfMO_moy[i]))/rinfMO_ecart[i];
+  }
+
+  for(i=0;i<rinfMO_NC1;i++){
+    a[i] = 0.0;
+    for(j=0;j<rinfMO_NE;j++){
+      a[i] += (x[j]*rinfMO_w1[j][i]);
+    }
+    a[i] = 1.715905*(float)tanh((2./3.)*(double)(a[i] + rinfMO_b1[i]));
+  }
+  for(i=0;i<rinfMO_NC2;i++){
+    b[i] = 0.0;
+    for(j=0;j<rinfMO_NC1;j++){
+      b[i] += (a[j]*rinfMO_w2[j][i]);
+    }
+    b[i] = 1.715905*(float)tanh((2./3.)*(double)(b[i] + rinfMO_b2[i]));
+  }
+  for(j=0;j<rinfMO_NC2;j++){
+    y += (b[j]*rinfMO_w3[j]);
+  }
+
+  /* Denormalisation */
+  y = 1.5*(y + rinfMO_b3)*rinfMO_ecart[rinfMO_NES-1] + rinfMO_moy[rinfMO_NES-1];
+  y = (float)pow(10.,y);
+  return(y);
+}
+
+
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float data_in[rinfSW_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  if( (fic=fopen("../LUTS/base_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213_test.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTs();
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&data_in[0])) == 1){
+    for(i=1; i<rinfSW_NE; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&result_in);
+    result_out = rinfSW_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf("%f %f",result_in,result_out);
+
+    data_in[5] = data_in[6];
+    result_out = rsupSW_neuron_passe_avant(data_in);
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    printf(" %f\n",result_out);
+    nb++;
+  }
+  printf("rmseInf = %f, rel errInf= %f,  rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, (float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+
+
+
+  fclose(fic);
+  exit(1);
+}*/
+
+/*int main (int argc, char *argv[])
+{
+  FILE *fic;
+  float fpoub, data_in[rinfSW_NE],result_in,result_out,res_norm, sumInf_rms=0., sumInf_rel=0., sumSup_rms=0., sumSup_rel=0.;
+  int i,nb,lu;
+
+  printf(" -- SUP --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_sup_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  neuron_lect_LUTswitch(idMODIS);
+
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rsupMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[4] == 488 ){
+    sumSup_rms += (float)pow((double)(result_in-result_out),2.);
+    sumSup_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseSup = %f, rel errSup= %f  nb = %d\n",(float)sqrt((double)sumSup_rms/nb),sumSup_rel/nb, nb);
+  fclose(fic);
+  
+  printf(" -- INF --\n");
+  if( (fic=fopen("../LUTS/base_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_test_inf_CSIRO.dat","r")) == NULL) {perror("input"); exit(-1);}
+  nb = 0;
+  while((lu=fscanf(fic,"%f",&fpoub)) == 1){
+    for(i=0; i<4; i++)
+      fscanf(fic,"%f",&data_in[i]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&data_in[4]);
+    fscanf(fic,"%f",&data_in[5]);
+    fscanf(fic,"%f",&fpoub);
+    fscanf(fic,"%f",&result_in);
+    
+    result_out = rinfMO_neuron_passe_avant(data_in);
+    result_in = (float)pow(10.,result_in);
+    if (data_in[5] == 488 ){
+    sumInf_rms += (float)pow((double)(result_in-result_out),2.);
+    sumInf_rel +=  (float)sqrt((double)(((result_in-result_out)/result_in) * ((result_in-result_out)/result_in)));
+    nb++;
+    }
+  }
+  printf("rmseInf = %f, rel errInf= %f  nb = %d\n",(float)sqrt((double)sumInf_rms/nb),sumInf_rel/nb, nb);
+  
+  
+  exit(1);
+}*/
+

+ 50 - 0
neuron_switch.h

@@ -0,0 +1,50 @@
+#include <stdio.h>
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 > 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rsup_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsup_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsup_NC1 6
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsup_NC2 6
+/* nombre de donnees de sortie - nb output*/
+#define rsup_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsup_NES 7
+
+/* LUTs file names */
+#define rsup_LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_3_ascii_6x1_hh_6_6_publi_091213.sn"
+#define rsup_LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_3_publi_091213.dat"
+#define rsup_LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_3_publi_091213.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 <= 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rinf_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinf_NE 7
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinf_NC1 4
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinf_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rinf_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinf_NES 8
+
+/* LUTs file names */
+#define rinf_LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ascii_6x1_hh_4_4_publi_091213.sn"
+#define rinf_LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213.dat"
+#define rinf_LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_publi_091213.dat"
+
+/* LUTs parameters definition */
+float rsup_b1[rsup_NC1], rsup_b2[rsup_NC2], rsup_b3;
+float rsup_w1[rsup_NE][rsup_NC1], rsup_w2[rsup_NC1][rsup_NC2], rsup_w3[rsup_NC2];
+
+float rsup_moy[rsup_NES], rsup_ecart[rsup_NES];
+
+float rinf_b1[rinf_NC1], rinf_b2[rinf_NC2], rinf_b3;
+float rinf_w1[rinf_NE][rinf_NC1], rinf_w2[rinf_NC1][rinf_NC2], rinf_w3[rinf_NC2];
+float rinf_moy[rinf_NES], rinf_ecart[rinf_NES];

+ 156 - 0
neuron_switch160715.h

@@ -0,0 +1,156 @@
+#include <stdio.h>
+
+/* =======================================================================================================
+ *  SeaWiFS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >= .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupSW_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupSW_NC1 4
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupSW_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupSW_NES 6
+
+/* LUTs file names */
+#define rsupSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_4_4_publi_200715.sn"
+#define rsupSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_160715.dat"
+#define rsupSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_160715.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 < .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfSW_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfSW_NC1 5
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfSW_NC2 5
+/* nombre de donnees de sortie - nb output*/
+#define rinfSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfSW_NES 7
+
+/* LUTs file names */
+#define rinfSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_5_publi_160715_ter.sn"
+#define rinfSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_160715.dat"
+#define rinfSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_160715.dat"
+
+/* LUTs parameters definition */
+float rsupSW_b1[rsupSW_NC1], rsupSW_b2[rsupSW_NC2], rsupSW_b3;
+float rsupSW_w1[rsupSW_NE][rsupSW_NC1], rsupSW_w2[rsupSW_NC1][rsupSW_NC2], rsupSW_w3[rsupSW_NC2];
+float rsupSW_moy[rsupSW_NES], rsupSW_ecart[rsupSW_NES];
+
+float rinfSW_b1[rinfSW_NC1], rinfSW_b2[rinfSW_NC2], rinfSW_b3;
+float rinfSW_w1[rinfSW_NE][rinfSW_NC1], rinfSW_w2[rinfSW_NC1][rinfSW_NC2], rinfSW_w3[rinfSW_NC2];
+float rinfSW_moy[rinfSW_NES], rinfSW_ecart[rinfSW_NES];
+
+
+/* =======================================================================================================
+ *  MODIS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >= .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupMO_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupMO_NC1 5
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupMO_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupMO_NES 6
+
+/* LUTs file names */
+#define rsupMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_4_publi_CSIRO.sn"
+#define rsupMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+#define rsupMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 < .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfMO_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfMO_NC1 10
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfMO_NC2 7
+/* nombre de donnees de sortie - nb output*/
+#define rinfMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfMO_NES 7
+
+/* LUTs file names */
+#define rinfMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_7_publi_CSIRO.sn"
+#define rinfMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+#define rinfMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+
+/* LUTs parameters definition */
+float rsupMO_b1[rsupMO_NC1], rsupMO_b2[rsupMO_NC2], rsupMO_b3;
+float rsupMO_w1[rsupMO_NE][rsupMO_NC1], rsupMO_w2[rsupMO_NC1][rsupMO_NC2], rsupMO_w3[rsupMO_NC2];
+float rsupMO_moy[rsupMO_NES], rsupMO_ecart[rsupMO_NES];
+
+float rinfMO_b1[rinfMO_NC1], rinfMO_b2[rinfMO_NC2], rinfMO_b3;
+float rinfMO_w1[rinfMO_NE][rinfMO_NC1], rinfMO_w2[rinfMO_NC1][rinfMO_NC2], rinfMO_w3[rinfMO_NC2];
+float rinfMO_moy[rinfMO_NES], rinfMO_ecart[rinfMO_NES];
+
+
+/* =======================================================================================================
+ *  MERIS / OLCI 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >= .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupOL_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupOL_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupOL_NC1 7
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupOL_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupOL_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupOL_NES 6
+
+/* LUTs file names */
+#define rsupOL_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_7_4_switch_110416.sn"
+#define rsupOL_LUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+#define rsupOL_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 < .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfOL_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfOL_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfOL_NC1 5
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfOL_NC2 5
+/* nombre de donnees de sortie - nb output*/
+#define rinfOL_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfOL_NES 7
+
+/* LUTs file names */
+#define rinfOL_LUT_POIDS "KdOLCI_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_5_switch_110416.sn"
+#define rinfOL_LUT_MOY "Moy_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+#define rinfOL_LUT_ECART "Ecart_KdOLCI_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_ss_620.dat"
+
+/* LUTs parameters definition */
+float rsupOL_b1[rsupOL_NC1], rsupOL_b2[rsupOL_NC2], rsupOL_b3;
+float rsupOL_w1[rsupOL_NE][rsupOL_NC1], rsupOL_w2[rsupOL_NC1][rsupOL_NC2], rsupOL_w3[rsupOL_NC2];
+float rsupOL_moy[rsupOL_NES], rsupOL_ecart[rsupOL_NES];
+
+float rinfOL_b1[rinfOL_NC1], rinfOL_b2[rinfOL_NC2], rinfOL_b3;
+float rinfOL_w1[rinfOL_NE][rinfOL_NC1], rinfOL_w2[rinfOL_NC1][rinfOL_NC2], rinfOL_w3[rinfOL_NC2];
+float rinfOL_moy[rinfOL_NES], rinfOL_ecart[rinfOL_NES];

+ 104 - 0
neuron_switch180515.h

@@ -0,0 +1,104 @@
+#include <stdio.h>
+
+/* =======================================================================================================
+ *  SeaWiFS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >= .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupSW_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupSW_NC1 10
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupSW_NC2 10
+/* nombre de donnees de sortie - nb output*/
+#define rsupSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupSW_NES 6
+
+/* LUTs file names */
+#define rsupSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_10_publi_180515.sn"
+#define rsupSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_180515.dat"
+#define rsupSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_180515.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 < .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfSW_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfSW_NC1 6
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfSW_NC2 6
+/* nombre de donnees de sortie - nb output*/
+#define rinfSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfSW_NES 7
+
+/* LUTs file names */
+#define rinfSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_6_6_publi_180515_bis.sn"
+#define rinfSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_180515.dat"
+#define rinfSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_180515.dat"
+
+/* LUTs parameters definition */
+float rsupSW_b1[rsupSW_NC1], rsupSW_b2[rsupSW_NC2], rsupSW_b3;
+float rsupSW_w1[rsupSW_NE][rsupSW_NC1], rsupSW_w2[rsupSW_NC1][rsupSW_NC2], rsupSW_w3[rsupSW_NC2];
+float rsupSW_moy[rsupSW_NES], rsupSW_ecart[rsupSW_NES];
+
+float rinfSW_b1[rinfSW_NC1], rinfSW_b2[rinfSW_NC2], rinfSW_b3;
+float rinfSW_w1[rinfSW_NE][rinfSW_NC1], rinfSW_w2[rinfSW_NC1][rinfSW_NC2], rinfSW_w3[rinfSW_NC2];
+float rinfSW_moy[rinfSW_NES], rinfSW_ecart[rinfSW_NES];
+
+
+/* =======================================================================================================
+ *  MODIS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >= .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupMO_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupMO_NC1 5
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupMO_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupMO_NES 6
+
+/* LUTs file names */
+#define rsupMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_4_publi_CSIRO.sn"
+#define rsupMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+#define rsupMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 < .85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfMO_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfMO_NC1 10
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfMO_NC2 7
+/* nombre de donnees de sortie - nb output*/
+#define rinfMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfMO_NES 7
+
+/* LUTs file names */
+#define rinfMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_7_publi_CSIRO.sn"
+#define rinfMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+#define rinfMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+
+/* LUTs parameters definition */
+float rsupMO_b1[rsupMO_NC1], rsupMO_b2[rsupMO_NC2], rsupMO_b3;
+float rsupMO_w1[rsupMO_NE][rsupMO_NC1], rsupMO_w2[rsupMO_NC1][rsupMO_NC2], rsupMO_w3[rsupMO_NC2];
+float rsupMO_moy[rsupMO_NES], rsupMO_ecart[rsupMO_NES];
+
+float rinfMO_b1[rinfMO_NC1], rinfMO_b2[rinfMO_NC2], rinfMO_b3;
+float rinfMO_w1[rinfMO_NE][rinfMO_NC1], rinfMO_w2[rinfMO_NC1][rinfMO_NC2], rinfMO_w3[rinfMO_NC2];
+float rinfMO_moy[rinfMO_NES], rinfMO_ecart[rinfMO_NES];

+ 48 - 0
neuron_switch2.h

@@ -0,0 +1,48 @@
+#include <stdio.h>
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 >=.85 */
+
+/* nombre de couches cachees - hidden layer number */
+#define rsup2_NC 1
+/* nombre de donnees d entree - input data number*/
+#define rsup2_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsup2_NC1 10
+/* nombre de donnees de sortie - nb output*/
+#define rsup2_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsup2_NES 6
+
+/* LUTs file names */
+#define rsup2_LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_publi_250314.sn"
+#define rsup2_LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_250314.dat"
+#define rsup2_LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_250314.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 <.85 */
+/* nombre de couches cachees - hidden layer number */
+#define rinf2_NC 1
+/* nombre de donnees d entree - input data number*/
+#define rinf2_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinf2_NC1 10
+/* nombre de donnees de sortie - nb output*/
+#define rinf2_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinf2_NES 7
+/* LUTs file names */
+#define rinf2_LUT_POIDS "../LUTS/KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_publi_250314.sn"
+#define rinf2_LUT_MOY "../LUTS/Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_250314.dat"
+#define rinf2_LUT_ECART "../LUTS/Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_250314.dat"
+
+/* LUTs parameters definition */
+float rsup2_b1[rsup2_NC1], rsup2_b2;
+float rsup2_w1[rsup2_NE][rsup2_NC1], rsup2_w2[rsup2_NC1];
+float rsup2_moy[rsup2_NES], rsup2_ecart[rsup2_NES];
+
+
+float rinf2_b1[rinf2_NC1], rinf2_b2;
+float rinf2_w1[rinf2_NE][rinf2_NC1], rinf2_w2[rinf2_NC1];
+float rinf2_moy[rinf2_NES], rinf2_ecart[rinf2_NES];
+
+

+ 104 - 0
neuron_switch3.h

@@ -0,0 +1,104 @@
+#include <stdio.h>
+
+/* =======================================================================================================
+ *  SeaWiFS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 > 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupSW_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupSW_NC1 6
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupSW_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupSW_NES 6
+
+/* LUTs file names */
+#define rsupSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_6_4_publi_280314.sn"
+#define rsupSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_280314.dat"
+#define rsupSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_280314.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 <= 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfSW_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfSW_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfSW_NC1 8
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfSW_NC2 5
+/* nombre de donnees de sortie - nb output*/
+#define rinfSW_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfSW_NES 7
+
+/* LUTs file names */
+#define rinfSW_LUT_POIDS "KdSeaWiFS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_8_5_publi_280314.sn"
+#define rinfSW_LUT_MOY "Moy_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_280314.dat"
+#define rinfSW_LUT_ECART "Ecart_KdSeaWiFS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_angle_publi_280314.dat"
+
+/* LUTs parameters definition */
+float rsupSW_b1[rsupSW_NC1], rsupSW_b2[rsupSW_NC2], rsupSW_b3;
+float rsupSW_w1[rsupSW_NE][rsupSW_NC1], rsupSW_w2[rsupSW_NC1][rsupSW_NC2], rsupSW_w3[rsupSW_NC2];
+float rsupSW_moy[rsupSW_NES], rsupSW_ecart[rsupSW_NES];
+
+float rinfSW_b1[rinfSW_NC1], rinfSW_b2[rinfSW_NC2], rinfSW_b3;
+float rinfSW_w1[rinfSW_NE][rinfSW_NC1], rinfSW_w2[rinfSW_NC1][rinfSW_NC2], rinfSW_w3[rinfSW_NC2];
+float rinfSW_moy[rinfSW_NES], rinfSW_ecart[rinfSW_NES];
+
+
+/* =======================================================================================================
+ *  MODIS 
+ * ======================================================================================================= */
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 > 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rsupMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rsupMO_NE 5
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rsupMO_NC1 5
+/* nombre de neurones de la deuxieme couche cachee */
+#define rsupMO_NC2 4
+/* nombre de donnees de sortie - nb output*/
+#define rsupMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rsupMO_NES 6
+
+/* LUTs file names */
+#define rsupMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_555_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_5_4_publi_CSIRO.sn"
+#define rsupMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+#define rsupMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_555_log_Kd_lambda_merge_seuil_15_ss_645_publi_sup_CSIRO.dat"
+
+
+/* Definition  des variables pour le reseau avec Rrs490/Rrs555 <= 1.5 */
+/* nombre de couches cachees - hidden layer number */
+#define rinfMO_NC 2
+/* nombre de donnees d entree - input data number*/
+#define rinfMO_NE 6
+/* nombre de neurones de la premiere couche cachee - number of neuron in the first hidden layer */
+#define rinfMO_NC1 10
+/* nombre de neurones de la deuxieme couche cachee */
+#define rinfMO_NC2 7
+/* nombre de donnees de sortie - nb output*/
+#define rinfMO_NS 1
+/* nombre de neurones d'entree + sortie - nb input + nb output*/
+#define rinfMO_NES 7
+
+/* LUTs file names */
+#define rinfMO_LUT_POIDS "KdMODIS_poids_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_443_to_670_log_Kd_lambda_merge_seuil_15_angle_ascii_6x1_hh_10_7_publi_CSIRO.sn"
+#define rinfMO_LUT_MOY "Moy_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+#define rinfMO_LUT_ECART "Ecart_KdMODIS_IOCCG_NOMAD_BOUM_ss_12_COASTCOLOUR_412_to_670_log_Kd_lambda_merge_seuil_15_ss_645_publi_inf_CSIRO.dat"
+
+/* LUTs parameters definition */
+float rsupMO_b1[rsupMO_NC1], rsupMO_b2[rsupMO_NC2], rsupMO_b3;
+float rsupMO_w1[rsupMO_NE][rsupMO_NC1], rsupMO_w2[rsupMO_NC1][rsupMO_NC2], rsupMO_w3[rsupMO_NC2];
+float rsupMO_moy[rsupMO_NES], rsupMO_ecart[rsupMO_NES];
+
+float rinfMO_b1[rinfMO_NC1], rinfMO_b2[rinfMO_NC2], rinfMO_b3;
+float rinfMO_w1[rinfMO_NE][rinfMO_NC1], rinfMO_w2[rinfMO_NC1][rinfMO_NC2], rinfMO_w3[rinfMO_NC2];
+float rinfMO_moy[rinfMO_NES], rinfMO_ecart[rinfMO_NES];