A new package of programs, called GFUN, has been developed for designing and calculating the fields of two-dimensional and three-dimensional magnets. The field due to the magnetisation of the iron is calculated directly. “DRAW” subprograms simplify the input of data for the iron and current regions, and display a picture of the iron and current elements for checking as they are read in. “GETB” subprograms allow the field at a point, along a line or over a region to be typed, graphed or contoured. Automatic optimisation is provided. GFUN results have been checked against TRIM calculations and against the measured fields of existing magnets. GFUN is being used for several magnets currently being designed at the Rutherford Laboratory.