ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_prn.cpp
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
File size: 3119 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

# User Rev Content
1 5 /* ecriture d'un reel sur n colonnes, optimiser la precision !!!!*/
2     /* auteur : Alain RASSINEUX 04/1994 */
3     #include <stdio.h>
4     #include <string.h>
5     #include <math.h>
6     #include "m3d_const.h"
7     #include "m3d_struct.h"
8     #include "prototype.h"
9     #define EPS_COLLAGE 1.e-10
10     void m3d_prn(FILE *output,int n,float val)
11     {
12     int i, j, nb, iexpo ;
13     double expo;
14     char buf[8],ext[8], bufn[8], bufexpo[8] ;
15     double val2 ;
16     /* signe */
17     m3d_itoa(n, bufn) ;
18     ext[0] = 0 ;
19    
20     if ((float)fabs((double)val)<EPS_COLLAGE)
21     {
22     fprintf(output,"0.") ;
23     for (i=0;i<n-2;i++) fprintf(output,"0") ;
24     return ;
25     }
26     if (val<0.)
27     {
28     fprintf(output,"-") ;
29     val = val * -1. ;
30     m3d_prn(output,n-1,val) ;/* appel recursif */
31     return ;
32     }
33     expo = log10((double)val) ;
34     if (val>=1.)
35     {
36     i = expo ;
37     /* valeurs superieures a 1 */
38     /* on dispose de n cases 1 pour le point et
39     i + 1 chiffres significatifs */
40     j = n - 2 - i ;/* nombre de decimales */
41     if (j>=0)
42     {
43     m3d_itoa(j, buf) ;
44     strcat(ext,"%-") ;
45     strcat(ext,bufn) ;
46     strcat(ext,".") ;
47     strcat(ext,buf);
48     strcat(ext,"f") ;
49     fprintf(output,ext,val) ;
50     return ;
51     }
52     if (i == n - 1)
53     {
54     strcat(ext,"%-") ;
55     strcat(ext,bufn) ;
56     strcat(ext,".0f") ;
57     fprintf(output,ext,val) ;
58     return ;
59     }
60     /* notation exposant */
61     /* determiner l'exposant */
62     /* et le nombre maxi de chiffres significatifs */
63     if ((i - (n - 3) + 1) <10 ) nb = n - 3 ;
64     else nb = n - 4 ;
65     val2 = val * pow((double)10.,(double)(nb-1-i)) ;
66     /* prendre nb chiffres significatifs */
67     val2 = ceil(val2) ;
68     j = val2 ;
69     strcat(ext,"E+") ;
70     iexpo = i - nb + 1 ;
71     m3d_itoa(iexpo, bufexpo) ;
72     strcat(ext,bufexpo);
73     fprintf(output,"%-d%s",j,ext) ;
74     return ;
75     }
76    
77     /* valeurs inferieures a 1 */
78     else
79     {
80     if ((expo<-20.) || (val==0.)) /* valeur nulle */
81     {
82     val = 0. ;
83     strcat(ext,"%-") ;
84     strcat(ext,bufn) ;
85     strcat(ext,".1f") ;
86     fprintf(output,ext,val) ;
87     return ;
88     }
89     i = expo ;
90     if ((expo - i) != 0.) i-- ;
91    
92     if (i == -1)
93     {
94     fprintf(output,".") ;
95     val2 = val * pow((double)10.,(double)(n-1)) ;
96     val2 = ceil(val2) ;
97     j = val2 ;
98     fprintf(output,"%-d",j) ;
99     }
100     else if (i == -2)
101     {
102     fprintf(output,".0") ;
103     val2 = val * pow((double)10.,(double)(n-1)) ;
104     val2 = ceil(val2) ;
105     j = val2 ;
106     fprintf(output,"%-d",j) ;
107     }
108     else /* valeur inferieure */
109     {
110     if ((i - (n - 3) + 1) > -10)
111     {
112     nb = n - 3 ;
113     iexpo = i - nb + 1 ;
114     val2 = val * pow((double)10.,(double)(nb-1-i)) ;
115     }
116     else if ((i - (n - 3) + 1) == -10)
117     {
118     nb = n - 4 ;
119     val2 = val * pow((double)10.,(double)(nb-1-i)) ;
120     val2 = ceil(val2) ;
121     j = val2 ;
122     strcat(ext,"E-09") ;
123     fprintf(output,"%-d%s",j,ext) ;
124     return ;
125     }
126     else
127     {
128     nb = n - 4 ;
129     iexpo = i - nb + 1 ;
130     val2 = val * pow((double)10.,(double)(nb-1-i)) ;
131     }
132     val2 = ceil(val2) ;
133     j = val2 ;
134     strcat(ext,"E") ;
135     m3d_itoa(iexpo, bufexpo) ;
136     strcat(ext,bufexpo);
137     fprintf(output,"%-d%s",j,ext) ;
138     }
139     }
140     return ;
141     }