Exemplo n.º 1
0
static bool
archive_file (char file_name[], size_t file_name_size,
              int archive_fd, bool *write_error)
{
  int file_fd = open (file_name);
  if (file_fd >= 0)
    {
      bool success;

      if (inumber (file_fd) != inumber (archive_fd))
        {
          if (!isdir (file_fd))
            success = archive_ordinary_file (file_name, file_fd,
                                             archive_fd, write_error);
          else
            success = archive_directory (file_name, file_name_size, file_fd,
                                         archive_fd, write_error);
        }
      else
        {
          /* Nothing to do: don't try to archive the archive file. */
          success = true;
        }

      close (file_fd);

      return success;
    }
  else
    {
      printf ("%s: open failed\n", file_name);
      return false;
    }
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    const char *dir, *out;
    FILE *file;

    if (argc < 3) {
        printf("Usage: packer [dir] [out]\n");
        exit(1);
    }

    dir = argv[1];
    out = argv[2];

    file = fopen(out, "wb");
    if (!file) {
        printf("Error opening '%s', aborting\n", out);
        exit(1);
    }

    archive_directory(file, dir, "");
    fclose(file);

    return 0;
}
    void Test2DSimulations() throw(Exception)
    {
        double conductivity_scale = 1;
        double h = 0.01; // cm
        double ode_time_step = 0.005; //ms
        double pde_time_step = 0.01; //ms
        unsigned num_stims = 1;

        TetrahedralMesh<2,2> mesh;
        unsigned num_elem_x = (unsigned)(0.5/h);  // num elements to make 5mm
        unsigned num_elem_y = (unsigned)(0.5/h);  // num elements to make 5mm
        //unsigned num_elem_z = (unsigned)(0.15/h);// Num elements to make 0.3cm
        double pacing_cycle_length = 350;
        double stim_mag = -500000;
        double stim_dur = 3;
        double area = 0.005;

        mesh.ConstructRectangularMesh(num_elem_x, num_elem_y);
        mesh.Scale(h,h); // Get mesh into units of cm.

        std::string archive_dir_base("LongPostprocessing_archives/archive");
        std::string archive_dir_current;

        // Setup
        HeartConfig::Instance()->SetSimulationDuration(pacing_cycle_length); //ms
        HeartConfig::Instance()->SetOutputDirectory("LongPostprocessing");
        HeartConfig::Instance()->SetOutputFilenamePrefix("results");

        // These lines make postprocessing fast or slow.
        HeartConfig::Instance()->SetOdePdeAndPrintingTimeSteps(ode_time_step, pde_time_step, 10); // Leads to 10MB VTK file
        //HeartConfig::Instance()->SetOdePdeAndPrintingTimeSteps(ode_time_step, pde_time_step, 0.01); // Leads to 1GB VTK file

        HeartConfig::Instance()->SetIntracellularConductivities(Create_c_vector(1.4*conductivity_scale*1.171, 1.4*conductivity_scale*1.171));
        HeartConfig::Instance()->SetSurfaceAreaToVolumeRatio(1400.0); // 1/cm
        HeartConfig::Instance()->SetCapacitance(1.0); // uF/cm^2
        HeartConfig::Instance()->SetVisualizeWithMeshalyzer();
#ifdef CHASTE_VTK
        HeartConfig::Instance()->SetVisualizeWithVtk();
#endif

        std::vector<std::pair<double,double> > apds_requested;
        apds_requested.push_back(std::pair<double, double>(90,-30)); //repolarisation percentage and threshold
        HeartConfig::Instance()->SetApdMaps(apds_requested);
//        std::vector<double> excitation_threshold;
//        excitation_threshold.push_back(-30.0);
//        HeartConfig::Instance()->SetUpstrokeTimeMaps(excitation_threshold);
//        HeartConfig::Instance()->SetMaxUpstrokeVelocityMaps(excitation_threshold);

        for (unsigned stim_counter=0; stim_counter < num_stims; stim_counter++ )
        {
            // Load problem
            MonodomainProblem<2> *p_monodomain_problem;
            if (stim_counter==0)
            {
                PointStimulusCellFactory<2> cell_factory(stim_mag, stim_dur, pacing_cycle_length, area);
                p_monodomain_problem = new MonodomainProblem<2>( &cell_factory );
                p_monodomain_problem->SetMesh(&mesh);
                p_monodomain_problem->Initialise();
            }
            else
            {
                p_monodomain_problem = CardiacSimulationArchiver<MonodomainProblem<2> >::Load(archive_dir_current);
            }

            HeartConfig::Instance()->SetSimulationDuration((double) (stim_counter+1)*pacing_cycle_length); //ms

            // set new directories to work from
            std::stringstream stringoutput;
            stringoutput << stim_counter;
            std::string stim_counter_string = stringoutput.str();

            archive_dir_current = archive_dir_base + "_" + stim_counter_string;
            OutputFileHandler archive_directory(archive_dir_current, true); // Clean a folder for new results
            HeartConfig::Instance()->SetOutputFilenamePrefix("results_" + stim_counter_string);

            // Solve problem (this does the postprocessing too when HeartConfig options are set).
            p_monodomain_problem->Solve();

            HeartEventHandler::Headings();
            HeartEventHandler::Report();

            // Save problem to archive
            CardiacSimulationArchiver<MonodomainProblem<2> >::Save(*p_monodomain_problem, archive_dir_current, false);
            std::cout << "Archived to " << archive_dir_current << "\n" << std::flush;

            // Copy the postprocessing results into the archive folders so they aren't wiped.
            std::vector<std::string> files;
            files.push_back("Apd_90_minus_30_Map");
//                files.push_back("MaxUpstrokeVelocityMap_-30");
//                files.push_back("UpstrokeTimeMap_-30");

            for (unsigned i=0; i<files.size(); i++)
            {
                FileFinder file_to_copy(HeartConfig::Instance()->GetOutputDirectory() + "/output/" + files[i] + ".dat", RelativeTo::ChasteTestOutput);
                TS_ASSERT(file_to_copy.IsFile());
                archive_directory.CopyFileTo(file_to_copy);
            }
        }// close for loop
    }//close void Test2dSimulations
