Index: /trunk/tools/create_OBSnetcdf.py
===================================================================
--- /trunk/tools/create_OBSnetcdf.py	(revision 1951)
+++ /trunk/tools/create_OBSnetcdf.py	(revision 1952)
@@ -168,4 +168,77 @@
     return ncvar
 
+def set_attributek(ncv, attrname, attrval, attrkind):
+    """ Sets a value of an attribute of a netCDF variable with a kind. Removes previous attribute value if exists
+    ncvar = object netcdf variable
+    attrname = name of the attribute
+    attrvalue = value of the attribute
+    atrtrkind = kind of attribute: 'S', string ('!' as spaces); 'U', unicode ('!' as spaces); 'I', integer; 
+      'Inp32', numpy integer 32; 'R', ot 'F' real; ' npfloat', np.float; 'D', np.float64
+    """
+    fname = 'set_attributek'
+    validk = {'S': 'string', 'U': 'unicode', 'I': 'integer',                         \
+      'Inp32': 'integer long (np.int32)', 'F': 'float', 'R': 'float',                \
+      'npfloat': 'np.float', 'D': 'float long (np.float64)'}
+
+    if type(attrkind) == type('s'):
+        if attrkind == 'S':
+            attrvalue = str(attrval.replace('!', ' '))
+        elif attrkind == 'U':
+            attrvalue = unicode(attrval.replace('!',' '))
+        elif attrkind == 'I':
+            attrvalue = np.int(attrval)
+        elif attrkind == 'R' or attrkind == 'F' :
+            attrvalue = float(attrval)
+        elif attrkind == 'npfloat':
+            attrvalue = np.float(attrval)
+        elif attrkind == 'D':
+            attrvalue = np.float64(attrval)
+        else:
+            print errormsg
+            print '  ' + fname + ": '" + attrkind + "' kind of attribute is not ready!"
+            print '  valid values: _______'
+            for key in validk.keys():
+                print '    ', key,':', validk[key]
+            quit(-1)
+    else:
+        if attrkind == type(str('a')):
+            attrvalue = str(attrval.replace('!', ' '))
+        elif attrkind == type(unicode('a')):
+            attrvalue = unicode(attrval.replace('!',' '))
+        elif attrkind == type(np.int(1)):
+            attrvalue = np.int(attrval)
+        elif attrkind == np.dtype('i'):
+            attrvalue = np.int32(attrval)
+        elif attrkind == type(float(1.)):
+            attrvalue = float(attrval)
+        elif attrkind == type(np.float(1.)):
+            attrvalue = np.float(attrval)
+        elif attrkind == np.dtype('float32'):
+            attrvalue = np.array(attrval, dtype='f')
+        elif attrkind == type(np.float32(1.)):
+            attrvalue = np.float32(attrval)
+        elif attrkind == type(np.float64(1.)):
+            attrvalue = np.float64(attrval)
+        elif attrkind == type(np.array([1.,2.])):
+            attrvalue = attrval
+        else:
+            print errormsg
+            print '  ' + fname + ": '" + attrkind + "' kind of attribute is not ready!"
+            print '  valid values: _______'
+            for key in validk.keys():
+                print '    ', key,':', validk[key]
+            quit(-1)
+
+    attvar = ncv.ncattrs()
+    if searchInlist(attvar, attrname):
+        attr = ncv.delncattr(attrname)
+
+    if attrname == 'original_subroutines_author': 
+        attrvalue = 'Cindy Bruyere'
+    attr = ncv.setncattr(attrname, attrvalue)
+        
+    return attr
+
+
 def basicvardef(varobj, vstname, vlname, vunits):
     """ Function to give the basic attributes to a variable
@@ -1130,4 +1203,35 @@
     return
 
+def add_global_PyNCplot(ObjFile, pyscript, funcname, version):
+    """ Function to add global attributes from 'PyNCplot' to a given netCDF
+      ObjFile= netCDF file object to which add the global attributes
+      funcname= name of the function from which file comes from
+      version= version of the function
+    """
+    fname = 'add_global_PyNCplot'
+
+    # Global values
+    ObjFile.setncattr('author', 'L. Fita')
+    newattr = set_attributek(ObjFile, 'institution', unicode('Centro de ' +          \
+     'Investigaciones del Mar y la Atm' + unichr(243) + 'sfera (CIMA)'), 'U')
+    newattr = set_attributek(ObjFile, 'institution2', unicode('Instituto Franco-' +  \
+      'Argentino sobre Estudios de Clima y sus Impactos (CNRS, UMI-3351-IFAECI'), 'U')
+    newattr = set_attributek(ObjFile, 'center', unicode('Consejo Nacional de ' +     \
+      'Investigaciones Cient' + unichr(237) + 'ficas y T' + unichr(233) +            \
+      'cnicas (CONICET)'), 'U')
+    ObjFile.setncattr('university', 'Universidad de Buenos Aires (UBA)')
+    ObjFile.setncattr('city', 'Buenos Aires')
+    ObjFile.setncattr('country', 'Argentina')
+    ObjFile.setncattr('tool', 'PyNCplot')
+    ObjFile.setncattr('url', 'http://www.xn--llusfb-5va.cat/python/PyNCplot')
+    ObjFile.setncattr('script', pyscript)
+    if funcname is not None:
+        ObjFile.setncattr('function', funcname)
+    ObjFile.setncattr('version', version)
+
+    ObjFile.sync()  
+
+    return
+
 ####### ###### ##### #### ### ## #
 
@@ -1414,12 +1518,5 @@
         set_attribute(objfile, descn, description[descn])
 
-set_attribute(objfile,'author_nc','Lluis Fita')
-set_attribute(objfile,'institution_nc','Centro de Investigaciones del Mar y la ' +   \
-  'Atmosfera (CIMA), CONICET-UBA, CNRS UMI-IFAECI, C.A. Buenos Aires')
-set_attribute(objfile,'country_nc','Argentina')
-set_attribute(objfile,'script_nc','create_OBSnetcdf.py')
-set_attribute(objfile,'version_script',version)
-set_attribute(objfile,'information',                                                 \
-  'http://www.lluÃ­sfb.cat/python/PyNCplot/')
+add_global_PyNCplot(objfile, main, 'main', version)
 
 objfile.sync()
