My recommendation in this situation would be to add a break point the code and then step through it line by line until you get to the exact call in which the error occurs. I would then check the type and value of the variable being set to the DIM keyword and make sure it is defined as expected. You can do this using the HELP command. For example, if the lines says the following:
ENVI_DOIT, 'ENVI_MASK_APPLY_DOIT', DIMS=b_dims,FID=b_fid, M_FID= Mask_8_fid, M_POS=m_pos[0], OUT_NAME= OldName+'-coast-breton-sound-md', POS=b_pos[0], R_FID=md_fid8, VALUE=0
I would enter the following commands into the IDL terminal and make sure they return the expected values:
help, b_dims
print, b_dims
|