/[PAMELA software]/yoda/techmodel/forroutines/tracker/readraw/findstart.c
ViewVC logotype

Diff of /yoda/techmodel/forroutines/tracker/readraw/findstart.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.0 by kusanagi, Tue Sep 21 20:51:20 2004 UTC revision 6.2 by mocchiut, Mon Oct 16 16:02:22 2006 UTC
# Line 1  Line 1 
1  /*  /************************************************************
2   * include needed system headers  *     11/9/2005 modified by david fedele to read buffer-data
3   */  *     instead raw-data-file
4    **************************************************************
5    
6    * include needed system headers
7    */
8  #include <stdio.h>       /* include standard i/o library */  #include <stdio.h>       /* include standard i/o library */
9  #include <stdlib.h>      /* include standard library */  #include <stdlib.h>      /* include standard library */
10  #include <string.h>      /* include string library */  #include <string.h>      /* include string library */
# Line 12  Line 16 
16  #include <time.h>        /* system time definitions */  #include <time.h>        /* system time definitions */
17  #include <math.h>        /* math library */  #include <math.h>        /* math library */
18    
 /*void findstart_(unsigned short *buffer, int *error, int *fd)*/  
   
 /*{*/  
 /*     int nread; */  
 /*     unsigned short word;//, *p_buffer; */  
   
   
 /* /\*** reads a word ***\/ */  
 /* //    p_buffer=&buffer; */  
 /*     nread=read(*fd, buffer, 2); */  
 /*     if(nread == 0) { */  
 /*      printf("findstart: Unexpected end of file %d at %d \n",*fd,nread); */  
 /*      *error=1; */  
 /*      return ; */  
 /*     } */  
 /*     if(nread != 2) { */  
 /*      printf("findstart: Error on reading: nread = %d \n",nread); */  
 /*      *error=-1; */  
 /*      return ;  */  
 /*     } */  
   
 /* /\*** correct byte ***\/ //??????????????????????SCAMBIA */  
 /*     word = buffer; */  
 /*     buffer = ( (word&0x00ff) << 8 ) | ( (word&0xff00) >> 8 ); */  
 /* //    printf("buffer %x , word: %x: \n", buffer, word);//??? */  
   
   
19  /*   looks for a DSP header beginning (a word beginning with 1110)   */  /*   looks for a DSP header beginning (a word beginning with 1110)   */
       
 void findstart_(int *error, int *fd)  
20    
21    /************************************************************
22    *     11/9/2005 modified by david fedele
23    *       void findstart_(int *error, int *fd)*/
24    void getbytes_(int *nbytes, char *buffer, int *p, unsigned int *value);
25    
26    void findstart_(int *error,char *buffer, int *len, int *curpos)
27  {  {
28      int nread;      char *buff=buffer;
29      unsigned short word;      int nbytes2=2;
30      unsigned short temp;      /* int nread */
31      /*     unsigned short word; */
32    /*     unsigned short temp; */
33        unsigned int word;
34    /***********************************************************/
35        
36        *error=0;
37      do {      do {
38          nread=read(*fd, &word, 2); //reads 16 bits  /************************************************************/
39          if(nread == 0) {  /*     11/9/2005 modified by david fedele                   */
40              //printf("findstart: Unexpected end of file %d at %d \n",*fd,nread);  /*        nread=read(*fd, &word, 2); //reads 16 bits        */
41              *error=1;  /*      if(nread == 0) { */
42              return ;  /* //       printf("findstart: Unexpected end of file %d at %d \n",*fd,nread); */
43          }  /*          *error=1; */
44          if(nread != 2) {  /*          return ; */
45              //printf("findstart: Error on reading: bytes read -> nread = %d \n",nread);  /*      } */
46              *error=-1;  /*      if(nread != 2) { */
47              return ;  /* //       printf("findstart: Error on reading: bytes read -> nread = %d \n",nread); */
48          }  /*          *error=-1; */
49    /*          return ; */
50    /*      } */
51          /*** corrects byte ***/ //endianess...  
52          temp = word;  /*      /\*** corrects byte ***\/ //endianess... */
53          word = ( (temp&0x00ff) << 8 ) | ( (temp&0xff00) >> 8 );  /*      temp = word; */
54  //      printf("word %x , temp: %x: \n", word, temp);//??? */  /*      word = ( (temp&0x00ff) << 8 ) | ( (temp&0xff00) >> 8 ); */
55    /* //   printf("word %x , temp: %x: \n", word, temp);//???  */
56            
57          /*** goes back 8 bits ***/  /*         /\*** goes back 8 bits ***\/ */
58          lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position  /*      lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position */
59    
60  //      unsigned short num=lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position  /* //   unsigned short num=lseek(*fd, -1, SEEK_CUR); //SEEK_CUR ---> from current position */
61  //      printf("%i \n",num);  /* //   printf("%i \n",num); */
62                
63      }          getbytes_(&nbytes2,buff,curpos,&word);
64      while ((word&0xf000) != 0xe000);            
65          *curpos=*curpos-1;
66          if(*curpos-1 > *len) {
67    //        printf("findstart: Unexpected end of file \n");
68              *error=1;
69              return ;
70          }
71    /***********************************************************/
72      
73        }     while ((word&0xf000) != 0xe000);
74            
75      /*** goes back 8 bits ***/  /************************************************************/
76      lseek(*fd, -1, SEEK_CUR);  /*     11/9/2005 modified by david fedele                   */
77    /*     /\*** goes back 8 bits ***\/ */
78    /*     lseek(*fd, -1, SEEK_CUR); */
79        *curpos=*curpos-1;
80        
81    /************************************************************/
82      return;      return;
83  }  }

Legend:
Removed from v.2.0  
changed lines
  Added in v.6.2

  ViewVC Help
Powered by ViewVC 1.1.23