  #!/bin/bash                                                                                                                                                                            
# Purpose : extract QC results from one site                                                                                                                                           
                                                                                                                                                                                       
outdir="/home/karolina/CADM/"                                                                                                                                                          
                                                                                                                                                                                       
beg=${01:?"par1: beg - gps_date format"} # begin date                                                                                                                                 $
end=${2:?"par2: end - gps_date fotmat"} # end daTE                                                                                                                                     
                                                                                                                                                                                       
                                                                                                                                                                                       
site="CADM"                                                                                                                                                                            
                                                                                                                                                                                       
mjdBeg=$(gps_date $beg -o "%J")                                                                                                                                                        
mjdEnd=$(gps_date $end -o "%J")                                                                                                                                                        
mjd=$mjdBeg                                                                                                                                                                            
                                                                                                                                                                                       
                                                                                                                                                                                       
# vytvoreni log souboru                                                                                                                                                                
outfile="/home/karolina/CADM/QCsum2021"                                                                                                                                                
                                                                                                                                                                                       
if [ -f "$outfile" ]; then                                                                                                                                                             
  rm $outfile                                                                                                                                                                          
fi                                                                                                                                                                                     
                                                                                                                                                                                       
touch $outfile                                                                                                                                                                         
                                                                                                                                                                                       
# vytvoreni hlavicky                                                                                                                                                                   
printf "DATE      #GPS expEP  HavEp UseEp csAll csEpo nSlp  mp1    mp2  #GAL expEP  HavEp UseEp csAll csEpo nSlp mp1   mp2 #GLO expEP  HavEp UseEp csAll csEpo nSlp mp1  mp2  #BDS exp$
                                                                                                                                                                                       
                                                                                                                                                                                       
while [ $[${mjd/./}] -le $[${mjdEnd/./}] ]                                                                                                                                             
do


year=$( gps_date "-mjd $mjd" -o "%Y")                                                                                                                                                
   doy=$( gps_date "-mjd $mjd" -o "%j")                                                                                                                                                
                                                                                                                                                                                       
FILE=QC/${year}/${site}${year}${doy}.xtr.gz                                                                                                                                            
                                                                                                                                                                                       
 if [ ! -f "$FILE" ]; then                                                                                                                                                            $
    mjd=$(echo $mjd + 1 | bc -l)                                                                                                                                                       
    else                                                                                                                                                                               
                                                                                                                                                                                       
expGPS=$(zgrep "=GPSSUM" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4 "   "$5 "   "$6 "   "$11 "   "$12 "   "$15 "   " $19 "   " $20}')                                   
satGPS=$(zgrep "=GPSSAT" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4}')                                                                                                  
                                                                                                                                                                                       
expGAL=$(zgrep "=GALSUM" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4 "   "$5 "   "$6 "   "$11 "   "$12 "   "$15 "   " $19 "   " $20}')                                  $
satGAL=$(zgrep "=GALSAT" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4}')                                                                                                  
                                                                                                                                                                                       
expGLO=$(zgrep "=GLOSUM" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4 "   "$5 "   "$6 "   "$11 "   "$12 "   "$15 "    " $19 "     " $20}')                                
satGLO=$(zgrep "=GLOSAT" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4}')                                                                                                 $
                                                                                                                                                                                       
expBDS=$(zgrep "=BDSSUM" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4 "   "$5 "   "$6 "   "$11 "   "$12 "   "$15 "   " $19 "   " $20}')                                   
satBDS=$(zgrep "=BDSSAT" "QC/${year}/${site}${year}${doy}.xtr.gz" | awk '{print $4}')                                                                                                  
                                                                                                                                                                                       
printf "%i-%s %5d %s %5d %s %5d %s %5d %s \n" "$year" "$doy" "$satGPS" "$expGPS"  "$satGAL"  "$expGAL" "$satGLO" "$expGLO" "$satBDS" "$expBDS" >> $outfile                            $
                                                                                                                                                                                       
  mjd=$(echo $mjd + 1 | bc -l)                                                                                                                                                         
  fi                                                                                                                                                                                   
done                                                                                                                                                                                   
                                                                                                                                                                                     
                                                                                                                                                                                       
                                                                                                                                                                                       
                                                                                                                                                                                       
                                                                                                                                                                                       
                                                                                                                                                                                       
                                                                                                                                                                            