Ignore:
Timestamp:
Mar 29, 2007 1:45:45 PM (16 years ago)
Author:
srkline
Message:

Initial file shuffling, partially done.
Created 3 new files:
SANS_Utilities
NCNR_Utils
NCNR_DataReadWrite

(SANS_Utilites may eventually become NCNR-specific, but I'm not sure)

Location:
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Includes_v500.ipf

    r59 r69  
    2929#include "ProDiv"                               version>=5.0 
    3030#include "ProtocolAsPanel"              version>=5.0 
    31 #include "RawDataReader"                version>=5.0 
     31//#include "RawDataReader"              version>=5.0                    //branched 29MAR07 
    3232#include "RawWindowHook"                version>=5.0 
    3333#include "RectAnnulAvg"                 version>=5.0 
     
    3535#include "Tile_2D"                              version>=5.0 
    3636#include "Transmission"                 version>=5.0 
    37 #include "VAXFileUtils"                 version>=5.0 
     37//#include "VAXFileUtils"                       version>=5.0            //branched 29MAR07 
    3838#include "WorkFileUtils"                version>=5.0 
    3939#include "WriteQIS"                             version>=5.0  
    40 #include "RealTimeUpdate_RT"            version>=5.0                    //removed button from main panel AUG2006 
     40// removed RT button from main panel AUG2006 
     41// removed RT ipf file in 29MAR07 branch (do not delete, but do not include or maintain) 
     42//#include "RealTimeUpdate_RT"          version>=5.0             
    4143#include "SANSPreferences"                              version>=5.0            //NEW 05MAY03 
    4244#include "Subtract_1D"                          version>=5.0                    //NEW 14MAY03 
     45 
     46#include "NCNR_Utils"                                                                   //new in the 29MAR07 branch 
     47#include "NCNR_DataReadWrite"                                                   //new in the 29MAR07 branch 
     48#include "SANS_Utilities"                                                               //new in the 29MAR07 branch 
    4349 
    4450// to include the analysis packages, uncomment the following 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Initialize.ipf

    r41 r69  
    3333        InitFakeProtocols() 
    3434        InitGlobals()    
     35        InitFacilityGlobals() 
    3536        DoWindow/F Main_Panel 
    3637        If(V_flag == 0) 
     
    6869//return data folder to root: before leaving 
    6970// 
    70 //now contains global parameters used for detector constants 
     71// global parameters used for detector constants are facility specific 
     72// and have been moved 
    7173// 
    7274Function InitGlobals() 
     
    9597        Variable/G root:myGlobals:gBinWidth=1 
    9698        Variable/G root:myGlobals:gNPhiSteps=72 
    97         Variable/G root:myGlobals:gNPixelsX=128 
    98         Variable/G root:myGlobals:gNPixelsY=128 
    99          
    100         //Detector -specific globals 
    101         Variable/G root:myGlobals:PixelResNG3_ILL = 1.0         //pixel resolution in cm 
    102         Variable/G root:myGlobals:PixelResNG5_ILL = 1.0 
    103         Variable/G root:myGlobals:PixelResNG7_ILL = 1.0 
    104         Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5 
    105         Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5 
    106         Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5 
    107         Variable/G root:myGlobals:PixelResDefault = 0.5 
    108          
    109         Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6              //deadtime in seconds 
    110         Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6 
    111         Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6 
    112         Variable/G root:myGlobals:DeadtimeNG3_ORNL = 3.4e-6 
    113         Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6             //as of 9 MAY 2002 
    114         Variable/G root:myGlobals:DeadtimeNG7_ORNL = 3.4e-6 
    115         Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6 
    116          
     99 
    117100        //set flag if Demo Version is detected 
    118101        Variable/G root:myGlobals:isDemoVersion = isDemo() 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/RawDataReader.ipf

    r41 r69  
    33#pragma IgorVersion=4.0 
    44 
    5 //************************** 
    6 // 
    7 // Vers. 1.2 092101 
    8 // 
    9 // functions for reading raw data files from the VAX 
    10 // - RAW data files are read into the RAW folder - integer data from the detector 
    11 //   is decompressed and given the proper orientation 
    12 // - header information is placed into real,integer, or text waves in the order they appear 
    13 //   in the file header 
    14 // 
    15 // Work data (DIV File) is read into the DIV folder 
    16 // 
    17 //***************************** 
    185 
    19 //simple, main entry procedure that will load a RAW sans data file (not a work file) 
    20 //into the RAW dataFolder 
    21 //(typically called from main panel button) 
    22 // 
    23 Proc LoadSANSData() 
    24         String msgStr = "Select a SANS data file" 
    25          
    26         Variable err 
    27         err = ReadBinarySANS(msgStr)            //will prompt for file 
    28         //ignore the error here  
    29 End 
    30  
    31 //function that does the guts of reading the binary data file 
    32 //fname is the full path:name;vers required to open the file 
    33 //VAX record markers are skipped as needed 
    34 //the data as read in is in compressed I*2 format, and is decompressed 
    35 //immediately after being read in. The final root:RAW:data wave is the real 
    36 //neutron counts and can be directly operated on 
    37 //header information is put into three wave, integers,reals, and text 
    38 //logicals in the header are currently skipped, since they are no use in the  
    39 //data reduction process. the logicals, however are left untouched. 
    40 // 
    41 Function ReadHeaderAndData(fname) 
    42         String fname 
    43         //this function is for reading in RAW data only, so it will always put data in RAW folder 
    44         String curPath = "root:RAW" 
    45         SetDataFolder curPath           //use the full path, so it will always work 
    46         Variable/G root:RAW:gIsLogScale = 0             //initial state is linear, keep this in RAW folder 
    47          
    48         Variable refNum,integer,realval 
    49         String sansfname,textstr 
    50          
    51         Make/O/N=23 $"root:RAW:IntegersRead" 
    52         Make/O/N=52 $"root:RAW:RealsRead" 
    53         Make/O/T/N=11 $"root:RAW:TextRead" 
    54          
    55         Wave intw=$"root:RAW:IntegersRead" 
    56         Wave realw=$"root:RAW:RealsRead" 
    57         Wave/T textw=$"root:RAW:TextRead" 
    58          
    59         //***NOTE **** 
    60         // the "current path" gets mysteriously reset to "root:" after the SECOND pass through 
    61         // this read routine, after the open dialog is presented 
    62         // the "--read" waves end up in the correct folder, but the data does not! Why? 
    63         //must re-set data folder before writing data array (done below) 
    64          
    65         //full filename and path is now passed in... 
    66         //actually open the file 
    67         Open/R refNum as fname 
    68         //skip first two bytes (VAX record length markers, not needed here) 
    69         FSetPos refNum, 2 
    70         //read the next 21 bytes as characters (fname) 
    71         FReadLine/N=21 refNum,textstr 
    72         textw[0]= textstr 
    73         //read four i*4 values  /F=3 flag, B=3 flag 
    74         FBinRead/F=3/B=3 refNum, integer 
    75         intw[0] = integer 
    76         // 
    77         FBinRead/F=3/B=3 refNum, integer 
    78         intw[1] = integer 
    79         // 
    80         FBinRead/F=3/B=3 refNum, integer 
    81         intw[2] = integer 
    82         // 
    83         FBinRead/F=3/B=3 refNum, integer 
    84         intw[3] = integer 
    85         // 6 text fields 
    86         FSetPos refNum,55               //will start reading at byte 56 
    87         FReadLine/N=20 refNum,textstr 
    88         textw[1]= textstr 
    89         FReadLine/N=3 refNum,textstr 
    90         textw[2]= textstr 
    91         FReadLine/N=11 refNum,textstr 
    92         textw[3]= textstr 
    93         FReadLine/N=1 refNum,textstr 
    94         textw[4]= textstr 
    95         FReadLine/N=8 refNum,textstr 
    96         textw[5]= textstr 
    97         FReadLine/N=60 refNum,textstr 
    98         textw[6]= textstr 
    99          
    100         //3 integers 
    101         FSetPos refNum,174 
    102         FBinRead/F=3/B=3 refNum, integer 
    103         intw[4] = integer 
    104         FBinRead/F=3/B=3 refNum, integer 
    105         intw[5] = integer 
    106         FBinRead/F=3/B=3 refNum, integer 
    107         intw[6] = integer 
    108          
    109         //2 integers, 3 text fields 
    110         FSetPos refNum,194 
    111         FBinRead/F=3/B=3 refNum, integer 
    112         intw[7] = integer 
    113         FBinRead/F=3/B=3 refNum, integer 
    114         intw[8] = integer 
    115         FReadLine/N=6 refNum,textstr 
    116         textw[7]= textstr 
    117         FReadLine/N=6 refNum,textstr 
    118         textw[8]= textstr 
    119         FReadLine/N=6 refNum,textstr 
    120         textw[9]= textstr 
    121          
    122         //2 integers 
    123         FSetPos refNum,244 
    124         FBinRead/F=3/B=3 refNum, integer 
    125         intw[9] = integer 
    126         FBinRead/F=3/B=3 refNum, integer 
    127         intw[10] = integer 
    128          
    129         //2 integers 
    130         FSetPos refNum,308 
    131         FBinRead/F=3/B=3 refNum, integer 
    132         intw[11] = integer 
    133         FBinRead/F=3/B=3 refNum, integer 
    134         intw[12] = integer 
    135          
    136         //2 integers 
    137         FSetPos refNum,332 
    138         FBinRead/F=3/B=3 refNum, integer 
    139         intw[13] = integer 
    140         FBinRead/F=3/B=3 refNum, integer 
    141         intw[14] = integer 
    142          
    143         //3 integers 
    144         FSetPos refNum,376 
    145         FBinRead/F=3/B=3 refNum, integer 
    146         intw[15] = integer 
    147         FBinRead/F=3/B=3 refNum, integer 
    148         intw[16] = integer 
    149         FBinRead/F=3/B=3 refNum, integer 
    150         intw[17] = integer 
    151          
    152         //1 text field 
    153         FSetPos refNum,404 
    154         FReadLine/N=42 refNum,textstr 
    155         textw[10]= textstr 
    156          
    157         //1 integer 
    158         FSetPos refNum,458 
    159         FBinRead/F=3/B=3 refNum, integer 
    160         intw[18] = integer 
    161          
    162         //4 integers 
    163         FSetPos refNum,478 
    164         FBinRead/F=3/B=3 refNum, integer 
    165         intw[19] = integer 
    166         FBinRead/F=3/B=3 refNum, integer 
    167         intw[20] = integer 
    168         FBinRead/F=3/B=3 refNum, integer 
    169         intw[21] = integer 
    170         FBinRead/F=3/B=3 refNum, integer 
    171         intw[22] = integer 
    172          
    173         Close refNum 
    174          
    175         //now get all of the reals 
    176         // 
    177         //Do all the GBLoadWaves at the end 
    178         // 
    179         //FBinRead Cannot handle 32 bit VAX floating point 
    180         //GBLoadWave, however, can properly read it 
    181         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    182         String strToExecute 
    183         //append "/S=offset/U=numofreals" to control the read 
    184         // then append fname to give the full file path 
    185         // then execute 
    186          
    187         Variable a=0,b=0 
    188          
    189         SetDataFolder curPath 
    190          
    191         // 4 R*4 values 
    192         strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" 
    193         Execute strToExecute 
    194         Wave w=$"root:RAW:tempGBWave0" 
    195         b=4     //num of reals read 
    196         realw[a,a+b-1] = w[p-a] 
    197         a+=b 
    198          
    199         // 4 R*4 values 
    200         SetDataFolder curPath 
    201         strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\"" 
    202         Execute strToExecute 
    203         b=4      
    204         realw[a,a+b-1] = w[p-a] 
    205         a+=b 
    206  
    207 /////////// 
    208         // 2 R*4 values 
    209         SetDataFolder curPath 
    210         strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" 
    211         Execute strToExecute 
    212         b=2      
    213         realw[a,a+b-1] = w[p-a] 
    214         a+=b 
    215  
    216         // 6 R*4 values 
    217         SetDataFolder curPath 
    218         strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\"" 
    219         Execute strToExecute 
    220         b=6      
    221         realw[a,a+b-1] = w[p-a] 
    222         a+=b 
    223          
    224         // 13 R*4 values 
    225         SetDataFolder curPath 
    226         strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\"" 
    227         Execute strToExecute 
    228         b=13 
    229         realw[a,a+b-1] = w[p-a] 
    230         a+=b 
    231          
    232         // 3 R*4 values 
    233         SetDataFolder curPath 
    234         strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\"" 
    235         Execute strToExecute 
    236         b=3      
    237         realw[a,a+b-1] = w[p-a] 
    238         a+=b 
    239          
    240         // 7 R*4 values 
    241         SetDataFolder curPath 
    242         strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\"" 
    243         Execute strToExecute 
    244         b=7 
    245         realw[a,a+b-1] = w[p-a] 
    246         a+=b 
    247          
    248         // 4 R*4 values 
    249         SetDataFolder curPath 
    250         strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\"" 
    251         Execute strToExecute 
    252         b=4      
    253         realw[a,a+b-1] = w[p-a] 
    254         a+=b 
    255          
    256         // 2 R*4 values 
    257         SetDataFolder curPath 
    258         strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\"" 
    259         Execute strToExecute 
    260         b=2 
    261         realw[a,a+b-1] = w[p-a] 
    262         a+=b 
    263          
    264         // 2 R*4 values 
    265         SetDataFolder curPath 
    266         strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\"" 
    267         Execute strToExecute 
    268         b=2 
    269         realw[a,a+b-1] = w[p-a] 
    270         a+=b 
    271          
    272         // 5 R*4 values 
    273         SetDataFolder curPath 
    274         strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\"" 
    275         Execute strToExecute 
    276         b=5      
    277         realw[a,a+b-1] = w[p-a] 
    278          
    279         //if the binary VAX data ws transferred to a MAC, all is OK 
    280         //if the data was trasnferred to an Intel machine (IBM), all the real values must be 
    281         //divided by 4 to get the correct floating point values 
    282         // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly 
    283         // on an Intel machine. 
    284         //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read 
    285         //VAX reals correctly, and no checking is necessary 12 APR 99 
    286         //if(cmpstr("Macintosh",IgorInfo(2)) == 0) 
    287                 //do nothing 
    288         //else 
    289                 //either Windows or Windows NT 
    290                 //realw /= 4 
    291         //endif 
    292          
    293         SetDataFolder curPath 
    294         //read in the data 
    295         strToExecute = "GBLoadWave/O/N=tempGBwave/B/T={16,2}/S=514/Q" + "\"" + fname + "\"" 
    296         Execute strToExecute 
    297  
    298         SetDataFolder curPath           //use the full path, so it will always work 
    299          
    300         Make/O/N=16384 $"root:RAW:data" 
    301         WAVE data=$"root:RAW:data" 
    302         SkipAndDecompressVAX(w,data) 
    303         Redimension/N=(128,128) data                    //NIST raw data is 128x128 - do not generalize 
    304          
    305         //keep a string with the filename in the RAW folder 
    306         String/G root:RAW:fileList = textw[0] 
    307          
    308         //set the globals to the detector dimensions (pixels) 
    309         Variable/G root:myGlobals:gNPixelsX=128         //default for Ordela data (also set in Initialize.ipf) 
    310         Variable/G root:myGlobals:gNPixelsY=128 
    311 //      if(cmpstr(textW[9],"ILL   ")==0)                //override if OLD Cerca data 
    312 //              Variable/G root:myGlobals:gNPixelsX=64 
    313 //              Variable/G root:myGlobals:gNPixelsY=64 
    314 //      endif 
    315          
    316         //clean up - get rid of w = $"root:RAW:tempGBWave0" 
    317         KillWaves/Z w 
    318          
    319         //return the data folder to root 
    320         SetDataFolder root: 
    321          
    322         Return 0 
    323  
    324 End 
    325  
    326 //function called by the main entry procedure 
    327 //sets global display variable, reads in the data, and displays it 
    328 //displays alert, and returns error if no file was selected 
    329 // 
    330 // calling routine must decide whether to abort the execution or not... 
    331 Function ReadBinarySANS(msgStr) 
    332         String msgStr 
    333  
    334         String filename="" 
    335  
    336         //each routine is responsible for checking the current (displayed) data folder 
    337         //selecting it, and returning to root when done 
    338         PathInfo/S catPathName          //should set the next dialog to the proper path... 
    339         //get the filename, then read it in 
    340         filename = PromptForPath(msgStr) 
    341         //check for cancel from dialog 
    342         if(strlen(filename)==0) 
    343                 //user cancelled, abort 
    344                 SetDataFolder root: 
    345                 DoAlert 0, "No file selected, action aborted" 
    346                 return(1) 
    347         Endif 
    348         //Print  "GetFileNameFromPath(filename) = " +  GetFileNameFromPathNoSemi(filename) 
    349         ReadHeaderAndData(filename)     //this is the full Path+file 
    350  
    351         //the calling macro must change the display type 
    352         String/G root:myGlobals:gDataDisplayType="RAW"          //displayed data type is raw 
    353          
    354         //data is displayed here 
    355         fRawWindowHook() 
    356          
    357         Return(0) 
    358 End 
    359  
    360 //function to take the I*2 data that was read in, in VAX format 
    361 //where the integers are "normal", but there are 2-byte record markers 
    362 //sprinkled evenly through the data 
    363 //there are skipped, leaving 128x128=16384 data values 
    364 //the input array (in) is larger than 16384 
    365 //(out) is 128x128 data (single precision) as defined in ReadHeaderAndData() 
    366 // 
    367 Function SkipAndDecompressVAX(in,out) 
    368         Wave in,out 
    369          
    370         Variable skip,ii 
    371  
    372         ii=0 
    373         skip=0 
    374         do 
    375                 if(mod(ii+skip,1022)==0) 
    376                         skip+=1 
    377                 endif 
    378                 out[ii] = Decompress(in[ii+skip]) 
    379                 ii+=1 
    380         while(ii<16384) 
    381         return(0) 
    382 End 
    383  
    384 //decompresses each I*2 data value to its real I*4 value 
    385 //using the decompression routine written by Jim Ryhne, many moons ago 
    386 // 
    387 // the compression routine (not shown here, contained in the VAX fortran RW_DATAFILE.FOR) maps I4 to I2 values. 
    388 // (back in the days where disk space *really* mattered). the I4toI2 function spit out: 
    389 // I4toI2 = I4                                                          when I4 in [0,32767] 
    390 // I4toI2 = -777                                                        when I4 in [2,767,000,...] 
    391 // I4toI2 mapped to -13277 to -32768    otherwise 
    392 // 
    393 // the mapped values [-776,-1] and [-13276,-778] are not used. 
    394 // in this compression scheme, only 4 significant digits are retained (to allow room for the exponent) 
    395 // technically, the maximum value should be 2,768,499 since this maps to -32768. But this is of 
    396 // little consequence. If you have individual pixel values on the detector that are that large, you need 
    397 // to re-think your experiment. 
    398 Function Decompress(val) 
    399         Variable val 
    400  
    401         Variable i4,npw,ipw,ib,nd 
    402  
    403         ib=10 
    404         nd=4 
    405         ipw=ib^nd 
    406         i4=val 
    407  
    408         if (i4 <= -ipw)  
    409                 npw=trunc(-i4/ipw) 
    410                 i4=mod(-i4,ipw)*(ib^npw) 
    411                 return i4 
    412         else 
    413                 return i4 
    414         endif 
    415 End 
    416  
    417 //**************** 
    418 //main entry procedure for reading a "WORK.DIV" file 
    419 //displays a quick image of the  file, to check that it's correct 
    420 //data is deposited in root:DIV data folder 
    421 // 
    422 Proc ReadWork_DIV() 
    423 //      Silent 1 
    424          
    425         String fname = PromptForPath("Select detector sensitivity file") 
    426         ReadHeaderAndWork("DIV",fname)          //puts what is read in work.div 
    427          
    428         String waveStr = "root:DIV:data" 
    429         NewImage/F/K=1/S=2 $waveStr             //this is an experimental IGOR operation 
    430         ModifyImage '' ctab= {*,*,YellowHot,0} 
    431         //Display;AppendImage $waveStr 
    432          
    433         //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage 
    434         String/G root:DIV:fileList = "WORK.DIV" 
    435          
    436         SetDataFolder root:             //(redundant) 
    437 //      Silent 0 
    438 End 
    439  
    440 //testing procedure that is not called anymore and is out-of-date 
    441 //with the new data structures. update before re-implementing 
    442 Proc ReadBinaryWork()           //this procedure is not called anymore 
    443  
    444 //      Silent 1 
    445          
    446         //make sure the globals are reset properly 
    447         Variable/G root:myGlobals:gIsLogScale=0 //image is linearly scaled to begin with 
    448         String/G root:myGlobals:gDataDisplayType="RAW"          //displayed data type is raw 
    449          
    450         //each routine is responsible for checking the current (displayed) data folder 
    451         //selecting it, and returning to root when done 
    452          
    453         ReadHeaderAndWork() 
    454  
    455         SetDataFolder root:RAW 
    456         //data is displayed here 
    457         Display;AppendImage data 
    458          
    459 //      Silent 0 
    460          
    461         //data folder was changed from root in this macro 
    462         SetDataFolder root: 
    463 End 
    464  
    465 //this function is the guts of reading a rinary VAX file of real (4-byte) values 
    466 // (i.e. a WORK.aaa file)  
    467 // work files have the same header structure as RAW SANS data, just with 
    468 //different data (real, rather than compressed integer data) 
    469 // 
    470 //************ 
    471 //this routine incorrectly reads in several data values where the VAX record 
    472 //marker splits the 4-byte real (at alternating record markers) 
    473 //this error seems to not be severe, but shoud be corrected (at great pain) 
    474 //************ 
    475 // 
    476 Function ReadHeaderAndWork(type,fname) 
    477         String type,fname 
    478          
    479         //type is the desired folder to read the workfile to 
    480         //this data will NOT be automatically displayed gDataDisplayType is unchanged 
    481  
    482 //      SVAR cur_folder=root:myGlobals:gDataDisplayType 
    483         String cur_folder = type 
    484         String curPath = "root:"+cur_folder 
    485         SetDataFolder curPath           //use the full path, so it will always work 
    486          
    487         Variable refNum,integer,realval 
    488         String sansfname,textstr 
    489         Variable/G $(curPath + ":gIsLogScale") = 0              //initial state is linear, keep this in DIV folder 
    490          
    491         Make/O/N=23 $(curPath + ":IntegersRead") 
    492         Make/O/N=52 $(curPath + ":RealsRead") 
    493         Make/O/T/N=11 $(curPath + ":TextRead") 
    494          
    495         WAVE intw=$(curPath + ":IntegersRead") 
    496         WAVE realw=$(curPath + ":RealsRead") 
    497         WAVE/T textw=$(curPath + ":TextRead") 
    498          
    499         //***NOTE **** 
    500         // the "current path" gets mysteriously reset to "root:" after the SECOND pass through 
    501         // this read routine, after the open dialog is presented 
    502         // the "--read" waves end up in the correct folder, but the data does not! Why? 
    503         //must re-set data folder before writing data array (done below) 
    504          
    505         SetDataFolder curPath 
    506          
    507         //actually open the file 
    508         Open/R refNum as fname 
    509         //skip first two bytes 
    510         FSetPos refNum, 2 
    511         //read the next 21 bytes as characters (fname) 
    512         FReadLine/N=21 refNum,textstr 
    513         textw[0]= textstr 
    514         //read four i*4 values  /F=3 flag, B=3 flag 
    515         FBinRead/F=3/B=3 refNum, integer 
    516         intw[0] = integer 
    517         // 
    518         FBinRead/F=3/B=3 refNum, integer 
    519         intw[1] = integer 
    520         // 
    521         FBinRead/F=3/B=3 refNum, integer 
    522         intw[2] = integer 
    523         // 
    524         FBinRead/F=3/B=3 refNum, integer 
    525         intw[3] = integer 
    526         // 6 text fields 
    527         FSetPos refNum,55               //will start reading at byte 56 
    528         FReadLine/N=20 refNum,textstr 
    529         textw[1]= textstr 
    530         FReadLine/N=3 refNum,textstr 
    531         textw[2]= textstr 
    532         FReadLine/N=11 refNum,textstr 
    533         textw[3]= textstr 
    534         FReadLine/N=1 refNum,textstr 
    535         textw[4]= textstr 
    536         FReadLine/N=8 refNum,textstr 
    537         textw[5]= textstr 
    538         FReadLine/N=60 refNum,textstr 
    539         textw[6]= textstr 
    540          
    541         //3 integers 
    542         FSetPos refNum,174 
    543         FBinRead/F=3/B=3 refNum, integer 
    544         intw[4] = integer 
    545         FBinRead/F=3/B=3 refNum, integer 
    546         intw[5] = integer 
    547         FBinRead/F=3/B=3 refNum, integer 
    548         intw[6] = integer 
    549          
    550         //2 integers, 3 text fields 
    551         FSetPos refNum,194 
    552         FBinRead/F=3/B=3 refNum, integer 
    553         intw[7] = integer 
    554         FBinRead/F=3/B=3 refNum, integer 
    555         intw[8] = integer 
    556         FReadLine/N=6 refNum,textstr 
    557         textw[7]= textstr 
    558         FReadLine/N=6 refNum,textstr 
    559         textw[8]= textstr 
    560         FReadLine/N=6 refNum,textstr 
    561         textw[9]= textstr 
    562          
    563         //2 integers 
    564         FSetPos refNum,244 
    565         FBinRead/F=3/B=3 refNum, integer 
    566         intw[9] = integer 
    567         FBinRead/F=3/B=3 refNum, integer 
    568         intw[10] = integer 
    569          
    570         //2 integers 
    571         FSetPos refNum,308 
    572         FBinRead/F=3/B=3 refNum, integer 
    573         intw[11] = integer 
    574         FBinRead/F=3/B=3 refNum, integer 
    575         intw[12] = integer 
    576          
    577         //2 integers 
    578         FSetPos refNum,332 
    579         FBinRead/F=3/B=3 refNum, integer 
    580         intw[13] = integer 
    581         FBinRead/F=3/B=3 refNum, integer 
    582         intw[14] = integer 
    583          
    584         //3 integers 
    585         FSetPos refNum,376 
    586         FBinRead/F=3/B=3 refNum, integer 
    587         intw[15] = integer 
    588         FBinRead/F=3/B=3 refNum, integer 
    589         intw[16] = integer 
    590         FBinRead/F=3/B=3 refNum, integer 
    591         intw[17] = integer 
    592          
    593         //1 text field 
    594         FSetPos refNum,404 
    595         FReadLine/N=42 refNum,textstr 
    596         textw[10]= textstr 
    597          
    598         //1 integer 
    599         FSetPos refNum,458 
    600         FBinRead/F=3/B=3 refNum, integer 
    601         intw[18] = integer 
    602          
    603         //4 integers 
    604         FSetPos refNum,478 
    605         FBinRead/F=3/B=3 refNum, integer 
    606         intw[19] = integer 
    607         FBinRead/F=3/B=3 refNum, integer 
    608         intw[20] = integer 
    609         FBinRead/F=3/B=3 refNum, integer 
    610         intw[21] = integer 
    611         FBinRead/F=3/B=3 refNum, integer 
    612         intw[22] = integer 
    613          
    614         Close refNum 
    615          
    616         //now get all of the reals 
    617         // 
    618         //Do all the GBLoadWaves at the end 
    619         // 
    620         //FBinRead Cannot handle 32 bit VAX floating point 
    621         //GBLoadWave, however, can properly read it 
    622         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    623         String strToExecute 
    624         //append "/S=offset/U=numofreals" to control the read 
    625         // then append fname to give the full file path 
    626         // then execute 
    627          
    628         Variable a=0,b=0 
    629          
    630         SetDataFolder curPath 
    631         // 4 R*4 values 
    632         strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" 
    633         Execute strToExecute 
    634          
    635         SetDataFolder curPath 
    636         Wave w=$(curPath + ":tempGBWave0") 
    637         b=4     //num of reals read 
    638         realw[a,a+b-1] = w[p-a] 
    639         a+=b 
    640          
    641         // 4 R*4 values 
    642         SetDataFolder curPath 
    643         strToExecute = GBLoadStr + "/S=158/U=4" + "\"" + fname + "\"" 
    644         Execute strToExecute 
    645         b=4      
    646         realw[a,a+b-1] = w[p-a] 
    647         a+=b 
    648  
    649 /////////// 
    650         // 2 R*4 values 
    651         SetDataFolder curPath 
    652         strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" 
    653         Execute strToExecute 
    654         b=2      
    655         realw[a,a+b-1] = w[p-a] 
    656         a+=b 
    657  
    658         // 6 R*4 values 
    659         SetDataFolder curPath 
    660         strToExecute = GBLoadStr + "/S=220/U=6" + "\"" + fname + "\"" 
    661         Execute strToExecute 
    662         b=6      
    663         realw[a,a+b-1] = w[p-a] 
    664         a+=b 
    665          
    666         // 13 R*4 values 
    667         SetDataFolder curPath 
    668         strToExecute = GBLoadStr + "/S=252/U=13" + "\"" + fname + "\"" 
    669         Execute strToExecute 
    670         b=13 
    671         realw[a,a+b-1] = w[p-a] 
    672         a+=b 
    673          
    674         // 3 R*4 values 
    675         SetDataFolder curPath 
    676         strToExecute = GBLoadStr + "/S=320/U=3" + "\"" + fname + "\"" 
    677         Execute strToExecute 
    678         b=3      
    679         realw[a,a+b-1] = w[p-a] 
    680         a+=b 
    681          
    682         // 7 R*4 values 
    683         SetDataFolder curPath 
    684         strToExecute = GBLoadStr + "/S=348/U=7" + "\"" + fname + "\"" 
    685         Execute strToExecute 
    686         b=7 
    687         realw[a,a+b-1] = w[p-a] 
    688         a+=b 
    689          
    690         // 4 R*4 values 
    691         SetDataFolder curPath 
    692         strToExecute = GBLoadStr + "/S=388/U=4" + "\"" + fname + "\"" 
    693         Execute strToExecute 
    694         b=4      
    695         realw[a,a+b-1] = w[p-a] 
    696         a+=b 
    697          
    698         // 2 R*4 values 
    699         SetDataFolder curPath 
    700         strToExecute = GBLoadStr + "/S=450/U=2" + "\"" + fname + "\"" 
    701         Execute strToExecute 
    702         b=2 
    703         realw[a,a+b-1] = w[p-a] 
    704         a+=b 
    705          
    706         // 2 R*4 values 
    707         SetDataFolder curPath 
    708         strToExecute = GBLoadStr + "/S=470/U=2" + "\"" + fname + "\"" 
    709         Execute strToExecute 
    710         b=2 
    711         realw[a,a+b-1] = w[p-a] 
    712         a+=b 
    713          
    714         // 5 R*4 values 
    715         SetDataFolder curPath 
    716         strToExecute = GBLoadStr + "/S=494/U=5" + "\"" + fname + "\"" 
    717         Execute strToExecute 
    718         b=5      
    719         realw[a,a+b-1] = w[p-a] 
    720          
    721         //if the binary VAX data ws transferred to a MAC, all is OK 
    722         //if the data was trasnferred to an Intel machine (IBM), all the real values must be 
    723         //divided by 4 to get the correct floating point values 
    724         // I can't find any combination of settings in GBLoadWave or FBinRead to read data in correctly 
    725         // on an Intel machine. 
    726         //With the corrected version of GBLoadWave XOP (v. 1.43 or higher) Mac and PC both read 
    727         //VAX reals correctly, and no checking is necessary 12 APR 99 
    728         //if(cmpstr("Macintosh",IgorInfo(2)) == 0) 
    729                 //do nothing 
    730         //else 
    731                 //either Windows or Windows NT 
    732                 //realw /= 4 
    733         //endif 
    734          
    735         //read in the data 
    736          GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    737  
    738         curPath = "root:"+cur_folder 
    739         SetDataFolder curPath           //use the full path, so it will always work 
    740          
    741         Make/O/N=16384 $(curPath + ":data") 
    742         WAVE data = $(curPath + ":data") 
    743          
    744         Variable skip,ii,offset 
    745          
    746         //read in a total of 16384 values (ii)  
    747         //as follows : 
    748         // skip first 2 bytes 
    749         // skip 512 byte header 
    750         // skip first 2 bytes of data 
    751         //(read 511 reals, skip 2b, 510 reals, skip 2b) -16 times = 16336 values 
    752         // read the final 48 values in seperately to avoid EOF error 
    753          
    754         ///////////// 
    755         SetDataFolder curPath 
    756         skip = 0 
    757         ii=0 
    758         offset = 514 +2 
    759         a=0 
    760         do 
    761                 SetDataFolder curPath 
    762                  
    763                 strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=511" + "\"" + fname + "\"" 
    764                 Execute strToExecute 
    765                 //Print strToExecute 
    766                 b=511 
    767                 data[a,a+b-1] = w[p-a] 
    768                 a+=b 
    769                  
    770                 offset += 511*4 +2 
    771                  
    772                 strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=510" + "\"" + fname + "\"" 
    773                 SetDataFolder curPath 
    774                 Execute strToExecute 
    775                 //Print strToExecute 
    776                 b=510 
    777                 data[a,a+b-1] = w[p-a] 
    778                 a+=b 
    779                  
    780                 offset += 510*4 +2 
    781                  
    782                 ii+=1 
    783                 //Print "inside do, data[2] =",data[2] 
    784                 //Print "inside do, tempGBwave0[0] = ",w[0] 
    785         while(ii<16) 
    786          
    787         // 16336 values have been read in -- 
    788         //read in last 64 values 
    789         strToExecute = GBLoadStr + "/S="+num2str(offset)+"/U=48" + "\"" + fname + "\"" 
    790          
    791         SetDataFolder curPath 
    792         Execute strToExecute 
    793         b=48 
    794         data[a,a+b-1] = w[p-a] 
    795         a+=b 
    796 // 
    797 /// done reading in raw data 
    798 // 
    799         //Print "in workdatareader , data = ", data[1][1] 
    800  
    801         Redimension/n=(128,128) data 
    802          
    803         //clean up - get rid of w = $"tempGBWave0" 
    804         KillWaves w 
    805          
    806         //divide the FP data by 4 if read from a PC (not since GBLoadWave update) 
    807         //if(cmpstr("Macintosh",IgorInfo(2)) == 0) 
    808                 //do nothing 
    809         //else 
    810                 //either Windows or Windows NT 
    811                 //data /= 4 
    812         //endif 
    813          
    814         //keep a string with the filename in the DIV folder 
    815         String/G $(curPath + ":fileList") = textw[0] 
    816          
    817         //return the data folder to root 
    818         SetDataFolder root: 
    819          
    820         Return(0) 
    821 End 
    822  
    823 //returns the path to the file, or null if cancel 
    824 Function/S DoOpenFileDialog(msg) 
    825         String msg 
    826          
    827         Variable refNum 
    828 //      String message = "Select a file" 
    829         String outputPath 
    830          
    831         Open/D/R/T="????"/M=msg refNum 
    832         outputPath = S_fileName 
    833          
    834         return outputPath 
    835 End 
    836  
    837 // returns the path to the file, or null if the user cancelled 
    838 Function/S DoSaveFileDialog(msg) 
    839         String msg 
    840         Variable refNum 
    841 //      String message = "Save the file as" 
    842         String outputPath 
    843          
    844         Open/D/M=msg refNum 
    845         outputPath = S_fileName 
    846          
    847         return outputPath 
    848 End 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/SANSPreferences.ipf

    r41 r69  
    8888//      SetVariable setvar3,limits={1,2000,1},value= root:myGlobals:gNPixelsY 
    8989 
    90 EndMacro 
     90End 
    9191 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Transmission.ipf

    r47 r69  
    18071807End 
    18081808 
    1809 //****************** 
    1810 //lookup tables for attenuator transmissions 
    1811 //NG3 and NG7 attenuators are physically different, so the transmissions are slightly different 
    1812 //NG1 - (8m SANS) is not supported 
    1813  
    1814 Proc MakeNG3AttenTable() 
    1815  
    1816         NewDataFolder/O root:myGlobals:Attenuators 
    1817         //do explicitly to avoid data folder problems, redundant, but it must work without fail 
    1818         Make/O/N=9 root:myGlobals:Attenuators:ng3att0 
    1819         Make/O/N=9 root:myGlobals:Attenuators:ng3att1 
    1820         Make/O/N=9 root:myGlobals:Attenuators:ng3att2 
    1821         Make/O/N=9 root:myGlobals:Attenuators:ng3att3 
    1822         Make/O/N=9 root:myGlobals:Attenuators:ng3att4 
    1823         Make/O/N=9 root:myGlobals:Attenuators:ng3att5 
    1824         Make/O/N=9 root:myGlobals:Attenuators:ng3att6 
    1825         Make/O/N=9 root:myGlobals:Attenuators:ng3att7 
    1826         Make/O/N=9 root:myGlobals:Attenuators:ng3att8 
    1827         Make/O/N=9 root:myGlobals:Attenuators:ng3att9 
    1828         Make/O/N=9 root:myGlobals:Attenuators:ng3att10 
    1829          
    1830         //each wave has 8 elements, the transmission of att# at the wavelengths  
    1831         //lambda = 5,6,7,8,10,12,14,17 
    1832         Make/O/N=9 root:myGlobals:Attenuators:ng3lambda={5,6,7,8,10,12,14,17,20} 
    1833         root:myGlobals:Attenuators:ng3att0 = {1, 1, 1, 1, 1, 1, 1, 1,1 } 
    1834         root:myGlobals:Attenuators:ng3att1 = {0.421, 0.394, 0.371, 0.349, 0.316, 0.293, 0.274, 0.245,0.220} 
    1835         root:myGlobals:Attenuators:ng3att2 = {0.187, 0.164, 0.145, 0.130, 0.106, 0.0916, 0.0808, 0.0651,0.0531} 
    1836         root:myGlobals:Attenuators:ng3att3 = {0.0777, 0.0636, 0.0534, 0.0446, 0.0330, 0.0262, 0.0217, 0.0157 ,0.0116} 
    1837         root:myGlobals:Attenuators:ng3att4 = {0.0328, 0.0252, 0.0195, 0.0156, 0.0104, 7.68e-3, 5.98e-3, 3.91e-3,0.00262} 
    1838         root:myGlobals:Attenuators:ng3att5 = {0.0139, 9.94e-3, 7.34e-3, 5.44e-3, 3.29e-3, 2.25e-3, 1.66e-3, 9.95e-4, 6.12e-4} 
    1839         root:myGlobals:Attenuators:ng3att6 = {5.95e-3, 3.97e-3, 2.77e-3, 1.95e-3, 1.06e-3, 6.81e-4, 4.71e-4, 2.59e-4 , 1.45e-4} 
    1840         root:myGlobals:Attenuators:ng3att7 = {1.07e-3, 6.24e-4, 3.90e-4, 2.44e-4, 1.14e-4, 6.55e-5, 4.10e-5, 1.64e-5 , 7.26e-6} 
    1841         root:myGlobals:Attenuators:ng3att8 = {1.90e-4, 9.84e-5, 5.60e-5, 3.25e-5, 1.55e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 
    1842         root:myGlobals:Attenuators:ng3att9 = {3.61e-5, 1.74e-5, 9.90e-6, 6.45e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 
    1843         root:myGlobals:Attenuators:ng3att10 = {7.60e-6, 3.99e-6, 2.96e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9 , 8.60e-10} 
    1844  
    1845 End 
    1846  
    1847 Proc MakeNG7AttenTable() 
    1848  
    1849         NewDataFolder/O root:myGlobals:Attenuators 
    1850          
    1851         Make/O/N=9 root:myGlobals:Attenuators:ng7att0 
    1852         Make/O/N=9 root:myGlobals:Attenuators:ng7att1 
    1853         Make/O/N=9 root:myGlobals:Attenuators:ng7att2 
    1854         Make/O/N=9 root:myGlobals:Attenuators:ng7att3 
    1855         Make/O/N=9 root:myGlobals:Attenuators:ng7att4 
    1856         Make/O/N=9 root:myGlobals:Attenuators:ng7att5 
    1857         Make/O/N=9 root:myGlobals:Attenuators:ng7att6 
    1858         Make/O/N=9 root:myGlobals:Attenuators:ng7att7 
    1859         Make/O/N=9 root:myGlobals:Attenuators:ng7att8 
    1860         Make/O/N=9 root:myGlobals:Attenuators:ng7att9 
    1861         Make/O/N=9 root:myGlobals:Attenuators:ng7att10 
    1862          
    1863         //each wave has 8 elements, the transmission of att# at the wavelengths  
    1864         //lambda = 5,6,7,8,10,12,14,17 
    1865         Make/O/N=9 root:myGlobals:Attenuators:ng7lambda={5,6,7,8,10,12,14,17,20} 
    1866         root:myGlobals:Attenuators:ng7att0 = {1, 1, 1, 1, 1, 1, 1, 1 ,1} 
    1867         root:myGlobals:Attenuators:ng7att1 = {0.418, 0.393, 0.369, 0.347, 0.313, 0.291, 0.271, 0.244, 0.219 } 
    1868         root:myGlobals:Attenuators:ng7att2 = {0.189, 0.167, 0.148, 0.132, 0.109, 0.0945, 0.0830, 0.0681, 0.0560} 
    1869         root:myGlobals:Attenuators:ng7att3 = {0.0784, 0.0651, 0.0541, 0.0456, 0.0340, 0.0273, 0.0223, 0.0164 , 0.0121} 
    1870         root:myGlobals:Attenuators:ng7att4 = {0.0328, 0.0256, 0.0200, 0.0159, 0.0107, 7.98e-3, 6.14e-3, 4.09e-3 , 0.00274} 
    1871         root:myGlobals:Attenuators:ng7att5 = {0.0139, 0.0101, 7.43e-3, 5.58e-3, 3.42e-3, 2.36e-3, 1.70e-3, 1.03e-3 , 6.27e-4} 
    1872         root:myGlobals:Attenuators:ng7att6 = {5.90e-3, 4.07e-3, 2.79e-3, 1.99e-3, 1.11e-3, 7.13e-4, 4.91e-4, 2.59e-4 , 1.42e-4} 
    1873         root:myGlobals:Attenuators:ng7att7 = {1.04e-3, 6.37e-4, 3.85e-4, 2.46e-4, 1.16e-4, 6.86e-5, 4.10e-5, 1.64e-5 ,7.02e-6} 
    1874         root:myGlobals:Attenuators:ng7att8 = {1.90e-4, 1.03e-4, 5.71e-5, 3.44e-5, 1.65e-5, 6.60e-6, 3.42e-6, 1.04e-6 , 3.48e-7} 
    1875         root:myGlobals:Attenuators:ng7att9 = {3.58e-5, 1.87e-5, 1.05e-5, 7.00e-6, 2.35e-6, 6.35e-7, 2.86e-7, 6.61e-8 , 1.73e-8} 
    1876         root:myGlobals:Attenuators:ng7att10 = {7.76e-6, 4.56e-6, 3.25e-6, 2.03e-6, 3.34e-7, 6.11e-8, 2.39e-8, 4.19e-9, 8.60e-10} 
    1877          
    1878 End 
    1879  
    1880 //returns the transmission of the attenuator (at NG3) given the attenuator number 
    1881 //which must be an integer(to select the wave) and given the wavelength. 
    1882 //the wavelength may be any value between 5 and 20 (A), and is interpolated 
    1883 //between calibrated wavelengths for a given attenuator 
    1884 Function LookupAttenNG3(lambda,attenNo) 
    1885         Variable lambda, attenNo 
    1886          
    1887         Variable trans 
    1888         String attStr="root:myGlobals:Attenuators:ng3att"+num2str(trunc(attenNo)) 
    1889         String lamStr = "root:myGlobals:Attenuators:ng3lambda" 
    1890          
    1891         if(attenNo == 0) 
    1892                 return (1)              //no attenuation, return trans == 1 
    1893         endif 
    1894          
    1895         if( (lambda < 5) || (lambda > 20 ) ) 
    1896                 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 
    1897         Endif 
    1898          
    1899         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1900                 Execute "MakeNG3AttenTable()" 
    1901         Endif 
    1902         //just in case creating the tables fails.... 
    1903         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1904                 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 
    1905         Endif 
    1906          
    1907         //lookup the value by interpolating the wavelength 
    1908         //the attenuator must always be an integer 
    1909         Wave att = $attStr 
    1910         Wave lam = $lamstr 
    1911         trans = interp(lambda,lam,att) 
    1912          
    1913 //      Print "trans = ",trans 
    1914          
    1915         return trans 
    1916 End 
    1917  
    1918 //returns the transmission of the attenuator (at NG7) given the attenuator number 
    1919 //which must be an integer(to select the wave) and given the wavelength. 
    1920 //the wavelength may be any value between 5 and 20 (A), and is interpolated 
    1921 //between calibrated wavelengths for a given attenuator 
    1922 // 
    1923 // this set of tables is also used for NG5 (NG1) SANS instrument - as the attenuator has yet to be calibrated 
    1924 Function LookupAttenNG7(lambda,attenNo) 
    1925         Variable lambda, attenNo 
    1926          
    1927         Variable trans 
    1928         String attStr="root:myGlobals:Attenuators:ng7att"+num2str(trunc(attenNo)) 
    1929         String lamStr = "root:myGlobals:Attenuators:ng7lambda" 
    1930          
    1931         if(attenNo == 0) 
    1932                 return (1)              //no attenuation, return trans == 1 
    1933         endif 
    1934          
    1935         if( (lambda < 5) || (lambda > 20 ) ) 
    1936                 Abort "Wavelength out of calibration range (5,20). You must manually enter the absolute parameters" 
    1937         Endif 
    1938          
    1939         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1940                 Execute "MakeNG7AttenTable()" 
    1941         Endif 
    1942         //just in case creating the tables fails.... 
    1943         if(!(WaveExists($attStr)) || !(WaveExists($lamStr)) ) 
    1944                 Abort "Attenuator lookup waves could not be found. You must manually enter the absolute parameters" 
    1945         Endif 
    1946          
    1947         //lookup the value by interpolating the wavelength 
    1948         //the attenuator must always be an integer 
    1949         Wave att = $attStr 
    1950         Wave lam = $lamstr 
    1951         trans = interp(lambda,lam,att) 
    1952          
    1953         //Print "trans = ",trans 
    1954          
    1955         return trans 
    1956  
    1957 End 
    1958  
    1959 //returns the proper attenuation factor based on the instrument (NG3, NG5, or NG7) 
    1960 //NG5 values are taken from the NG7 tables (there is very little difference in the 
    1961 //values, and NG5 attenuators have not been calibrated (as of 8/01) 
    1962 //filestr as passed is textread[3], the default directory 
    1963 Function AttenuationFactor(fileStr,lam,attenNo) 
    1964         String fileStr 
    1965         Variable lam,attenNo 
    1966          
    1967         Variable attenFactor=1,loc 
    1968         String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) 
    1969          
    1970         strswitch(instr) 
    1971                 case "NG3": 
    1972                         attenFactor = LookupAttenNG3(lam,attenNo) 
    1973                         break 
    1974                 case "NG5": 
    1975                         //using NG7 lookup Table 
    1976                         attenFactor = LookupAttenNG7(lam,attenNo) 
    1977                         break 
    1978                 case "NG7": 
    1979                         attenFactor = LookupAttenNG7(lam,attenNo) 
    1980                         break 
    1981                 default:                                                         
    1982                         //return error? 
    1983                         attenFactor=1 
    1984         endswitch 
    1985 //      print "instr, lambda, attenNo,attenFactor = ",instr,lam,attenNo,attenFactor 
    1986         return(attenFactor) 
    1987 End 
     1809 
    19881810 
    19891811//******************* 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/VAXFileUtils.ipf

    r47 r69  
    33#pragma IgorVersion=4.0 
    44 
    5 //************************** 
    6 // Vers. 1.2 092101 
    7 // 
    8 //this file is a collection of uilities for processing vax filenames 
    9 //and processing lists (especially for display in popup menus) 
    10 // 
    11 //required to correctly account for VAX supplied version numbers, which 
    12 //may or may not be removed by the ftp utility 
    13 // 
    14 // - parses lists of run numbers into real filenames 
    15 // - selects proper detector constants 
    16 // 
    17 //************************** 
    18  
    19  
    20 //given a filename of a SANS data filename of the form 
    21 //TTTTTnnn.SAn_TTT_Txxx 
    22 //returns the run number "nnn" as a number 
    23 //returns -1 as an invalid file number 
    24 Function GetRunNumFromFile(item) 
    25         String item 
    26         Variable invalid = -1   //negative numbers are invalid 
    27         Variable num=-1 
    28          
    29         //find the "dot" 
    30         String runStr="" 
    31         Variable pos = strsearch(item,".",0) 
    32         if(pos == -1) 
    33                 //"dot" not found 
    34                 return (invalid) 
    35         else 
    36                 //found, get the three characters preceeding it 
    37                 if (pos <=2) 
    38                         //not enough characters 
    39                         return (invalid) 
    40                 else 
    41                         runStr = item[pos-3,pos-1] 
    42                         //convert to a number 
    43                         num = str2num(runStr) 
    44                         //if valid, return it 
    45                         if (num == NaN) 
    46                                 //3 characters were not a number 
    47                                 return (invalid) 
    48                         else 
    49                                 //run was OK 
    50                                 return (num) 
    51                         Endif 
    52                 Endif 
    53         Endif 
    54 End 
    55  
    56 //given a filename of a SANS data filename of the form 
    57 //TTTTTnnn.SAn_TTT_Txxx 
    58 //returns the run number "nnn" as a STRING of THREE characters 
    59 //returns "ABC" as an invalid file number 
    60 Function/S GetRunNumStrFromFile(item) 
    61         String item 
    62         String invalid = "ABC"  //"ABC" is not a valid run number, since it's text 
    63         Variable num=-1 
    64          
    65         //find the "dot" 
    66         String runStr="" 
    67         Variable pos = strsearch(item,".",0) 
    68         if(pos == -1) 
    69                 //"dot" not found 
    70                 return (invalid) 
    71         else 
    72                 //found, get the three characters preceeding it 
    73                 if (pos <=2) 
    74                         //not enough characters 
    75                         return (invalid) 
    76                 else 
    77                         runStr = item[pos-3,pos-1] 
    78                         return (runStr) 
    79                 Endif 
    80         Endif 
    81 End 
    82  
    83 //returns a string containing the full path and file to the file containing the  
    84 //run number "num". The null string is returned if no valid file can be found 
    85 //the path "catPathName" used and is hard-wired, will abort if this path does not exist 
    86 //the file returned will be a RAW SANS data file, other types of files are  
    87 //filtered out. 
    88 Function/S FindFileFromRunNumber(num) 
    89         Variable num 
    90          
    91         String fullName="",partialName="",item="" 
    92         //get list of raw data files in folder that match "num" (add leading zeros) 
    93         if( (num>999) || (num<=0) ) 
    94                 //Print "error in  FindFileFromRunNumber(num), file number too large or too small" 
    95                 Return ("") 
    96         Endif 
    97         //make a three character string of the run number 
    98         String numStr="" 
    99         if(num<10) 
    100                 numStr = "00"+num2str(num) 
    101         else 
    102                 if(num<100) 
    103                         numStr = "0"+num2str(num) 
    104                 else 
    105                         numStr = num2str(num) 
    106                 Endif 
    107         Endif 
    108         //Print "numstr = ",numstr 
    109          
    110         //make sure that path exists 
    111         PathInfo catPathName 
    112         String path = S_path 
    113         if (V_flag == 0) 
    114                 Abort "folder path does not exist - use Pick Path button" 
    115         Endif 
    116         String list="",newList="",testStr="" 
    117          
    118         list = IndexedFile(catPathName,-1,"????")       //get all files in folder 
    119         //find (the) one with the number in the run # location in the name 
    120         Variable numItems,ii,runFound,isRAW 
    121         numItems = ItemsInList(list,";")                //get the new number of items in the list 
    122         ii=0 
    123         do 
    124                 //parse through the list in this order: 
    125                 // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy" 
    126                 // 2 - exclude by isRaw? (to minimize disk access) 
    127                 item = StringFromList(ii, list  ,";" ) 
    128                 if(strlen(item) != 0) 
    129                         //find the run number, if it exists as a three character string 
    130                         testStr = GetRunNumStrFromFile(item) 
    131                         runFound= cmpstr(numStr,testStr)        //compare the three character strings, 0 if equal 
    132                         if(runFound == 0) 
    133                                 //the run Number was found 
    134                                 //build valid filename 
    135                                 partialName = FindValidFileName(item) 
    136                                 if(strlen(partialName) != 0)            //non-null return from FindValidFileName() 
    137                                         fullName = path + partialName 
    138                                         //check if RAW, if so,this must be the file! 
    139                                         isRAW = CheckIfRawData(fullName) 
    140                                         if(isRaw) 
    141                                                 //stop here 
    142                                                 return(fullname) 
    143                                         Endif 
    144                                 Endif 
    145                         Endif 
    146                 Endif 
    147                 ii+=1 
    148         while(ii<numItems)              //process all items in list 
    149         Return ("")     //null return if file not found in list 
    150 End 
    151  
    152 //function to test a binary file to see if it is a RAW binary SANS file 
    153 //first checks the total bytes in the file (which for raw data is 33316 bytes) 
    154 //**note that the "DIV" file will also show up as a raw file by the run field 
    155 //should be listed in CAT/SHORT and in patch windows 
    156 // 
    157 //Function then checks the file fname (full path:file) for "RAW" run.type field 
    158 //if not found, the data is not raw data and zero is returned 
    159 Function CheckIfRawData(fname) 
    160         String fname 
    161          
    162         Variable refnum,totalBytes 
    163         String testStr="" 
    164          
    165         Open/R/T="????TEXT" refNum as fname 
    166         //get the total number of bytes in the file, to avoid moving past EOF 
    167         FStatus refNum 
    168         totalBytes = V_logEOF 
    169         //Print totalBytes 
    170         if(totalBytes!=33316) 
    171                 //can't possibly be a raw data file 
    172                 Close refnum 
    173                 return(0)               //not a raw SANS file 
    174         Endif 
    175         FSetPos refNum,75 
    176         FReadLine/N=3 refNum,testStr 
    177         Close refNum 
    178          
    179         if(cmpstr(testStr,"RAW")==0) 
    180                 //true, is raw data file 
    181                 Return(1) 
    182         else 
    183                 //some other file 
    184                 Return(0) 
    185         Endif 
    186 End 
    187  
    188 //function to remove all spaces from names when searching for filenames 
    189 //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) 
    190 //but the text field in the header WILL, if less than 3 characters were used for the  
    191 //user's initials, and can have leading spaces if prefix was less than 5 characters 
    192 // 
    193 //returns a string identical to the original string, except with the interior spaces removed 
    194 // 
    195 Function/S RemoveAllSpaces(str) 
    196         String str 
    197          
    198         String tempstr = str 
    199         Variable ii,spc,len             //should never be more than 2 or 3 trailing spaces in a filename 
    200         ii=0 
    201         do 
    202                 len = strlen(tempStr) 
    203                 spc = strsearch(tempStr," ",0)          //is the last character a space? 
    204                 if (spc == -1) 
    205                         break           //no more spaces found, get out 
    206                 endif 
    207                 str = tempstr 
    208                 tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string 
    209         While(1)        //should never be more than 2 or 3 
    210          
    211         If(strlen(tempStr) < 1) 
    212                 tempStr = ""            //be sure to return a null string if problem found 
    213         Endif 
    214          
    215         //Print strlen(tempstr) 
    216          
    217         Return(tempStr) 
    218                  
    219 End 
    220  
    221  
    222 //Function attempts to find valid filename from partial name that has been stripped of 
    223 //the VAX version number. The partial name is tried first 
    224 //*** the PATH is hard-wired to catPathName (which is assumed to exist) 
    225 //version numers up to ;10 are tried 
    226 //only the "name;vers" is returned. the path is not prepended, hence the return string 
    227 //is not a complete specification of the file 
    228 // 
    229 // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary 
    230 // since from marquee, the filename field (textread[0]) must be used, and can be a mix of 
    231 // upper/lowercase letters, while the filename on the server (should) be all caps 
    232 // now makes repeated calls to ValidFileString() 
    233 // 
    234 Function/S FindValidFilename(partialName) 
    235         String PartialName 
    236          
    237         String retStr="" 
    238          
    239         //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 
    240         retStr = ValidFileString(partialName) 
    241         if(cmpstr(retStr,"") !=0) 
    242                 //non-null return 
    243                 return(retStr) 
    244         Endif 
    245          
    246         //if the partial name is derived from the file header, there can be spaces at the beginning 
    247         //or in the middle of the filename - depending on the prefix and initials used 
    248         // 
    249         //remove any leading spaces from the name before starting 
    250         partialName = RemoveAllSpaces(partialName) 
    251          
    252         //try name with no spaces 
    253         retStr = ValidFileString(partialName) 
    254         if(cmpstr(retStr,"") !=0) 
    255                 //non-null return 
    256                 return(retStr) 
    257         Endif 
    258          
    259         //try all UPPERCASE 
    260         partialName = UpperStr(partialName) 
    261         retStr = ValidFileString(partialName) 
    262         if(cmpstr(retStr,"") !=0) 
    263                 //non-null return 
    264                 return(retStr) 
    265         Endif 
    266          
    267         //try all lowercase (ret null if failure) 
    268         partialName = LowerStr(partialName) 
    269         retStr = ValidFileString(partialName) 
    270         if(cmpstr(retStr,"") !=0) 
    271                 //non-null return 
    272                 return(retStr) 
    273         else 
    274                 return(retStr) 
    275         Endif 
    276 End 
    277  
    278 //Function attempts to find valid filename from partial name that has been stripped of 
    279 //the VAX version number. The partial name is tried first 
    280 //*** the PATH is hard-wired to catPathName (which is assumed to exist) 
    281 //version numers up to ;10 are tried 
    282 //only the "name;vers" is returned. the path is not prepended, hence the return string 
    283 //is not a complete specification of the file 
    284 // 
    285 Function/S ValidFileString(partialName) 
    286         String partialName 
    287          
    288         String tempName = "",msg="" 
    289         Variable ii,refnum 
    290          
    291         ii=0 
    292         do 
    293                 if(ii==0) 
    294                         //first pass, try the partialName 
    295                         tempName = partialName 
    296                         Open/Z/R/T="????TEXT"/P=catPathName refnum tempName     //Does open file (/Z flag) 
    297                         if(V_flag == 0) 
    298                                 //file exists 
    299                                 Close refnum            //YES needed,  
    300                                 break 
    301                         endif 
    302                 else 
    303                         tempName = partialName + ";" + num2str(ii) 
    304                         Open/Z/R/T="????TEXT"/P=catPathName refnum tempName 
    305                         if(V_flag == 0) 
    306                                 //file exists 
    307                                 Close refnum 
    308                                 break 
    309                         endif 
    310                 Endif 
    311                 ii+=1 
    312                 //print "ii=",ii 
    313         while(ii<11) 
    314         //go get the selected bits of information, using tempName, which exists 
    315         if(ii>=11) 
    316                 //msg = partialName + " not found. is version number > 11?" 
    317                 //DoAlert 0, msg 
    318                 //PathInfo catPathName 
    319                 //Print S_Path 
    320                 Return ("")             //use null string as error condition 
    321         Endif 
    322          
    323         Return (tempName) 
    324 End 
    3255 
    3266 
    3277 
    328 //the following is a WaveMetrics procedure from <StrMatchList> 
    329 // MatchList(matchStr,list,sep) 
    330 // Returns the items of the list whose items match matchStr 
    331 // The lists are separated by the sep character, usually ";" 
    332 // 
    333 // matchStr may be something like "abc", in which case it is identical to CmpStr 
    334 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc", 
    335 //      "*abc" to match anything ending with "abc". 
    336 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of 
    337 //      the pattern. 
    338 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed. 
    339 // 
    340 Function/S MyMatchList(matchStr,list,sep) 
    341         String matchStr,list,sep 
    342         String item,outList="" 
    343         Variable n=strlen(list) 
    344         Variable en,st=0 
    345         do 
    346                 en= strsearch(list,sep,st) 
    347                 if( en < 0 ) 
    348                         if( st < n-1 ) 
    349                                 en= n   // no trailing separator 
    350                                 sep=""  // don't put sep in output, either 
    351                         else 
    352                                 break   // no more items in list 
    353                         endif 
    354                 endif 
    355                 item=list[st,en-1] 
    356                 if( MyStrMatch(matchStr,item) == 0 ) 
    357                         outlist += item+sep 
    358                 Endif 
    359                 st=en+1  
    360         while (st < n ) // exit is by break, above 
    361         return outlist 
    362 End 
    363  
    364 //the following is a WaveMetrics procedure from <StrMatchList> 
    365 // StrMatch(matchStr,str) 
    366 // Returns 0 if the pattern in matchStr matches str, else it returns 1 
    367 // 
    368 // matchStr may be something like "abc", in which case it is identical to CmpStr 
    369 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc", 
    370 //      "*abc" to match anything ending with "abc". 
    371 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of 
    372 //      the pattern. 
    373 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed. 
    374 // 
    375 Function MyStrMatch(matchStr,str) 
    376         String matchStr,str 
    377         Variable match = 1              // 0 means match 
    378         Variable invert= strsearch(matchStr,"!",0) == 0 
    379         if( invert ) 
    380                 matchStr[0,0]=""        // remove the "!" 
    381         endif 
    382         Variable st=0,en=strlen(str)-1 
    383         Variable starPos= strsearch(matchStr,"*",0) 
    384         if( starPos >= 0 )      // have a star 
    385                 if( starPos == 0 )      // at start 
    386                         matchStr[0,0]=""                                // remove star at start 
    387                 else                                    // at end 
    388                         matchStr[starPos,999999]=""     // remove star and rest of (ignored, illegal) pattern 
    389                 endif 
    390                 Variable len=strlen(matchStr) 
    391                 if( len > 0 ) 
    392                         if(starPos == 0)        // star at start, match must be at end 
    393                                 st=en-len+1 
    394                         else 
    395                                 en=len-1        // star at end, match at start 
    396                         endif 
    397                 else 
    398                         str=""  // so that "*" matches anything 
    399                 endif 
    400         endif 
    401         match= !CmpStr(matchStr,str[st,en])==0  // 1 or 0 
    402         if( invert ) 
    403                 match= 1-match 
    404         endif 
    405         return match 
    406 End 
    407  
    408  
    409 //returns a string containing filename (WITHOUT the ;vers) 
    410 //the input string is a full path to the file (Mac-style, still works on Win in IGOR) 
    411 //with the folders separated by colons 
    412 Function/S GetFileNameFromPathNoSemi(fullPath) 
    413         String fullPath 
    414          
    415         Variable offset1,offset2 
    416         String filename="" 
    417         //String PartialPath 
    418         offset1 = 0 
    419         do 
    420                 offset2 = StrSearch(fullPath, ":", offset1) 
    421                 if (offset2 == -1)                              // no more colons ? 
    422                         fileName = FullPath[offset1,strlen(FullPath) ] 
    423                         //PartialPath = FullPath[0, offset1-1] 
    424                         break 
    425                 endif 
    426                 offset1 = offset2+1 
    427         while (1) 
    428          
    429         //remove version number from name, if it's there - format should be: filename;N 
    430         filename =  StringFromList(0,filename,";")              //returns null if error 
    431          
    432         Return filename 
    433 End 
    434  
    435 //returns a string containing filename (INCLUDING the ;vers) 
    436 //the input string is a full path to the file (Mac-style, still works on Win in IGOR) 
    437 //with the folders separated by colons 
    438 Function/S GetFileNameFromPathKeepSemi(fullPath) 
    439         String fullPath 
    440          
    441         Variable offset1,offset2 
    442         String filename 
    443         //String PartialPath 
    444         offset1 = 0 
    445         do 
    446                 offset2 = StrSearch(fullPath, ":", offset1) 
    447                 if (offset2 == -1)                              // no more colons ? 
    448                         fileName = FullPath[offset1,strlen(FullPath) ] 
    449                         //PartialPath = FullPath[0, offset1-1] 
    450                         break 
    451                 endif 
    452                 offset1 = offset2+1 
    453         while (1) 
    454          
    455         //keep version number from name, if it's there - format should be: filename;N 
    456          
    457         Return filename 
    458 End 
    459  
    460 //given the full path and filename (fullPath), strips the data path 
    461 //(Mac-style, separated by colons) and returns this path 
    462 //this partial path is the same string that would be returned from PathInfo, for example 
    463 Function/S GetPathStrFromfullName(fullPath) 
    464         String fullPath 
    465          
    466         Variable offset1,offset2 
    467         //String filename 
    468         String PartialPath 
    469         offset1 = 0 
    470         do 
    471                 offset2 = StrSearch(fullPath, ":", offset1) 
    472                 if (offset2 == -1)                              // no more colons ? 
    473                         //fileName = FullPath[offset1,strlen(FullPath) ] 
    474                         PartialPath = FullPath[0, offset1-1] 
    475                         break 
    476                 endif 
    477                 offset1 = offset2+1 
    478         while (1) 
    479          
    480         Return PartialPath 
    481 End 
    482  
    483 //given the VAX filename, pull off the first 8 characters to make a valid 
    484 //file string that can be used for naming averaged 1-d files 
    485 Function/S GetNameFromHeader(fullName) 
    486         String fullName 
    487         String temp, newName = "" 
    488         Variable spc,ii=0 
    489          
    490         //filename is 20 characters NNNNNxxx.SAn_NNN_NNN 
    491         //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning 
    492         //NNNNN was entered as less than 5 characters 
    493         //returns a null string if no name can be found 
    494         do 
    495                 temp = fullname[ii,7]           //characters ii,7 of the name 
    496                 spc = strsearch(temp," ",0) 
    497                 if (spc == -1) 
    498                         break           //no more spaces found 
    499                 endif 
    500                 ii+=1 
    501         While(ii<8) 
    502          
    503         If(strlen(temp) < 1) 
    504                 newName = ""            //be sure to return a null string if problem found 
    505         else 
    506                 newName = temp 
    507         Endif 
    508          
    509         Return(newName) 
    510 End 
    511  
    512 //list (input) is a list, typically returned from IndexedFile() 
    513 //which is semicolon-delimited, and may contain filesnames from the VAX 
    514 //that contain version numbers, where the version number appears as a separate list item 
    515 //(and also as a non-existent file) 
    516 //these numbers must be purged from the list, especially for display in a popup 
    517 //or list processing of filenames 
    518 //the function returns the list, cleaned of version numbers (up to 11) 
    519 //raw data files will typically never have a version number other than 1. 
    520 Function/S RemoveVersNumsFromList(list) 
    521         String list 
    522          
    523         //get rid of version numbers first (up to 11) 
    524         Variable ii,num 
    525         String item  
    526         num = ItemsInList(list,";") 
    527         ii=1 
    528         do 
    529                 item = num2str(ii) 
    530                 list = RemoveFromList(item, list ,";" ) 
    531                 ii+=1 
    532         while(ii<12) 
    533          
    534         return (list) 
    535 End 
    536  
    537 //input is a list of run numbers, and output is a list of filenames (not the full path) 
    538 //*** input list must be COMMA delimited*** 
    539 //output is equivalent to selecting from the CAT table 
    540 //if some or all of the list items are valid filenames, keep them... 
    541 //if an error is encountered, notify of the offending element and return the null list 
    542 // 
    543 //output is COMMA delimited 
    544 // 
    545 // this routine is expecting that the "ask", "none" special cases are handled elsewhere 
    546 //and not passed here 
    547 Function/S ParseRunNumberList(list) 
    548         String list 
    549          
    550         String newList="",item="",tempStr="" 
    551         Variable num,ii,runNum 
    552          
    553         //expand number ranges, if any 
    554         list = ExpandNumRanges(list) 
    555          
    556         num=itemsinlist(list,",") 
    557          
    558         for(ii=0;ii<num;ii+=1) 
    559                 //get the item 
    560                 item = StringFromList(ii,list,",") 
    561                 //is it already a valid filename? 
    562                 tempStr=FindValidFilename(item) //returns filename if good, null if error 
    563                 if(strlen(tempstr)!=0) 
    564                         //valid name, add to list 
    565                         //Print "it's a file" 
    566                         newList += tempStr + "," 
    567                 else 
    568                         //not a valid name 
    569                         //is it a number? 
    570                         runNum=str2num(item) 
    571                         //print runnum 
    572                         if(numtype(runNum) != 0) 
    573                                 //not a number -  maybe an error                         
    574                                 DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." 
    575                                 return("") 
    576                         else 
    577                                 //a run number or an error 
    578                                 tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) ) 
    579                                 if(strlen(tempstr)==0) 
    580                                         //file not found, error 
    581                                         DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." 
    582                                         return("") 
    583                                 else 
    584                                         newList += tempStr + "," 
    585                                 endif 
    586                         endif 
    587                 endif 
    588         endfor          //loop over all items in list 
    589          
    590         return(newList) 
    591 End 
    592  
    593 //takes a comma delimited list that MAY contain number range, and 
    594 //expands any range of run numbers into a comma-delimited list... 
    595 //and returns the new list - if not a range, return unchanged 
    596 Function/S ExpandNumRanges(list) 
    597         String list 
    598          
    599         String newList="",dash="-",item,str 
    600         Variable num,ii,hasDash 
    601          
    602         num=itemsinlist(list,",") 
    603 //      print num 
    604         for(ii=0;ii<num;ii+=1) 
    605                 //get the item 
    606                 item = StringFromList(ii,list,",") 
    607                 //does it contain a dash? 
    608                 hasDash = strsearch(item,dash,0)                //-1 if no dash found 
    609                 if(hasDash == -1) 
    610                         //not a range, keep it in the list 
    611                         newList += item + "," 
    612                 else 
    613                         //has a dash (so it's a range), expand (or add null) 
    614                         newList += ListFromDash(item)            
    615                 endif 
    616         endfor 
    617          
    618         return newList 
    619 End 
    620  
    621 //be sure to add a trailing comma to the return string... 
    622 Function/S ListFromDash(item) 
    623         String item 
    624          
    625         String numList="",loStr="",hiStr="" 
    626         Variable lo,hi,ii 
    627          
    628         loStr=StringFromList(0,item,"-")        //treat the range as a list 
    629         hiStr=StringFromList(1,item,"-") 
    630         lo=str2num(loStr) 
    631         hi=str2num(hiStr) 
    632         if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) 
    633                 numList="" 
    634                 return numList 
    635         endif 
    636         for(ii=lo;ii<=hi;ii+=1) 
    637                 numList += num2str(ii) + "," 
    638         endfor 
    639          
    640         Return numList 
    641 End 
    642  
    643  
    644 //**************** 
    645 //utilities for handling binary data - prompting for files or paths, 
    646 //moving data from one folder to another (within IGOR) 
    647 //and converting data to log or linear scale 
    648  
    649  
    650 //prompts user to choose the local folder that contains the SANS Data 
    651 //only one folder can be used, and its path is catPathName (and is a NAME, not a string) 
    652 //this will overwrite the path selection 
    653 //returns 1 if no path selected as error condition, or if user cancelled 
    654 Function PickPath() 
    655          
    656         //set the global string to the selected pathname 
    657         NewPath/O/M="pick the SANS data folder" catPathName 
    658         if(V_Flag != 0) 
    659                 return(1)               //user cancelled 
    660         endif 
    661          
    662         PathInfo/S catPathName 
    663         String dum = S_path 
    664         String alertStr = "" 
    665         alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood" 
    666         //alertStr += "  Please see the manual for details." 
    667         if (V_flag == 0) 
    668                 //path does not exist - no folder selected 
    669                 String/G root:myGlobals:gCatPathStr = "no folder selected" 
    670                 return(1) 
    671         else 
    672                 //set the global to the path (as a string) 
    673                 // need 4 \ since it is the escape character 
    674                 if(cmpstr("\\\\",dum[0,1])==0)  //Windoze user going through network neighborhood 
    675                         DoAlert 0,alertStr 
    676                         KillPath catPathName 
    677                         return(1) 
    678                 endif 
    679                 String/G root:myGlobals:gCatPathStr = dum 
    680                 // these are now set in theire respective procedures, since the folders don't exist yet! 
    681 //              String/G root:myGlobals:Patch:gCatPathStr = dum //and the global used by Patch and Trans 
    682 //              String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum       //and the global used by Patch and Trans 
    683                 return(0)               //no error 
    684         endif 
    685 End 
    686  
    687 //a utility function that prompts the user for a file (of any type) 
    688 //and returns the full path:name;vers string required to open the file 
    689 //the file is NOT opened by this routine (/D flag) 
    690 //a null string is returned if no file is selected 
    691 //"msgStr" is the message displayed in the dialog, informing the user what 
    692 //file is desired 
    693 // 
    694 Function/S PromptForPath(msgStr) 
    695         String msgStr 
    696         String fullPath 
    697         Variable refnum 
    698          
    699         //this just asks for the filename, doesn't open the file 
    700         Open/D/R/T="????"/M=(msgStr) refNum 
    701         fullPath = S_FileName           //fname is the full path 
    702         //      Print refnum,fullPath 
    703          
    704         //null string is returned in S_FileName if user cancelled, and is passed back to calling  function 
    705         Return(fullPath) 
    706 End 
    707  
    708  
    709 //returns a string containg the transmision stored in the file that is  
    710 //currently in the "type" folder (not from the binary header) 
    711 //returns "none" if the value (in RealsRead) cannot be found 
    712 // 
    713 Function/S GetTrans(type) 
    714         String type 
    715          
    716         String name="root:"+type+":realsread" 
    717         WAVE reals = $name 
    718         if(waveExists(reals)) 
    719                 return(num2str(reals[4])) 
    720         else 
    721                 return("none") 
    722         endif    
    723 End 
    724  
    725 //returns a string containg the sample thickness stored in the file that is  
    726 //currently in the "type" folder (not from the binary header) 
    727 //returns "none" if the value (in RealsRead) cannot be found 
    728 // 
    729 Function/S GetThick(type) 
    730         String type 
    731          
    732         String name="root:"+type+":realsread" 
    733         WAVE reals = $name 
    734         if(waveExists(reals)) 
    735                 return(num2str(reals[5])) 
    736         else 
    737                 return("none") 
    738         endif    
    739 End 
    740  
    741 //procedure is not called from anywhere, for debugging purposes only 
    742 //not for gerneral users, since it Kills data folders, requiring 
    743 //re-initialization of the experiment 
    744 // 
    745 Proc ClearWorkFolders() 
    746  
    747         //not foolproof - will generage an error if any wavs, etc.. are in use. 
    748         KillDataFolder root:RAW 
    749         KillDataFolder root:SAM 
    750         KillDataFolder root:EMP 
    751         KillDataFolder root:BGD 
    752         KillDataFolder root:COR 
    753         KillDataFolder root:DIV 
    754         KillDataFolder root:MSK 
    755         KillDataFolder root:ABS 
    756         KillDataFolder root:CAL 
    757         SetDataFolder root: 
    758          
    759 End 
    760  
    761 //not used - but potentially very useful for ensuring that old 
    762 // data in work folders is not accidentally being used 
    763 // 
    764 Function ClearWorkFolder(type) 
    765         String type 
    766          
    767         SetDataFolder $("root:"+type) 
    768         KillWaves/A/Z 
    769         KillStrings/A/Z 
    770         KillVariables/A/Z 
    771          
    772         SetDataFolder root: 
    773 End 
    774  
    775  
    776 //procedure is not called from anywhere, for debugging purposes only 
    777 //not for gerneral users, but could be useful in reducon clutter 
    778 // 
    779 Proc ClearRootFolder() 
    780  
    781         DoAlert 1,"Are you sure you want to delete everything from the root level?" 
    782         SetDataFolder root: 
    783         KillWaves/A/Z 
    784         KillStrings/A/Z 
    785         KillVariables/A/Z 
    786          
    787 End 
    788  
    789 ///***************** 
    790 //unused testing procedure for writing a 4 byte floating point value in VAX format 
    791 Proc TestReWriteReal() 
    792         String Path 
    793         Variable value,start 
    794          
    795         GetFileAndPath() 
    796         Path = S_Path + S_filename 
    797          
    798         value = 0.2222 
    799         start = 158             //trans starts at byte 159 
    800         ReWriteReal(path,value,start) 
    801          
    802         SetDataFolder root: 
    803 End 
    804  
    805 //function will re-write a real value (4bytes) to the header of a RAW data file 
    806 //to ensure re-readability, the real value must be written mimicking VAX binary format 
    807 //which is done in this function 
    808 //path is the full path:file;vers to the file 
    809 //value is the real value to write 
    810 //start is the position to move the file marker to, to begin writing 
    811 //--so start is actually the "end byte" of the previous value 
    812 // 
    813 //this procedure takes care of all file open/close pairs needed 
    814 // 
    815 Function ReWriteReal(path,value,start) 
    816         String path 
    817         Variable value,start 
    818          
    819         //Print " in F(), path = " + path 
    820         Variable refnum,int1,int2, value4 
    821  
    822 ////// 
    823         value4 = 4*value 
    824          
    825         Open/A/T="????TEXT" refnum as path 
    826         //write IEEE FP, 4*desired value 
    827         FSetPos refnum,start 
    828         FBinWrite/B=3/F=4 refnum,value4         //write out as little endian 
    829          
    830         //move to the end of the file 
    831         FStatus refnum 
    832         FSetPos refnum,V_logEOF 
    833         //Print "Wrote end of header to " + num2str(V_filePOS) 
    834          
    835         Close refnum 
    836          
    837 /////// 
    838         Open/R refnum as path 
    839         //read back as two 16-bit integers 
    840         FSetPos refnum,start 
    841         FBinRead/B=2/F=2 refnum,int1    //read as big-endian 
    842         FBinRead/B=2/F=2 refnum,int2 
    843          
    844         //file was opened read-only 
    845         //no need to move to the end of the file, just close it 
    846          
    847         Close refnum 
    848 /////// 
    849         Open/A/T="????TEXT" refnum as path 
    850         //write the two 16-bit integers, reversed 
    851         FSetPos refnum,start 
    852         FBinWrite/B=2/F=2 refnum,int2   //re-write as big endian 
    853         FBinWrite/B=2/F=2 refnum,int1 
    854          
    855         //move to the end of the file 
    856         FStatus refnum 
    857         FSetPos refnum,V_logEOF 
    858         //Print "Wrote end of header to " + num2str(V_filePOS) 
    859          
    860         Close refnum                            //at this point, it is as the VAX would have written it.  
    861          
    862         Return(0) 
    863 End 
    864  
    865 //Utility function that returns the detector resolution (in cm) given information  
    866 //from the file header 
    867 //Global values are set in the Initialize procedure 
    868 Function DetectorPixelResolution(fileStr,detStr) 
    869         String fileStr,detStr 
    870          
    871         Variable DDet 
    872         String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) 
    873          
    874         NVAR PixelResNG3_ILL = root:myGlobals:PixelResNG3_ILL           //pixel resolution in cm 
    875         NVAR PixelResNG5_ILL = root:myGlobals:PixelResNG5_ILL 
    876         NVAR PixelResNG7_ILL = root:myGlobals:PixelResNG7_ILL 
    877         NVAR PixelResNG3_ORNL = root:myGlobals:PixelResNG3_ORNL 
    878         NVAR PixelResNG5_ORNL = root:myGlobals:PixelResNG5_ORNL 
    879         NVAR PixelResNG7_ORNL = root:myGlobals:PixelResNG7_ORNL 
    880         NVAR PixelResDefault = root:myGlobals:PixelResDefault 
    881          
    882         strswitch(instr) 
    883                 case "NG3": 
    884                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    885                                 DDet= PixelResNG3_ILL 
    886                         else 
    887                                 DDet = PixelResNG3_ORNL //detector is ordella-type 
    888                         endif 
    889                         break 
    890                 case "NG5": 
    891                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    892                                 DDet= PixelResNG5_ILL 
    893                         else 
    894                                 DDet = PixelResNG5_ORNL //detector is ordella-type 
    895                         endif 
    896                         break 
    897                 case "NG7": 
    898                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    899                                 DDet= PixelResNG7_ILL 
    900                         else 
    901                                 DDet = PixelResNG7_ORNL //detector is ordella-type 
    902                         endif 
    903                         break 
    904                 default:                                                         
    905                         //return error? 
    906                         DDet = PixelResDefault  //5mm, typical for new ORNL detectors 
    907         endswitch 
    908          
    909         return(DDet) 
    910 End 
    911  
    912 //Utility function that returns the detector deadtime (in seconds) given information  
    913 //from the file header 
    914 //Global values are set in the Initialize procedure 
    915 Function DetectorDeadtime(fileStr,detStr) 
    916         String fileStr,detStr 
    917          
    918         Variable deadtime 
    919         String instr=fileStr[1,3]       //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total) 
    920          
    921         NVAR DeadtimeNG3_ILL = root:myGlobals:DeadtimeNG3_ILL           //pixel resolution in cm 
    922         NVAR DeadtimeNG5_ILL = root:myGlobals:DeadtimeNG5_ILL 
    923         NVAR DeadtimeNG7_ILL = root:myGlobals:DeadtimeNG7_ILL 
    924         NVAR DeadtimeNG3_ORNL = root:myGlobals:DeadtimeNG3_ORNL 
    925         NVAR DeadtimeNG5_ORNL = root:myGlobals:DeadtimeNG5_ORNL 
    926         NVAR DeadtimeNG7_ORNL = root:myGlobals:DeadtimeNG7_ORNL 
    927         NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault 
    928          
    929         strswitch(instr) 
    930                 case "NG3": 
    931                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    932                                 deadtime= DeadtimeNG3_ILL 
    933                         else 
    934                                 deadtime = DeadtimeNG3_ORNL     //detector is ordella-type 
    935                         endif 
    936                         break 
    937                 case "NG5": 
    938                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    939                                 deadtime= DeadtimeNG5_ILL 
    940                         else 
    941                                 deadtime = DeadtimeNG5_ORNL     //detector is ordella-type 
    942                         endif 
    943                         break 
    944                 case "NG7": 
    945                         if(cmpstr(detStr, "ILL   ") == 0 ) 
    946                                 deadtime= DeadtimeNG7_ILL 
    947                         else 
    948                                 deadtime = DeadtimeNG7_ORNL     //detector is ordella-type 
    949                         endif 
    950                         break 
    951                 default:                                                         
    952                         //return error? 
    953                         deadtime = DeadtimeDefault      //1e-6 seconds, typical for new ORNL detectors 
    954         endswitch 
    955          
    956         return(deadtime) 
    957 End 
    958  
    959 ////////////////////// 
    960 // "intelligent" differentiation of the data files based on information gathered while 
    961 // getting the FIle Catalog. Uses some waves that are generated there, but not displayed in the table 
    962 // 
    963 // See CatVSTable.ipf for where these files are created (and sorted to keep them together) 
    964 //////////// 
    965  
    966 //testing - unused 
    967 // 
    968 Function/S TextWave2SemiList(textW) 
    969         Wave/T textW 
    970          
    971         String list="" 
    972         Variable num=numpnts(textW),ii=0 
    973         do 
    974                 list += textw[ii] + ";" 
    975                 ii+=1 
    976         while(ii<num) 
    977         return(list) 
    978 End 
    979  
    980 Function/S NumWave2CommaList(numW) 
    981         Wave numW 
    982          
    983         String list="" 
    984         Variable num=numpnts(numW),ii=0 
    985         do 
    986                 list += num2Str(numW[ii]) + "," 
    987                 ii+=1 
    988         while(ii<num) 
    989         return(list) 
    990 End 
    991  
    992 // utility function to convert a list (string) of semicolon-delimited 
    993 //items to a text wave 
    994 Function List2TextWave(str,tw) 
    995         String str 
    996         wave/T tw 
    997          
    998         Variable num=ItemsinList(str,";"),ii=0 
    999         Redimension/N=(num) tw 
    1000         do 
    1001                 tw[ii] = StringFromList(ii, str ,";") 
    1002                 ii+=1 
    1003         while(ii<num) 
    1004         return(0) 
    1005          
    1006 End 
    1007  
    1008 // generates a list of the procedure files in the experiment 
    1009 // putting the results in a wave named "tw", editing and sorting the wave 
    1010 // 
    1011 Proc ListIncludedFiles() 
    1012         Make/O/T/N=2 tw 
    1013         String str="" 
    1014         //str = WinList("*", ";","INCLUDE:6") 
    1015         str = WinList("*", ";","WIN:128") 
    1016         List2TextWave(str,tw) 
    1017         Edit tw 
    1018         Sort tw tw 
    1019 End 
    1020  
    1021 // returns a comma delimited list of run numbers based on the run numbers collected 
    1022 // during the building of the File Catalog (why do it twice) 
    1023 Function/S RunNumberList() 
    1024  
    1025         Wave w= $"root:myGlobals:CatVSHeaderInfo:RunNumber" 
    1026         String list="" 
    1027         if(WaveExists(w) == 0) 
    1028                 list = "" 
    1029         else 
    1030                 list=NumWave2CommaList(w) 
    1031         endif 
    1032         return(list) 
    1033 End 
    1034  
    1035 // list is a comma delimited list of run numbers, from the File Catalog 
    1036 // - scan through the list and remove numbers that are not transmission files 
    1037 // 
    1038 Function/S isTransList(list) 
    1039         String list 
    1040          
    1041         //scan through the list, find the corresponding point number, and see what isTrans says 
    1042         Variable ii,num,temp 
    1043         String newList="" 
    1044         num=ItemsInList(list ,",") 
    1045         for(ii=0;ii<num;ii+=1) 
    1046                 temp = str2num( StringFromList(ii, list ,",") ) 
    1047                 if(RunNumIsTransFile(temp)) 
    1048                         newList += num2str(temp) + "," 
    1049                 endif 
    1050         endfor 
    1051          
    1052         return(newList) 
    1053 End 
    1054  
    1055 //truth if run number is a transmission file 
    1056 // based on whatever is currently in the File Catalog 
    1057 // 
    1058 // Can't use findlevel - it assumes a monotonic RunNumber wave 
    1059 Function RunNumIsTransFile(num) 
    1060         Variable num 
    1061          
    1062         Wave isTrans = $"root:myGlobals:CatVSHeaderInfo:IsTrans" 
    1063         Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber" 
    1064          
    1065         if( (WaveExists(isTrans) == 0 ) ||  (WaveExists(RunNumber) == 0 ) ) 
    1066                 return(0) 
    1067         endif 
    1068          
    1069         Variable pts=numpnts(RunNumber),ii 
    1070         for(ii=0;ii<pts;ii+=1) 
    1071                 if(RunNumber[ii] == num) 
    1072                         return(isTrans[ii]) 
    1073                 endif 
    1074         endfor 
    1075 //      FindLevel/P/Q RunNumber,num 
    1076 // 
    1077 //      if(isTrans[V_LevelX]==1) 
    1078 //              return(1) 
    1079 //      else 
    1080 //              return(0) 
    1081 //      endif 
    1082 End 
    1083  
    1084 //truth if run number is at the given sample to detector distance 
    1085 // based on whatever is currently in the File Catalog 
    1086 // 
    1087 // need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004      !!! 
    1088 Function RunNumIsAtSDD(num,sdd) 
    1089         Variable num,sdd 
    1090          
    1091         Wave w = $"root:myGlobals:CatVSHeaderInfo:SDD" 
    1092         Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber" 
    1093          
    1094         if( (WaveExists(w) == 0 ) ||  (WaveExists(RunNumber) == 0 ) ) 
    1095                 return(0) 
    1096         endif 
    1097         Variable pts=numpnts(RunNumber),ii 
    1098         for(ii=0;ii<pts;ii+=1) 
    1099                 if(RunNumber[ii] == num) 
    1100                         if(abs(w[ii] - sdd) < 0.001     )               //if numerically within 0.001 meter, they're the same 
    1101                                 return(1) 
    1102                         else 
    1103                                 return(0) 
    1104                         endif 
    1105                 endif 
    1106         endfor 
    1107 End 
    1108  
    1109  
    1110 // list is a comma delimited list of run numbers, from the File Catalog 
    1111 // - scan through the list and remove numbers that are not at the specified SDD 
    1112 // 
    1113 Function/S atSDDList(list,sdd) 
    1114         String list 
    1115         Variable sdd 
    1116          
    1117         //scan through the list, find the corresponding point number, and see what SDD the run is at 
    1118         Variable ii,num,temp 
    1119         String newList="" 
    1120         num=ItemsInList(list ,",") 
    1121         for(ii=0;ii<num;ii+=1) 
    1122                 temp = str2num( StringFromList(ii, list ,",") ) 
    1123                 if(RunNumIsAtSDD(temp,sdd)) 
    1124                         newList += num2str(temp) + "," 
    1125                 endif 
    1126         endfor 
    1127          
    1128         return(newList) 
    1129 End 
    1130  
    1131 //given a comma-delimited list, remove those that are trans files 
    1132 // 
    1133 Function/S removeTrans(list) 
    1134         String list 
    1135          
    1136         //scan through the list, and remove those that are trans files 
    1137         Variable ii,num,temp 
    1138 //      String newList="" 
    1139         num=ItemsInList(list ,",") 
    1140         for(ii=0;ii<num;ii+=1) 
    1141                 temp = str2num( StringFromList(ii, list ,",") ) 
    1142                 if(RunNumIsTransFile(temp)) 
    1143                         list = RemoveFromList(num2str(temp),list,",") 
    1144                         ii -= 1                 //item ii was just deleted (everything moves to fill in) 
    1145                         num -= 1                // and the list is shorter now 
    1146                 endif 
    1147         endfor 
    1148          
    1149         return(list) 
    1150 End 
    1151  
    1152 Function setMREDFileList(str) 
    1153         String str 
    1154          
    1155         SVAR/Z list = root:myGlobals:MRED:gFileNumList 
    1156         if(SVAR_Exists(list)==0)                //check for myself 
    1157                 DoAlert 0,"The Multiple Reduce Panel must be open for you to use this function" 
    1158                 Return(1) 
    1159         endif 
    1160          
    1161         list = str 
    1162          
    1163         //force an update If the SVAR exists, then the panel does too - MRED cleans up after itself when done 
    1164         DoWindow/F Multiple_Reduce_Panel                        //bring to front 
    1165         MRedPopMenuProc("MRFilesPopup",0,"")            //parse the list, pop the menu 
    1166          
    1167         return(0) 
    1168 End 
    1169  
    1170 Proc FillEMPUsingSelection() 
    1171         FillEMPFilenameWSelection() 
    1172 End 
    1173  
    1174 Proc GuessEveryTransFiles(num) 
    1175         Variable num=6 
    1176         GuessAllTransFiles(num) 
    1177 End 
    1178  
    1179 Proc GuessSelectedTransFiles(num) 
    1180         Variable num=6 
    1181         fGuessSelectedTransFiles(num) 
    1182 End 
    1183  
    1184 Proc ClearSelectedTransAssignments() 
    1185         ClearSelectedAssignments() 
    1186 End 
    1187  
    1188 Proc CreateRunNumList() 
    1189         String/G rStr="" 
    1190         rStr=RunNumberList() 
    1191         Print "The list is stored in root:rStr" 
    1192         print rStr 
    1193 End 
    1194  
    1195 Proc TransList() 
    1196         String/G rStr="" 
    1197         rStr=RunNumberList() 
    1198         rStr=isTransList(rStr) 
    1199         print rStr 
    1200 End 
    1201  
    1202 Proc ScatteringAtSDDList(sdd) 
    1203         Variable sdd=13 
    1204          
    1205         String/G rStr="" 
    1206         rStr=RunNumberList() 
    1207         rStr=removeTrans(rStr) 
    1208         rStr=atSDDList(rStr,sdd) 
    1209          
    1210         //for Igor 4, the search is case-sensitive, so use all permutations 
    1211         // in Igor 5, use the proper flag in strsearch() inside FindStringInLabel() 
    1212         rStr = RemoveEmptyBlocked(rStr,"EMPTY") 
    1213         rStr = RemoveEmptyBlocked(rStr,"Empty") 
    1214         rStr = RemoveEmptyBlocked(rStr,"empty") 
    1215         rStr = RemoveEmptyBlocked(rStr,"MT Cell") 
    1216         rStr = RemoveEmptyBlocked(rStr,"MT CELL") 
    1217         rStr = RemoveEmptyBlocked(rStr,"mt cell") 
    1218         rStr = RemoveEmptyBlocked(rStr,"BLOCKED") 
    1219         rStr = RemoveEmptyBlocked(rStr,"Blocked") 
    1220         rStr = RemoveEmptyBlocked(rStr,"blocked") 
    1221          
    1222         print rStr 
    1223 End 
    1224  
    1225 Proc FillMREDList() 
    1226         setMREDFileList(rStr) 
    1227         DoUpdate 
    1228 End 
    1229  
    1230 //num passed in is the run number, as in the list 
    1231 // ii is the index of all of the files from the catalog 
    1232 //return will be -1 if string not found, >=0 if found 
    1233 // 
    1234 Function FindStringInLabel(num,findThisStr) 
    1235         Variable num 
    1236         String findThisStr 
    1237          
    1238         Wave/T w = $"root:myGlobals:CatVSHeaderInfo:Labels" 
    1239         Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber" 
    1240          
    1241         if( (WaveExists(w) == 0 ) ||  (WaveExists(RunNumber) == 0 ) ) 
    1242                 return(0) 
    1243         endif 
    1244          
    1245         Variable pts=numpnts(RunNumber),ii,loc 
    1246         for(ii=0;ii<pts;ii+=1) 
    1247                 if(RunNumber[ii] == num) 
    1248                         loc = strsearch(w[ii], findThisStr, 0)                  //Igor 4 version is case-sensitive 
    1249 //                      loc = strsearch(w[ii], findThisStr, 0 ,2)               //2==case insensitive, but Igor 5 specific 
    1250                         if(loc != -1) 
    1251                                 Print "Remove w[ii] = ",num,"  ",w[ii] 
    1252                         endif 
    1253                 endif 
    1254         endfor 
    1255          
    1256         return(loc)             //return will be -1 if string not found, >=0 if found 
    1257 end 
    1258  
    1259 //rStr is the global string, already atSDD (so there should be only one instance of 
    1260 // empty and one instance of blocked 
    1261 // 
    1262 //scan through the list, and remove those that are have "empty" or "blocked" in the label 
    1263 // or anything that is listed in StrToFind 
    1264 // 
    1265 Function/S RemoveEmptyBlocked(list,StrToFind) 
    1266         String list,StrToFind 
    1267          
    1268         Variable ii,num,temp 
    1269         num=ItemsInList(list ,",") 
    1270         for(ii=0;ii<num;ii+=1) 
    1271                 temp = str2num( StringFromList(ii, list ,",") ) 
    1272                 if(FindStringInLabel(temp,StrToFind) != -1) 
    1273                         list = RemoveFromList(num2str(temp),list,",") 
    1274                         ii -= 1                 //item ii was just deleted (everything moves to fill in) 
    1275                         num -= 1                // and the list is shorter now 
    1276                 endif 
    1277         endfor 
    1278         //print list 
    1279         return(list) 
    1280 end 
    1281  
    1282 // input is a single run number to remove from the list 
    1283 //  - typically EC and BN - before sending to MRED 
    1284 Proc RemoveRunFromList(remList) 
    1285         String remList="" 
    1286           
    1287         rStr = RemoveFromList(remList, rStr ,",") 
    1288 end 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/WriteQIS.ipf

    r60 r69  
    77// 
    88//************************ 
    9  
    10  
    11 //***this function is not used - WriteWaves_W_Protocol() is used instead 
    12 // 
    13 //for writing out data (q-i-s) from the "type" folder 
    14 //if fullpath is a complete HD path:filename, no dialog will be presented 
    15 //if fullpath is just a filename, the save dialog will be presented (forced if dialog =1) 
    16 //writes ONLY the standard header information (no protocol information) 
    17 // 
    18 Function WriteWaves(type,fullpath,dialog) 
    19         String type,fullpath 
    20         Variable dialog         //=1 will present dialog for name 
    21          
    22         String destStr="" 
    23         destStr = "root:"+type 
    24          
    25         Variable refNum 
    26         String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" 
    27         String fname,ave="C",headerFormat = "%10.4g %8.2g %8.2g %8.2g %8.3g %8.3g %8s %5.0g\r\n" 
    28         Variable step=1 
    29          
    30         //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
    31         WAVE intw=$(destStr + ":integersRead") 
    32         WAVE rw=$(destStr + ":realsRead") 
    33         WAVE/T textw=$(destStr + ":textRead") 
    34         WAVE qvals =$(destStr + ":qval") 
    35         WAVE inten=$(destStr + ":aveint") 
    36         WAVE sig=$(destStr + ":sigave") 
    37         WAVE qbar = $(destStr + ":QBar") 
    38         WAVE sigmaq = $(destStr + ":SigmaQ") 
    39         WAVE fsubs = $(destStr + ":fSubS") 
    40  
    41         //check each wave 
    42         If(!(WaveExists(intw))) 
    43                 Abort "intw DNExist BinaryWrite()" 
    44         Endif 
    45         If(!(WaveExists(rw))) 
    46                 Abort "rw DNExist BinaryWrite()" 
    47         Endif 
    48         If(!(WaveExists(textw))) 
    49                 Abort "textw DNExist BinaryWrite()" 
    50         Endif 
    51         If(!(WaveExists(qvals))) 
    52                 Abort "qvals DNExist BinaryWrite()" 
    53         Endif 
    54         If(!(WaveExists(inten))) 
    55                 Abort "inten DNExist BinaryWrite()" 
    56         Endif 
    57         If(!(WaveExists(sig))) 
    58                 Abort "sig DNExist BinaryWrite()" 
    59         Endif 
    60         If(!(WaveExists(qbar))) 
    61                 Abort "qbar DNExist BinaryWrite()" 
    62         Endif 
    63         If(!(WaveExists(sigmaq))) 
    64                 Abort "sigmaq DNExist BinaryWrite()" 
    65         Endif 
    66         If(!(WaveExists(fsubs))) 
    67                 Abort "fsubs DNExist BinaryWrite()" 
    68         Endif 
    69                  
    70         if(dialog) 
    71                 PathInfo/S catPathName 
    72                 fullPath = DoSaveFileDialog("Save data as") 
    73                 If(cmpstr(fullPath,"")==0) 
    74                         //user cancel, don't write out a file 
    75                         Close/A 
    76                         Abort "no data file was written" 
    77                 Endif 
    78                 //Print "dialog fullpath = ",fullpath 
    79         Endif 
    80          
    81         //actually open the file 
    82         Open refNum as fullpath 
    83          
    84         fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 
    85         fprintf refnum,"LABEL: %s\r\n",textw[6] 
    86         fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n" 
    87         fprintf refnum,headerFormat,rw[0],rw[26],rw[19],rw[18],rw[4],rw[5],ave,step 
    88         wfprintf refnum, formatStr, qvals,inten,sig,sigmaq,qbar,fsubs 
    89          
    90         Close refnum 
    91          
    92         SetDataFolder root:             //(redundant) 
    93          
    94         Return(0) 
    95 End 
    96  
    979 
    9810//for writing out data (q-i-s) from the "type" folder, and including reduction information 
     
    539451End 
    540452 
    541 //********************** 
    542 // Resolution calculation - used by the averaging routines 
    543 // to calculate the resolution function at each q-value 
    544 // - the return value is not used 
    545 // 
    546 // equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR 
    547 // Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114 
    548 // 
    549 // - 21 MAR 07 uses projected BS diameter on the detector 
    550 // 
    551 Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,SigmaQ,QBar,fSubS) 
    552         Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r 
    553         Variable &fSubS, &QBar, &SigmaQ         //these are the output quantities at the input Q value 
    554          
    555         //lots of calculation variables 
    556         Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g 
    557         Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r 
    558  
    559         //Constants 
    560         //Variable del_r = .1 
    561         Variable vz_1 = 3.956e5         //velocity [cm/s] of 1 A neutron 
    562         Variable g = 981.0                              //gravity acceleration [cm/s^2] 
    563  
    564         String results 
    565         results ="Failure" 
    566  
    567         //rename for working variables,  these must be gotten from global 
    568         //variables 
    569  
    570 //      Variable wLam, wLW, wL1, wL2, wS1, wS2 
    571 //      Variable wBS, wDDet, wApOff 
    572 //      wLam = lambda 
    573 //      wLW = lambdaWidth 
    574 //      wDDet = DDet 
    575 //      wApOff = apOff 
    576         S1 *= 0.5*0.1                   //convert to radius and [cm] 
    577         S2 *= 0.5*0.1 
    578  
    579         L1 *= 100.0                     // [cm] 
    580         L1 -= apOff                             //correct the distance 
    581  
    582         L2 *= 100.0 
    583         L2 += apOff 
    584         del_r *= 0.1                            //width of annulus, convert mm to [cm] 
    585          
    586         BS *= 0.5*0.1                   //nominal BS diameter passed in, convert to radius and [cm] 
    587         // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture 
    588         Variable LB 
    589         LB = 20.1 + 1.61*BS                     //distance in cm from beamstop to anode plane (empirical) 
    590         BS = bs + bs*lb/(l2-lb)         //adjusted diameter of shadow from parallax 
    591          
    592         //Start resolution calculation 
    593         a2 = S1*L2/L1 + S2*(L1+L2)/L1 
    594         q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2) 
    595         lp = 1.0/( 1.0/L1 + 1.0/L2) 
    596  
    597         v_lambda = lambdaWidth^2/6.0 
    598         v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2 
    599         v_d = (DDet/2.3548)^2 + del_r^2/12.0 
    600         vz = vz_1 / lambda 
    601         yg = 0.5*g*L2*(L1+L2)/vz^2 
    602         v_g = 2.0*yg^2*v_lambda 
    603  
    604         r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) )) 
    605         delta = 0.5*(BS - r0)^2/v_d 
    606  
    607         if (r0 < BS)  
    608                 inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta)) 
    609         else 
    610                 inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta)) 
    611         endif 
    612  
    613         fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) ) 
    614         if (fSubS <= 0.0)  
    615                 fSubS = 1.e-10 
    616         endif 
    617         fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi)) 
    618         fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d 
    619  
    620         rmd = fr*r0 
    621         v_r1 = v_b + fv*v_d +v_g 
    622  
    623         rm = rmd + 0.5*v_r1/rmd 
    624         v_r = v_r1 - 0.5*(v_r1/rmd)^2 
    625         if (v_r < 0.0)  
    626                 v_r = 0.0 
    627         endif 
    628         QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2)) 
    629         SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda) 
    630  
    631         results = "success" 
    632         Return results 
    633 End 
    634453 
    635454//ASCII export of data as 3-columns qx-qy-Intensity 
     
    805624        return(0) 
    806625End 
     626 
     627 
     628//returns the path to the file, or null if cancel 
     629Function/S DoOpenFileDialog(msg) 
     630        String msg 
     631         
     632        Variable refNum 
     633//      String message = "Select a file" 
     634        String outputPath 
     635         
     636        Open/D/R/T="????"/M=msg refNum 
     637        outputPath = S_fileName 
     638         
     639        return outputPath 
     640End 
     641 
     642// returns the path to the file, or null if the user cancelled 
     643Function/S DoSaveFileDialog(msg) 
     644        String msg 
     645        Variable refNum 
     646//      String message = "Save the file as" 
     647        String outputPath 
     648         
     649        Open/D/M=msg refNum 
     650        outputPath = S_fileName 
     651         
     652        return outputPath 
     653End 
     654 
     655 
     656////***this function is not used - WriteWaves_W_Protocol() is used instead 
     657//// 
     658////for writing out data (q-i-s) from the "type" folder 
     659////if fullpath is a complete HD path:filename, no dialog will be presented 
     660////if fullpath is just a filename, the save dialog will be presented (forced if dialog =1) 
     661////writes ONLY the standard header information (no protocol information) 
     662//// 
     663//Function WriteWaves(type,fullpath,dialog) 
     664//      String type,fullpath 
     665//      Variable dialog         //=1 will present dialog for name 
     666//       
     667//      String destStr="" 
     668//      destStr = "root:"+type 
     669//       
     670//      Variable refNum 
     671//      String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n" 
     672//      String fname,ave="C",headerFormat = "%10.4g %8.2g %8.2g %8.2g %8.3g %8.3g %8s %5.0g\r\n" 
     673//      Variable step=1 
     674//       
     675//      //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** 
     676//      WAVE intw=$(destStr + ":integersRead") 
     677//      WAVE rw=$(destStr + ":realsRead") 
     678//      WAVE/T textw=$(destStr + ":textRead") 
     679//      WAVE qvals =$(destStr + ":qval") 
     680//      WAVE inten=$(destStr + ":aveint") 
     681//      WAVE sig=$(destStr + ":sigave") 
     682//      WAVE qbar = $(destStr + ":QBar") 
     683//      WAVE sigmaq = $(destStr + ":SigmaQ") 
     684//      WAVE fsubs = $(destStr + ":fSubS") 
     685// 
     686//      //check each wave 
     687//      If(!(WaveExists(intw))) 
     688//              Abort "intw DNExist BinaryWrite()" 
     689//      Endif 
     690//      If(!(WaveExists(rw))) 
     691//              Abort "rw DNExist BinaryWrite()" 
     692//      Endif 
     693//      If(!(WaveExists(textw))) 
     694//              Abort "textw DNExist BinaryWrite()" 
     695//      Endif 
     696//      If(!(WaveExists(qvals))) 
     697//              Abort "qvals DNExist BinaryWrite()" 
     698//      Endif 
     699//      If(!(WaveExists(inten))) 
     700//              Abort "inten DNExist BinaryWrite()" 
     701//      Endif 
     702//      If(!(WaveExists(sig))) 
     703//              Abort "sig DNExist BinaryWrite()" 
     704//      Endif 
     705//      If(!(WaveExists(qbar))) 
     706//              Abort "qbar DNExist BinaryWrite()" 
     707//      Endif 
     708//      If(!(WaveExists(sigmaq))) 
     709//              Abort "sigmaq DNExist BinaryWrite()" 
     710//      Endif 
     711//      If(!(WaveExists(fsubs))) 
     712//              Abort "fsubs DNExist BinaryWrite()" 
     713//      Endif 
     714//               
     715//      if(dialog) 
     716//              PathInfo/S catPathName 
     717//              fullPath = DoSaveFileDialog("Save data as") 
     718//              If(cmpstr(fullPath,"")==0) 
     719//                      //user cancel, don't write out a file 
     720//                      Close/A 
     721//                      Abort "no data file was written" 
     722//              Endif 
     723//              //Print "dialog fullpath = ",fullpath 
     724//      Endif 
     725//       
     726//      //actually open the file 
     727//      Open refNum as fullpath 
     728//       
     729//      fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1] 
     730//      fprintf refnum,"LABEL: %s\r\n",textw[6] 
     731//      fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n" 
     732//      fprintf refnum,headerFormat,rw[0],rw[26],rw[19],rw[18],rw[4],rw[5],ave,step 
     733//      wfprintf refnum, formatStr, qvals,inten,sig,sigmaq,qbar,fsubs 
     734//       
     735//      Close refnum 
     736//       
     737//      SetDataFolder root:             //(redundant) 
     738//       
     739//      Return(0) 
     740//End 
Note: See TracChangeset for help on using the changeset viewer.