At a glance, you have a lot of duplicated code. You could eliminate some of that by using helper functions, even without loops.

For example, rate7() could be simplified by


float...