Move sub%var2D and sub%mask2D array allocation outside of if-statement, so that they are allocated in every case.