Script bash pour récup nom de fichier

Résolu/Fermé
christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008 - 4 juin 2008 à 14:21
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 - 4 juin 2008 à 19:04
Bonjour,

je souhaiterai faire un script bash permettant de récupérer les noms de fichiers souhaité d'un fichiers comment faire?
Après je voudrais me reservir de ces noms de fichiers pour pouvoir m'en reservir pour les faire tourner et tracer des graphe histogramme en série

Merci d'avance
A voir également:

3 réponses

HostOfSeraphim Messages postés 6750 Date d'inscription jeudi 2 février 2006 Statut Contributeur Dernière intervention 31 juillet 2016 1 608
4 juin 2008 à 14:22
Les noms de fichiers souhaité d'un fichier...

Tu peux expliquer plus clairement, stp ? Merci !

0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 897
4 juin 2008 à 14:40
Salut,

Non c'est pas clair ;-((

Il nous faut un exemple de l'arborescence de ton dossier, et un exemple de ce que tu veux récupérer...
0
christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008 1
4 juin 2008 à 14:53
ok je vous le met arborecence:
/home/sotty/Bureau/Stage_bossage/28-03-08/ et là dedans j'ai des fichiers dont je veux récupérer les noms

pour faire tourner la routine drawframe( ) et stats ( ) du fichier snap.cxx

//////////////////////////////////////////readFrame.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include "constant_fpga.h"
#include <string.h>
/* #include <sys/types.h> */
#include <fcntl.h>
#include <linux/types.h>

#define FALSE 0
#define TRUE 1
#define SWAP FALSE
#define HEADER_SIZE 19

int readU32( unsigned int *, FILE*, int);
int swapU16 ( unsigned short * );
unsigned short** readDataByFrame( FILE *fp, unsigned long numFrame, unsigned long *header);
unsigned long *readHeader(FILE *fp);

void close_all();

FILE *fp_raw;

#define REF(f,i,j) f[j][i*2+1]
#define OUT7(f,i,j) f[j][i*2]

extern char *optarg;
extern int optind, opterr, optopt;

void usage(char *progname);


int main(argc, argv)
int argc;
char **argv;

