# Script para processar arquivos L1A -> GEO -> L1B -> L2 -> L3b -> L3m em um diretório.

for FILE in *L1A_LAC*
#for FILE in *L3b*
do

  # The line below assumes an extension, and creates a base name without that extension
  BASE=`echo $FILE |awk -F. '{ print $1 }'`
  GEOFILE=${BASE}.GEO
  L1BFILE1KM=${BASE}.L1B_LAC
  L1BFILEHKM=${BASE}.L1B_HKM
  L1BFILEQKM=${BASE}.L1B_QKM
  L2FILE=${BASE}.L2
  L3bFILE=${BASE}.L3b
  L3mFILE=${BASE}.L3m

  # process the L1A file to GEO
  modis_GEO.py -v $FILE -o $GEOFILE

  # process the L1A/GEO subscene files to L1B
  modis_L1B.py -v $FILE $GEOFILE -o $L1BFILE1KM -k $L1BFILEHKM -q $L1BFILEQKM

  # process the L1B subscene to L2
 #  645 e 859 nm
  l2gen ifile=$L1BFILE1KM geofile=$GEOFILE ofile=$L2FILE l2prod='Rrs_645,Rrs_859' aer_opt=-1 aer_wave_short=1240 aer_wave_long=2130 filter_file=/usr/local/seadas-7.5.3/ocssw/share/modis/msl12_filter_custom_turb.dat resolution=250 cloud_thresh=0.018 cloud_wave=2130.0 maskhilt=off maskstlight=on north=-17.4 south=-20.7 east=-38.2 west=-40.6
   
  #555 nm
  # l2gen ifile=$L1BFILE1KM geofile=$GEOFILE ofile=$L2FILE l2prod='nLw_555,Rrs_555' aer_opt=-1 aer_wave_short=1240 aer_wave_long=2130 filter_file=/usr/local/seadas-7.5.3/ocssw/share/modis/msl12_filter_custom_555.dat resolution=500 cloud_thresh=0.018 cloud_wave=2130.0 maskhilt=off maskstlight=on north=-16.3 south=-23.3 east=-37.5 west=-43.0
  
  # Processar os arquivos L2 para l2bin para posterior geração dos L3 gridados
  l2bin ifile=$L2FILE ofile=$L3bFILE resolution='Q' flaguse='NONE'

  # Processar os arquivos L3 gridados
  l3mapgen ifile=$L3bFILE ofile=$L3mFILE resolution='qkm' interp='area' fudge=2 north=-17.4 south=-20.7 east=-38.2 west=-40.6

done
