/* commands.c: main commands */ /*- * Copyright (c) 1997, 1998, 2003 * LEMIS (SA) Pty Ltd. * * Written by Greg Lehey * * This software is distributed under the so-called ``Berkeley * License'': * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * This software is provided ``as is'', and any express or implied * warranties, including, but not limited to, the implied warranties of * merchantability and fitness for a particular purpose are disclaimed. * In no event shall the company or contributors be liable for any * direct, indirect, incidental, special, exemplary, or consequential * damages (including, but not limited to, procurement of substitute * goods or services; loss of use, data, or profits; or business * interruption) however caused and on any theory of liability, whether * in contract, strict liability, or tort (including negligence or * otherwise) arising in any way out of the use of this software, even if * advised of the possibility of such damage. * * $Id: commands.c,v 1.3 2004/12/12 03:08:24 grog Exp grog $ */ #include "brew.h" void sugar_usage (char *myname) { fprintf (stderr, "Usage:\n" "%s [-s ] [-d ] [-m ] [-e ] [-F FG] [-P Plato] [-S OG] litres\n\n" "\t, , and 0? "Add": "Remove", fabs (sugar_needed), fabs (sugar_needed / dme_fraction), fabs (sugar_needed / extract_fraction), fabs (sugar_needed / malt_fraction), sugar_needed > 0? "remove": "add", water_adjustment, desired_Plato, desired_OG); } } void hops_usage (char *myname) { fprintf (stderr, "Usage:\n" "%s [-a ] [-l ] [-S ] [-t ] \n", myname ); } void hops_command (int argc, char *argv [], char *arg0 []) { int i; float aaprop = 0.05; /* default alpha acid */ float total_aa = 0; /* and total so far */ float boil_time = 60; /* time this component is boiled */ float total_volume = 0; /* total volume of boil */ float SG = 1.060; /* default boil gravity */ enum { rager, tinseth } util_type = tinseth; printf ("Hop weight\tAA %%\tBoil time\tUtil\tAA\tTotal AA\n\n"); if (argc == 1) { hops_usage (argv [0]); return; } for (i = 1; i < argc; i++) { if (argv [i] [0] == '-') { if (strncmp (argv [i], "-a", 2) == 0) /* alpha acid */ { if (argv [i] [2]) /* specified percentage */ aaprop = percentage (atof (&argv [i] [2])); else if (argc > (i + 1)) { i++; aaprop = percentage (atof (argv [i])); } else { fprintf (stderr, "No alpha acid component specified\n\n"); hops_usage (argv [0]); return; } } else if (strncmp (argv [i], "-l", 2) == 0) /* litres */ { if (total_volume != 0) /* already specified */ fprintf (stderr, "Warning: volume redefined, was %4.2f\n", total_volume ); if (argv [i] [2]) /* specified percentage */ total_volume = atof (&argv [i] [2]); else if (argc > (i + 1)) { i++; total_volume = atof (argv [i]); } else { fprintf (stderr, "No volume specified\n\n"); hops_usage (argv [0]); return; } } else if (strncmp (argv [i], "-R", 2) == 0) /* Rager equations */ util_type = rager; else if (strncmp (argv [i], "-S", 2) == 0) /* desired OG */ { if (argv [i] [2]) /* specified percentage */ SG = densityval (atof (&argv [i] [2])); else if (argc > (i + 1)) { i++; SG = densityval (atof (argv [i])); } else { fprintf (stderr, "No SG specified\n\n"); hops_usage (argv [0]); return; } } else if (strncmp (argv [i], "-T", 2) == 0) /* Tinseth equations */ util_type = tinseth; else if (strncmp (argv [i], "-t", 2) == 0) /* boil time */ { if (argv [i] [2]) /* specified percentage */ boil_time = atof (&argv [i] [2]); else if (argc > (i + 1)) { i++; boil_time = atof (argv [i]); } else { fprintf (stderr, "No volume specified\n\n"); hops_usage (argv [0]); return; } } else { fprintf (stderr, "Unknown option: %s\n\n", argv [i]); hops_usage (argv [0]); return; } } else /* hop weight */ { float util; float hop_weight; float hop_extract; /* Decipher rager and do it */ if (util_type = tinseth) util = tinseth_hop_utilization (SG, boil_time); else util = 0.2; /* XXX */ hop_weight = atof (argv [i]); hop_extract = hop_weight * util * aaprop; total_aa += hop_extract; printf ("%6.2f\t\t%6.2f\t%6.0f\t\t%4.1f\t%6.3f\t%6.3f\n", hop_weight, aaprop * 100, boil_time, util * 100, hop_extract, total_aa ); } } /* Finished: show results */ if (total_volume) /* got a volume */ printf ("\n" "Boil density:\t\t%7.3f\n" "Total alpha acid:\t%7.3f g\n" "Volume:\t\t\t%7.3f l\n" "IBUs:\t\t\t%3.0f\n", SG, total_aa, total_volume, total_aa / total_volume * 1000 ); } void brix_command (int argc, char *argv [], char *arg0 []) { } void brix2fg_command (int argc, char *argv [], char *arg0 []) { float obrix; float fbrix; if (argc < 2) { fprintf (stderr, "Usage: %s original-brix final-brix\n", argv [0]); return; } obrix = atof (argv [1]); fbrix = atof (argv [2]); printf ("\t\tBrix\tSG\tAttenuation\n" "Original\t%6.2f\t%6.3f\n" "Final\t\t%6.2f\t%6.3f\t%6.0f%%\n", obrix, brix_to_sg (obrix), fbrix, brix_to_fg (obrix, fbrix), 100 - (brix_to_fg (obrix, fbrix) - 1) / (brix_to_sg (obrix) - 1) * 100); } void decoct_command (int argc, char *argv [], char *arg0 []) { float totalweight; float mashtemp; float goaltemp; if (argc < 3) { fprintf (stderr, "Usage: %s totalweight mashtemp goaltemp\n", argv [0]); return; } totalweight = atof (argv [1]); mashtemp = atof (argv [2]); goaltemp = atof (argv [3]); printf ("Mash weight:\t\t%6.3f kg\n" "Mash temperature:\t%6.0f°\n" "Goal temperature:\t%6.0f°\n" "Decoction weight:\t%6.3f kg\n", totalweight, mashtemp, goaltemp, totalweight * (goaltemp - mashtemp) / (100 - mashtemp) ); } void debug_command (int argc, char *argv [], char *arg0 []) { }