Knowledge about the subsurface structure for any type of building is crucial for its construction, maintenance, and repair. In cases where the required information cannot be obtained by direct observation, indirect data acquisition techniques offer an alternative, such as gravimetric or magnetic surveys. Their major advantages are that the data collection neither disturbs the building nor its environment. The data analysis of indirect measuring techniques represents an inverse problem that has the goal to determine the underlying subsurface structure. It was first addressed by G. G. Stokes (1819-1903) on a world-wide scale, who proved that there is no unique solution to the interior mass distribution of the earth from a given external gravity field. In this work, an automatic numerical scheme based on the least squares adjustment method is introduced to analyze such indirect data. The suitability of the described approach is demonstrated by examining a gravimetric survey of Hagia Sophia, one of the oldest sacred monuments in the world, built between 532-537 AD under the reign of Roman emperor Justinian in today's Istanbul (Turkey).