- Timestamp:
- Oct 14, 2009 5:20:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.