Ignore:
Timestamp:
Nov 4, 2009 12:52:13 PM (13 years ago)
Author:
srkline
Message:

Cosmetic changes to monteCarlo code. Added some ".0" here and there to make sure that all of the numerical values are really interpreted as floating point. Also changed the variable "result" to be "retVal" to avoid confusion with the wave of returned values "results"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/XOP_Dev/MonteCarlo/MonteCarlo.c

    r552 r591  
    5151//      double *MC_linear_data;                         /* pointer to double precision wave data */ 
    5252        double *results;                                /* pointer to double precision wave data */ 
    53         double result;                          //return value 
     53        double retVal;                          //return value 
    5454 
    5555        long imon; 
     
    8686        /* check that wave handles are all valid */ 
    8787        if (p->inputWaveH == NIL) { 
    88                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     88                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    8989                return(NON_EXISTENT_WAVE); 
    9090        } 
    9191        if (p->ran_devH == NIL) { 
    92                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     92                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    9393                return(NON_EXISTENT_WAVE); 
    9494        }        
    9595        if (p->ntH == NIL) { 
    96                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     96                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    9797                return(NON_EXISTENT_WAVE); 
    9898        } 
    9999        if (p->j1H == NIL) { 
    100                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     100                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    101101                return(NON_EXISTENT_WAVE); 
    102102        } 
    103103        if (p->j2H == NIL) { 
    104                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     104                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    105105                return(NON_EXISTENT_WAVE); 
    106106        } 
    107107        if (p->nnH == NIL) { 
    108                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     108                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    109109                return(NON_EXISTENT_WAVE); 
    110110        } 
    111111        if (p->MC_linear_dataH == NIL) { 
    112                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     112                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    113113                return(NON_EXISTENT_WAVE); 
    114114        } 
    115115        if (p->resultsH == NIL) { 
    116                 SetNaN64(&p->result);                                   /* return NaN if wave is not valid */ 
     116                SetNaN64(&p->retVal);                                   /* return NaN if wave is not valid */ 
    117117                return(NON_EXISTENT_WAVE); 
    118118        } 
    119119         
    120         p->result = 0; 
     120        p->retVal = 0.0; 
    121121         
    122122// trusting that all inputs are DOUBLE PRECISION WAVES!!! 
     
    157157         
    158158        dummy = MDGetWaveScaling(p->ran_devH, 0, &delta, &left);                //0 is the rows 
    159         if (result = MDGetWaveDimensions(p->ran_devH, &numDimensions, dimensionSizes)) 
    160                 return result; 
     159        if (retVal = MDGetWaveDimensions(p->ran_devH, &numDimensions, dimensionSizes)) 
     160                return retVal; 
    161161        numRows_ran_dev = dimensionSizes[0]; 
    162162         
     
    173173//      if (waveType==TEXT_WAVE_TYPE) 
    174174//              return NUMERIC_ACCESS_ON_TEXT_WAVE; 
    175 //      if (result = MDGetWaveDimensions(wavH, &numDimensions, dimensionSizes)) 
    176 //              return result; 
     175//      if (retVal = MDGetWaveDimensions(wavH, &numDimensions, dimensionSizes)) 
     176//              return retVal; 
    177177//      numRows = dimensionSizes[0]; 
    178178//      numColumns = dimensionSizes[1]; 
    179179         
    180 //      if (result = MDAccessNumericWaveData(wavH, kMDWaveAccessMode0, &dataOffset)) 
    181 //              return result; 
     180//      if (retVal = MDAccessNumericWaveData(wavH, kMDWaveAccessMode0, &dataOffset)) 
     181//              return retVal; 
    182182                 
    183183//      hState = MoveLockHandle(wavH);          // So wave data can't move. Remember to call HSetState when done. 
     
    204204        ratio = sig_incoh / sig_total; 
    205205         
    206         theta_max = wavelength*qmax/(2*pi); 
     206        theta_max = wavelength*qmax/(2.0*pi); 
    207207//C     SET Theta-STEP SIZE. 
    208208        dth = theta_max/num_bins; 
     
    229229                ////SpinProcess() IS A CALLBACK, and not good for Threading! 
    230230//              if ((n1 % 1000 == 0) && gCallSpinProcess && SpinProcess()) {            // Spins cursor and allows background processing. 
    231 //                              result = -1;                                                            // User aborted. 
     231//                              retVal = -1;                                                            // User aborted. 
    232232//                              break; 
    233233//              } 
     
    294294                                                 
    295295                                                q0 =left + locate_interp(ran_dev,numRows_ran_dev,ran3(&seed))*delta; 
    296                                                 theta = q0/2/pi*wavelength;             //SAS approximation. 1% error at theta=30 degrees 
     296                                                theta = q0/2.0/pi*wavelength;           //SAS approximation. 1% error at theta=30 degrees 
    297297                                                 
    298298                                                find_theta = 1;         //always accept 
     
    326326                                indices[0] =index;                      //this sets access to nn[index] 
    327327                                if (index <= n_index) { 
    328                                         if (result = MDGetNumericWavePointValue(p->nnH, indices, value)) 
    329                                                 return result; 
     328                                        if (retVal = MDGetNumericWavePointValue(p->nnH, indices, value)) 
     329                                                return retVal; 
    330330                                        value[0] += 1; // add one to the value 
    331                                         if (result = MDSetNumericWavePointValue(p->nnH, indices, value)) 
    332                                                 return result; 
     331                                        if (retVal = MDSetNumericWavePointValue(p->nnH, indices, value)) 
     332                                                return retVal; 
    333333                                //      nn[index] += 1; 
    334334                                } 
     
    336336                                if( index != 0) {               //neutron was scattered, figure out where it went 
    337337                                        theta_z = acos(vz);             // Angle (= 2theta) WITH respect to z axis. 
    338                                         testQ = 2*pi*sin(theta_z)/wavelength; 
     338                                        testQ = 2.0*pi*sin(theta_z)/wavelength; 
    339339                                         
    340340                                        // pick a random phi angle, and see if it lands on the detector 
    341341                                        // since the scattering is isotropic, I can safely pick a new, random value 
    342342                                        // this would not be true if simulating anisotropic scattering. 
    343                                         testPhi = ran3(&seed)*2*pi; 
     343                                        testPhi = ran3(&seed)*2.0*pi; 
    344344                                         
    345345                                        // is it on the detector?        
     
    351351                                                indices[0] = xPixel; 
    352352                                                indices[1] = yPixel; 
    353                                                 if (result = MDGetNumericWavePointValue(wavH, indices, value)) 
    354                                                         return result; 
     353                                                if (retVal = MDGetNumericWavePointValue(wavH, indices, value)) 
     354                                                        return retVal; 
    355355                                                value[0] += 1; // Real part 
    356                                                 if (result = MDSetNumericWavePointValue(wavH, indices, value)) 
    357                                                         return result; 
     356                                                if (retVal = MDSetNumericWavePointValue(wavH, indices, value)) 
     357                                                        return retVal; 
    358358                                                //if(index==1)  // only the single scattering events 
    359359                                                        //dp = dp0 + xPixel + yPixel*numColumns;                //offset the pointer to the exact memory location 
     
    415415                                                if(indices[1] < 0) indices[1] = 0; 
    416416                                                 
    417                                                 if (result = MDGetNumericWavePointValue(wavH, indices, value)) 
    418                                                         return result; 
     417                                                if (retVal = MDGetNumericWavePointValue(wavH, indices, value)) 
     418                                                        return retVal; 
    419419                                                value[0] += 1; // Real part 
    420                                                 if (result = MDSetNumericWavePointValue(wavH, indices, value)) 
    421                                                         return result; 
     420                                                if (retVal = MDSetNumericWavePointValue(wavH, indices, value)) 
     421                                                        return retVal; 
    422422                                        }        
    423423                        } 
     
    430430        value[0] = (double)n1; 
    431431        indices[0] = 0; 
    432         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    433                 return result; 
     432        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     433                return retVal; 
    434434        value[0] = (double)n2; 
    435435        indices[0] = 1; 
    436         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    437                 return result; 
     436        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     437                return retVal; 
    438438        value[0] = (double)isOn; 
    439439        indices[0] = 2; 
    440         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    441                 return result; 
     440        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     441                return retVal; 
    442442        value[0] = (double)NScatterEvents; 
    443443        indices[0] = 3; 
    444         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    445                 return result; 
     444        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     445                return retVal; 
    446446        value[0] = (double)NSingleCoherent; 
    447447        indices[0] = 4; 
    448         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    449                 return result; 
     448        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     449                return retVal; 
    450450        value[0] = (double)NMultipleCoherent; 
    451451        indices[0] = 5; 
    452         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    453                 return result; 
     452        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     453                return retVal; 
    454454        value[0] = (double)NMultipleScatter; 
    455455        indices[0] = 6; 
    456         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    457                 return result 
     456        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     457                return retVal 
    458458        value[0] = (double)NCoherentEvents; 
    459459        indices[0] = 7; 
    460         if (result = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
    461                 return result 
     460        if (retVal = MDSetNumericWavePointValue(p->resultsH, indices, value)) 
     461                return retVal 
    462462 
    463463 
     
    480480 
    481481        //convert qx,qy to pixel locations relative to # of pixels x, y from center 
    482         theta = 2*asin(qy*lam/4/pi); 
     482        theta = 2.0*asin(qy*lam/4.0/pi); 
    483483        dy = sdd*tan(theta); 
    484484        *yPixel = round(yCtr + dy/pixSize); 
    485485         
    486         theta = 2*asin(qx*lam/4/pi); 
     486        theta = 2.0*asin(qx*lam/4.0/pi); 
    487487        dx = sdd*tan(theta); 
    488488        *xPixel = round(xCtr + dx/pixSize); 
     
    543543        double retval; 
    544544         
    545         retval = -1*log(1-aval)/sig_tot; 
     545        retval = -1.0*log(1.0-aval)/sig_tot; 
    546546         
    547547        return(retval); 
Note: See TracChangeset for help on using the changeset viewer.