Experimental report on the analysis and processing of big data of "C language" multi-temperature sensor

Source: Internet
Author: User

Objective: To measure the data from the experimental instrument and record it in the text document II. reading the data of the record table. Check whether the temperature in the record table meets the standard. Experimental steps: First, the measurement of data from the experimental instrument and recorded in a text document according to the circuit Connection diagram on the experimental instrument to connect the relevant route to read the relevant data, and recorded in the file. Second, read the data of the record table under the current project directory to create a text document, the measured data (time, temperature, humidity) recorded in a text document, such as:

(i) Record form

The limited data of this file is read out and displayed on the terminal (running on the screen) by the program run, and the maximum and average temperature is obtained. Third, check whether the temperature in the record table is in accordance with the standard to another standard table, that is, to create a text document, another set of data (time, temperature, humidity), also need to read the standard table data, through the record table and the standard table in the equivalent time of the temperature comparison, check the record table temperature compliance, if not qualified, The Output record table in the unqualified temperature and the corresponding time. The standard table is as follows:

(ii) Standard table

Through the eyes to compare the record table and the standard table, if the temperature difference between the two tables in the equivalent time is more than 2 unqualified, then we know at a glance that the last two data in the record table is unqualified, then the two time and temperature corresponding output to the terminal. In conjunction with the two or three-step source code, this source code is as follows:
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#define MAX#define Time_len#define Temperature_len 5#define Humidity_len 5#define CHECK_STAND 2.0Doublecheck_failtem[ -];Charcheck_failtime[ -][ -];structtxt{CharTime[time_len];CharTemperature[temperature_len];CharHumidity[humidity_len];} txt[ -],check[ -];voidPrint () {printf("++++++++++++++++++++++\n");printf("1-> reads data from the log table \ n");printf("2-> reads data from standard table \ n");printf("3-> The maximum value of the recording table temperature \ n");printf("4-> to find the average temperature of the recording table \ n");printf("5-> Check if the temperature is qualified at some time \ n");printf("++++++++++++++++++++++\n");printf("\ n Please enter the serial number:");}voidFileread_write ()//Read data from the record table{FILE *pfread = fopen ("C:/users/samsung/documents/visual Studio 2013/projects/txtchuanganqi2015_6_24/debug/sulijuan.txt","rb+");if(Pfread = = NULL) {Perror ("Error");Exit(exit_failure); }printf("Time temperature humidity \ n"); for(inti =0; I <5; i++) {fgets (Txt[i].time,5, Pfread); Fseek (Pfread,1, seek_cur); Fgets (Txt[i].temperature,5, Pfread); Fseek (Pfread,1, seek_cur); Fgets (Txt[i].humidity,6, Pfread); Fseek (Pfread,1, seek_cur);printf('%s%s%s\n ', Txt[i].time, Txt[i].temperature, txt[i].humidity); }printf("\ n"); Fclose (Pfread);}voidFileread_stadard ()//Read data from standard tables{FILE *fcheck = fopen ("C:/users/samsung/documents/visual Studio 2013/projects/txtchuanganqi2015_6_24/debug/standardtemperature.txt ","rb+");printf("Time temperature humidity \ n"); for(inti =0; I <5; i++) {fgets (Check[i].time,5, Fcheck); Fseek (Fcheck,1, seek_cur); Fgets (Check[i].temperature,5, Fcheck); Fseek (Fcheck,1, seek_cur); Fgets (Check[i].humidity,6, Fcheck); Fseek (Fcheck,1, seek_cur);printf('%s%s%s\n ', Check[i].time, Check[i].temperature, check[i].humidity); }printf("\ n"); Fclose (Fcheck);}voidTemperature_max (structTXT txt[])//To find the maximum value of the recording table temperature{inti =0;DoubleN,max =0.0; max = Atof (txt[0].temperature); for(i =1; I <5; i++) {n = atof (txt[i].temperature);if(N>max)         {max = n; }    }printf("Temperature_max =%f\n", Max);printf("\ n");}voidTemperature_avg (structTXT txt[])//Calculate the average of the temperature of the recording table{DoubleM,sum =0.0;intI sum = atof (txt[0].temperature); for(i =1; I <5;        i++) {m = Atof (txt[i].temperature);    sum + = m; }printf("Temperature_avg =%f\n", sum/5);printf("%f",fabs(Atof (check[3].temperature)-Atof (txt[3(].temperature)));printf("\ n");}voidCheck_temperature (structTXT txt[],structTXT check[])//Check whether the temperature is qualified{inti =0, j =0; for(i =0; i<5; i++) {if(strcmp(Txt[i].time, check[i].time) = =0)        {if((fabs(Atof (Check[i].temperature)-atof (txt[i].temperature))) > Check_stand) {strcpy(Check_failtime[i],txt[i].time); Check_failtem[i] = atof (txt[i].temperature);printf('%s ', Check_failtime[i]);printf("%f\n", Check_failtem[i]);//fwrite (& (Txt[i].temperature), sizeof (TXT), 1, pf);}        }    }}intMain () {intInput while(1) {print ();scanf("%d", &input);Switch(input) { Case 1: Fileread_write (); Break; Case 2: Fileread_stadard (); Break; Case 3: Temperature_max (TXT); Break; Case 4: Temperature_avg (TXT); Break; Case 5: Check_temperature (TXT, Check); Break;default:printf("Invalid sequence number \ n"); Break; }    }return 0;}
Resolution One: Open the created record table with fopen, through the fgets operation file pointer line by line to read the time, temperature, humidity, and placed in an array, easy to find to do the operation. Parsing two: Two tables of data are read out in two different arrays, through the operation of the array of two table temperature comparison, when the same time will be compared to the temperature. Running result: (a) reading data from a file in a record table

(ii) The maximum and average values of the temperature in the data being read

(iii) reading data from a file in a standard table

(iv) comparison of records and standard tables to check whether the temperature is qualified at a certain time in the recording table

Experimental Summary: (1), the circuit must be connected correctly, record a limited number of relevant data. (2), when writing the program implementation file read data, if the file is created under the current directory, the read can be used relative path to open the file, otherwise open the file with absolute path. Experimental experience: Through this experiment, I learned how the data should be recorded in order to read it correctly from the file, and to use the program to manipulate the file more understanding.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Experimental report on the analysis and processing of big data of "C language" multi-temperature sensor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.