|
ocssw
1.0
|
00001 #include <string.h> 00002 #include <libgen.h> 00003 #include "l1stat.h" 00004 #include "l1stat_proto.h" 00005 extern int32 stat_status; 00006 extern char bad_stat_str[320]; 00007 00008 #define DETAIL_PRT 0 /* 1 to print detail, 0 to not print detail */ 00009 00010 void rpt_noise( int32 sdfid, int16 dtynum, int32 nscans, int32 nsamp, 00011 int *spike_cnt, float *line_sd, float pct_noise_thresh, 00012 float pct_encrypt_thresh ) 00013 /******************************************************************* 00014 00015 rpt_noise 00016 00017 purpose: get information from 5 other SDSes that flag noise in 00018 the data, combine it with the spike count and std deviation 00019 computed from the chk_count routine and decide if this dataset 00020 has too much noise to just pass 00021 00022 Returns type: void - none 00023 00024 Parameters: (in calling order) 00025 Type Name I/O Description 00026 ---- ---- --- ----------- 00027 int32 sdfid I SD interface ID 00028 int16 dtynum I data type number (not used now) 00029 int32 nscans I # lines in dataset 00030 int32 nsamp I # samples / line 00031 int * spike_cnt I size nscans by 8 array of 00032 spike counts found 00033 float * line_sd I size nscans by 8 array of 00034 std deviations found 00035 float pct_noise_thresh I reporting limit for % of 00036 noisey lines 00037 float pct_encrypt_thresh I reporting limit for % of 00038 encrypted lines 00039 00040 access spike_cnt and line_sd to get band b, line l with 00041 index = b * nrec + l 00042 00043 Modification history: 00044 Programmer Date Description of change 00045 ---------- ---- --------------------- 00046 W. Robinson 31-Jul-1998 Original development 00047 W. Robinson 24-Oct-2001 have input noise report thresholds 00048 00049 *******************************************************************/ 00050 { 00051 int irec, ibnd, icode; 00052 int16 *s_satp, *s_zerop, *dark_rest, *start_syn, *stop_syn; 00053 int32 *msec; 00054 int16 code_start_syn[8]={ 1023, 0, 1023, 0, 1023, 0, 1023, 0 }, c_start_syn[8]; 00055 int16 code_stop_syn[8]={ 1023, 1023, 0, 0, 1023, 1023, 0, 0 }, c_stop_syn[8]; 00056 float s_zerop_thresh[8] = { 0., 0., 0., 0., 0.0016, 0.008, 0.016, 0.008 }; 00057 /* this is fraction of # pixels with 0 counts and corresponds 00058 to 0, 0, 0, 0, 2, 10, 20, 10 for 1285 pixels (in a HRPT) */ 00059 int32 start[3], edge[3], encrypt_cnt, ds_noise_cnt, lin_prob_cnt, 00060 s_satp_bad, s_zerop_bad, dark_rest_bad, start_syn_bad, 00061 stop_syn_bad, sum_spikes; 00062 /* normal noisey line threshold = 80, encrypted: 70. now have as inputs */ 00063 float pct_noise, pct_encrypt; 00064 double pct_s_satp = 0., pct_s_zerop = 0., pct_dark_rest = 0., 00065 pct_start_syn = 0., pct_stop_syn = 0.; 00066 char str[12]; 00067 00068 /* 00069 * set up the start and stop sync to check using the code and data type 00070 */ 00071 if( ( dtynum == IGC ) || (dtynum == TDI ) || (dtynum == SOL ) ) 00072 { 00073 for( ibnd = 0; ibnd < 7; ibnd++ ) 00074 { 00075 c_start_syn[ibnd] = 1023 - code_start_syn[ibnd]; 00076 c_stop_syn[ibnd] = 1023 - code_stop_syn[ibnd]; 00077 } 00078 } 00079 else 00080 { 00081 for( ibnd = 0; ibnd < 7; ibnd++ ) 00082 { 00083 c_start_syn[ibnd] = code_start_syn[ibnd]; 00084 c_stop_syn[ibnd] = code_stop_syn[ibnd]; 00085 } 00086 } 00087 00088 /* 00089 * allocate the space needed for the 5 arrays 00090 */ 00091 if( ( s_satp = (int16 *) malloc( 8 * nscans * sizeof( int16 ) ) ) 00092 == NULL ) 00093 { 00094 printf( "\n*****rpt_noise: program error, unable to allocate s_satp space\n" ); 00095 stat_status = stat_status | 1; 00096 return; 00097 } 00098 if( ( s_zerop = (int16 *) malloc( 8 * nscans * sizeof( int16 ) ) ) 00099 == NULL ) 00100 { 00101 printf( "\n*****rpt_noise: program error, unable to allocate s_zerop space\n" ); 00102 stat_status = stat_status | 1; 00103 return; 00104 } 00105 if( ( dark_rest = (int16 *) malloc( 8 * nscans * sizeof( int16 ) ) ) 00106 == NULL ) 00107 { 00108 printf( "\n*****rpt_noise: program error, unable to allocate dark_rest space\n" ); 00109 stat_status = stat_status | 1; 00110 return; 00111 } 00112 if( ( start_syn = (int16 *) malloc( 8 * nscans * sizeof( int16 ) ) ) 00113 == NULL ) 00114 { 00115 printf( "\n*****rpt_noise: program error, unable to allocate start_syn space\n" ); 00116 stat_status = stat_status | 1; 00117 return; 00118 } 00119 if( ( stop_syn = (int16 *) malloc( 8 * nscans * sizeof( int16 ) ) ) 00120 == NULL ) 00121 { 00122 printf( "\n*****rpt_noise: program error, unable to allocate stop_syn space\n" ); 00123 stat_status = stat_status | 1; 00124 return; 00125 } 00126 00127 /* 00128 * for other tests, get msec also (for line id) 00129 */ 00130 if( ( msec = (int32 *) malloc( nscans * sizeof( int32 ) ) ) 00131 == NULL ) 00132 { 00133 printf( "\n*****rpt_noise: program error, unable to allocate msec space\n" ); 00134 stat_status = stat_status | 1; 00135 return; 00136 } 00137 00138 /* 00139 * read the arrays from the L1 dataset 00140 */ 00141 start[0] = start[1] = start[2] = 0; 00142 edge[0] = nscans; 00143 edge[1] = 8; 00144 edge[2] = 0; 00145 00146 if( rdslice( sdfid, "s_satp", start, edge, (void *)s_satp ) < 0 ) 00147 { 00148 stat_status = stat_status | 1; 00149 printf( "\n*****rpt_noise: program error, unable to read s_satp\n" ); 00150 return; 00151 } 00152 00153 if( rdslice( sdfid, "s_zerop", start, edge, (void *)s_zerop ) < 0 ) 00154 { 00155 stat_status = stat_status | 1; 00156 printf( "\n*****rpt_noise: program error, unable to read s_zerop\n" ); 00157 return; 00158 } 00159 00160 if( rdslice( sdfid, "dark_rest", start, edge, (void *)dark_rest ) < 0 ) 00161 { 00162 stat_status = stat_status | 1; 00163 printf( "\n*****rpt_noise: program error, unable to read dark_rest\n" ); 00164 return; 00165 } 00166 00167 if( rdslice( sdfid, "start_syn", start, edge, (void *)start_syn ) < 0 ) 00168 { 00169 stat_status = stat_status | 1; 00170 printf( "\n*****rpt_noise: program error, unable to read start_syn\n" ); 00171 return; 00172 } 00173 00174 if( rdslice( sdfid, "stop_syn", start, edge, (void *)stop_syn ) < 0 ) 00175 { 00176 stat_status = stat_status | 1; 00177 printf( "\n*****rpt_noise: program error, unable to read stop_syn\n" ); 00178 return; 00179 } 00180 00181 edge[0] = nscans; 00182 edge[1] = 0; 00183 edge[2] = 0; 00184 if( rdslice( sdfid, "msec", start, edge, (void *)msec ) < 0 ) 00185 { 00186 stat_status = stat_status | 1; 00187 printf( "\n*****rpt_noise: program error, unable to read stop_syn\n" ); 00188 return; 00189 } 00190 00191 /* 00192 * initialize some values for the entire dataset 00193 */ 00194 encrypt_cnt = 0; 00195 ds_noise_cnt = 0; 00196 00197 /* 00198 * print heading for line-by-line report (if enabled) 00199 */ 00200 00201 if( DETAIL_PRT ) 00202 { 00203 printf( "\n\nLine-by-line report of noise and noise type found\n" ); 00204 printf( "line # bands # bands # bands w # bad strt # bad stop std dev # spikes msec line\n" ); 00205 printf( " # saturated zero high dark sync wds/7 sync wds/7 band 1 all bnds tag type\n" ); 00206 printf( "---- --------- ------- --------- ---------- ---------- ------- -------- -------- ----\n" ); 00207 } 00208 00209 /* 00210 * loop through the records and get onfo on each one 00211 */ 00212 for( irec = 0; irec < nscans; irec++ ) 00213 { 00214 /* 00215 * initialize counts for each line 00216 */ 00217 lin_prob_cnt = 0; 00218 s_satp_bad = 0; 00219 s_zerop_bad = 0; 00220 dark_rest_bad = 0; 00221 start_syn_bad = 0; 00222 stop_syn_bad = 0; 00223 sum_spikes = 0; 00224 00225 /* 00226 * loop through each band or sync word (only 7 checked for sync words ) 00227 */ 00228 for( ibnd = 0; ibnd < 8; ibnd++ ) 00229 { 00230 if( *( s_satp + ibnd + 8 * irec ) != 0 ) 00231 { 00232 s_satp_bad++; 00233 lin_prob_cnt++; 00234 } 00235 if( (float) *( s_zerop + ibnd + 8 * irec ) / nsamp 00236 > *( s_zerop_thresh + ibnd ) ) 00237 { 00238 s_zerop_bad++; 00239 lin_prob_cnt++; 00240 } 00241 if( *( dark_rest + ibnd + 8 * irec ) > 30 ) 00242 { 00243 dark_rest_bad++; 00244 lin_prob_cnt++; 00245 } 00246 if( ibnd < 7 ) /* only check the 1st 7 words for the sync */ 00247 { 00248 if( *( start_syn + ibnd + 8 * irec ) != *( c_start_syn + ibnd ) ) 00249 { 00250 start_syn_bad++; 00251 lin_prob_cnt++; 00252 } 00253 if( *( stop_syn + ibnd + 8 * irec ) != *( c_stop_syn + ibnd ) ) 00254 { 00255 stop_syn_bad++; 00256 lin_prob_cnt++; 00257 } 00258 } 00259 sum_spikes += *( spike_cnt + ibnd + 8 * irec ); 00260 } /* end band (word) loop, report the line results */ 00261 00262 if( DETAIL_PRT ) 00263 { 00264 printf( "%4d%10d%9d%11d%12d%12d%9.2f%10d%9d", irec, s_satp_bad, 00265 s_zerop_bad, dark_rest_bad, start_syn_bad, stop_syn_bad, 00266 *( line_sd + 8 * irec ), sum_spikes, *( msec + irec ) ); 00267 } 00268 00269 /* 00270 * need to add the line type at the end 00271 */ 00272 if( *( line_sd + 8 * irec ) > 220. ) 00273 { 00274 if( DETAIL_PRT ) 00275 { 00276 printf( " **** Encrypted line\n" ); 00277 } 00278 encrypt_cnt++; 00279 ds_noise_cnt++; 00280 } 00281 else if( lin_prob_cnt > 0 ) 00282 { 00283 if( DETAIL_PRT ) 00284 { 00285 printf( " ** Noisey line\n" ); 00286 } 00287 ds_noise_cnt++; 00288 } 00289 else 00290 { 00291 if( DETAIL_PRT ) 00292 { 00293 printf( " Good line\n" ); 00294 } 00295 } 00296 00297 /* 00298 * count the occurences of each of the 5 SDS violations 00299 * (make into percentages at the end) 00300 */ 00301 if( s_satp_bad > 0 ) pct_s_satp++; 00302 if( s_zerop_bad > 0 ) pct_s_zerop++; 00303 if( dark_rest_bad > 0 ) pct_dark_rest++; 00304 if( start_syn_bad > 0 ) pct_start_syn++; 00305 if( stop_syn_bad > 0 ) pct_stop_syn++; 00306 00307 } /* end record loop, time for the final reconing */ 00308 00309 /* 00310 * report percentages of the 5 sdses violated 00311 */ 00312 printf( "\n\n#Noise report summary\n\n" ); 00313 printf( "# --- Percentage bad lines ---\n" ); 00314 printf( "# bands bands bands w bad strt bad stop \n" ); 00315 printf( "# saturated zero high dark sync wds/7 sync wds/7 \n" ); 00316 printf( "# --------- ------- --------- ---------- ---------- \n" ); 00317 printf( "# %10.2f%9.2f%11.2f%12.2f%12.2f\n\n", 00318 ( 100. * pct_s_satp / nscans ), ( 100. * pct_s_zerop / nscans ), 00319 ( 100. * pct_dark_rest / nscans ), ( 100. * pct_start_syn / nscans ), 00320 ( 100. * pct_stop_syn / nscans ) ); 00321 00322 printf( "\n\n#total # lines: %9d # with noise: %9d # encrypted: %d\n", 00323 nscans, ds_noise_cnt, encrypt_cnt ); 00324 pct_noise = 100. * (float)ds_noise_cnt / nscans; 00325 pct_encrypt = 100. * (float)encrypt_cnt / nscans; 00326 printf 00327 ( " %9.2f %% %9.2f %%\n\n\n", 00328 pct_noise, pct_encrypt ); 00329 /* 00330 * add the encryption and noise reports also 00331 */ 00332 printf( "\n\n#Mnemonic Code %% lines %% threshold\n" ); 00333 printf( " -------- ---- ------- -----------\n" ); 00334 if( ( dtynum == GAC ) || ( dtynum == LAC ) || ( dtynum == HRPT ) ) 00335 { 00336 icode = 0; 00337 if( pct_encrypt > pct_encrypt_thresh ) 00338 { 00339 printf( "#*** dataset failed due to > %7.2f %% encryption noise\n", 00340 pct_encrypt_thresh ); 00341 stat_status = stat_status | 2; 00342 icode = 1; 00343 sprintf( str, "ENCRYPT " ); 00344 if( strlen( bad_stat_str ) <= 300 ) 00345 strcat( bad_stat_str, str ); 00346 } 00347 printf( "ENCRYPT %2d %7.2f %7.2f\n", icode, pct_encrypt, 00348 pct_encrypt_thresh ); 00349 icode = 0; 00350 if( pct_noise > pct_noise_thresh ) 00351 { 00352 printf( "#*** dataset failed due to > %7.2f %% general noise\n", 00353 pct_noise_thresh ); 00354 stat_status = stat_status | 2; 00355 icode = 1; 00356 sprintf( str, "NOISE " ); 00357 if( strlen( bad_stat_str ) <= 300 ) 00358 strcat( bad_stat_str, str ); 00359 } 00360 printf( "NOISE %2d %7.2f %7.2f\n\n", icode, 00361 pct_noise, pct_noise_thresh ); 00362 } 00363 else 00364 { 00365 printf( "ENCRYPT N/A %7.2f %7.2f\n", pct_encrypt, 00366 pct_encrypt_thresh ); 00367 printf( "NOISE N/A %7.2f %7.2f\n\n", 00368 pct_noise, pct_noise_thresh ); 00369 } 00370 /* 00371 * make a 1 line mnemonic version for easy auto-pull-out 00372 */ 00373 printf( "\n\n#1 line version for auto-identification\n" ); 00374 printf( "\n#Mnemonic Code noise encrypt sat zero dark start stop\n" ); 00375 printf( "#----------------------------------------------------------------------------\n" ); 00376 if( ( dtynum == GAC ) || ( dtynum == LAC ) || ( dtynum == HRPT ) ) 00377 { 00378 printf( "L1NOISE %2d%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f\n", 00379 icode, pct_noise, pct_encrypt, ( 100. * pct_s_satp / nscans ), 00380 ( 100. * pct_s_zerop / nscans ), ( 100. * pct_dark_rest / nscans ), 00381 ( 100. * pct_start_syn / nscans ), ( 100. * pct_stop_syn / nscans ) ); 00382 } 00383 else 00384 { 00385 printf( "L1NOISE N/A%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f%7.2f\n", 00386 pct_noise, pct_encrypt, ( 100. * pct_s_satp / nscans ), 00387 ( 100. * pct_s_zerop / nscans ), ( 100. * pct_dark_rest / nscans ), 00388 ( 100. * pct_start_syn / nscans ), ( 100. * pct_stop_syn / nscans ) ); 00389 } 00390 00391 free( s_satp ); 00392 free( s_zerop ); 00393 free( dark_rest ); 00394 free( start_syn ); 00395 free( stop_syn ); 00396 00397 /* 00398 * that's all 00399 */ 00400 return; 00401 }
1.7.6.1