Index: trunk/SophyaLib/BaseTools/ppersist.cc
===================================================================
--- trunk/SophyaLib/BaseTools/ppersist.cc	(revision 2430)
+++ trunk/SophyaLib/BaseTools/ppersist.cc	(revision 2441)
@@ -336,5 +336,5 @@
 //--
 {
-  s.WriteTag(tag);
+  s.WriteNameTag(tag);
   s.PutPPObject(this);
 }
@@ -431,12 +431,14 @@
   rbuf[32] = '\0'; 
   struct tm tm;
-  #if !(defined(__MWERKS__) || defined(OS_MACOSX))
+  /*  #if !(defined(__MWERKS__) || defined(OS_MACOSX))  RZ-DEL */
   strptime(rbuf,"%d/%m/%Y %H:%M:%S GMT",&tm);
-  #else
+  /*  #else
   sscanf(rbuf,"%2d/%2d/%4d %2d:%2d:%2d GMT",&tm.tm_mday,&tm.tm_mon,&tm.tm_year,
                                             &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
+
   tm.tm_mon  --;
   tm.tm_year -= 1900;
-  #endif
+  #endif    RZ-DEL */
+
   creationdate = mktime(&tm);
   filename = flnm;  // keep the filename
@@ -516,5 +518,5 @@
     if (ppstype == PPS_EOF) break;
     
-    if (ppstype != PPS_TAG)
+    if (ppstype != PPS_NAMETAG_TABLE)
       throw FileFormatExc("PInPersist::Scan   corrupted file, bad tag entry");
 
@@ -540,10 +542,21 @@
 
 bool 
-PInPersist::GotoTag(string const& name)
+PInPersist::GotoPositionTag(int_8 pos)
+{
+  s->seekg(pos);
+  int_8 tpos;
+  GetRawI8(tpos);
+  if (tpos != pos) 
+    throw FileFormatExc("PInPersist::GotoPositionTag() - Wrong tag position!");
+  return true;
+}
+
+bool 
+PInPersist::GotoNameTag(string const& name)
 {
   map<string, int_8>::iterator i = tags.find(name);
   if (i == tags.end()) 
     return false;
-      //    throw NotFoundExc("PInPersist::GotoTag   tag not found");
+      //    throw NotFoundExc("PInPersist::GotoNameTag   tag not found");
   s->seekg((*i).second);
   seqread = false;
@@ -551,4 +564,5 @@
   return(true); 
 }
+
 
 bool
