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.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
Files:
5 edited

Legend:

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

    r570 r571  
    11371137end 
    11381138 
     1139////// OCT 2009, facility specific bits from ProDiv() 
     1140//"type" is the data folder that has the corrected, patched, and normalized DIV data array 
     1141// 
     1142// the header of this file is rather unimportant. Filling in a title at least would be helpful/ 
     1143// 
     1144Function Write_DIV_File(type) 
     1145        String type 
     1146         
     1147        // Your file writing function here. Don't try to duplicate the VAX binary format... 
     1148        WriteVAXWorkFile(type) 
     1149         
     1150        return(0) 
     1151End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_DataReadWrite.ipf

    r570 r571  
    19861986        return out 
    19871987End 
     1988 
     1989 
     1990////// OCT 2009, facility specific bits from ProDiv() 
     1991//"type" is the data folder that has the corrected, patched, and normalized DIV data array 
     1992// 
     1993// the header of this file is rather unimportant. Filling in a title at least would be helpful/ 
     1994// 
     1995Function Write_DIV_File(type) 
     1996        String type 
     1997         
     1998        // Your file writing function here. Don't try to duplicate the VAX binary format... 
     1999         
     2000        return(0) 
     2001End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ILL_DataReadWrite.ipf

    r570 r571  
    21222122 
    21232123end 
     2124////// OCT 2009, facility specific bits from ProDiv() 
     2125//"type" is the data folder that has the corrected, patched, and normalized DIV data array 
     2126// 
     2127// the header of this file is rather unimportant. Filling in a title at least would be helpful/ 
     2128// 
     2129Function Write_DIV_File(type) 
     2130        String type 
     2131         
     2132        // Your file writing function here. Don't try to duplicate the VAX binary format... 
     2133         
     2134        return(0) 
     2135End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_DataReadWrite.ipf

    r570 r571  
    27812781        return(0) 
    27822782End 
     2783 
     2784 
     2785////// OCT 2009, facility specific bits from ProDiv() 
     2786//"type" is the data folder that has the corrected, patched, and normalized DIV data array 
     2787// 
     2788// the header of this file is rather unimportant. Filling in a title at least would be helpful/ 
     2789// 
     2790Function Write_DIV_File(type) 
     2791        String type 
     2792         
     2793        // Your file writing function here. Don't try to duplicate the VAX binary format... 
     2794        WriteVAXWorkFile(type) 
     2795         
     2796        return(0) 
     2797End 
     2798 
     2799//writes an VAX-style WORK file, "exactly" as it would be output from the VAX 
     2800//except for the "dummy" header and the record markers - the record marker bytes are 
     2801// in the files - they are just written as zeros and are meaningless 
     2802//file is: 
     2803//      516 bytes header 
     2804// 128x128=16384 (x4) bytes of data  
     2805// + 2 byte record markers interspersed just for fun 
     2806// = 66116 bytes 
     2807//prompts for name of the output file. 
     2808// 
     2809Function WriteVAXWorkFile(type) 
     2810        String type 
     2811         
     2812        Wave data=$("root:Packages:NIST:"+type+":data") 
     2813         
     2814        Variable refnum,ii=0,hdrBytes=516,a,b,offset 
     2815        String fullpath="" 
     2816         
     2817        Duplicate/O data,tempData 
     2818        Redimension/S/N=(128*128) tempData 
     2819        tempData *= 4 
     2820         
     2821        PathInfo/S catPathName 
     2822        fullPath = DoSaveFileDialog("Save data as")       //won't actually open the file 
     2823        If(cmpstr(fullPath,"")==0) 
     2824                //user cancel, don't write out a file 
     2825          Close/A 
     2826          Abort "no data file was written" 
     2827        Endif 
     2828         
     2829        Make/B/O/N=(hdrBytes) hdrWave 
     2830        hdrWave=0 
     2831        FakeDIVHeader(hdrWave) 
     2832         
     2833        Make/Y=2/O/N=(510) bw510                //Y=2 specifies 32 bit (=4 byte) floating point 
     2834        Make/Y=2/O/N=(511) bw511 
     2835        Make/Y=2/O/N=(48) bw48 
     2836 
     2837        Make/O/B/N=2 recWave            //two bytes 
     2838 
     2839        //actually open the file 
     2840        Open/C="????"/T="TEXT" refNum as fullpath 
     2841        FSetPos refNum, 0 
     2842        //write header bytes (to be skipped when reading the file later) 
     2843         
     2844        FBinWrite /F=1 refnum,hdrWave 
     2845         
     2846        ii=0 
     2847        a=0 
     2848        do 
     2849                //write 511 4-byte values (little-endian order), 4* true value 
     2850                bw511[] = tempData[p+a] 
     2851                FBinWrite /B=3/F=4 refnum,bw511 
     2852                a+=511 
     2853                //write a 2-byte record marker 
     2854                FBinWrite refnum,recWave 
     2855                 
     2856                //write 510 4-byte values (little-endian) 4* true value 
     2857                bw510[] = tempData[p+a] 
     2858                FBinWrite /B=3/F=4 refnum,bw510 
     2859                a+=510 
     2860                 
     2861                //write a 2-byte record marker 
     2862                FBinWrite refnum,recWave 
     2863                 
     2864                ii+=1    
     2865        while(ii<16) 
     2866        //write out last 48  4-byte values (little-endian) 4* true value 
     2867        bw48[] = tempData[p+a] 
     2868        FBinWrite /B=3/F=4 refnum,bw48 
     2869        //close the file 
     2870        Close refnum 
     2871         
     2872        //go back through and make it look like a VAX datafile 
     2873        Make/W/U/O/N=(511*2) int511             // /W=16 bit signed integers /U=unsigned 
     2874        Make/W/U/O/N=(510*2) int510 
     2875        Make/W/U/O/N=(48*2) int48 
     2876         
     2877        //skip the header for now 
     2878        Open/A/T="????TEXT" refnum as fullPath 
     2879        FSetPos refnum,0 
     2880         
     2881        offset=hdrBytes 
     2882        ii=0 
     2883        do 
     2884                //511*2 integers 
     2885                FSetPos refnum,offset 
     2886                FBinRead/B=2/F=2 refnum,int511 
     2887                Swap16BWave(int511) 
     2888                FSetPos refnum,offset 
     2889                FBinWrite/B=2/F=2 refnum,int511 
     2890                 
     2891                //skip 511 4-byte FP = (511*2)*2 2byte int  + 2 bytes record marker 
     2892                offset += 511*2*2 + 2 
     2893                 
     2894                //510*2 integers 
     2895                FSetPos refnum,offset 
     2896                FBinRead/B=2/F=2 refnum,int510 
     2897                Swap16BWave(int510) 
     2898                FSetPos refnum,offset 
     2899                FBinWrite/B=2/F=2 refnum,int510 
     2900                 
     2901                // 
     2902                offset += 510*2*2 + 2 
     2903                 
     2904                ii+=1 
     2905        while(ii<16) 
     2906        //48*2 integers 
     2907        FSetPos refnum,offset 
     2908        FBinRead/B=2/F=2 refnum,int48 
     2909        Swap16BWave(int48) 
     2910        FSetPos refnum,offset 
     2911        FBinWrite/B=2/F=2 refnum,int48 
     2912 
     2913        //move to EOF and close 
     2914        FStatus refnum 
     2915        FSetPos refnum,V_logEOF 
     2916         
     2917        Close refnum 
     2918         
     2919        Killwaves/Z hdrWave,bw48,bw511,bw510,recWave,temp16,int511,int510,int48 
     2920End 
     2921 
     2922// given a 16 bit integer wave, read in as 2-byte pairs of 32-bit FP data 
     2923// swap the order of the 2-byte pairs 
     2924//  
     2925Function Swap16BWave(w) 
     2926        Wave w 
     2927 
     2928        Duplicate/O w,temp16 
     2929        //Variable num=numpnts(w),ii=0 
     2930 
     2931        //elegant way to swap even/odd values, using wave assignments 
     2932        w[0,*;2] = temp16[p+1] 
     2933        w[1,*;2] = temp16[p-1] 
     2934 
     2935//crude way, using a loop        
     2936//      for(ii=0;ii<num;ii+=2) 
     2937//              w[ii] = temp16[ii+1] 
     2938//              w[ii+1] = temp16[ii] 
     2939//      endfor 
     2940         
     2941        return(0)        
     2942End 
     2943 
     2944// writes a fake label into the header of the DIV file 
     2945// 
     2946Function FakeDIVHeader(hdrWave) 
     2947        WAVE hdrWave 
     2948         
     2949        //put some fake text into the sample label position (60 characters=60 bytes) 
     2950        String day=date(),tim=time(),lbl="" 
     2951        Variable start=98,num,ii 
     2952         
     2953        lbl = "Sensitivity (DIV) created "+day +" "+tim 
     2954        num=strlen(lbl) 
     2955        for(ii=0;ii<num;ii+=1) 
     2956                hdrWave[start+ii] = char2num(lbl[ii]) 
     2957        endfor 
     2958 
     2959        return(0) 
     2960End 
     2961 
     2962////////end of ProDiv() specifics 
  • 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.