/* main begin */
{

unsigned int dataIn;
unsigned long *dataHeader;
unsigned short adcTestMode;
unsigned short resetMode;
unsigned short outputMode;
unsigned short readoutMode;
unsigned short windowMode;
unsigned short debugMatrixEnb;
unsigned short nbBurst;
unsigned short nbFrame;
unsigned short burstDelay;
unsigned short burstDelayRange;
unsigned short adcFrequencyDiv;
unsigned long adcFrequency;
unsigned short pixelResetWidth;
unsigned short rowResetWidth;
unsigned short startRow;
unsigned short stopRow;
unsigned short startPixel;
unsigned short stopPixel;
unsigned short startRowima;
unsigned short stopRowima;
unsigned short startPixelima;
unsigned short stopPixelima;
unsigned long frameSize;
unsigned long dataSize;
unsigned short numFrame;
int opt;
int nfra,ind,icold,nframax,nfrafirst,indl,iscan,jscan,ii,jj,ik,jk;
float zfra[1024][1024];

char file_raw[200];
int i,j;
unsigned short **frame;

if( argc != 3 )
{
printf("USAGE %s <binary data File> <num frame>\n", argv[0]);
return 0;
}

strcpy(file_raw, argv[1]);
fp_raw=fopen(file_raw,"r");

if( fp_raw == NULL)
{
printf("Can't open file %s not found or acces denied \n", argv[1]);
return -1;
}
nframax = atoi(argv[2]);


dataHeader = readHeader(fp_raw);
if( dataHeader[0] != 0x01234567 || dataHeader[18] != 0x89ABCDEF )
{
printf("Invalid Header\n");
close_all();
return 1;
}

adcTestMode = (dataHeader[1] & (0x1));
resetMode = (dataHeader[2] & (0x1));
outputMode = (dataHeader[3] & (0x1)) ? DUAL : SINGLE;
readoutMode = (dataHeader[4] & (0x1)) ? FAST : SLOW;
windowMode = (dataHeader[5] & (0x1)) ? WINDOW_MODE_ENB : WINDOW_MODE_DIS;
debugMatrixEnb = (dataHeader[6] & (0x1));
nbBurst = dataHeader[7];
nbFrame = dataHeader[8];
burstDelay = dataHeader[9];
burstDelayRange = dataHeader[10];
adcFrequencyDiv = (readoutMode == SLOW) ? (dataHeader[11] & 0x3) : ((dataHeader[11] & 0xC) >> 2);
pixelResetWidth = dataHeader[12];
rowResetWidth = dataHeader[13];
startRow = dataHeader[14];
stopRow = dataHeader[15];
startPixel = dataHeader[16];
stopPixel = dataHeader[17];
adcFrequency = (readoutMode == SLOW) ? 100 : 2000;
adcFrequency = adcFrequency / (unsigned long)( powl(2.0, (double)(adcFrequencyDiv)));

if (adcTestMode != 0)
{
printf("Invalid data file adcTestMode=1 !\n");
close_all();
return 1;
}

if (debugMatrixEnb != 0)
{
printf("Invalid data file debugMatrixEnb=1 !\n");
close_all();
return 1;
}

nframax = nbFrame*nbBurst;

printf(" %d %d %d %d %d %d\n",nbFrame,nbBurst,startRow,stopRow,startPixel,stopPixel);

for (nfra = 0 ; nfra <nframax ; nfra++) /* start loop on frames */
{
numFrame = nfra;

if (numFrame >= nbFrame*nbBurst )
{
numFrame = nbFrame*nbBurst-1;
printf("Warning invalid frame number max in this file is %d\n", numFrame);
}

frame= readDataByFrame(fp_raw, numFrame, dataHeader);

if(frame==NULL)
{
printf("Read error \n");
close_all();
return(1);
}

printf(" %d\n",nfra);

for(jj=startRow; jj<=stopRow; jj++)
{
for(ii=startPixel; ii<=stopPixel; ii++)
{
i=ii-startPixel;
j=jj-startRow;
zfra[i][j]=REF(frame,i,j);
printf("% 7.0f",zfra[i][j]);
}
printf("\n");
}
printf("\n");

for(jj=startRow; jj<=stopRow; jj++)
{
for(ii=startPixel; ii<=stopPixel; ii++)
{
i=ii-startPixel;
j=jj-startRow;
/* printf(" %ld",OUT7(frame,i,j)); */
zfra[i][j]=OUT7(frame,i,j);
printf("% 7.0f",zfra[i][j]);
}
printf("\n");
}


free(frame);

} /* end loop on frames compute averages */



fflush(NULL);



close_all();
return 0;

} /* end main */


unsigned short** readDataByFrame( FILE *fp, unsigned long numFrame, unsigned long *header )
{
unsigned short **frame;
unsigned short startRow;
unsigned short stopRow;
unsigned short startPixel;
unsigned short stopPixel;
unsigned short startRowima;
unsigned short stopRowima;
unsigned short startPixelima;
unsigned short stopPixelima;


unsigned long frameSize;
unsigned long dataSize;
unsigned short windowMode;
unsigned short outputMode;
unsigned short dimx;
unsigned short dimy;
unsigned short dimxima;
unsigned short dimyima;
unsigned short lengthx;
int j;

windowMode = (header[5] & (0x1)) ? WINDOW_MODE_ENB : WINDOW_MODE_DIS;
outputMode = (header[3] & (0x1)) ? DUAL : SINGLE;
startRow = header[14];
stopRow = header[15];
startPixel = header[16];
stopPixel = header[17];

if(windowMode != WINDOW_MODE_ENB)
{
startRow = 0;
stopRow = 1023;
startPixel = 0;
stopPixel = 1023;
}


dimx = (stopPixel-startPixel + 1);
dimy = (stopRow-startRow + 1);

lengthx = (outputMode == DUAL) ? dimx*3 : dimx*2;

frameSize = (stopRow-startRow+1) * (stopPixel-startPixel+1);

dataSize = (outputMode == DUAL) ? frameSize*3 + 2 : frameSize*2 +2; /* size in 16 bits words */

/* rewind(fp); */

fseek(fp, HEADER_SIZE*4+ numFrame*dataSize*2, SEEK_SET);

frame = (unsigned short **)(malloc(sizeof(unsigned short *)*dimy));
if(frame==NULL)
{
printf("Can't allocate memory\n");
return(NULL);
}

for(j=0 ; j<dimy ; j++){
frame[j] = (unsigned short *)(malloc(sizeof(unsigned short)*(lengthx)));
if(frame[j]==NULL) {
printf("Can't allocate memory\n");
return(NULL);
}
fread(frame[j], sizeof(unsigned short), lengthx, fp);
}


return(frame);
}


