# Script para processar arquivos -> L1B -> L2 em um diretório, adquirindo as variáveis chl, sst e qual_sst.
 for FILE in *L1A_LAC*
#for FILE in *.L2
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
  #NOTE! customize the l2gen parameters here
  l2gen ifile=$L1BFILE1KM geofile=$GEOFILE ofile=$L2FILE l2prod='Rrs_645,Rrs_859,Rrs_469,Rrs_555,Rrs_1240,Rrs_1640,Rrs_2130' 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_sal.dat resolution=500 cloud_thresh=0.018 cloud_wave=2130.0 maskhilt=off maskstlight=on maskland=on maskcloud=on proc_sst=0 north=-16.3 south=-23.3 east=-37.5 west=-43.0
   
  
  l2bin ifile=$L2FILE ofile=$L3bFILE resolution='H' flaguse='ATMFAIL','LAND','HILT','HISATZEN','CLDICE','LOWLW','NAVWARN','ABSAER','MAXAERITER','ATMWARN','HISOLZEN','NAVFAIL','FILTER'

  l3mapgen ifile=$L3bFILE ofile=$L3mFILE resolution='hkm' interp='area' fudge=2 north=-16.3 south=-23.3 east=-37.5 west=-43.0

done
