This library provides the ability to compute the median, circular median, mean and standard deviation of a dataset stored in a circular buffer
util.cpp@6:df815bdada09, 2013-05-28 (annotated)
- Committer:
- greletj
- Date:
- Tue May 28 17:50:55 2013 +0000
- Revision:
- 6:df815bdada09
- Parent:
- 3:27019c77bf90
add default in switch(mode) to suppress compiler warning: ; enumeration value 'SETF' not handled in switch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greletj | 1:a4c87bc5b008 | 1 | /* Copyright (c) <2012> <copyright J. Grelet>, MIT License |
greletj | 1:a4c87bc5b008 | 2 | * |
greletj | 1:a4c87bc5b008 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
greletj | 1:a4c87bc5b008 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
greletj | 1:a4c87bc5b008 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
greletj | 1:a4c87bc5b008 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
greletj | 1:a4c87bc5b008 | 7 | * furnished to do so, subject to the following conditions: |
greletj | 1:a4c87bc5b008 | 8 | * |
greletj | 1:a4c87bc5b008 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
greletj | 1:a4c87bc5b008 | 10 | * substantial portions of the Software. |
greletj | 1:a4c87bc5b008 | 11 | * |
greletj | 1:a4c87bc5b008 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
greletj | 1:a4c87bc5b008 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
greletj | 1:a4c87bc5b008 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
greletj | 1:a4c87bc5b008 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
greletj | 1:a4c87bc5b008 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
greletj | 1:a4c87bc5b008 | 17 | */ |
greletj | 1:a4c87bc5b008 | 18 | |
greletj | 1:a4c87bc5b008 | 19 | // util.cpp |
greletj | 0:b3a2e39a13ad | 20 | |
greletj | 0:b3a2e39a13ad | 21 | #include <string.h> |
greletj | 0:b3a2e39a13ad | 22 | //#include <sys/types.h> |
greletj | 0:b3a2e39a13ad | 23 | #include <time.h> |
greletj | 0:b3a2e39a13ad | 24 | #include <math.h> |
greletj | 0:b3a2e39a13ad | 25 | #include <ctype.h> |
greletj | 0:b3a2e39a13ad | 26 | #include "util.h" |
greletj | 0:b3a2e39a13ad | 27 | |
greletj | 0:b3a2e39a13ad | 28 | |
greletj | 0:b3a2e39a13ad | 29 | #define COMPACT 0 /* Supprime les blancs a la lecture du descripteur */ |
greletj | 0:b3a2e39a13ad | 30 | #define CONT_CHAR '\\' /* Caractere de continuation au milieu d'un champs */ |
greletj | 0:b3a2e39a13ad | 31 | #define TOKEN_SIZE 240 // Taille maxi d'un element du descripteur |
greletj | 0:b3a2e39a13ad | 32 | |
greletj | 0:b3a2e39a13ad | 33 | |
greletj | 0:b3a2e39a13ad | 34 | /***************************************************************************** |
greletj | 0:b3a2e39a13ad | 35 | Convertit la position exprimee en degres/minutes en degres decimaux |
greletj | 0:b3a2e39a13ad | 36 | lat = -1328.837 -> -13.4806 |
greletj | 0:b3a2e39a13ad | 37 | *****************************************************************************/ |
greletj | 0:b3a2e39a13ad | 38 | double convert_position( double data ) |
greletj | 0:b3a2e39a13ad | 39 | { |
greletj | 0:b3a2e39a13ad | 40 | double integer; |
greletj | 0:b3a2e39a13ad | 41 | double dec; |
greletj | 0:b3a2e39a13ad | 42 | |
greletj | 0:b3a2e39a13ad | 43 | dec = (double)( modf( data / 100.0 , &integer ) ); |
greletj | 0:b3a2e39a13ad | 44 | dec /= 0.60; |
greletj | 0:b3a2e39a13ad | 45 | |
greletj | 0:b3a2e39a13ad | 46 | data = ( (double)( integer ) + dec ) * 100000.0; |
greletj | 0:b3a2e39a13ad | 47 | return( rint( data ) / 100000.0 ); |
greletj | 0:b3a2e39a13ad | 48 | } |
greletj | 0:b3a2e39a13ad | 49 | |
greletj | 0:b3a2e39a13ad | 50 | /***************************************************************************** |
greletj | 0:b3a2e39a13ad | 51 | Convertit le temps date/heure en jour julien decimal |
greletj | 0:b3a2e39a13ad | 52 | *****************************************************************************/ |
greletj | 0:b3a2e39a13ad | 53 | double temps( unsigned jour_julien, double heure_decimal ) |
greletj | 0:b3a2e39a13ad | 54 | { |
greletj | 0:b3a2e39a13ad | 55 | double heure, |
greletj | 0:b3a2e39a13ad | 56 | minute, |
greletj | 0:b3a2e39a13ad | 57 | seconde, |
greletj | 0:b3a2e39a13ad | 58 | dec; |
greletj | 0:b3a2e39a13ad | 59 | |
greletj | 0:b3a2e39a13ad | 60 | dec = modf( heure_decimal / 100.0 , &heure ); |
greletj | 0:b3a2e39a13ad | 61 | seconde = ( modf( dec * 100.0 , &minute ) ); |
greletj | 0:b3a2e39a13ad | 62 | return( (double)jour_julien + ( ( (heure * 3600.0) + (minute * 60.0 ) + seconde) / 86400.0 ) ); |
greletj | 0:b3a2e39a13ad | 63 | } |
greletj | 0:b3a2e39a13ad | 64 | |
greletj | 0:b3a2e39a13ad | 65 | |
greletj | 0:b3a2e39a13ad | 66 | /***************************************************************************** |
greletj | 0:b3a2e39a13ad | 67 | *****************************************************************************/ |
greletj | 0:b3a2e39a13ad | 68 | STRING *gen_str( unsigned taille /*= 80*/ ) |
greletj | 0:b3a2e39a13ad | 69 | { |
greletj | 0:b3a2e39a13ad | 70 | static char liste_str[ MAX_CHAR_POOL ]; |
greletj | 0:b3a2e39a13ad | 71 | static STRING *courant = (STRING *) &liste_str; |
greletj | 0:b3a2e39a13ad | 72 | STRING *retour; |
greletj | 0:b3a2e39a13ad | 73 | |
greletj | 0:b3a2e39a13ad | 74 | ++taille; // Pour le \0 en plus |
greletj | 0:b3a2e39a13ad | 75 | if( *courant + taille >= liste_str + MAX_CHAR_POOL ) { |
greletj | 0:b3a2e39a13ad | 76 | courant = (STRING *) &liste_str; |
greletj | 0:b3a2e39a13ad | 77 | } |
greletj | 0:b3a2e39a13ad | 78 | retour = courant; |
greletj | 0:b3a2e39a13ad | 79 | memset( *retour,'\0',taille ); // Initialise la zone avec \0 |
greletj | 0:b3a2e39a13ad | 80 | courant = (STRING *) ( (char *) courant + taille ); // Bon deplacement |
greletj | 0:b3a2e39a13ad | 81 | return( retour ); |
greletj | 0:b3a2e39a13ad | 82 | } |