Commit c21f5f3a authored by Ruben Farinelli's avatar Ruben Farinelli
Browse files

Modified the format of the polarimetric output to ensure compatibility with...

Modified the format of the polarimetric output to ensure compatibility with the Python plotting routine
parent 243fca98
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -56,8 +56,13 @@ void compute_stokes(double ene, double* k_lab, double* polvect_cart, stokes_para
            }

            ptr_stokes[ii].array_I[jj] = ptr_stokes[ii].array_I[jj] + 1;
            
            ptr_stokes[ii].array_Q[jj] = ptr_stokes[ii].array_Q[jj] + Qs;
            ptr_stokes[ii].array_Qsq[jj] = ptr_stokes[ii].array_Qsq[jj] + Qs*Qs;
            
            ptr_stokes[ii].array_U[jj] = ptr_stokes[ii].array_U[jj] + Us;
            ptr_stokes[ii].array_Usq[jj] = ptr_stokes[ii].array_Usq[jj] + Us*Us;
            
            ptr_stokes[ii].counter[jj]++;

            FlagFound = TRUE;
+91 −5
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@
#include <stdio.h>

char* set_filename(char* root, char* tau_char, char* seed_char, char* albedo, char* method);
char* set_mc_filename(const char* root, double ktbb, double kte, double tau, int seed, double albedo,
                   const char* method);
void smart_double_to_string(char* buffer, size_t size, double value);

void int_to_string(char* buffer, size_t size, int value);


int seed;
double tau_c;
@@ -294,22 +300,22 @@ int main(int argc, char* argv[])

    if (diffusion == 0x0)
    {
      diffusion = set_filename("diffusion_mc_tau", tau_char, seed_char, albedo_char, "mc");
      diffusion = set_mc_filename("diffusion_mc", ktbb, kte, disktau, seed, albedobase, "mc");
    }

    if (outspec == 0x0)
    {
      outspec = set_filename("spectrum_mc_tau", tau_char, seed_char, albedo_char, "mc");
      outspec = set_mc_filename("spectrum_mc", ktbb, kte, disktau, seed, albedobase, "mc");
    }

    if (integral == 0x0)
    {
      integral = set_filename("integralpolar_mc_tau", tau_char, seed_char, albedo_char, "mc");
      integral = set_mc_filename("integralpolar_mc", ktbb, kte, disktau, seed, albedobase, "mc");
    }

    if (polarfile == 0x0)
    {
      polarfile = set_filename("energypolar_mc_tau", tau_char, seed_char, albedo_char, "mc");
      polarfile = set_mc_filename("energypolar_mc", ktbb, kte, disktau, seed, albedobase, "mc");
    }

    status = slab_mc(nph, seed);
@@ -365,4 +371,84 @@ char* set_filename(char* root, char* tau_char, char* seed_char, char* albedo, ch
  return filename;
}

/*==============================================================================*/




/*======================================================================================*/

// Conversione intelligente dei double (senza decimali inutili)
void smart_double_to_string(char* buffer, size_t size, double value)
{
    if (value == (int)value)
        snprintf(buffer, size, "%d", (int)value);     // Esempio: 1.0 → _1
    else
        snprintf(buffer, size, "%.3f", value);        // Esempio: 0.123 → _0.123
}

// Conversione int in stringa
void int_to_string(char* buffer, size_t size, int value)
{
    snprintf(buffer, size, "%d", value);
}




char* set_mc_filename(const char* root, double ktbb, double kte, double tau, int seed, double albedo,
                      const char* method)
{
    // Buffer per le conversioni
    char ktbb_str[20], kte_str[20], tau_str[20], albedo_str[20], seed_str[20];

    smart_double_to_string(ktbb_str, sizeof(ktbb_str), ktbb);
    smart_double_to_string(kte_str, sizeof(kte_str), kte);
    smart_double_to_string(tau_str, sizeof(tau_str), tau);
    smart_double_to_string(albedo_str, sizeof(albedo_str), albedo);
    int_to_string(seed_str, sizeof(seed_str), seed);

    // Calcolo dimensione necessaria per il nome file
    size_t len = strlen(root)
               + strlen("_ktbb") + strlen(ktbb_str)
               + strlen("_kte") + strlen(kte_str)   
               + strlen("_tau")+ strlen(tau_str)
               + strlen("_seed") + strlen(seed_str)
               + strlen(".qdp") + 1;

    if (strcmp(method, "mc") == 0)
    {
        len += strlen("_A") + strlen(albedo_str);
    }

    // Allocazione della stringa finale
    char* filename = malloc(len);
    if (!filename)
    {
        fprintf(stderr, "Errore: allocazione memoria fallita\n");
        exit(EXIT_FAILURE);
    }

    // Costruzione della stringa
    strcpy(filename, root);
    strcat(filename, "_ktbb");
    strcat(filename, ktbb_str);
    strcat(filename, "_kte");
    strcat(filename, kte_str);
    strcat(filename, "_tau");
    strcat(filename, tau_str);
    strcat(filename, "_seed");
    strcat(filename, seed_str);

    if (strcmp(method, "mc") == 0)
    {
        strcat(filename, "_A");
        strcat(filename, albedo_str);
    }

    strcat(filename, ".qdp");

    return filename;  // Ricorda di liberare con free()
}


+10 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ int slab_mc(int nphot, int seed)
  T_maxw = gsl_root_fsolver_bisection;
  s_maxw = gsl_root_fsolver_alloc(T_maxw);

  nstepangles = 40;
  nstepangles = 20;
  obsmindeg = 0.;
  obsmaxdeg = 90.;

@@ -354,6 +354,15 @@ int slab_mc(int nphot, int seed)

    MPI_Reduce(struct_stokes[ii].counter, struct_stokes_average[ii].counter, nstepangles, MPI_INT,
               MPI_SUM, 0, MPI_COMM_WORLD);
               
     MPI_Reduce(struct_stokes[ii].array_Qsq, struct_stokes_average[ii].array_Qsq, nstepangles, MPI_DOUBLE,
               MPI_SUM, 0, MPI_COMM_WORLD);

	 MPI_Reduce(struct_stokes[ii].array_Usq, struct_stokes_average[ii].array_Usq, nstepangles, MPI_DOUBLE,
               MPI_SUM, 0, MPI_COMM_WORLD);


               
  }

  for (ii = 0; ii < NSTEP_ENE; ii++)