• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

channelize.196.c

Go to the documentation of this file.
00001 /** @file channelize.196.c takes a block of data and dechannelize to 
00002     logical channels.
00003  *
00004  * usage:
00005  * channelize.196 [nchan]
00006  */
00007 
00008 #include <assert.h>
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <unistd.h>
00012 #include <errno.h>
00013 
00014 #include <sys/types.h>
00015 #include <sys/stat.h>
00016 #include <fcntl.h>
00017 
00018 #define SSZ (sizeof(short))
00019 
00020 int fd_in;
00021 FILE* fd_out;
00022 
00023 #define INPUT fd_in
00024 #define OUTPUT fd_out
00025 
00026 int acq200_lookup_pchan(int lchannel)
00027 /* lchannel {1:32} returns physical channel {1:32} */
00028 {
00029         static  int plut[] = {
00030 /* index on logical channel {1:32} , map to physical channel {1:32} */
00031                 [ 1] =  1, 
00032                 [ 2] = 17, 
00033                 [ 3] =  2, 
00034                 [ 4] = 18, 
00035                 [ 5] =  9,      
00036                 [ 6] = 25,
00037                 [ 7] = 10,
00038                 [ 8] = 26,
00039 
00040                 [ 9] =  3,
00041                 [10] = 19,
00042                 [11] =  4,
00043                 [12] = 20,
00044                 [13] = 11,
00045                 [14] = 27,
00046                 [15] = 12,
00047                 [16] = 28,
00048 
00049                 [17] =  5,
00050                 [18] = 21,
00051                 [19] =  6,
00052                 [20] = 22,
00053                 [21] = 13,
00054                 [22] = 29,
00055                 [23] = 14,
00056                 [24] = 30,
00057 
00058                 [25] =  7,
00059                 [26] = 23,
00060                 [27] =  8,
00061                 [28] = 24,
00062                 [29] = 15,
00063                 [30] = 31,
00064                 [31] = 16,
00065                 [32] = 32 
00066         };
00067 
00068 
00069         int block = ((lchannel-1)/32);
00070         int index = lchannel - block*32;
00071 
00072         return block*32 + plut[index];
00073 }
00074 
00075 int acq200_lookup_lchan(int pchan)
00076 /* input pchan {1:32} returns logical channel {1:32} */
00077 {
00078         static  int llut[] = {
00079 /* index on physical channel {1:32} , map to logical channel {1:32}*/
00080                 [ 1]            =  1, 
00081                 [17]            =  2, 
00082                 [ 2]            =  3, 
00083                 [18]            =  4, 
00084                 [ 9]            =  5, 
00085                 [25]            =  6, 
00086                 [10]            =  7, 
00087                 [26]            =  8, 
00088 
00089                 [ 3]            =  9, 
00090                 [19]            = 10, 
00091                 [ 4]            = 11, 
00092                 [20]            = 12, 
00093                 [11]            = 13, 
00094                 [27]            = 14, 
00095                 [12]            = 15, 
00096                 [28]            = 16, 
00097 
00098                 [ 5]            = 17, 
00099                 [21]            = 18, 
00100                 [ 6]            = 19, 
00101                 [22]            = 20, 
00102                 [13]            = 21, 
00103                 [29]            = 22, 
00104                 [14]            = 23, 
00105                 [30]            = 24, 
00106 
00107                 [ 7]            = 25, 
00108                 [23]            = 26, 
00109                 [ 8]            = 27, 
00110                 [24]            = 28, 
00111                 [15]            = 29, 
00112                 [31]            = 30, 
00113                 [16]            = 31, 
00114                 [32]            = 32
00115         };
00116 
00117         int block = ((pchan-1)/32);
00118         int index = pchan - block*32;
00119 
00120         return block*32 + llut[index];
00121 }
00122 
00123 
00124 static void open_files(const char* fname_in)
00125 {
00126         char fname_out[80];
00127 
00128         fd_in = open(fname_in, O_RDONLY);
00129         assert(fd_in != -1);
00130 
00131         sprintf(fname_out, "%s.ch", fname_in);
00132 
00133         fd_out = fopen(fname_out, "w");
00134 }
00135 
00136 static int load(short* input, int ndata)
00137 {
00138         int rc;
00139 
00140         fprintf(stderr, "load call read(%d %p %lu)\n",
00141                 INPUT, input, ndata*SSZ);
00142 
00143 
00144         rc = read(INPUT, input, ndata*SSZ);
00145 
00146         if (rc > 0){
00147                 fprintf(stderr, "load returning %lu\n", rc/SSZ);
00148                 return rc/SSZ;
00149         }else{
00150                 perror( "ERROR on load");
00151                 _exit(errno);
00152         }
00153 }
00154 
00155 static void channelize(short* output, short* input, int nchan, int nsamples)
00156 {
00157         int isample;
00158         int ichan;
00159 
00160         fprintf(stderr, "channelize %d %d\n", nchan, nsamples);
00161 
00162         for (isample = 0; isample != nsamples; ++isample){
00163                 for (ichan = 1; ichan <= nchan; ++ichan){
00164                         output[(ichan-1)*nsamples + isample] = 
00165                                 input[acq200_lookup_lchan(ichan)-1];
00166                 }
00167                 input += nchan;
00168         }
00169 
00170         fprintf(stderr, "channelize %d %d done\n", nchan, nsamples);
00171 }
00172 static void store(short* output, int ndata)
00173 {
00174         int rc = fwrite(output, SSZ, ndata, OUTPUT);
00175 
00176         assert(rc == ndata);
00177 }
00178 
00179 int main(int argc, char* argv[])
00180 {
00181         int nchannels = 96;
00182         int nsamples = 1;
00183         short* input;
00184         short* output;
00185         int ncs_product;
00186         const char* raw_fn = 0;
00187         
00188 
00189         switch (argc){
00190         case 4:
00191                 raw_fn = argv[3];
00192         case 3:
00193                 nsamples = atoi(argv[2]);
00194         case 2:
00195                 nchannels = atoi(argv[1]);
00196                 break;
00197         default:
00198                 fprintf(stderr,"usage channelize.196 <nchannels> <len> <raw>\n");
00199                 _exit(-1);
00200         }          
00201 
00202         open_files(raw_fn);
00203         
00204         ncs_product = nsamples * nchannels;
00205 
00206         input = malloc( ncs_product * SSZ );
00207         output = malloc( ncs_product * SSZ );
00208 
00209         assert(input);
00210         assert(output);
00211         
00212         ncs_product = load(input, nsamples*nchannels);
00213         nsamples = ncs_product / nchannels;
00214 
00215         channelize(output, input, nchannels, nsamples);
00216         store(output, nsamples*nchannels);
00217 
00218         return 0;
00219 }

Generated on Wed Jan 5 2011 for llcontrol by  doxygen 1.7.1