void main(int argc,char **argv){ FILE *fp=fopen(argv[1],"rb"); int quality=read_quality(fp); quality=set_quality(quality); printf("q=%d\n",quality); fclose(fp); }
static void quality_changed(GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self) { g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); /* no need to upate quality if auto quality is enabled */ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return; /* only update if the scale button is released, to reduce the number of updates */ if (priv->quality_scale_pressed) return; /* we get the value directly from the widget, in case this function is not * called from the event */ if (priv->call) set_quality(priv->call, FALSE, gtk_scale_button_get_value(button)); }
static void autoquality_toggled(GtkToggleButton *button, CurrentCallView *self) { g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); gboolean auto_quality_on = gtk_toggle_button_get_active(button); auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality)); auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality)); auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality)); gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on); gtk_widget_set_sensitive(plus_button, !auto_quality_on); gtk_widget_set_sensitive(minus_button, !auto_quality_on); double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality)); if (priv->call) set_quality(priv->call, auto_quality_on, desired_quality); }
void convert_datacube(char *in,char *out) { E3D_file src,dst; SPECTRUM sig, noise, *rms, *signal; SPAXEL *spaxels; E3Dspec_desc *ptdesc; int i, specId, nbspax, npix=-1; double start = -1, end; char extname[lg_name+1], tablename[lg_name+1]; if (open_E3D_file(&src,in,"I")<0) { print_error("Cannot open input file %s",in); exit_session(ERR_OPEN); } else { if (has_common_bounds(&src)) { get_common_param(&src,&npix,&start,&end); } if (create_E3D_file(&dst,out,npix,start,src.step,src.data_type,src.ident,src.cunit) < 0) { close_E3D_file(&src); print_error("Cannot create output file %s",out); exit_session(ERR_CREAT); } else { signal = NULL; rms = NULL; ptdesc = NULL; if (src.signal != NULL) { signal = &sig; ptdesc = src.signal; } if (src.noise != NULL) { rms = &noise; ptdesc = src.noise; } else { if (src.signal == NULL) { close_E3D_file(&src); print_error("Inconsistent input file (no spectra inside)"); exit_session(ERR_BAD_PARAM); } } reset_print_progress(); for (i=0;i<src.nbspec;i++) { print_progress("Convert datacube: ", (int)((100*i)/src.nbspec),1); specId = ptdesc[i].specId; get_E3D_spec(&src,signal,rms,specId); set_quality(rms); put_E3D_spec(&dst,signal,rms,specId); nbspax = get_E3D_spaxels(&src,specId,&spaxels); put_E3D_spaxels(&dst,specId,nbspax,spaxels); } if (src.data_format == TIGER_FORMAT) { /* set groups */ set_tiger_group(&src); } put_E3D_groups(&dst,src.ngroups,src.groups); print_progress("Convert datacube: ", (int)100,1); CP_non_std_desc(&src,&dst); close_E3D_file(&src); close_E3D_file(&dst); printf("\n"); if (src.data_format == TIGER_FORMAT) { /* save table in special extension */ get_science_table_name(in,tablename); append_tbl_extension(out, OutputIO.basic_io); sprintf(extname,"%s[%s]",out,E3D_TIGER_EXT); convert_table(tablename,extname); } if (dst.data_format == TIGER_FORMAT) { /* save science extension as table */ strcpy(tablename,out); remove_file_extension(tablename); sprintf(extname,"%s[%s]",in,E3D_TIGER_EXT); convert_table(extname,tablename); } } } }
/* ADAPTIVE_SNR * ------------ * Input parameters: * dataCol - the column with the data * numChans - number of channels in groupCol and qualCol * snr - the signal-to-noise ratio threshold * groupCol - the GROUPING column * qualCol - the QUALITY column * tabStops - array giving channels with tabs or stops * errorCol - optional error column * useErr - if true, use errorCol data, else use counts * maxLength - maximum size of groups */ int grp_do_adaptive_snr(double *dataCol, long numChans, double snr, short *groupCol, short *qualCol, short *tabStops, double *errorCol, short useErr, double maxLength, dsErrList *errList){ long ii, jj, tempLength, tempMax, counter = 0; long curWidth = 0; double runningSnr = 0.0; double runningSignal = 0.0; double runningNoise = 0.0; short *usedChans; int returnVal = GRP_SUCCESS; /* Check for obviously bad inputs */ if(!dataCol || (numChans <= 0) || (snr <= 0) || !groupCol || !qualCol || !tabStops || !errorCol){ if(errList) dsErrAdd(errList, dsDMGROUPBADPARAMERR, Accumulation, Generic); else err_msg("ERROR: At least one input parameter has an " "invalid value.\n"); return(GRP_ERROR); } if(maxLength <= 0.0) maxLength = MAX_BIN_LENGTH; /* Create used channel list */ usedChans = (short *) calloc(numChans, sizeof(short)); for(ii = 0; ii < numChans; ii++){ if(tabStops[ii] || (qualCol[ii] != 0)) usedChans[ii] = GRP_TRUE; else usedChans[ii] = GRP_FALSE; } /* Main loop through adaptive group sizes */ while((curWidth + 1) <= maxLength){ curWidth++; /* Determine maxLength each time as it might be limited */ tempLength = 0; tempMax = 0; for(ii = 0; ii < numChans; ii++){ if(!usedChans[ii]){ tempLength++; if(tempLength > tempMax) tempMax = tempLength; } else tempLength = 0; } if(tempMax < maxLength) maxLength = tempMax; /* Iterate over each row for each group size */ for(ii = 0; ii < (numChans - curWidth); ii++){ if(usedChans[ii]) continue; runningSnr = 0.0; runningSignal = 0.0; runningNoise = 0.0; /* Try to make groups of the current width */ for(jj = 0; jj < curWidth; jj++){ if(usedChans[ii + jj]){ runningSnr = 0.0; runningSignal = 0.0; runningNoise = 0.0; break; } if(useErr){ if(!errorCol[ii + jj]){ if(errList) dsErrAdd(errList, dsDMGROUPZEROERRORERR, Accumulation, Generic); else err_msg("WARNING: The supplied error column " "contains zero-valued data."); returnVal = GRP_WARNING; } else { runningSnr += pow((dataCol[ii + jj] / errorCol[ii + jj]), 2); runningSignal += dataCol[ii+jj]; runningNoise += (errorCol[ii+jj]*errorCol[ii+jj]); runningSnr = runningSignal/runningNoise; runningSnr *= runningSnr; } } else if(dataCol[ii + jj]) { runningSignal += dataCol[ii]; runningSnr = runningSignal; } if(jj == (curWidth - 1)){ if(sqrt(runningSnr) > snr){ /* Enough counts - let's group it */ mark_used(usedChans, ii, ii + jj); create_group(groupCol, ii, ii + jj); set_quality(qualCol, GRP_GOOD, ii, ii + jj); } } } /* end for(jj) */ } /* end for(ii) */ } /* end while() */ /* Put unused channels into "bad" groups */ for(ii = 0; ii < numChans; ii++){ /* Are we in a used channel? */ if(usedChans[ii]){ if(counter != 0){ set_incomplete(groupCol, qualCol, ii - counter, ii - 1); counter = 0; } } /* Are we at the end of the table? */ else if(ii == (numChans - 1)){ /* Does this complete a group? */ if(counter != 0) set_incomplete(groupCol, qualCol, ii - counter, ii); else set_incomplete(groupCol, qualCol, ii, ii); } /* Are we at the end of a group */ else if(usedChans[ii + 1]){ set_incomplete(groupCol, qualCol, ii - counter, ii); counter = 0; } /* Are we at the beginning of a group? */ else{ counter++; } } /* end for(ii) */ free(usedChans); return(GRP_SUCCESS); }
/* ADAPTIVE * -------- * Input parameters: * dataCol - the column with the data * numChans - number of channels in groupCol and qualCol * minCounts - the minimum number of counts desired in each group * groupCol - the GROUPING column * qualCol - the QUALITY column * tabStops - array giving channels with tabs or stops * maxLength - maximum size of groups */ int grp_do_adaptive(double *dataCol, long numChans, double minCounts, short *groupCol, short *qualCol, short *tabStops, double maxLength, dsErrList *errList){ short *usedChans; long ii, jj, tempLength, tempMax, curWidth = 0; long counter = 0; double groupCounts = 0.0; /* Check for obviously bad inputs */ if(!dataCol || (numChans <= 0) || (minCounts <= 0) || !groupCol || !qualCol || !tabStops){ if(errList) dsErrAdd(errList, dsDMGROUPBADPARAMERR, Accumulation, Generic); else err_msg("ERROR: At least one input parameter has an " "invalid value.\n"); return(GRP_ERROR); } if(maxLength <= 0.0) maxLength = MAX_BIN_LENGTH; /* Create and initialize used channel list */ usedChans = (short *) calloc(numChans, sizeof(short)); for(ii = 0; ii < numChans; ii++){ if(tabStops[ii] || (qualCol[ii] != 0)) usedChans[ii] = GRP_TRUE; else usedChans[ii] = GRP_FALSE; } /* Main loop through adaptive group sizes */ while((curWidth + 1) <= maxLength){ curWidth++; /* Determine maxLength each time as it might be limited */ tempLength = 0; tempMax = 0; for(ii = 0; ii < numChans; ii++){ if(!usedChans[ii]){ tempLength++; if(tempLength > tempMax) tempMax = tempLength; } else tempLength = 0; } if(tempMax < maxLength) maxLength = tempMax; /* Iterate over each row for each group size */ for(ii = 0; ii < (numChans - curWidth); ii++){ if(usedChans[ii]) continue; groupCounts = 0.0; /* Try to make groups of the current width */ for(jj = 0; jj < curWidth; jj++){ if(usedChans[ii + jj]) break; groupCounts += dataCol[ii + jj]; if(jj == curWidth - 1){ if(groupCounts >= minCounts){ /* Enough counts - let's group it */ mark_used(usedChans, ii, ii + jj); create_group(groupCol, ii, ii + jj); set_quality(qualCol, GRP_GOOD, ii, ii + jj); } } } /* end for(jj) */ } /* end for(ii) */ } /* end while() */ /* Put unused channels into "bad" groups */ for(ii = 0; ii < numChans; ii++){ /* Are we in a used channel? */ if(usedChans[ii]){ if(counter != 0){ set_incomplete(groupCol, qualCol, ii - counter, ii - 1); counter = 0; } } /* Are we at the end of the table? */ else if(ii == (numChans - 1)){ /* Does this complete a group? */ if(counter != 0) set_incomplete(groupCol, qualCol, ii - counter, ii); else set_incomplete(groupCol, qualCol, ii, ii); } /* Are we at the end of a group */ else if(usedChans[ii + 1]){ set_incomplete(groupCol, qualCol, ii - counter, ii); counter = 0; } /* Are we at the beginning of a group? */ else{ counter++; } } /* end for(ii) */ free(usedChans); return(GRP_SUCCESS); }
/* MAX_SLOPE * --------- * Input parameters: * dataCol - the column representing the independent axis * binCol - the column with the data values * numChans - number of channels in groupCol and qualCol * slope - the maximum slope threshold * groupCol - the GROUPING column * qualCol - the QUALITY column * tabStops - array giving channels with tabs or stops * maxlength - maximum size of groups */ int grp_do_max_slope(double *dataCol, double *binCol, long numChans, double slope, short *groupCol, short *qualCol, short *tabStops, double maxlength, dsErrList *errList){ long ii, jj, counter = 0; double range = 0.0; double tempSlope = 0.0; short *usedChans; /* Check for obviously bad inputs */ if(!dataCol || !binCol || (numChans < 2) || (slope <= 0) || !groupCol || !qualCol || !tabStops){ if(errList) dsErrAdd(errList, dsDMGROUPBADPARAMERR, Accumulation, Generic); else err_msg("ERROR: At least one input parameter has an " "invalid value.\n"); return(GRP_ERROR); } if(maxlength <= 0.0) maxlength = MAX_BIN_LENGTH; /* Create and initialize used channel list */ usedChans = (short *) calloc(numChans, sizeof(short)); for(ii = 0; ii < numChans; ii++){ if(tabStops[ii] || (qualCol[ii] != 0)) usedChans[ii] = GRP_TRUE; else usedChans[ii] = GRP_FALSE; } ii = 0; jj = 1; while(ii < (numChans - 1)){ /* Are we in a tab or stop? */ if(tabStops[ii]){ ii++; jj = (ii + 1); } else{ while(jj < numChans){ /* Calculate current slope */ tempSlope = fabs(((binCol[jj] - binCol[ii]) / (dataCol[jj] - dataCol[ii]))); range = (dataCol[jj] - dataCol[ii]); /* Are we in a tab or stop? */ if(tabStops[jj]){ ii++; jj = (ii + 1); break; } /* Are we at the end of the table? */ else if(jj == (numChans - 1)){ /* Does this complete a group? */ if((tempSlope >= slope) || (range >= maxlength)){ mark_used(usedChans, ii, jj); create_group(groupCol, ii, jj); set_quality(qualCol, GRP_GOOD, ii, jj); ii = jj; break; } else{ ii++; jj = (ii + 1); break; } } /* Are we at the end of a group or have reached * maxlength? */ else if((tempSlope >= slope) || (range >= maxlength)){ mark_used(usedChans, ii, jj); create_group(groupCol, ii, jj); set_quality(qualCol, GRP_GOOD, ii, jj); ii = (jj + 1); jj = (ii + 1); break; } /* Keep looking */ else jj++; } /* end while(jj) */ } /* end if */ } /* end while(ii) */ /* Put unused channels into "bad" groups */ for(ii = 0; ii < numChans; ii++){ /* Are we in a used channel? */ if(usedChans[ii]){ if(counter != 0){ set_incomplete(groupCol, qualCol, ii - counter, ii - 1); counter = 0; } } /* Are we at the end of the table? */ else if(ii == (numChans - 1)){ /* Does this complete a group? */ if(counter != 0) set_incomplete(groupCol, qualCol, ii - counter, ii); else set_incomplete(groupCol, qualCol, ii, ii); } /* Are we at the end of a group */ else if(usedChans[ii + 1]){ set_incomplete(groupCol, qualCol, ii - counter, ii); counter = 0; } /* Are we at the beginning of a group? */ else{ counter++; } } /* end for(ii) */ free(usedChans); return(GRP_SUCCESS); }