unsigned long *readHeader(FILE *fp)
{
unsigned long *pt;

pt = (unsigned long*)(malloc(sizeof(unsigned long) * HEADER_SIZE) );

fread(pt, sizeof(unsigned long), HEADER_SIZE, fp);


return pt;
}





/******************************************
/* */
/* SWAP 2 BYTES of a 16 bits WORD */
/* */
/******************************************/

int swapU16( sbuf)
unsigned short * sbuf;
{
unsigned short lsb, msb;

if ( sbuf != NULL ) {
lsb = *sbuf << 8;
msb = *sbuf >> 8;
*sbuf = lsb | msb;
return 1;
}
else
return 0;
}

//********************************************
/* */
/* READ 2 BYTES in the file pointed by fp */
/* and SWAP if SW is TRUE */
/* - */
//********************************************/

int readU16(buf, fp, sw)
unsigned short * buf;
FILE *fp;
int sw;
{
unsigned short tmp_buf;

if (buf != NULL)
{
if (sw == TRUE) {
if(fread(&tmp_buf, 2, 1, fp) != 0){
swapU16(&tmp_buf);
*buf = tmp_buf;
return(1);}
else
return(0);
}
else {

fread(buf, 2, 1, fp);

return(1);
}
}
else
return(0);


}

//********************************************
/* */
/* READ 4 BYTES in the file pointed by fp */
/* and SWAP in the following way */
/* */
/* 1234 2143 */
/* */
/********************************************/

int readU32(buf, fp, sw )
unsigned int * buf;
FILE *fp;
int sw;
{
unsigned short sbuf_lsb;
unsigned int buf_tmp;
unsigned int buf_msb;
unsigned int buf_lsb;
unsigned short sbuf_msb;

if ( buf != NULL ) {
if (sw == TRUE) {
if (fread(&buf_tmp, 4, 1, fp) != 0 ) {
sbuf_msb = (buf_tmp >> 16);
swapU16(&sbuf_msb);
sbuf_lsb = buf_tmp;
swapU16(&sbuf_lsb);
buf_msb = sbuf_msb;
buf_lsb = sbuf_lsb;
*buf = (buf_lsb >> 16 ) | buf_msb;
return 1;}
else
return 0;}
else {
return(fread(buf, 4, 1, fp)); }
}
else
return 0;
}

/******************************************/
/* */
/* Close all files and free memory */
/* */
/******************************************/

void close_all()
{
fclose(fp_raw);
}
///////////////////////////////////////////constant_fpga.h

#ifndef _CONSTANT_FPGA_H
#define _CONSTANT_FPGA_H

#define JTAG_MODE (0x1)

#define SOFT_FPGA_RESET (0x1 << 5)
#define LOCK2_FPGA (0x1 << 6)
#define LOCK4_FPGA (0x1 << 7)

#define LOCK2_FPGA_VAL(d) ((LOCK2_FPGA & d) >> 6)
#define LOCK4_FPGA_VAL(d) ((LOCK4_FPGA & d) >> 7)

/****************************************/
/* Configure the GPIO pin dir in util.c */
/****************************************/
#define GPIOA_1 (0x1 << 1) /* dual purpose R22 => pin Mezz_93 */
#define GPIOA_3 (0x1 << 3) /* dual purpose R18 => pin Mezz_89 */
#define GPIOA_4 (0x1 << 4) /* dual purpose R19 => pin Mezz_86 */