Exemplo n.º 4
0
int archive_directory(FILE *file, const char *path, const char *relative)
{
    DIR *dir;
    struct dirent *ent;
    struct stat st;
    char fullpath[256] = "";
    char relpath[256] = "";
    FILE *ent_file;
    int length;
    int result = 0;
    char *blob;

    dir = opendir(path);
    if (dir) {
        while ((ent = readdir(dir))) {
            if (ent->d_name[0] == '.')
                continue;

            strcpy(fullpath, path);
            strcat(fullpath, "/");
            strcat(fullpath, ent->d_name);

            strcpy(relpath, "");
            if (strlen(relative) > 0) {
                strcpy(relpath, relative);
                strcat(relpath, "/");
            }
            strcat(relpath, ent->d_name);
            printf("%s", relpath);

            stat(fullpath, &st);

            if (st.st_mode & S_IFREG) {
                /* Write this file to the archive */
                ent_file = fopen(fullpath, "rb");
                fseek(ent_file, 0, SEEK_END);
                length = ftell(ent_file);
                fseek(ent_file, 0, SEEK_SET);

                printf(" (%d bytes)\n", length);

                archive_size += length;
                if (archive_size > MAX_FILESIZE) {
                    printf("Archive exceeds maximum size, aborting\n");
                    result = 1;
                    goto done;
                }

                blob = malloc(length);
                fread(blob, 1, length, ent_file);
                fwrite(relpath, 1, 256, file);
                fwrite(&length, 4, 1, file);
                fwrite(blob, 1, length, file);
                free(blob);
                fclose(ent_file);
            } else if (st.st_mode & S_IFDIR) {
                printf("\n");

                /* Recurse into this directory */
                if (archive_directory(file, fullpath, relpath) != 0) {
                    result = 1;
                    goto done;
                }
            }
        }
done:
        closedir(dir);
        return result;
    } else {
        printf("FAILED!\n");
        return 1;
    }
}