@@ -625,7 +639,11 @@
 PInPersist::GetTypeTag(unsigned char& c) 
 {
-  c = PPS_TAG_MARK;
-  while (c == PPS_TAG_MARK) GetRawUByte(c);
-  //  while (c == PPS_TAG_MARK) {    Il ne faut plus faire ca !
+  int_8 tpos;
+  c = PPS_NAMETAG_MARK;
+  while ( (c == PPS_NAMETAG_MARK) || (c == PPS_POSTAG_MARK) ) {
+    GetRawUByte(c);
+    if (c == PPS_POSTAG_MARK)  GetRawI8(tpos);
+  } 
+  //  while (c == PPS_NAMETAG_MARK) {    Il ne faut plus faire ca !
   //    objList.clear();             $CHECK$ Reza 03/2000
   //    GetRawByte(c);
@@ -776,4 +794,32 @@
 
 void
+PInPersist::GetI1   (int_1& result)
+{
+  CheckTag(1,PPS_DATATYPE_INTEGER);
+  GetRawBytes(&result, sizeof(int_1));
+}
+
+void
+PInPersist::GetI1s  (int_1* tab, size_t n)
+{
+  CheckArrayTag(1,n,PPS_DATATYPE_INTEGER);
+  GetRawBytes(tab, n*sizeof(int_1));
+}
+
+void
+PInPersist::GetU1   (uint_1& result)
+{
+  CheckTag(1,PPS_DATATYPE_UNSIGNED);
+  GetRawBytes(&result, sizeof(uint_1));
+}
+
+void
+PInPersist::GetU1s  (uint_1* tab, size_t n)
+{
+  CheckArrayTag(1,n,PPS_DATATYPE_UNSIGNED);
+  GetRawBytes(tab, n*sizeof(uint_1));
+}
+
+void
 PInPersist::GetI2   (int_2& result)
 {
@@ -934,4 +980,94 @@
 }
 
+void
+PInPersist::GetZ4   (complex<r_4>& result)
+{
+  CheckTag(4,PPS_DATATYPE_COMPLEX);
+  r_4 reim[2];
+  GetRawBytes(reim, 2*sizeof(r_4));
+  if (bigEndian != IS_BIG_ENDIAN) {
+    bswap4(reim);
+    bswap4(reim+1);
+  }
+  result = complex<r_4>(reim[0], reim[1]);
+}
+
+void
+PInPersist::GetZ4s  (complex<r_4>* tab, size_t n)
+{  
+  CheckArrayTag(4,n,PPS_DATATYPE_COMPLEX);
+  GetRawBytes(tab, n*2*sizeof(r_4));
+  if (bigEndian == IS_BIG_ENDIAN) return;
+
+  r_4 * p = (r_4 *)tab;
+  for (unsigned int i=0; i<n; i++) {
+    bswap4(p);  p++;
+    bswap4(p);  p++;
+  }
+  return;
+}
+
+void
+PInPersist::GetZ8   (complex<r_8>& result)
+{
+  CheckTag(8,PPS_DATATYPE_COMPLEX);
+  r_8 reim[2];
+  GetRawBytes(reim, 2*sizeof(r_8));
+  if (bigEndian != IS_BIG_ENDIAN) {
+    bswap8(reim);
+    bswap8(reim+1);
+  }
+  result = complex<r_8>(reim[0], reim[1]);
+}
+
+void
+PInPersist::GetZ8s  (complex<r_8>* tab, size_t n)
+{
+  CheckArrayTag(8,n,PPS_DATATYPE_COMPLEX);
+  GetRawBytes(tab, n*2*sizeof(r_8));
+  if (bigEndian == IS_BIG_ENDIAN) return;
+
+  r_8 * p = (r_8 *)tab;
+  for (unsigned int i=0; i<n; i++) {
+    bswap8(p);  p++;
+    bswap8(p);  p++;
+  }
+  return;
+}
+
+
+void
+PInPersist::GetPosTagTable(int_8* ptab, size_t sz)
+{
+  unsigned char ppstype;
+  GetTypeTag(ppstype);
+  if (ppstype != PPS_POSTAG_TABLE) 
+    throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
+  int_4 tsz;
+  GetRawI4(tsz);
+  if (tsz != sz)
+    throw FileFormatExc("PInPersist::GetPosTagTable Size mismatch ");
+  for(int kk=0; kk<tsz; kk++)
+    GetRawI8(ptab[kk]);
+  return;
+}
+
+void
+PInPersist::GetPosTagTable(vector<int_8>& ptab)
+{
+  unsigned char ppstype;
+  GetTypeTag(ppstype);
+  if (ppstype != PPS_POSTAG_TABLE) 
+    throw FileFormatExc("PInPersist::GetPosTagTable  bad type in ppersist stream");
+  ptab.clear();
+  int_4 tsz;
+  GetRawI4(tsz);
+  int_8 tpos;
+  for(int kk=0; kk<tsz; kk++) {
+    GetRawI8(tpos);
+    ptab.push_back(tpos);
+  }
+  return;
+}
 
 PPersist*
@@ -1010,5 +1146,5 @@
 {
   unsigned char ppstag=0;
-  unsigned char ppst1,ppst2,ppst3;
+  unsigned char ppst1,ppst2,ppst3,ppst30;
   uint_8 cpos,fsize;
   uint_8 ui8,cid,oid;
@@ -1053,4 +1189,5 @@
     ppst2 = ppstag&0x30;  // bits     45
     ppst3 = ppstag&0xc0;  // bits       67
+    ppst30 = ppstag&0xc1; // bits 0     67
     if ((ppst2 == 0) && (ppst3 == 0) ) {
       switch (ppst1) {
@@ -1081,6 +1218,12 @@
 	break;
 
-      case PPS_TAG_MARK :
-	cout << "<PPS_TAG_MARK> tag at position " << hex << cpos << dec << endl; 
+      case PPS_NAMETAG_MARK :
+	cout << "<PPS_NAMETAG_MARK> tag at position " << hex << cpos << dec << endl; 
+	break;
+
+      case PPS_POSTAG_MARK :
+	GetRawI8(i8);	
+	cout << "<PPS_POSTAG_MARK> tag at position " << hex << cpos 
+	     << " TPos=" << i8 << dec << endl; 
 	break;
      
@@ -1091,5 +1234,11 @@
 	break;
 
-      case PPS_TAG :
+      case PPS_POSTAG_TABLE :
+	GetRawI4(i4);
+	for(int kkt=0; kkt<i4; kkt++)  GetRawI8(i8);	
+	cout << "<PPS_POSTAG_TABLE> tag at position " << hex << cpos << dec << endl; 
+	break;
+
+      case PPS_NAMETAG_TABLE :
 	GetRawI8(i8);
 	GetRawI4(i4);
@@ -1117,9 +1266,15 @@
     else {
       string dtype = "???? x";
-      if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
+      if (ppst30 == PPS_DATATYPE_COMPLEX) dtype = "COMPLEX x";
+      else if (ppst3 == PPS_DATATYPE_CHAR) dtype = "CHAR x";
       else if (ppst3 == PPS_DATATYPE_FLOAT) dtype = "FLOAT x";
       else if (ppst3 == PPS_DATATYPE_INTEGER) dtype = "INTEGER x";
       else if (ppst3 == PPS_DATATYPE_UNSIGNED) dtype = "UNSIGNED x";
       int_4 dsize = ppst1;
+      int_4 dsizeskip = dsize;
+      if (ppst30 == PPS_DATATYPE_COMPLEX) { 
+	dsize--;
+	dsizeskip = 2*dsize;
+      }
       char sb[16];
       sprintf(sb, "%d", dsize);
@@ -1131,5 +1286,5 @@
 	if (lev > 2)  cout << "<PPS_SIMPLE> tag at position " << hex << cpos << dec 
 			   << " DataType=" << dtype << endl;
-	s->seekg(dsize, ios::cur);
+	s->seekg(dsizeskip, ios::cur);
 	break;
 
@@ -1138,5 +1293,5 @@
 	if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY4> tag at position " << hex << cpos << dec 
 			   << " DataType=" << dtype << " NElts= " << i4 << endl;
-	s->seekg((uint_8)dsize*(uint_8)i4, ios::cur);
+	s->seekg((uint_8)dsizeskip*(uint_8)i4, ios::cur);
 	break;
 
@@ -1145,5 +1300,5 @@
 	if (lev > 0)  cout << "<PPS_SIMPLE_ARRAY8> tag at position " << hex << cpos << dec 
 			   << " DataType=" << dtype << " NElts= " << ui8 << endl;
-	s->seekg((uint_8)dsize*ui8, ios::cur);
+	s->seekg((uint_8)dsizeskip*ui8, ios::cur);
 	break;
       }
@@ -1247,7 +1402,7 @@
   // Output stream creation
   s = new ofstream(flnm.c_str(),ios::out | IOS_BIN);  
-
+  version = 3;
   // Header
-  PutRawBytes("SOS-SOPHYA-PPersistFile V2               ",32);
+  PutRawBytes("SOS-SOPHYA-PPersistFile V3               ",32);
   PutRawBytes(bigEndian 
 	   ? "BIG-ENDIAN                             "
@@ -1279,5 +1434,5 @@
       string name = (*i).first;
       int_8 pos = (*i).second;
-      PutRawUByte(PPS_TAG);                       // This is a tag
+      PutRawUByte(PPS_NAMETAG_TABLE);                       // This is a tag
       PutRawI8(pos);                             // position of previous tag
       PutRawI4(name.length());                   // length of the name
@@ -1291,13 +1446,26 @@
 }
 
-
-void
-POutPersist::WriteTag(string const& name)
+int_8
+POutPersist::WritePositionTag()
+{
+  int_8 tagpos;
+#ifdef STREAMPOS_IS_CLASS
+  tagpos = s->tellp().offset();
+#else
+  tagpos = s->tellp();
+#endif
+  PutRawByte(PPS_POSTAG_MARK);
+  PutI8(tagpos);
+  return(tagpos);
+}
+
+void
+POutPersist::WriteNameTag(string const& name)
 {
   if (name.length() > MAXTAGLEN) 
-    throw ParmError("POutPersist::WriteTag   tag name too long");
+    throw ParmError("POutPersist::WriteNameTag   tag name too long");
 
   if (tags.find(name) != tags.end())
-    throw DuplicateIdExc("POutPersist::WriteTag   duplicate tag name");
+    throw DuplicateIdExc("POutPersist::WriteNameTag   duplicate tag name");
 
   // Get current file position
@@ -1311,5 +1479,5 @@
 
   tags[name] = tagPos;
-  PutRawUByte(PPS_TAG_MARK);                       // This is a tag
+  PutRawUByte(PPS_NAMETAG_MARK);                       // This is a tag
   //  objList.clear(); // $CHECK$ EA 171199  - Ne pas faire ? Reza 03/2000
 }
@@ -1482,4 +1650,32 @@
 
 void
+POutPersist::PutI1   (int_1 val)
+{
+  PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_INTEGER);
+  PutRawBytes(&val, sizeof(int_1));
+}
+
+void
+POutPersist::PutI1s  (int_1 const* tab, size_t n)
+{
+  PutArrayTag(1, n, PPS_DATATYPE_INTEGER);
+  PutRawBytes(tab, n*sizeof(int_1));
+}
+
+void
+POutPersist::PutU1   (uint_1 val)
+{
+  PutRawUByte(PPS_SIMPLE + 1 + PPS_DATATYPE_UNSIGNED);
+  PutRawBytes(&val, sizeof(uint_1));
+}
+
+void
+POutPersist::PutU1s  (uint_1 const* tab, size_t n)
+{
+  PutArrayTag(1, n, PPS_DATATYPE_UNSIGNED);
+  PutRawBytes(tab, n*sizeof(uint_1));
+}
+
+void
 POutPersist::PutI2   (int_2 val)
 {
@@ -1660,4 +1856,92 @@
 
 void
+POutPersist::PutZ4   (complex<r_4> val)
+{
+  PutRawUByte(PPS_SIMPLE + 4 + PPS_DATATYPE_COMPLEX);
+  r_4 reim[2];
+  reim[0] = val.real();
+  reim[1] = val.imag();
+  if (bigEndian != IS_BIG_ENDIAN) {
+    bswap4(reim);
+    bswap4(reim+1);
+  }
+  PutRawBytes(reim, 2*sizeof(r_4));
+}
+
+void
+POutPersist::PutZ4s  (complex<r_4> const* tab, size_t n)
+{
+  PutArrayTag(4, n, PPS_DATATYPE_COMPLEX);
+
+  if (bigEndian == IS_BIG_ENDIAN) {
+    PutRawBytes(tab, n*2*sizeof(r_4));
+  } else {
+    for (unsigned int i=0; i<n; i++) {
+      r_4 reim[2];
+      reim[0] = tab[i].real();
+      reim[1] = tab[i].imag();
+      bswap4(reim);
+      bswap4(reim+1);
+      PutRawBytes(reim, 2*sizeof(r_4));
+    }
+  }
+}
+
+void
+POutPersist::PutZ8   (complex<r_8> val)
+{
+  PutRawUByte(PPS_SIMPLE + 8 + PPS_DATATYPE_COMPLEX);
+  r_8 reim[2];
+  reim[0] = val.real();
+  reim[1] = val.imag();
+  if (bigEndian != IS_BIG_ENDIAN) {
+    bswap8(reim);
+    bswap8(reim+1);
+  }
+  PutRawBytes(reim, 2*sizeof(r_8));
+}
+
+void
+POutPersist::PutZ8s  (complex<r_8> const* tab, size_t n)
+{
+  PutArrayTag(8, n, PPS_DATATYPE_COMPLEX);
+
+  if (bigEndian == IS_BIG_ENDIAN) {
+    PutRawBytes(tab, n*2*sizeof(r_8));
+  } else {
+    for (unsigned int i=0; i<n; i++) {
+      r_8 reim[2];
+      reim[0] = tab[i].real();
+      reim[1] = tab[i].imag();
+      bswap8(reim);
+      bswap8(reim+1);
+      PutRawBytes(reim, 2*sizeof(r_8));
+    }
+  }
+}
+
+void
+POutPersist::PutPosTagTable(int_8 const * ptab, size_t sz)
+{
+  PutRawUByte(PPS_POSTAG_TABLE);
+  int_4 tsz = sz;
+  PutRawI4(tsz);
+  for(int kk=0; kk<tsz; kk++)
+    PutRawI8(ptab[kk]);
+  return;
+}
+
+void
+POutPersist::PutPosTagTable(vector<int_8> const& ptab)
+{
+  PutRawUByte(PPS_POSTAG_TABLE);
+  int_4 tsz = ptab.size();
+  PutRawI4(tsz);
+  for(int kk=0; kk<tsz; kk++)
+    PutRawI8(ptab[kk]);
+  return;
+}
+
+void
 POutPersist::PutObject(AnyDataObj & o)
 {
@@ -1673,5 +1957,5 @@
 POutPersist::PutObject(AnyDataObj & o, string tagname)
 {
-  WriteTag(tagname);
+  WriteNameTag(tagname);
   PutObject(o);
 }
