Calculation of magnetic flux profiles and deduction of critical current densities for type II superconductors