[LON-CAPA-cvs] cvs: capa /capa51/pProj capaCommon.c

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 01 Dec 2005 22:32:14 -0000


albertel		Thu Dec  1 17:32:14 2005 EDT

  Modified files:              
    /capa/capa51/pProj	capaCommon.c 
  Log:
  - handle the case where there are no samples pojts to sample (and thus no variables to vary) correctly
  
  
Index: capa/capa51/pProj/capaCommon.c
diff -u capa/capa51/pProj/capaCommon.c:1.25 capa/capa51/pProj/capaCommon.c:1.26
--- capa/capa51/pProj/capaCommon.c:1.25	Thu Dec  1 15:05:22 2005
+++ capa/capa51/pProj/capaCommon.c	Thu Dec  1 17:32:10 2005
@@ -3250,6 +3250,25 @@
   return (result);
 }
 
+int check_tol (formula_val,tol_type,tol)
+double formula_val;int tol_type;double tol;
+{
+  double diff;
+  int outcome=APPROX_ANS;
+  if( tol_type == TOL_ABSOLUTE ) {
+    diff = tol - formula_val;
+    if( diff < 0.0 )  {
+      outcome = INCORRECT;
+    }
+  } else {
+    diff = fabs(1.0 - formula_val) * 100.0 ;
+    if( diff > tol ) {
+      outcome = INCORRECT;
+    }
+  }
+  return outcome;
+}
+
 /* -------------------------------------------------------------------------- */
 /*   assumming the formula is *fml_str and the student input is *input_str             */
 /*   according to the type of tolerance, we form the final formula as                  */
@@ -3262,7 +3281,7 @@
   char         *check_fml_str;
   int           f_len, i_len, outcome, error_code;
   PointsList_t *pt, *next;
-  double        formula_val, diff;
+  double        formula_val;
   
   f_len = strlen(fml_str);
   i_len = strlen(input_str);
@@ -3274,21 +3293,20 @@
     sprintf(check_fml_str,"(%s) / (%s)",input_str,fml_str);
   }
   outcome = APPROX_ANS;
+  if( pts_list==NULL ) {
+    error_code = f_eval_formula(&formula_val,check_fml_str, var_list, NULL);
+    if( ! error_code ) {
+      outcome = check_tol(formula_val,tol_type,tol);
+    } else {
+      outcome = BAD_FORMULA;
+    }      
+  }
+
   for(pt= pts_list; pt!=NULL ; pt=next) {
     next=pt->pts_next;
     error_code = f_eval_formula(&formula_val,check_fml_str, var_list, pt->pts_str);
     if( ! error_code ) {
-      if( tol_type == TOL_ABSOLUTE ) {
-        diff = tol - formula_val;
-        if( diff < 0.0 )  {
-          outcome = INCORRECT;
-        }
-      } else {
-        diff = abs(1.0 - formula_val) * 100.0 ;
-        if( diff > tol ) {
-          outcome = INCORRECT;
-        }
-      }
+      outcome = check_tol(formula_val,tol_type,tol);
     } else {
       outcome = BAD_FORMULA;
       break;