CLUMPY  Version 2011.09_corr2
void halo_load_list ( string const &  file_halos,
vector< struct gStructHalo > &  list_halos,
bool  is_clear = true 
)

Definition at line 3421 of file janalysis.cc.

{
   //--- Reads list of halos (name, position, distance...)
   //    The format must be as in data/generic_list.txt
   //  file_halos   File to be read
   //  list_halos   vector of halo parameters
   //  is_clear      Mode to load new objects from list
   //                   - true: clears any pre-loaded file (default call)
   //                   - queues the objects with some previously loaded ones (is_clear=false)
   //                     [checks that the object to be added is not already loaded]

   // Open file and check if exists
   ifstream f_list(file_halos.c_str());
   if (!f_list) {
      cout << "ERROR in halo_load_list: COULD NOT OPEN FILE " << file_halos << "  => ABORT()" << endl;
      abort();
   }
   cout << ">>>>> Load " << file_halos << endl;

   struct gStructHalo tmp;
   if (is_clear) list_halos.clear();

   // Loop over lines: skip empty ones or those starting with #
   string line;
   while (getline(f_list, line)) {
      size_t pos = line.find_first_not_of(" ");
      if (line.empty() || pos == string::npos || line[pos] == '#') continue;

      vector<string> params;
      string_to_listofstrings(line, " ", params);

      if (params.size() != 13) {
         cout << ">>>> Wrong number of columns (" << params.size() << " instead of 13) => abort()" << endl;
         abort();
      }

      // Fill parameters
      tmp.Name = params[0];
      tmp.Type = upper_case(params[1]);
      tmp.PsiDeg = atof(params[2].c_str());
      tmp.ThetaDeg = atof(params[3].c_str());
      tmp.l = atof(params[4].c_str());
      tmp.z = atof(params[5].c_str());
      tmp.Rvir = atof(params[6].c_str());
      tmp.Rhos = atof(params[7].c_str());
      tmp.Rscale = atof(params[8].c_str());
      tmp.Profile = string_to_enum("FLAG_PROFILE", params[9]);
      tmp.ShapeParam1 = atof(params[10].c_str());
      tmp.ShapeParam2 = atof(params[11].c_str());
      tmp.ShapeParam3 = atof(params[12].c_str());

      const int npar = 7;
      double par_tot[npar] = {tmp.Rhos, tmp.Rscale, tmp.ShapeParam1, tmp.ShapeParam2, tmp.ShapeParam3, tmp.Profile, tmp.Rvir};
      tmp.Mtot = mass_singlehalo(par_tot, 1.e-4);

      // Find matching type for halo
      int i_type = -1;
      for (int ii = 0; ii < gN_TYPEHALOES; ++ii) {
         if (tmp.Type == gNAMES_TYPEHALOES[ii]) {
            i_type = ii;
            break;
         }
      }
      if (i_type == -1) {
         cout << "Warning: " << tmp.Name << "'s type " << tmp.Type
              << " found in " << gLIST_HALOES
              << " does not match any existing type" << endl;
         cout << "  => available types are: ";
         for (int ii = 0; ii < gN_TYPEHALOES; ++ii)
            cout << gNAMES_TYPEHALOES[ii] << " ";
         cout << endl << "  => abort()" << endl;
         abort();
      }

      tmp.Subs_mfrac = gHALO_SUBS_MASSFRACTION[i_type];
      tmp.Subs_dPdM_Slope = gHALO_DPDM_SLOPE[i_type];

      // if kHOST selected for dpdv profile
      if (gHALO_DPDV_FLAG_PROFILE[i_type] == kHOST) {
         tmp.Subs_dPdV_Profile = tmp.Profile;
         tmp.Subs_dPdV_ShapeParam1 = tmp.ShapeParam1;
         tmp.Subs_dPdV_ShapeParam2 = tmp.ShapeParam2;
         tmp.Subs_dPdV_ShapeParam3 = tmp.ShapeParam3;
      } else {
         tmp.Subs_dPdV_Profile = gHALO_DPDV_FLAG_PROFILE[i_type];
         tmp.Subs_dPdV_ShapeParam1 = gHALO_DPDV_SHAPE_PARAMS[i_type][0];
         tmp.Subs_dPdV_ShapeParam2 = gHALO_DPDV_SHAPE_PARAMS[i_type][1];
         tmp.Subs_dPdV_ShapeParam3 = gHALO_DPDV_SHAPE_PARAMS[i_type][2];
      }
      // if kHOST selected for rscale profile
      if (gHALO_DPDV_RSCALE[i_type] < 0.)
         tmp.Subs_dPdV_Rscale = tmp.Rscale;
      else
         tmp.Subs_dPdV_Rscale = gHALO_DPDV_RSCALE[i_type];
      tmp.Subs_Inner_cvirmvir = gHALO_CLUMPS_FLAG_CVIRMVIR[i_type];
      tmp.Subs_Inner_Profile = gHALO_CLUMPS_FLAG_PROFILE[i_type];
      tmp.Subs_Inner_ShapeParam1 = gHALO_CLUMPS_SHAPE_PARAMS[i_type][0];
      tmp.Subs_Inner_ShapeParam2 = gHALO_CLUMPS_SHAPE_PARAMS[i_type][1];
      tmp.Subs_Inner_ShapeParam3 = gHALO_CLUMPS_SHAPE_PARAMS[i_type][2];
      tmp.Subs_Mmax = gDM_MMAXFRAC_SUBS * tmp.Mtot;


      // If old list was not cleared, check if new list is really new!
      if (is_clear == false) {
         for (int i = 0; i < (int)list_halos.size(); ++i) {
            if (upper_case(tmp.Name) == upper_case(list_halos[i].Name) &&  upper_case(tmp.Type) == upper_case(list_halos[i].Type)) {
               printf("  WARNING in halo_load_list: %s %s already loaded => overides old values from those read in %s\n",
                      (tmp.Name).c_str(), (tmp.Type).c_str(), file_halos.c_str());
               list_halos[i] = tmp;
            }
         }
      } else list_halos.push_back(tmp);
   }

   printf("  - List of halos loaded from %s\n", file_halos.c_str());
   printf("#***********************************************************************************************************#\n");
   printf("#                  [OBJECT LOCATION AND SIZE]                |             DM DISTRIBUTION (RHO_TOT)        #\n");
   printf("# Name           Type    long.   lat.    d      z     Rvir   |     rhos       rs     prof.   #1   #2   #3   #\n");
   printf("#  -               -     [deg]   [deg]  [kpc]   -    [kpc]   |  [Msol/kpc3]  [kpc]  [enum]    -    -    -   #\n");
   printf("#***********************************************************************************************************#\n");
   for (int i = 0; i < (int)list_halos.size(); ++i) {
      printf("%-15s %-8s %+6.1lf %+6.1lf %.1le %4.1lf  %.1le     %5.1le   %5.1le  %-10s %.2lf %.2lf %.2lf\n",
             (list_halos[i].Name).c_str(), (list_halos[i].Type).c_str(), list_halos[i].PsiDeg, list_halos[i].ThetaDeg,
             list_halos[i].l, list_halos[i].z, list_halos[i].Rvir,
             list_halos[i].Rhos, list_halos[i].Rscale, gNAMES_PROFILE[(int)list_halos[i].Profile],
             list_halos[i].ShapeParam1, list_halos[i].ShapeParam2, list_halos[i].ShapeParam3);

   }
   printf("#***********************************************************************************************************#\n");
}
 All Classes Files Functions Variables Enumerations Enumerator Defines