#include "watom_t.h"
#include "wabor_t_array_functions.h"


void watom_t_setup(void){

    if (watom_t_test_compileparam()) {
        post("External Wabor: Plugin Compiled with wrong parameters."); //Testet alle Parameter ob sie richtig sind    
        return;
    }
    pcWatom_t = class_new(gensym("watom_tilde"),
            (t_newmethod)watom_t_new, (t_method)watom_t_delete,
            sizeof(sWatom_t),
            CLASS_DEFAULT,
            A_DEFFLOAT, 0);

    class_addmethod(pcWatom_t, (t_method)watom_t_dsp, gensym("dsp"), 0);
    class_addbang(pcWatom_t, watom_t_bang);
    class_addlist(pcWatom_t, (t_method) watom_t_make_receive_list);
    
    class_addmethod(pcWatom_t, (t_method)watom_t_make, gensym("make"),  A_DEFFLOAT, 0); 
    class_addmethod(pcWatom_t, (t_method)watom_t_shorten, gensym("shorten"),  A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_test, gensym("test"),  A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_copy_pac2paf, gensym("copy_pac2paf"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_copy_paf2pac, gensym("copy_paf2pac"), A_DEFFLOAT, 0);
    
    class_addmethod(pcWatom_t, (t_method)watom_t_paf2list, gensym("paf2list"), A_GIMME, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_send_windows, gensym("send_windows"), A_GIMME,0);
    

    class_addmethod(pcWatom_t, (t_method)watom_t_set_window_type, gensym("set_window_type"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_theta_type, gensym("set_theta_type"), A_GIMME, 0);    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_b, gensym("set_C_b"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_T_c, gensym("set_C_T_c"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_T_max, gensym("set_T_max"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_d, gensym("set_C_d"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_q, gensym("set_C_q"), A_DEFFLOAT, 0);
    
    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_SR, gensym("set_C_SR"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_K, gensym("set_K"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_compute_type, gensym("set_compute_type"), A_DEFFLOAT, 0);
    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_thetaf0, gensym("set_thetaf0"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_thetak, gensym("set_thetak"), A_DEFFLOAT, 0);    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_C_cut, gensym("set_C_cut"), A_DEFFLOAT, 0);    
    class_addmethod(pcWatom_t, (t_method)watom_t_initialize, gensym("initialize"), A_DEFFLOAT, 0);    
    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_var, gensym("set_var"), A_DEFFLOAT, 0);    
    class_addmethod(pcWatom_t, (t_method)watom_t_set_winlength_window, gensym("set_winlength_window"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_winlength_compute, gensym("set_winlength_compute"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_a, gensym("set_a"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_b, gensym("set_b"), A_DEFFLOAT, 0);
    
        
    class_addmethod(pcWatom_t, (t_method)watom_t_get_first_zero_paf, gensym("get_first_zero_paf"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_get_window_length_paf, gensym("get_window_length_paf"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_get_window_length_pac, gensym("get_window_length_pac"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_print_first_and_last_value, gensym("print_first_and_last_value"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_print_band, gensym("print_band"), A_DEFFLOAT, 0);
         
    class_addmethod(pcWatom_t, (t_method)watom_t_abs, gensym("abs"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_componentabs, gensym("componentabs"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_ln, gensym("ln"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_mult, gensym("mult"), A_GIMME, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_cut, gensym("cut"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_nan_to_zero, gensym("set_nan_to_zero"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_set_inf_to_zero, gensym("set_inf_to_zero"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_normalize, gensym("normalize"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_cycle, gensym("cycle"), A_GIMME, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_fft, gensym("fft"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_floating_average, gensym("floating_average"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_differentiate, gensym("differentiate"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_integrate, gensym("integrate"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_imag_plus_real, gensym("imag_plus_real"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_make_dc_offset, gensym("make_dc_offset"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_inner_product, gensym("inner_product"), A_DEFFLOAT, A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_length_of_vector, gensym("length_of_vector"), A_DEFFLOAT, 0);
    class_addmethod(pcWatom_t, (t_method)watom_t_prolong, gensym("prolong"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
        
    class_addmethod(pcWatom_t, (t_method)watom_t_array_synopsis, gensym("array_synopsis"), A_GIMME, 0);
    
    
    
    class_addmethod(pcWatom_t, (t_method)watom_t_round_up_to_multiple_of_small_primes, gensym("round_up_to_multiple_of_small_primes"), A_DEFFLOAT, A_DEFFLOAT, 0);
    
    //srand(time(NULL)); // Initialize Random

}

void watom_t_set_pointers_to_NULL(sWatom_t *psW){
    //Setzt alle Pointer auf NULL
    
    psW->x_outC = NULL;
    psW->x_outM = NULL;
    
    psW->sParam.Theta = NULL; 
    psW->sParam.Theta_inv = NULL;
    psW->sParam.d_Theta_infimum = NULL;
    psW->sParam.thetadata = NULL;
    
    psW->sParam.aldDq_real = NULL;
    psW->sParam.aldDq = NULL;
    psW->sParam.aiDq = NULL;
     
    psW->pac = NULL;
    psW->sParam.paf_r = NULL;
    psW->sParam.paf_i = NULL;
   
}
void watom_t_set_start_values(sWatom_t *psW){
    //Setzt alles auf Startwerte, diese sind nicht notwendigerweise sinnvoll, dürfen aber zu keinen Abstürzen führen
    
    psW->sParam.eWindowType =   WIN_SQRT_GAUSS;
                                  
                                    
    psW->sParam.C_SR    = 1;
    psW->sParam.C_b     = 2;
    psW->sParam.C_T_c   = 3;
    psW->sParam.T_max=10;
    psW->sParam.C_d     = 2;
    psW->sParam.C_q=0;
    
    psW->sParam._K  = 1;

    
    psW->sParam.C_cut   = 1e5; //Genauigkeit von Float ist 7-8 Stellen. Das heisst, alle Werte die kleiner als das sind, werden von anderen Fenster komplett ueberschrieben
    psW->sParam.iComputeType                    = 0; //Wenn iComputeType=1 werden hohe Frequenzen auf negative Frequenzen abgebildet.
    
    psW->var=1;
    
    //Werte die berechnet werden muessen, deshalb werden hier NICHT SINNVOLLE Werte gesetzt jett
    psW->sParam._R=-1;
    psW->sParam.dWinlength_window = -INFINITY;
    psW->sParam.dWinlength_compute = -INFINITY;
    psW->sParam._a=-INFINITY;
    psW->sParam._b=-INFINITY;
    psW->sParam.iq_compute_sup=0;
    
    psW->sParam.iLongestFrame_paf = -1;

    psW->sParam.eThetaType =    4;
    psW->sParam.Theta =         wabor_t_Theta_exp_c1_nyqu; 
    psW->sParam.Theta_inv =     wabor_t_Theta_inv_exp_c1_nyqu;
    psW->sParam.d_Theta_infimum = wabor_t_d_Theta_inf_exp_c1_nyqu;
    psW->sParam.thetadata=wabor_t_malloc0(4 * sizeof(pac_type_real)); //Weil c1_nyquist 4 dinge braucht
    psW->sParam.thetadata[0]=12; //dThetaF0
    psW->sParam.thetadata[1]=36; //dThetaF0
    psW->sParam.thetadata[2]=4*PD_SAMPLING_RATE; //fny 
    psW->sParam.thetadata[3]=3*PD_SAMPLING_RATE; //wny       

    
    
    
}

void *watom_t_new(t_floatarg fArg UNUSED){
    
    sWatom_t *psW = (sWatom_t *)pd_new(pcWatom_t);
    
    watom_t_set_pointers_to_NULL(psW);
    
    psW->x_outC = outlet_new(&(psW->x_obj), &s_signal);

    psW->x_outM = outlet_new(&(psW->x_obj), 0); 
    
    watom_t_set_start_values(psW);        
    
    watom_t_initialize(psW,0);
    
    return (void *)psW;
}

void watom_t_delete(sWatom_t* psW){

        outlet_free(psW->x_outC);
        outlet_free(psW->x_outM);
        
 	watom_t_initialize_pac(psW);
	watom_t_initialize_paf(psW);
        
        wabor_t_free(psW->pac);
        wabor_t_free(psW->sParam.paf_r);
        wabor_t_free(psW->sParam.paf_i);
        watom_t_set_pointers_to_NULL(psW);
}

void watom_t_dsp(sWatom_t* psW, t_signal **sp){
#define WATOM_T_PERFORM_NUM_POINTERS (2)
        dsp_add(watom_t_perform, WATOM_T_PERFORM_NUM_POINTERS, 
            psW,
            sp[0]->s_vec
            );
}

t_int *watom_t_perform(t_int *aw){
    
    sWatom_t    *psW = (sWatom_t *)(aw[1]);
    t_sample    *outC = (t_sample *)(aw[2]);
    
    hide_int_at_address( WABOR_T_MAGIC_NUMBER_C, &outC[WABOR_T_MAGIC_NUMBER_BIN]);
    hide_pointer_at_address(&(psW->sParam), &outC[WABOR_T_WATOM_PARAM]);
    
    
    return (aw + WATOM_T_PERFORM_NUM_POINTERS + 1);
}



void watom_t_bang(sWatom_t const * const psW){
    static t_int i=0;
    sWatom_Param const * const p = &(psW->sParam);
    ++i;
    
    if(i>10 && i<20) post("Why are you banging me?"); 
    if(i>20 && i<26) post("I don't like being banged!"); 
    if(i>26 && i<30) post("WHY ARE YOU BANGING ME?");
    if(i>30) post("tommsch is the best!");
    
    
    post("\n-----------------Wabor--------------:");
    post("WinType: \t%i",(int)p->eWindowType);        
    post("ThetaType: \t%i",(int)p->eThetaType);
    post("ThetaPath: \t%s", p->thetapath);
    post("qsup: \t%i", (int)p->iq_compute_sup);
    post("Essential Bandwidth: \t%f Hz",(double)p->_K);
    post("R: \t %f",p->_R);
    post("T_window: \t%f\ts",(double)p->dWinlength_window);
    double ratio =(double)p->dWinlength_window/(double)p->dWinlength_compute;
    post("T_compute: \t%f\ts, C_T_c:  \t%f \ts, \t, T_h/T_c:\t %f \t" ,(double)p->dWinlength_compute, (double)p->C_T_c, ratio);
    post("T_max: \t%f\ts", (double)p->T_max);
    post("Longest Frame paf: \t%i smp=\t%f\ts", (int)p->iLongestFrame_paf, p->iLongestFrame_paf/PD_SAMPLING_RATE);
    double _a=(double)p->_a, _aSamples=(double)p->_a*PD_SAMPLING_RATE, _b=(double)p->_b;
    post("a: \t%f[s]=%f\tsmp, b: \t%f\tHz, C_b: \t%f", _a, _aSamples, _b,(double)p->C_b);
    post("f0: \t%f\tHz, k: \t%f",(double)(p->thetadata[0]), (double)(p->thetadata[1]));
    post("C_d: \t%f",(double)p->C_d);    
    post("C_cut: \t%f",p->C_cut);
    if(DEBUG) post("ComputeType: \t%i", (int)p->iComputeType);
    float fComplexity=0;
    float fComplexityWorst=0;
    float fAverage=0;
    for(t_int q=0; q<p->iq_compute_sup; ++q){
        if(psW->sParam.paf_r[q]==NULL || p->aiDq==NULL) {
            fComplexity=-1;
            fComplexityWorst=-1;
            fAverage=-1;
            break;
        } 
        fComplexity+=psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]/(float)p->aiDq[q];
        fComplexityWorst+=psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN];
        fAverage+=psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN];
    }
    fAverage/=psW->sParam.iq_compute_sup;
    fComplexity*=4;
    fComplexityWorst*=4;
    if(fComplexity!=-1)         post("4 Sum_q T_q/d_q: \t%f",fComplexity);
    if(fComplexityWorst!=-1)    post("4 Sum_q T_q: \t%f\t smp",fComplexityWorst);
    if(fAverage!=-1)            post("1/N_q Sum_q T_q: \t%f\t smp",fAverage);
    if (DEBUG) {
        post("------------------Not important stuff");
        char* cDate = __DATE__;
        char* cTime = __TIME__;
        post("Buildtime \t%s\t, \t%s",cDate, cTime);
        post("Var= \t%f", psW->var);
    }
    return;

}


void watom_t_make_receive_list(sWatom_t* psW UNUSED, t_symbol *s UNUSED, int argc UNUSED, t_atom *argv UNUSED){
    post("test");
}

t_int watom_t_test_compileparam(){ 
    t_int iErrCount=0;
    //Folgende Tests brauch ich, damit alles richtig aligned ist
    if(DEBUG) post("sizeof pac_type: \t%i", sizeof(pac_type));
    if(DEBUG) post("sizeof paf_type: \t%i", sizeof(paf_type));
    if(7*sizeof(void*)>PD_BLOCKSIZE*sizeof(t_float)) {error ("wabor_t: 7*sizeof(void*)>PD_BLOCKSIZE*sizeof(t_float). Can't save pointer/gabor data in audio frame. Change Sourcecode."); }

    if(PD_BLOCKSIZE!=64) {error ("PD_BLOCKSIZE!=64"); ++iErrCount; }
    
    return iErrCount;
}

t_int watom_t_test_param(sWatom_t const * const psW, const t_int iPrintOutput){
    double f;
    //t_int iErrCount=0;
    sWatom_Param  const * const p=&(psW->sParam);
    if(iPrintOutput) error("Ueberpruefe Parameter von Wabor:");
    
    if(sys_getsr()!=44100) error("Samplerate=%f falsch.",sys_getsr());
    
    //Allgemeine Tests
    if(p->iq_compute_sup<=0) {error("q_sup<0");}
    
    //Test ob F_MIN passt
    if(p->thetadata[0]<= 0) {error("ThetaF0 <= 0"); }
    
    //Test ob C_SR passt
    if( p->C_SR < 1) { error("C_SR < 1");}
    for(t_int q=0; q<p->iq_compute_sup; ++q){
        if(p->aiDq[q]<1) { 
            error("d_q < 1 sample bei Band: \t%i\t, d_%i=\t%f",(int)q,(int)q,(double)p->aldDq_real[q]);
        }
    }
    for(t_int q=1; q<p->iq_compute_sup; ++q){
        if(p->aiDq[q-1] < p->aiDq[q]-1) error("d[%i]=\t%i\t > d[%i]=\t%i",(int)q-1,(int)p->aiDq[q-1],(int)q,(int)p->aiDq[q]);
    }
    
        
    return 0;
}

void watom_t_initialize(sWatom_t* psW, t_float override){
    sWatom_Param *p=&(psW->sParam);
    
    {
        pac_type_real f0, k;
        f0=p->thetadata[0];
        k=p->thetadata[1];
        wabor_t_free(p->thetadata);
        p->thetadata=wabor_t_malloc0(4*sizeof(pac_type_real));
        p->thetadata[0]=f0;
        p->thetadata[1]=k;
        p->thetadata[2]=4*PD_SAMPLING_RATE;
        p->thetadata[3]=3*PD_SAMPLING_RATE;
    }
    
    switch ((t_int)p->eThetaType)
    {    
        default:
            error("wabor_t: Wrong Theta chosen");
            error("wabor_t: Change to EXP_C1_NYQU");
            p->eThetaType=EXP_C1_NYQU;
        case EXP_C1_NYQU:            
            p->Theta=wabor_t_Theta_exp_c1_nyqu; 
            p->Theta_inv=wabor_t_Theta_inv_exp_c1_nyqu;
            p->d_Theta_infimum=wabor_t_d_Theta_inf_exp_c1_nyqu;
            break;
        case ID:
            p->Theta=wabor_t_Theta_id;
            p->Theta_inv=wabor_t_Theta_inv_id;
            p->d_Theta_infimum=wabor_t_d_Theta_inf_id;
            break;
        case LIN:
            p->Theta=wabor_t_Theta_lin; 
            p->Theta_inv=wabor_t_Theta_inv_lin;
            p->d_Theta_infimum=wabor_t_d_Theta_inf_lin;
            break; 
        case SQUARE:
            p->Theta=wabor_t_Theta_square; 
            p->Theta_inv=wabor_t_Theta_inv_square;
            p->d_Theta_infimum=wabor_t_d_Theta_inf_square;
            break;
         case BSPLINE:
         {
             
            p->Theta=wabor_t_Theta_bspline;
            p->Theta_inv=wabor_t_Theta_inv_bspline;
            p->d_Theta_infimum=wabor_t_d_Theta_inf_bspline;

            FILE *processedFile;
            if(strlen(p->thetapath)<WABOR_T_MAXPATHLENGTH-10-1){
                char processedpath[WABOR_T_MAXPATHLENGTH];
                strcpy(processedpath,p->thetapath);
                strcat(processedpath,".processed");
                processedFile = fopen (processedpath, "r");
            }
            if(processedFile!=NULL){ //if file was already opened before, this file exists and the data for the program is directly read from that file
                pac_type_real f0, k;
                f0=p->thetadata[0];
                k=p->thetadata[1];
                wabor_t_free(p->thetadata);
                
                int sizew, startw, sizef, startf;
                
                fscanf(processedFile, "%d %d %d %d", &sizew, &startw, &sizef, &startf);
                p->thetadata=wabor_t_malloc0((4+sizew+sizef+2*WABOR_T_PADDING_LEFT)*sizeof(pac_type_real));
                
                pac_type_real* data_theta_of_w=p->thetadata+4+WABOR_T_PADDING_LEFT;
                pac_type_real* data_theta_of_f=p->thetadata+4+WABOR_T_PADDING_LEFT+sizew+WABOR_T_PADDING_LEFT;

                data_theta_of_f[WABOR_T_LENGTH_BIN]=sizef;
                data_theta_of_f[WABOR_T_PLACE_HOLDER]=startf;
                data_theta_of_w[WABOR_T_LENGTH_BIN]=sizew;            
                data_theta_of_w[WABOR_T_PLACE_HOLDER]=startw;

                p->thetadata[0]=f0;
                p->thetadata[1]=k;
                p->thetadata[2]=4*PD_SAMPLING_RATE;
                p->thetadata[3]=3*PD_SAMPLING_RATE;
                
                pac_type_real val;
                for(int w=0; w<sizew; ++w){
                    fscanf(processedFile, "%lf", &val);
                    data_theta_of_w[w]=val;
                }
                for(int f=0; f<sizef; ++f){
                    fscanf(processedFile, "%lf", &val);
                    data_theta_of_f[f]=val;                    
                }
                
                fclose(processedFile);
                processedFile=NULL;
                
            } else { //if file was not read before
                
                fclose(processedFile);
                processedFile=NULL;
                
                FILE *myFile;
                myFile = fopen(p->thetapath, "r");
                if(myFile==NULL){ // if file can't be read
                    p->thetapath[WABOR_T_MAXPATHLENGTH- 20 ]='\0'; //'File not found' is 14 characters long, 20 is bigger than 14+1
                    strcat(p->thetapath, "File not found.");
                    post("File not found. Change to EXP_C1_NYQU.");
                    fclose(myFile);        
                    p->eThetaType=EXP_C1_NYQU;
                    watom_t_initialize(psW, override);
                    return;
                }           


                int sizet;

                fscanf(myFile, "%d", &sizet); //Groesse steht in der ersten Zeile

                pac_type_real f0, k;
                f0=p->thetadata[0];
                k=p->thetadata[1];
                wabor_t_free(p->thetadata);
         

                if(sizet<=0){
                    p->thetapath[WABOR_T_MAXPATHLENGTH- 20 ]='\0'; //'File not found' is 14 characters long, 20 is bigger than 14+1
                    post("Thetadata file is wrong. Size entry in first row nonpositive.");
                    fclose(myFile);        
                    p->eThetaType=EXP_C1_NYQU;
                    watom_t_initialize(psW, override);
                    return;
                }

                pac_type_real* tablef=wabor_t_malloc0(sizet*sizeof(pac_type_real));
                pac_type_real* tablew=wabor_t_malloc0(sizet*sizeof(pac_type_real));


                double valw,valf;
                fscanf(myFile, "%lf %lf", &valf, &valw);

                tablef[0]=(pac_type_real)valw; //valW->tableF is on purpose
                tablew[0]=(pac_type_real)valf; //valF->tableW is on purpose
                if(tablef[0]>0 || tablew[0]>0 ){
                    post("Thetadata file is wrong. Data does not start with negative values.");
                }
                for(int i=1;i<sizet;++i){
                    fscanf(myFile, "%lf %lf", &valf, &valw);
                    tablef[i]=(pac_type_real)valw; //valW->tableF is on purpose
                    tablew[i]=(pac_type_real)valf; //valF->tableW is on purpose

                    if(tablef[i]-tablef[i-1]<0 || tablew[i]-tablew[i-1]<0 ){
                        post("Thetadata file is wrong. Data not monotone increasing.");
                    }
                }
                fclose(myFile);
                myFile=NULL;

                int startf=(int)tablef[0]; //Sollte kein Problem sein hier plus eins zu schreiben
                int startw=(int)tablew[0];
                int endf=(int)(1+tablef[sizet-1]);
                int endw=(int)(1+tablew[sizet-1]);
                int sizew=endw-startw;
                int sizef=endf-startf;


                p->thetadata=wabor_t_malloc0((4+sizew+sizef+2*WABOR_T_PADDING_LEFT)*sizeof(pac_type_real));
                pac_type_real* data_theta_of_w=p->thetadata+4+WABOR_T_PADDING_LEFT;
                pac_type_real* data_theta_of_f=p->thetadata+4+WABOR_T_PADDING_LEFT+sizew+WABOR_T_PADDING_LEFT;

                data_theta_of_f[WABOR_T_LENGTH_BIN]=sizef;
                data_theta_of_f[WABOR_T_PLACE_HOLDER]=startf;
                data_theta_of_w[WABOR_T_LENGTH_BIN]=sizew;            
                data_theta_of_w[WABOR_T_PLACE_HOLDER]=startw;

                p->thetadata[0]=f0;
                p->thetadata[1]=k;
                p->thetadata[2]=4*PD_SAMPLING_RATE;
                p->thetadata[3]=3*PD_SAMPLING_RATE;

                pac_type_real tw=0;
                for(int w=startw; w<endw; ++w){
                    tw=bspline_inter_inv(bspline_inter2_second,w,tablef,tablew,sizet,WABOR_T_BSPLINE_ORDER,tw,tw+1,1e-9);
                    pac_type_real f= data_theta_of_w[w-startw]=bspline_inter2_first(tw,tablef,tablew,sizet,WABOR_T_BSPLINE_ORDER);
                    data_theta_of_w[w-startw]=f;
                }
                pac_type_real tf=0;
                for(int f=startf; f<endf; ++f){
                    tf=bspline_inter_inv(bspline_inter2_first,f,tablef,tablew,sizet,WABOR_T_BSPLINE_ORDER,tf,tf+1,1e-9);
                    pac_type_real w=bspline_inter2_second(  tf,tablef,tablew,sizet,WABOR_T_BSPLINE_ORDER);
                    data_theta_of_f[f-startf]=w;
                }

                wabor_t_free(tablef); tablef=NULL;
                wabor_t_free(tablew); tablew=NULL;


                if(strlen(p->thetapath)<WABOR_T_MAXPATHLENGTH-10-1){
                    pac_type_real* dataf=p->thetadata+4+WABOR_T_PADDING_LEFT;
                    pac_type_real* dataw=p->thetadata+4+WABOR_T_PADDING_LEFT+((int)(dataf[WABOR_T_LENGTH_BIN]))+WABOR_T_PADDING_LEFT;
                    FILE * outputfile;
                    char newpath[WABOR_T_MAXPATHLENGTH];
                    strcpy(newpath,p->thetapath);
                    strcat(newpath,".processed");
                    outputfile = fopen (newpath, "w+");

                    if(outputfile!=NULL){
                        int fmax=(int)dataf[WABOR_T_LENGTH_BIN];
                        int fstart=(int)dataf[WABOR_T_PLACE_HOLDER];
                        int wmax=(int)dataw[WABOR_T_LENGTH_BIN];
                        int wstart=(int)dataw[WABOR_T_PLACE_HOLDER];

                        fprintf(outputfile, "%d \n%d\n", fmax,fstart);
                        fprintf(outputfile, "%d \n%d\n", wmax,wstart);

                        for(int i=0; i<fmax; ++i){
                            fprintf(outputfile, "%.17g\n", dataf[i]);
                        }

                        for(int i=0; i<wmax; ++i){
                            fprintf(outputfile, "%.17g\n", dataw[i]);
                        }
                    }     
                    fclose(outputfile);
                    outputfile=NULL;
                    
                }
            }
            
            
            
        }
        break;

    }

    
    //Alles loeschen
    watom_t_initialize_diverse_vectors(psW);
    
    watom_t_initialize_pac(psW);    wabor_t_free(psW->pac);             psW->pac=NULL;
    watom_t_initialize_paf(psW);    wabor_t_free(psW->sParam.paf_r);
                                    wabor_t_free(psW->sParam.paf_i); 
                                    psW->sParam.paf_r=NULL;
                                    psW->sParam.paf_i=NULL;
    
    psW->var=1;
    
    //Werte neu berechnen
    
   
    if(!override){
        
        switch (psW->sParam.eWindowType){

            case WIN_COS:
            {
                p->_R=p->_K;
                pac_type_real f0=p->thetadata[0];
                p->dWinlength_window=p->_R/2.0L/f0;
                pac_type_real theta_inf=p->d_Theta_infimum(0, p->thetadata);
                if( fabsPAC(p->d_Theta_infimum(0, p->thetadata)) < 1e-2 ) {
                    p->dWinlength_compute = p->dWinlength_window*3*p->C_T_c; // Beliebig gewaehlter Wert
                } else {
                    p->dWinlength_compute=p->dWinlength_window*1.0L/p->d_Theta_infimum(0, p->thetadata)*p->C_T_c; 
                }
                p->_a=p->dWinlength_window/(pac_type_real)p->_R;
                p->_b=1.0L/( p->_a * p->_R * p->C_b);
                //p->_K=(pac_type_real)p->_R/p->dWinlength_window;
                break;
            }

            case WIN_COS_NOT_WARPED:
            {
                p->_R=p->_K;
                pac_type_real f0=p->thetadata[0];
                p->dWinlength_window=p->_R/(2.0L*f0);
                p->dWinlength_compute=p->dWinlength_window;
                p->_a = 1.0L/(2.0L*f0);
                p->_b = (2.0L*f0)/(p->_R*p->C_b);
                //p->_K=p->_R/p->dWinlength_window;
                break;
            }

            default:
            case WIN_SQRT_GAUSS:
            {
                pac_type_real f0=p->thetadata[0];

                p->_R=p->_K; //Aufrunden auf nachste ganze Zahl
                p->dWinlength_window=p->_R/2.0L/f0;
                pac_type_real theta_inf=p->d_Theta_infimum(0, p->thetadata);
#define WABOR_T_MAX_CONSTANT (3.0) // Beliebig gewaehlter Wert
                if( fabsPAC(p->d_Theta_infimum(0, p->thetadata)) < 1.0/WABOR_T_MAX_CONSTANT ) {
                    p->dWinlength_compute = p->dWinlength_window*WABOR_T_MAX_CONSTANT*p->C_T_c; 
#undef WABOR_T_MAX_CONSTANT                    
                } else {
                    p->dWinlength_compute=p->dWinlength_window*1.0L/theta_inf*p->C_T_c; 
                }
                p->_a=p->dWinlength_window/(pac_type_real)p->_R;
                p->_b=1.0L/( p->_a * p->_R * p->C_b);
                //p->_K=(pac_type_real)p->_R/p->dWinlength_window;            
                

                (p->thetadata)[2]=PD_SAMPLING_RATE*4;   
                (p->thetadata)[3]=PD_SAMPLING_RATE*3;              
                
                break;
            }
        }
    }
    
    //Alles neu machen
    p->iq_compute_sup = watom_t_get_q_compute_sup(psW); 
    
    watom_t_initialize_diverse_vectors(psW);   
    watom_t_initialize_pac(psW);    
    watom_t_initialize_paf(psW);    
    
    //Diverse Vektoren berechnen berechnen
    
    for(t_int q=0; q < p->iq_compute_sup; ++q){
        //Berechnen von adDq und aiDq
          
        pac_type_real d1 = psW->sParam.Theta( q * p->_b + p->_K *p->_b / 2.0L, p->thetadata); 
        pac_type_real d2 = psW->sParam.Theta( q * p->_b - p->_K *p->_b / 2.0L, p->thetadata);
        pac_type_real ldBq = d1-d2;
        p->aldDq_real[q]= fabsPAC(1.0L/ldBq/p->C_d);
        
        p->aiDq[q] = (t_int)(p->aldDq_real[q]*PD_SAMPLING_RATE);  //d_q auf Bins runden
        if(p->aiDq[q]>=2) {
            p->aldDq[q]=(pac_type_real)p->aiDq[q]/(pac_type_real)PD_SAMPLING_RATE; // d_q nachberechnen
        } else if (p->aiDq[q]>=1){
            post("wabor_t: Probably window with to high bandwidth: d_q < 2 sample at frequency bin %i",(int)q);
            p->aldDq[q]=(pac_type_real)p->aiDq[q]/(pac_type_real)PD_SAMPLING_RATE; // d_q nachberechnen
        } else {
            error("wabor_t: Window with too high bandwidth: d_q < 1 sample at frequency bin %i",(int)q);
            p->aiDq[q]=1;
            p->aldDq[q]=p->aldDq_real[q];
            //Hier berechne ich aldDq nicht nach
        }
    }      
    
    watom_t_test_param(psW, 0);
}

void watom_t_initialize_pac(sWatom_t* psW){
   //NULL
    //Initialisiert pac/paf
    //Diese Funktion muss aufgerufen werden, bevor irgendwas mit pac/paf gemacht wird
    //Nach dem Aufruf dieser Funktion sind alle pac[i]/paf[i] == NULL
    //Diese Funktion kann ohne Probleme oefters aufgerufen werden duerfen

    //Alle Funktionen muessen pac und paf in konsistentem Zustand hinterlassen
    //pac[i] == NULL wenn kein speicher mehr fuer pac[i] allokiert ist
    //Wenn pac[i] != NULL dann ist in 
    //crealPAC(pac[i][WABOR_T_LENGTH_BIN]), paf[i][WABOR_T_LENGTH_BIN] :die Laenge des Vektors pac[i]
    //cimagPAC(pac[i][WABOR_T_LENGTH_BIN]) : unbenutzt
    //crealPAC(pac[i][WABOR_T_PLACE_HOLDER]), paf[i][WABOR_T_FREQU_BIN]: Faktor (Natuerliche Zahl groessergleich 1) Mit welcher SR es gespeichert ist
    //cimagPAC(pac[i][WABOR_T_PLACE_HOLDER]): Unbenutzt

    t_int q_sup = psW->sParam.iq_compute_sup;
    if(q_sup<=0) return;
    if(psW->pac==NULL){
        psW->pac = wabor_t_malloc0(q_sup * sizeof *(psW->pac));
        if(psW->pac == NULL) return;
        for (t_int q = 0; q < q_sup; ++q){
                psW->pac[q] = NULL;
        }
    } else {
        for (t_int q = 0; q < q_sup; ++q) {
            wabor_t_free(psW->pac[q]);
            psW->pac[q] = NULL;
        }
    }
    return;
}

void watom_t_initialize_paf(sWatom_t* psW){
    //NULL 
    //Erklaerung siehe watom_t_initialize_pac
    t_int q_sup = psW->sParam.iq_compute_sup;
    if(q_sup==0) return;
    if(psW->sParam.paf_r==NULL){ //Wenn das NULL ist, sind noch keine arrays allokiert
        psW->sParam.paf_r = wabor_t_malloc0(q_sup * sizeof *(psW->sParam.paf_r)); 
        psW->sParam.paf_i = wabor_t_malloc0(q_sup * sizeof *(psW->sParam.paf_i));
        if(psW->sParam.paf_r==NULL || psW->sParam.paf_i==NULL ){
            wabor_t_free(psW->sParam.paf_r);
            wabor_t_free(psW->sParam.paf_i);
            psW->sParam.paf_r=NULL; 
            psW->sParam.paf_i=NULL; 
            return;
        }
        for (t_int i = 0; i < q_sup; ++i) { 
            psW->sParam.paf_r[i] = NULL; 
            psW->sParam.paf_i[i] = NULL; 
        }
    } else {
        for (t_int i = 0; i < q_sup; ++i) {
            wabor_t_free(psW->sParam.paf_r[i]); 
            wabor_t_free(psW->sParam.paf_i[i]); 
            psW->sParam.paf_r[i] = NULL; 
            psW->sParam.paf_i[i] = NULL; 
        }
    }
    return;
}


void watom_t_initialize_diverse_vectors(sWatom_t* psW){
    t_int q_sup = psW->sParam.iq_compute_sup;
    wabor_t_free(psW->sParam.aldDq_real);
    wabor_t_free(psW->sParam.aldDq);
    wabor_t_free(psW->sParam.aiDq);
    
    psW->sParam.aldDq=NULL;
    if(q_sup<=0) return;
    
    psW->sParam.aldDq_real = wabor_t_malloc0(q_sup * sizeof *(psW->sParam.aldDq_real));
    psW->sParam.aldDq = wabor_t_malloc0(q_sup * sizeof *(psW->sParam.aldDq));
    psW->sParam.aiDq = wabor_t_malloc0(q_sup * sizeof *(psW->sParam.aiDq));
    
    return;
    
}

 void watom_t_make(sWatom_t *psW, t_float fAN){
    watom_t_make_windows(psW, (t_int)fAN);
    return;
}
void watom_t_shorten(sWatom_t *psW, t_float fAN){ 
    watom_t_shorten_windows(psW, (t_int)fAN);
    return;
}
void watom_t_test(sWatom_t *psW, t_float fPrintOut){ 
    watom_t_test_windows(psW, (t_int)fPrintOut);
    return;
}

void watom_t_make_windows(sWatom_t *psW, t_int iAN){
    //Alle Fenster die nur einmal vorkommen sollen in synthese muessen durch 2 dividiert werden,
    // da in der synthese mit 2 multipliziert wird.
    
    t_int qmin,qsup;
    if(iAN<0){
    qmin=0;
    qsup=psW->sParam.iq_compute_sup;
    } else if(iAN>psW->sParam.iq_compute_sup){
        return;
    } else {
        qmin=(t_int)iAN;
        qsup=qmin+1;
    }

    enum _eWindowType eTYPE=psW->sParam.eWindowType;
    switch (eTYPE)
    {          
        case WIN_COS_NOT_WARPED:
        {
            
            if(psW->sParam.aldDq==NULL) return;
            const pac_type_real ldWL=psW->sParam.dWinlength_window;
            const pac_type_real dN = ldWL * PD_SAMPLING_RATE * psW->sParam.C_SR;
            t_int iN=(t_int) dN;
            if(dN!=iN) post("Fensterlaenge dN=%f nicht ganzzahlig",(double)dN);
            const pac_type_real _b=psW->sParam._b;
            const pac_type_real _a=psW->sParam._a;
            const pac_type_real ldHeight=sqrtPAC(2.0L*_b/psW->sParam._R); //Original
            const pac_type_real d = psW->sParam.aldDq[0];
            
            if(qsup*sizeof(pac_type)*iN>WABOR_T_MAX_WINDOW_MEMORY){
                post("Windows need too much memory");
                return;
            }
            
            for(t_int q=qmin; q<qsup; ++q){

                wabor_t_free(psW->pac[q]);
                psW->pac[q]=wabor_t_malloc0(iN * sizeof **(psW->pac)); 
                if(psW->pac[q]==NULL) {
                    error("watom_t_make: Out of memory");
                    watom_t_initialize_pac(psW);
                    return;
                }
                for(t_int i=0; i<iN; ++i){
                    #define I2T(i) ((i)*ldWL/dN-ldWL/2.0L)
                    
                    
                    pac_type_real time=(pac_type_real)I2T(i);
                    pac_type exponent=2.0L*PI*I*wabor_t_Theta_lin(q*_b,psW->sParam.thetadata)*time;
                    pac_type val=sqrtPAC(d/_a)*cexpPAC(exponent)*wabor_t_wf_win_cos(time, ldHeight, ldWL, 0);
                    psW->pac[q][i]=val;
                    #undef I2T  
                }
                
                if(q!=0){ 
                    for(t_int i=0; i<iN; ++i){
                        psW->pac[q][i]*=SQRT2; //Since these window must be counted twice
                    }
                }
                
                psW->pac[q][WABOR_T_LENGTH_BIN]=iN+0*I;
                psW->pac[q][WABOR_T_PLACE_HOLDER]=0+0*I;

            }
            
            break;   
        }
        
        case WIN_SQRT_GAUSS:
        {
            
            t_int iSRFactor=psW->sParam.C_SR;
            const pac_type_real _b=psW->sParam._b;
            const pac_type_real _a=psW->sParam._a;
            t_int iN_output = (t_int)(psW->sParam.dWinlength_compute * PD_SAMPLING_RATE + 0.5);
            iN_output=round_up_to_multiple_of_small_primes(iN_output,31);
            psW->sParam.dWinlength_compute=(pac_type_real)iN_output/PD_SAMPLING_RATE;
            t_int iN = iN_output * iSRFactor;
            
            if(qsup*sizeof(pac_type)*iN>WABOR_T_MAX_WINDOW_MEMORY){
                post("Windows need too much memory");
                return;
            }
            
            pac_type_real ldDeltaF=1.0L/psW->sParam.dWinlength_compute;
            pac_type_real ldHeight=sqrtPAC(_b/2/psW->sParam._R); //SQRT_GAUSS
            pac_type_real ldLength_window=psW->sParam.dWinlength_window;
            for(t_int q=qmin; q<qsup; ++q) {                
                pac_type_real ldFactor=sqrtPAC(fabsPAC(psW->sParam.aldDq[q]/_a));
                
            psW->sParam.thetadata[2]=(qsup-psW->sParam.C_q)*psW->sParam._b;
            psW->sParam.thetadata[3]=PD_SAMPLING_RATE/2;
#define WIN(f) (wabor_t_wf_WIN_SQRT_GAUSS((f),ldHeight, ldLength_window, 0))
#define THETA_INV(f) (psW->sParam.Theta_inv((f),psW->sParam.thetadata))
#define I2F(m) ((m)*ldDeltaF)
                pac_type_real *TEMP=psW->sParam.thetadata;
                wabor_t_free(psW->pac[q]);
                psW->pac[q]=wabor_t_malloc0(iN * sizeof **(psW->pac)); 
                if(psW->pac[q]==NULL) {
                    error("watom_t_make: Out of memory");
                    watom_t_initialize_pac(psW);
                    return;
                }
                pac_type val;
                for(t_int i=0; i<=iN/2; ++i) {  
                   val = WIN(THETA_INV(I2F(i))-q*_b)*ldFactor;
                   if(psW->sParam.iComputeType==1) {
                       val+= WIN(THETA_INV(I2F(i) - PD_SAMPLING_RATE)-q*_b)*ldFactor +
                             WIN(THETA_INV(I2F(i) + PD_SAMPLING_RATE)-q*_b)*ldFactor;//echt
                   }
                   psW->pac[q][i]=val;
                }
                for(t_int i=iN/2+1; i<iN; ++i) {
                    val= WIN(THETA_INV(I2F(i-iN))-q*_b)*ldFactor;
                    if(psW->sParam.iComputeType==1) {                                   
                        val+=WIN(THETA_INV(I2F(i-iN) - PD_SAMPLING_RATE)-q*_b)*ldFactor +
                             WIN(THETA_INV(I2F(i-iN) + PD_SAMPLING_RATE)-q*_b)*ldFactor; //echt
                    }
                    psW->pac[q][i]=val;
                }      
                if(DEBUG) for(t_int j=0; j<iN; ++j){
                    if( !isfinite(crealPAC(psW->pac[q][j])) || !isfinite(cimagPAC(psW->pac[q][j])) ){
                        post("Value in make_window wrong.");
                    }
                }
                
                if(iSRFactor!=1 && psW->sParam.iComputeType==0){
                    const t_int i0=PD_SAMPLING_RATE/(2.0*ldDeltaF); 
                    if(i0>0 && i0<iN) {
                        for(t_int i=i0; i<-iN-i0+1; ++i){ //Alle Frequenzen die groesser als SR/2 sind, loeschen
                            psW->pac[q][i]=0; 
                        }
                    }
                }
                if(psW->sParam.iComputeType==1){
                    if(q!=0 && q<qsup-1){
                        for(t_int i=0; i<iN; ++i){
                            psW->pac[q][i]*=SQRT2; //Since theses window must be computed twice
                        }                     
                    }
                } else {
                    if(q!=0){
                        for(t_int i=0; i<iN; ++i){
                            psW->pac[q][i]*=SQRT2; //Since theses window must be computed twice
                        }   
                    }
                        
                }

                psW->pac[q][WABOR_T_LENGTH_BIN]=iN+0*I;
                psW->pac[q][WABOR_T_PLACE_HOLDER]=0+0*I;
                
 
                wabor_t_simplefft_array(&(psW->pac[q]),&(psW->pac[q]),FFTW_BACKWARD);

                //Ich cycle hier, weil ich die Fenster zum Verarbeiten in dieser Lage dann brauche
                wabor_t_cycle_array(&(psW->pac[q]),-iN/2);  

                for(t_int i=0; i<iN; ++i){
                    psW->pac[q][i]=psW->pac[q][i]*ldDeltaF;
                }

                if(iSRFactor!=1){
                    for(t_int i=0; i<iN_output; ++i){
                        psW->pac[q][i]=psW->pac[q][i*iSRFactor]; //Downsampling. Ich kann linear downsamplen, da ich oben alle hohen Frequenzanteile auf 0 gesetzt habe
                    }
                }
                
                psW->pac[q][WABOR_T_LENGTH_BIN]=iN_output+0*I;
                     
#undef WIN
#undef THETA_INV
#undef I2F
            }
            break;
        }
        
        
        case WIN_COS:
        {         
            t_int iSRFactor=psW->sParam.C_SR;
            const pac_type_real _b=psW->sParam._b;
            const pac_type_real _a=psW->sParam._a;
            t_int iN_output = (t_int)(psW->sParam.dWinlength_compute * PD_SAMPLING_RATE + 0.5);
            iN_output=round_up_to_multiple_of_small_primes(iN_output,5);
            psW->sParam.dWinlength_compute=(pac_type_real)iN_output/PD_SAMPLING_RATE;
            t_int iN = iN_output * iSRFactor;
            pac_type_real ldDeltaF=1.0L/psW->sParam.dWinlength_compute;

            pac_type_real ldHeight=sqrtPAC(2.0L*_b/psW->sParam._R); //Original
            pac_type_real ldLength_window=psW->sParam.dWinlength_window;
            for(t_int q=qmin; q<qsup; ++q) {
                
                pac_type_real ldFactor=sqrtPAC(fabsPAC(psW->sParam.aldDq[q]/_a));
                
#define WIN(f) (wabor_t_wf_WIN_COS((f),ldHeight, ldLength_window, 0))
#define THETA_INV(f) (psW->sParam.Theta_inv((f), psW->sParam.thetadata))
#define I2F(m) ((m)*ldDeltaF)
                
                wabor_t_free(psW->pac[q]);
                psW->pac[q]=wabor_t_malloc0(iN * sizeof **(psW->pac)); 
                if(psW->pac[q]==NULL) {
                    error("watom_t_make: Out of memory");
                    watom_t_initialize_pac(psW);
                    return;
                }
                pac_type val;
                for(t_int i=0; i<=iN/2; ++i) {  
                   val = WIN(THETA_INV(I2F(i))-q*_b)*ldFactor;
                   if(psW->sParam.iComputeType==1) {
                       val+= WIN(THETA_INV(I2F(i) - PD_SAMPLING_RATE)-q*_b)*ldFactor +
                             WIN(THETA_INV(I2F(i) + PD_SAMPLING_RATE)-q*_b)*ldFactor;//echt
                   }
                   psW->pac[q][i]=val;
               }
               for(t_int i=iN/2+1; i<iN; ++i) {
                   val= WIN(THETA_INV(I2F(i-iN))-q*_b)*ldFactor;
                   if(psW->sParam.iComputeType==1) {                                   
                       val+=WIN(THETA_INV(I2F(i-iN) - PD_SAMPLING_RATE)-q*_b)*ldFactor +
                            WIN(THETA_INV(I2F(i-iN) + PD_SAMPLING_RATE)-q*_b)*ldFactor; //echt
                   }
                   psW->pac[q][i]=val;
               } 

                if(iSRFactor!=1 && psW->sParam.iComputeType==0){
                    const t_int i0=PD_SAMPLING_RATE/(2.0*ldDeltaF); 
                    if(i0>0 && i0<iN) {
                        for(t_int i=i0; i<-iN-i0+1; ++i){ //Alle Frequenzen die groesser als SR/2 sind, loeschen
                            psW->pac[q][i]=0; 
                        }
                    }
                }
                if(psW->sParam.iComputeType==1){
                    if(q!=0 && q<qsup-1){
                        for(t_int i=0; i<iN; ++i){
                            psW->pac[q][i]*=SQRT2; //Since theses window must be computed twice
                        }                     
                    }
                } else {
                    if(q!=0){
                        for(t_int i=0; i<iN; ++i){
                            psW->pac[q][i]*=SQRT2; //Since theses window must be computed twice
                        }   
                    }
                        
                }

                psW->pac[q][WABOR_T_LENGTH_BIN]=iN+0*I;
                psW->pac[q][WABOR_T_PLACE_HOLDER]=0+0*I;                
 
                wabor_t_simplefft_array(&(psW->pac[q]),&(psW->pac[q]),FFTW_BACKWARD);           

                //Ich cycle hier, weil ich die Fenster zum Verarbeiten in dieser Lage dann brauche
                wabor_t_cycle_array(&(psW->pac[q]),-iN/2); 

                for(t_int i=0; i<iN; ++i){
                    psW->pac[q][i]=psW->pac[q][i]*ldDeltaF;
                }

                
                if(iSRFactor!=1){
                    for(t_int i=0; i<iN_output; ++i){
                        psW->pac[q][i]=psW->pac[q][i*iSRFactor]; //Downsampling. Ich kann linear downsamplen, da ich oben alle hohen Frequenzanteile auf 0 gesetzt habe
                    }
                }
                
                psW->pac[q][WABOR_T_LENGTH_BIN]=iN_output+0*I;
                    
#undef WIN
#undef THETA_INV
#undef I2F

            }
            break;
        }
            		
    default:
        {
            error("Keine zulaessiges Fenster gewaehlt. Setze Fenster auf 0");
            //Fallthrough
    case WIN_ZERO:
            {
                t_int iLength=PD_BLOCKSIZE;
                for(t_int q=qmin; q<qsup; ++q) {
                    wabor_t_free(psW->pac[q]);
                    psW->pac[q]=wabor_t_malloc0(iLength  * sizeof **(psW->pac));
                    if(psW->pac[q]==NULL) {
                       watom_t_initialize_pac(psW);
                       error("watom_t_make: Out of memory");
                       return;
                    }
                    for(t_int i=0; i<iLength; ++i) psW->pac[q][i]=0+0*I;
                    psW->pac[q][WABOR_T_LENGTH_BIN]=iLength  +0*I;
                    psW->pac[q][WABOR_T_PLACE_HOLDER]=0+0*I;
                }
            }
        }
    }
    return;
}

void watom_t_shorten_windows_OLD(sWatom_t *psW, t_int iAN){
    
    sWatom_Param *p=&(psW->sParam);
    t_int qmin,qsup;
    if(iAN<0){
    qmin=0;    
    qsup=p->iq_compute_sup;
    } else if(iAN>p->iq_compute_sup){
        return;
    } else {
        qmin=(t_int)iAN;
        qsup=qmin+1;
    }
    
    t_int iN=0;
    enum _eWindowType eTYPE = p->eWindowType;
    switch (eTYPE)
    {    
       
        case WIN_SQRT_GAUSS:
        case WIN_COS:
        {
            pac_type_real ldMax;
            pac_type_real UNUSED ldSmallVal;
            for(t_int q=qmin; q<qsup; ++q){
                if(psW->pac[q]==NULL) break;
                iN=(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]); //Length of the window
                pac_type placeholder=psW->pac[q][WABOR_T_PLACE_HOLDER];
                ldMax=wabor_t_maximum_array(&(psW->pac[q]));
                ldSmallVal=ldMax/p->C_cut;
                {   
                    t_int N_max=p->T_max*PD_SAMPLING_RATE;
                    //YY fuer Abschneiden nach Betrag
                    t_int N0= wabor_t_get_first_small_value_array(&(psW->pac[q]), ldSmallVal);
                    t_int N1=iN-N0;
                    if((N1-N0)>N_max){
                        N0=(iN-N_max)/2;
                        N1=(iN+N_max)/2;
                        post("Fenster laenger als Tmax fuer q=%i",q);
                    }                 
                    //double t0=N0/PD_SAMPLING_RATE;                    
                    //double t1=(double)N1/(double)PD_SAMPLING_RATE;
                    
                    t_int iTemp=roundup_x(iN-N1,p->aiDq[q]);
                    N1=iN-iTemp; //Hier rechne ich um, damit das Abschneiden mit den d_q zusammenpasst, und meine Fenster weiterhin ausgerichtet sind.
                    t_int iN_new=N1-N0;
                    if( iN_new >= iN) {
                        post("T_c zu klein fuer q=%i",q);
                        iN_new=iN;
                        //Nichts tun
                    } else if (N0<0) {
                        post("wabor_t Abgeschnittenes Fenster ware länger als originales fuer q=%i.",q);
                    }
                    else if( iN_new<=0) {
                        error("make: Fensterfehler");
                        wabor_t_free(psW->pac[q]);
                        psW->pac[q]=NULL;
                    } else {
                        pac_type *pc=NULL;
                        pc=wabor_t_malloc0(iN_new * sizeof **(psW->pac)); 
                        if(pc==NULL){
                            error("watom_t_shorten_windows: Out of memory");
                            return;
                        }
                        memcpy(pc, &(psW->pac[q][N0]), iN_new * sizeof **(psW->pac));
                        wabor_t_free(psW->pac[q]);
                        psW->pac[q]=pc;
                        psW->pac[q][WABOR_T_LENGTH_BIN]=iN_new+0*I;
                        psW->pac[q][WABOR_T_PLACE_HOLDER]=placeholder;

                    }
                }
            }
            break;
        }
        
        case WIN_COS_NOT_WARPED:{
            break;
        }
        default:
            //durchrutschen
        case WIN_ZERO:
        {
            break;
        }
            
    }
    
}

void watom_t_shorten_windows(sWatom_t *psW, t_int iAN){
    
    sWatom_Param *p=&(psW->sParam);
    t_int qmin,qsup;
    if(iAN<0){
    qmin=0;    
    qsup=p->iq_compute_sup;
    } else if(iAN>p->iq_compute_sup){
        return;
    } else {
        qmin=(t_int)iAN;
        qsup=qmin+1;
    }
    
    enum _eWindowType eTYPE = p->eWindowType;
    switch (eTYPE)
    {    
       
        case WIN_SQRT_GAUSS:
        case WIN_COS:
        {
            pac_type_real ldMax;
            pac_type_real UNUSED ldSmallVal;
            for(t_int q=qmin; q<qsup; ++q){
                if(psW->pac[q]==NULL) break;
                t_int Nold=(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]); //Length of the window
                pac_type placeholder=psW->pac[q][WABOR_T_PLACE_HOLDER];
                ldMax=wabor_t_maximum_array(&(psW->pac[q]));
            ldSmallVal=ldMax/p->C_cut;  
                t_int N_max=p->T_max*PD_SAMPLING_RATE;
                //YY fuer Abschneiden nach Betrag
                t_int N0= wabor_t_get_first_small_value_array(&(psW->pac[q]), ldSmallVal);//erster Wert der links ueberbleibt
                t_int N1=Nold-N0;//erster Wert der rechts weggeloescht wird
                if((N1-N0)>N_max){ //Wenn Fenster laenger ist als die maximale gewuenschte Laenge
                    N0=(Nold-N_max)/2;
                    N1=(Nold+N_max)/2;
                    post("Fenster laenger als Tmax fuer q=%i",(int)q);
                }
                
                N0=rounddown_x(N0,p->aiDq[q]); //aufrunden auf vielfaches von dq   //XX
                N1=Nold-N0;
                        
                if(N1<=N0){ 
                    post("Fenster nicht stutzbar fuer q=%i",(int)q);
                    continue; 
                } 
               
                t_int N_new=N1-N0;
                if( N_new >= Nold) {
                    post("T_c zu klein fuer q=%i",(int)q);
                    //Nichts tun
                } else if (N0<0) {
                    post("wabor_t Abgeschnittenes Fenster ware länger als originales fuer q=%i.",(int)q);
                    //Nichts tun
                    
                }
                else if( N_new<=0) {
                    error("make: Fensterfehler fuer q=%i",(int)q);
                    //Nichts tun
                } else {
                    pac_type *pc=wabor_t_malloc0(N_new * sizeof **(psW->pac)); 
                    if(pc==NULL){
                        error("watom_t_shorten_windows Out of memory for q=%i",(int)q);
                        //Nichts tun;
                    } else {
                        memcpy(pc, &(psW->pac[q][N0]), N_new * sizeof **(psW->pac));
                        wabor_t_free(psW->pac[q]);
                        psW->pac[q]=pc;
                        psW->pac[q][WABOR_T_LENGTH_BIN]=N_new+0*I;
                        psW->pac[q][WABOR_T_PLACE_HOLDER]=placeholder;    
                    }
                }
            }
            break;
        }
        
        case WIN_COS_NOT_WARPED:{
            break;
        }
        default:
            //durchrutschen
        case WIN_ZERO:
        {
            break;
        }
            
    }
    
}


t_int watom_t_test_windows(sWatom_t const * const psW, t_int iPrintOutput){
    //Testet ob Fenster alle passen
    t_int iErrCount=0;
    t_int iLength;
    t_int iIsNan=0;
    t_int iIsInf=0;
    t_int iZeros =0 ;
    if(iPrintOutput) error("Ueberpruefe Fenster");
    for(t_int q=0; q<psW->sParam.iq_compute_sup;++q){
        if(psW->pac[q]==NULL) { ++iErrCount; error("Fenster %i: nicht vorhanden",(int)q); break; continue;}
        iLength=psW->pac[q][WABOR_T_LENGTH_BIN];
        
        if( (pac_type_real)iLength < psW->sParam.aiDq[q] ) { ++iErrCount; error ("Fenster %i, Laenge = %i < (t_int)dq = %i",(int)q, (int)iLength ,(int)psW->sParam.aiDq[q]); }
        if( psW->sParam.aiDq[q]==0 ) { ++iErrCount; if(iPrintOutput) error ("(t_int)d_%i = 0",(int)q); }
        
        for( t_int i=0;i<iLength; ++i) { 
            if(isnan(crealPAC(psW->pac[q][i]))) { ++iIsNan; ++iErrCount; }
            if(isnan(cimagPAC(psW->pac[q][i]))) { ++iIsNan; ++iErrCount; }
            if(isinf(crealPAC(psW->pac[q][i]))) { ++iIsInf; ++iErrCount; }
            if(isinf(cimagPAC(psW->pac[q][i]))) { ++iIsInf; ++iErrCount; }
        }
        if(iIsNan) error("Fenster %i: Anzahl Nans: %i",(int)q,(int)iIsNan);
        if(iIsInf) error("Fenster %i: Anzahl Nans: %i",(int)q,(int)iIsInf);
    }
    
    
    if(iErrCount) error("Es gibt Fehler");
    if(iPrintOutput) error("Keine Fehler");
    return iErrCount;
       
    
}
/*pac_type_real watom_t_frequency_shift(pac_type_real dF, pac_type_real dSR){
    //dSR... Sampling Rate
    //dF.... Eingangsfrequenz
    //wenn dF>dSR/2, dann gibt Funktion dF-dSR zurueck
    //ansonsten gibt es dF zuruck
    if(dF>dSR/2.0L) {
        return dF-dSR;
    }
    return dF;
}*/

void watom_t_copy_pac2paf(sWatom_t *psW, t_float fAN){
    //Kopiert alle Werte von pac nach paf
    t_int qmin,qsup;
    t_int iLengthPaf;
    if(fAN<0){
        qmin=0;
        qsup=psW->sParam.iq_compute_sup;
    } else if(fAN>psW->sParam.iq_compute_sup){
        return;
    } else {
        qmin=(t_int)fAN;
        qsup=qmin+1;
    }
    
    for (t_int q = qmin; q < qsup; ++q){
        if (psW->pac[q] != NULL) {
            iLengthPaf=(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]);
            wabor_t_free(psW->sParam.paf_r[q]);
            wabor_t_free(psW->sParam.paf_i[q]);
            psW->sParam.paf_r[q] = wabor_t_malloc0(iLengthPaf * sizeof **(psW->sParam.paf_r));
            psW->sParam.paf_i[q] = wabor_t_malloc0(iLengthPaf * sizeof **(psW->sParam.paf_i));
            if(psW->sParam.paf_r[q]==NULL || psW->sParam.paf_i[q]==NULL){
                error("watom_t_copy_pac2paf: Out of Memory");
                watom_t_initialize_paf(psW);
                return;
            }
            for (t_int j = 0; j < iLengthPaf ; ++j) {
                pac_type Val;
                paf_type Val_r=0;
                paf_type Val_i=0;
                Val=psW->pac[q][j];
                Val_r=(paf_type) crealPAC(Val);
                Val_i=(paf_type) cimagPAC(Val);
                psW->sParam.paf_r[q][j] = Val_r;		
                psW->sParam.paf_i[q][j] = Val_i;
            }
            psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN] = (paf_type)iLengthPaf;
            psW->sParam.paf_r[q][WABOR_T_PLACE_HOLDER] = crealPAC(psW->pac[q][WABOR_T_PLACE_HOLDER]);
            psW->sParam.paf_i[q][WABOR_T_LENGTH_BIN] = (paf_type)iLengthPaf;
            psW->sParam.paf_i[q][WABOR_T_PLACE_HOLDER] = cimagPAC(psW->pac[q][WABOR_T_PLACE_HOLDER]);
        }
    }
    psW->sParam.iLongestFrame_paf=watom_t_find_longest_frame_paf(psW);
}

void watom_t_copy_paf2pac(sWatom_t *psW, t_float fAN){
    //Kopiert alle Werte von paf nach pac
    //Muss nix freen, weil ich dass davor in watom_t_initialize mache
    t_int qmin,qsup;
    if(fAN<0){
    qmin=0;
    qsup=psW->sParam.iq_compute_sup;
    } else if(fAN>psW->sParam.iq_compute_sup){
        return;
    } else {
        qmin=(t_int)fAN;
        qsup=qmin+1;
    }
    
    t_int iLengthPac;
    t_int iLengthPaf;
    
    for (t_int q = qmin; q < qsup; ++q){
        if (psW->sParam.paf_r[q] != NULL) {
            iLengthPaf=(t_int)psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN];
            iLengthPac=iLengthPaf;
            wabor_t_free(psW->pac[q]);
            psW->pac[q] = wabor_t_malloc0(iLengthPac * sizeof **(psW->pac));
            if(psW->pac[q]==NULL){
                error("watom_t_copy_paf2pac: Out of Memory");
                watom_t_initialize_pac(psW);
                return;
            }
            for (t_int i = 0; i < iLengthPaf; ++i){
                const pac_type_real Val_r=psW->sParam.paf_r[q][i];
                const pac_type_real Val_i=psW->sParam.paf_i[q][i];
                psW->pac[q][i]=Val_r+Val_i*I;
            }
            psW->pac[q][WABOR_T_LENGTH_BIN] = iLengthPac;
            psW->pac[q][WABOR_T_PLACE_HOLDER] = psW->sParam.paf_r[q][WABOR_T_PLACE_HOLDER]+I*psW->sParam.paf_i[q][WABOR_T_PLACE_HOLDER];

        }
    }
}

void watom_t_paf2list(sWatom_t const * const psW, t_symbol *s, t_int argc, t_atom *argv){
    //Wenn nur ein Wert x uebergeben wird, wird einfach die Liste x ausgegeben.
    //Wenn zwei Werte x,y uebergeben werden, wird die Liste x ausgegeben, und an erste Stelle der Wert y gesetzt
    //Wenn kein Wert uebergeben wird, passiert nichts

    //fArrayNumber gibt an, welches Array aus paf in Liste umgewandelt werden soll
    //Sendet list ueber outM aus
    //Laenge der Liste wird nicht ausgegeben, ebenso nicht der allerletzte Wert
    //Diese zwei Werte werden falls DEBUG defined ist, ueber post ausgegeben
    if(s==NULL) return; //YY NUR GEGEN WARNUNG
    t_int i=0; //Zaehlervariable fuer unten
    t_int iAN=-1;
    t_int iLength;
    t_atom *pAtomList;
    if(argc==0) {error("Falscher Aufruf der Runktion paf2list"); return;}
    if(argc>=1) iAN = (t_int)atom_getfloat(argv);
    if(iAN<0) return;
    if(iAN>=psW->sParam.iq_compute_sup) return;
    if(psW->sParam.paf_r[iAN] == NULL) return;
    iLength = (t_int)psW->sParam.paf_r[iAN][WABOR_T_LENGTH_BIN];
    pAtomList = wabor_t_malloc0((iLength+1) * sizeof *pAtomList);
    if(pAtomList==NULL) return;

    if(argc>=2) {
        SETFLOAT(&pAtomList[i], atom_getfloat(argv+1));
        ++i;
    }
    for (t_int j=0; i < iLength; ++i,++j) {
            SETFLOAT(&pAtomList[i], (t_float)psW->sParam.paf_r[iAN][j]);
    }		
    outlet_list(psW->x_outM, &s_list, iLength, pAtomList);

    wabor_t_free(pAtomList);
    pAtomList = NULL;
    return;
}

void watom_t_send_windows(sWatom_t const * const psW, t_symbol *s UNUSED, t_int argc UNUSED, t_atom *argv UNUSED){
    t_atom *pAtomList;
    pAtomList=wabor_t_malloc0(4*sizeof *pAtomList);
    SETFLOAT(&pAtomList[0],WABOR_T_MAGIC_NUMBER_C);
    SETFLOAT(&pAtomList[1],WABOR_T_MAGIC_NUMBER_G);
    int asnumber=(int)psW;
    float asfloat=asnumber;
    
    SETFLOAT(&pAtomList[2],asfloat);
    
    outlet_list(psW->x_outM, &s_list, 3, pAtomList);
    
    wabor_t_free(pAtomList);
    pAtomList = NULL;
    
    return;
}

#define WABOR_T_F_COMPUTE_SUP (PD_SAMPLING_RATE/2)
t_int watom_t_get_q_compute_sup(sWatom_t const * const psW){ //Liefert kleinstes q zurueck, sodass Theta(q*b) groesser ist als WABOR_T_F_MAX
    if(psW->sParam.Theta_inv==0) return 0;
    t_int q= psW->sParam.Theta_inv(WABOR_T_F_COMPUTE_SUP, psW->sParam.thetadata )/psW->sParam._b;
    q+=1+psW->sParam.C_q;
    return q;
}
t_int watom_t_get_q_compute_min(sWatom_t const * const  psW UNUSED){
    return 0;
}




t_int watom_t_find_longest_frame_paf(sWatom_t const * const psW) {
    //sucht das laengste Frame
    t_int iMax=0;
    if(psW->sParam.paf_r==NULL) return 0;
    if(psW->sParam.paf_r[0]==NULL) return 0;
    for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) { 
        if(psW->sParam.paf_r[q]!=NULL) {
            if (iMax < (t_int)psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]) iMax=(t_int)psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]; 
        }
    } //laengstes Suchen
    return iMax;
}
t_int watom_t_find_shortest_frame_paf(sWatom_t const * const psW){
    //sucht das kuerzeste frame
    t_int iMin;
    if(psW->sParam.paf_r==NULL) return 0;
    if(psW->sParam.paf_r[0]==NULL) {return 0; }
    iMin = (t_int)psW->sParam.paf_r[0][WABOR_T_LENGTH_BIN];
    for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
        if(psW->sParam.paf_r[q]!=NULL) {
            if (iMin > (t_int)psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]) iMin=(t_int)psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]; 
        }
    } 
    return iMin;
}
t_int watom_t_find_longest_frame_pac(sWatom_t const * const psW) {
    //sucht das laengste Frame
    t_int iMax=0;
    if(psW->pac==NULL) return 0;
    if(psW->pac[0]==NULL) return 0;
    for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) { 
        if(psW->pac[q]!=NULL) {
            if (iMax < (t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN])) iMax=(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]); 
        }
    } //laengstes Suchen
    return iMax;
}
t_int watom_t_find_shortest_frame_pac(sWatom_t const * const psW){
    //sucht das kuerzeste frame
    t_int iMin;
    if(psW->pac==NULL) return 0;
    if(psW->pac[0]==NULL) {return 0; }
    iMin = (t_int)crealPAC(psW->pac[0][WABOR_T_LENGTH_BIN]);
    for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
        if(psW->pac[q]!=NULL) {
            if (iMin > (t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN])) iMin=(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]); 
        }
    } 
    return iMin;
}

void watom_t_set_window_type(sWatom_t *psW, t_float fWindowType){
    psW->sParam.eWindowType=(enum _eWindowType) fWindowType; 
    return;
}
void watom_t_set_theta_type(sWatom_t *psW, t_symbol *s, t_int argc, t_atom *argv){
        
    if(s==NULL) return; //YY Nur gegen Warnung
    
    t_int iThetaType;
    
    if(argc<1) {
        post("set_theta_type: needs at least 1 parameter"); 
        return;
    }
    iThetaType = (t_int)atom_getfloat(argv);
    
    
    if(argc>=2){
        atom_string(argv+1,psW->sParam.thetapath,WABOR_T_MAXPATHLENGTH);
    } else {
        psW->sParam.thetapath[0]=0;
    }    
    
    //atom_string(&path, psW->sParam.path, WABOR_T_MAXPATHLENGTH);
    psW->sParam.eThetaType=iThetaType;
    return;
}
void watom_t_set_C_b(sWatom_t *psW, t_float fC_b){
    if(fC_b<=0) fC_b=1;
    psW->sParam.C_b=fC_b;
    return;
}
void watom_t_set_C_T_c(sWatom_t *psW, t_float factor){
    if(factor<=0) factor=1;
    psW->sParam.C_T_c=factor;
    return;
}
void watom_t_set_T_max(sWatom_t *psW, t_float fT_max){
    if(fT_max<=0) fT_max=1;
    psW->sParam.T_max=fT_max;
    return;
}
void watom_t_set_C_d(sWatom_t *psW, t_float fFactor){
    if(fFactor<=0) fFactor=1;
    psW->sParam.C_d=fFactor;
    return;
}
void watom_t_set_C_q(sWatom_t *psW, t_float fFactor){
    if(fFactor<0) fFactor=0;
    psW->sParam.C_q=fFactor;
    return;
}
void watom_t_set_C_SR(sWatom_t *psW, t_float fSampleRateFactor){
    if( fSampleRateFactor<=0 ) fSampleRateFactor=1;
    psW->sParam.C_SR = (t_int)fSampleRateFactor;
    return;
}
void watom_t_set_K(sWatom_t *psW, t_float fBandwidthInLobes){
    if(fBandwidthInLobes<=0) fBandwidthInLobes=1;
    psW->sParam._K=fBandwidthInLobes;
    return;
}
void watom_t_set_compute_type(sWatom_t *psW, t_float fComputeType){
    if(fComputeType!=0) fComputeType=1;
    psW->sParam.iComputeType=(t_int)fComputeType;
    return;
}
void watom_t_set_thetaf0(sWatom_t *psW, t_float fThetaF0){
    if(fThetaF0<=0) fThetaF0=10;
    psW->sParam.thetadata[0] = (pac_type_real)fThetaF0;
    return;
}

void watom_t_set_thetak(sWatom_t *psW, t_float fDilation){
    if(fDilation<=1) fDilation=12;
    psW->sParam.thetadata[1] = (pac_type_real)fDilation;
    return;
}
void watom_t_set_C_cut(sWatom_t *psW, t_float fCutRatio){
    if(fCutRatio<0) fCutRatio=1.0;
    psW->sParam.C_cut=fCutRatio;
    return;
}

void watom_t_set_var(sWatom_t* psW, t_float f){
    psW->var=f;
}
void watom_t_set_R(sWatom_t* psW, t_float fR){
    psW->sParam._R=fR;
}
void watom_t_set_winlength_window(sWatom_t* psW, t_float fWL_w){
    psW->sParam.dWinlength_window=fWL_w;
}
void watom_t_set_winlength_compute(sWatom_t* psW, t_float fWL_c){
    psW->sParam.dWinlength_compute=fWL_c;
}
void watom_t_set_a(sWatom_t* psW, t_float fa){
    psW->sParam._aTemp=fa;
    psW->sParam._a=fa;
}
void watom_t_set_b(sWatom_t* psW, t_float fb){
    psW->sParam._bTemp=fb;
    psW->sParam._b=fb;
}
//void watom_t_set_essential_bandwidth(sWatom_t* psW, t_float fessbw){
//    psW->sParam._K=fessbw;
//}


void watom_t_get_first_zero_paf(sWatom_t const * const psW, t_float fAN){
    //sucht den ersten Werte der kleiner Null ist.
    if(fAN<0 || (t_int)fAN >= psW->sParam.iq_compute_sup) return ;   
    if(psW->sParam.paf_r[(t_int)fAN]==NULL) return ;
    t_float f=(t_float)wabor_t_get_first_zero_array(&(psW->pac[(t_int)fAN]));
    outlet_float(psW->x_outM, f );
    post("First Real Negative Value at:");
    post("paf[%f]: %f",fAN, f); 
}
void watom_t_get_window_length_paf(sWatom_t const * const psW, t_float fAN){
    if(fAN<0 || (t_int)fAN >= psW->sParam.iq_compute_sup) return;    
    if(psW->sParam.paf_r[(t_int)fAN]==NULL) return;
    outlet_float(psW->x_outM, psW->sParam.paf_r[(t_int)fAN][WABOR_T_LENGTH_BIN] );    
}
void watom_t_get_window_length_pac(sWatom_t const * const psW, t_float fAN){
    if(fAN<0 || (t_int)fAN >= psW->sParam.iq_compute_sup) return;    
    outlet_float(psW->x_outM, (t_float)wabor_t_get_window_length_array(&(psW->pac[(t_int)fAN])) );
}

void watom_t_print_first_and_last_value(sWatom_t const * const psW, float fAN){
    pac_type cValLast=0;
    pac_type cValFirst=0;
    
    if(fAN<=-1 || fAN>=psW->sParam.iq_compute_sup){
        post("Ausgabe der letzten Werte aller Arrays.");
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
            cValFirst=wabor_t_first_value_array(&(psW->pac[q]));
            cValLast =wabor_t_last_value_array (&(psW->pac[q]));
            post("pac[%i][0] = \t %f+I*%f, \t"
                 "pac[%i][%i] = \t %f+I*%f",
                    q,                                            (double) crealPAC(cValFirst), (double) cimagPAC(cValFirst),
                    q,(t_int)crealPAC(psW->pac[q][WABOR_T_LENGTH_BIN]), (double) crealPAC(cValLast),  (double) cimagPAC(cValLast)
                    );
        }
        post("-------------");
    } else {
        post("pac[%i][0] = \t %f+I*%f, \t"
             "pac[%i][%i] = \t %f+I*%f,",
                (t_int)fAN,                                                   (double) crealPAC(cValFirst), (double) cimagPAC(cValFirst),
                (t_int)fAN,(t_int)crealPAC(psW->pac[(t_int)fAN][WABOR_T_LENGTH_BIN]), (double) crealPAC(cValLast),  (double) cimagPAC(cValLast)
                );    
    }
    return;    
}
void watom_t_print_band(sWatom_t const * const psW, t_float fAN){
    
    t_int qmin, qsup;
    t_int iAN=(t_int)fAN;
    
    if(iAN<=-1){
        qmin=0;
        qsup=psW->sParam.iq_compute_sup;
    } else {
        qmin=iAN;
        qsup=iAN+1;
    }
    post("normalized Overlap: 4.59615*sigma/d_q, This gives the usual values for a raised cosine window");
    post("Band: \t \t, Centerfrq.:\t  \t \t[Hz], \tBW: \t \t[Hz], d = \t= \t[smp], Variance = \t[s], Overlap = \t[1] ");
    for(t_int q=qmin; q<qsup; ++q){
        pac_type_real ldDq_real;
        t_int idq;
        pac_type_real dN;
        
        if(psW->sParam.aldDq!=NULL) { 
            ldDq_real=(double)psW->sParam.aldDq_real[q]; 
            idq=psW->sParam.aiDq[q]; 
        } else {
            ldDq_real = NAN;
            idq = -1;
        }
        if(psW->sParam.paf_r[q]!=NULL) { dN=psW->sParam.paf_r[q][WABOR_T_LENGTH_BIN]; } else {dN = NAN; };
        pac_type_real dCenterFreq=(double)psW->sParam.Theta(q*psW->sParam._b, psW->sParam.thetadata);
        pac_type_real variance=wabor_t_abs_sigma_coarse_array(&(psW->pac[q]));
        pac_type_real overlap = 4.59615*variance/(pac_type_real)idq; //This gives the usual value for for a raised cosine window.
        pac_type_real dBW= 1.0/ldDq_real;      
        //pac_type_real mu=wabor_t_abs_mu_coarse_array(&(psW->pac[q]));
        //pac_type_real sum=wabor_t_abs_sum_coarse_array(&(psW->pac[q]));

        post("Band \t%3i\t: Centerfrq.:\t%8.2f\t[Hz], \tBW: \t%8.2f\t[Hz], d = \t%4i\t[smp], "
                "Length = \t%6.2f [smp], sigma = \t%6.2f [smp], norm. Overlap = \t%6.2f [1]",
                q,(double)dCenterFreq,(double)dBW,idq,
                (double) dN, (double)variance, (double)overlap);
    }
    post("---------------");

}

void watom_t_badfilter(sWatom_t *psW, t_int iBin0, t_int iBin1){
    //Schneidet Arrays ab mit einem (halben) Tuckey Fenster. Uebergang ist zeischen iBin0 und iBin1. Bei iBin0 =0, ab iBin = 1
    if(psW->pac==NULL) return;
    for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) { 
        wabor_t_badfilter_array(&(psW->pac[q]),iBin0,iBin1);
    }
}
void watom_t_abs(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_abs_array(&(psW->pac[q]));}
        return;
    } 
    if((t_int)fAN >= psW->sParam.iq_compute_sup) return;
    wabor_t_abs_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_componentabs(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_componentabs_array(&(psW->pac[q]));}
        return;
    }
    if((t_int)fAN > psW->sParam.iq_compute_sup) return;
    wabor_t_componentabs_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_ln (sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_ln_array(&(psW->pac[q]));}
        return;
    }
    wabor_t_ln_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_mult(sWatom_t *psW, t_symbol *s, t_int argc, t_atom *argv){
    
    if(s==NULL) return; //YY Nur gegen Warnung

    enum _eMultType eType = 0;
    char sTIMES_VAL[]="TIMES_VAL";  
    char sTIMES_CONJ[]="TIMES_CONJ";
    char sSQUARE[]="SQUARE";
    char sTIMES_N[]="TIMES_N";
    char sDIV_N[]="DIV_N";
    char sRECIPROCAL[]="RECIPROCAL";
    char sCONJUGATE[]="CONJUGATE";
    char sNORMALIZE[]="NORMALIZE";
    
    t_int iAN;
    t_float fRandom=0;
    char sType[256];
    pac_type cVal, cValR;
    
    if(argc<4) {post("Aufruf mult: Arraynummer welche_Art Wert_Real Wert_Complex [Random]"); return;}
    iAN = (t_int)atom_getfloat(argv);
    if(iAN<-1 || iAN >= psW->sParam.iq_compute_sup) { post("cycle: Array Index zu klein/gross"); return; }
    
    atom_string(argv+1,sType,256);
    cVal = (pac_type_real) atom_getfloat(argv+2) + I* (pac_type_real)atom_getfloatarg(3,argc,argv);
            
    //enum _eMultType { TIMES_CONJ, SQUARE, TIMES_N, DIV_N, TIMES_VAL, RECIPROCAL, CONJUGATE, NORMALIE };

    if(!strcmp(sType, sTIMES_VAL)) eType=TIMES_VAL;
    if(!strcmp(sType, sTIMES_CONJ)) eType=TIMES_CONJ;
    if(!strcmp(sType, sSQUARE)) eType=SQUARE;
    if(!strcmp(sType, sTIMES_N)) eType=TIMES_N;
    if(!strcmp(sType, sDIV_N)) eType=DIV_N;
    if(!strcmp(sType, sRECIPROCAL)) eType=RECIPROCAL;
    if(!strcmp(sType, sCONJUGATE)) eType=CONJUGATE;
    if(!strcmp(sType, sNORMALIZE)) eType=NORMALIZE;
    
    if(argc<=5) {
        fRandom=atom_getfloat(argv+4);
    }
    if(iAN<=-1) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
            cValR=cVal;
            if(fRandom){
                cValR = (pac_type_real)rand() + I*(pac_type_real)rand();
                cValR*=cabsPAC(cVal)/cabsPAC(cValR);
            }
            wabor_t_mult_array(&(psW->pac[q]), eType, cValR);
        }
        return;
    }  
    if((t_int)iAN >= psW->sParam.iq_compute_sup) return;
    wabor_t_mult_array(&(psW->pac[(t_int)iAN]), eType, cVal);
    
}
void watom_t_cut(sWatom_t *psW, t_float fAN, t_float fCutLow, t_float fCutHigh){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q < psW->sParam.iq_compute_sup; ++q) {wabor_t_cut_array(&(psW->pac[q]), (double)fCutLow, (double)fCutHigh, (pac_type)fCutLow, (pac_type)fCutHigh); }
        return;
    }  
    wabor_t_cut_array(&(psW->pac[(t_int)fAN]), (pac_type_real)fCutLow, (pac_type_real)fCutHigh, (pac_type)fCutLow, (pac_type)fCutHigh); 
}
void watom_t_set_nan_to_zero(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_set_nan_to_zero_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_set_nan_to_zero_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_set_inf_to_zero(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_set_inf_to_zero_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_set_inf_to_zero_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_normalize(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_normalize_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_normalize_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_cycle(sWatom_t *psW, t_symbol *s, t_int argc, t_atom *argv){
    if(s==NULL) return; //YY NUR GEGEN WARNUNG
    if(psW->pac==NULL) return;
    t_int iAN;
    t_int iBins=0;
    t_int iDenom=0;
    if(argc<2) {post("cycle: Falscher Aufruf der Funktion"); return;}
    iAN = (t_int)atom_getfloat(argv);
    if(iAN<-1 || iAN >= psW->sParam.iq_compute_sup) { post("cycle: Array Index zu klein/gross"); return; }
    if(atom_getint(argv+1)!=0) {
        iBins=atom_getint(argv+1);
    } else if (atom_getsymbol(argv+1)!=0){ 
        char c[8];
        atom_string(argv+1,c,8);
        if( c[0]=='-' && c[1]=='N' && c[2]=='/' && c[3]>='1' && c[3]<='9' ){
            iDenom=-(c[3]-48);//schieben um -N/iDenom
        } else if ( c[0]=='N' && c[1]=='/' && c[2]>='1' && c[2]<='9' ){
            iDenom=c[2]-48;//schieben um N/iDenom
        } else if ( c[0]=='+' && c[1]=='N' && c[2]=='/' && c[3]>='1' && c[3] <= '9' ){ 
            iDenom=c[3]-48;//schieben um N/iDenom
        }
    }
    if(iAN<=-1) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
            if(iDenom!=0) {
                if(psW->pac[q]) {
                    iBins=((t_int)psW->pac[q][WABOR_T_LENGTH_BIN])/iDenom; 
                } else {
                    iBins=0;
                }
            }
            if(iBins!=0)  {
                wabor_t_cycle_array(&(psW->pac[q]),iBins);
            }
        }
        return;
    }  
    if(iDenom!=0) {
        if(psW->pac[iAN]) iBins=((t_int)psW->pac[iAN][WABOR_T_LENGTH_BIN])/iDenom; else return;
        iBins=((t_int)psW->pac[iAN][WABOR_T_LENGTH_BIN])/iDenom;
    }
    if(iBins!=0)  wabor_t_cycle_array(&(psW->pac[iAN]),iBins);
    return;   
}
void watom_t_fft(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_fft_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_fft_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_floating_average(sWatom_t *psW, t_float fAN, t_float fFactor, t_float fMax){
    //fFactor gibt an um wieviel kuerzer als eine ~Viertel Periode geglaettet werdeb soll.
    //Ist die Zahl negativ gibt es direkt an, ueber wieviele Samples geglaettet werden soll.
    //fMax gibt ueber wieviel Samples maximal gemittelt wird
    if(fFactor==0) fFactor=1;
    if(fMax<0) post("Falsche Parameter bei watom_t_floating_average");
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
            t_int iWL=wabor_t_get_first_zero_array(&(psW->pac[q]));
            post("First Zero: %i",iWL);
            iWL/=(t_int)fFactor;
            if(fFactor<0) iWL=-fFactor;
            if(fMax!= 0 && iWL>fMax) iWL=fMax;
            post("Averaging mit Laenge iWL %i",iWL);
            wabor_t_floating_average_array(&(psW->pac[q]),iWL);
        }
        return;
    }  
    t_int iWL=wabor_t_get_first_zero_array(&(psW->pac[(t_int)fAN]));
    wabor_t_floating_average_array(&(psW->pac[(t_int)fAN]),iWL);   
}
void watom_t_differentiate(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_differentiate_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_fft_array(&(psW->pac[(t_int)fAN])); 
}
void watom_t_integrate(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_integrate_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_fft_array(&(psW->pac[(t_int)fAN]));    
}
void watom_t_imag_plus_real(sWatom_t *psW, t_float fAN){ 
    if(fAN <= -1.0 || fAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {wabor_t_imag_plus_real_array(&(psW->pac[q]));}
        return;
    }  
    wabor_t_imag_plus_real_array(&(psW->pac[(t_int)fAN]));     
}
void watom_t_make_dc_offset(sWatom_t *psW, t_float fAN, t_float fChangeOffset, t_float fDCOffset_real, t_float fDCOffset_imag){
    t_int iAN=(t_int)fAN;
    pac_type cOffset=fDCOffset_real+I*fDCOffset_imag;
    pac_type cReturn;
    if(iAN <= -1.0 || iAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q){
            cReturn = wabor_t_make_dc_offset_array(&(psW->pac[q]), (t_int)fChangeOffset, cOffset);
            if(!fChangeOffset) post("Offset[%i]:%f+I*%f",q,(double)crealPAC(cReturn),(double)cimagPAC(cReturn));
        }
        return;
    }
    cReturn = wabor_t_make_dc_offset_array(&(psW->pac[iAN]), (t_int)fChangeOffset, cOffset);
    if(!fChangeOffset) post("Offset[%i]:%f+I*%f",iAN,(double)crealPAC(cReturn),(double)cimagPAC(cReturn));
    t_atom *pAtomList;       
    pAtomList = wabor_t_malloc0(2 * sizeof *pAtomList);
    if(pAtomList!=NULL){
        SETFLOAT(&pAtomList[0], (t_float)crealPAC(cReturn));
        SETFLOAT(&pAtomList[1], (t_float)cimagPAC(cReturn));
        outlet_list(psW->x_outM, &s_list, 2, pAtomList);
        wabor_t_free(pAtomList);
        pAtomList = NULL;
    }	
    return;
}
void watom_t_inner_product(sWatom_t const * const psW, t_float fAN1, t_float fAN2){
    t_int iAN1=(t_int)fAN1;
    t_int iAN2=(t_int)fAN2;
    pac_type cDotProd;
    if(DEBUG) post("inner_product");
    if(iAN1 <= -1.0 || iAN1 >= psW->sParam.iq_compute_sup) {
        for(t_int q1=0; q1<psW->sParam.iq_compute_sup; ++q1){
            if(iAN2 <= -1.0 || iAN2 >= psW->sParam.iq_compute_sup) {
                for(t_int q2=0; q2<psW->sParam.iq_compute_sup; ++q2){
                    //alle q1, alle q2
                    cDotProd=wabor_t_inner_product_array( &(psW->pac[q1]),&(psW->pac[q2]) ) / wabor_t_length_of_vector_array(&(psW->pac[q1])) / wabor_t_length_of_vector_array(&(psW->pac[q2]));;
                    post("[%i]*[%i]/L=\t%+8e+\tI*%+8e",q1,q2,(double)crealPAC(cDotProd),(double)cimagPAC(cDotProd));
                }
            } else {
                //alle q1, nur iAN2
                cDotProd=wabor_t_inner_product_array( &(psW->pac[q1]),&(psW->pac[iAN2]) ) / wabor_t_length_of_vector_array(&(psW->pac[q1])) / wabor_t_length_of_vector_array(&(psW->pac[iAN2]));
                post("[%i]*[%i]/L=\t%e+\tI*%e",q1,iAN2,(double)crealPAC(cDotProd),(double)cimagPAC(cDotProd));                
            }
        } 
        return;
    }
    if(iAN2 <= -1.0 || iAN2 >= psW->sParam.iq_compute_sup) {
        for(t_int q2=0; q2<psW->sParam.iq_compute_sup; ++q2){
            //nur iAN1, alle q2
            cDotProd=wabor_t_inner_product_array( &(psW->pac[iAN1]),&(psW->pac[q2]) ) / wabor_t_length_of_vector_array(&(psW->pac[iAN1])) / wabor_t_length_of_vector_array(&(psW->pac[q2]));
            post("[%i]*[%i]/L=\t%e+\tI*%e",iAN1,q2,(double)crealPAC(cDotProd),(double)cimagPAC(cDotProd));
        }
        return;
    }
    //nur iAN1, nur iAN2
    cDotProd=wabor_t_inner_product_array( &(psW->pac[iAN1]),&(psW->pac[iAN2]) ) / wabor_t_length_of_vector_array(&(psW->pac[iAN1])) / wabor_t_length_of_vector_array(&(psW->pac[iAN2]));
    post("[%i]*[%i]/L=\t%e+\tI*%e",iAN1,iAN2,(double)crealPAC(cDotProd),(double)cimagPAC(cDotProd));
    t_atom *pAtomList;       
    pAtomList = wabor_t_malloc0(2 * sizeof *pAtomList);
    if(pAtomList!=NULL){
        SETFLOAT(&pAtomList[0], (t_float)crealPAC(cDotProd));
        SETFLOAT(&pAtomList[1], (t_float)cimagPAC(cDotProd));
        outlet_list(psW->x_outM, &s_list, 2, pAtomList);
        wabor_t_free(pAtomList);
        pAtomList = NULL;
    }
    return;    
}

