Index: /ether_iasi_L1C/trunk/IASI_mot_2004_l1b_all_spots_V1.0
===================================================================
--- /ether_iasi_L1C/trunk/IASI_mot_2004_l1b_all_spots_V1.0	(revision 27)
+++ /ether_iasi_L1C/trunk/IASI_mot_2004_l1b_all_spots_V1.0	(revision 27)
@@ -0,0 +1,475 @@
+#!/bin/ksh
+##################################################################
+# extract_iasi.job
+# --------------------
+# Objet : permet d'extraire des orbites IASI une liste de mot 
+# predefinie en plus de ceux demandes par l'utilisateur.
+#  
+# Usage : IASI_mot_2004_l1b -d Debut(aammjj),Fin(aammjj) 
+#                    -iasi liste_de_mot_iasi (separes par ',' ou '-')
+#                    -amsu liste_de_mot_amsu (separes par ',' ou '-')
+#                    -s code_satellite (Metop, ...)
+#                    -lat latmin,latmax
+#                    -lon lonmin,lonmax
+#                    -idtm indice_terre_mer (0=mer,1=terre,2=mer+terre)
+#                    -idjn indice_jour_nuit (0=nuit,1=jour,2=nuit+jour)
+#                    [-c] (sortie format carto)
+# Remarques :
+#  - ordre des options sans importance
+#  - la virgule (',') est le seul separateur reconnu
+#  - le tiret ('-') permet de definir une plage de mots
+#  - les fichiers de sortie sont dans $PATH_Resu :
+#      /IASI_mots.Code_SatVersion.Saammjj.Eaammjj.mNbrMots
+#      /IASI_mots.Code_SatVersion.Saammjj.Eaammjj.mNbrMots.m15.info
+# [-c  /IASI_mots.Code_SatVersion.Saammjj.Eaammjj.mNbrMots_IASI-n°mot ]
+#  - par defaut, la zone geographique extraite est -90,90 en latitude
+#    et -180,180 en longitude
+#  - par defaut, l'extraction se fait pour mer+terre et jour+nuit
+# --------------------
+# Exemple :
+#
+#  IASI_mot_2004_l1b -d 910701,910730 -m 1,10-15,123 -s Metop
+#
+# --------------------
+# 01/07/2007 - R. Armante (LMD/ARA/IPSL) :
+#              erreur selection fichiers retenus en fonction
+#              datedeb et fin demandees ==> parametres M_stop et J_stop
+##################################################################
+
+##################################################################
+# Variables d'environnement
+# -------------------
+#PATH_Orbiasi_l1b="/data/sva/IASI_dev/lmd/New_version_v0.0/Data"
+#PATH_PROG="/data/sva/iasi_l1c/bin"
+#PATH_LOGS="/data/sva/iasi_l1c/logs"
+PROGRAMME="extract_iasi_words_all_spots"
+#PATH_Resu="/data/sva/IASI_dev/lmd/New_version_v0.0/Result"
+
+##################################################################
+# Recupere les options - verifie leur nombre
+# --------------------
+Carto="FALSE"
+Lati="-90,90"
+Long="-180,180"
+Indtm="2"
+Indjn="2"
+typeset -i NbrOptionOblig=0
+while [ $# -ge 1 ]
+do
+  case $1 in
+    -d) shift 1;Date="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
+    -iasi) shift 1;Mot_iasi="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
+    -s) shift 1;Sat="$1";  NbrOptionOblig=$(($NbrOptionOblig+1));;
+    -rd) shift 1;PATH_Resu="$1";  NbrOptionOblig=$(($NbrOptionOblig+1));;
+    -lat) shift 1;Lati="$1";;
+    -lon) shift 1;Long="$1";;
+    -idtm) shift 1;Indtm="$1";;
+    -idjn) shift 1;Indjn="$1";;
+    -logs) shift 1;file_logs="$1";;
+    -req) shift 1;req="$1";;
+    -c) Carto="TRUE";;
+    *) print 'Parameter ' $1 'is not defined in the script !!!'; echo "Parameter ' $1 'is not defined in the script !!!'" >> $PATH_LOGS/iasi_l1c_user_request_$req.txt; exit 1;;
+  esac
+  shift 1
+done
+
+TMPDIR="$PATH_Resu/tmpdir"
+
+
+if [ $NbrOptionOblig -ne 4 ]; then
+  echo $*
+  echo "ERREUR: toutes les options obligatoires ne sont pas remplies"
+  echo "USAGE : "$0" -d Debut(aammjj),Fin(aammjj) "
+  echo "                   -iasi  liste_de_canaux_iasi (separes par ',' ou '-')"
+  echo "                   -s code_satellite (Metop, ...)"
+  echo "                   -rd repertoire resultat"
+  echo "                  [-lat] latmin,latmax"
+  echo "                  [-lon] lonmin,lonmax"
+  echo "                  [-idtm] indice_terre_mer (0=mer,1=terre,2=mer+terre)"
+  echo "                  [-idjn] indice_jour_nuit (0=nuit,1=jour,2=nuit+jour)"
+  echo "                  [-c] (sortie format carto)"
+  exit 1
+fi
+
+conf_file="./conf.txt"
+while read line
+do
+        ll=${#line}
+
+        if [[ -n $(echo $line | grep PATH_PROG) ]] ; then
+		chem=`expr $ll - 11`
+		temp=`echo $line | cut -c11-$ll`
+                PATH_PROG=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_LOGS) ]] ; then
+		chem=`expr $ll - 11`
+		temp=`echo $line | cut -c11-$ll`
+                PATH_LOGS=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_SUN_WEB_SERVICES) ]] ; then
+		chem=`expr $ll - 23`
+		temp=`echo $line | cut -c23-$ll`
+                PATH_SUN_WEB_SERVICES=$temp
+        fi
+	if [[ -n $(echo $line | grep PATH_Orbiasi_l1b) ]] ; then
+		chem=`expr $ll - 18`
+		temp=`echo $line | cut -c18-$ll`
+                PATH_Orbiasi_l1b=$temp
+        fi
+	if [[ -n $(echo $line | grep PATH_TEMP) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_TEMP=$temp
+        fi
+
+
+done < $conf_file
+
+echo "PATH_Orbiasi_l1b=$PATH_Orbiasi_l1b"
+
+
+##################################################################
+# affiche les valeurs passees
+# --------------------
+echo " "$0 $*
+echo "Parametres choisis:"
+echo "  Date     : "$Date 
+echo "  Airs TBs : "$Mot_iasi
+echo "  Satellite: "$Sat
+echo "  Latitude : "$Lati
+echo "  Longitude: "$Long
+echo "  Ind T/M  : "$Indtm
+echo "  Ind J/N  : "$Indjn
+echo "  Carto    : "$Carto
+
+if [ $Indjn -eq 0 ] ;then Filtre_jn='N';fi
+if [ $Indjn -eq 1 ] ;then Filtre_jn='J';fi
+if [ $Indjn -eq 2 ] ;then Filtre_jn='u';fi
+echo 'Filtre_jn' $Filtre_jn
+##################################################################
+# Argument Date
+# --------------------
+
+Date1=`echo $Date | cut -d, -f1`
+Date2=`echo $Date | cut -d, -f2`
+
+# Mise en place de l'environnement de travail
+# --------------------
+if [[ ! -d $PATH_Resu ]];
+then
+  echo "creation du repertoire : " $PATH_Resu
+  mkdir $PATH_Resu
+else
+  echo "WARNING : " $PATH_Resu" existe deja."
+  sleep 5
+# echo "  Ecraser les eventuels fichiers existant (o/n) ?"
+# read choix
+# case $choix in
+#   [Yy]|[Oo]) echo "  => Ecraser"; Ecrase="true";;
+#   [Nn])      echo "  => Conserver"; Ecrase="false";;
+#   *)         echo "  => Mode par defaut = conserver"; Ecrase="false";;
+# esac
+fi
+cd $PATH_Resu
+
+if [[ ! -d $TMPDIR ]];
+then
+  echo "creation d'un repertoire temporaire" $TMPDIR
+  mkdir $TMPDIR
+else
+  echo "WARNING : "$TMPDIR" existe deja." 
+  sleep 5
+fi
+
+cd $TMPDIR
+##################################################################
+# Liste les archives correspondant a la demande
+# --------------------
+# Date1=A1M1J1 et Date2=A2M2J2
+A1=`echo $Date1 | cut -c1-2`;A2=`echo $Date2 | cut -c1-2`
+M1=`echo $Date1 | cut -c3-4`;M2=`echo $Date2 | cut -c3-4`
+J1=`echo $Date1 | cut -c5-6`;J2=`echo $Date2 | cut -c5-6`
+H1=`echo $Date1 | cut -c7-8`;H2=`echo $Date2 | cut -c7-8`
+
+typeset -i Lati1=0
+typeset -i Lati2=0
+typeset -i Long1=0
+typeset -i Long1=0
+
+Lati1=`echo $Lati | cut -d, -f1`
+Lati2=`echo $Lati | cut -d, -f2`
+Long1=`echo $Long | cut -d, -f1`
+Long2=`echo $Long | cut -d, -f2`
+
+echo "Lati1=$Lati1"
+echo "Lati2=$Lati2"
+echo "Long1=$Long1"
+echo "Long2=$Long2"
+
+typeset -i -Z2 aa=$A1
+typeset -i -Z2 mm=$M1
+typeset -i -Z2 jj=$J1
+typeset -i -Z2 hh=$H1
+
+typeset -i lat1=0
+typeset -i lat2=0
+typeset -i lon1=0
+typeset -i lon2=0
+
+if [[ -f Orbites_PRV_erreur ]]; then
+  /bin/rm Orbites_PRV_erreur
+fi
+if [[ -f Orbites_PRV ]]; then
+  /bin/rm Orbites_PRV
+fi
+
+M_stop=12
+J_stop=31
+H_stop=23
+
+echo $aa$mm$jj $M_stop $J_stop $H_stop $A2
+while [[ $aa -le $A2 ]]; do
+echo $aa $A2
+  if [[ $aa -eq $A2 ]]; then M_stop=$M2 ; fi
+  while [[ $mm -le $M_stop ]]; do
+echo $mm $M_stop $M2 $A2
+    if [[ $mm -eq $M2 && $aa -eq $A2 ]]; then J_stop=$J2 ; fi
+    while [[ $jj -le $J_stop ]]; do
+	if [[ $jj -eq $J2 && $mm -eq $M2 ]]; then H_stop=$H2 ; fi 
+	while [[ $hh -le $H_stop  ]]; do
+      #Date_jul=`$PATH_PROG/date_to_quant $aa$mm$jj`
+
+      #cd $PATH_Orbiasi_l1b
+	cd $PATH_Orbiasi_l1b/20$aa/$mm/$jj
+	print "$PATH_Orbiasi_l1b/20$aa/$mm/$jj"
+
+	#echo ">>>>>>>>"
+	#echo $PATH_Orbiasi_l1b
+	#echo "$PATH_Orbiasi_l1b/20$aa/$mm/$jj"
+	#echo ">>>>>>>>"
+      #for fich in iasi_20$aa$mm$jj??.tar
+      for fich in iasi_20$aa$mm$jj$hh.tar
+      do
+	cd $PATH_Orbiasi_l1b/20$aa/$mm/$jj
+
+        tar tf $fich >> $TMPDIR/list_tar_temp
+	cd $TMPDIR
+	
+	cat $TMPDIR/list_tar_temp  |grep "_20$aa$mm$jj$hh" | grep ".f" | while read fichF ;do
+	#cat list_tar_temp  |grep "_20$aa$mm$jj" | grep ".f" | while read fichF ;do
+		#test sur lat et lon
+
+                lat1=`echo $fichF | cut -d_ -f3`
+                lat2=`echo $fichF | cut -d_ -f5`
+                lon1=`echo $fichF | cut -d_ -f4`
+                lon2=`echo $fichF | cut -d_ -f6`
+	
+		lat1=$(($lat1-90))
+		lat2=$(($lat2-90))
+		lon1=$(($lon1-180))
+		lon2=$(($lon2-180))
+
+                test=1
+
+                if [[ $lat1 -ge $Lati1 && $lat1 -le $Lati2 || $lat2 -ge $Lati1 && $lat2 -le $Lati2 ]]; then
+			if [[ $lon1 -lt $lon2 ]]; then
+				if [[ $lon1 -ge $Long1 && $lon1 -le $Long2 || $lon2 -ge $Long1 && $lon2 -le $Long2 ]]; then
+					test=0	
+				fi
+			else
+				if [[ $lon2 -ge $Long1 || $lon1 -le $Long2 ]]; then
+					test=0
+                                fi
+			fi	
+                fi
+
+                if [[ $test -eq 0 ]]; then
+                        #echo "$fichF"
+                        cd $PATH_Orbiasi_l1b/20$aa/$mm/$jj
+                        tar xvf $fich $fichF
+			cp $fichF $TMPDIR 
+                        
+                        echo $TMPDIR"/"$fichF >> $TMPDIR/Orbites_PRV
+                fi
+
+         done
+
+        /bin/rm $TMPDIR/list_tar_temp
+
+
+      done
+
+
+      #/bin/rm *.LT
+      #cd $TMPDIR
+      #ls $PATH_Orbiasi_l1b  |grep $aa$mm$jj$hh | grep ".f" | while read fichF ;do
+      #   echo $PATH_Orbiasi_l1b/$fichF >> $TMPDIR/Orbites_PRV
+      #done
+#     ls $PATH_Orbiasi_l1b/??$aa$mm$jj*.asc 2>> Orbites_PRV_erreur >> Orbites_PRV
+
+
+	if [[ $hh -eq $H_stop ]] ; then
+	  break
+	fi
+
+
+      #rq: certains fichiers n'existent pas d'ou la redirection d'erreur
+      (( hh=$hh+1 )) 
+    done
+    #raz compteur jour pour mois suivant
+    hh=00
+    (( jj=$jj+1 ))
+    done
+    #raz compteur jour pour mois suivant
+    jj=01
+    (( mm=$mm+1 ))
+  done
+  #raz compteur jour pour annee suivante
+  mm=01
+  (( aa=$aa+1 ))
+done
+cd $TMPDIR
+if [[ ! -s Orbites_PRV ]]; then
+  echo "Erreur : aucune archive ne correspond a la requete"
+#  /bin/rm -R $TMPDIR
+  exit 1
+fi
+
+typeset -i Nb_Archives=0
+Nb_Archives=`cat Orbites_PRV | wc -l`
+echo "Nombre d'archives correspondant a la requete: "$Nb_Archives
+
+##################################################################
+# Traitement de la liste de mots
+# --------------------
+# Remplace les virgules par des espaces
+# --------------------
+set -A Mots_iasi `echo $Mot_iasi | sed y/,/' '/`
+# Complete la liste de mot si '-' rencontre
+# --------------------
+echo "Mots_iasi="${Mots_iasi[*]}
+NbrMots_iasi=0
+for elem in ${Mots_iasi[*]}
+do
+  if [[ $elem != *-* ]]; then
+    Liste_Mots_iasi[$NbrMots_iasi]=$elem
+    NbrMots_iasi=$(($NbrMots_iasi+1))
+  else
+    N1=`echo $elem | cut -d- -f1`
+    N2=`echo $elem | cut -d- -f2`
+    if [[ $N1 -ge $N2  ]]; then
+      echo "erreur mots:" $N1 ">=" $N2
+      exit 1
+    fi
+    typeset -i nb=$N1
+    while [[ nb -le $N2 ]] ;
+    do      
+      Liste_Mots_iasi[$NbrMots_iasi]=$nb
+      NbrMots_iasi=$(($NbrMots_iasi+1))
+      nb=nb+1
+    done 
+  fi
+done
+echo ${Liste_Mots_iasi[*]}
+# Ajout des mots par defaut (29 30 31 35 36 37 39 228)
+# pour affichage uniquement, le Fortran les ajoute en "dur"
+# --------------------
+Liste_Mots=${Liste_Mots_iasi[*]}
+NbrMots=$(($NbrMots_iasi))
+echo $NbrMots ${Liste_Mots[*]}
+##################################################################
+# Fichier sortie
+# --------------------
+File=`echo "IASI_mots_all_spots_"$req"."$Sat$Version".S"$Date1".E"$Date2".m"$NbrMots`
+
+##################################################################
+# Affiche les arguments traites
+# --------------------
+echo "req=$req"
+cat > $File".info" <<EOF
+Recapitulatif des parametres:
+  Satellite et version: $Sat $Version
+  DateDebut: $Date1
+  DateFin  : $Date2
+  Latitude : $Lati
+  Longitude: $Long
+  Nombre total de mots: $NbrMots
+  Liste totale des mots: ${Liste_Mots[*]}
+  Fichier Sortie: $File
+EOF
+cat $File".info"
+
+##################################################################
+# Boucle sur les archives
+# --------------------
+FlagHeader="TRUE" #permet d'ecrire un header. Ne le faire que la 1ere fois!
+typeset -i CptPRV=1
+while read Archive
+do
+echo $Archive
+echo "Archive=$Archive"
+  # Execution du programme Fortran
+  # --------------------
+
+  $PATH_PROG/bufr $Archive
+  /bin/rm $Archive
+  ls |grep ".asc" > Orbites_PR
+  $PATH_PROG/$PROGRAMME $Carto $FlagHeader $Lati $Long $Indtm $Indjn Orbites_PR temp_file ${Liste_Mots[*]}
+  for fichF in $(<Orbites_PR) ; do /bin/rm $fichF ; done
+
+	echo "TMPDIR=$TMPDIR"
+	echo "PATH_Result=$PATH_Resu"
+
+	#cp Orbites_PR $PATH_PROG/Orb_PR
+  rm $TMPDIR/Orbites_PR
+
+  #on desactive le header pour la prochaine etape
+  FlagHeader="FALSE"
+  # Sauvegarde du resultat temporaire
+  # --------------------
+  cat temp_file >> $File
+  
+  # ====================
+  # Si option carto
+  # ====================
+  if [[ $Carto = "TRUE" ]]; then
+    for j in ${Mots_desire[*]};
+    do
+      #extract_iii complete les indices des mots par des zeros (ex:IASI-005)
+      #carto comprend l'indice sans completion (ex:IASI-5)
+      typeset -i -Z3 JJJ=$j
+      cat temp_file*$JJJ > $File"_IASI-"$j
+    done
+    #on desactive l'option carto pour la prochaine etape
+    #(evite de creer des fichiers trop long inutiles)
+    Carto="FALSE"
+    echo "WARNING : Option carto desactivee pour archives suivantes"
+  fi
+  # ====================
+
+  # Efface les fichiers temporaires
+  # --------------------
+ #/bin/rm temp_file*
+  #/bin/rm Orbites_PR
+
+  # Passe a l'archive suivante
+  # --------------------
+  (( CptPRV=$CptPRV+1 ))
+
+done < Orbites_PRV
+
+##################################################################
+# Sauvegarde des resultats
+# --------------------
+if [[ $Ecrase = "true" ]];
+then
+  /bin/mv -f $File* $PATH_TEMP/
+else
+  /bin/mv -fu $File* $PATH_TEMP/
+fi
+echo "Les fichiers resultats se trouvent dans : "$PATH_Resu
+##################################################################
+# Suppression du repertoire temporaire
+# --------------------
+echo "suppression du repertoire temporaire"
+#/bin/rm -r $PATH_Resu
Index: /ether_iasi_L1C/trunk/bufr.cpp
===================================================================
--- /ether_iasi_L1C/trunk/bufr.cpp	(revision 27)
+++ /ether_iasi_L1C/trunk/bufr.cpp	(revision 27)
@@ -0,0 +1,1527 @@
+/*
+$Id: BUFR.cpp,v 1.5 2007/02/19 12:53:34 dhurtma Exp $
+$Id: BUFR.cpp,v 1.6 2007/06/10 cboonne $
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#include <math.h>
+#include <time.h>
+
+// Usefull Window Definitions
+typedef unsigned char       BYTE;
+typedef unsigned short      WORD;
+typedef unsigned long       DWORD,DWORD_PTR,LONG;
+
+#define BOOL  bool
+#define TRUE  1
+#define FALSE 0
+#define MAX_PATH 260
+
+#define MAKEWORD(a, b)      ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
+#define MAKELONG(a, b)      ((LONG)(((WORD)((DWORD_PTR)(a) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)(b) & 0xffff))) << 16))
+#define LOWORD(l)           ((WORD)((DWORD_PTR)(l) & 0xffff))
+#define HIWORD(l)           ((WORD)((DWORD_PTR)(l) >> 16))
+#define LOBYTE(w)           ((BYTE)((DWORD_PTR)(w) & 0xff))
+#define HIBYTE(w)           ((BYTE)((DWORD_PTR)(w) >> 8))
+
+
+
+unsigned long convert24_32(unsigned char *lpData)
+{
+ unsigned long l_data;
+
+ l_data=lpData[0];
+ l_data=(l_data<<8)+lpData[1];
+ l_data=(l_data<<8)+lpData[2];
+
+ return l_data;
+}
+
+unsigned short convert16_16(unsigned char *lpData)
+{
+ unsigned short l_data;
+
+ l_data=lpData[0];
+ l_data=(l_data<<8)+lpData[1];
+
+ return l_data;
+}
+
+typedef struct _bufr_section_ptrs
+{
+ long p0;
+ long p1;
+ long p2;
+ long p3;
+ long p4;
+ long p5;
+} SECTION_PTR;
+
+typedef struct bufr_section_0
+{
+ char BUFR[4];
+ static const unsigned long length=8;
+ unsigned long FileLength;
+ unsigned char edition; 
+} SECTION_0,*LPSECTION_0;
+
+typedef enum
+{
+ DC_Surface_Land=0,
+ DC_Surface_Sea,
+ DC_Vertical,
+ DC_Vertical_Satellite,
+ DC_Single_Level_Upper,
+ DC_Single_Level_Upper_Satellite,
+ DC_Surface_Satellite=12,
+ DC_Oceanographic=31 
+} DATA_CATEGORY;
+
+typedef struct bufr_section_1
+{
+ unsigned long  length;
+ unsigned char  Master_Table_Number;
+ unsigned char  Sub_Centre;
+ unsigned char  Centre;
+ unsigned char  Update_Sequence;
+ bool           bOptional;
+ DATA_CATEGORY  Data_Category;
+ unsigned char  Data_Sub_Category;
+ unsigned char  Master_Table_Version;
+ unsigned char  Local_Table_Version;
+ unsigned short Year;
+ unsigned char  Month;
+ unsigned char  Day;
+ unsigned char  Hour;
+ unsigned char  Minute;
+ unsigned char *lpADP_Reserved;
+} SECTION_1,*LPSECTION_1;
+
+typedef struct bufr_section_2
+{
+ unsigned long  length;
+ unsigned char  dummy;
+ unsigned char *lpADP_Reserved; 
+} SECTION_2,*LPSECTION_2;
+
+typedef struct bufr_descriptor
+{
+ unsigned char X : 6;  // F=0,3 Class; F=1 # of parameters, F=2  
+ unsigned char F : 2;  // 0 --> Element Table B, 1 --> Replicator, 2 --> Operator Table C, 3 --> Sequence Table D
+ unsigned char Y;      // F=0,3 Entry within class, F=1 times to replicate if 0 read in data
+} DESCRIPTOR,*LPDESCRIPTOR;
+ 
+typedef struct bufr_section_3
+{
+ unsigned long  length;
+ unsigned char  dummy;
+ unsigned short Number_Subsets;
+ bool           bObserved;
+ bool           bCompressed;
+ unsigned long  Number_Descriptors;
+ LPDESCRIPTOR   lpDescriptors;
+} SECTION_3,*LPSECTION_3;
+
+typedef struct bufr_section_4
+{
+ unsigned long  length;
+ unsigned char  dummy;
+ unsigned char *lpData;
+} SECTION_4,*LPSECTION_4;
+
+typedef struct bufr_3_40_002
+{
+ unsigned short Start_Channel;            // 14 bits
+ unsigned short End_Channel;              // 14 bits
+ unsigned char  Channel_Scale_Factor;     //  6 bits
+}DESCR_3_40_002;
+
+typedef struct bufr_3_40_003
+{
+ unsigned short Channel_Number[100];	     //	14 bits
+ unsigned short Scaled_Iasi_Radiance[100];// 16 bits
+}DESCR_3_40_003;
+
+typedef struct bufr_3_40_004
+{
+ unsigned long Y_angular_position;        // 24 bits
+ unsigned long Z_angular_position;        //	24 bits
+ unsigned char Fraction_clear_pixels_HIRS;// 	7 bits
+
+ unsigned char Channel_Number[6];        	// 	6 bits
+ unsigned char Channel_Scale_Factor_1[6];	// 	6 bits
+ unsigned long Scaled_Mean_AVHRR_Rad[6]; 	// 31 bits
+ unsigned char Channel_Scale_Factor_2[6];	// 	6 bits
+ unsigned long Scaled_Std_AVHRR_Rad[6];	  // 31 bits
+}DESCR_3_40_004;
+
+typedef struct bufr_3_40_001
+{
+ unsigned short Satellite_Identifier;     // 10 bits  
+ unsigned short Originating_Centre;       // 16 bits  
+ unsigned short Satellite_Instruments_1;  // 11 bits  
+ unsigned short Satellite_Classification; //  9 bits  
+ unsigned short Year;                     // 12 bits
+ unsigned char  Month;                    //  4 bits
+ unsigned char  Day;                      //  6 bits
+ unsigned char  Hour;                     //  5 bits
+ unsigned char  Minute;                   //  6 bits
+ unsigned short Second;                   //	16 bits
+ unsigned long  Latitude;                 //	25 bits
+ unsigned long  Longitude;                //	26 bits
+ unsigned short Satellite_Zenith_Angle;   // 15 bits
+ unsigned short Azimuth;                  //	16 bits
+ unsigned short Solar_Zenith_Angle;       // 15 bits
+ unsigned short Solar_Azimuth;            //	16 bits
+ unsigned char  FOV_Number;               // 	8 bits
+ unsigned long  Orbit_Number;             //	24 bits
+ unsigned short Scan_Line_Number;         //	13 bits
+ unsigned char  Major_Frame_Count;        // 	8 bits
+ unsigned short Height_of_Station;	       //	15 bits
+ unsigned char  GQisFlagQual;	            //		2 bits
+ unsigned char  QGisQualIndex;	           //		7 bits
+ unsigned char  QGisQualIndexLoc;	        //		7 bits
+ unsigned char  QGisQualIndexRad;	        //		7 bits
+ unsigned char  QGisQualIndexSpect;	      //		7 bits
+ unsigned long  GQisQualIndexTexSondQual;	//	24 bits
+ DESCR_3_40_002 Band_Description[10];
+ DESCR_3_40_003 Channels_Sequence[87];
+ unsigned short Satellite_Instruments_2;  // 11 bits
+ unsigned char  AVHRR_channel_combination;//  7 bits 
+ DESCR_3_40_004 AVHRR_Scene_Sequence[7];    
+}DESCR_3_40_001;
+
+typedef struct iasi_amp
+{
+ char          szMagic[16];               // AMP_IASI_V1
+ double        date;
+ double        Latitude;
+ double        Longitude;
+ unsigned char QualFlag;
+ double        Satellite_Zenith_Angle;
+ double        Azimuth;
+ double        Solar_Zenith_Angle;
+ double        Solar_Azimuth;
+ unsigned long Orbit_Number;
+ double        Height_of_Station;
+ double        Cloud_Free_Fraction[7];
+ double        AVHRR_Mean[6][7];
+ double        AVHRR_Std[6][7];
+ double        nu_start;
+ double        nu_end;
+ long          nbp; 
+ double        Radiance[8700];
+} IASI_AMP,*LPIASI_AMP;
+
+IASI_AMP      specs[120];
+
+BOOL ProcessCompressedIasiLevel1CData(SECTION_1 s1,SECTION_3 s3,SECTION_4 s4,LPIASI_AMP specs);
+
+void bufr_parse_section_4(unsigned char *lpData,SECTION_4 &s4)
+{
+ unsigned short offset=3;
+ unsigned long  length_Data;
+ 
+ s4.length=convert24_32(lpData); 
+ s4.dummy=lpData[offset++];
+ length_Data=s4.length-offset;
+
+ s4.lpData=(unsigned char*)malloc(length_Data);
+ memcpy(s4.lpData,lpData+offset,length_Data);
+}
+
+void bufr_free_s4(SECTION_4 &s4)
+{
+ if (s4.lpData)
+    free(s4.lpData);
+}
+
+void bufr_parse_section_3(unsigned char *lpData,SECTION_3 &s3)
+{
+ unsigned short offset=3;
+ unsigned long  length_Descriptor;
+ 
+ s3.length=convert24_32(lpData); 
+ s3.dummy=lpData[offset++];
+ s3.Number_Subsets=convert16_16(lpData+offset)  ;
+ offset=6;
+ s3.bObserved=((lpData[offset]&128)==128);
+ s3.bCompressed=((lpData[offset]&64)==64);
+ offset=7;
+ length_Descriptor=s3.length-offset;
+ s3.Number_Descriptors=length_Descriptor/2;
+ s3.lpDescriptors=(LPDESCRIPTOR)malloc(length_Descriptor);
+ memcpy(s3.lpDescriptors,lpData+offset,length_Descriptor);
+}
+
+void bufr_free_s3(SECTION_3 &s3)
+{
+ if (s3.lpDescriptors)
+    free(s3.lpDescriptors);
+}
+
+void bufr_parse_section_2(unsigned char *lpData,SECTION_2 &s2)
+{
+ unsigned short offset=4;
+ unsigned long  length_Reserved;
+
+ s2.length=convert24_32(lpData); 
+ s2.dummy=lpData[3]; 
+ length_Reserved=s2.length-offset;
+ s2.lpADP_Reserved=(unsigned char*)malloc(length_Reserved);
+ memcpy(s2.lpADP_Reserved,lpData+offset,length_Reserved);
+}
+
+void bufr_free_s2(SECTION_2 &s2)
+{
+ if (s2.lpADP_Reserved)
+    free(s2.lpADP_Reserved);
+}
+
+void bufr_parse_section_1(unsigned char *lpData,SECTION_1 &s1)
+{
+ unsigned short offset=3;
+ unsigned long  length_Reserved;
+
+ s1.length=convert24_32(lpData); 
+ s1.Master_Table_Number=lpData[offset++];
+ s1.Sub_Centre=lpData[offset++];
+ s1.Centre=lpData[offset++];
+ s1.Update_Sequence=lpData[offset++];
+ s1.bOptional=((lpData[offset++]&128)==128);
+ s1.Data_Category=(DATA_CATEGORY)lpData[offset++];
+ s1.Data_Sub_Category=lpData[offset++];
+ s1.Master_Table_Version=lpData[offset++];
+ s1.Local_Table_Version=lpData[offset++];
+ s1.Year=2000+lpData[offset++];
+ s1.Month=lpData[offset++];
+ s1.Day=lpData[offset++];
+ s1.Hour=lpData[offset++];
+ s1.Minute=lpData[offset++];
+ length_Reserved=s1.length-offset;
+ s1.lpADP_Reserved=(unsigned char*)malloc(length_Reserved);
+ memcpy(s1.lpADP_Reserved,lpData+offset,length_Reserved);
+}
+
+void bufr_free_s1(SECTION_1 &s1)
+{
+ if (s1.lpADP_Reserved)
+    free(s1.lpADP_Reserved);
+}
+
+void bufr_parse_section_0(unsigned char *lpData,SECTION_0 &s0)
+{
+ memcpy(s0.BUFR,lpData,4);
+ s0.FileLength=convert24_32(lpData+4); 
+ s0.edition=lpData[7];
+}
+
+int main(int argc, char* argv[])
+{
+ FILE *fin;
+ unsigned char *lpData;
+ unsigned long DataAllocated;
+ unsigned long length;
+ SECTION_0     s0={0};
+ SECTION_1     s1={0};
+ SECTION_2     s2={0};
+ SECTION_3     s3={0};
+ SECTION_4     s4={0};
+ long          it=0;
+ long          filelength;
+ unsigned long i,j,k;
+ SECTION_PTR   sp;
+ BOOL          bAnswer;
+
+
+ fin=fopen(argv[1],"rb");
+
+ DataAllocated=8;
+ lpData=(unsigned char*)malloc(DataAllocated);
+ fseek(fin,0,SEEK_END);
+ filelength=ftell(fin);
+ sp.p0=0; 
+
+L_AGAIN:
+ it++;
+ // Add preamble
+ sp.p0+=34; //Orbit, hour,...?
+ // Section 0
+ if (fseek(fin,sp.p0,SEEK_SET)>0)
+    goto L_FIN;
+ // Section 0 is always 8 bytes long
+ length=8;
+ // Read & parse
+ if (fread(lpData,length,1,fin)<1)
+    goto L_FIN;
+ bufr_parse_section_0(lpData,s0);
+ sp.p1=sp.p0+s0.length;
+
+ // Section 1 
+ fseek(fin,sp.p1,SEEK_SET);
+ // Get length
+ fread(lpData,3,1,fin);
+ length=convert24_32(lpData);
+ // Reallocate buffer if needed
+ if (length>DataAllocated)
+   {
+    DataAllocated=length;
+    lpData=(unsigned char*)realloc(lpData,length);
+   }
+ // Read & parse
+ fseek(fin,sp.p1,SEEK_SET);
+ fread(lpData,length,1,fin);
+ bufr_parse_section_1(lpData,s1);
+ if (s1.bOptional)
+   {
+    sp.p2=sp.p1+s1.length;
+
+    // Section 2
+    fseek(fin,sp.p2,SEEK_SET);
+
+    // Get length
+    fread(lpData,3,1,fin);
+    length=convert24_32(lpData);
+    // Reallocate buffer if needed
+    if (length>DataAllocated)
+      {
+       DataAllocated=length;
+       lpData=(unsigned char*)realloc(lpData,length);
+      }
+    // Read & parse
+    fseek(fin,sp.p2,SEEK_SET);
+    fread(lpData,length,1,fin);
+    bufr_parse_section_2(lpData,s2);
+
+    sp.p3=sp.p2+s2.length;
+   }
+ else
+   {
+    sp.p2=-1;
+    sp.p3=sp.p1+s1.length;
+   }
+
+ // Section 3
+ fseek(fin,sp.p3,SEEK_SET);
+ // Get length
+ fread(lpData,3,1,fin);
+ length=convert24_32(lpData);
+ // Reallocate buffer if needed
+ if (length>DataAllocated)
+   {
+    DataAllocated=length;
+    lpData=(unsigned char*)realloc(lpData,length);
+   }
+ // Read & parse
+ fseek(fin,sp.p3,SEEK_SET);
+ fread(lpData,length,1,fin);
+ bufr_parse_section_3(lpData,s3);
+ sp.p4=sp.p3+s3.length;
+
+ // Section 4
+ fseek(fin,sp.p4,SEEK_SET);
+ // Get length
+ fread(lpData,3,1,fin);
+ length=convert24_32(lpData);
+
+ // Reallocate buffer if needed
+ if (length>DataAllocated)
+   {
+    DataAllocated=length;
+    lpData=(unsigned char*)realloc(lpData,length);
+   }
+
+ // Read & parse
+ fseek(fin,sp.p4,SEEK_SET);
+ memset(lpData,0xff,length);
+
+ fread(lpData,1,length,fin);
+ 
+ bufr_parse_section_4(lpData,s4);
+ sp.p5=sp.p4+s4.length;
+
+/*
+ for (i=0;i<s3.Number_Descriptors;++i)
+    {
+     printf ("%.2d:%.2d => %.1d %.2d %.3d\n",it,i,s3.lpDescriptors[i].F,s3.lpDescriptors[i].X,s3.lpDescriptors[i].Y);
+    }
+*/
+ 
+ //Check section 5 is 7777
+ fseek(fin,sp.p5,SEEK_SET);
+ fread(lpData,4,1,fin);
+ if (strncmp((char*)lpData,"7777",4)!=0)
+    printf("Error\n");
+     
+ // Process lpdata
+ bAnswer=ProcessCompressedIasiLevel1CData(s1,s3,s4,specs);
+/*
+ if (bAnswer)
+     printf("AVHRR status  : Seems OK\n");
+ else
+     printf("AVHRR status  : Seems Corrupt\n");
+*/
+ 
+ // Save spectra...
+ for (k=0;k<120;++k)
+    {
+     char szFName[MAX_PATH];
+     FILE *fSpec;
+
+     sprintf(szFName,"%15.6lf_%.3d_%.5d_%.5d.asc",specs[k].date,k+1,int((specs[k].Latitude+90)*100),int((specs[k].Longitude+180)*100));
+     fSpec=fopen(szFName,"w");
+
+     fprintf(fSpec,"==========================================================\n");
+     {
+      struct tm   *newTime;
+      time_t      szClock;
+
+      // Get time in seconds
+      time( &szClock );
+
+      // Convert time to struct tm form 
+      newTime = localtime( &szClock );
+
+      // Note: asctime is deprecated; consider using asctime_s instead
+      fprintf(fSpec,"IASI file converted on %s", asctime(newTime)) ;
+     }
+
+     fprintf(fSpec,"==========================================================\n");
+     fprintf(fSpec,"%15.9lf : Date\n",specs[k].date);
+     fprintf(fSpec,"%.08d : Orbit Number\n",specs[k].Orbit_Number);
+     switch (specs[k].QualFlag)
+           {
+            case 0: 
+                fprintf(fSpec,"good : Quality Flag\n");
+                break;
+            case 1: 
+                fprintf(fSpec,"bad : Quality Flag\n");
+                break;
+            case 2: 
+                fprintf(fSpec,"reserved : Quality Flag\n");
+                break;
+            case 3: 
+                fprintf(fSpec,"missing : Quality Flag\n");
+                break;
+           }
+/*
+     if (bAnswer)
+         fprintf(fSpec,"AVHRR status  : Seems OK\n");
+     else
+         fprintf(fSpec,"AVHRR status  : Seems Corrupt\n");
+*/
+     printf("%+7.5lf,%+7.5lf,%5.2lf,%5.1lf,%15.9lf,%.08d,%s,%.1d\n",specs[k].Latitude,specs[k].Longitude,specs[k].Satellite_Zenith_Angle,
+            specs[k].Height_of_Station,specs[k].date,specs[k].Orbit_Number,szFName,specs[k].QualFlag);
+     fprintf(fSpec,"%+7.5lf : Latitude(?)\n",specs[k].Latitude);
+     fprintf(fSpec,"%+7.5lf : Longitude(?)\n",specs[k].Longitude);
+     fprintf(fSpec,"%5.2lf : Sat ZA(?)\n",specs[k].Satellite_Zenith_Angle);
+     fprintf(fSpec,"%5.2lf : Sat AZ(?)\n",specs[k].Azimuth);
+     fprintf(fSpec,"%5.2lf : Sun ZA(?)\n",specs[k].Solar_Zenith_Angle);
+     fprintf(fSpec,"%5.2lf : Sun AZ(?)\n",specs[k].Solar_Azimuth);
+     fprintf(fSpec,"%5.1lf : Altitude(km)\n",specs[k].Height_of_Station);
+     fprintf(fSpec," ");
+     for (i=0;i<7;++i)
+         fprintf(fSpec,"%+2.0lf ",specs[k].Cloud_Free_Fraction[i]);
+     fprintf(fSpec," : Cloud Free(%%)\n");
+     for (j=0;j<6;++j)
+        {
+         fprintf(fSpec,"AVHRR Pixel    : %.1d\n",j+1);
+         fprintf(fSpec,"      Mean     : ");
+         for (i=0;i<7;++i)
+             fprintf(fSpec,"%.4le ",specs[k].AVHRR_Mean[j][i]);
+         fprintf(fSpec,"\n");
+         fprintf(fSpec,"      Std      : ");
+         for (i=0;i<7;++i)
+             fprintf(fSpec,"%.4le ",specs[k].AVHRR_Std[j][i]);
+         fprintf(fSpec,"\n");
+        }
+ 
+     fprintf(fSpec,"%7.2lf : nu start(cm-1)\n",specs[k].nu_start);
+     fprintf(fSpec,"%7.2lf : nu end(cm-1)\n",specs[k].nu_end);
+     fprintf(fSpec,"%.3d : nbp\n",specs[k].nbp);
+     fprintf(fSpec,"==========================================================\n");
+     for (int i=0;i<8700;++i)
+         fprintf(fSpec,"%+.4le\n",specs[k].Radiance[i]);
+     fclose(fSpec);          
+    } 
+
+ // Cleanup and free
+ bufr_free_s1(s1);
+ bufr_free_s2(s2);
+ bufr_free_s3(s3);
+ bufr_free_s4(s4);
+
+ sp.p0=sp.p5+4; // size of section 5
+ sp.p0+=4;      // End of message post bytes
+
+
+ if (sp.p0<filelength)
+   {
+    goto L_AGAIN;
+   }
+
+L_FIN:
+ free(lpData);
+ fclose(fin); 
+	return 0;
+}
+
+void GetNextBits(unsigned char *lpData,unsigned char NbBits,unsigned char ReturnSize,void* lpReturn,bool bReset=false)
+{
+ static long   BytePos;
+ static int    BitPos;
+ unsigned char ByteTempBuffer[5];
+ unsigned char *lpTempReturn;
+ int           nBytes;
+
+ if (bReset)
+   {
+    BytePos=0;
+    BitPos=0;
+    return;
+   } 
+ lpTempReturn=(unsigned char*)lpReturn;
+ memset(ByteTempBuffer,0,5*sizeof(unsigned char));
+ nBytes=(NbBits+BitPos)/8+((NbBits+BitPos)%8>0);
+ // Transfer from lpData to Buffer with byte reversing
+ for (int i=0;i<nBytes;++i)
+    {
+     ByteTempBuffer[i]=lpData[BytePos+i];
+    }
+ memset(lpReturn,0,ReturnSize);
+
+ // Mask
+ switch (nBytes)
+       {
+        case 1:
+            {
+             char           Shift_8;
+             unsigned char  Mask;
+             unsigned char  Work;
+
+             Shift_8=(8-BitPos)-NbBits;
+ 
+             Mask=((unsigned char)1<<NbBits)-1;                  // Build the Mask (eg: 00111111 for 6 bits data)
+             Work=ByteTempBuffer[0];                             // Transfer data to Work
+             Work>>=Shift_8;                                     // Align bits to the window
+             Work&=Mask;                                         // Apply the mask
+             ByteTempBuffer[0]=Work;                             // Save Work back in buffer
+             break;
+            }
+
+        case 2:
+            {
+             char           Shift_16;
+             unsigned short Mask;
+             unsigned short Work;
+
+             Shift_16=(16-BitPos)-NbBits;
+
+             Mask=((unsigned short)1<<NbBits)-1;                  // Build the Mask
+             Work=MAKEWORD(ByteTempBuffer[1],ByteTempBuffer[0]);  // Transfer data to Work
+             Work>>=Shift_16;                                     // Align bits to the window
+             Work&=Mask;                                          // Apply the mask
+             ByteTempBuffer[0]=LOBYTE(Work);                      // Save Work back in buffer with proper "endianness"
+             ByteTempBuffer[1]=HIBYTE(Work);                      
+             break;
+            }
+
+        case 3:
+            {
+             char           Shift_24;
+             unsigned long  Mask;                                 // Work in 4 bytes as there is no 3 bytes types
+             unsigned long  Work;
+             unsigned short W1,W2;
+
+             Shift_24=(24-BitPos)-NbBits;
+
+             Mask=((unsigned long)1<<NbBits)-1;                   // Build the Mask
+             W2=MAKEWORD(ByteTempBuffer[2],ByteTempBuffer[1]);    // Transfer data to High Word of Work
+             W1=MAKEWORD(ByteTempBuffer[0],0);                    // Transfer data to Low Word of  Work
+             Work=MAKELONG(W2,W1);
+             Work>>=Shift_24;                                     // Align bits to the window
+             Work&=Mask;                                          // Apply the mask
+             W1=LOWORD(Work);
+             W2=HIWORD(Work);
+             ByteTempBuffer[0]=LOBYTE(W1);                        // Save Work back in buffer with proper "endianness"
+             ByteTempBuffer[1]=HIBYTE(W1);                      
+             ByteTempBuffer[2]=LOBYTE(W2);                      
+             ByteTempBuffer[3]=0;                      
+             break;
+            }
+
+        case 4:
+            {
+             char           Shift_32;
+             unsigned long  Mask;
+             unsigned long  Work;
+             unsigned short W1,W2;
+
+             Shift_32=(32-BitPos)-NbBits;
+
+             Mask=((unsigned long)1<<NbBits)-1;                   // Build the Mask
+             W2=MAKEWORD(ByteTempBuffer[3],ByteTempBuffer[2]);    // Transfer data to High Word of Work
+             W1=MAKEWORD(ByteTempBuffer[1],ByteTempBuffer[0]);    // Transfer data to Low Word of  Work
+             Work=MAKELONG(W2,W1);
+             Work>>=Shift_32;                                     // Align bits to the window
+             Work&=Mask;                                          // Apply the mask
+             W1=LOWORD(Work);
+             W2=HIWORD(Work);
+             ByteTempBuffer[0]=LOBYTE(W1);                        // Save Work back in buffer with proper "endianness"
+             ByteTempBuffer[1]=HIBYTE(W1);                      
+             ByteTempBuffer[2]=LOBYTE(W2);                      
+             ByteTempBuffer[3]=HIBYTE(W2);                      
+             break;
+            }
+
+        case 5:
+             unsigned char  Shift_40;
+             unsigned long  Mask;                                 // Use more than 4 bytes but store only on 4
+             unsigned long  Work;
+             unsigned char  WorkLSB;
+             unsigned char  ShiftLSB;
+             unsigned short W1,W2;
+
+             Shift_40=BitPos+NbBits-32;
+
+             Mask=((unsigned long)1<<NbBits)-1;                   // Build the Mask
+             ShiftLSB=7-Shift_40;
+
+             W2=MAKEWORD(ByteTempBuffer[3],ByteTempBuffer[2]);    // Transfer data to High Word of Work
+             W1=MAKEWORD(ByteTempBuffer[1],ByteTempBuffer[0]);    // Transfer data to Low Word of  Work
+             Work=MAKELONG(W2,W1);
+             Work<<=Shift_40;                                     // We work reverse here.
+             WorkLSB=ByteTempBuffer[4];
+             WorkLSB>>=ShiftLSB;
+             Work|=WorkLSB;                                       // Join the shifted LSB bits to Work
+             Work&=Mask;                                          // Apply the mask
+             W1=LOWORD(Work);
+             W2=HIWORD(Work);
+             ByteTempBuffer[0]=LOBYTE(W1);                        // Save Work back in buffer with proper "endianness"
+             ByteTempBuffer[1]=HIBYTE(W1);                      
+             ByteTempBuffer[2]=LOBYTE(W2);                      
+             ByteTempBuffer[3]=HIBYTE(W2);                      
+             break;
+       }
+ // Set return value
+ memcpy(lpTempReturn,ByteTempBuffer,ReturnSize);
+
+ // Update position
+ BitPos+=NbBits;
+ BytePos+=BitPos/8;
+ BitPos%=8;
+}
+
+BOOL ProcessCompressedIasiLevel1CData(SECTION_1 s1,SECTION_3 s3,SECTION_4 s4,LPIASI_AMP specs)
+{
+ unsigned char NbBits;
+ 
+ DESCR_3_40_002 LocalChannel[120*10];
+ DESCR_3_40_001 LocalBufr;
+
+ for (int k=0;k<120;++k)
+    {
+     specs[k].nbp=8700;
+     specs[k].nu_start=645.;
+     specs[k].nu_end=2819.75;
+     strcpy(specs[k].szMagic,"AMP_IASI_V1");
+    }
+
+ GetNextBits(0,0,0,0,true);
+ GetNextBits(s4.lpData,10,sizeof(LocalBufr.Satellite_Identifier),&LocalBufr.Satellite_Identifier,false);
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Satellite_Identifier;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,16,sizeof(LocalBufr.Originating_Centre),&LocalBufr.Originating_Centre,false);
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Originating_Centre;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,11,sizeof(LocalBufr.Satellite_Instruments_1),&LocalBufr.Satellite_Instruments_1,false);
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Satellite_Instruments_1;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData, 9,sizeof(LocalBufr.Satellite_Classification),&LocalBufr.Satellite_Classification,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Satellite_Classification;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,12,sizeof(LocalBufr.Year),&LocalBufr.Year,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Year;
+        specs[k].date=temp*10000;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date=LocalBufr.Year*10000;
+   }
+
+ GetNextBits(s4.lpData, 4,sizeof(LocalBufr.Month),&LocalBufr.Month,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Month;
+        specs[k].date+=temp*100;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date+=LocalBufr.Month*100;
+   }
+ GetNextBits(s4.lpData, 6,sizeof(LocalBufr.Day),&LocalBufr.Day,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Day;
+        specs[k].date+=temp;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date+=LocalBufr.Day;
+   }
+ GetNextBits(s4.lpData, 5,sizeof(LocalBufr.Hour),&LocalBufr.Hour,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Hour;
+        specs[k].date+=temp/100.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date+=LocalBufr.Hour/100.;
+   }
+ GetNextBits(s4.lpData, 6,sizeof(LocalBufr.Minute),&LocalBufr.Minute,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Minute;
+        specs[k].date+=temp/10000.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date+=LocalBufr.Minute/10000.;
+   }
+ GetNextBits(s4.lpData,16,sizeof(LocalBufr.Second),&LocalBufr.Second,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Second;
+        specs[k].date+=temp/1e9;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].date+=LocalBufr.Second/1e9;
+   }
+
+ GetNextBits(s4.lpData,25,sizeof(LocalBufr.Latitude),&LocalBufr.Latitude,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned long temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Latitude;
+        specs[k].Latitude=temp/1e5-90.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Latitude=LocalBufr.Latitude/1e5-90.;
+   }
+
+ GetNextBits(s4.lpData,26,sizeof(LocalBufr.Longitude),&LocalBufr.Longitude,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned long temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Longitude;
+        specs[k].Longitude=temp/1e5-180.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Longitude=LocalBufr.Longitude/1e5-180.;
+   }
+
+ GetNextBits(s4.lpData,15,sizeof(LocalBufr.Satellite_Zenith_Angle),&LocalBufr.Satellite_Zenith_Angle,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Satellite_Zenith_Angle;
+        specs[k].Satellite_Zenith_Angle=temp/100.-90.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Satellite_Zenith_Angle=LocalBufr.Satellite_Zenith_Angle/100.-90.;
+   }
+
+ GetNextBits(s4.lpData,16,sizeof(LocalBufr.Azimuth),&LocalBufr.Azimuth,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Azimuth;
+        specs[k].Azimuth=temp/100.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Azimuth=LocalBufr.Azimuth/100.;
+   }
+
+ GetNextBits(s4.lpData,15,sizeof(LocalBufr.Solar_Zenith_Angle),&LocalBufr.Solar_Zenith_Angle,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Solar_Zenith_Angle;
+        specs[k].Solar_Zenith_Angle=temp/100.-90.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Solar_Zenith_Angle=LocalBufr.Solar_Zenith_Angle/100.-90.;
+   }
+
+ GetNextBits(s4.lpData,16,sizeof(LocalBufr.Solar_Azimuth),&LocalBufr.Solar_Azimuth,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Solar_Azimuth;
+        specs[k].Solar_Azimuth=temp/100.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Solar_Azimuth=LocalBufr.Solar_Azimuth/100.;
+   }
+
+ GetNextBits(s4.lpData, 8,sizeof(LocalBufr.FOV_Number),&LocalBufr.FOV_Number,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.FOV_Number;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,24,sizeof(LocalBufr.Orbit_Number),&LocalBufr.Orbit_Number,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned long temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Orbit_Number;
+        specs[k].Orbit_Number=temp;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Orbit_Number=LocalBufr.Orbit_Number;
+   }
+
+ GetNextBits(s4.lpData,13,sizeof(LocalBufr.Scan_Line_Number),&LocalBufr.Scan_Line_Number,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Scan_Line_Number;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,8,sizeof(LocalBufr.Major_Frame_Count),&LocalBufr.Major_Frame_Count,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Major_Frame_Count;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData,15,sizeof(LocalBufr.Height_of_Station),&LocalBufr.Height_of_Station,false);  
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Height_of_Station;
+        specs[k].Height_of_Station=temp/10.-4.;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].Height_of_Station=LocalBufr.Height_of_Station/10.-4.;
+   }
+
+ GetNextBits(s4.lpData, 2,sizeof(LocalBufr.GQisFlagQual),&LocalBufr.GQisFlagQual,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.GQisFlagQual;
+        specs[k].QualFlag=temp;
+       }
+   }
+ else
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+        specs[k].QualFlag=LocalBufr.GQisFlagQual;
+   }
+
+ GetNextBits(s4.lpData, 7,sizeof(LocalBufr.QGisQualIndex),&LocalBufr.QGisQualIndex,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.QGisQualIndex;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData, 7,sizeof(LocalBufr.QGisQualIndexLoc),&LocalBufr.QGisQualIndexLoc,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.QGisQualIndexLoc;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData, 7,sizeof(LocalBufr.QGisQualIndexRad),&LocalBufr.QGisQualIndexRad,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.QGisQualIndexRad;
+       }
+   }
+ else
+   {
+   }
+ GetNextBits(s4.lpData, 7,sizeof(LocalBufr.QGisQualIndexSpect),&LocalBufr.QGisQualIndexSpect,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.QGisQualIndexSpect;
+       }
+   }
+ else
+   {
+   }
+ GetNextBits(s4.lpData,24,sizeof(LocalBufr.GQisQualIndexTexSondQual),&LocalBufr.GQisQualIndexTexSondQual,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned long temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.GQisQualIndexTexSondQual;
+       }
+   }
+ else
+   {
+   }
+
+ for (int i=0;i<10;++i)
+    {
+     GetNextBits(s4.lpData,14,sizeof(LocalBufr.Band_Description[i].Start_Channel),&LocalBufr.Band_Description[i].Start_Channel,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned short temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.Band_Description[i].Start_Channel;
+            LocalChannel[k*10+i].Start_Channel=temp;
+           }
+       }
+     else
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+            LocalChannel[k*10+i].Start_Channel=LocalBufr.Band_Description[i].Start_Channel;
+       }
+
+     GetNextBits(s4.lpData,14,sizeof(LocalBufr.Band_Description[i].End_Channel),&LocalBufr.Band_Description[i].End_Channel,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned short temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.Band_Description[i].End_Channel;
+            LocalChannel[k*10+i].End_Channel=temp;
+           }
+       }
+     else
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+            LocalChannel[k*10+i].End_Channel=LocalBufr.Band_Description[i].End_Channel;
+       }
+
+     GetNextBits(s4.lpData, 6,sizeof(LocalBufr.Band_Description[i].Channel_Scale_Factor),&LocalBufr.Band_Description[i].Channel_Scale_Factor,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned char temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.Band_Description[i].Channel_Scale_Factor;
+            LocalChannel[k*10+i].Channel_Scale_Factor=temp;
+           }
+       }
+     else
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+            LocalChannel[k*10+i].Channel_Scale_Factor=LocalBufr.Band_Description[i].Channel_Scale_Factor;
+       }
+    }
+
+ for (int i=0;i<87;++i)
+    {
+     for (int j=0;j<100;++j)
+        {
+         GetNextBits(s4.lpData,14,sizeof(LocalBufr.Channels_Sequence[i].Channel_Number[j]),&LocalBufr.Channels_Sequence[i].Channel_Number[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned short temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.Channels_Sequence[i].Channel_Number[j];
+               }
+           }
+         else
+           {
+           }
+         GetNextBits(s4.lpData,16,sizeof(LocalBufr.Channels_Sequence[i].Scaled_Iasi_Radiance[j]),&LocalBufr.Channels_Sequence[i].Scaled_Iasi_Radiance[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned short temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.Channels_Sequence[i].Scaled_Iasi_Radiance[j];
+                specs[k].Radiance[i*100+j]=temp-5000.;
+               }
+           }
+         else
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+                specs[k].Radiance[i*100+j]=LocalBufr.Channels_Sequence[i].Scaled_Iasi_Radiance[j]-5000.;
+           }
+        }
+    }
+
+
+ // Scale radiances...
+ for (long i=0;i<10;++i)
+    {
+     for (long k=0;k<s3.Number_Subsets;++k)
+        {
+         if (LocalChannel[k*10+i].Start_Channel<=8700)
+           {
+            for (long j=LocalChannel[k*10+i].Start_Channel-1;j<LocalChannel[k*10+i].End_Channel;++j)
+               {
+                specs[k].Radiance[j]*=pow(10.,-LocalChannel[k*10+i].Channel_Scale_Factor);
+               }
+           }
+        }
+    }
+
+ GetNextBits(s4.lpData,11,sizeof(LocalBufr.Satellite_Instruments_2),&LocalBufr.Satellite_Instruments_2,false); 
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned short temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.Satellite_Instruments_2;
+       }
+   }
+ else
+   {
+   }
+
+ GetNextBits(s4.lpData, 7,sizeof(LocalBufr.AVHRR_channel_combination),&LocalBufr.AVHRR_channel_combination,false);
+ // 1 bit per channel at most 6, 127 (0x7F) if absent.
+ GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+ if (NbBits>0)
+   {
+    for (long k=0;k<s3.Number_Subsets;++k)
+       {
+        unsigned char temp;
+        GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+        temp+=LocalBufr.AVHRR_channel_combination;
+       }
+   }
+ else
+   {
+   }
+
+ //Reset AVHRR Scenes
+ for (long k=0;k<s3.Number_Subsets;++k)
+    {
+     for (int i=0;i<6;++i) //  Pixels AVHRR
+        {
+         specs[k].Cloud_Free_Fraction[i]=-1.;
+         for (int j=0;j<7;++j)
+            {
+             specs[k].AVHRR_Mean[i][j]=-1.;
+             specs[k].AVHRR_Std[i][j]=-1.;
+            }
+        }
+    }
+
+ /* 
+   Now we have 7 AVHRR Scenes
+   Each of them contains 
+         - Y angular position        24 bits -8000000 *10^6  16777215    FFFFFF
+         - Z angular position        24 bits -8000000 *10^6  16777215    FFFFFF
+         - Fraction HIRS clear pixel  7 bits                      127        7F 
+         - 6 Channels 
+           with  - Channel Number     6 bits                       63        3F
+                 - Scale Factor       6 bits                       63        3F
+                 - Mean Radiance     31 bits               2147483647  7FFFFFFF
+                 - Scale Factor       6 bits                       63        3F
+                 - StDev Radiance    31 bits               2147483647  7FFFFFFF
+ */ 
+
+ for (int i=0;i<7;++i) //  AVHRR Scenes
+    {
+     GetNextBits(s4.lpData,24,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Y_angular_position),&LocalBufr.AVHRR_Scene_Sequence[i].Y_angular_position,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>24)
+       {
+        return FALSE;
+       }
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned long temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.AVHRR_Scene_Sequence[i].Y_angular_position;
+           }
+       }
+     else
+       {
+       }
+
+     GetNextBits(s4.lpData,24,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Z_angular_position),&LocalBufr.AVHRR_Scene_Sequence[i].Z_angular_position,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>24)
+       {
+        return FALSE;
+       }
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned long temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.AVHRR_Scene_Sequence[i].Z_angular_position;
+           }
+       }
+     else
+       {
+       }
+
+     GetNextBits(s4.lpData, 7,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Fraction_clear_pixels_HIRS),&LocalBufr.AVHRR_Scene_Sequence[i].Fraction_clear_pixels_HIRS,false); 
+     GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+     if (NbBits>7)
+       {
+        return FALSE;
+       }
+     if (NbBits>0)
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            unsigned char temp;
+            GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+            temp+=LocalBufr.AVHRR_Scene_Sequence[i].Fraction_clear_pixels_HIRS;
+            specs[k].Cloud_Free_Fraction [i]=(double)temp;
+           }
+       }
+     else
+       {
+        for (long k=0;k<s3.Number_Subsets;++k)
+           {
+            specs[k].Cloud_Free_Fraction[i]=(double)LocalBufr.AVHRR_Scene_Sequence[i].Fraction_clear_pixels_HIRS;
+           }
+       }
+
+     for (int j=0;j<6;++j) // Channels
+        {
+         GetNextBits(s4.lpData, 6,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Channel_Number[j]),&LocalBufr.AVHRR_Scene_Sequence[i].Channel_Number[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>6)
+           {
+            return FALSE;
+           }
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned char temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.AVHRR_Scene_Sequence[i].Channel_Number[j];
+           }
+           }
+         else
+           {
+           }
+
+         GetNextBits(s4.lpData, 6,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_1[j]),&LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_1[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>6)
+           {
+            return FALSE;
+           }
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned char temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_1[j];
+                specs[k].AVHRR_Mean[j][i]=pow(10.,-temp);
+               }
+           }
+         else
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                specs[k].AVHRR_Mean[j][i]=pow(10.,-LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_1[j]);
+               }
+           }
+
+         GetNextBits(s4.lpData,31,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Mean_AVHRR_Rad[j]),&LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Mean_AVHRR_Rad[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>31)
+           {
+            return FALSE;
+           }
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned long temp;                
+                GetNextBits(s4.lpData,NbBits,4,&temp,false);
+                temp+=LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Mean_AVHRR_Rad[j];
+                specs[k].AVHRR_Mean[j][i]=specs[k].AVHRR_Mean[j][i]*(double)temp;
+               }
+           }
+         else
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                specs[k].AVHRR_Mean[j][i]*=LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Mean_AVHRR_Rad[j];
+               }
+           }
+
+         GetNextBits(s4.lpData, 6,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_2[j]),&LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_2[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>6)
+           {
+            return FALSE;
+           }
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned char temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_2[j];
+                specs[k].AVHRR_Std[j][i]=pow(10.,-temp);
+               }
+           }
+         else
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+                specs[k].AVHRR_Std[j][i]=pow(10.,-LocalBufr.AVHRR_Scene_Sequence[i].Channel_Scale_Factor_2[j]);
+           }
+
+         GetNextBits(s4.lpData,31,sizeof(LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Std_AVHRR_Rad[j]),&LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Std_AVHRR_Rad[j],false); 
+         GetNextBits(s4.lpData,6,sizeof(NbBits),&NbBits,false);
+         if (NbBits>31)
+           {
+            return FALSE;
+           }
+         if (NbBits>0)
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+               {
+                unsigned long temp;
+                GetNextBits(s4.lpData,NbBits,sizeof(temp),&temp,false);
+                temp+=LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Std_AVHRR_Rad[j];
+                specs[k].AVHRR_Std[j][i]*=temp;
+               }
+           }
+         else
+           {
+            for (long k=0;k<s3.Number_Subsets;++k)
+                specs[k].AVHRR_Std[j][i]*=LocalBufr.AVHRR_Scene_Sequence[i].Scaled_Std_AVHRR_Rad[j];
+           }
+
+        }
+    }
+ return TRUE;
+}
Index: /ether_iasi_L1C/trunk/build.sh
===================================================================
--- /ether_iasi_L1C/trunk/build.sh	(revision 27)
+++ /ether_iasi_L1C/trunk/build.sh	(revision 27)
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+g++ -m32 bufr.cpp -o bufr
Index: /ether_iasi_L1C/trunk/conf.txt
===================================================================
--- /ether_iasi_L1C/trunk/conf.txt	(revision 27)
+++ /ether_iasi_L1C/trunk/conf.txt	(revision 27)
@@ -0,0 +1,7 @@
+PATH_PROG=/data/sva/iasi_l1c/bin
+PATH_LOGS=/data/sva/iasi_l1c/logs
+PATH_Orbiasi_l1b=/data/sva/IASI_dev/lmd/New_version_v0.0/Data
+PATH_SUN_WEB_SERVICES=/data/sva/space/ether/services
+PATH_TEMP=/data/sva/iasi_l1c/temp
+PATH_RES=/doc/space/ether/users
+WEB_SERVER=www@davis
Index: /ether_iasi_L1C/trunk/create_uproc.sh
===================================================================
--- /ether_iasi_L1C/trunk/create_uproc.sh	(revision 27)
+++ /ether_iasi_L1C/trunk/create_uproc.sh	(revision 27)
@@ -0,0 +1,171 @@
+#!/bin/sh
+
+Loginu=$1
+Date=$2
+Mailu=$3
+Mot_iasi=$4
+Sat=$5
+Lati=$6
+Long=$7
+Indtm=$8
+Indjn=$9
+
+
+cd ${@:10:1} 
+
+conf_file="conf.txt"
+while read line
+do
+        ll=${#line}
+
+        if [[ -n $(echo $line | grep PATH_PROG) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_PROG=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_LOGS) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_LOGS=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_SUN_WEB_SERVICES) ]] ; then
+                chem=`expr $ll - 23`
+                temp=`echo $line | cut -c23-$ll`
+                PATH_SUN_WEB_SERVICES=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_Orbiasi_l1b) ]] ; then
+                chem=`expr $ll - 18`
+                temp=`echo $line | cut -c18-$ll`
+                PATH_Orbiasi_l1b=$temp
+        fi
+	if [[ -n $(echo $line | grep PATH_TEMP) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_TEMP=$temp
+        fi
+	if [[ -n $(echo $line | grep PATH_RES) ]] ; then
+                chem=`expr $ll - 10`
+                temp=`echo $line | cut -c10-$ll`
+                PATH_RES=$temp
+        fi
+	if [[ -n $(echo $line | grep WEB_SERVER) ]] ; then
+                chem=`expr $ll - 12`
+                temp=`echo $line | cut -c12-$ll`
+                WEB_SERVER=$temp
+        fi
+	
+
+
+
+
+done < $conf_file
+
+
+echo "PATH_LOGS=$PATH_LOGS"
+echo "PATH_PROG=$PATH_PROG"
+echo "PATH_Orbiasi_l1b=$PATH_Orbiasi_l1b"
+echo "PATH_TEMP=$PATH_TEMP"
+echo "PATH_RES=$PATH_RES"
+echo "WEB_SERVER=$WEB_SERVER"
+
+DATE=$(date +%Y%m%d-%H%M)
+
+file_logs="$PATH_LOGS/iasi_l1c_user_request_$Loginu_$DATE.txt"
+
+echo "Start user request treatment" >> $file_logs 
+echo "Creation of user tempory rep" >> $file_logs 
+
+cd $PATH_PROG
+./create_repu -l $Loginu -d $DATE -logs $file_logs
+sleep 1
+cd $PATH_TEMP/$Loginu/Order_$DATE
+echo $Loginu > requete.txt
+echo $Mailu >> requete.txt
+echo $Date >> requete.txt
+echo $Mot_iasi >> requete.txt
+echo $Sat >> requete.txt
+echo $Lati >> requete.txt
+echo $Long >> requete.txt
+echo $Indtm >> requete.txt
+echo $Indjn >> requete.txt
+
+if [ $Indtm -eq 0 ]; then
+	tIndtm="Sea"
+fi
+if [ $Indtm -eq 1 ]; then
+	tIndtm="Land"
+fi
+if [ $Indtm -eq 2 ];
+then
+	tIndtm="Land and sea"
+fi
+
+if [ $Indjn -eq 0 ]; then
+        tIndjn="Night"
+fi
+if [ $Indjn -eq 1 ]; then
+        tIndjn="Day"
+fi
+if [ $Indjn -eq 2 ]; then
+        tIndjn="Night and day"
+fi
+
+
+echo "Copy of user request parameters in $PATH_TEMP/$Loginu/Order_$DATE/request.txt" >> $file_logs 
+
+echo $PATH_TEMP/$Loginu/Order_$DATE >> requete.txt
+echo $DATE >> requete.txt
+
+cp requete.txt $PATH_PROG
+chmod 755 requete.txt
+
+echo "Request process" >> $file_logs
+cp $PATH_PROG/treat_request.sh . 
+cp $PATH_PROG/conf.txt . 
+
+./treat_request.sh -f requete.txt -logs $file_logs
+
+var=$?
+
+if [ $var -eq 0 ]; then
+	ssh $WEB_SERVER "mkdir $PATH_RES/$Loginu/Order_$DATE ; chmod 755 $PATH_RES/$Loginu/Order_$DATE"
+	scp $PATH_TEMP/IASI_mots_all_spots_$Loginu_$DATE* $WEB_SERVER:$PATH_RES/$Loginu/Order_$DATE
+
+        echo "The result of your request is in the repository Order_$DATE in your user space.
+
+Date range : $Date
+Channels : $Mot_iasi
+Latitude range : $Lati
+Longitude range : $Long
+Land/sea index : $tIndtm
+Night/day index : $tIndjn
+
+Le service Ether" > $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+	$PATH_PROG/mailu $Mailu $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+	/bin/rm $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+	/bin/rm $PATH_TEMP/IASI_mots_all_spots_$Loginu_$DATE*
+	/bin/rm -R $PATH_TEMP/$Loginu/Order_$DATE
+
+else
+	echo "Your request Order_$DATE has no result. 
+
+Date range : $Date
+Channels : $Mot_iasi
+Latitude range : $Lati
+Longitude range : $Long
+Land/sea index : $tIndtm 
+Night/day index : $tIndjn
+
+Ether service
+" > $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+	$PATH_PROG/mailu $Mailu $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+        /bin/rm $PATH_TEMP/mail_retour_$Loginu_$DATE.txt
+fi
+
+echo "var=$var"
+
+exit $var
+
+
+
+
Index: /ether_iasi_L1C/trunk/extract_iasi_words_all_spots.f90
===================================================================
--- /ether_iasi_L1C/trunk/extract_iasi_words_all_spots.f90	(revision 27)
+++ /ether_iasi_L1C/trunk/extract_iasi_words_all_spots.f90	(revision 27)
@@ -0,0 +1,359 @@
+!------------------------------------------------
+! extract_iii
+!
+! Usage:
+!  extract_iii FlagCarto FlagHeader Lati Long DataFile ResuFile Mot1 ... MotN
+!
+!  FlagCarto  = 'TRUE'/'false' = genere des sorties au format carto
+!  FlagHeader = 'TRUE'/'false' = genere un header pour DataFile
+!  Lati       = bornes en latitude (latmin,latmax)
+!  Long       = bornes en longitude (lonmin,lonmax)
+!  Indtm      = indice terre/mer (0=mer,1=terre, 2=mer+terre)
+!  Indjn      = indice jour+nuit (0=nuit,1=jour, 2=nuit+jour)
+!  DataFile   = fichier contenant la liste des donnees
+!  ResuFile   = fichier resultat (longueur=9!!!)
+!  Mot1...N   = entiers designant le mot a extraire
+!
+! Creation :
+! 12/11/2003 - O.Maury
+!------------------------------------------------
+! Modifications :
+! 24/11/2003 - O.Maury : 
+!   - ajout d'un header a ResuFile
+!   - ajout des mots par defaut
+!   - ajout sorties carto (ResuFile_III-*)
+! 25/11/2003 - O.Maury : 
+!   - ajout de la date dans mots par defaut (228)
+! 26/11/2003 - O.Maury
+!   - correction date : lue dans le header (228)
+! 03/12/2003 - R. Armante
+!   - passage des coordonnees d'une zone geographique
+!     par defaut, -90,90 en latitude et -180,180 en longitude
+!   - choix de l'indice terre/mer (terre+mer par defaut)
+!   - choix de l'indice jour/nuit (jour/nuit par defaut)
+!   - correction bug sur la date : lorsque l'on ecrit la date sous la forme
+!     ddmmyyyy, on depasse la precision de la machine sur le nombre de chiffre
+!     apres la virgule sur les flottants. 
+!     ==> correction en ramenant la date sous la forme ddmmyy
+!------------------------------------------------
+! Definition des  variables
+!
+      PARAMETER (Nbval_Header=8,npt_iasi=8461)
+      CHARACTER DataFile*50,ResuFile*9
+
+      INTEGER MotDefaut(Nbval_Header)
+      INTEGER MotDesire(500)
+      INTEGER IndiceMot(500)
+
+      LOGICAL DateIdentique
+
+      REAL*4 ValeurMot(500),Corrige(500)
+      REAL Latmin,Latmax,Lonmin,Lonmax
+      REAL Indice_tm,Indice_jn
+      real cor_ang(324,13),ang_zen(13)
+      data ang_zen/00.00,05.72,09.19,12.93,16.69,20.41,24.04,27.85,31.67,35.28,39.18,43.47,47.14/
+
+      CHARACTER*5 FlagCarto
+      CHARACTER*5 FlagHeader
+      CHARACTER*20 Lati,Longi
+      CHARACTER*4 arg
+      CHARACTER*3 extract
+      CHARACTER*8 Suff
+      CHARACTER*15 carac
+
+! 29 = latitude (°)
+! 30 = longitude (°)
+! 31 = local zenith angle for the box (°)
+! 35 = surface elevation (m)
+! 36 = identification of cloud test
+! 37 = time (hhmmss)
+! 39 = land/sea + day/night flag
+! 228 ou 230 (du header)= date du spot (ddmmyy)
+! Rq: le mot 228 est celui du header, pas des donnees
+      DATA MotDefaut /0,0,0,0,0,0,0,0/
+!     DATA MotDefaut /29,30,31,35,36,37,39,228/
+! Declaration partie Airs
+INTEGER,PARAMETER :: NCHANNELMAXIASI=8461,NCHANNELMAXAMSU=15
+INTEGER  yy,mm,dd,hh,mn,ss,yyyymmd,hhmnss
+
+REAL IASI_Time,IASI_Latitude,IASI_Longitude, &
+     IASI_Satellite_Zenith,IASI_Solar_Zenith,Cloud_Cover
+INTEGER Land_Sea_Alti
+REAL ,DIMENSION(NCHANNELMAXIASI) :: IASI_Radiances
+REAL*8  date_iasi
+integer Orbit_number
+character*4 IASI_Quality_Flag
+
+REAL ,DIMENSION(NCHANNELMAXAMSU) :: AMSU_BT
+REAL  AMSU_Quality_Flag
+
+      CHARACTER*100 Nom_buffer !nom du fichier buffer à lire
+      CHARACTER*100 SORTIE !sortie ascii
+      CHARACTER*5 process !nom de l'action à effectuer : NCEP,Prcom,STRAT,DAO
+      CHARACTER*3 CGRANULE,CJOUR
+      CHARACTER*2 CHEUREDEB,CHEUREFIN,CMINDEB,CMINFIN,CANNEE
+      CHARACTER*40 PREFIXE,SUFFIXE,PATH_DATA
+      INTEGER Ngranule,ANNEE,HEUREDEB,MINDEB,HEUREFIN,MINFIN,JOUR
+      real freq_iasi(8461),tb_hs(8461)
+!**Test ciel clair**
+      integer test_ciel_clair, couv_nuage
+!**Test terre/mer**
+      integer*4 indtermer(2160,1080),flagtermer,terre_mer,inittm,iunittm
+      character*200 nomfichtermer
+
+      INTEGER ii
+
+      include 'iasidatafile.h'
+! definition des canaux HS
+      do i=1,npt_iasi
+         tb_hs(i)=0
+      enddo
+! canaux 128 et 263 morts a partir de mars 2003
+!     tb_hs(116)=1.
+      do i=1,npt_iasi
+         if(tb_hs(i).eq.1) write(*,*)'canal',i, &
+         ' HS ==> flag quality pas pris en compte'
+      enddo
+!***Lecture des frequences des canaux***
+      do i=1, NCHANNELMAXIASI
+         freq_iasi(i)=645.+(i-1)*0.25
+      enddo
+
+!***Terre/mer***
+      nomfichtermer=trim(racine_iasidata)//'/land_sea_alti_map.dat'
+      inittm = 0
+      iunittm = 1
+!*CHARGEMENT DE LA BANQUE TERRE/MER DANS LE TABLEAU indtermer*
+      CALL sub_land_sea_alti(0.,0.,inittm,terre_mer,iunittm   &
+                          ,indtermer,nomfichtermer)
+!*DRAPEAU D'UTILISATION DE LA BANQUE TERRE/MER*
+      inittm = 1
+
+!***Test ciel clair***
+!     test_ciel_clair=couv_nuage   &
+!              (0,AIRS_Radiances,AMSU_BT   &
+!              ,1,1,freq_airs,0)
+      cloud_cover=-1.
+
+!------------------------------------------------
+! Lecture arguments (pas de test)
+!
+      CALL getarg(1,FlagCarto)
+      CALL getarg(2,FlagHeader)
+      CALL getarg(3,Lati)
+      CALL getarg(4,Longi)
+      CALL getarg(5,arg)
+      read(arg,*) Indice_tm
+      CALL getarg(6,arg)
+      read(arg,*) Indice_jn
+      CALL getarg(7,DataFile)
+      CALL getarg(8,ResuFile)
+
+      IFIN = iargc()
+      NbrDesire = IFIN-8
+      DO ind = 9,IFIN
+         CALL getarg(ind,arg)
+         read (arg,*) Mot
+         MotDesire(ind-8)=Mot
+      END DO
+  
+!      print *,FlagCarto
+!      print *,FlagHeader
+!      print *,DataFile
+!      print *,ResuFile
+!      print *,NbrDesire
+       do indi=1,len(Lati)
+          if(Lati(indi:indi).eq.',') Ind_lati=indi
+       enddo
+       do indi=1,len(Longi)
+          if(Longi(indi:indi).eq.',') Ind_long=indi
+       enddo
+       read(Lati(1:Ind_lati-1),*) Latmin
+       read(Lati(Ind_lati+1:len(Lati)),*) Latmax
+       read(Longi(1:Ind_long-1),*) Lonmin
+       read(Longi(Ind_long+1:len(Longi)),*) Lonmax
+    
+!------------------------------------------------
+! Ajout mots par defaut
+!
+      DO ii=1,Nbval_Header
+         IndiceMot(ii)=MotDefaut(ii)
+      END DO
+      DO jj=1,NbrDesire
+         ii=jj+Nbval_Header
+         IndiceMot(ii)=MotDesire(jj)
+      END DO
+      NbrMots = NbrDesire+Nbval_Header
+
+!      print *,NbrMots
+!      print *,IndiceMot
+
+!------------------------------------------------
+! Ouverture des fichiers
+!
+      close(11)
+      open(unit=10, file = DataFile)
+      open(unit=20, file = ResuFile, form='unformatted')
+      open(599,file='fort.599',form='unformatted')
+! Option Carto ?
+      IF (FlagCarto .eq. 'TRUE') THEN
+         DO iCarto=1,NbrDesire
+            write(Suff,FMT='(A5,I3.3)') '_III-',MotDesire(iCarto)
+            open(unit=(40+iCarto), file = ResuFile // Suff, &
+                 form='unformatted')
+         END DO
+      END IF         
+
+!------------------------------------------------
+! Ecriture du header
+!
+      IF (FlagHeader .eq. 'TRUE') THEN
+!         print *, NbrMots,(IndiceMot(ind),ind=1,NbrMots)
+         WRITE (20) NbrMots,(IndiceMot(ind),ind=1,NbrMots)
+         WRITE (*,*) 'Header',NbrMots,(IndiceMot(ind),ind=1,NbrMots)
+      END IF
+
+!================================================
+! Debut boucle sur les fichiers de donnees
+!================================================
+ 5    CONTINUE
+!------------------------------------------------
+! Lit le nom du fichier courrant puis l'ouvre 
+!
+      read(10,'(a100)', END = 15) Nom_buffer
+!lecture iasi bufr
+      open(1111,file=Nom_buffer,form='formatted')
+          read(1111,*)
+          read(1111,*)
+          read(1111,*)
+          read(1111,*) date_iasi
+          yyyymmdd=int(date_iasi)
+          hhmnss=int((date_iasi-yyyymmdd*1.)*1000000.)
+          write(*,*) date_iasi,hhmnss
+          read(1111,*) Orbit_number
+          read(1111,*) IASI_Quality_Flag
+          if(IASI_Quality_Flag.ne.'good') then
+             close(1111)
+             goto 5
+          endif
+          read(1111,*) Rlat
+          read(1111,*) Rlon
+          read(1111,*) IASI_Satellite_Zenith
+          read(1111,*) IASI_Satellite_Azimuth
+          read(1111,*) IASI_Solar_Zenith
+          read(1111,*) IASI_Solar_Azimuth
+          read(1111,*) IASI_Satellite_Alt
+          read(1111,*) IASI_Cloud_Free
+! skip avhrr informations
+          do i=1,18
+             read(1111,*)
+          enddo
+          read(1111,*) wavenb_deb
+          read(1111,*) wavenb_fin
+          read(1111,*) 
+          read(1111,*) 
+          do i=1,npt_iasi
+             read(1111,*) IASI_Radiances(i)
+          enddo
+       close(1111)
+
+       nbatm_tot=0
+       nbatm_clear=0
+!      DO I=1,number_of_golf_balls
+          extract='oui'
+          CALL sub_land_sea_alti(IASI_Latitude,IASI_Longitude   &
+                 ,inittm,Land_Sea_Alti,iunittm,indtermer,nomfichtermer)
+            indtm=0
+            if(Land_Sea_Alti.ge.0) indtm=1
+!          cloud_cover=couv_nuage(1,IASI_Radiances,AMSU_BT   &
+!                   ,I,J,freq_airs,indtm)
+!          if(cloud_cover.ne.0) extract='non'
+          Do j=1,NbrMots+1
+             ValeurMot(j)=0.
+          Enddo
+! determination de l'angle le plus proche
+          angmin=99.99
+          do iiang=1,13
+             dist=abs(IASI_Satellite_Zenith-ang_zen(iiang))
+             if(dist.lt.angmin) then
+                 angmin=dist
+                 iiangmin=iiang
+             endif
+          enddo
+!         Do J=1,IASI_FOVS
+         if(Rlat.lt.Latmin.or.Rlat.gt.Latmax) extract='non'
+         if(Rlon.lt.Lonmin.or.Rlon.gt.Lonmax) extract='non'
+          if(extract.eq.'oui') then
+          indtm=0
+          if(Land_Sea_Alti.ge.0) indtm=1
+          endif
+          indjn=1
+          if(IASI_Solar_Zenith.ge.90) indjn=0
+         if(indtm.ne.Indice_tm.and.Indice_tm.ne.2) extract='non'
+         if(indjn.ne.Indice_jn.and.Indice_jn.ne.2) extract='non'
+         if(extract.eq.'oui') then
+          ValeurMot(1)=Rlat
+          ValeurMot(2)=Rlon
+          ValeurMot(3)=IASI_Satellite_Zenith
+          ValeurMot(4)=Land_Sea_Alti
+          ValeurMot(5)=cloud_cover
+!         call seconds_to_calender(dble(IASI_Time/1000.),yy,mm,dd,hh,mn,ss)
+          ValeurMot(6)=hhmnss
+          ValeurMot(7)=float(indtm*10+indjn)
+          ValeurMot(8)=yyyymmdd
+          DO ind = 1, NbrDesire
+        if(tb_hs(MotDesire(ind)).ne.1.and.IASI_Quality_Flag.ne.'good') &
+           write(*,*) MotDesire(ind),IASI_Quality_Flag
+            if(MotDesire(ind).le.npt_iasi.and.IASI_Quality_Flag.ne.'good') extract='non'
+            if(MotDesire(ind).le.npt_iasi.and.IASI_Quality_Flag.eq.'good') then
+!              ValeurMot(Nbval_Header+ind)= IASI_Radiances(MotDesire(ind))
+               ValeurMot(Nbval_Header+ind)=tbrillans(freq_iasi(MotDesire(ind)), &
+                        1e02*IASI_Radiances(MotDesire(ind)))
+            endif
+!           if(MotDesire(ind).gt.npt_iasi.and.AMSU_Quality_Flag(MotDesire(ind)-npt_iasi,1,I).ne.0) extract='non'
+!           if(MotDesire(ind).gt.npt_iasi.and.AMSU_Quality_Flag(MotDesire(ind)-npt_iasi,1,I).eq.0) &
+!              ValeurMot(Nbval_Header+ind)=AMSU_BT(MotDesire(ind)-npt_iasi,1,I) 
+!           endif
+          END DO
+        ValeurMot(NbrMots+1)=IASI_Solar_Zenith
+
+          nbatm_tot=nbatm_tot+1
+         if(extract.eq.'oui') then
+            nbatm_clear=nbatm_clear+1
+            WRITE (20) (ValeurMot(ind),ind=1,NbrMots+1),Orbit_number
+         endif
+
+!        WRITE (20) (ValeurMot(ind),ind=1,NbrMots+1)
+! Option Carto ?
+         IF (FlagCarto .eq. 'TRUE') THEN
+            DO iCarto=1,NbrDesire
+               write(40+iCarto) ValeurMot(1),ValeurMot(2), &
+                    ValeurMot(iCarto+Nbval_Header)
+            END DO
+         END IF
+         end if
+       write(*,*) 'Nb clear',nbatm_clear,nbatm_tot
+
+!================================================
+! Fin boucle
+!================================================
+      GO TO 5
+ 15   CONTINUE
+
+!------------------------------------------------
+! Fermeture des fichiers
+!
+      close (10)
+      close (20)
+
+      IF (FlagCarto .eq. 'TRUE') THEN
+         DO iCarto=1,NbrDesire
+            close(40+iCarto)
+         END DO
+      END IF
+!------------------------------------------------
+! FIN PROGRAM extract_iii
+!
+! 777  CONTINUE
+
+      END
Index: /ether_iasi_L1C/trunk/iasidatafile.h
===================================================================
--- /ether_iasi_L1C/trunk/iasidatafile.h	(revision 27)
+++ /ether_iasi_L1C/trunk/iasidatafile.h	(revision 27)
@@ -0,0 +1,2 @@
+      character*250 racine_iasidata
+      racine_iasidata='/data/sva/IASI_dev/lmd/New_version_v0.0/Data_in'
Index: /ether_iasi_L1C/trunk/lec_extract_iasi.f
===================================================================
--- /ether_iasi_L1C/trunk/lec_extract_iasi.f	(revision 27)
+++ /ether_iasi_L1C/trunk/lec_extract_iasi.f	(revision 27)
@@ -0,0 +1,47 @@
+      program elc
+c         Header(1)=Rlat
+c         Header(2)=Rlon
+c         Header(3)=IASI_Satellite_Zenith(J,I)
+c         Header(4)=Land_Sea_Alti(J,I)
+c         Header(5)=cloud_cover(J,I)
+c         Header(6)=hh*1.e4+mn*1.e2+ss
+c         Header(7)=float(indtm*10+indjn)
+c         Header(8)=yyyymmdd
+      real head(8),mots(339)
+      real ang_sol,norb
+      integer indi(339)
+      character*200 filein
+c header : rlat,rlon,angle_zen,
+      call getarg(1,filein)
+      open(1,file=filein,form='unformatted')
+      read(1) nbmots,(indi(i),i=1,nbmots)
+       print *,'nbmots',nbmots,(indi(i),i=1,nbmots)
+
+! nbre de temperatures de brillance extraites = nbmots - nbre mots header - angle solaire - numero orbite
+      nb_TBs=nbmots-8-2
+      write(*,*) nb_TBs
+      icpt=0
+      ic=0
+      imn=0
+      imj=0
+      itn=0
+      itj=0
+! ixx calcule le nombre de points dans 4 classes combinant les indices terre/mer/jour/nuit
+* xx=mn pour mer/nuit
+ 10   read(1,end=100) head,(mots(i),i=1,nb_TBs),ang_sol,norb
+	print * ,"head=",nb_TBs
+      sectta=1./cosd(head(3))
+      !write(*,1) head(1),head(6),head(8),mots(1),ang_sol,int(norb)
+1     format(f8.2,2f10.0,2f8.2,i7)
+      if(head(7).eq.0) imn=imn+1
+      if(head(7).eq.1) imj=imj+1
+      if(head(7).eq.10) itn=itn+1
+      if(head(7).eq.11) itj=itj+1
+      icpt=icpt+1
+      ic=ic+1
+      goto 10
+ 100  continue
+ 14    format(8f11.3,2i4)
+ 15    format(3f11.3,2i4)
+       print *,icpt,imn,imj,itn,itj
+      end
Index: /ether_iasi_L1C/trunk/requete.txt
===================================================================
--- /ether_iasi_L1C/trunk/requete.txt	(revision 27)
+++ /ether_iasi_L1C/trunk/requete.txt	(revision 27)
@@ -0,0 +1,11 @@
+girod
+francoise.girod@cnes.fr
+07060900,07060900
+100-110
+metop
+46,90
+-180,180
+2
+2
+/data/sva/iasi_l1c/temp/girod/Order_20070904-2127
+20070904-2127
Index: /ether_iasi_L1C/trunk/sub_land_sea_alti.f
===================================================================
--- /ether_iasi_L1C/trunk/sub_land_sea_alti.f	(revision 27)
+++ /ether_iasi_L1C/trunk/sub_land_sea_alti.f	(revision 27)
@@ -0,0 +1,58 @@
+      subroutine sub_land_sea_alti(alat,alon,init,flagtermer,iunittm
+     &                         ,indtermer,nomfichtermer)
+C*****************************************************************
+C
+C PROCEDURE DE LECTURE ET DE DECODAGE DE L'INDICE TERRE/MER
+C (RESOLUTION = 1/6 DEGRE DE 90N A 90S DE LATITUDE ET DE
+C 0 a 360 DEGRES DE LONGITUDE).
+C ON A UN ENREGISTREMENT PAR LATITUDE (1080 ENREGISTREMENTS).
+C POUR CHAQUE LATITUDE, ON A 2160 LONGITUDES DIFFERENTES QUI SONT CODEES
+C SUR 72 INTEGER*4 (SOIT LES 30 PREMIERS BITS UTILISES DE CHAQUE ENTIER).
+C LE BIT EST MIS A 1 LORSQUE L'ON EST SUR MER.
+C
+C*****************************************************************
+C Declaration A rajouter dans le programme principal
+      real alat,alon
+      integer*4 indtermer(2160,1080),flagtermer,init,iunittm
+      character*200 nomfichtermer
+C Fin **********************************************
+      integer*2 nb_lon,indi_relief(2160),alti_relief(2160)
+
+C *** INIT=0 : LECTURE DES 72*1080 INTEGER*4 DANS LE FICHIER 
+C *** nomfichtermer D'UNITE LOGIQUE iunittm
+      if(init.eq.0) then
+        open(iunittm,file=nomfichtermer,form='unformatted')
+         do ilat=1,1080
+            do ilon=1,2160
+               indtermer(ilon,ilat)=-1
+            enddo
+            read(1)nb_lon,(indi_relief(ilon)
+     &                    ,alti_relief(ilon),ilon=1,nb_lon)
+            do ilon=1,nb_lon
+               indtermer(indi_relief(ilon),ilat)=alti_relief(ilon)
+      if(alti_relief(ilon).eq.-30) write(*,*) ilon,ilat
+            enddo
+         enddo
+         close(iunittm)
+       else
+
+C *** UNIT = 1 : RECHERCHE ET DECODAGE DE L'INTEGER*4 QUI CONTIENT
+C *** L'INDICE TERRE/MER POUR LA LATITUDE alat ET LA LONGITUDE alon
+C *** ILAT = NUMERO DU RECORD A LIRE DANS LE FICHIER EN ACCES DIRECT
+C *** ILON = INDICE DE 1 A 2160 POUR LA LONGITUDE
+C *** INDMOT = NUMERO DE L'INTEGER*4 DANS LE TABLEAU indtermer
+C *** NUMBIT = NUMERO DU BIT A RETENIR POUR AVOIR L'INDICE TERRE/MER
+C ***          CORRESPONDANT A alat ET alon
+         ilat=int((90.+1./12.-alat)*6.+0.5)
+         if(ilat.le.0) ilat=1
+         if(ilat.gt.1080) ilat=1080
+         ilon=int(alon*6.+0.5)
+         if(alon.lt.0) ilon=int((alon+360.)*6.+0.5)
+         if(ilon.le.0) ilon=1
+         flagtermer=indtermer(ilon,ilat)
+         if(ilat.le.0.or.ilat.gt.1080)
+     &   write(*,*) alat,ilat,alon,ilon,indmot,numbit,
+     &               indtermer(ilon,ilat)
+       endif
+       return
+       end
Index: /ether_iasi_L1C/trunk/tbrillans.f
===================================================================
--- /ether_iasi_L1C/trunk/tbrillans.f	(revision 27)
+++ /ether_iasi_L1C/trunk/tbrillans.f	(revision 27)
@@ -0,0 +1,19 @@
+!************************************************************
+!***Calcul des Tb a partir des B***
+
+      FUNCTION tbrillans(nu,b)
+!    nu en cm-1 t en Kelvin  b en Watt / ( m2 strd cm-1 )
+!    c en m/s  h en J.s  k en J/K
+      real nu,nu0,tbrillans,b
+      real c,h,k
+      c=2.998e+08
+      k=1.381e-23
+      h=6.6262e-34
+      scale=100
+      nu0=nu*scale
+!      planck=scale*2.*h*c**2*nu0**3/(exp(h*c/k*nu0/t)-1)
+      tbrillans=h*c/k*nu0/log((scale*2.*h*c**2*nu0**3/b)+1)
+      return
+
+      END
+
Index: /ether_iasi_L1C/trunk/treat_request.sh
===================================================================
--- /ether_iasi_L1C/trunk/treat_request.sh	(revision 27)
+++ /ether_iasi_L1C/trunk/treat_request.sh	(revision 27)
@@ -0,0 +1,77 @@
+#!/bin/ksh
+
+#PATH_PROG="/data/sva/iasi_l1c/bin"
+#PATH_LOGS="/data/sva/iasi_l1c/logs"
+
+typeset -i NbrOptionOblig=0
+while [ $# -ge 1 ]
+do
+  case $1 in
+    -f) shift 1;file="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
+    -logs) shift 1;file_logs="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));;
+    *) print '' $1 'is not an option';exit 1;;
+  esac
+  shift 1
+done
+
+if [ $NbrOptionOblig -ne 2 ]; then
+  echo $*
+  echo "USAGE : -f <file_name> -logs <file_logs>"
+  exit 1
+fi
+
+
+conf_file="conf.txt"
+while read line
+do
+        ll=${#line}
+
+        if [[ -n $(echo $line | grep PATH_PROG) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_PROG=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_LOGS) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_LOGS=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_SUN_WEB_SERVICES) ]] ; then
+                chem=`expr $ll - 23`
+                temp=`echo $line | cut -c23-$ll`
+                PATH_SUN_WEB_SERVICES=$temp
+        fi
+        if [[ -n $(echo $line | grep PATH_Orbiasi_l1b) ]] ; then
+                chem=`expr $ll - 18`
+                temp=`echo $line | cut -c18-$ll`
+                PATH_Orbiasi_l1b=$temp
+        fi
+	if [[ -n $(echo $line | grep PATH_TEMP) ]] ; then
+                chem=`expr $ll - 11`
+                temp=`echo $line | cut -c11-$ll`
+                PATH_TEMP=$temp
+        fi
+	
+
+done < $conf_file
+
+
+ind=0
+while read line
+do
+	ind=$((ind+1))	 
+	param[$ind]="$line"
+done < $file 
+
+
+$PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 -d ${param[3]} -s ${param[5]} -iasi ${param[4]} -lat ${param[6]} -lon ${param[7]} -idtm ${param[8]} -idjn ${param[9]} -rd ${param[10]} -logs $file_logs -req ${param[11]}_${param[1]}
+
+var=$?
+
+echo "PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 executing ... " >> $file_logs 
+echo "$PATH_PROG/IASI_mot_2004_l1b_all_spots_V1.0 -d ${param[3]} -s ${param[5]} -iasi ${param[4]} -lat ${param[6]} -lon ${param[7]} -idtm ${param[8]} -idjn ${param[9]} -rd ${param[10]} -logs $file_logs -req ${param[11]}_${param[1]}" >> $file_logs
+
+exit $var
+
+
+
