void temp_convert_range(float start_temp, float end_temp, float step) { float next_temp = start_temp + step; printf("%12.2f => %12.2f\n", start_temp, temp_convert(start_temp)); if (next_temp <= end_temp) { temp_convert_range(next_temp, end_temp, step); } }
int celsius_to_fahr(){ float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; celsius = lower; printf("Celsius-Fahrenheit table:\n\n"); while (celsius <= upper){ printf("%3.0f %6.1f\n", celsius, temp_convert(celsius)); celsius = celsius + step; } return 0; }
int main(int argc, char **argv) { FILE *bin, *yaml; if(argc < 2) { fprintf(stderr, "Usage: %s <binfile>\n", argv[0]); return -1; } bin = fopen(argv[1], "rb"); if(!bin) { fprintf(stderr, "Unable to open file: %s\n", argv[1]); return -1; } char *filename = strdup(argv[1]); int len = strlen(filename); strcpy(filename + len - 3, "yml"); yaml = fopen(filename, "w"); if(!yaml) { fprintf(stderr, "unable to open yaml file '%s' for writing, using \n", argv[2]); yaml = stdout; return -1; } /* print the YAML metadata header */ fputs("metadata:\n", yaml); fputs(INDENT, yaml); fputs("team_number: 3\n", yaml); fputs("\n", yaml); fputs("samples:\n", yaml); do { uint32_t index, time, date; uint16_t accel[3], temp; float lat, lng; int count = 0; // 0 0 count += fread(&index, 4, 1, bin); // 1 1 count += fread(&time, 4, 1, bin); // 1 2 count += fread(&date, 4, 1, bin); // 1 3 count += fread(&accel, 2, 3, bin); // 3 6 count += fread(&lat, 4, 1, bin); // 1 7 count += fread(&lng, 4, 1, bin); // 1 8 count += fread(&temp, 2, 1, bin); // 1 9 if(count == 9) { // all items read successfully // these are always generated fputs(INDENT, yaml); fprintf(yaml, "- temperature: %d\n", temp_convert(temp)); fputs(INDENT, yaml); accel_print(yaml, accel); /* if the high bit is set then we had a fix, so lat * and long coordinates should be generated */ if(index & (1 << 31)) { // fix flag set fputs(INDENT, yaml); time_print(yaml, time, date); fputs(INDENT, yaml); fprintf(yaml, " latitude: %f\n", gps_correct(lat)); fputs(INDENT, yaml); fprintf(yaml, " longitude: %f\n", gps_correct(lng)); } fputs("\n", yaml); } else { if(feof(bin)) { break; } fprintf(stderr, "Error reading file: %s", argv[1]); return -1; } } while( !feof(bin) && !ferror(bin)); fclose(yaml); fclose(bin); return 0; }
main() { temp_convert(0, 300, 20); return 0; }