; $Id: ctm_cleanup.pro,v 1.10 1999/01/22 19:30:15 mgs Stab $ ;------------------------------------------------------------- ;+ ; NAME: ; CTM_CLEANUP ; ; PURPOSE: ; Free memory blocked by excessive use of the GAMAP package. ; With the /DATA_ONLY option, only the data blocks themselves ; are freed, all header information remains accessible. ; This speeds up any further analysis. ; ; CATEGORY: ; GAMAP tool ; ; CALLING SEQUENCE: ; CTM_CLEANUP [,/ONLY_DATA] ; ; INPUTS: ; none ; ; KEYWORD PARAMETERS: ; ONLY_DATA -> Only free heap variables that point to the ; actual data records. Leave all 'info' intact. Default ; is to remove everything includign the global ; DataInfo and FileInfo structure arrays. ; ; OUTPUTS: ; ; SUBROUTINES: ; ; REQUIREMENTS: ; ; NOTES: ; ; EXAMPLE: ; CTM_CLEANUP ; ; MODIFICATION HISTORY: ; mgs, 05 Oct 1998: VERSION 1.00 ; mgs, 08 Oct 1998: - fixed DATA_ONLY part so that status is ; reset to zero and derived data records are removed ; ;- ; Copyright (C) 1998, Martin Schultz, Harvard University ; This software is provided as is without any warranty ; whatsoever. It may be freely used, copied or distributed ; for non-commercial purposes. This copyright notice must be ; kept with any copy of this software. If this software shall ; be used commercially or sold as part of a larger package, ; please contact the author to arrange payment. ; Bugs and comments should be directed to mgs@io.harvard.edu ; with subject "IDL routine ctm_cleanup" ;------------------------------------------------------------- pro ctm_cleanup,data_only=data_only ; include global common block @gamap_cmn ; close all open files close,/all ; set DEBUG level to 'undefined' if (n_elements(DEBUG) gt 0) then DEBUG = -1 ; can exit now, if no global datainfo available if (not ptr_valid(pGlobalDataInfo)) then return ; ================================================================ ; loop through DATAINFO records and free ; all valid data pointers ; ================================================================ d = *pGlobalDataInfo for i=0,n_elements(d)-1 do $ if (ptr_valid(d[i].data)) then ptr_free,d[i].data ; ================================================================ ; if only the data shall be removed, set all status variables ; to 0 (not read) and remove all derived data from the global ; lists (ilun lt 0) ; ================================================================ if (keyword_set(DATA_ONLY)) then begin d.status = 0 ind = where(d.ilun gt 0) if (ind[0] ge 0) then $ *pGlobalDataInfo = d[ind] if (ptr_valid(pGlobalFileInfo)) then begin f = *pGlobalFileInfo ind = where(f.ilun gt 0) if (ind[0] ge 0) then $ *pGlobalFileInfo = f[ind] endif return endif ; ================================================================ ; otherwise: free all fileinfo.gridinfo pointers ; ================================================================ if (ptr_valid(pGlobalFileInfo)) then begin f = *pGlobalFileInfo for i=0,n_elements(f)-1 do $ if (ptr_valid(f[i].gridinfo)) then ptr_free,f[i].gridinfo endif ; finally free the global fileinfo and datainfo pointers ; themselves if (ptr_valid(pGlobalDataInfo)) then $ ptr_free,pGlobalDataInfo if (ptr_valid(pGlobalFileInfo)) then $ ptr_free,pGlobalFileInfo return end