[cig-commits] r11900 - cs/avm/trunk

tan2 at geodynamics.org tan2 at geodynamics.org
Fri May 2 15:36:59 PDT 2008


Author: tan2
Date: 2008-05-02 15:36:59 -0700 (Fri, 02 May 2008)
New Revision: 11900

Modified:
   cs/avm/trunk/avm-partition.c
   cs/avm/trunk/elastic-models.c
   cs/avm/trunk/elastic-models.h
   cs/avm/trunk/prem-derived-models.c
   cs/avm/trunk/prem-derived-models.h
Log:
Get filename of parameter file from command line argument

Modified: cs/avm/trunk/avm-partition.c
===================================================================
--- cs/avm/trunk/avm-partition.c	2008-05-02 21:06:40 UTC (rev 11899)
+++ cs/avm/trunk/avm-partition.c	2008-05-02 22:36:59 UTC (rev 11900)
@@ -43,19 +43,22 @@
 int main(int argc, char **argv)
 {
     FILE **out; int nout;
+    char *paramfilename;
     int i, old_type, old_num_columns, old_num_compositions;
     elastic_model_fn elastic_model = NULL;
     void *context = NULL;
 
-    if (argc < 2) {
-        fprintf(stderr, "usage: %s FILE...\n", argv[0]);
+    if (argc < 3) {
+        fprintf(stderr, "usage: %s param_file tracer_file(s) ...\n", argv[0]);
         return 1;
     }
 
+    paramfilename = argv[1];
+
     old_type = old_num_columns = old_num_compositions = -1;
     nout = 0;
     out = NULL;
-    for (i = 1; i < argc; ++i) {
+    for (i = 2; i < argc; ++i) {
         char *ifilename;
         char buffer[256], *p;
         FILE *in;
@@ -101,7 +104,7 @@
 
             /* select and setup elastic model for later use */
             select_elastic_model(model_type, num_columns, num_compositions,
-                                 &elastic_model, &context);
+                                 paramfilename, &elastic_model, &context);
         }
         else {
             if ((old_type != model_type) ||

Modified: cs/avm/trunk/elastic-models.c
===================================================================
--- cs/avm/trunk/elastic-models.c	2008-05-02 21:06:40 UTC (rev 11899)
+++ cs/avm/trunk/elastic-models.c	2008-05-02 22:36:59 UTC (rev 11900)
@@ -55,6 +55,7 @@
  */
 void select_elastic_model(int model_type,
                           int num_columns, int num_compositions,
+                          char *paramfilename,
                           elastic_model_fn *fn, void **context)
 {
     /*
@@ -67,12 +68,14 @@
     switch (model_type) {
     case 1:
         /* using modulus derivatives */
-        prem_mod_derv_em_init(num_columns, num_compositions, context);
+        prem_mod_derv_em_init(num_columns, num_compositions,
+                              paramfilename, context);
         *fn = prem_mod_derv_em;
         return;
     case 2:
         /* using velocity derivatives */
-        prem_vel_derv_em_init(num_columns, num_compositions, context);
+        prem_vel_derv_em_init(num_columns, num_compositions,
+                              paramfilename, context);
         *fn = prem_vel_derv_em;
         return;
     case 100:

Modified: cs/avm/trunk/elastic-models.h
===================================================================
--- cs/avm/trunk/elastic-models.h	2008-05-02 21:06:40 UTC (rev 11899)
+++ cs/avm/trunk/elastic-models.h	2008-05-02 22:36:59 UTC (rev 11900)
@@ -31,4 +31,5 @@
 
 void select_elastic_model(int model_type,
                           int num_columns, int num_compositions,
+                          char *paramfilename,
                           elastic_model_fn *fn, void **context);

Modified: cs/avm/trunk/prem-derived-models.c
===================================================================
--- cs/avm/trunk/prem-derived-models.c	2008-05-02 21:06:40 UTC (rev 11899)
+++ cs/avm/trunk/prem-derived-models.c	2008-05-02 22:36:59 UTC (rev 11900)
@@ -100,7 +100,7 @@
 
 
 void prem_mod_derv_em_init(int num_columns, int num_compositions,
-                           void **context)
+                           char *paramfilename, void **context)
 {
     /* see the comment of fields format in the next function */
     const int num_required_fields = num_compositions + 4;
@@ -109,7 +109,6 @@
     int total_columns, num_layers;
     int itmp;
     double *tmp;
-    const char ifilename[] = "modulus-derivatives.dat";
     FILE *in;
     prem_modulus_derv_t *p;
 
@@ -126,14 +125,14 @@
     }
 
     /* read d*dc, d*dt from file, the filename is hard coded */
-    in = fopen(ifilename, "r");
+    in = fopen(paramfilename, "r");
     if (!in) {
-        fprintf(stderr, "Cannot open input `%s': ", ifilename);
+        fprintf(stderr, "Cannot open input `%s': ", paramfilename);
         perror("");
         exit(2);
     }
 
-    read_header(in, ifilename, num_compositions, &num_layers);
+    read_header(in, paramfilename, num_compositions, &num_layers);
     p->num_layers = num_layers;
 
     /* allocate memory */
@@ -163,7 +162,7 @@
     for (i = 0; i < num_layers; ++i) {
         itmp = read_double_vector(in, total_columns, tmp);
         if (itmp != total_columns) {
-            fprintf(stderr, "Bad line in input file: `%s'\n", ifilename);
+            fprintf(stderr, "Bad line in input file: `%s'\n", paramfilename);
             exit(2);
         }
 
@@ -263,7 +262,7 @@
 
 
 void prem_vel_derv_em_init(int num_columns, int num_compositions,
-                           void **context)
+                           char *paramfilename, void **context)
 {
     /* see the comment of fields format in the next function */
     const int num_required_fields = num_compositions + 4;
@@ -272,7 +271,6 @@
     int total_columns, num_layers;
     int itmp;
     double *tmp;
-    const char ifilename[] = "velocity-derivatives.dat";
     FILE *in;
     prem_velocity_derv_t *p;
 
@@ -289,14 +287,14 @@
     }
 
     /* read d*dc, d*dt from file, the filename is hard coded */
-    in = fopen(ifilename, "r");
+    in = fopen(paramfilename, "r");
     if (!in) {
-        fprintf(stderr, "Cannot open input `%s': ", ifilename);
+        fprintf(stderr, "Cannot open input `%s': ", paramfilename);
         perror("");
         exit(2);
     }
 
-    read_header(in, ifilename, num_compositions, &num_layers);
+    read_header(in, paramfilename, num_compositions, &num_layers);
     p->num_layers = num_layers;
 
     /* allocate memory */
@@ -326,7 +324,7 @@
     for (i = 0; i < num_layers; ++i) {
         itmp = read_double_vector(in, total_columns, tmp);
         if (itmp != total_columns) {
-            fprintf(stderr, "Bad line in input file: `%s'\n", ifilename);
+            fprintf(stderr, "Bad line in input file: `%s'\n", paramfilename);
             exit(2);
         }
 

Modified: cs/avm/trunk/prem-derived-models.h
===================================================================
--- cs/avm/trunk/prem-derived-models.h	2008-05-02 21:06:40 UTC (rev 11899)
+++ cs/avm/trunk/prem-derived-models.h	2008-05-02 22:36:59 UTC (rev 11900)
@@ -26,11 +26,11 @@
 
 
 void prem_mod_derv_em_init(int num_columns, int num_compositions,
-                           void **context);
+                           char *paramfilename, void **context);
 int prem_mod_derv_em(void *context, double *fields,
                      double *rho, double *ks, double *mu);
 
 void prem_vel_derv_em_init(int num_columns, int num_compositions,
-                           void **context);
+                           char *paramfilename, void **context);
 int prem_vel_derv_em(void *context, double *fields,
                      double *rho, double *ks, double *mu);



More information about the cig-commits mailing list