#define GPIOB_0 (0x1) /* dual purpose R3 => pin Mezz_35 */
#define GPIOB_1 (0x1 << 1) /* dual purpose R9 => pin Mezz_34 */
#define GPIOB_2 (0x1 << 2) /* dual purpose R23 => pin Mezz_94 */
#define GPIOB_3 (0x1 << 3) /* dual purpose R24 => pin Mezz_95 */


#define TMS (0x1 << 1)
#define TDI (0x1)
#define TCK (0x1 << 2)
#define TDO (0x1 << 3)

#define OPERA 0x11
#define OPERA_RPC 0x12
#define OPERA_TDC 0x13
#define CRTBT 0x21
#define ROCKWELL 0x33

#define FIRMWARE_VERION 0x1A
#define REG_FIFO_CONFIG (0x0)
#define REG_IRQ_STATUS (0x18)
#define FIFO_RDO_ADDR (0x0)
#define REG_DATA_FIFO_STAT (0x2)
#define REG_FIFO_PAE_OFFSET (0x34)
#define REG_FIFO_PAF_OFFSET (0x36)

#define DFIFO_HF(d) ((d & 0x400) >> 10)
#define DFIFO_PAE(d) ((d & 0x800) >> 11)
#define DFIFO_PAF(d) ((d & 0x200) >> 9)
#define DFIFO_EF(d) ((d & 0x1000) >> 12)
#define DFIFO_FF(d) ((d & 0x80) >> 8)

#define CMD_FIFO_MASTER_RESET (0x2000)
#define CMD_FIFO_PARTIAL_RESET (0x2002)
#define CMD_CLR_IRQ (0x2010)

#define FIFO_BE (0x1)
#define FIFO_BM (0x1 << 1)
#define FIFO_OW (0x1 << 2)
#define FIFO_IW (0x1 << 3)
#define FIFO_FWFT (0x1 << 4)
#define FIFO_RTM (0x1 << 5)
#define FIFO_PFM (0x1 << 6)
#define FIFO_IP (0x1 << 7)
#define FIFO_LD (0x1 << 8)
#define FIFO_FSEL0 (0x1 << 9)
#define FIFO_FSEL1 (0x1 << 10)


#define IDT_FIFO_FULL 131072
#define IDT_FIFO_HALF_FULL 65537

/**** H1RG readout control ****/

#define H1RG_READOUT_CTRL_REG 0x4

/*** H1RG cyclone registers address ***/

#define I2C_ADDR 0x4000
#define I2C_DATA_WR 0x4002
#define I2C_DATA_RD 0x4020
#define I2C_STAT 0x4004
#define I2C_RESET 0x4004
#define DAC_CONTROL 0x4006
#define ADC_CONTROL 0x4008
#define H1RG_SERIAL_DATAIN 0x400A
#define H1RG_SERIAL_DATAOUT 0x4022
#define H1RG_RESET_WIDTH 0x400C
#define H1RG_FRAME_BURST_DELAY 0x400E
#define H1RG_FRAME_BURST_CONTROL 0x401E
#define H1RG_READOUT_CONTROL 0x4010
#define H1RG_NORMAL_MODE_REG 0x401A
#define H1RG_WINDOW_MODE_REG 0x401C
#define H1RG_VERT_START_REG 0x4012
#define H1RG_VERT_STOP_REG 0x4014
#define H1RG_HORI_START_REG 0x4016
#define H1RG_HORI_STOP_REG 0x4018

#define MISC_ADDR (0x7 << 12) /* "0111" */
#define OPTIONS_ADDR (0xD << 12) /* "1101" */
#define OUTPUT_MODE_ADDR (0x3 << 12) /* "0011" */

#define HMODE_BIT(d) ( (d != 0) ? (0x1 << 1) : 0)
#define HMODWM_BIT(d) ( (d != 0) ? (0x1 << 1) : 0)
#define HWMEN_BIT(d) ( (d != 0) ? (0x1 << 1) : 0)
#define VWMEN_BIT(d) ( (d != 0) ? (0x1 ) : 0)
#define IFCTRL_BIT(d) ( (d != 0) ? (0x1 << 2) : 0)
#define DOEN_BIT(d) ( (d != 0) ? (0x1 << 3) : 0)
#define REFROW_BIT(d) ( (d != 0) ? (0x1 << 7) : 0)

