ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_nastof.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 2633 byte(s)
Log Message:
structure de l'écriture

File Contents

# User Rev Content
1 francois 283 #include <stdio.h>
2     #include <math.h>
3     #include <string.h>
4     #include "m3d_const.h"
5     #include "m3d_hotes.h"
6     #include "m3d_struct.h"
7     #include "prototype.h"
8     #include <cstdlib>
9     void m3d_nastof(char *abuf,int *lg,float *resu,int *ierr)
10     {
11     char tabel[MAX_LINE] ;
12     char tabel2[MAX_LINE] ;
13     char tabel3[MAX_LINE] ;
14     int gtrouve = 0 ;
15     int i = 0, nb = 0, j=0 ;
16     int i_e = 0, i_point = 0, i_plus = 0, i_moins = 0, i_sign = 0;
17    
18     tabel2[0] = 0 ;
19     while (i<*lg)
20     {
21     tabel[0] = 0 ;
22     strncat(tabel,abuf+i,1) ;
23     if (strcmp (tabel," "))
24     {
25     strncat(tabel2,tabel,1) ;
26     nb++ ;
27     }
28     i++ ;
29     }
30     if (nb==0)
31     {
32     *resu = 0. ;
33     return ;
34     }
35     /* chaine de caracteres de dimension nb */
36     i = 0 ;
37     while (i<nb)
38     {
39     tabel[0] = 0 ;
40     strncat(tabel,tabel2+i,1) ;
41     if (!strcmp (tabel,"+")) i_sign ++ ;
42     else if (!strcmp (tabel,"-")) i_sign ++ ;
43     else if (!strcmp (tabel,".")) i_point ++ ;
44     else if (!strcmp (tabel,"E")) i_e ++ ;
45     else if (!strcmp (tabel,"e")) i_e ++ ;
46     i++ ;
47     }
48     if (i_e !=0)
49     {
50     *resu = (float)atof(tabel2) ;
51     return ;
52     }
53     if (i_sign == 0)
54     {
55     *resu = (float)atof(tabel2) ;
56     return ;
57     }
58     /* i_sign != 0 */
59     /* lecture du premier caractere de la nouvelle chaine */
60     tabel[0] = 0 ;
61     strncat(tabel,tabel2,1) ;
62     if (!strcmp (tabel,"-") || !strcmp (tabel,"+"))
63     {
64     if (i_sign == 1)
65     {
66     *resu = (float)atof(tabel2) ;
67     return ;
68     }
69     else
70     {
71     tabel[0] = 0 ;
72     strncat(tabel,tabel2,1) ;
73     j = 1 ;
74     while (j<nb)
75     {
76     tabel3[0] = 0 ;
77     strncat(tabel3,tabel2+j,1) ;
78     if ( !strcmp (tabel3,"-") || !strcmp (tabel3,"+") ) break ;
79     strncat(tabel,tabel2+j,1) ;
80     j++ ;
81     }
82     strncat(tabel,"E",1) ;
83     while (j<nb)
84     {
85     strncat(tabel,tabel2+j,1) ;
86     j++ ;
87     }
88     *resu = (float)atof(tabel) ;
89     return ;
90     }
91     }
92     tabel[0] = 0 ;
93     strncat(tabel,tabel2,1) ;
94     j = 1 ;
95     while (j<nb)
96     {
97     tabel3[0] = 0 ;
98     strncat(tabel3,tabel2+j,1) ;
99     if ( !strcmp (tabel3,"-") || !strcmp (tabel3,"+") ) break ;
100     strncat(tabel,tabel2+j,1) ;
101     j++ ;
102     }
103     strncat(tabel,"E",1) ;
104     while (j<nb)
105     {
106     strncat(tabel,tabel2+j,1) ;
107     j++ ;
108     }
109     *resu = (float)atof(tabel) ;
110     return ;
111     }
112