Changeset 571 for sans/Dev/trunk
- Timestamp:
- Oct 14, 2009 5:20:29 PM (13 years ago)
- 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 1137 1137 end 1138 1138 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 // 1144 Function 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) 1151 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_DataReadWrite.ipf
r570 r571 1986 1986 return out 1987 1987 End 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 // 1995 Function 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) 2001 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ILL_DataReadWrite.ipf
r570 r571 2122 2122 2123 2123 end 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 // 2129 Function 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) 2135 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_DataReadWrite.ipf
r570 r571 2781 2781 return(0) 2782 2782 End 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 // 2790 Function 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) 2797 End 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 // 2809 Function 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 2920 End 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 // 2925 Function 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) 2942 End 2943 2944 // writes a fake label into the header of the DIV file 2945 // 2946 Function 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) 2960 End 2961 2962 ////////end of ProDiv() specifics -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProDiv.ipf
r570 r571 21 21 // JAN2006 - not modified! still hard-wired to take a 128x128 detector image 22 22 // 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 // 23 30 //********************* 24 31 25 //writes an VAX-style WORK file, "exactly" as it would be output from the VAX26 //except for the "dummy" header and the record markers - the record marker bytes are27 // in the files - they are just written as zeros and are meaningless28 //file is:29 // 516 bytes header30 // 128x128=16384 (x4) bytes of data31 // + 2 byte record markers interspersed just for fun32 // = 66116 bytes33 //prompts for name of the output file.34 //35 Function WriteVAXWorkFile(type)36 String type37 38 Wave data=$("root:Packages:NIST:"+type+":data")39 40 Variable refnum,ii=0,hdrBytes=516,a,b,offset41 String fullpath=""42 43 Duplicate/O data,tempData44 Redimension/S/N=(128*128) tempData45 tempData *= 446 47 PathInfo/S catPathName48 fullPath = DoSaveFileDialog("Save data as") //won't actually open the file49 If(cmpstr(fullPath,"")==0)50 //user cancel, don't write out a file51 Close/A52 Abort "no data file was written"53 Endif54 55 Make/B/O/N=(hdrBytes) hdrWave56 hdrWave=057 FakeDIVHeader(hdrWave)58 59 Make/Y=2/O/N=(510) bw510 //Y=2 specifies 32 bit (=4 byte) floating point60 Make/Y=2/O/N=(511) bw51161 Make/Y=2/O/N=(48) bw4862 63 Make/O/B/N=2 recWave //two bytes64 65 //actually open the file66 Open/C="????"/T="TEXT" refNum as fullpath67 FSetPos refNum, 068 //write header bytes (to be skipped when reading the file later)69 70 FBinWrite /F=1 refnum,hdrWave71 72 ii=073 a=074 do75 //write 511 4-byte values (little-endian order), 4* true value76 bw511[] = tempData[p+a]77 FBinWrite /B=3/F=4 refnum,bw51178 a+=51179 //write a 2-byte record marker80 FBinWrite refnum,recWave81 82 //write 510 4-byte values (little-endian) 4* true value83 bw510[] = tempData[p+a]84 FBinWrite /B=3/F=4 refnum,bw51085 a+=51086 87 //write a 2-byte record marker88 FBinWrite refnum,recWave89 90 ii+=191 while(ii<16)92 //write out last 48 4-byte values (little-endian) 4* true value93 bw48[] = tempData[p+a]94 FBinWrite /B=3/F=4 refnum,bw4895 //close the file96 Close refnum97 98 //go back through and make it look like a VAX datafile99 Make/W/U/O/N=(511*2) int511 // /W=16 bit signed integers /U=unsigned100 Make/W/U/O/N=(510*2) int510101 Make/W/U/O/N=(48*2) int48102 103 //skip the header for now104 Open/A/T="????TEXT" refnum as fullPath105 FSetPos refnum,0106 107 offset=hdrBytes108 ii=0109 do110 //511*2 integers111 FSetPos refnum,offset112 FBinRead/B=2/F=2 refnum,int511113 Swap16BWave(int511)114 FSetPos refnum,offset115 FBinWrite/B=2/F=2 refnum,int511116 117 //skip 511 4-byte FP = (511*2)*2 2byte int + 2 bytes record marker118 offset += 511*2*2 + 2119 120 //510*2 integers121 FSetPos refnum,offset122 FBinRead/B=2/F=2 refnum,int510123 Swap16BWave(int510)124 FSetPos refnum,offset125 FBinWrite/B=2/F=2 refnum,int510126 127 //128 offset += 510*2*2 + 2129 130 ii+=1131 while(ii<16)132 //48*2 integers133 FSetPos refnum,offset134 FBinRead/B=2/F=2 refnum,int48135 Swap16BWave(int48)136 FSetPos refnum,offset137 FBinWrite/B=2/F=2 refnum,int48138 139 //move to EOF and close140 FStatus refnum141 FSetPos refnum,V_logEOF142 143 Close refnum144 145 Killwaves/Z hdrWave,bw48,bw511,bw510,recWave,temp16,int511,int510,int48146 End147 148 // given a 16 bit integer wave, read in as 2-byte pairs of 32-bit FP data149 // swap the order of the 2-byte pairs150 //151 Function Swap16BWave(w)152 Wave w153 154 Duplicate/O w,temp16155 //Variable num=numpnts(w),ii=0156 157 //elegant way to swap even/odd values, using wave assignments158 w[0,*;2] = temp16[p+1]159 w[1,*;2] = temp16[p-1]160 161 //crude way, using a loop162 // for(ii=0;ii<num;ii+=2)163 // w[ii] = temp16[ii+1]164 // w[ii+1] = temp16[ii]165 // endfor166 167 return(0)168 End169 170 // writes a fake label into the header of the DIV file171 //172 Function FakeDIVHeader(hdrWave)173 WAVE hdrWave174 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,ii178 179 lbl = "Sensitivity (DIV) created "+day +" "+tim180 num=strlen(lbl)181 for(ii=0;ii<num;ii+=1)182 hdrWave[start+ii] = char2num(lbl[ii])183 endfor184 185 return(0)186 End187 32 188 33 //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) 190 35 // calling procedure must make sure that the folder is on linear scale FIRST 191 36 Function NormalizeDIV(type) … … 194 39 WAVE data=$("root:Packages:NIST:"+type+":data") 195 40 Variable totCts=sum(data,Inf,-Inf) //sum all of the data 41 NVAR pixelX = root:myGlobals:gNPixelsX 42 NVAR pixelY = root:myGlobals:gNPixelsY 43 196 44 197 45 data /= totCts 198 data *= 128*12846 data *= pixelX*pixelY 199 47 200 48 return(0) … … 259 107 UpdateDisplayInformation(ctrtype) 260 108 //write out the new data file 261 Write VAXWorkFile(ctrtype)109 Write_DIV_File(ctrtype) 262 110 gLog = oldState //set log/lin pref back to user - set preference 263 111 Return(0) … … 267 115 //simple replacement of the selected data... 268 116 // 117 // working in detector coordinates 269 118 Function ReplaceDataBlock(ctrType,offType,x1,x2,y1,y2) 270 119 String ctrType,offType … … 526 375 UpdateDisplayInformation("STO") 527 376 //write out the new data file 528 Write VAXWorkFile("STO")377 Write_DIV_File("STO") 529 378 530 379 gLog=oldState //revert display preference to old state … … 563 412 Button button4,pos={240,481},size={80,20},proc=DoneDIVButtonProc,title="Done" 564 413 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:gPlexY2566 SetVariable setvar00202,pos={15,350},size={50,15},limits={0, 128,1},title=" ",value= root:myGlobals:Protocols:gPlexX1567 SetVariable setvar00203,pos={85,399},size={50,15},limits={0, 128,1},title=" ",value= root:myGlobals:Protocols:gPlexY1568 SetVariable setvar00204,pos={156,348},size={50,15},limits={0, 128,1},title=" ",value= root:myGlobals:Protocols:gPlexX2414 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 569 418 EndMacro 570 419 … … 619 468 return 0 620 469 End 470
Note: See TracChangeset
for help on using the changeset viewer.