#define BY_ROW 0x0
#define BY_PIXEL (0x2 << 4)
#define DUAL (0x1 << 3)
#define SINGLE 0x0
#define FAST (0x1 << 2)
#define SLOW 0x0
#define WINDOW_MODE_ENB (0x1 << 1)
#define WINDOW_MODE_DIS (0x0 )

#define ACQUISITION_ENB (0x1 << 1)
#define IRQ_FIFO_FLAG(d) ( (d & 0x7) << 3)


#define DEFAULT_VERT_SIZE 1024
#define DEFAULT_HORI_SIZE 1024
#define DEFAULT_START_ROW 0
#define DEFAULT_STOP_ROW (DEFAULT_VERT_SIZE-1)
#define DEFAULT_START_PIXEL 0
#define DEFAULT_STOP_PIXEL_1 (DEFAULT_HORI_SIZE-1)
#define DEFAULT_STOP_PIXEL_2 ((DEFAULT_HORI_SIZE/2)-1)

#define DEBUG_VERT_SIZE 10
#define DEBUG_HORI_SIZE 10
#define DEBUG_START_ROW 0
#define DEBUG_STOP_ROW (DEBUG_VERT_SIZE-1)
#define DEBUG_START_PIXEL 0
#define DEBUG_STOP_PIXEL_1 (DEBUG_HORI_SIZE-1)
#define DEBUG_STOP_PIXEL_2 ((DEBUG_HORI_SIZE/2)-1)

#define DEBUG_MATRIX_ENB (0x1 << 6)
#define ADC_TEST_MODE (0x1 << 14)

#define X1 0
#define X10 (0x1 << 14)
#define X100 (0x2 << 14)
#define X1000 (0x3 << 14)


#define I2C_AD7418_ADDR (0x50)
#define I2C_WRITE_MODE (0x0)
#define I2C_READ_MODE (0x1)
#define I2C_ONE_BYTE (0x0)
#define I2C_TWO_BYTE (0x100)

#define I2C_SUCCESS_BIT 1
#define I2C_READY_BIT 0
#define I2C_BUS_BUSY_BIT 2
#define I2C_ARB_LOST_BIT 3

#define I2C_SUCCESS(d) ((d & (0x1 << I2C_SUCCESS_BIT)) >> I2C_SUCCESS_BIT)
#define I2C_READY(d) ((d & (0x1 << I2C_READY_BIT)) >> I2C_READY_BIT)
#define I2C_BUS_BUSY(d) ((d & (0x1 << I2C_BUS_BUSY_BIT)) >> I2C_BUS_BUSY_BIT)
#define I2C_ARB_LOST(d) ((d & (0x1 << I2C_ARB_LOST_BIT)) >> I2C_ARB_LOST_BIT)


#define DAC_DATA (0x0FFF)
#define DAC_1 (0x4000)
#define DAC_2 (0x8000)
#define DAC_CHAN_A (0x0000)
#define DAC_CHAN_B (0x1000)

#endif

////////////////////////////////////////////////////////////smap.cxx
#include <iostream>
using namespace std;
#include "SnapFile.hh"

