Changeset 683
- Timestamp:
- Apr 12, 2010 11:03:04 AM (12 years ago)
- Location:
- sans/Dev/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ANSTO_Utils.ipf
r575 r683 869 869 return("Function Empty") 870 870 End 871 872 // Return the filename that represents the previous or next file. 873 // Input is current filename and increment. 874 // Increment should be -1 or 1 875 // -1 => previous file 876 // 1 => next file 877 Function/S GetPrevNextRawFile(curfilename, prevnext) 878 String curfilename 879 Variable prevnext 880 881 String filename 882 883 //get the run number 884 Variable num = GetRunNumFromFile(curfilename) 885 886 //find the next specified file by number 887 fileName = FindFileFromRunNumber(num+prevnext) 888 889 if(cmpstr(fileName,"")==0) 890 //null return, do nothing 891 fileName = FindFileFromRunNumber(num) 892 Endif 893 894 // print "in FU "+filename 895 896 Return filename 897 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Buttons.ipf
r680 r683 214 214 SVAR oldName = root:Packages:NIST:RAW:fileList 215 215 216 print oldName216 // print oldName 217 217 218 218 filename = oldname … … 221 221 endfor 222 222 223 print filename223 // print filename 224 224 225 225 // display the specified RAW data file -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/FACILITY_Utils.ipf
r573 r683 703 703 return("Function Empty") 704 704 End 705 706 707 // Return the filename that represents the previous or next file. 708 // Input is current filename and increment. 709 // Increment should be -1 or 1 710 // -1 => previous file 711 // 1 => next file 712 Function/S GetPrevNextRawFile(curfilename, prevnext) 713 String curfilename 714 Variable prevnext 715 716 String filename 717 718 //get the run number 719 Variable num = GetRunNumFromFile(curfilename) 720 721 //find the next specified file by number 722 fileName = FindFileFromRunNumber(num+prevnext) 723 724 if(cmpstr(fileName,"")==0) 725 //null return, do nothing 726 fileName = FindFileFromRunNumber(num) 727 Endif 728 729 // print "in FU "+filename 730 731 Return filename 732 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_DataReadWrite.ipf
r641 r683 41 41 PathInfo/S catPathName //should set the next dialog to the proper path... 42 42 //get the filename, then read it in 43 filename = PromptForPath(msgStr) //in SANS_Utils.ipf 43 filename = PromptForPath(msgStr)//in SANS_Utils.ipf 44 44 45 //check for cancel from dialog 45 46 if(strlen(filename)==0) … … 77 78 DoAlert 0, errorMsg 78 79 //Clean up waves... 79 KillWaves/Z M_listAttr, nsList,W_xmlcontentnodes80 //KillWaves/Z M_listAttr, nsList,W_xmlcontentnodes 80 81 return(1) //Do not change. 81 82 endif … … 87 88 // fRawWindowHook() 88 89 SetDataFolder root: 89 //Clean up waves...90 KillWaves/Z M_listAttr, nsList,W_xmlcontentnodes91 90 92 91 Print "Time to load and display (s) = ",(ticks-t1)/60.15 … … 138 137 refNum = XmlOpenFile(filename) 139 138 if (refNum < 0) 139 XmlCloseFile(refNum,0) 140 140 //print "\r ==> Failed: Not a standard xml file format." 141 141 return (-2) //Not a xml file. Do nothing... … … 154 154 ///////////////////////////////////////////////////////////////////////////////////////////////\/\/\/\ from P. R. Jemian 155 155 156 //temp list of ns157 Make/T/N=(1)/O nsList158 nsList[0] = "1.1"159 160 156 // Check if it is the SPICE version = 1.1 161 Variable item,i 162 String thislocation,ns = "" 163 164 for (item = 0; item < DimSize(nsList, 0); item += 1) // loop over all possible namespaces 165 XMLlistAttr(refNum, "/SPICErack", nsList[item]) 166 wave/T M_listAttr 167 168 for (i = 0; i < DimSize(M_listAttr,0); i+=1) // loop over all available attributes 169 // Expect the required hfir XML header (will fail if "schemalocation" is not found) 170 if ( CmpStr( LowerStr(M_listAttr[i][1]), LowerStr("SPICE_version") ) == 0 ) 171 thisLocation = HFIR_TrimWS(M_listAttr[i][2]) 172 if ( StringMatch(thisLocation, nsList[item] + "*") ) 173 ns = nsList[item] 174 175 Break // found it! 176 endif 177 endif 178 endfor 179 if (strlen(ns)) 180 Break 181 endif 182 endfor 183 184 if (StringMatch(ns,"1.1") <1) 157 String ns_ver = "1.1" 158 Variable ns = 0 159 ns = str2num(XMLstrFmXpath(refNum, "//SPICErack/@SPICE_version","","")) 160 161 // older version 162 if (ns <1.1) 185 163 //errorMsg = filename + ": This SPICE version is not supported" 186 164 XmlCloseFile(refNum,0) 187 KillWaves/Z M_listAttr, nsList,W_xmlcontentnodes188 165 SetDataFolder root: 189 166 return (-4) 190 167 endif 191 192 168 193 169 //this function is for reading in RAW data only, so it will always put data in RAW folder … … 218 194 //data =0 219 195 220 // Print "Time to open (s) = ",(ticks-t1)/60.15221 222 196 //ORNL HFIR SANS DATA 223 String tempheadhfir 224 tempheadhfir = "" 225 226 ReadHFIRSansRaw(refNum,curFolder,tempheadhfir) 227 228 i=0 229 do 230 //Take the file name from "actual file name", not from the header: (JC found some cases that those are different.) 231 //This DOLOOP can be removed where the problem is solved.... 232 textw[0]=stringfromlist(i,filename,":") 233 if (stringmatch(textw[0],"*.xml")>0) 234 break 235 endif 236 i +=1 237 while (1) 238 197 String tempheadhfir ="" 198 ReadHFIRSansRaw(refNum,curFolder,tempheadhfir) 199 200 //Take the file name from "actual file name", not from the header: (JC found some cases that those are different.) 201 //This can be removed where the problem is solved.... 202 textw[0]=GetFName(filename, 1) 203 204 SetDataFolder curPath 205 String/G fileList = textw[0] 239 206 //return the data folder to root 240 207 SetDataFolder root: 241 //clean up - get rid of w = $"root:Packages:NIST:RAW:tempGBWave0" 242 KillWaves/Z M_listAttr, nsList,W_xmlcontentnodes 243 244 XMLclosefile(refNum, 0) 208 245 209 Return 0 246 210 … … 256 220 // 257 221 // 222 258 223 Proc ReadWork_DIV() 259 // Silent 1260 224 261 225 String fname = PromptForPath("Select detector sensitivity file") … … 265 229 NewImage/F/K=1/S=2 $waveStr //this is an experimental IGOR operation 266 230 ModifyImage '' ctab= {*,*,YellowHot,0} 267 //Display;AppendImage $waveStr 268 269 //change the title string to WORK.DIV, rather than PLEXnnn_TST_asdfa garbage 231 270 232 String/G root:Packages:NIST:DIV:fileList = "WORK.DIV" 271 233 272 234 SetDataFolder root: //(redundant) 273 // Silent 0274 235 End 275 236 … … 325 286 refNum = XmlOpenFile(fname) 326 287 if (refNum < 0) 288 XMLclosefile(refNum, 0) 327 289 return 0 //Not a xml file. Do nothing... 328 290 endif 291 329 292 //ORNL HFIR SANS DATA 330 String tempheadhfir 331 tempheadhfir = "" 293 String tempheadhfir ="" 332 294 ReadHFIRSansRaw(refNum,cur_folder,tempheadhfir) 333 Variable i=0 334 do 335 //Take the file name from "actual file name", not from the header: (JC found some cases that those are different.) 336 textw[0]=stringfromlist(i,fname,":") 337 if (stringmatch(textw[0],"*.xml")>0) 338 break 339 endif 340 i +=1 341 while (1) 342 343 //divide the FP data by 4 if read from a PC (not since GBLoadWave update) 344 //if(cmpstr("Macintosh",IgorInfo(2)) == 0) 345 //do nothing 346 //else 347 //either Windows or Windows NT 348 //data /= 4 349 //endif 295 296 //Take the file name from "actual file name", not from the header: (JC found some cases that those are different.) 297 //This can be removed where the problem is solved.... 298 textw[0]=GetFName(fname, 1) 350 299 351 300 //keep a string with the filename in the DIV folder 352 301 String/G $(curPath + ":fileList") = textw[0] 353 302 354 XMLclosefile(refNum, 0)355 303 //return the data folder to root 356 304 SetDataFolder root: … … 417 365 418 366 KillWaves/Z temp0 419 367 Close/A 420 368 //return the data folder to root 421 369 SetDataFolder root: … … 494 442 formatStr="FILE: %s CREATED: %s" 495 443 sscanf hdr[0],formatStr,tempStr,junkStr 496 // Print tempStr 497 // Print junkStr 444 498 445 String/G $("root:"+destFolder+":fileList") = tempStr 499 446 textw[0] = tempStr //filename 500 447 textw[1] = junkStr //run date-time 501 448 502 //file label = hdr[1]503 449 tempStr = hdr[1] 504 450 tempStr = tempStr[0,strlen(tempStr)-2] //clean off the last LF 505 // Print tempStr 451 506 452 textW[6] = tempStr //sample label 507 453 … … 515 461 String fname, wantedterm //full path:name, term name 516 462 517 518 463 String str = "" 519 464 Variable refNum,i 520 465 521 // actually open the file466 //check the ext. 522 467 if (stringmatch(fname,"*.xml") <1) 523 468 //print "Failed: Not a *.xml file." … … 528 473 if (refNum < 0) 529 474 //print "Failed: Not a xml file." 475 XmlCloseFile(refNum,0) 530 476 return (str) //Not a xml file. Do nothing... 531 477 endif 532 478 533 479 //ORNL HFIR SANS strings meta DATA 534 if (stringmatch("filename",wantedterm)>0) 535 i=0 536 do 537 //Get the file name from "actual file name", not from the header: (JC found some cases that those are different.) 538 //This DOLOOP can be removed when the problem is solved.... 539 str=stringfromlist(i,fname,":") 540 if (stringmatch(str,"*.xml")>0 && stringmatch(stringfromlist(i+1,fname,":"),"")>0) 541 break 542 endif 543 i +=1 544 while (1) 480 if (stringmatch("*filename",wantedterm)>0) 481 str =GetFName(fname, 1) 545 482 else 546 483 str=ReadSFromHHead(refNum,wantedterm) //Get it from the header. … … 549 486 //return the data folder to root 550 487 //SetDataFolder root: 551 XMLclosefile(refNum, 0)552 488 553 489 return(str) … … 560 496 String fname 561 497 562 return(getStringFromHeader(fname," suffix")) //!!!!!!!!!!!!!!!!!!!!!!!!!498 return(getStringFromHeader(fname,"//suffix")) //!!!!!!!!!!!!!!!!!!!!!!!!! 563 499 End 564 500 … … 568 504 String fname 569 505 570 return(getStringFromHeader(fname," assoc_suffix")) //!!!!!!!!!!!!!!!!!!!!!!!!!506 return(getStringFromHeader(fname,"//assoc_suffix")) //!!!!!!!!!!!!!!!!!!!!!!!!! 571 507 End 572 508 … … 575 511 String fname 576 512 577 return(getStringFromHeader(fname," Scan_Title"))513 return(getStringFromHeader(fname,"//Header/Scan_Title")) 578 514 End 579 515 … … 582 518 String fname 583 519 584 return(getStringFromHeader(fname," start_time"))520 return(getStringFromHeader(fname,"//SPICErack/@start_time")) 585 521 End 586 522 … … 588 524 Function/S getIsTrans(fname) 589 525 String fname 590 return(getStringFromHeader(fname," Transmission"))526 return(getStringFromHeader(fname,"//Header/Transmission")) 591 527 End 592 528 … … 598 534 Variable refNum 599 535 600 //actually open the file601 536 if (stringmatch(fname,"*.xml") <1) 602 537 //print "Failed: Not a *.xml file." … … 609 544 return 0 //Not a xml file. Do nothing... 610 545 endif 611 546 612 547 //ORNL HFIR SANS strings meta DATA 613 548 vresult=ReadVFromHHead(refNum,wantedterm,unit) 614 615 //return the data folder to root616 //SetDataFolder root:617 XMLclosefile(refNum, 0)618 549 619 550 return(vresult) … … 624 555 String fname 625 556 626 return(getRealValueFromHeader(fname," monitor",""))557 return(getRealValueFromHeader(fname,"//Counters/monitor","")) 627 558 end 628 559 … … 631 562 String fname 632 563 633 return(getRealValueFromHeader(fname," monitor","")) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!??564 return(getRealValueFromHeader(fname,"//Counters/monitor","")) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!?? 634 565 end 635 566 … … 638 569 String fname 639 570 640 return(getRealValueFromHeader(fname," psd","")) //Need to check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!571 return(getRealValueFromHeader(fname,"//Counters/psd","")) //Need to check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 641 572 end 642 573 … … 645 576 String fname 646 577 647 return(getRealValueFromHeader(fname," attenuation","percent")) //in unit of percents578 return(getRealValueFromHeader(fname,"//Motor_Positions/attenuation","percent")) //in unit of percents 648 579 end 649 580 … … 651 582 Function getSampleTrans(fname) 652 583 String fname 653 return(getRealValueFromHeader(fname," Transmission_for_Sample",""))584 return(getRealValueFromHeader(fname,"//Transmission_for_Sample","")) 654 585 end 655 586 … … 658 589 String fname 659 590 660 return(getRealValueFromHeader(fname," Box_Counts",""))591 return(getRealValueFromHeader(fname,"//Box_Counts","")) 661 592 end 662 593 … … 665 596 String fname 666 597 667 return(getRealValueFromHeader(fname," detector","")) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!598 return(getRealValueFromHeader(fname,"//Counters/detector","")) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 668 599 end 669 600 … … 672 603 String fname 673 604 674 return(getRealValueFromHeader(fname," Sample_Thickness","cm"))605 return(getRealValueFromHeader(fname,"//Header/Sample_Thickness","cm")) 675 606 end 676 607 … … 686 617 String fname 687 618 688 return(getRealValueFromHeader(fname," temp","C"))619 return(getRealValueFromHeader(fname,"//Parameter_Positions/tsample","C")) 689 620 end 690 621 … … 693 624 String fname 694 625 695 return(getRealValueFromHeader(fname," magnetic_field","G"))626 return(getRealValueFromHeader(fname,"//magnetic_field","G")) 696 627 end 697 628 … … 700 631 String fname 701 632 702 return(getRealValueFromHeader(fname," beam_center_x_pixel",""))633 return(getRealValueFromHeader(fname,"//Header/beam_center_x_pixel","")) 703 634 end 704 635 … … 707 638 String fname 708 639 709 return(getRealValueFromHeader(fname," beam_center_y_pixel",""))640 return(getRealValueFromHeader(fname,"//Header/beam_center_y_pixel","")) 710 641 end 711 642 … … 714 645 String fname 715 646 716 return(getRealValueFromHeader(fname," sample_det_dist","m"))647 return(getRealValueFromHeader(fname,"//Motor_Positions/sample_det_dist","m")) 717 648 end 718 649 … … 721 652 String fname 722 653 723 return(getRealValueFromHeader(fname," detector_trans","cm")) //cm: HFIR mm654 return(getRealValueFromHeader(fname,"//Motor_Positions/detector_trans","cm")) //cm: HFIR mm 724 655 end 725 656 … … 728 659 String fname 729 660 730 return(getRealValueFromHeader(fname," beam_trap_size","mm")) //check if this beamstop diameter?661 return(getRealValueFromHeader(fname,"//Motor_Positions/beam_trap_size","mm")) //check if this beamstop diameter? 731 662 end 732 663 … … 735 666 String fname 736 667 737 return(getRealValueFromHeader(fname," source_aperture_size","mm"))668 return(getRealValueFromHeader(fname,"//Header/source_aperture_size","mm")) 738 669 end 739 670 … … 742 673 String fname 743 674 744 return(getRealValueFromHeader(fname," sample_aperture_size","mm"))675 return(getRealValueFromHeader(fname,"//Header/sample_aperture_size","mm")) 745 676 end 746 677 … … 749 680 String fname 750 681 751 return(getRealValueFromHeader(fname," source_distance","m")) //unit=m :hfir = mm682 return(getRealValueFromHeader(fname,"//Header/source_distance","m")) //unit=m :hfir = mm 752 683 end 753 684 … … 756 687 String fname 757 688 758 return(getRealValueFromHeader(fname," wavelength", "A"))689 return(getRealValueFromHeader(fname,"//Header/wavelength", "A")) 759 690 end 760 691 … … 763 694 String fname 764 695 765 return(getRealValueFromHeader(fname," wavelength_spread",""))696 return(getRealValueFromHeader(fname,"//Header/wavelength_spread","")) 766 697 end 767 698 … … 777 708 String fname 778 709 779 return(getRealValueFromHeader(fname," x_mm_per_pixel","mm"))710 return(getRealValueFromHeader(fname,"//Header/x_mm_per_pixel","mm")) 780 711 end 781 712 … … 784 715 String fname 785 716 786 return(getRealValueFromHeader(fname," y_mm_per_pixel","mm"))717 return(getRealValueFromHeader(fname,"//Header/y_mm_per_pixel","mm")) 787 718 end 788 719 … … 792 723 Variable mtime 793 724 794 mtime = getRealValueFromHeader(fname," time","")725 mtime = getRealValueFromHeader(fname,"//Counters/time","") 795 726 if (mtime == 0) 796 mtime = 1 //get rid of a singular for calculating a rate .727 mtime = 1 //get rid of a singular for calculating a rate in case. 797 728 endif 798 729 return(mtime) … … 808 739 Variable vresult 809 740 810 //actually open the file811 741 if (stringmatch(fname,"*.xml") <1) 812 742 //print "Failed: Not a *.xml file." … … 814 744 endif 815 745 //actually open the file 816 refNum = XmlOpenFile(fname) 746 refNum = XmlOpenFile(fname) 747 XMLclosefile(refNum, 0) 817 748 if (refNum < 0) 818 749 //print "Failed: Not a xml file." … … 822 753 //ORNL HFIR SANS strings meta DATA 823 754 vresult=ReadVFromHHead(refNum,wanted, "") 824 825 //return the data folder to root826 //SetDataFolder root:827 XMLclosefile(refNum, 0)828 755 829 756 return(0) … … 841 768 Variable lambdaFromFile, fileVar, junkVal 842 769 lambdaFromFile = 6.0 770 843 771 Open/R/P=catPathName fileVar as tempName 844 772 FReadLine fileVar, junkString … … 876 804 877 805 // return your bounding box coordinates or default values of 0 878 x1=getRealValueFromHeader(fname," XYBox_x1","")879 x2=getRealValueFromHeader(fname," XYBox_x2","")880 y1=getRealValueFromHeader(fname," XYBox_y1","")881 y2=getRealValueFromHeader(fname," XYBox_y2","")806 x1=getRealValueFromHeader(fname,"//XYBox_x1","") 807 x2=getRealValueFromHeader(fname,"//XYBox_x2","") 808 y1=getRealValueFromHeader(fname,"//XYBox_y1","") 809 y2=getRealValueFromHeader(fname,"//XYBox_y2","") 882 810 883 811 if (x1 == -1 || x2 == -1 || y1 == -1 || y2 == -1) … … 907 835 sprintf y2str, "%d", y2 908 836 909 WriteHFIRHead(fname,x1str," XYBox_x1" ,"")910 WriteHFIRHead(fname,x2str," XYBox_x2" ,"")911 WriteHFIRHead(fname,y1str," XYBox_y1" ,"")912 WriteHFIRHead(fname,y2str," XYBox_y2" ,"")837 WriteHFIRHead(fname,x1str,"/SPICErack/XYBox_x1" ,"") 838 WriteHFIRHead(fname,x2str,"/SPICErack/XYBox_x2" ,"") 839 WriteHFIRHead(fname,y1str,"/SPICErack/XYBox_y1" ,"") 840 WriteHFIRHead(fname,y2str,"/SPICErack/XYBox_y2" ,"") 913 841 914 842 return(0) … … 922 850 923 851 924 WriteHFIRHead(fname,suffix," assoc_suffix" ,"text")852 WriteHFIRHead(fname,suffix,"/SPICErack/assoc_suffix" ,"text") 925 853 return(0) 926 854 end … … 993 921 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 994 922 Function ReadHFIRSansRaw(refNum,curFolder,tempheadhfir) 995 996 923 Variable refNum 924 String curFolder,tempheadhfir 997 925 998 926 String curPath="root:Packages:NIST:"+curFolder … … 1008 936 Variable ind,i,j,centerdata=1 1009 937 Variable pixnumx=0,pixnumy=0 1010 String val = ""// numerical and text values 1011 Variable value,t1=ticks 938 String val = "", pix_num = ""// numerical and text values 939 Variable value = 0.0,t1=ticks 940 String unitstr ="" //unit string 1012 941 1013 942 //Initialize wave values 1014 // data=11015 943 realw=0 1016 944 intw=0 … … 1033 961 //textw[2]="RAW" //???? 1034 962 1035 //if (stringmatch(tempheadhfir,"Number_of_X_Pixels")>0 || stringmatch(tempheadhfir,"Number_of_Y_Pixels")>0)1036 XMLlistAttr(refNum,"/SPICErack/Data/Detector","")1037 WAVE/T M_listAttr1038 for (i = 0; i<DimSize(M_listAttr,0);i+=1)1039 if ( Strsearch(M_listAttr[i][1],"type",0) !=-1) //find INT32[xxx,xxx]1040 pixnumy=Str2num(StringFromList(0,StringFromList(1,M_listAttr[i][2] ,","),"]"))1041 pixnumx=Str2num(StringFromList(1,StringFromList(0,M_listAttr[i][2] ,","),"["))1042 Variable/G root:myGlobals:gNPixelsX=pixnumx1043 Variable/G root:myGlobals:gNPixelsY=pixnumy1044 SetDataFolder curPath1045 break1046 endif1047 endfor1048 //endif1049 963 // Print "Time to list attributes (s) = ",(ticks-t1)/60.15 1050 1051 XMLelemlist(refNum)1052 WAVE/T W_ElementList1053 964 // Print "Time to list elements (s) = ",(ticks-t1)/60.15 1054 965 1055 for (ind = 0; ind<DimSize(W_ElementList,0); ind +=1) 1056 String unitstr ="" //unit string 1057 tempheadhfir = W_ElementList[ind][3] 1058 1059 //Find unit if exists. If no unit is found, unit convertor will do nothing. 1060 XMLlistAttr(refNum,W_ElementList[ind][0],"") 1061 WAVE/T M_listAttr 1062 for (i = 0; i < DimSize( M_listAttr,0); i+=1) 1063 if (stringmatch(M_listAttr[i][1],"units") >0) 1064 unitstr = M_listAttr[i][2] 1065 break 1066 endif 1067 endfor 1068 1069 //Find string or values. 1070 XMLwaveFmXpath(refNum,W_ElementList[ind][0],""," \t\n\r") 1071 WAVE/T M_xmlContent 1072 1073 if (DimSize(M_xmlContent, 0)==0) //For NULL content 1074 Make/O/T /N=1 M_xmlContent 1075 M_xmlContent = "" 1076 endif 1077 1078 val = M_xmlContent[0] 1079 1080 sscanf val, "%f", value 1081 966 // Get and set the number of pixels from the line just above data. 967 pix_num = XMLstrFmXpath(refNum,"//Data/Detector/@type","","") 968 pixnumx=Str2num(StringFromList(0,StringFromList(1,pix_num ,","),"]")) 969 pixnumy=Str2num(StringFromList(1,StringFromList(0,pix_num ,","),"[")) 970 Variable/G root:myGlobals:gNPixelsX=pixnumx 971 Variable/G root:myGlobals:gNPixelsY=pixnumy 972 SetDataFolder curPath 973 1082 974 //******Below deleted since HFIR prefers to use <Data type="INT32[xxx,xxx]" for pixnumbers 1083 975 //********Leave the following lines in case they change the policy. … … 1091 983 // SetDataFolder curPath 1092 984 // Note for units: If in-unit is null, out will be unity. 1093 if (stringmatch(tempheadhfir,"Scan_Title")>0) 1094 for (i = 1; i < DimSize(M_xmlContent,0);i +=1) 1095 val += " " + M_xmlContent[i] 1096 endfor 1097 textw[6] = val 1098 // fake values to get valid deadtime and detector constants 1099 // 1100 //textw[9]=detTyp+" " //6 characters 4+2 spaces 1101 //textw[3]="[NGxSANS00]" //11 chars, NGx will return default values for atten trans, deadtime... 1102 elseif (stringmatch(tempheadhfir,"Users")>0) 1103 for (i = 1; i < DimSize(M_xmlContent,0);i +=1) 1104 val += " " + M_xmlContent[i] 1105 endfor 1106 textw[3] = val //ToDo: Define 1107 elseif (stringmatch(tempheadhfir,"Instrument")>0) 1108 for (i = 1; i < DimSize(M_xmlContent,0);i +=1) 1109 val += " " + M_xmlContent[i] 1110 endfor 1111 textw[9] = val //ToDo: Define 1112 elseif (stringmatch(tempheadhfir,"Transmission_for_Sample")>0) 1113 if (value <= 0) 1114 value = 1 //HFIR default = -1 while NIST package not working if it is <=0: Set default =1. <=NOT good!!! 1115 endif 1116 realw[4] = unit_convert(value,unitstr,"") 1117 elseif (stringmatch(tempheadhfir,"attenuation")>0) 1118 realw[3] = unit_convert(value,unitstr,"percent") 1119 elseif (stringmatch(tempheadhfir,"tsample")>0) 1120 realw[8] = unit_convert(value,unitstr,"C") 1121 elseif (stringmatch(tempheadhfir,"monitor")>0) 1122 realw[0] =unit_convert(value,unitstr,"") 1123 elseif (stringmatch(tempheadhfir,"Sample_Thickness")>0) 1124 realw[5] =unit_convert(value,unitstr,"cm") 1125 elseif (stringmatch(tempheadhfir,"psd")>0) 1126 realw[2] = unit_convert(value,unitstr,"") ////Need to check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1127 elseif (stringmatch(tempheadhfir,"x_mm_per_pixel")>0) 1128 realw[10] = unit_convert(value,unitstr,"mm") 1129 elseif (stringmatch(tempheadhfir,"y_mm_per_pixel")>0) 1130 realw[13] = unit_convert(value,unitstr,"mm") 1131 Variable/G root:myGlobals:PixelResDefault = unit_convert(realw[13],"mm","cm") //back to cm unit for this default value??!! 1132 SetDataFolder curPath 1133 elseif (stringmatch(tempheadhfir,"beam_center_x_pixel")>0) 1134 realw[16] = unit_convert(value,unitstr,"") 1135 elseif (stringmatch(tempheadhfir,"beam_center_y_pixel")>0) 1136 realw[17] =unit_convert(value,unitstr,"") 1137 elseif (stringmatch(tempheadhfir,"beam_trap_size")>0) //what is the beam trap diameter??? 1138 realw[21] = unit_convert(value,unitstr,"mm") 1139 elseif (stringmatch(tempheadhfir,"sample_det_dist")>0) 1140 realw[18] = unit_convert(value,unitstr,"m") 1141 elseif (stringmatch(tempheadhfir,"time")>0) 1142 intw[1] =unit_convert(value,unitstr,"sec") //Not supported. Assumed in "sec" 1143 intw[2] = intw[1] //??? 1144 elseif (stringmatch(tempheadhfir,"source_aperture_size")>0) //diameter??? 1145 realw[23] = unit_convert(value,unitstr,"mm") 1146 elseif (stringmatch(tempheadhfir,"sample_aperture_size")>0) //diameter??? 1147 realw[24]= unit_convert(value,unitstr,"mm") 985 textw[6] = XMLstrFmXpath(refNum,"//Header/Scan_Title","","") 986 987 textw[3] = XMLstrFmXpath(refNum,"//Header/Users","","") //ToDo: Define 1148 988 1149 //The units of the source_distance is treated special... 1150 elseif (stringmatch(tempheadhfir,"source_distance")>0) 1151 if (strlen(unitstr)==0) 1152 unitstr = "mm" //Give mm unit since no unit is provided from the file. ///This needs to be corrected soon!!!! 1153 endif 1154 realw[25] =value*length_unit_convert(unitstr,"m") //Unit's Not provided from the file but it is in mm. 1155 1156 elseif (stringmatch(tempheadhfir,"wavelength")>0) 1157 realw[26] =unit_convert(value,unitstr,"a") 1158 elseif (stringmatch(tempheadhfir,"wavelength_spread")>0) 1159 realw[27] =unit_convert(value,unitstr,"") 1160 elseif (stringmatch(tempheadhfir,"Detector")>0) 1161 SetDataFolder curPath 1162 NVAR pixnumx1= root:myGlobals:gNPixelsX 1163 NVAR pixnumy1= root:myGlobals:gNPixelsY 1164 Variable pixnx = pixnumx1, pixny = pixnumy1 1165 realw[20] = realw[10]*pixnx/10 // physical detector width in cm // ToDo: Need to check for ypix size??? 1166 Make/O/N=(pixnumx1*pixnumy1) $(curPath+":data") 1167 WAVE data=$(curPath+":data") 1168 //set the globals to the detector dimensions (pixels) 1169 Redimension/N=(pixnx,pixny) data //ORNL pixnums are given from the data file 1170 Variable intens = 0 1171 for (i=0;i<pixnx;i+=1) 1172 for (j=0;j<pixny;j+=1) 1173 sscanf M_xmlContent[j+i*pixny],"%i", intens 1174 data[i][j]=intens 1175 endfor 989 textw[9] = XMLstrFmXpath(refNum,"//Header/Instrument","","") //ToDo: Define 990 991 value = ValfromUnit(refNum,"//Transmission_for_Sample","") 992 if (value <= 0) 993 value = 1 //HFIR default = -1 while NIST package not working if it is <=0: Set default =1. <=NOT good!!! 994 endif 995 realw[4] = value 996 997 realw[3] = ValfromUnit(refNum,"//Motor_Positions/attenuation","percent") 998 realw[8] = ValfromUnit(refNum,"//Parameter_Positions/tsample","C") 999 realw[0] = ValfromUnit(refNum,"//Counters/monitor","") 1000 realw[5] = ValfromUnit(refNum,"//Header/Sample_Thickness","cm") 1001 realw[2] = ValfromUnit(refNum,"//Counters/psd","") ////Need to check!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1002 realw[10] = ValfromUnit(refNum,"//Header/x_mm_per_pixel","mm") 1003 realw[13] = ValfromUnit(refNum,"//Header/y_mm_per_pixel","mm") 1004 Variable/G root:myGlobals:PixelResDefault = unit_convert(realw[13],"mm","cm") //back to cm unit for this default value??!! 1005 SetDataFolder curPath 1006 1007 realw[16] = ValfromUnit(refNum,"//Header/beam_center_x_pixel","") 1008 realw[17] = ValfromUnit(refNum,"//Header/beam_center_y_pixel","") 1009 realw[21] = ValfromUnit(refNum,"//Motor_Positions/beam_trap_size","mm") //what is different from the beam trap diameter in the file??? 1010 realw[18] = ValfromUnit(refNum,"//Motor_Positions/sample_det_dist","m") 1011 intw[1] = ValfromUnit(refNum,"//Counters/time","sec") //Not supported. Assumed in "sec" 1012 intw[2] = intw[1] //??? 1013 realw[23] = ValfromUnit(refNum,"//Header/source_aperture_size","mm") //diameter??? 1014 realw[24] = ValfromUnit(refNum,"//Header/sample_aperture_size","mm") //diameter??? 1015 realw[25] = ValfromUnit(refNum,"//Header/source_distance","m") 1016 realw[26] = ValfromUnit(refNum,"//Header/wavelength","a") 1017 realw[27] = ValfromUnit(refNum,"//Header/wavelength_spread","") 1018 1019 //Set pixel numbers 1020 //SetDataFolder curPath 1021 NVAR pixnumx1= root:myGlobals:gNPixelsX 1022 NVAR pixnumy1= root:myGlobals:gNPixelsY 1023 Variable pixnx = pixnumx1, pixny = pixnumy1 1024 realw[20] = realw[10]*pixnx/10.0 // physical detector width in cm // ToDo: Need to check for ypix size??? 1025 1026 //prepare to get data 1027 Make/O/N=(pixnumx1*pixnumy1) $(curPath+":data") 1028 WAVE data=$(curPath+":data") 1029 //set the globals to the detector dimensions (pixels) 1030 Redimension/N=(pixnx,pixny) data //ORNL pixnums are given from the data file 1031 Variable intens = 0 1032 1033 // Read 2d data 1034 XMLwaveFmXpath(refNum,"/SPICErack/Data/Detector",""," \t\n\r") 1035 WAVE/T M_xmlContent 1036 for (i=0;i<pixnx;i+=1) 1037 for (j=0;j<pixny;j+=1) 1038 sscanf M_xmlContent[j+i*pixny],"%i", intens 1039 data[i][j]=intens 1176 1040 endfor 1177 endif 1041 endfor 1042 1043 1178 1044 1179 1045 ///////unit test 1/2////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 1183 1049 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1184 1050 1185 endfor 1186 1187 // Print "Time to loop over elements (s) = ",(ticks-t1)/60.15 1188 1189 //If the data is a sensitivity scan, normalize so that the average =1. 1190 print curFolder 1191 if (stringmatch(curFolder,"DIV") >0)1192 WaveStats/Z/Q data1193 data /= V_avg1194 endif 1195 //keep a string withthe filename in the RAW folder1051 1052 1053 //If the data is a sensitivity data, need to be narmalize so that the average over the detector should be 1. 1054 If (stringmatch(curFolder, "DIV") >0) 1055 //Variable V_avg 1056 WaveStats/Z/Q data 1057 data /= V_avg 1058 endif 1059 1060 1061 //keep a string of the filename in the RAW folder 1196 1062 1197 1063 Variable strpos 1198 WAVE/T M_listAttr 1199 XMLlistAttr(refNum,"/SPICErack","") 1200 1201 for (i = 0; i<DimSize(M_listAttr,0);i+=1) 1202 if ( Strsearch(M_listAttr[i][1],"filename",0) !=-1) //find file name 1203 textw[0]=M_listAttr[i][2] //filename 1204 1205 elseif (Strsearch(M_listAttr[i][1],"start_time",0) !=-1) 1206 textw[1]=M_listAttr[i][2] //Date and Time 1207 1208 textw[5]=StringFromList(0,textw[1]," ") //Date 1209 endif 1210 endfor 1211 String/G $(curPath+":FileList") = textw[0] 1064 1065 textw[0] = RemoveAllSpaces(XMLstrFmXpath(refNum,"//SPICErack/@filename","","") ) //////ShortFileName(RemoveAllSpaces(XMLstrFmXpath(refNum,"//SPICErack/@filename","","") ) ) // file name 1066 textw[1] = XMLstrFmXpath(refNum,"//SPICErack/@start_time","","") //Date and Time 1067 textw[5]=StringFromList(0,textw[1]," ") //Date 1068 1069 //String/G $(curPath+":FileList") = textw[0] 1212 1070 1213 1071 ///////unit test 2/2////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 1224 1082 //endfor 1225 1083 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1226 1084 // We have everything from file: Need to close the file soon as possible 1085 XMLclosefile(refNum, 0) 1227 1086 SetDataFolder curPath 1228 1229 // Print "Time to exit reader (s) = ",(ticks-t1)/60.15 1230 1231 // Killwaves/Z nsList,M_listAttr,M_xmlContent,W_ElementList,M_listXPath,W_xmlcontentnodes 1232 return(0) 1233 1087 Killwaves/Z M_listXPath 1088 End 1089 1090 /// Get real value in NIST unit /////////////////////////////////////////////////////////////////////////////////////////////////// 1091 Function ValfromUnit(refNum,wantedterm,NISTunit) 1092 Variable refNum //FileID 1093 String wantedterm,NISTunit //Xpath, value in string, unit from HFIR, unit from NIST 1094 1095 String val="", unitstr="" 1096 Variable value = 0.0 1097 //SetDataFolder curPath ////????????/ 1098 1099 val = XMLstrFmXpath(refNum,wantedterm,"","") 1100 unitstr = RemoveAllSpaces(XMLstrFmXpath(refNum,wantedterm+"/@units","","")) 1101 1102 //The units of the source_distance is treated special... 1103 if (stringmatch(wantedterm,"*source_distance")>0 ) 1104 if (strlen(unitstr)==0) 1105 unitstr = "mm" //Give mm unit since no unit is provided from the file. ///This needs to be corrected soon!!!! 1106 endif 1107 endif 1108 //String to double 1109 sscanf val, "%f", value 1110 Variable data 1111 data = unit_convert(value,unitstr,NISTunit) 1112 1113 return data 1234 1114 End 1235 1115 … … 1246 1126 String ntype = "" 1247 1127 String savedDataFolder = GetDataFolder(1) 1248 //Default for transmission rate (between 0 to 1): HFIR not provide this as a Float number???? ==>make one 1249 if (stringmatch(wantedterm," Transmission_for_Sample")>0)1128 //Default for transmission rate (between 0 to 1): HFIR not provide this as a Float number???? ==>make one: if exist, read it below. 1129 if (stringmatch(wantedterm,"//Transmission_for_Sample")>0) 1250 1130 vresult=1 1251 1131 endif 1252 1132 1253 XMLelemlist(refNum) 1254 WAVE/T W_ElementList 1255 1256 for (ind = 0; ind<DimSize(W_ElementList,0); ind +=1) 1257 String unitstr = "",tempheadhfir="", val="" 1258 tempheadhfir=W_ElementList[ind][3] 1259 1260 //Find the value 1261 XMLwaveFmXpath(refNum,W_ElementList[ind][0],""," \t\n\r") 1262 WAVE/T M_xmlContent 1263 val = M_xmlContent[0] 1264 1265 if (stringmatch("",wantedterm)>0) 1266 vresult =0 1267 break 1268 elseif (stringmatch(tempheadhfir,wantedterm)>0) 1269 //Find unit if exists. 1270 XMLlistAttr(refNum,W_ElementList[ind][0],"") 1271 WAVE/T M_listAttr 1272 for (i = 0; i < DimSize( M_listAttr,0); i+=1) 1273 if (stringmatch(M_listAttr[i][1],"units") >0) 1274 unitstr = M_listAttr[i][2] 1275 break 1276 endif 1277 endfor 1278 ntype ="s" //TEXT 1279 for (i = 0; i < DimSize( M_listAttr,0); i+=1) 1280 if (stringmatch(M_listAttr[i][1],"type")>0) 1281 if (stringmatch(M_listAttr[i][2], "INT*")>0) 1282 ntype = "i" //INT32 1283 break 1284 elseif (stringmatch(M_listAttr[i][2], "FLOAT*")>0) 1285 ntype ="f" //FLOAT32 1286 break 1287 endif 1288 endif 1289 endfor 1290 if (strlen(ntype) == 0) 1291 ntype = "s" //for no "type" attr. 1292 endif 1293 String ustr ="%f" //default: float 1294 if (stringmatch(ntype,"i") > 0) //for integer 1295 ustr = "%d" 1296 endif 1133 String unitstr = "", typestr="",tempheadhfir="", val="" 1134 1135 if (stringmatch(wantedterm,"") >0 ) // set zero if wnatedterm is "" ,not defined(eg., rotation angle). 1136 vresult =0 1137 //close here 1138 XMLclosefile(refNum, 0) 1139 return vresult 1140 else 1141 //Find the value,unit, and type of the value: a little ugly but faster... 1142 val = XMLstrFmXpath(refNum,wantedterm,"","") 1143 unitstr = RemoveAllSpaces(XMLstrFmXpath(refNum,wantedterm+"/@units","","")) 1144 typestr = RemoveAllSpaces(XMLstrFmXpath(refNum,wantedterm+"/@type","","")) 1145 //close here 1146 XMLclosefile(refNum, 0) 1147 endif 1148 1149 if (stringmatch(typestr , "INT*")>0) 1150 ntype = "i" //INT32 1151 elseif (stringmatch(typestr , "FLOAT*")>0) 1152 ntype ="f" //FLOAT32 1153 else 1154 ntype ="s" //TEXT 1155 endif 1156 1157 String ustr ="%f" //default: float 1158 if (stringmatch(ntype,"i") > 0) //for integer 1159 ustr = "%d" 1160 endif 1297 1161 1298 //Special case starts!!! 1299 //No unit found in hfir ("mm") but needs to convert to meters. 1300 //The following 3 lines should be removed once HFIR puts th units on the raw data files. 1301 if (stringmatch(wantedterm,"source_distance")>0&& strlen(unitstr) ==0) 1302 unitstr = "mm" 1303 endif 1304 //Special case ends!!! 1305 sscanf val, ustr, value 1306 1307 vresult = unit_convert(value,unitstr,NCunit) 1308 //Set PixResDefault from y_mm_per_pixel (not x_mm_per_pixel!!!!!!!!) 1309 if (stringmatch(wantedterm,"y_mm_per_pixel")>0) 1310 Variable/G root:myGlobals:PixelResDefault = unit_convert(vresult,"mm","cm") //back to cm unit for this default value??!! 1311 SetDataFolder savedDataFolder //In case... 1312 endif 1313 break 1314 endif 1162 //Special case starts!!! 1163 //No unit found in hfir ("mm") but needs to convert to meters. 1164 //The following 3 lines should be removed once HFIR puts th units on the raw data files. 1165 if (stringmatch(wantedterm,"*source_distance")>0&& strlen(unitstr) ==0) 1166 unitstr = "mm" 1167 endif 1168 //Special case ends!!! 1169 1170 //Do NOT use str2num(): will loose many decimal digits. 1171 sscanf val, ustr, value 1172 vresult = unit_convert(value,unitstr,NCunit) 1173 if (stringmatch(wantedterm,"*Transmission_for_Sample")>0 && vresult == 0) 1174 //Transmission default value if it was set to 0. 1175 vresult = 1 1176 endif 1177 1178 //Set PixResDefault from y_mm_per_pixel (not x_mm_per_pixel!!!!!!!!) 1179 if (stringmatch(wantedterm,"*y_mm_per_pixel")>0) 1180 Variable/G root:myGlobals:PixelResDefault = unit_convert(vresult,"mm","cm") //back to cm unit for this default value??!! 1181 SetDataFolder savedDataFolder //In case... 1182 endif 1183 1315 1184 1316 endfor1317 KillWaves/Z W_ElementList,M_xmlContent1318 1185 return (vresult) 1319 1186 … … 1328 1195 1329 1196 String tempheadhfir = "" 1330 String result = "",gotterm ="n" 1197 String result = "",gotterm ="n" ,name 1331 1198 Variable ind,i 1332 1199 1333 1200 if (stringmatch(wantedterm,"")>0) 1334 1201 result = "" 1202 XMLclosefile(refNum, 0) 1335 1203 return (result) 1336 1204 endif 1337 1338 XMLlistAttr(refNum,"/SPICErack","") 1339 WAVE/T M_listAttr 1340 if (stringmatch("filename",wantedterm)>0 || stringmatch("start_time",wantedterm)>0) 1341 for (i = 0; i<DimSize(M_listAttr,0);i+=1) 1342 if ( Strsearch(M_listAttr[i][1],wantedterm,0) !=-1 ) 1343 result=M_listAttr[i][2] 1344 gotterm ="y" 1345 break 1346 endif 1347 endfor 1348 else 1349 XMLelemlist(refNum) 1350 WAVE/T W_ElementList 1351 1352 for (ind = 0; ind<DimSize(W_ElementList,0); ind +=1) 1353 1354 tempheadhfir=W_ElementList[ind][3] 1355 1356 XMLwaveFmXpath(refNum,W_ElementList[ind][0],""," \t\n\r") 1357 WAVE/T M_xmlContent 1358 1359 if (DimSize(M_xmlContent, 0)==0) //For NULL content 1360 Make/O/T /N=1 M_xmlContent 1361 M_xmlContent = "" 1362 endif 1363 1364 result = M_xmlContent[0] 1365 1366 if (stringmatch(tempheadhfir,wantedterm)>0) 1367 for (i = 1; i < DimSize(M_xmlContent,0);i +=1) 1368 result += " " + M_xmlContent[i] 1369 endfor 1370 gotterm ="y" 1371 break 1372 endif 1373 endfor 1374 endif 1375 1205 1206 result = XMLstrFmXpath(refNum,wantedterm,"","") 1207 if (stringmatch(result, "") != -1 ) 1208 gotterm ="y" 1209 endif 1210 1211 //HFIR header does not have "suffix" tag but one can get the info from file name before user writes the tag into the header. 1212 if (stringmatch("",result)>0 && stringmatch("//suffix",wantedterm)>0 ) 1213 name = RemoveAllSpaces(XMLstrFmXpath(refNum,"//SPICErack/@filename","","")) 1214 result=StringFromList(2,StringFromList(0, name,"."), "_")+"_"+StringFromList(3,StringFromList(0,name,"."), "_") 1215 endif 1216 1217 //Close file here. 1218 XMLclosefile(refNum, 0) 1376 1219 1377 1220 if (stringmatch(gotterm,"n")>0 ) 1378 1221 result = "" 1379 endif 1380 //HFIR header does not have "suffix" tag but one can get the info from file name before user writes the tag into the header. 1381 if (stringmatch("suffix",wantedterm)>0 && stringmatch("",result)>0) 1382 for (i = 0; i<DimSize(M_listAttr,0);i+=1) 1383 if ( Strsearch(M_listAttr[i][1],"filename",0) !=-1 ) 1384 result=StringFromList(2,StringFromList(0,M_listAttr[i][2],"."), "_")+"_"+StringFromList(3,StringFromList(0,M_listAttr[i][2],"."), "_") 1385 break 1386 endif 1387 endfor 1388 //make sure not to have a left-over content (only for text; numbers are set to -1 later as a default if not found) 1389 //else 1390 endif 1391 1392 //Make sure to clean up things... 1393 KillWaves/Z M_listAttr,W_ElementList,M_xmlContent,,W_xmlcontentnodes 1394 1222 endif 1223 1395 1224 return (result) 1396 1225 End … … 1412 1241 Variable typenum = 0 1413 1242 String ntype = "" //Do not change this initial, "". 1414 String nstr = "/SPICErack" //to add new nodes and content .1243 String nstr = "/SPICErack" //to add new nodes and content: NEVER CAHNGE this string 1415 1244 String errorMsg ="" 1416 1245 … … 1436 1265 return -1 //Not a xml file. Do nothing... 1437 1266 endif 1438 1439 XMLelemlist(refNum) 1440 WAVE/T W_ElementList 1441 1442 for (ind = 0; ind<DimSize(W_ElementList,0); ind +=1) 1443 String unitstr = "",tempheadhfir="", val="" 1444 tempheadhfir=W_ElementList[ind][3] 1267 1268 String unitstr = "",typestr="", val="" 1445 1269 1446 1270 if (strlen(wantedterm)==0) 1447 1271 vresult =0 //If input is NULL, do nothing... 1448 1272 nstr = "" //reset as No new node 1449 break 1450 elseif (stringmatch(tempheadhfir,wantedterm)>0) 1451 1452 XMLlistAttr(refNum,W_ElementList[ind][0],"") 1453 WAVE/T M_listAttr 1454 1273 1274 else //(stringmatch(tempheadhfir,wantedterm)>0) 1275 val = XMLstrFmXpath(refNum,wantedterm,"","") 1276 1455 1277 //Special case starts!!! 1456 1278 //No unit founds in hfir ("mm") file but needs to convert to meters. Let's give it one. 1457 if (stringmatch(wantedterm,"source_distance")>0&& strlen(unitstr) ==0) 1458 unitstr = "mm" 1279 if (stringmatch(wantedterm,"*source_distance")>0&& strlen(unitstr) ==0) 1280 unitstr = "mm" 1281 ntype ="f" 1459 1282 //Special case ends!!! 1460 1283 else 1461 //Check the unit 1462 for (i = 0; i < DimSize( M_listAttr,0); i+=1) 1463 if (stringmatch(M_listAttr[i][1],"units") >0) 1464 unitstr = M_listAttr[i][2] 1465 break 1466 endif 1467 endfor 1284 unitstr = XMLstrFmXpath(refNum,wantedterm+"/@units","","") 1285 typestr = RemoveAllSpaces(XMLstrFmXpath(refNum,wantedterm+"/@type","","")) 1286 1468 1287 ntype ="s" //TEXT 1469 for (i = 0; i < DimSize( M_listAttr,0); i+=1) 1470 if (stringmatch(M_listAttr[i][1],"type")>0) 1471 if (stringmatch(M_listAttr[i][2], "INT*")>0) 1472 ntype = "i" //INT32 1473 break 1474 elseif (stringmatch(M_listAttr[i][2], "FLOAT*")>0) 1475 ntype ="f" //FLOAT32 1476 break 1477 endif 1478 endif 1479 endfor 1480 if (strlen(ntype) == 0) 1481 ntype = "s" //for no "type" attr. 1482 endif 1288 1289 if (strlen(typestr)==0) 1290 ntype = "s" 1291 elseif (stringmatch(typestr, "INT*")>0) 1292 ntype = "i" //INT32 1293 elseif (stringmatch(typestr, "FLOAT*")>0) 1294 ntype ="f" //FLOAT32 1295 endif 1483 1296 endif 1297 1484 1298 if (stringmatch(ntype,"s") > 0) //for strings 1485 1299 vresult = 1 … … 1492 1306 sscanf value,ustr, vals 1493 1307 vresult = unit_convert(vals,NCunit,unitstr) //Unit correction...(back to the HFIR unit) 1308 1494 1309 sprintf valstr,ustr, vresult 1495 //valstr = vresult1496 1310 endif 1497 XMLsetNodeStr(refNum,W_ElementList[ind][0],"",valstr) //to set 1498 nstr = "" //reset as No new node 1499 break 1311 1312 if (stringmatch(wantedterm,"/SPICErack/*")>0&& strlen(val) ==0) 1313 nstr = "/SPICErack" 1314 // remove "/SPICErack/" from wantedterm 1315 wantedterm = StringFromList(2, wantedterm,"/SPICErack/") 1316 else 1317 XMLsetNodeStr(refNum,wantedterm,"",valstr) //to set 1318 nstr = "" //reset as No new node 1319 endif 1320 //break 1500 1321 endif 1501 endfor 1502 1503 if (strlen(nstr)>0) //to write a new attribut name and value which is not found in the raw file. 1322 //to write new attr name and value which are not found in the raw file. 1323 if (strlen(nstr)>2) 1504 1324 XMLaddNode(refNum,nstr,"",wantedterm,value,1) 1505 nstr += "/" + wantedterm 1325 // nstr to add new node 1326 nstr = "//"+wantedterm 1327 // get unit 1506 1328 if (stringmatch(NCunit,"text")>0) 1507 1329 ntype = "text" … … 1513 1335 vresult = vals 1514 1336 endif 1515 print "*** Note:*** \r *** No parameter named",wantedterm, "was found, so it was added to the end of your data file."1337 //print "*** Note:*** \r *** No parameter named",wantedterm, "was found, so it was added to the end of your data file." 1516 1338 XMLsetAttr(refNum,nstr,"","type",ntype) 1517 1339 endif 1518 1340 1519 KillWaves/Z W_ElementList,M_xmlContent,M_listXPath,M_listAttr //clean up1341 //KillWaves/Z W_ElementList,M_xmlContent,M_listXPath,M_listAttr //clean up 1520 1342 if (strlen(wantedterm)==0 && vresult == -1) 1521 1343 XMLclosefile(refNum, 0) … … 1566 1388 String fname,str 1567 1389 1568 WriteHFIRHead(fname,str, " Transmission","text")1390 WriteHFIRHead(fname,str, "//Header/Transmission","text") 1569 1391 return(0) 1570 1392 End … … 1578 1400 sprintf transstr, "%f", trans 1579 1401 1580 WriteHFIRHead(fname,transstr," Transmission_for_Sample" ,"")1402 WriteHFIRHead(fname,transstr,"/SPICErack/Transmission_for_Sample" ,"") 1581 1403 return(0) 1582 1404 End … … 1590 1412 sprintf transstr, "%f", trans 1591 1413 1592 WriteHFIRHead(fname,transstr," detector" ,"") //????????????????????????????????????????????????????????1414 WriteHFIRHead(fname,transstr,"//Counters/detector" ,"") //???????????????????????????????????????????????????????? 1593 1415 return(0) 1594 1416 End … … 1604 1426 sprintf countsstr, "%f", counts 1605 1427 1606 WriteHFIRHead(fname,countsstr," Box_Counts" ,"")1428 WriteHFIRHead(fname,countsstr,"/SPICErack/Box_Counts" ,"") 1607 1429 return(0) 1608 1430 End … … 1617 1439 sprintf xposstr, "%f", xpos 1618 1440 1619 WriteHFIRHead(fname,xposstr," beam_trap_x","mm") ///Is this diameter???!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1441 WriteHFIRHead(fname,xposstr,"//Motor_Positions/beam_trap_x","mm") ///Is this diameter? 1620 1442 return(0) 1621 1443 End … … 1629 1451 sprintf numstr, "%f", num 1630 1452 1631 WriteHFIRHead(fname,numstr," Sample_Thickness","cm")1453 WriteHFIRHead(fname,numstr,"//Header/Sample_Thickness","cm") 1632 1454 return(0) 1633 1455 End … … 1641 1463 sprintf numstr, "%f", num 1642 1464 1643 WriteHFIRHead(fname,numstr," beam_center_x_pixel" ,"")1465 WriteHFIRHead(fname,numstr,"//Header/beam_center_x_pixel" ,"") 1644 1466 return(0) 1645 1467 End … … 1653 1475 sprintf numstr, "%f", num 1654 1476 1655 WriteHFIRHead(fname,numstr," beam_center_y_pixel","")1477 WriteHFIRHead(fname,numstr,"//Header/beam_center_y_pixel","") 1656 1478 return(0) 1657 1479 End … … 1665 1487 sprintf numstr, "%f", num 1666 1488 1667 WriteHFIRHead(fname,numstr," attenuation","percent") // HFIR has attenuation % instead of this. thus user has to use patch unless somebody change the format!!!!1489 WriteHFIRHead(fname,numstr,"//Motor_Positions/attenuation","percent") // HFIR has attenuation % instead of this. thus user has to use patch unless somebody change the format!!!! 1668 1490 return(0) 1669 1491 End … … 1677 1499 sprintf numstr, "%f", num 1678 1500 1679 WriteHFIRHead(fname,numstr," monitor","")1501 WriteHFIRHead(fname,numstr,"//Counters/monitor","") 1680 1502 return(0) 1681 1503 End … … 1689 1511 sprintf numstr, "%f", num 1690 1512 1691 WriteHFIRHead(fname,numstr," psd","")1513 WriteHFIRHead(fname,numstr,"//Counters/psd","") 1692 1514 return(0) 1693 1515 End … … 1701 1523 sprintf numstr, "%f", num 1702 1524 1703 WriteHFIRHead(fname,numstr," detector","") ///Check with Steve & Ken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1525 WriteHFIRHead(fname,numstr,"//Counters/detector","") ///Check with Steve & Ken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1704 1526 return(0) 1705 1527 End … … 1713 1535 sprintf numstr, "%f", num 1714 1536 1715 WriteHFIRHead(fname,numstr," wavelength" ,"angstroms")1537 WriteHFIRHead(fname,numstr,"//Header/wavelength" ,"angstroms") 1716 1538 return(0) 1717 1539 End … … 1725 1547 sprintf numstr, "%f", num 1726 1548 1727 WriteHFIRHead(fname,numstr," wavelength_spread","")1549 WriteHFIRHead(fname,numstr,"//Header/wavelength_spread","") 1728 1550 return(0) 1729 1551 End … … 1737 1559 sprintf numstr, "%f", num 1738 1560 1739 WriteHFIRHead(fname,numstr," temp" ,"C")1561 WriteHFIRHead(fname,numstr,"//Parameter_Positions/tsample" ,"C") 1740 1562 return(0) 1741 1563 End … … 1749 1571 sprintf numstr, "%f", num 1750 1572 1751 WriteHFIRHead(fname,numstr," magnetic_field","G") //Not defined on HFIR file... Should be changed the name when decided...1573 WriteHFIRHead(fname,numstr,"/SPICErack/magnetic_field","G") //Not defined on HFIR file... Should be changed the name when decided... 1752 1574 return(0) 1753 1575 End … … 1761 1583 sprintf numstr, "%f", num 1762 1584 1763 WriteHFIRHead(fname,numstr," source_aperture_size","mm")1585 WriteHFIRHead(fname,numstr,"//Header/source_aperture_size","mm") 1764 1586 return(0) 1765 1587 End … … 1785 1607 sprintf numstr, "%f", num 1786 1608 1787 WriteHFIRHead(fname,numstr," source_distance","m") //unit=m :hfir = mm ???????????????1609 WriteHFIRHead(fname,numstr,"//Header/source_distance","m") //unit=m :hfir = mm ??????????????? 1788 1610 return(0) 1789 1611 End … … 1797 1619 sprintf numstr, "%f", num 1798 1620 1799 WriteHFIRHead(fname,numstr," detector_trans","cm") //cm: HFIR = mm !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1621 WriteHFIRHead(fname,numstr,"//Header/detector_trans","cm") //cm: HFIR = mm !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1800 1622 return(0) 1801 1623 End … … 1809 1631 sprintf numstr, "%f", num 1810 1632 1811 WriteHFIRHead(fname,numstr," beam_trap_size","mm") //check !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1633 WriteHFIRHead(fname,numstr,"//Motor_Positions/beam_trap_size","mm") //check !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1812 1634 return(0) 1813 1635 End … … 1821 1643 sprintf numstr, "%f", num 1822 1644 1823 WriteHFIRHead(fname,numstr," sample_det_dist","m")1645 WriteHFIRHead(fname,numstr,"//Motor_Positions/sample_det_dist","m") 1824 1646 return(0) 1825 1647 End … … 1833 1655 sprintf numstr, "%f", num 1834 1656 1835 WriteHFIRHead(fname,numstr, " x_mm_per_pixel","mm")1657 WriteHFIRHead(fname,numstr, "//Header/x_mm_per_pixel","mm") 1836 1658 return(0) 1837 1659 End … … 1845 1667 sprintf numstr, "%f", num 1846 1668 1847 WriteHFIRHead(fname,numstr, " y_mm_per_pixel","mm")1669 WriteHFIRHead(fname,numstr, "//Header/y_mm_per_pixel","mm") 1848 1670 return(0) 1849 1671 End … … 1857 1679 str = str[0,59] 1858 1680 endif 1859 WriteHFIRHead(fname,str, " Scan_Title","text") //Users tend to put the sample descrpt here instead of "Sample_Name"...1681 WriteHFIRHead(fname,str, "//Header/Scan_Title","text") //Users tend to put the sample descrpt here instead of "Sample_Name"... 1860 1682 return(0) 1861 1683 End … … 1869 1691 sprintf numstr, "%f", num 1870 1692 1871 WriteHFIRHead(fname,numstr," time","sec")1693 WriteHFIRHead(fname,numstr,"//Counters/time","sec") 1872 1694 return(0) 1873 1695 End … … 1881 1703 1882 1704 Make/O/T/N=(18,2) munit 1883 1884 //length units 1705 1706 //ToDo: to combine the same units 1707 //length units 1885 1708 munit[0][0]="m" //popular units first... 1886 1709 munit[0][1]= "1" … … 1957 1780 Variable val 1958 1781 String from, to 1959 1782 1783 from = RemoveAllSpaces(from) 1784 to = RemoveAllSpaces(to) 1785 1960 1786 Variable i, out = val 1961 1787 1962 1788 //Search for two same strings, or one with none. 1963 1789 if (stringmatch(from,to)>0 ||strlen(from) == 0||strlen(to)==0) … … 1981 1807 String from, to 1982 1808 1983 Variable i, out = val1809 Variable i, j, out = val 1984 1810 1985 1811 Make/O/T/N=(2,2) tunit … … 1989 1815 tunit[1][0]="K" 1990 1816 tunit[1][1]= "0" 1991 1817 1992 1818 String v_from="", v_to="" 1993 1819 1994 1820 for (i = 0; i<DimSize(tunit,0); i+=1) 1995 if (stringmatch(tunit[i][0],from) >0) // IgorPro "stringmatch()" function handles both lower & upper cases.1821 if (stringmatch(tunit[i][0],from)==1) // IgorPro "stringmatch()" function handles both lower & upper cases. 1996 1822 v_from = tunit[i][1] 1997 1823 break 1998 1824 endif 1999 1825 endfor 2000 2001 for ( i = 0; i<DimSize(tunit,0); i+=1)2002 if (stringmatch(tunit[ i][0],to)>0)2003 v_to = tunit[ i][1]1826 1827 for (j = 0; j<DimSize(tunit,0); j+=1) 1828 if (stringmatch(tunit[j][0],to)==1) 1829 v_to = tunit[j][1] 2004 1830 break 2005 1831 endif 2006 1832 endfor 2007 1833 KillWaves/Z tunit 2008 2009 1834 if (strlen(v_from)==0 || strlen(v_to) ==0) 2010 1835 out = 1 //Do nothing... … … 2015 1840 out = val + (vt - vf) 2016 1841 endif 2017 2018 1842 return out 1843 End 1844 1845 1846 ///This function make HFIR SANS data file shorter which is more than 30 characters causing problem taking other names after the file name. 1847 //Will remove instrumental name. 1848 Function/S ShortFileName(fileName) 1849 String fileName 1850 //Default: just passing 1851 String fname = fileName 1852 1853 //Check whether it is from HiResSANS or BioSANS and remove the head 1854 if (stringmatch(fileName,"HiResSANS_*.*")>0 ) 1855 fname = ReplaceString("HiResSANS_",fname,"HS_",0,1) 1856 elseif (stringmatch(filename,"BioSANS_*.*")>0) 1857 fname = ReplaceString("BioSANS_",fname,"BS_",0,1) 1858 endif 1859 return fname 1860 END 1861 1862 //Not used 1863 ///This function return the original HFIR SANS data file name that was shorten before. 1864 //Put them back to HiResSANS*** or BioSANS***. 1865 Function/S FullFileName(fname) 1866 String fname 1867 //Default: just passing 1868 String fileName = fname 1869 1870 //Check whether it is from HiResSANS or BioSANS 1871 if (stringmatch(fname,"*HS_*.*")>0 ) 1872 fileName = ReplaceString("HS_",fname,"HiResSANS_",0,1) 1873 elseif (stringmatch(fname,"*BS_*.*")>0) 1874 fileName = ReplaceString("BS_",fname,"BioSANS_",0,1) 1875 endif 1876 1877 return fileName 1878 END 1879 1880 1881 ///Find file name from full Path+file 1882 Function/S GetFName(path, length) 1883 String path 1884 Variable length // 1 for full name, 0 for shorten name, others pass the name 1885 1886 Variable index 1887 String ofname, mfname 1888 1889 // get index of the file name 1890 index = ItemsInList(path,":") - 1 1891 // get file name 1892 ofname = StringFromList(index,path,":") 1893 //modify the name if need otherwise return w/o change 1894 if (length == 0) 1895 mfname = ShortFileName(ofname) 1896 elseif (length == 1) 1897 mfname = FullFileName(ofname) 1898 else 1899 mfname = ofname 1900 endif 1901 // return the path+modified file name 1902 return mfname 1903 End 1904 1905 1906 ///Find file name from full Path+file and replace file name to a shorter or full name in path+file. 1907 Function/S ReplaceFName(path, length) 1908 String path 1909 Variable length // 1 for full name, 0 for shorten name 1910 1911 Variable index 1912 String ofname,mfname 1913 1914 // get index of the file name 1915 index = ItemsInList(path,":") - 1 1916 // get file name 1917 ofname = StringFromList(index,path,":") 1918 //modify the name if need otherwise return w/o change 1919 if (length == 0) 1920 mfname = ShortFileName(ofname) 1921 else 1922 mfname = FullFileName(ofname) 1923 endif 1924 // return the path+modified file name 1925 return ReplaceString(ofname,path,mfname,0,1) 1926 End 1927 1928 ////Unused ///Not working well 1929 // Change file name before and after Xml open 1930 Function/S XmlFileOpen(fname) 1931 String fname 1932 1933 // fname = path + full file name 1934 fname = ReplaceFName(fname, 1) 1935 XmlOpenFile(fname) 1936 // path + short file name 1937 return ReplaceFName(fname, 0) 2019 1938 End 2020 1939 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_Includes_v520.ipf
r671 r683 13 13 return(0) 14 14 End 15 16 15 17 16 -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/HFIR_Utils.ipf
r647 r683 993 993 return("Function Empty") 994 994 End 995 996 // Return the filename that represents the previous or next file. 997 // Input is current filename and increment. 998 // Increment should be -1 or 1 999 // -1 => previous file 1000 // 1 => next file 1001 Function/S GetPrevNextRawFile(curfilename, prevnext) 1002 String curfilename 1003 Variable prevnext 1004 1005 String filename 1006 1007 //get the run number 1008 Variable num = GetRunNumFromFile(curfilename) 1009 1010 //find the next specified file by number 1011 fileName = FindFileFromRunNumber(num+prevnext) 1012 1013 if(cmpstr(fileName,"")==0) 1014 //null return, do nothing 1015 fileName = FindFileFromRunNumber(num) 1016 Endif 1017 1018 // print "in FU "+filename 1019 1020 Return filename 1021 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ILL_Utils.ipf
r576 r683 987 987 return(ff) 988 988 End 989 990 991 // Return the filename that represents the previous or next file. 992 // Input is current filename and increment. 993 // Increment should be -1 or 1 994 // -1 => previous file 995 // 1 => next file 996 Function/S GetPrevNextRawFile(curfilename, prevnext) 997 String curfilename 998 Variable prevnext 999 1000 String filename 1001 1002 //get the run number 1003 Variable num = GetRunNumFromFile(curfilename) 1004 1005 //find the next specified file by number 1006 fileName = FindFileFromRunNumber(num+prevnext) 1007 1008 if(cmpstr(fileName,"")==0) 1009 //null return, do nothing 1010 fileName = FindFileFromRunNumber(num) 1011 Endif 1012 1013 // print "in FU "+filename 1014 1015 Return filename 1016 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Initialize.ipf
r668 r683 45 45 Endif 46 46 ResizeCmdWindow() 47 48 //unload the NCNR_Package_Loader, if NCNR not defined 49 UnloadNCNR_Igor_Procedures() 50 47 51 End 48 52 … … 159 163 End 160 164 165 // since the NCNR procedures can't be loaded concurrently with the other facility functions, 166 // unload this procedure file, and add this to the functions that run at initialization of the 167 // experiment 168 Function UnloadNCNR_Igor_Procedures() 169 170 #if (exists("NCNR")==6) //defined in the main #includes file. 171 //do nothing if an NCNR reduction experiment 172 #else 173 if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128"))) 174 Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\"" 175 Execute/P "COMPILEPROCEDURES " 176 endif 177 #endif 178 179 End 161 180 162 181 //returns 1 if demo version, 0 if full version -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_Utils.ipf
r680 r683 1366 1366 Endif 1367 1367 1368 print "in FU "+filename1368 // print "in FU "+filename 1369 1369 1370 1370 Return filename
Note: See TracChangeset
for help on using the changeset viewer.