| [2480] | 1 | #include "sophyainit.h" | 
|---|
|  | 2 | #include "array.h" | 
|---|
|  | 3 | #include "fiondblock.h" | 
|---|
|  | 4 | #include "fioarr.h" | 
|---|
|  | 5 | #include "tarrinit.h" | 
|---|
|  | 6 |  | 
|---|
|  | 7 |  | 
|---|
|  | 8 | int main(int narg, char* arg[]) | 
|---|
|  | 9 | { | 
|---|
|  | 10 |  | 
|---|
|  | 11 | cout << " ------------------------------------------------ " << endl; | 
|---|
|  | 12 | cout << " ---------- Start of ppftswap program ----------- " << endl; | 
|---|
|  | 13 |  | 
|---|
|  | 14 | try { | 
|---|
|  | 15 | SophyaInit(); | 
|---|
|  | 16 | // Phase d'ecriture - remplissage de fichier PPF | 
|---|
|  | 17 | cout << ">>>> Create/Write PPF stream  ppfts.ppf " << endl; | 
|---|
|  | 18 | { | 
|---|
|  | 19 | #define DSZ_SWT  8 | 
|---|
|  | 20 | // Vecteur pour garder les positions des tableaux ecrits | 
|---|
|  | 21 | TVector<int_8> sw_fpos(10, BaseArray::RowVector); | 
|---|
|  | 22 | vector<int_8> swsvfp; | 
|---|
|  | 23 | // Tableau pour les donnees a ecrire (en mode swap) | 
|---|
|  | 24 | // ds le flot PPersist | 
|---|
|  | 25 | NDataBlock<int_4> sw_data(DSZ_SWT); | 
|---|
|  | 26 | // Objets divers a ecrire dans le meme flot | 
|---|
|  | 27 | NDataBlock<int_4> idb(16); | 
|---|
|  | 28 | idb = 16; | 
|---|
|  | 29 | NDataBlock<r_4> fdb(7); | 
|---|
|  | 30 | fdb = 4.5; | 
|---|
|  | 31 | TVector<int_4> iv(7, BaseArray::RowVector); | 
|---|
|  | 32 | iv = RegularSequence(5.,3.); | 
|---|
|  | 33 | TMatrix<r_4> mx(3,5); | 
|---|
|  | 34 | mx = RegularSequence(0.14,0.2); | 
|---|
|  | 35 | // ------------------------------------------------------------- | 
|---|
|  | 36 | // Generation de donnees et ecriture (pour lecture en mode swap) | 
|---|
|  | 37 | // ------------------------------------------------------------- | 
|---|
|  | 38 | POutPersist so("ppfts.ppf"); | 
|---|
|  | 39 | cout << " Writing data for testing swap ... " << endl; | 
|---|
|  | 40 | for(int i=0; i<sw_fpos.Size(); i++) { | 
|---|
|  | 41 | for(int j=0; j<sw_data.Size(); j++) sw_data(j) = i*100+j; | 
|---|
|  | 42 | // Ecriture de tag de positionnement | 
|---|
|  | 43 | sw_fpos(i) = so.WritePositionTag(); | 
|---|
|  | 44 | swsvfp.push_back(sw_fpos(i)); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | // Ecriture de donnees correspondantes | 
|---|
|  | 47 | // Il vaut mieux ne pas utiliser un objet a ce stade | 
|---|
|  | 48 | so.PutI4s(sw_data.Data(), sw_data.Size()); | 
|---|
|  | 49 | cout << "[" << i << "] Written data (Pos=" << sw_fpos(i) | 
|---|
|  | 50 | << ") : " << sw_data << endl; | 
|---|
|  | 51 | } | 
|---|
|  | 52 | // On ecrit d'autres objets | 
|---|
|  | 53 | cout << " Writing DataBlock idb= \n" << idb << endl; | 
|---|
|  | 54 | so << idb; | 
|---|
|  | 55 | cout << " Writing Vector iv" << iv << endl; | 
|---|
|  | 56 | so << iv; | 
|---|
|  | 57 | cout << " Writing DataBlock fdb with TagName FDB : \n" << fdb << endl; | 
|---|
|  | 58 | so << PPFNameTag("FDB") << fdb; | 
|---|
|  | 59 | cout << " Writing Matrix mtx with TagName MTX " << mx << endl; | 
|---|
|  | 60 | so << PPFNameTag("MTX") << mx; | 
|---|
|  | 61 | // On ecrit finalement Les Positions Tag | 
|---|
|  | 62 | string posttable="PosTagTable"; | 
|---|
|  | 63 | so.WriteNameTag(posttable); | 
|---|
|  | 64 | // Ecriture de la table des PositionTags | 
|---|
|  | 65 | // C'est cette methode qui doit etre utilisee en principe | 
|---|
|  | 66 | so.PutPosTagTable(swsvfp); | 
|---|
|  | 67 | // On ecrit aussi le TVecteur sw_fpos | 
|---|
|  | 68 | so.PutObject(sw_fpos); | 
|---|
|  | 69 |  | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
|  | 72 | // Phase de relecture | 
|---|
|  | 73 | cout << ">>>> Reading objects from PPF stream  ppfts.ppf " << endl; | 
|---|
|  | 74 | { | 
|---|
|  | 75 | TVector<int_8> sw_fpos; | 
|---|
|  | 76 | vector<int_8> swsvfp; | 
|---|
|  | 77 | NDataBlock<int_4> sw_data(DSZ_SWT); | 
|---|
|  | 78 | NDataBlock<int_4> idb; | 
|---|
|  | 79 | NDataBlock<r_4> fdb; | 
|---|
|  | 80 | TVector<int_4> iv; | 
|---|
|  | 81 | TMatrix<r_4> mx; | 
|---|
|  | 82 |  | 
|---|
|  | 83 | PInPersist si("ppfts.ppf"); | 
|---|
|  | 84 | si >> idb; | 
|---|
|  | 85 | cout << " Read-OK DataBlock idb= \n" << idb << endl; | 
|---|
|  | 86 | si.GetObject(iv); | 
|---|
|  | 87 | cout << " Read-OK Vector iv= " << iv << endl; | 
|---|
|  | 88 | si >> PPFNameTag("MTX") >> mx; | 
|---|
|  | 89 | cout << " Read-OK Matrix mx= " << mx << endl; | 
|---|
|  | 90 | string tname = "FDB"; | 
|---|
|  | 91 | si.GotoNameTag(tname); | 
|---|
|  | 92 | si >> fdb; | 
|---|
|  | 93 | cout << " Read-OK DataBlock fdb at tag FDB : \n" << fdb << endl; | 
|---|
|  | 94 | cout << " --- Reading PositionTagTable ... " << endl; | 
|---|
|  | 95 | si >> PPFNameTag("PosTagTable"); | 
|---|
|  | 96 | si >> sw_fpos; | 
|---|
|  | 97 | cout << " Read-OK sw_fpos= " << sw_fpos << endl; | 
|---|
|  | 98 | for(int i=0; i<sw_fpos.Size(); i++) { | 
|---|
|  | 99 | // On se positionne | 
|---|
|  | 100 | si.GotoPositionTag(sw_fpos(i)); | 
|---|
|  | 101 | // On lit le tableau | 
|---|
|  | 102 | si.GetI4s(sw_data.Data(), sw_data.Size()); | 
|---|
|  | 103 | cout << "[" << i << "] Read data (Pos=" << sw_fpos(i) | 
|---|
|  | 104 | << ") : " << sw_data << endl; | 
|---|
|  | 105 | } | 
|---|
|  | 106 | // On lit quand meme le PosTagTable pour verification | 
|---|
|  | 107 | cout << " Reading the PositionTagTable .... " << endl; | 
|---|
|  | 108 | si >> PPFNameTag("PosTagTable"); | 
|---|
|  | 109 | si.GetPosTagTable(swsvfp); | 
|---|
|  | 110 | for(int k=0; k<swsvfp.size(); k++) | 
|---|
|  | 111 | cout << swsvfp[k] << "  "; | 
|---|
|  | 112 | cout << endl; | 
|---|
|  | 113 | } | 
|---|
|  | 114 |  | 
|---|
|  | 115 | } | 
|---|
|  | 116 | catch (PThrowable & exc) { | 
|---|
|  | 117 | cerr << " ppftswap/Catched Exception " << (string)typeid(exc).name() | 
|---|
|  | 118 | << " - Msg= " << exc.Msg() << endl; | 
|---|
|  | 119 | } | 
|---|
|  | 120 | catch (...) { | 
|---|
|  | 121 | cerr << " ppftswap/some other exception was caught ! " << endl; | 
|---|
|  | 122 | } | 
|---|
|  | 123 |  | 
|---|
|  | 124 | cout << " ----------- End of ppftswap program ------------ " << endl; | 
|---|
|  | 125 | cout << " ------------------------------------------------ " << endl; | 
|---|
|  | 126 |  | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|