void stats(char* fname)
{
cout << "Read data...\n";
SnapFile f(fname);
f.Info();

cout << "Calculation...\n";
// Wanna see ref and out7



// prepare arrays for mean and sigma of d (d = {Data - Ref}_i - {Data - Ref}_i-1) for each pixel
const int npix = f.rows*f.cols; // total number of pixels
float* mean = new float[npix];
float* sigma = new float[npix];
for (int i = 0; i < npix; i++)
mean[i] = sigma[i] = 0.;

// first step is filling these arrays with summs of d and d^2
for (int i = 1; i < f.frames; i++)
for (int r = 0; r < f.rows; r++)
for (int c = 0; c < f.cols; c++) {
float d = f.Adjusted(i, r, c) - f.Adjusted(i-1, r, c);
mean[r*f.cols + c] += d;
sigma[r*f.cols + c] += d*d;
}

// and now we calculate mean and sigma itself
const int N = f.frames - 1;
for (int i = 0; i < npix; i++) {
mean[i] /= N;
sigma[i] = sqrt(sigma[i]/N - mean[i]*mean[i]);
}

cout << "Histograming...\n";
TCanvas* cnv = new TCanvas("SNAP", "SNAP", 0, 0, 1400, 850);
cnv->Divide(2, 2, 0.005, 0.005);
gStyle->SetPalette(1);
gStyle->SetOptStat("nemruo");

// dependance of slope and dispersion on pixel position
TH2F* histSlope = new TH2F("slope", "Slope;row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
TH2F* histDispersion = new TH2F("dispersion", "Dispersion;row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
// histograms of slope and dispersion of all pixel
TH1F* histS = new TH1F("slope_dist", "Slope distribution", 100, -5., 5.);
TH1F* histD = new TH1F("dispersion_dist", "Dispersion distribution", 100, 5., 25.);



for (int r = 0; r < f.rows; r++)
for (int c = 0; c < f.cols; c++) {
histSlope->SetBinContent(r+1, c+1, mean[r*f.cols + c]);
histDispersion->SetBinContent(r+1, c+1, sigma[r*f.cols + c]);
histS->Fill(mean[r*f.cols + c]);
histD->Fill(sigma[r*f.cols + c]);
}



cnv->cd(1)->SetPhi(30+180); histSlope->Draw("LEGO2");
// cnv->cd(1)->SetPhi(30+180); histSlope->Draw("COLZ");
cnv->cd(2)->SetPhi(30+180); histDispersion->Draw("LEGO2");
// cnv->cd(2)->SetPhi(30+180); histDispersion->Draw("COLZ");
cnv->cd(3); histS->Draw();
cnv->cd(4); histD->Draw();
}

// displays specified frame
// and specified pixel
// opt=0 - colz; =1 - lego
void drawframe(char* fname, int frame = 10, int row = 50, int col = 45, int opt=1)
{
cout << "Read data...\n";
SnapFile f(fname);
f.Info();

cout << "Histograming...\n";
stringstream s;
s << "H1RG: " << fname << " | frame = " << frame << " | pixel[row:column] = " << row << ":" << col;
TCanvas* c = new TCanvas("SNAP", s.str().c_str(), 0, 0, 1400, 850);
gStyle->SetOptStat(kFALSE);
c->Divide(4, 2, 0.005, 0.005);
gStyle->SetPalette(1);

TH2I* histData = new TH2I("data", "Data frame;row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
TH2I* histRef = new TH2I("ref", "Reference frame;row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
TH2I* histAdj = new TH2I("adj", "Calibrated frame (Data-Ref);row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
TH2I* histDiff = new TH2I("diff", "Frames difference;row;col", f.rows, 0, f.rows, f.cols, 0, f.cols);
for (int i = 0; i < f.rows; i++)
for (int j = 0; j < f.cols; j++) {
histRef->SetBinContent(i+1, j+1, f.Ref(frame, i, j));
histData->SetBinContent(i+1, j+1, f.Data(frame, i, j));
histAdj->SetBinContent(i+1, j+1, f.Adjusted(frame, i, j));
histDiff->SetBinContent(i+1, j+1, f.Adjusted(frame, i, j)-f.Adjusted(frame-1, i, j));
}
if (opt==1) {
c->cd(1); histData->Draw("COLZ");
c->cd(2); histRef->Draw("COLZ");
c->cd(3); histAdj->Draw("COLZ");
c->cd(4); histDiff->Draw("COLZ");
}else {
c->cd(1); histData->Draw("LEGO2");
c->cd(2); histRef->Draw("LEGO2");
c->cd(3); histAdj->Draw("LEGO2");
c->cd(4); histDiff->Draw("LEGO2");
}

TH1I* histRefPixel = new TH1I("ref_pixel", "Reference pixel value;frame", f.frames, 0, f.frames);
TH1I* histDataPixel = new TH1I("data_pixel", "Data pixel value;frame", f.frames, 0, f.frames);
TH1I* histAdjPixel = new TH1I("calibrated_pixel", "Calibrated pixel value (Data-Ref);frame", f.frames, 0, f.frames);
TH1I* histDiffPixel = new TH1I("diff_pixel", "Diff pixel value;frame", f.frames-1, 1, f.frames);
for (int i = 0; i < f.frames; i++) {
histRefPixel->SetBinContent(i+1, f.Ref(i, row, col));
histDataPixel->SetBinContent(i+1, f.Data(i, row, col));
histAdjPixel->SetBinContent(i+1, f.Adjusted(i, row, col));
if (i > 0)
histDiffPixel->SetBinContent(i, f.Adjusted(i, row, col)-f.Adjusted(i-1, row, col));
}

c->cd(5); histDataPixel->SetLineColor(kBlue); histDataPixel->Draw();
c->cd(6); histRefPixel->SetLineColor(kRed); histRefPixel->Draw();
c->cd(7); histAdjPixel->SetLineColor(kGreen); histAdjPixel->Draw();
c->cd(8); histDiffPixel->Draw();
}

void header(char* fname)
{
cout << "Read data...\n";
SnapFile f(fname);
f.Info();

}
///////////////////////////////////////////////////SnapFile.hh
#ifndef SnapFile_hh
#define SnapFile_hh

#include <iostream>
#include <fstream>
#include "constant_fpga.h"

// header structure
// 19 x DWORD
typedef struct {
unsigned long header; // file signature
unsigned long adcTestMode;
unsigned long resetMode;
unsigned long outputMode;
unsigned long readoutMode;
unsigned long windowMode;
unsigned long debugMatrixEnb;
unsigned long nbBurst;
unsigned long nbFrame;
unsigned long burstDelay;
unsigned long burstDelayRange;
unsigned long adcFrequencyDiv;
unsigned long pixelResetWidth;
unsigned long rowResetWidth;
unsigned long startRow;
unsigned long stopRow;
unsigned long startPixel;
unsigned long stopPixel;
unsigned long footer; // file signature
} SnapHeader;

class SnapFile {
public:
SnapFile(char* fname);
~SnapFile();

void Info();
// reference pixel data
inline unsigned short Ref(int nFrame, int row, int col);
// regular pixel data
inline unsigned short Data(int nFrame, int row, int col);
// calibrated pixel data (Data - Ref)
inline int Adjusted(int nFrame, int row, int col);
// number of frames, rows and cols in file
unsigned long frames, rows, cols;

private:
SnapHeader h;
unsigned short* data;
unsigned long rowSize, frameSize;
};

SnapFile::SnapFile(char* fname)
{
// open data file
std::ifstream f(fname, std::ifstream::binary);
if (!f)
throw "Can't open file";

// read & check & correct header
f.read((char*) &h, sizeof(h));
if (h.header != 0x01234567 || h.footer != 0x89ABCDEF)
throw "Invalid header";

// ??? - masks?
h.adcTestMode = (h.adcTestMode & 0x1);
h.resetMode = (h.resetMode & 0x1);
h.outputMode = (h.outputMode & 0x1) ? DUAL : SINGLE;
h.readoutMode = (h.readoutMode & 0x1) ? FAST : SLOW;
h.windowMode = (h.windowMode & 0x1) ? WINDOW_MODE_ENB : WINDOW_MODE_DIS;
h.debugMatrixEnb = (h.debugMatrixEnb & 0x1);
h.adcFrequencyDiv = (h.readoutMode == SLOW) ? (h.adcFrequencyDiv & 0x3) : ((h.adcFrequencyDiv & 0xC) >> 2);
if (h.windowMode != WINDOW_MODE_ENB) {
h.startRow = DEFAULT_START_ROW; h.stopRow = DEFAULT_STOP_ROW;
h.startPixel = DEFAULT_START_PIXEL; h.stopPixel = DEFAULT_STOP_PIXEL_1;
}

// check for test or debug type of data file
if (h.adcTestMode != 0)
throw "Invalid data file adcTestMode=1 !";

if (h.debugMatrixEnb != 0)
throw "Invalid data file debugMatrixEnb=1 !";

// read data to internal buffer
// For feb 08 H1Rg data nnbFrame=10 in the Header but is 1 in the data

h.nbFrame = 1;

frames = h.nbFrame*h.nbBurst;
rows = (h.stopRow-h.startRow + 1);
cols = (h.stopPixel-h.startPixel + 1);
rowSize = (h.outputMode == DUAL) ? 3*cols : 2*cols; // in WORDs
frameSize = rowSize*rows + 2; // in WORDs
data = new unsigned short[frames*frameSize];
f.read((char*) data, frames*frameSize*sizeof(unsigned short));
if (f.bad())
throw "Data read error";

// TD: check for file end
f.close();
}

SnapFile::~SnapFile()
{
delete [] data;
}

void SnapFile::Info()
{
// data file information
std::cout << "Header : " << h.header << "\n"
<< "AdcTestMode : " << h.adcTestMode << "\n"
<< "ResetMode : " << h.resetMode << "\n"
<< "OutputMode : " << h.outputMode << "\n"
<< "ReadoutMode : " << h.readoutMode << "\n"
<< "WindowMode : " << h.windowMode << "\n"
<< "DebugMatrix : " << h.debugMatrixEnb << "\n"
<< "NbBurst: : " << h.nbBurst << "\n"
<< "NbFrame : " << h.nbFrame << "\n"
<< "BurstDelay : " << h.burstDelay << "\n"
<< "BurstDelatR : " << h.burstDelayRange << "\n"
<< "AdcFrequDiv : " << h.adcFrequencyDiv << "\n"
<< "PixelResetW : " << h.pixelResetWidth << "\n"
<< "RowResetW : " << h.rowResetWidth<< "\n"
<< "startRow: : " << h.startRow << "\n"
<< "stopRow: : " << h.stopRow << "\n"
<< "startPixel : " << h.startPixel << "\n"
<< "stopPixel : " << h.stopPixel << "\n"
<< "Footer : " << h.footer<<endl;

// not used
unsigned long adcFrequency = (h.readoutMode == SLOW) ? 100 : 2000;
adcFrequency = adcFrequency >> h.adcFrequencyDiv;
}

inline unsigned short SnapFile::Ref(int nFrame, int row, int col)
{
return data[nFrame*frameSize + row*rowSize + (2*col + 1)];
}

inline unsigned short SnapFile::Data(int nFrame, int row, int col)
{
return data[nFrame*frameSize + row*rowSize + (2*col)];
}

inline int SnapFile::Adjusted(int nFrame, int row, int col)
{
int address = nFrame*frameSize + row*rowSize + (2*col);
// data - ref
return int(data[address]) - data[address+1];
}

#endif
///////////////////////////////////////////////////////////////////////////////
0
christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008 1 > christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008
4 juin 2008 à 19:02
svp de l'aide
0
HostOfSeraphim Messages postés 6750 Date d'inscription jeudi 2 février 2006 Statut Contributeur Dernière intervention 31 juillet 2016 1 608 > christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008
4 juin 2008 à 19:03
Regarde le message #5.

0
jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 897 > christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008
4 juin 2008 à 19:04
Cette réponse ne te convient pas ?
0
christouff Messages postés 77 Date d'inscription dimanche 6 août 2006 Statut Membre Dernière intervention 16 septembre 2008 1
4 juin 2008 à 14:38
Et bien en fait je veux écrire dans un fichier texte, les noms des fichiers d'un dossier.

Je pourrai ensuite récupérer ces noms sous forme string sous C++ avec %s mais je sais pas comment pour l'instant

En fait mon vrai but c'est de tracer des graphes à l'aide de données contenues dans les fichiers dont je veux récupérer les noms.
Voilà

En fait ce qu'il faudrait que j'arrive à faire c'est extraire les noms de fichiers de ce dossier et les écrire dans un fichier texte pour pouvoir m'en reservir. mais c'est pas gagné

J'espère que ça t'a un peu éclairé

Merci
-1
farwarx Messages postés 125 Date d'inscription vendredi 30 mai 2008 Statut Membre Dernière intervention 21 mars 2010 18
4 juin 2008 à 14:54
Essaye ça:

ls * /ton-repertoire > fichier-sortie
cat fichier-sortie


"ls" liste un répertoire
Je pense qu'il te suffit juste de rediriger la sortie vers un fichier et voilà.
0