write file, add codebook