scia_lv1_patch_mds: optimized loops