Action_Thermostats
        Add_AtomRandomPerturbation
        Add_SelectAtomByNameAction
        Adding_Graph_to_ChangeBondActions
        Adding_MD_integration_tests
        Adding_StructOpt_integration_tests
        AutomationFragmentation_failures
        Candidate_v1.6.1
        Candidate_v1.7.0
        ChangeBugEmailaddress
        ChemicalSpaceEvaluator
        EmpiricalPotential_contain_HomologyGraph_documentation
        Enhance_userguide
        Enhanced_StructuralOptimization
        Enhanced_StructuralOptimization_continued
        Example_ManyWaysToTranslateAtom
        Exclude_Hydrogens_annealWithBondGraph
        Fix_Verbose_Codepatterns
        ForceAnnealing_oldresults
        ForceAnnealing_with_BondGraph
        ForceAnnealing_with_BondGraph_continued
        ForceAnnealing_with_BondGraph_continued_betteresults
        ForceAnnealing_with_BondGraph_contraction-expansion
        GeometryObjects
        Gui_displays_atomic_force_velocity
        IndependentFragmentGrids_IntegrationTest
        JobMarket_RobustOnKillsSegFaults
        JobMarket_StableWorkerPool
        PythonUI_with_named_parameters
        QtGui_reactivate_TimeChanged_changes
        Recreated_GuiChecks
        StoppableMakroAction
        TremoloParser_IncreasedPrecision
        TremoloParser_MultipleTimesteps
        stable
      
      
      
| Line |   | 
|---|
| 1 | /*! \defgroup PSIO libpsio: The PSI I/O Library */
 | 
|---|
| 2 | 
 | 
|---|
| 3 | /*!
 | 
|---|
| 4 | ** \file close.cc
 | 
|---|
| 5 | ** \ingroup (PSIO)
 | 
|---|
| 6 | */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include <unistd.h>
 | 
|---|
| 9 | #include <string.h>
 | 
|---|
| 10 | #include <stdlib.h>
 | 
|---|
| 11 | #include <util/psi3/libpsio/psio.h>
 | 
|---|
| 12 | 
 | 
|---|
| 13 | namespace psi3 {
 | 
|---|
| 14 | namespace libpsio {
 | 
|---|
| 15 | 
 | 
|---|
| 16 | /*!
 | 
|---|
| 17 | ** \ingroup (PSIO)
 | 
|---|
| 18 | ** PSIO_CLOSE(): Closes a multivolume PSI direct access file.
 | 
|---|
| 19 | **
 | 
|---|
| 20 | **  \param unit = The PSI unit number used to identify the file to all read
 | 
|---|
| 21 | **                and write functions.
 | 
|---|
| 22 | **  \param keep = Boolean to indicate if the file should be deleted (0) or
 | 
|---|
| 23 | **                retained (1).
 | 
|---|
| 24 | */
 | 
|---|
| 25 | 
 | 
|---|
| 26 | int psio_close(unsigned int unit, int keep)
 | 
|---|
| 27 | {
 | 
|---|
| 28 |   unsigned int i;
 | 
|---|
| 29 |   psio_ud *this_unit;
 | 
|---|
| 30 |   psio_tocentry *this_entry, *next_entry;
 | 
|---|
| 31 | 
 | 
|---|
| 32 |   this_unit = &(psio_unit[unit]);
 | 
|---|
| 33 | 
 | 
|---|
| 34 |   /* First check to see if this unit is already closed */
 | 
|---|
| 35 |   if(this_unit->vol[0].stream == -1) psio_error(unit,PSIO_ERROR_RECLOSE);
 | 
|---|
| 36 | 
 | 
|---|
| 37 |   /* Dump the current TOC back out to disk */
 | 
|---|
| 38 |   psio_tocwrite(unit);
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   /* Free the TOC */
 | 
|---|
| 41 |   this_entry = this_unit->toc;
 | 
|---|
| 42 |   for(i=0; i < this_unit->toclen; i++) {
 | 
|---|
| 43 |       next_entry = this_entry->next;
 | 
|---|
| 44 |       free(this_entry);
 | 
|---|
| 45 |       this_entry = next_entry;
 | 
|---|
| 46 |     }
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   /* Close each volume (remove if necessary) and free the path */
 | 
|---|
| 49 |   for(i=0; i < this_unit->numvols; i++) {
 | 
|---|
| 50 | 
 | 
|---|
| 51 |       if(close(this_unit->vol[i].stream) == -1)
 | 
|---|
| 52 |           psio_error(unit,PSIO_ERROR_CLOSE);
 | 
|---|
| 53 | 
 | 
|---|
| 54 |       /* Delete the file completely if requested */
 | 
|---|
| 55 |       if(!keep) unlink(this_unit->vol[i].path);
 | 
|---|
| 56 | 
 | 
|---|
| 57 |       free(this_unit->vol[i].path);
 | 
|---|
| 58 |       this_unit->vol[i].path = NULL;
 | 
|---|
| 59 |       this_unit->vol[i].stream = -1;
 | 
|---|
| 60 |     }
 | 
|---|
| 61 | 
 | 
|---|
| 62 |   /* Reset the global page stats to zero */
 | 
|---|
| 63 |   this_unit->numvols = 0;
 | 
|---|
| 64 |   this_unit->toclen = 0;
 | 
|---|
| 65 |   this_unit->tocaddress.page = 0;
 | 
|---|
| 66 |   this_unit->tocaddress.offset = 0;
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   return(0);
 | 
|---|
| 69 | }
 | 
|---|
| 70 | 
 | 
|---|
| 71 | }
 | 
|---|
| 72 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.