#!/bin/csh -fx

setenv INFILE  hrrr.t14z.wrfsfcf04.grib2 

wgrib2 $INFILE  | egrep VIS  | wgrib2 -i  $INFILE  -grib_out vis.grb2
wgrib2 $INFILE  | egrep LCDC | wgrib2 -i  $INFILE  -grib_out lcdc.grb2
wgrib2 $INFILE  | egrep MCDC | wgrib2 -i  $INFILE  -grib_out mcdc.grb2
wgrib2 $INFILE  | egrep HCDC | wgrib2 -i  $INFILE  -grib_out hcdc.grb2
wgrib2 $INFILE  | egrep REFC | wgrib2 -i  $INFILE  -grib_out refc.grb2

cdo max lcdc.grb2 mcdc.grb2 2levs.grb2
cdo max 2levs.grb2 hcdc.grb2 3levs.grb2
cdo mulc,-1 3levs.grb2 3levs_neg1.grb2
cdo addc,100.0 3levs_neg1.grb2 3levs_neg1_add100.grb2

cdo -gec,0.000 refc.grb2 refc_ge0.grb2
cdo mulc,-100. refc_ge0.grb2 refc_ge0_mulneg100.grb2
cdo add 3levs_neg1_add100.grb2 refc_ge0_mulneg100.grb2 cldfrac+refc.grb2

cdo -gec,0.000 cldfrac+refc.grb2 cldfrac+refc_ge0.grb2
cdo mul cldfrac+refc_ge0.grb2 cldfrac+refc.grb2 cldfrac+refc_final.grb2

cdo ltc,2000.00 vis.grb2 poor_vis_mask.grb2
cdo ltc,10000.00 vis.grb2 low_vis_mask.grb2
cdo ltc,30000.00 vis.grb2 mod_vis_mask.grb2
cdo sub low_vis_mask.grb2 poor_vis_mask.grb2 low-poor.grb2
cdo sub mod_vis_mask.grb2 low_vis_mask.grb2 mod-low.grb2
cdo mulc,-100.000 poor_vis_mask.grb2 poor_neg100.grb2
cdo mulc,-50.000 low-poor.grb2 low_neg50.grb2
cdo mulc,-10.000 mod-low.grb2 mod_neg10.grb2

cdo add poor_neg100.grb2 low_neg50.grb2 p100low50.grb2
cdo add p100low50.grb2 mod_neg10.grb2 allvis_negs.grb2
cdo add cldfrac+refc_final.grb2 allvis_negs.grb2 clds_refc_vis.grb2

cdo -gec,0.000 clds_refc_vis.grb2 clds_refc_vis_ge0.grb2
cdo mul clds_refc_vis_ge0.grb2 clds_refc_vis.grb2 clds_refc_vis_final.grb2


exit

