A new six-dimensional variational code is presented for the determination of the rovibrational energy levels of four atom molecules which are centrally connected. Internal (displacement) coordinates are used. Using formaldehyde as the first example we have attempted to refine a quartic potential surface and simultaneously to optimize the geometry. The parameters have been adjusted to obtain as good agreement as possible with the lowest 65 J = 0 observed vibrational lines of H2CO and the fundamentals of D2CO, and the J = 1 observed rotational lines of the fundamentals of both H2CO and D2CO. This is a highly nonlinear problem, and it is not possible to refine separately the geometry and force field. We have simultaneously optimized the geometry and quadratic force field, and separately the cubic and quartic force field. Fermi and Coriolis resonances have been reproduced. The predicted geometry, with uncertainties, is CH = 1.1003 +/- 0.0005 Angstrom, CO = 1.2031 +/- 0.0005 Angstrom, and HCO = 121.62 +/- 0.05 degrees. (C) 1996 Academic Press, Inc.