An html version of castling.cql. Created by Gady Costeff and Lewis Stiller.

;;This file looks for all studies in which black or white castles in the main line
;; or in a variation (or both)
;; This is done simply by looking for positions such that the current move is 
;; a move of a King from the e file to the c or g files

(match
 :pgn heijden.pgn
 :output castle.pgn
 (position
  :movefrom [Kk]e?
  :moveto .[c?,g?]
  :variations ; look also in the variations
  )
)

After executing this with "> cql Castling.cql" there are 605 studies found in the Harold van der Heijden Database V 2015.
NB. When you see {MATCH} in the text, it means that cql has found the position asked for.

Below only 5 studies are presented:

Some more studies with castling contributed by Mario Garcia: