Ignore:
Timestamp:
Oct 14, 2009 5:20:29 PM (13 years ago)
Author:
srkline
Message:

Changed to ProDiv?.ipf to pull out the NCNR-specific writing of the DIV file. Also removed 128x128 specific and made it xy generic.

Changed NCNR, FACILITY, HFIR, and ILL DataReadWrite?.ipf to reflect these changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProDiv.ipf

    r570 r571  
    2121// JAN2006 - not modified! still hard-wired to take a 128x128 detector image 
    2222// 
     23// Oct 2009 - SRK - pulled out the writing of the data file to NCNR_DataReadWrite.ipf 
     24//      leaving a stub Write_DIV_File() for the writer. Fully corrected, patched, and normalized DIV data 
     25//      is written out from "type" folder. The DIV file written out must be written in a  
     26//      format that is readable by ReadHeaderAndWork(type,fname). Each facility gets to pick their own format. 
     27// 
     28//      no longer hard-wired to 128x128 
     29// 
    2330//********************* 
    2431 
    25 //writes an VAX-style WORK file, "exactly" as it would be output from the VAX 
    26 //except for the "dummy" header and the record markers - the record marker bytes are 
    27 // in the files - they are just written as zeros and are meaningless 
    28 //file is: 
    29 //      516 bytes header 
    30 // 128x128=16384 (x4) bytes of data  
    31 // + 2 byte record markers interspersed just for fun 
    32 // = 66116 bytes 
    33 //prompts for name of the output file. 
    34 // 
    35 Function WriteVAXWorkFile(type) 
    36         String type 
    37          
    38         Wave data=$("root:Packages:NIST:"+type+":data") 
    39          
    40         Variable refnum,ii=0,hdrBytes=516,a,b,offset 
    41         String fullpath="" 
    42          
    43         Duplicate/O data,tempData 
    44         Redimension/S/N=(128*128) tempData 
    45         tempData *= 4 
    46          
    47         PathInfo/S catPathName 
    48         fullPath = DoSaveFileDialog("Save data as")       //won't actually open the file 
    49         If(cmpstr(fullPath,"")==0) 
    50                 //user cancel, don't write out a file 
    51           Close/A 
    52           Abort "no data file was written" 
    53         Endif 
    54          
    55         Make/B/O/N=(hdrBytes) hdrWave 
    56         hdrWave=0 
    57         FakeDIVHeader(hdrWave) 
    58          
    59         Make/Y=2/O/N=(510) bw510                //Y=2 specifies 32 bit (=4 byte) floating point 
    60         Make/Y=2/O/N=(511) bw511 
    61         Make/Y=2/O/N=(48) bw48 
    62  
    63         Make/O/B/N=2 recWave            //two bytes 
    64  
    65         //actually open the file 
    66         Open/C="????"/T="TEXT" refNum as fullpath 
    67         FSetPos refNum, 0 
    68         //write header bytes (to be skipped when reading the file later) 
    69          
    70         FBinWrite /F=1 refnum,hdrWave 
    71          
    72         ii=0 
    73         a=0 
    74         do 
    75                 //write 511 4-byte values (little-endian order), 4* true value 
    76                 bw511[] = tempData[p+a] 
    77                 FBinWrite /B=3/F=4 refnum,bw511 
    78                 a+=511 
    79                 //write a 2-byte record marker 
    80                 FBinWrite refnum,recWave 
    81                  
    82                 //write 510 4-byte values (little-endian) 4* true value 
    83                 bw510[] = tempData[p+a] 
    84                 FBinWrite /B=3/F=4 refnum,bw510 
    85                 a+=510 
    86                  
    87                 //write a 2-byte record marker 
    88                 FBinWrite refnum,recWave 
    89                  
    90                 ii+=1    
    91         while(ii<16) 
    92         //write out last 48  4-byte values (little-endian) 4* true value 
    93         bw48[] = tempData[p+a] 
    94         FBinWrite /B=3/F=4 refnum,bw48 
    95         //close the file 
    96         Close refnum 
    97          
    98         //go back through and make it look like a VAX datafile 
    99         Make/W/U/O/N=(511*2) int511             // /W=16 bit signed integers /U=unsigned 
    100         Make/W/U/O/N=(510*2) int510 
    101         Make/W/U/O/N=(48*2) int48 
    102          
    103         //skip the header for now 
    104         Open/A/T="????TEXT" refnum as fullPath 
    105         FSetPos refnum,0 
    106          
    107         offset=hdrBytes 
    108         ii=0 
    109         do 
    110                 //511*2 integers 
    111                 FSetPos refnum,offset 
    112                 FBinRead/B=2/F=2 refnum,int511 
    113                 Swap16BWave(int511) 
    114                 FSetPos refnum,offset 
    115                 FBinWrite/B=2/F=2 refnum,int511 
    116                  
    117                 //skip 511 4-byte FP = (511*2)*2 2byte int  + 2 bytes record marker 
    118                 offset += 511*2*2 + 2 
    119                  
    120                 //510*2 integers 
    121                 FSetPos refnum,offset 
    122                 FBinRead/B=2/F=2 refnum,int510 
    123                 Swap16BWave(int510) 
    124                 FSetPos refnum,offset 
    125                 FBinWrite/B=2/F=2 refnum,int510 
    126                  
    127                 // 
    128                 offset += 510*2*2 + 2 
    129                  
    130                 ii+=1 
    131         while(ii<16) 
    132         //48*2 integers 
    133         FSetPos refnum,offset 
    134         FBinRead/B=2/F=2 refnum,int48 
    135         Swap16BWave(int48) 
    136         FSetPos refnum,offset 
    137         FBinWrite/B=2/F=2 refnum,int48 
    138  
    139         //move to EOF and close 
    140         FStatus refnum 
    141         FSetPos refnum,V_logEOF 
    142          
    143         Close refnum 
    144          
    145         Killwaves/Z hdrWave,bw48,bw511,bw510,recWave,temp16,int511,int510,int48 
    146 End 
    147  
    148 // given a 16 bit integer wave, read in as 2-byte pairs of 32-bit FP data 
    149 // swap the order of the 2-byte pairs 
    150 //  
    151 Function Swap16BWave(w) 
    152         Wave w 
    153  
    154         Duplicate/O w,temp16 
    155         //Variable num=numpnts(w),ii=0 
    156  
    157         //elegant way to swap even/odd values, using wave assignments 
    158         w[0,*;2] = temp16[p+1] 
    159         w[1,*;2] = temp16[p-1] 
    160  
    161 //crude way, using a loop        
    162 //      for(ii=0;ii<num;ii+=2) 
    163 //              w[ii] = temp16[ii+1] 
    164 //              w[ii+1] = temp16[ii] 
    165 //      endfor 
    166          
    167         return(0)        
    168 End 
    169  
    170 // writes a fake label into the header of the DIV file 
    171 // 
    172 Function FakeDIVHeader(hdrWave) 
    173         WAVE hdrWave 
    174          
    175         //put some fake text into the sample label position (60 characters=60 bytes) 
    176         String day=date(),tim=time(),lbl="" 
    177         Variable start=98,num,ii 
    178          
    179         lbl = "Sensitivity (DIV) created "+day +" "+tim 
    180         num=strlen(lbl) 
    181         for(ii=0;ii<num;ii+=1) 
    182                 hdrWave[start+ii] = char2num(lbl[ii]) 
    183         endfor 
    184  
    185         return(0) 
    186 End 
    18732 
    18833//works on the data in "type" folder 
    189 //sums all of the data, and normalizes by the number of cells (=128*128) 
     34//sums all of the data, and normalizes by the number of cells (=pixelX*pixelY) 
    19035// calling procedure must make sure that the folder is on linear scale FIRST 
    19136Function NormalizeDIV(type) 
     
    19439        WAVE data=$("root:Packages:NIST:"+type+":data") 
    19540        Variable totCts=sum(data,Inf,-Inf)              //sum all of the data 
     41        NVAR pixelX = root:myGlobals:gNPixelsX 
     42        NVAR pixelY = root:myGlobals:gNPixelsY 
     43 
    19644         
    19745        data /= totCts 
    198         data *= 128*128 
     46        data *= pixelX*pixelY 
    19947         
    20048        return(0) 
     
    259107        UpdateDisplayInformation(ctrtype) 
    260108        //write out the new data file 
    261         WriteVAXWorkFile(ctrtype) 
     109        Write_DIV_File(ctrtype) 
    262110        gLog = oldState         //set log/lin pref back to user - set preference 
    263111        Return(0) 
     
    267115//simple replacement of the selected data... 
    268116// 
     117// working in detector coordinates 
    269118Function ReplaceDataBlock(ctrType,offType,x1,x2,y1,y2) 
    270119        String ctrType,offType 
     
    526375                        UpdateDisplayInformation("STO") 
    527376                //write out the new data file 
    528                         WriteVAXWorkFile("STO") 
     377                        Write_DIV_File("STO") 
    529378                                 
    530379                        gLog=oldState           //revert display preference to old state         
     
    563412        Button button4,pos={240,481},size={80,20},proc=DoneDIVButtonProc,title="Done" 
    564413        Button button3,pos={240,10},size={50,20},proc=DIVHelpButtonProc,title="Help" 
    565         SetVariable setvar00201,pos={84,297},size={50,15},limits={0,128,1},title=" ",value= root:myGlobals:Protocols:gPlexY2 
    566         SetVariable setvar00202,pos={15,350},size={50,15},limits={0,128,1},title=" ",value= root:myGlobals:Protocols:gPlexX1 
    567         SetVariable setvar00203,pos={85,399},size={50,15},limits={0,128,1},title=" ",value= root:myGlobals:Protocols:gPlexY1 
    568         SetVariable setvar00204,pos={156,348},size={50,15},limits={0,128,1},title=" ",value= root:myGlobals:Protocols:gPlexX2 
     414        SetVariable setvar00201,pos={84,297},size={50,15},limits={0,root:myGlobals:gNPixelsY-1,1},title=" ",value= root:myGlobals:Protocols:gPlexY2 
     415        SetVariable setvar00202,pos={15,350},size={50,15},limits={0,root:myGlobals:gNPixelsX-1,1},title=" ",value= root:myGlobals:Protocols:gPlexX1 
     416        SetVariable setvar00203,pos={85,399},size={50,15},limits={0,root:myGlobals:gNPixelsY-1,1},title=" ",value= root:myGlobals:Protocols:gPlexY1 
     417        SetVariable setvar00204,pos={156,348},size={50,15},limits={0,root:myGlobals:gNPixelsX-1,1},title=" ",value= root:myGlobals:Protocols:gPlexX2 
    569418EndMacro 
    570419 
     
    619468        return 0 
    620469End 
     470 
Note: See TracChangeset for help on using the changeset viewer.