| 1 | #include "sopnamsp.h" | 
|---|
| 2 | #include "machdefs.h" | 
|---|
| 3 | #include <math.h> | 
|---|
| 4 | #include <iostream> | 
|---|
| 5 | #include <stdio.h> | 
|---|
| 6 | #include <typeinfo> | 
|---|
| 7 |  | 
|---|
| 8 | // Pour | 
|---|
| 9 | #include <unistd.h> | 
|---|
| 10 | #include <fcntl.h> | 
|---|
| 11 | #include <sys/types.h> | 
|---|
| 12 | #include <sys/stat.h> | 
|---|
| 13 |  | 
|---|
| 14 | #include "pexceptions.h"  // les exceptions SOPHYA | 
|---|
| 15 |  | 
|---|
| 16 | #include "tvector.h" // Pour l'utilisation des classes TArray, TMatrix , TVector | 
|---|
| 17 | #include "fioarr.h"  // Pour IO PPF TArray | 
|---|
| 18 | #include "sopemtx.h" | 
|---|
| 19 | #include "matharr.h" | 
|---|
| 20 |  | 
|---|
| 21 | #include "fitsfile.h"     // Pour IO FITS TArray | 
|---|
| 22 | #include "fitsarrhand.h"     // Pour IO FITS TArray | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | // Pour l'initialisation des modules  TArray , FitsIOServer | 
|---|
| 26 | #include "tarrinit.h" | 
|---|
| 27 | #include "fiosinit.h" | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | #include "timing.h" | 
|---|
| 31 | #include "ctimer.h" | 
|---|
| 32 |  | 
|---|
| 33 | //----------------------------------------------------------- | 
|---|
| 34 |  | 
|---|
| 35 | static sa_size_t SIZE = 25000; | 
|---|
| 36 | static int NFILE = 10; | 
|---|
| 37 |  | 
|---|
| 38 | void tio_raw(); | 
|---|
| 39 | void tio_fraw(); | 
|---|
| 40 | void tio_ppf(); | 
|---|
| 41 | void tio_fits(); | 
|---|
| 42 |  | 
|---|
| 43 | /* -------------------------------------------------------- | 
|---|
| 44 | Programme de comparaison IO disk - manip BAO-Radio | 
|---|
| 45 | --------------------------------------------------------- */ | 
|---|
| 46 |  | 
|---|
| 47 | int main(int narg, char* arg[]) | 
|---|
| 48 | { | 
|---|
| 49 | // Sophya modules initialization | 
|---|
| 50 | TArrayInitiator  _inia; | 
|---|
| 51 | FitsIOServerInitiator  _inif; | 
|---|
| 52 | //------- AU LIEU DE ------>  SophyaInit(); | 
|---|
| 53 |  | 
|---|
| 54 | InitTim();   // Initializing the CPU timer | 
|---|
| 55 |  | 
|---|
| 56 | if (narg < 2) { | 
|---|
| 57 | cout << "  Usage: traidio SEL [Size [NFile]] \n" | 
|---|
| 58 | << "    SEL = raw OU fraw OU ppf  OU fits \n" | 
|---|
| 59 | << "    Size : taille tableau (int_4) \n" | 
|---|
| 60 | << "    NFile : Nb de fichiers \n" << endl; | 
|---|
| 61 | return 1; | 
|---|
| 62 | } | 
|---|
| 63 | string sel = arg[1]; | 
|---|
| 64 | if (narg > 2)  SIZE = atol(arg[2]); | 
|---|
| 65 | if (narg > 3)  NFILE = atoi(arg[3]); | 
|---|
| 66 | cout << " ====== traidio : SEL=" << sel << " Size=" << SIZE << " NFile= " << NFILE << endl; | 
|---|
| 67 | int rc = 0; | 
|---|
| 68 | try { | 
|---|
| 69 | if (sel == "raw") tio_raw(); | 
|---|
| 70 | else if (sel == "fraw") tio_fraw(); | 
|---|
| 71 | else if (sel == "ppf") tio_ppf(); | 
|---|
| 72 | else if (sel == "fits") tio_fits(); | 
|---|
| 73 | else { rc = 2; cout << " traidio/erreur : SEL non valide" << endl;} | 
|---|
| 74 | } | 
|---|
| 75 | catch (PThrowable& exc) { | 
|---|
| 76 | cerr << " traidio.cc catched Exception " << exc.Msg() << endl; | 
|---|
| 77 | rc = 77; | 
|---|
| 78 | } | 
|---|
| 79 | catch (std::exception& sex) { | 
|---|
| 80 | cerr << "\n traidio.cc std::exception :" | 
|---|
| 81 | << (string)typeid(sex).name() << "\n msg= " | 
|---|
| 82 | << sex.what() << endl; | 
|---|
| 83 | rc = 78; | 
|---|
| 84 | } | 
|---|
| 85 | catch (...) { | 
|---|
| 86 | cerr << " traidio.cc catched unknown (...) exception  " << endl; | 
|---|
| 87 | rc = 79; | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | cout << ">>>> traidio.cc ------- FIN ----------- RC=" << rc << endl; | 
|---|
| 91 | PrtTim("FIN traidio.cc"); | 
|---|
| 92 | return rc; | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | void tio_raw() | 
|---|
| 99 | { | 
|---|
| 100 | Timer tm("traidio/tio_raw"); | 
|---|
| 101 | TArray<int_4> ia(SIZE,0,0); | 
|---|
| 102 | ia = RegularSequence(); | 
|---|
| 103 | tm.Split("tio_raw/ia-OK"); | 
|---|
| 104 | char flnm[128]; | 
|---|
| 105 | for(int i=0; i<NFILE; i++) { | 
|---|
| 106 | sprintf(flnm, "traid%d.raw",i); | 
|---|
| 107 | string ss = flnm; | 
|---|
| 108 | cout << i << "-----> Creating file " << flnm << endl; | 
|---|
| 109 | int fid = -1; | 
|---|
| 110 | fid = open(flnm,O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR); | 
|---|
| 111 | if (fid < 0) { | 
|---|
| 112 | cout << i << " ERROR !!!! creating file " << flnm << endl; | 
|---|
| 113 | continue; | 
|---|
| 114 | } | 
|---|
| 115 | write(fid, ia.Data(), SIZE*sizeof(int_4)); | 
|---|
| 116 | close(fid); | 
|---|
| 117 | tm.Split("tio_raw/Write-Done"); | 
|---|
| 118 | } | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | void tio_fraw() | 
|---|
| 122 | { | 
|---|
| 123 | Timer tm("traidio/tio_fraw"); | 
|---|
| 124 | TArray<int_4> ia(SIZE,0,0); | 
|---|
| 125 | ia = RegularSequence(); | 
|---|
| 126 | tm.Split("tio_fraw/ia-OK"); | 
|---|
| 127 | char flnm[128]; | 
|---|
| 128 | for(int i=0; i<NFILE; i++) { | 
|---|
| 129 | sprintf(flnm, "traid%d.fraw",i); | 
|---|
| 130 | string ss = flnm; | 
|---|
| 131 | cout << i << "-----> Creating file " << flnm << endl; | 
|---|
| 132 | FILE* fip = NULL; | 
|---|
| 133 | fip = fopen(flnm,"w"); | 
|---|
| 134 | if (fip == NULL) { | 
|---|
| 135 | cout << i << " ERROR !!!! creating file " << flnm << endl; | 
|---|
| 136 | continue; | 
|---|
| 137 | } | 
|---|
| 138 | fwrite(ia.Data(), SIZE, sizeof(int_4), fip); | 
|---|
| 139 | fclose(fip); | 
|---|
| 140 | tm.Split("tio_fraw/Write-Done"); | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | void tio_ppf() | 
|---|
| 145 | { | 
|---|
| 146 | Timer tm("traidio/tio_ppf"); | 
|---|
| 147 | TArray<int_4> ia(SIZE,0,0); | 
|---|
| 148 | ia = RegularSequence(); | 
|---|
| 149 | tm.Split("tio_ppf/ia-OK"); | 
|---|
| 150 | char flnm[128]; | 
|---|
| 151 | for(int i=0; i<NFILE; i++) { | 
|---|
| 152 | sprintf(flnm, "traid%d.ppf",i); | 
|---|
| 153 | string ss = flnm; | 
|---|
| 154 | cout << i << "-----> Creating file " << flnm << endl; | 
|---|
| 155 | POutPersist po(ss); | 
|---|
| 156 | po << ia; | 
|---|
| 157 | tm.Split("tio_ppf/Write-Done"); | 
|---|
| 158 | } | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | void tio_fits() | 
|---|
| 162 | { | 
|---|
| 163 | Timer tm("traidio/tio_fits"); | 
|---|
| 164 | TArray<int_4> ia(SIZE,0,0); | 
|---|
| 165 | ia = RegularSequence(); | 
|---|
| 166 | tm.Split("tio_fits/ia-OK"); | 
|---|
| 167 | char flnm[128]; | 
|---|
| 168 | for(int i=0; i<NFILE; i++) { | 
|---|
| 169 | sprintf(flnm, "!traid%d.fits",i); | 
|---|
| 170 | string ss = flnm; | 
|---|
| 171 | cout << i << "-----> Creating file " << flnm << endl; | 
|---|
| 172 | FitsOutFile fo(ss); | 
|---|
| 173 | fo << ia; | 
|---|
| 174 | tm.Split("tio_fits/Write-Done"); | 
|---|
| 175 | } | 
|---|
| 176 | } | 
|---|