Changeset 1559 in Sophya for trunk/SophyaLib/BaseTools


Ignore:
Timestamp:
Jul 2, 2001, 6:14:58 PM (24 years ago)
Author:
ansari
Message:

Modif MuTyV pour decodage ASCII - Reza 2/7/2001

Location:
trunk/SophyaLib/BaseTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/mutyv.cc

    r1310 r1559  
    3232
    3333
    34 static void mutyv_decodestr(const char * si, double& r, double& im);
     34static void mutyv_decodestr(string const &, double& r, double& im);
     35static inline void mutyv_decodestr_cp(const char * si, double& r, double& im)
     36{
     37  r = im = 0.;
     38  string s = si;
     39  mutyv_decodestr(s, r, im);
     40}
    3541
    3642/* --Methode-- */
     
    106112    char buff[96];
    107113    if (typ == MTVInteger)  sprintf(buff,"%ld", (long)iv);
    108     else if (typ == MTVFloat) sprintf(buff,"%.20g", dv);
    109     else if (typ == MTVComplex) sprintf(buff,"(%.20g , %.20g)", dv, dv_im);
     114    else if (typ == MTVFloat) sprintf(buff,"%g", dv);
     115    else if (typ == MTVComplex) sprintf(buff,"(%g,%g)", dv, dv_im);
    110116    else buff[0] = '\0';
    111117    return(string(buff));
     
    114120
    115121
    116 static void mutyv_decodestr(const char * si, double& r, double& im)
     122
     123static void mutyv_decodestr(string const & s, double& r, double& im)
    117124  // decodage d'une chaine contenant une ou deux valeurs
    118125{
    119126  r = im = 0.;
    120   string s = si;
    121127  size_t l = s.length();
    122   size_t p = s.find_first_not_of(" ()\t",0);
     128  size_t p = s.find_first_not_of(" \t",0);
     129  size_t q,q2;
    123130  if (p >= l) return;
    124   size_t q = s.find_first_of(" ()\t",p+1);
    125  
    126  
     131  if (s[p] == '(') {  // C'est un complexe
     132    if ((q2=s.find(')',p)) >= l)  return;
     133    size_t pz = s.find_first_not_of(" \t",p+1);
     134    size_t qz = q2;
     135    if ((q=s.find(',',pz)) < q2) qz = q;
     136    if (isdigit(s[pz]) || !(s[pz] == '+') || (s[pz] == '-') ) 
     137      r = atof(s.substr(pz,qz-pz).c_str());
     138    else return;
     139    if (qz == q) {
     140      pz = s.find_first_not_of(" \t",qz+1);
     141      if (isdigit(s[pz]) || (s[pz] == '+') || (s[pz] == '-') ) 
     142        im = atof(s.substr(pz,q2-pz).c_str());     
     143    }
     144  }
     145
     146  q = s.find_first_of(" \t",p+1);
    127147  if (!isdigit(s[p]) && !(s[p] == '+') && !(s[p] == '-') )
    128148    return;
    129149  r = atof(s.substr(p,q-p).c_str());
    130 
    131   p = s.find_first_not_of(" ()\t",q+1);
    132   if (p >= l) return;
    133   q = s.find_first_of(" ()\t",p+1);
    134   if (!isdigit(s[p]) && !(s[p] == '+') && !(s[p] == '-') )
    135     return;
    136   im = atof(s.substr(p,q-p).c_str());
     150  im = 0.;
    137151}
    138152
  • trunk/SophyaLib/BaseTools/sversion.h

    r1555 r1559  
    33
    44#define SOPHYA_VERSION   1.1
    5 #define SOPHYA_REVISION  42
     5#define SOPHYA_REVISION  44
    66#define SOPHYA_TAG       "V_Jun2001"
    77
Note: See TracChangeset for help on using the changeset viewer.