#!/bin/ksh

#parametres en entree

typeset -i NbrOptionOblig=0
typeset -i nbfiles=0
while [ $# -ge 1 ]
do
  case $1 in
    -y) shift 1;annee="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #annee traitee
    -s) shift 1;suf="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #suffixe des fichiers de données
    -d) shift 1;rep_data="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #repertoire des fichiers de donnees
    -r) shift 1;reader="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #nom du lecteur
    -dr) shift 1;rep_reader="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #repertoire du lecteur
    -m) shift 1;debug="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #mode affichage
    -st) shift 1;station="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #abreviation station
    -res) shift 1;rep_res="$1"; NbrOptionOblig=$(($NbrOptionOblig+1));; #repertoire resultat 
    *) echo 'Parameter ' $1 'not defined';
	echo "-y : annee traitee";	
	echo "-s : station";
	echo "-d : repertoire des fichiers de donnees";	
	echo "-r : nom du lecteur";	
	echo "-dr : repertoire du lecteur";	
	echo "-m : mode affichage";
	exit 1;;

  esac
  shift 1
done

if [[ $debug == '' ]]
then
	debug=1 
fi

if [[ $rep_res == '' ]]
then
       	rep_res="." 
fi

echo "annee=$annee"

list_file=`ls "$rep_data"./O3NO2_20"$annee"_co.$station`
rm data_files_tmp

echo "$rep_data" > data_files_tmp
nbfiles=`ls "$rep_data"./O3NO2_20"$annee"_co.$station | wc -l`
echo "$nbfiles" >> data_files_tmp
echo "$debug" >> data_files_tmp
echo "20$annee" >> data_files_tmp
echo "$station" >> data_files_tmp 
echo "$rep_res" >> data_files_tmp 
echo "$suf" >> data_files_tmp 


for file in $list_file
do
	echo "$file" >> data_files_tmp 
done

if [[ $station == 'oh' ]] then
	stationM="OH"
fi
if [[ $station == 'sb' ]] then
        stationM="SB"
fi
if [[ $station == 'ba' ]] then
        stationM="BA"
fi
if [[ $station == 're' ]] then
        stationM="RE"
fi
if [[ $station == 'kr' ]] then
        stationM="KR"
fi
if [[ $station == 'dd' ]] then
        stationM="DD"
fi
if [[ $station == 'so' ]] then
        stationM="SO"
fi
if [[ $station == 'zg' ]] then
        stationM="ZG"
fi
if [[ $station == 'sa' ]] then
        stationM="SA"
fi
if [[ $station == 'sk' ]] then
        stationM="SK"
fi


rm $rep_data/list_info
list_info=`ls "$rep_data"./SAOZ_*.$stationM`
for file in $list_info
do
        echo "$file" >> list_info
done

mv list_info $rep_data

./treat_files_list data_files_tmp
 
