Ignore:
Timestamp:
Nov 13, 2015 4:03:38 PM (7 years ago)
Author:
srkline
Message:

more additions to the R/W functions to access VSANS data files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_RW_Utils.ipf

    r967 r969  
    11#pragma rtGlobals=3             // Use modern global access method and strict wave access. 
    22 
    3  
    4  
    5 // 
    6 // Start to build up and test the r/w accessors for VSANS 
    7 // (SANS has a template, VSANS does not, so just start from scratch here, since the  
    8 // file structure will be different) 
    9 // 
    10 // 
     3// 
     4// The base functions for R/W from HDF5 files. 
     5// All of the specific "get" and "write" functions call these base functions which are responsible 
     6// for all of the open/close mechanics. 
     7// 
     8// These VSANS file-specific functions are in: 
     9// V_HDF5_Read.ipf 
     10//               and 
     11// V_HDF5_Write.ipf 
     12// 
     13 
    1114 
    1215 
    1316// thought this would be useful, but the file name (folder) is stuck in the middle... 
    14 Strconstant ksPathPrefix = "root:(folder):entry:entry1:" 
     17//Strconstant ksPathPrefix = "root:(folder):entry:entry1:" 
    1518 
    1619 
     
    152155End 
    153156 
     157// Returns a wave reference, not just a single value 
     158// ---then you pick what you need from the wave 
     159//  
     160// - fname passed in is the full path to the file on disk 
     161// - path is the path to the value in the HDF tree 
     162// 
     163// check to see if the value exists (It will be a wave) 
     164// -- if it does, return the value from the local folder 
     165// -- if not, read the file in, then return the value 
     166// 
     167Function/WAVE V_getTextWaveFromHDF5(fname,path) 
     168        String fname,path 
     169 
     170        String folderStr="" 
     171        Variable valExists=0 
     172         
     173        folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) 
     174         
     175        if(Exists("root:"+folderStr+":"+path)) 
     176                valExists=1 
     177        endif 
     178         
     179        if(!valExists) 
     180                //then read in the file 
     181                V_LoadHDF5_NoAtt(fname) 
     182        endif 
     183 
     184// this should exist now - if not, I need to see the error 
     185        Wave/T wOut = $("root:"+folderStr+":"+path) 
     186         
     187        return wOut 
     188         
     189End 
     190 
     191 
    154192// 
    155193//   TODO 
     
    159197// 
    160198// truncate to integer before returning?? 
     199// 
     200//  TODO 
     201// write a "getIntegerWave" function?? 
    161202// 
    162203//////  integer values 
     
    390431        return err 
    391432end 
     433 
     434////////////////////////////// 
     435////////////////////////////// 
     436////////////////////////////// 
     437 
     438Function V_KillNamedDataFolder(fname) 
     439        String fname 
     440         
     441        Variable err=0 
     442         
     443        String folderStr = V_GetFileNameFromPathNoSemi(fname) 
     444        folderStr = V_RemoveDotExtension(folderStr) 
     445         
     446        KillDataFolder/Z $("root:"+folderStr) 
     447        err = V_flag 
     448         
     449        return(err) 
     450end 
     451 
     452//given a filename of a SANS data filename of the form 
     453// name.anything 
     454//returns the name as a string without the ".fbdfasga" extension 
     455// 
     456// returns the input string if a"." can't be found (maybe it wasn't there" 
     457Function/S V_RemoveDotExtension(item) 
     458        String item 
     459        String invalid = item   // 
     460        Variable num=-1 
     461         
     462        //find the "dot" 
     463        String runStr="" 
     464        Variable pos = strsearch(item,".",0) 
     465        if(pos == -1) 
     466                //"dot" not found 
     467                return (invalid) 
     468        else 
     469                //found, get all of the characters preceeding it 
     470                runStr = item[0,pos-1] 
     471                return (runStr) 
     472        Endif 
     473End 
     474 
     475//returns a string containing filename (WITHOUT the ;vers) 
     476//the input string is a full path to the file (Mac-style, still works on Win in IGOR) 
     477//with the folders separated by colons 
     478// 
     479// called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf 
     480// 
     481Function/S V_GetFileNameFromPathNoSemi(fullPath) 
     482        String fullPath 
     483         
     484        Variable offset1,offset2 
     485        String filename="" 
     486        //String PartialPath 
     487        offset1 = 0 
     488        do 
     489                offset2 = StrSearch(fullPath, ":", offset1) 
     490                if (offset2 == -1)                              // no more colons ? 
     491                        fileName = FullPath[offset1,strlen(FullPath) ] 
     492                        //PartialPath = FullPath[0, offset1-1] 
     493                        break 
     494                endif 
     495                offset1 = offset2+1 
     496        while (1) 
     497         
     498        //remove version number from name, if it's there - format should be: filename;N 
     499        filename =  StringFromList(0,filename,";")              //returns null if error 
     500         
     501        Return filename 
     502End 
Note: See TracChangeset for help on using the changeset viewer.