void watom_t_length_of_vector(sWatom_t const * const psW, t_float fAN){
    t_int iAN=(t_int)fAN;  
    pac_type_real length;
    if(iAN <= -1.0 || iAN >= psW->sParam.iq_compute_sup) {
        for(t_int q=0; q<psW->sParam.iq_compute_sup; ++q) {
            length=wabor_t_length_of_vector_array(&(psW->pac[q]));
            if(DEBUG) post("Length(%i)=%f",q,(double)length);
        }
        return;
    }  
    length=wabor_t_length_of_vector_array(&(psW->pac[iAN])); 
    if(DEBUG) post("Length(%i)=%f",iAN,(double)length);
    return;
}
void watom_t_prolong(sWatom_t const * const psW, t_float fAN, t_float fN, t_float fWhere, t_float fRandom){
    //Verlaengert Fenster um Nuller 
        //fWhere=0: am Anfang, 1: in der Mitte, 2: am Ende
    //Ist fRandom gesetzt werden zufaellig viele Nuller zwischen Null und fN geschriben
    t_int qmin,qsup;
    t_int iAN=(t_int)fAN;
    if(iAN<=-1 || iAN  >= psW->sParam.iq_compute_sup) { qmin=0; qsup = psW->sParam.iq_compute_sup;} 
        else {qmin=iAN; qsup=iAN+1; }
    for(t_int q=qmin; q<qsup; ++q){
        wabor_t_prolong_array(&(psW->pac[q]), (t_int)fN, (t_int)fWhere, (t_int)fRandom);
    }
}

