Whenever a criminal defendant who appears, as a result of chronic alcoholism or the use of narcotics or restricted dangerous drugs, to be a danger to others, to himself, or to be gravely disabled, is brought before any judge, the judge may order the defendant’s evaluation under conditions set forth in this article, provided evaluation services designated in the county plan pursuant to Section 5654 are available.