Changeset 71


Ignore:
Timestamp:
Mar 29, 2007 5:07:06 PM (15 years ago)
Author:
srkline
Message:

many changes to PatchFiles?.ipf to get the reads and writes separated
and put into NCNR_DataReadWrite.ipf

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

Legend:

Unmodified
Added
Removed
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/NCNR_DataReadWrite.ipf

    r70 r71  
    907907End 
    908908 
     909//rewrite a text field back to the header 
     910// fname is the full path:name 
     911// str is the CORRECT length - it will all be written - pad before sending 
     912// start is the start byte 
     913Function RewriteTextToHeader(fname,str,start) 
     914        String fname,str 
     915        Variable start 
     916         
     917        Variable refnum 
     918        Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing! 
     919        FSetPos refnum,start 
     920        FBinWrite/F=0 refnum, str      //native object format (character) 
     921        //move to the end of the file before closing 
     922        FStatus refnum 
     923        FSetPos refnum,V_logEOF 
     924        //Print "Wrote end of header to " + num2str(V_filePOS) 
     925        Close refnum 
     926                 
     927        return(0) 
     928end 
     929 
     930//rewrite an integer field back to the header 
     931// fname is the full path:name 
     932// val is the integer value 
     933// start is the start byte 
     934Function RewriteIntegerToHeader(fname,val,start) 
     935        String fname 
     936        Variable val,start 
     937         
     938        Variable refnum 
     939        Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing! 
     940        FSetPos refnum,31 
     941        FBinWrite/B=3/F=3 refnum, val      //write a 4-byte integer 
     942        //move to the end of the file before closing 
     943        FStatus refnum 
     944        FSetPos refnum,V_logEOF 
     945        //Print "Wrote end of header to " + num2str(V_filePOS) 
     946        Close refnum 
     947                 
     948        return(0) 
     949end 
     950 
    909951// read specific bits of information from the header 
    910952// each of these operations MUST take care of open/close on their own 
     
    951993End 
    952994 
     995//monitor count is at byte 39 
     996Function getMonitorCount(fname) 
     997        String fname 
     998         
     999        return(getRealValueFromHeader(fname,39)) 
     1000end 
     1001 
     1002//saved monitor count is at byte 43 
     1003Function getSavMon(fname) 
     1004        String fname 
     1005         
     1006        return(getRealValueFromHeader(fname,43)) 
     1007end 
     1008 
     1009//detector count is at byte 47 
     1010Function getDetCount(fname) 
     1011        String fname 
     1012         
     1013        return(getRealValueFromHeader(fname,47)) 
     1014end 
     1015 
     1016//Attenuator number is at byte 51 
     1017Function getAttenNumber(fname) 
     1018        String fname 
     1019         
     1020        return(getRealValueFromHeader(fname,51)) 
     1021end 
     1022 
     1023//transmission is at byte 158 
     1024Function getSampleTrans(fname) 
     1025        String fname 
     1026         
     1027        return(getRealValueFromHeader(fname,158)) 
     1028end 
     1029 
     1030//SampleThickness is at byte 162 
     1031Function getSampleThickness(fname) 
     1032        String fname 
     1033         
     1034        return(getRealValueFromHeader(fname,162)) 
     1035end 
     1036 
     1037//temperature is at byte 186 
     1038Function getTemperature(fname) 
     1039        String fname 
     1040         
     1041        return(getRealValueFromHeader(fname,186)) 
     1042end 
     1043 
     1044//field strength is at byte 190 
     1045Function getFieldStrength(fname) 
     1046        String fname 
     1047         
     1048        return(getRealValueFromHeader(fname,190)) 
     1049end 
     1050 
     1051//beamstop xPos is at byte 252 
     1052Function getBSXPos(fname) 
     1053        String fname 
     1054         
     1055        return(getRealValueFromHeader(fname,252)) 
     1056end 
     1057 
     1058//beamstop Y pos is at byte 256 
     1059Function getBSYPos(fname) 
     1060        String fname 
     1061         
     1062        return(getRealValueFromHeader(fname,256)) 
     1063end 
     1064 
    9531065//SDD is at byte 260 
    9541066Function getSDD(fname) 
     
    9571069        return(getRealValueFromHeader(fname,260)) 
    9581070end 
     1071 
     1072//detector offset is at byte 264 
     1073Function getDetectorOffset(fname) 
     1074        String fname 
     1075         
     1076        return(getRealValueFromHeader(fname,264)) 
     1077end 
     1078 
     1079//Beamstop diameter is at byte 272 
     1080Function getBSDiameter(fname) 
     1081        String fname 
     1082         
     1083        return(getRealValueFromHeader(fname,272)) 
     1084end 
     1085 
     1086//source aperture diameter is at byte 280 
     1087Function getSourceApertureDiam(fname) 
     1088        String fname 
     1089         
     1090        return(getRealValueFromHeader(fname,280)) 
     1091end 
     1092 
     1093//sample aperture diameter is at byte 284 
     1094Function getSampleApertureDiam(fname) 
     1095        String fname 
     1096         
     1097        return(getRealValueFromHeader(fname,284)) 
     1098end 
     1099 
     1100//source AP to Sample AP distance is at byte 288 
     1101Function getSourceToSampleDist(fname) 
     1102        String fname 
     1103         
     1104        return(getRealValueFromHeader(fname,288)) 
     1105end 
     1106 
     1107//wavelength is at byte 292 
     1108Function getWavelength(fname) 
     1109        String fname 
     1110         
     1111        return(getRealValueFromHeader(fname,292)) 
     1112end 
     1113 
     1114//wavelength spread is at byte 296 
     1115Function getWavelengthSpread(fname) 
     1116        String fname 
     1117         
     1118        return(getRealValueFromHeader(fname,296)) 
     1119end 
     1120 
     1121//transmission detector count is at byte 388 
     1122Function getTransDetectorCounts(fname) 
     1123        String fname 
     1124         
     1125        return(getRealValueFromHeader(fname,388)) 
     1126end 
     1127 
     1128 
     1129 
     1130Function getIntegerFromHeader(fname,start) 
     1131        String fname                            //full path:name 
     1132        Variable start          //starting byte 
     1133         
     1134        Variable refnum,val 
     1135        Open/R refNum as fname 
     1136        FSetPos refNum,start 
     1137        FBinRead/B=3/F=3 refnum,val 
     1138        Close refnum 
     1139         
     1140        return(val) 
     1141End 
     1142 
     1143//total count time is at byte 31         
     1144Function getCountTime(fname) 
     1145        String fname 
     1146        return(getIntegerFromHeader(fname,31)) 
     1147end 
     1148 
     1149 
    9591150//reads the wavelength from a reduced data file (not very reliable) 
    9601151// - does not work with NSORTed files 
  • sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/PatchFiles.ipf

    r59 r71  
    417417        //change the sample label ? 
    418418        if(change[0]) 
    419                 Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing! 
    420                 textstr = textVal[0] 
    421                 FSetPos refnum,98 
    422                 FBinWrite/F=0 refnum, textstr      //native object format (character) 
    423                 //move to the end of the file before closing 
    424                 FStatus refnum 
    425                 FSetPos refnum,V_logEOF 
    426                 //Print "Wrote end of header to " + num2str(V_filePOS) 
    427          
    428                 Close refnum 
     419                RewriteTextToHeader(fname,textVal[0],98) 
    429420        Endif 
    430421         
    431422        //total count time is an integer, handle separately 
    432423        if(change[6]) 
    433                 Open/A/T="????TEXT" refnum as fname      //Open for writing! Move to EOF before closing! 
    434424                num =str2num(textVal[6]) 
    435                 FSetPos refnum,31 
    436                 FBinWrite/B=3/F=3 refnum, num      //write a 4-byte integer 
    437                 //move to the end of the file before closing 
    438                 FStatus refnum 
    439                 FSetPos refnum,V_logEOF 
    440                 //Print "Wrote end of header to " + num2str(V_filePOS) 
    441          
    442                 Close refnum 
     425                RewriteIntegerToHeader(fname,num,31) 
    443426        Endif 
    444427         
     
    689672End 
    690673 
    691  
    692674//This function will read only the selected values editable in the patch panel 
    693675//The values read are passed to the panel through the global variables 
     
    701683        //just reset the global variables that are on the patch panel 
    702684         
    703         Variable refNum,integer,realval 
    704         String textstr="" 
    705         Variable countTime 
    706          
    707         //full filename with path is passed in 
    708         //actually open the file 
    709         Open/R refNum as fname 
    710          
    711         // read the sample.label text field 
    712         FSetPos refNum,98          //will start reading at byte 99 
    713         FReadLine/N=60 refNum,textstr 
    714         FSetPos refNum,31 
    715         FBinRead/B=3/F=3 refnum,countTime 
    716          
    717         Close refNum 
    718          
    719         //Print "countTime = ",countTime 
    720          
    721         //now get all of the reals 
    722         // 
    723         //Do all the GBLoadWaves at the end 
    724         // 
    725         //FBinRead Cannot handle 32 bit VAX floating point 
    726         //GBLoadWave, however, can properly read it 
    727         String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
    728         String strToExecute 
    729         //append "/S=offset/U=numofreals" to control the read 
    730         // then append fname to give the full file path 
    731         // then execute 
    732          
    733         // NEW reads 
    734         Variable moncnt,savmon,detcnt,atten,trans,thick,temp,field 
    735         Variable dis,ang,bstop,ap1,ap2,ap12dis,lmda,dlmda,beamx,beamy,trnscnt 
    736          
    737         strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" 
    738         Execute strToExecute 
    739         Wave w=$"tempGBWave0" 
    740         moncnt = w[0] 
    741         savmon = w[1] 
    742         detcnt = w[2] 
    743         atten = w[3] 
    744         //printf "moncnt = %g,savmon = %g,detcnt = %g,atten = %g\r",moncnt,savmon,detcnt,atten 
    745          
    746         strToExecute = GBLoadStr + "/S=158/U=2" + "\"" + fname + "\"" 
    747         Execute strToExecute 
    748         trans = w[0] 
    749         thick = w[1] 
    750         //printf "trans = %g, thick = %g\r",trans,thick 
    751          
    752         strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" 
    753         Execute strToExecute 
    754         temp = w[0] 
    755         field = w[1] 
    756         //printf "temp = %g, field = %g\r",temp,field 
    757          
    758         strToExecute = GBLoadStr + "/S=252/U=12" + "\"" + fname + "\"" 
    759         Execute strToExecute 
    760         beamx = w[0] 
    761         beamy = w[1] 
    762         dis = w[2] 
    763         ang = w[3] 
    764         // w[4] det size 
    765         bstop = w[5] 
    766         // w[6] blank 
    767         ap1 = w[7] 
    768         ap2 = w[8] 
    769         ap12dis = w[9] 
    770         lmda = w[10] 
    771         dlmda = w[11] 
    772         //printf "beamx = %g, beamy = %g\r",beamx,beamy 
    773         //printf "dis = %g,ang = %g, bstop = %g,ap1= %g,ap2 = %g\r",dis,ang,bstop,ap1,ap2 
    774         //printf "ap12dis = %g, lmda = %g, dlmda = %g\r",ap12dis,lmda,dlmda 
    775          
    776         strToExecute = GBLoadStr + "/S=388/U=1" + "\"" + fname + "\"" 
    777         Execute strToExecute 
    778         trnscnt = w[0] 
    779         //printf "trnscnt = %g\r",trnscnt 
     685//      Variable refNum,integer,realval 
     686//      String textstr="" 
     687//      Variable countTime 
     688//       
     689//      //full filename with path is passed in 
     690//      //actually open the file 
     691//      Open/R refNum as fname 
     692//       
     693//      // read the sample.label text field 
     694//      FSetPos refNum,98          //will start reading at byte 99 
     695//      FReadLine/N=60 refNum,textstr 
     696//      FSetPos refNum,31 
     697//      FBinRead/B=3/F=3 refnum,countTime 
     698//       
     699//      Close refNum 
     700//       
     701//      //Print "countTime = ",countTime 
     702//       
     703//      //now get all of the reals 
     704//      // 
     705//      //Do all the GBLoadWaves at the end 
     706//      // 
     707//      //FBinRead Cannot handle 32 bit VAX floating point 
     708//      //GBLoadWave, however, can properly read it 
     709//      String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" 
     710//      String strToExecute 
     711//      //append "/S=offset/U=numofreals" to control the read 
     712//      // then append fname to give the full file path 
     713//      // then execute 
     714//       
     715//      // NEW reads 
     716//      Variable moncnt,savmon,detcnt,atten,trans,thick,temp,field 
     717//      Variable dis,ang,bstop,ap1,ap2,ap12dis,lmda,dlmda,beamx,beamy,trnscnt 
     718//       
     719//      strToExecute = GBLoadStr + "/S=39/U=4" + "\"" + fname + "\"" 
     720//      Execute strToExecute 
     721//      Wave w=$"tempGBWave0" 
     722//      moncnt = w[0] 
     723//      savmon = w[1] 
     724//      detcnt = w[2] 
     725//      atten = w[3] 
     726//      //printf "moncnt = %g,savmon = %g,detcnt = %g,atten = %g\r",moncnt,savmon,detcnt,atten 
     727//       
     728//      strToExecute = GBLoadStr + "/S=158/U=2" + "\"" + fname + "\"" 
     729//      Execute strToExecute 
     730//      trans = w[0] 
     731//      thick = w[1] 
     732//      //printf "trans = %g, thick = %g\r",trans,thick 
     733//       
     734//      strToExecute = GBLoadStr + "/S=186/U=2" + "\"" + fname + "\"" 
     735//      Execute strToExecute 
     736//      temp = w[0] 
     737//      field = w[1] 
     738//      //printf "temp = %g, field = %g\r",temp,field 
     739//       
     740//      strToExecute = GBLoadStr + "/S=252/U=12" + "\"" + fname + "\"" 
     741//      Execute strToExecute 
     742//      beamx = w[0] 
     743//      beamy = w[1] 
     744//      dis = w[2] 
     745//      ang = w[3] 
     746//      // w[4] det size 
     747//      bstop = w[5] 
     748//      // w[6] blank 
     749//      ap1 = w[7] 
     750//      ap2 = w[8] 
     751//      ap12dis = w[9] 
     752//      lmda = w[10] 
     753//      dlmda = w[11] 
     754//      //printf "beamx = %g, beamy = %g\r",beamx,beamy 
     755//      //printf "dis = %g,ang = %g, bstop = %g,ap1= %g,ap2 = %g\r",dis,ang,bstop,ap1,ap2 
     756//      //printf "ap12dis = %g, lmda = %g, dlmda = %g\r",ap12dis,lmda,dlmda 
     757//       
     758//      strToExecute = GBLoadStr + "/S=388/U=1" + "\"" + fname + "\"" 
     759//      Execute strToExecute 
     760//      trnscnt = w[0] 
     761//      //printf "trnscnt = %g\r",trnscnt 
     762//       
     763//      //assign to the globals for display in the panel 
     764//      String/G root:myGlobals:Patch:gPS1= textstr 
     765//      Variable/G root:myGlobals:Patch:gPV1 = trans 
     766//      Variable/G root:myGlobals:Patch:gPV2 = thick 
     767//      Variable/G root:myGlobals:Patch:gPV3 = beamx 
     768//      Variable/G root:myGlobals:Patch:gPV4 = beamy 
     769//      Variable/G root:myGlobals:Patch:gPV5 = atten 
     770//      Variable/G root:myGlobals:Patch:gPV6 = countTime 
     771//      Variable/G root:myGlobals:Patch:gPV7 = moncnt 
     772//      Variable/G root:myGlobals:Patch:gPV8 = detcnt 
     773//      Variable/G root:myGlobals:Patch:gPV9 = trnscnt 
     774//      Variable/G root:myGlobals:Patch:gPV10 = lmda 
     775//      Variable/G root:myGlobals:Patch:gPV11 = dlmda 
     776//      Variable/G root:myGlobals:Patch:gPV12 = temp 
     777//      Variable/G root:myGlobals:Patch:gPV13 = field 
     778//      Variable/G root:myGlobals:Patch:gPV14 = ap1 
     779//      Variable/G root:myGlobals:Patch:gPV15 = ap2 
     780//      Variable/G root:myGlobals:Patch:gPV16 = ap12dis 
     781//      Variable/G root:myGlobals:Patch:gPV17 = ang 
     782//      Variable/G root:myGlobals:Patch:gPV18 = bstop 
     783//      Variable/G root:myGlobals:Patch:gPV19 = dis 
     784//       
     785//      //clean up - get rid of w = $"tempGBWave0" 
     786//      KillWaves/Z w 
     787         
     788        // each "get" is an individual call to GBLoadWave... 
     789        // test for acceptable speed over a network... 
    780790         
    781791        //assign to the globals for display in the panel 
    782         String/G root:myGlobals:Patch:gPS1= textstr 
    783         Variable/G root:myGlobals:Patch:gPV1 = trans 
    784         Variable/G root:myGlobals:Patch:gPV2 = thick 
    785         Variable/G root:myGlobals:Patch:gPV3 = beamx 
    786         Variable/G root:myGlobals:Patch:gPV4 = beamy 
    787         Variable/G root:myGlobals:Patch:gPV5 = atten 
    788         Variable/G root:myGlobals:Patch:gPV6 = countTime 
    789         Variable/G root:myGlobals:Patch:gPV7 = moncnt 
    790         Variable/G root:myGlobals:Patch:gPV8 = detcnt 
    791         Variable/G root:myGlobals:Patch:gPV9 = trnscnt 
    792         Variable/G root:myGlobals:Patch:gPV10 = lmda 
    793         Variable/G root:myGlobals:Patch:gPV11 = dlmda 
    794         Variable/G root:myGlobals:Patch:gPV12 = temp 
    795         Variable/G root:myGlobals:Patch:gPV13 = field 
    796         Variable/G root:myGlobals:Patch:gPV14 = ap1 
    797         Variable/G root:myGlobals:Patch:gPV15 = ap2 
    798         Variable/G root:myGlobals:Patch:gPV16 = ap12dis 
    799         Variable/G root:myGlobals:Patch:gPV17 = ang 
    800         Variable/G root:myGlobals:Patch:gPV18 = bstop 
    801         Variable/G root:myGlobals:Patch:gPV19 = dis 
    802          
    803         //clean up - get rid of w = $"tempGBWave0" 
    804         KillWaves/Z w 
     792        String/G root:myGlobals:Patch:gPS1= getSampleLabel(fname) 
     793        Variable/G root:myGlobals:Patch:gPV1 = getSampleTrans(fname) 
     794        Variable/G root:myGlobals:Patch:gPV2 = getSampleThickness(fname) 
     795        Variable/G root:myGlobals:Patch:gPV3 = getBSXPos(fname) 
     796        Variable/G root:myGlobals:Patch:gPV4 = getBSYPos(fname) 
     797        Variable/G root:myGlobals:Patch:gPV5 = getAttenNumber(fname) 
     798        Variable/G root:myGlobals:Patch:gPV6 = getCountTime(fname) 
     799        Variable/G root:myGlobals:Patch:gPV7 = getMonitorCount(fname) 
     800        Variable/G root:myGlobals:Patch:gPV8 = getDetCount(fname) 
     801        Variable/G root:myGlobals:Patch:gPV9 = getTransDetectorCounts(fname) 
     802        Variable/G root:myGlobals:Patch:gPV10 = getWavelength(fname) 
     803        Variable/G root:myGlobals:Patch:gPV11 = getWavelengthSpread(fname) 
     804        Variable/G root:myGlobals:Patch:gPV12 = getTemperature(fname) 
     805        Variable/G root:myGlobals:Patch:gPV13 = getFieldStrength(fname) 
     806        Variable/G root:myGlobals:Patch:gPV14 = getSourceApertureDiam(fname) 
     807        Variable/G root:myGlobals:Patch:gPV15 = getSampleApertureDiam(fname) 
     808        Variable/G root:myGlobals:Patch:gPV16 = getSourceToSampleDist(fname) 
     809        Variable/G root:myGlobals:Patch:gPV17 = getDetectorOffset(fname) 
     810        Variable/G root:myGlobals:Patch:gPV18 = getBSDiameter(fname) 
     811        Variable/G root:myGlobals:Patch:gPV19 = getSDD(fname) 
    805812         
    806813        Return 0 
Note: See TracChangeset for help on using the changeset viewer.