[cmor] 165/190: Marks history fix - may have missed some things

Alastair McKinstry mckinstry at moszumanska.debian.org
Tue Jul 21 12:54:51 UTC 2015


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository cmor.

commit addafcb0121c69f88b3127003e13bd36e2e4fdb8
Author: Jamie Kettleborough <jamie.kettleborough at metoffice.gov.uk>
Date:   Mon Nov 18 14:37:34 2013 +0000

    Marks history fix - may have missed some things
---
 Src/cmor.c              | 51 ++++++++++++++++++++++++++++++-------------------
 Src/cmor_variables.c    | 22 ++++++++++++++++++++-
 include/cmor_func_def.h |  2 ++
 3 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/Src/cmor.c b/Src/cmor.c
index 9bdc370..a1fcd18 100644
--- a/Src/cmor.c
+++ b/Src/cmor.c
@@ -55,37 +55,43 @@ int CMOR_CREATE_SUBDIRECTORIES = 1;
 char cmor_input_path[CMOR_MAX_STRING];
 char cmor_traceback_info[CMOR_MAX_STRING];
 
-void cmor_cat_unique_string (char* dest, char* src) {
+/* Test routines implemented out of the way at the end of this code */
+int test_cat_unique_string(void);
+
+
+/* is src in dest? Negative=src already in dest */
+
+int cmor_stringinstring (char* dest, char* src) {
   char* pstr=dest;
-  int destlen=strlen(dest);
-  int spare_space=CMOR_MAX_STRING-destlen;
-  /* if this string is in msg */
   while (pstr=strstr(pstr, src)) {
     /* if this word is at the beginning of msg or preceeded by a space */
     if (pstr==dest || pstr[-1]==' ') {
       /* if it isn't a substring match */
       if ((pstr[strlen(src)] != ' ') &&
           (pstr[strlen(src)] != 0)) {
-        /* then add this string to the end of msg */
-        strncat(pstr, " " ,spare_space);
-        spare_space--;
-        strncat(pstr, src, spare_space);
+        /* then return 1 to indicate string found */
+        return 1;
       }
-      break; /* Either existed here or didn't*/
     }
-    /* If it gets here, then it was a partial match, like "rum" and "rumble". */
     pstr++;/* In which case, skip to the next char */
-    spare_space=CMOR_MAX_STRING-(pstr-dest); /* shorten the space available for the rest of the destination string */
-    /* and go round again */
   }
-  if (pstr==0) {
-    /* this string is not in msg, therefore append it */
-    if (dest[0]!=0) {
-      /* This is being appended to a preexisting string, so separate with a space */
-      strncat(dest, " ", spare_space);
-      spare_space--;
-    }
-    strncat(dest, src, spare_space);
+  /* nothing like src is in dest, and so return the location of the end of string*/
+  return 0;
+}
+
+void cmor_cat_unique_string (char* dest, char* src) {
+  int offset;
+  int spare_space;
+  /* if this string is in msg */
+  if (cmor_stringinstring(dest, src)) {
+    /* do nothing */
+  } else if (offset=strlen(dest)) {
+    dest[offset]=' ';
+    offset++;
+    spare_space=CMOR_MAX_STRING-offset-1;
+    strncat(dest+offset, src, spare_space);
+  } else if (offset=0) {
+     strncpy(dest, src, CMOR_MAX_STRING);
   }
 }
 
@@ -2536,7 +2542,12 @@ int cmor_write(int var_id,void *data, char type, char *suffix, int ntimes_passed
       /* did we flip that guy? */
       if (cmor_axes[cmor_vars[var_id].axes_ids[i]].revert==-1) {
 	sprintf(msg,"Inverted axis: %s",cmor_axes[cmor_vars[var_id].axes_ids[i]].id);
+        /* fiddle to avoid duplicated effort here if it's already inverted */
+        if (cmor_history_contains(var_id, msg)) {
+          /* do nothing */
+        } else {
 	cmor_update_history(var_id,msg);
+        }
       }
       /* Axis length */
       j=cmor_axes[cmor_vars[var_id].axes_ids[i]].length;
diff --git a/Src/cmor_variables.c b/Src/cmor_variables.c
index a58c4e8..95bf462 100644
--- a/Src/cmor_variables.c
+++ b/Src/cmor_variables.c
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <math.h>
 
-
 int cmor_is_required_variable_attribute(cmor_var_def_t var, char *attribute_name) 
 {
   
@@ -571,6 +570,27 @@ int cmor_update_history(int var_id,char *add){
   return 0;
 }
 
+int cmor_history_contains(int var_id,char *add){
+  struct tm *ptr;
+  time_t lt;
+  char date[CMOR_MAX_STRING];
+  char tmp[CMOR_MAX_STRING];
+  char tmp2[CMOR_MAX_STRING];
+
+  /* first figures out time */
+  cmor_add_traceback("cmor_update_history");
+  lt = time(NULL);
+  ptr = gmtime(&lt);
+  snprintf(date,CMOR_MAX_STRING,"%.4i-%.2i-%.2iT%.2i:%.2i:%.2iZ",ptr->tm_year+1900,ptr->tm_mon+1,ptr->tm_mday,ptr->tm_hour,ptr->tm_min,ptr->tm_sec);
+  if (cmor_has_variable_attribute(var_id,"history")==0) {
+    cmor_get_variable_attribute(var_id,"history",&tmp[0]);
+    if (cmor_stringinstring(tmp, add)) {
+      return 1;
+    }
+  }
+  return 0;
+}
+
 int cmor_variable(int *var_id, char *name, char *units, int ndims, int axes_ids[], char type, void *missing, double *tolerance, char *positive, char*original_name, char *history, char *comment) 
 {
   extern int cmor_nvars,cmor_naxes;
diff --git a/include/cmor_func_def.h b/include/cmor_func_def.h
index ffdab26..b02cc54 100644
--- a/include/cmor_func_def.h
+++ b/include/cmor_func_def.h
@@ -100,4 +100,6 @@ extern int cmor_set_dataset_att(cmor_table_t *table, char att[CMOR_MAX_STRING],c
 extern int cmor_set_table(int table);
 extern int cmor_load_table(char table[CMOR_MAX_STRING], int *table_id);
 extern int cmor_time_varying_grid_coordinate(int *coord_grid_id, int  grid_id, char *name, char *units, char type, void *missing, int *coordinate_type);
+extern void cmor_cat_unique_string (char* dest, char* src);
+extern int cmor_stringinstring (char* dest, char* src);
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cmor.git



More information about the debian-science-commits mailing list