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