Changeset 201


Ignore:
Timestamp:
Nov 15, 2007 11:29:51 AM (15 years ago)
Author:
srkline
Message:

Added a 2D ASCII export that is compatible with import into Grasp. Added a radio button on the ASCII export panel for the selector.

Added conditional compiles in the WriteQIS file save routines to allow for faster saves, especially the QxQy?

Location:
sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/Tile_2D.ipf

    r116 r201  
    473473        Button button4,pos={330,16},size={25,20},proc=ShowRawExportHelp,title="?" 
    474474        Button button4,help={"Show the help file for 2-D export of raw data files"} 
    475         CheckBox check0,pos={242,66},size={115,14},title="detector coordinates",value= 1,mode=1 
     475        CheckBox check0,pos={220,50},size={115,14},title="detector coordinates",value= 1,mode=1 
    476476        CheckBox check0,proc=RA_ExportCheckProc 
    477         CheckBox check1,pos={242,82},size={104,14},title="Qx,Qy coordinates",value= 0,mode=1 
     477        CheckBox check1,pos={220,66},size={104,14},title="Qx,Qy coordinates",value= 0,mode=1 
    478478        CheckBox check1,proc=RA_ExportCheckProc 
     479        CheckBox check2,pos={220,82},size={104,14},title="Det. Coord, Grasp compatible",value= 0,mode=1 
     480        CheckBox check2,proc=RA_ExportCheckProc 
    479481EndMacro 
    480482 
     
    487489                        CheckBox check0,value=1 
    488490                        CheckBox check1,value=0 
     491                        CheckBox check2,value=0 
    489492                        break 
    490493                case "check1": 
    491494                        CheckBox check0,value=0 
    492495                        CheckBox check1,value=1 
     496                        CheckBox check2,value=0 
     497                        break 
     498                case "check2": 
     499                        CheckBox check0,value=0 
     500                        CheckBox check1,value=0 
     501                        CheckBox check2,value=1 
    493502        endswitch 
    494503        return(0) 
     
    541550        Wave/T fileWave=$"root:myGlobals:RAW2ASCII:fileWave" 
    542551        Wave sel=$"root:myGlobals:RAW2ASCII:selWave" 
    543         Variable num=numpnts(sel),ii=0,qxqy=0 
     552        Variable num=numpnts(sel),ii=0,qxqy=0,detCoord=0,GraspASCII=0 
    544553        String fname="",pathStr="",fullPath="",newFileName="" 
    545554         
     
    547556        pathStr=S_path 
    548557         
    549         //what type of export? check1 is qxqy 
     558        //what type of export? 
     559        // check0 is det coord, check1 is QxQy, check2 is old-style VAX ASCII for Grasp 
     560        ControlInfo check0 
     561        detCoord=V_Value                //==1 if detCoord desired 
    550562        ControlInfo check1 
    551563        qxqy=V_Value            //==1 if qxqy desired 
     564        ControlInfo check2 
     565        GraspASCII=V_Value              //==1 if GraspASCII desired 
    552566         
    553567        // get the current state 
     
    563577                        WAVE/T/Z tw = $"root:RAW:textRead"      //to be sure that wave exists if no data was ever displayed 
    564578                        newFileName= GetNameFromHeader(tw[0]) 
    565                         if(qxqy==1) 
     579                         
     580                        if(qxqy) 
    566581                                fullPath=pathStr+newFileName+".DAT" 
    567582                                QxQy_Export("RAW",fullpath,0) 
    568                         else 
     583                        endif 
     584                        if(detCoord) 
    569585                                fullPath=pathStr+newFileName+".ASC" 
    570586                                Fast2dExport("RAW",fullpath,0) 
     587                        endif 
     588                        if(GraspASCII) 
     589                                fullPath=pathStr+newFileName+"_G.ASC" 
     590                                Fast2dExport_OldStyle("RAW",fullpath,0) 
    571591                        endif 
    572592                endif 
  • sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/WriteQIS.ipf

    r116 r201  
    336336        Variable dialog         //=1 will present dialog for name 
    337337         
     338        Variable enter=StopMSTimer(-2) 
     339         
    338340        String destStr="",ave="C",typeStr="" 
    339341        Variable step=1,refnum 
     
    394396        Endif 
    395397         
     398        Print "Before fill = ",(StopMSTimer(-2) - enter)/1e6 
    396399///////// 
    397400        Variable numTextLines=18 
     
    431434//              termStr = "\r\n" 
    432435//      Endif 
     436 
     437        Print "After fill = ",(StopMSTimer(-2) - enter)/1e6 
    433438         
    434439        Duplicate/O data,spWave          
    435440        Redimension/S/N=(pixelsX*pixelsY) spWave                //single precision (/S) 
    436441         
    437         //not demo- compatible, but approx 6x faster!! 
    438 //      Save/G/M="\r\n" labelWave,spWave as fullPath            // /M=termStr specifies terminator 
    439         /// 
    440          
     442        Print "Before save = ",(StopMSTimer(-2) - enter)/1e6 
     443        //not demo- compatible, but approx 100x faster!! 
     444         
     445#if(cmpstr(stringbykey("IGORKIND",IgorInfo(0),":",";"),"pro") == 0) 
     446        Save/G/M="\r\n" labelWave,spWave as fullPath 
     447#else 
    441448        Open refNum as fullpath 
    442449        wfprintf refNum,"%s\r\n",labelWave 
     
    444451        wfprintf refNum,"%g\r\n",spWave 
    445452        Close refNum 
    446          
     453#endif 
     454 
    447455        Killwaves/Z spWave,labelWave            //don't delete proto! 
    448456         
    449457        Print "2D ASCII File written: ", GetFileNameFromPathNoSemi(fullPath) 
     458         
     459        Print "Before exit = ",(StopMSTimer(-2) - enter)/1e6 
    450460        return(0) 
    451461End 
     462 
     463 
     464//// ASCII EXPORT in detector coordinates - mimicking the VAX ASCII/128 command 
     465// this is done simply to be able to produce converted raw data files that can be  
     466// read in with Grasp. A rather awkward structure, definitely not the preferred export format 
     467// 
     468// SRK 14 NOV 07 
     469// 
     470Function Fast2dExport_OldStyle(type,fullpath,dialog) 
     471        String type,fullpath 
     472        Variable dialog         //=1 will present dialog for name 
     473         
     474        Variable enter=StopMSTimer(-2) 
     475         
     476        String destStr="" 
     477        String typeStr="" 
     478        Variable refnum 
     479         
     480        destStr = "root:"+type 
     481         
     482        //must select the linear_data to export 
     483        // can't export log data if there are -ve intensities from a subtraction 
     484        NVAR isLog = $(destStr+":gIsLogScale") 
     485        if(isLog==1) 
     486                typeStr = ":linear_data" 
     487        else 
     488                typeStr = ":data" 
     489        endif 
     490         
     491        NVAR pixelsX = root:myGlobals:gNPixelsX 
     492        NVAR pixelsY = root:myGlobals:gNPixelsY 
     493         
     494        Wave data=$(destStr+typeStr) 
     495        WAVE intw=$(destStr + ":integersRead") 
     496        WAVE rw=$(destStr + ":realsRead") 
     497        WAVE/T textw=$(destStr + ":textRead") 
     498 
     499        //check each wave - MUST exist, or will cause a crash 
     500        If(!(WaveExists(data))) 
     501                Abort "data DNExist AsciiExport()" 
     502        Endif 
     503        If(!(WaveExists(intw))) 
     504                Abort "intw DNExist AsciiExport()" 
     505        Endif 
     506        If(!(WaveExists(rw))) 
     507                Abort "rw DNExist AsciiExport()" 
     508        Endif 
     509        If(!(WaveExists(textw))) 
     510                Abort "textw DNExist AsciiExport()" 
     511        Endif 
     512 
     513        if(dialog) 
     514                PathInfo/S catPathName 
     515                fullPath = DoSaveFileDialog("Save data as") 
     516                If(cmpstr(fullPath,"")==0) 
     517                        //user cancel, don't write out a file 
     518                        Close/A 
     519                        Abort "no data file was written" 
     520                Endif 
     521                //Print "dialog fullpath = ",fullpath 
     522        Endif 
     523         
     524        Print "Before fill = ",(StopMSTimer(-2) - enter)/1e6 
     525///////// 
     526        String tmpStr="" 
     527        Variable numTextLines=17 
     528        Make/O/T/N=(numTextLines) labelWave 
     529         
     530        sprintf tmpStr," '%s'   '%s'   '%s'",textw[0],textw[1],textw[2] 
     531        labelWave[0] = tmpStr 
     532        labelWave[1] = textw[6]         //label 
     533        sprintf tmpStr," %d   %g   %g   %g",intw[2],rw[0],rw[39],rw[2] 
     534        labelWave[2] = tmpStr 
     535        labelWave[3] = " Cnt.Time(sec.)    Mon. Cnt.      Trans. Det. Cnt.  Tot. Det. Cnt." 
     536        sprintf tmpStr," %g   %g   %g   %g   %d   %d   %g",rw[4],rw[5],rw[8],rw[9],intw[4],intw[5],rw[6] 
     537        labelWave[4] = tmpStr 
     538        labelWave[5] = " Trans.      Thckns       Temp.           H Field         Table  Holder  Pos" 
     539        sprintf tmpStr," %g   %g   %d   '%s'   %g",rw[26],rw[27],intw[9],textw[9],rw[7] 
     540        labelWave[6] = tmpStr 
     541        labelWave[7] = " Wavelength &  Spread(FWHM)    Det.#  Type      Sample Rotation Angle" 
     542        sprintf tmpStr," %g   %g   %g   %g   %g   %g",rw[18],rw[19],rw[16],rw[17],rw[21],rw[3] 
     543        labelWave[8] = tmpStr 
     544        labelWave[9] = " Sam-Det Dis.(m)   Det.Ang.(cm.)   Beam Center(x,y)  Beam Stop(mm)  Atten.No." 
     545        sprintf tmpStr," %g   %g   %g   %g   %g   %g",rw[10],rw[11],rw[12],rw[13],rw[14],rw[15] 
     546        labelWave[10] = tmpStr 
     547        labelWave[11] = "        Det. Calib Consts. (x)           Det. Calib Consts. (y)" 
     548        sprintf tmpStr," %g  %g  %g  '%s'   %g   %g",rw[23],rw[24],rw[25],"    F",rw[32],rw[32] 
     549        labelWave[12] = tmpStr 
     550        labelWave[13] = " Aperture (A1,A2) Sizes(mm)    Sep.(m)    Flip ON   Horiz. and Vert. Cur.(amps)" 
     551        sprintf tmpStr," %d  %d  %d  %d  %g  %g  %g",intw[19],intw[20],intw[21],intw[22],rw[47],rw[48],rw[49] 
     552        labelWave[14] = tmpStr 
     553        labelWave[15] = "      Rows        Cols       Factor   Qmin      Qmax" 
     554        labelWave[16] = " Packed Counts by Rows (L -> R) and Top -> Bot" 
     555          
     556        //strings can be too long to print-- must trim to 255 chars 
     557        Variable ii 
     558        for(ii=0;ii<numTextLines;ii+=1) 
     559                labelWave[ii] = (labelWave[ii])[0,240] 
     560        endfor 
     561 
     562        Print "After fill = ",(StopMSTimer(-2) - enter)/1e6 
     563         
     564        Duplicate/O data,spWave          
     565        Redimension/S/N=(pixelsX*pixelsY) spWave                //single precision (/S) 
     566         
     567//      now need to convert the wave of data points into row of no more than 80 characters 
     568// per row, comma delimited, not splitting any values 
     569        Make/O/T/N=0 tw 
     570         
     571        Variable sPt,ePt,ind=0,len 
     572        sPt=0 
     573        ePt=0 
     574        len = pixelsX*pixelsY 
     575        do 
     576                tmpStr = Fill80Chars(spWave,sPt,ePt,len) 
     577                InsertPoints ind, 1, tw 
     578                tw[ind]=tmpStr 
     579                ind+=1 
     580//              Print "at top, ePt = ",ePt 
     581                sPt=ePt 
     582        while(ePt<len-1) 
     583         
     584        Print "Before save = ",(StopMSTimer(-2) - enter)/1e6 
     585         
     586        Open refNum as fullpath 
     587        wfprintf refNum,"%s\r",labelWave                        //VAX uses just \r 
     588        wfprintf refNum,"%s\r",tw 
     589        Close refNum 
     590         
     591        Killwaves/Z spWave,labelWave,tw         //clean up 
     592         
     593        Print "2D ASCII File written for Grasp: ", GetFileNameFromPathNoSemi(fullPath) 
     594         
     595        Print "Before exit = ",(StopMSTimer(-2) - enter)/1e6 
     596        return(0) 
     597End 
     598 
     599Function/S Fill80chars(w,sPt,ePt,len) 
     600        Wave w 
     601        Variable sPt,&ePt,len 
     602         
     603        String retStr 
     604        Variable numChars=1,numPt=0 
     605         
     606        retStr = " "            //lines start with a space 
     607        do 
     608                if( (numChars + strlen(num2str(w[sPt+numPt])) + 1 <= 80)         && (sPt + numPt) < len ) 
     609                        retStr += num2str(w[sPt+numPt]) +"," 
     610                        numChars += strlen(num2str(w[sPt+numPt])) + 1 
     611                        numPt += 1 
     612                else 
     613                        // pad to 80 chars 
     614                        ePt = sPt + numPt 
     615                        if(strlen(retStr) < 80) 
     616                                do 
     617                                        retStr += " " 
     618                                while(strlen(retStr) < 80) 
     619                        endif 
     620//                      Print strlen(retStr),sPt,ePt 
     621                        break 
     622                endif 
     623        while(1) 
     624         
     625        return(retStr) 
     626End 
     627 
     628//// end ASCII - old style export procedures 
    452629 
    453630 
     
    565742        qy_val = CalcQy(qy_val+1,rw[17],rw[18],rw[26]) 
    566743 
    567         //not demo-compatible, but approx 8x faster!!            
    568 //      Save/G/M="\r\n" labelWave,qx_val,qy_val,z_val as fullpath       // /M=termStr specifies terminator 
    569         // 
    570          
     744        //not demo-compatible, but approx 8x faster!!    
     745#if(cmpstr(stringbykey("IGORKIND",IgorInfo(0),":",";"),"pro") == 0)      
     746        Save/G/M="\r\n" labelWave,qx_val,qy_val,z_val as fullpath       // /M=termStr specifies terminator 
     747#else 
    571748        Open refNum as fullpath 
    572749        wfprintf refNum,"%s\r\n",labelWave 
     
    574751        wfprintf refNum,"%8g\t%8g\t%8g\r\n",qx_val,qy_val,z_val 
    575752        Close refNum 
     753#endif 
    576754         
    577755        Killwaves/Z spWave,labelWave,qx_val,qy_val,z_val 
Note: See TracChangeset for help on using the changeset viewer.