void watom_t_array_synopsis(sWatom_t const * const psW, t_symbol *s, t_int argc, t_atom *argv){
    //Wenn nur ein Wert x uebergeben wird, wird einfach die Liste x zusammengefasst
    //Wenn nur ein Wert x uebergeben wird, und dieser ist -1, werden alle .
    //Wenn zwei Werte x,y uebergeben werden, wird die Liste x bis y (beide incl) zusammengefasst
    //Wenn kein Wert uebergeben wird, passiert nichts

    t_int iAN;
    if(argc<=0) {post("Falscher Aufruf der Funktion array_synopsis, %s",s); return;}
    if(argc>=1) iAN = (t_int)atom_getfloat(argv);
    if(argc==1) {
        if(iAN<-1 || iAN >= psW->sParam.iq_compute_sup) {
            post("Falscher Aufruf der Funktion array_synopsis, %s",s); 
            return;
        }
        if(iAN==-1) {
            for( t_int  q = 0; q<psW->sParam.iq_compute_sup; ++q) {
                if(psW->pac[q]){
                    post("Array pac[%i]",q);
                    wabor_t_array_synopsis_array(&(psW->pac[q]));
                }
            }
            return;
        }
        wabor_t_array_synopsis_array(&(psW->pac[iAN])); 
        return;
        
    }
    if(argc>1) {
        t_int qmin=(t_int)atom_getfloat(argv);
        t_int qsup=(t_int)atom_getfloat(argv+1);
        if(qmin<0) qmin=0;
        if(qsup>psW->sParam.iq_compute_sup) qsup=psW->sParam.iq_compute_sup;
        for( t_int q = qmin; q<qsup; ++q) wabor_t_array_synopsis_array(&(psW->pac[q]));
    }
    return;
}



t_int watom_t_round_up_to_multiple_of_small_primes(UNUSED sWatom_t const * const psW, t_float n, t_float maxprime){
    t_int val=round_up_to_multiple_of_small_primes((t_int)n,(t_int)maxprime);
    post("Nearest Number with small primes: %i", val);
    return val;
}

