source: trunk/etc/src/yrms.c

Last change on this file was 610, checked in by grlod, 12 years ago

header replacements
uml diagrams updated
should have been committed 3 months ago ...

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1/*
2Copyright or © or Copr. MMSA team, LOCEAN Paris (2011)
3
4This software is a framework for variational data assimilation in
5numerical models.
6
7This software is governed by the CeCILL license under French law and
8abiding by the rules of distribution of free software.  You can  use,
9modify and/ or redistribute the software under the terms of the CeCILL
10license as circulated by CEA, CNRS and INRIA at the following URL
11"http://www.cecill.info".
12
13As a counterpart to the access to the source code and  rights to copy,
14modify and redistribute granted by the license, users are provided only
15with a limited warranty  and the software's author,  the holder of the
16economic rights,  and the successive licensors  have only  limited
17liability.
18
19In this respect, the user's attention is drawn to the risks associated
20with loading,  using,  modifying and/or developing or reproducing the
21software by the user in light of its specific status of free software,
22that may mean  that it is complicated to manipulate,  and  that  also
23therefore means  that it is reserved for developers  and  experienced
24professionals having in-depth computer knowledge. Users are therefore
25encouraged to load and test the software's suitability as regards their
26requirements in conditions enabling the security of their systems and/or
27data to be ensured and,  more generally, to use and operate it in the
28same conditions as regards security.
29
30The fact that you are presently reading this means that you have had
31knowledge of the CeCILL license and that you accept its terms.
32
33YAO website : http://www.locean-ipsl.upmc.fr/~yao/
34Contact : yao@locean-ipsl.upmc.fr
35*/
36// Contributor : Charles Sorror
37
38/************************************************************************/
39/*              yrms : is a part of Yao utilities and tools             */
40/************************************************************************/
41
42#include <stdio.h>
43#include <stdlib.h>
44#include <math.h>
45
46#define BUFSIZE 80
47
48int main (int argc, char *argv[])
49{    /* . Syntaxe: yrms f1 f2 zspace [f3] */
50     /* . Purpose: calculer l'erreur rms entre 2 trajectoires d'espace
51                 dont les valeurs sont respectvement dans les fichiers
52                 f1 et f2 passes en parametres qui doivent contenir
53                 le meme nombre d'elements qui doit d'ailleurs etre
54                 un multiple de zspace qui est la taille de l'espace
55                 le resultat, {pour chaque pas d'espace, zspace} est
56                 ecrit dans f3 s'il est mentionne sinon sur la sortie
57                 standard.
58                 la somme des rms est affichee a la fin
59        . Warning: la detection de ligne blanche ou vide n'est pas geree
60        . Compilation : cc -Wall -o yrms yrms.c -lm                     */
61
62        FILE    *f1, *f2, *f3;
63        char    buf1[BUFSIZE+1], buf2[BUFSIZE+1];
64        int     zspace, rstelt, nbt;
65        double  x1, x2, errsumt, errsumallt, rms, sumrms;
66
67        if (argc<4 || argc > 5)
68        {       printf("syntaxe error !!! : yrms f1 f2 zspace [f3]\n");
69                exit(0);
70        }
71
72        if ((f1 = fopen(argv[1], "r")) <= 0)
73        {       printf ("file1 %s not found !!!\n", argv[1]);
74                exit(0);
75        }
76        if ((f2 = fopen(argv[2], "r")) <= 0)
77        {       printf ("file2 %s not found !!!\n", argv[2]);
78                exit(0);
79        }
80        if (argc==5)
81        {       if ((f3 = fopen(argv[4], "w")) <= 0)
82                {       printf ("failed while opening file3 %s !!!\n", argv[3]);
83                        exit(0);
84                }
85        }
86        else
87                f3 = stdout;
88
89        zspace = atoi(argv[3]);
90        if (zspace<=0)
91        {       printf ("zspace must be a integer greater than zero !!!\n");
92                exit(0);
93        }
94
95        rstelt=0; nbt=0; errsumt=0.0; errsumallt=0.0, sumrms=0.0;
96        while (1) /* boucle de */
97        {       /* lecture paralle des 2 fichiers */
98                if (fgets (buf1, BUFSIZE, f1) == NULL)
99                {  /* fin du 1er fichier => fin du 2eme fichier */
100                   if (fgets (buf2, BUFSIZE, f2) != NULL)
101                   {  printf("erratum 1: the files have not the same size !!!\n");
102                      exit(0);
103                   }
104
105                   /* fin: le nombre d'elt devait etre un multiple de zspace */
106                   if (rstelt!=0)
107                   {  printf("erratum 3: number of element is not o multiple of zspace\n");
108                      exit(0);
109                   }
110
111                   /* fin fin */
112                   break;
113                }
114
115                /* on doit pouvoir lire le 2eme fichier */
116                if (fgets (buf2, BUFSIZE, f2) == NULL)
117                {  printf("erratum 2: the files have not the same size !!!\n");
118                   exit(0);
119                }
120
121                x1 = atof(buf1);        x2 = atof(buf2);
122                //printf("x1=%f x2=%f \n", x1, x2);
123
124                errsumt += ((x1-x2)*(x1-x2));
125                errsumallt += errsumt;
126
127                rstelt = (rstelt+1)%zspace;
128                if (rstelt==0)
129                {       //printf ("errsumt=%f \n", errsumt);
130                        rms = sqrt(errsumt/zspace);
131                        fprintf(f3, "%f\n",  rms);
132                        errsumt = 0.0;
133                        ++nbt;
134                        sumrms += rms;
135                }
136
137        } /* fin du while de la boucle de lecture parallele */
138        printf("SUMt(rms) = %30.20e\n", sumrms);
139
140        /* rms sur tout la trajectoire */
141        rms = sqrt(errsumallt/(zspace*nbt));
142        printf("RMS(trajectoire::%i pas de temps) = %30.20e\n", nbt, rms);
143
144        printf("yrms: process end normaly\n");
145        return (0);
146}
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Note: See TracBrowser for help on using the repository browser.