Index: trunk/src/nc2struct.m
===================================================================
--- trunk/src/nc2struct.m	(revision 188)
+++ trunk/src/nc2struct.m	(revision 227)
@@ -65,6 +65,6 @@
             nc=netcdf.open(nc,'NC_NOWRITE');
             testfile=1;
-            catch errormsg
-              Data.Txt=['ERROR opening ' nc ': ' errormsg.identifier];
+            catch ME
+              Data.Txt=['ERROR opening ' nc ': ' ME.message];
               return
             end
@@ -77,11 +77,11 @@
     end
     
-    %% short reading opion for global attributes only, if the first argument is 'ListGlobalAttribute'
+    %% short reading option for global attributes only, if the first argument is 'ListGlobalAttribute'
     if isequal(varargin{1},'ListGlobalAttribute')
         for ilist=2:numel(varargin)
+            valuestr=[];%default
             try
             valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
-            catch
-                valuestr=[];
+            catch ME
             end
             eval(['Data.' varargin{ilist} '=valuestr;'])
@@ -97,30 +97,28 @@
     %%  -------- read all global attributes (constants)-----------
     att_key={};%default
-    iatt_g=0;
+%     iatt_g=0;
     Data.ListGlobalAttribute={};%default
     for iatt=1:ngatts
         keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
-        indstr1=regexp(keystr,'\\','once');%detect '\\'
-        indstr2=regexp(keystr,'\.','once');%detect '\.'
-        %indtitle=regexp(keystr,'title','once');%detect 'title'(bad characters)
-        if isempty(indstr1) && isempty(indstr2)%&&isempty(indtitle)
-           valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr);
-           if ischar(valuestr) & length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters
-                iatt_g=iatt_g+1;
-                indstr1=regexp(keystr,'\\','once');%detect '\\'
-                indstr2=regexp(keystr,'\.','once');%detect '\.'
-                if isempty(indstr1) && isempty(indstr2)
-                    eval(['Data.' keystr '=''' valuestr ''';'])
-                    att_key{iatt_g}=keystr;
-                end
-            elseif isempty(valuestr)
-                iatt_g=iatt_g+1;
-                eval(['Data.' keystr '=[];'])
-                att_key{iatt_g}=keystr;
+        valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr);
+        keystr=regexprep(keystr,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
+        if strcmp(keystr(1),'_')
+            keystr(1)=[];
+        end
+        try
+            if ischar(valuestr) & length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters
+               % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'})%remove  '\','.' or '-' if exists
+                eval(['Data.' keystr '=''' valuestr ''';'])
+%             elseif isempty(valuestr)
+%                 eval(['Data.' keystr '=[];'])
             elseif isnumeric(valuestr)
-                iatt_g=iatt_g+1;
                 eval(['Data.' keystr '=valuestr;'])
-                att_key{iatt_g}=keystr;
-            end
+            else
+                eval(['Data.' keystr '='';']) 
+            end
+            att_key{iatt}=keystr;
+        catch ME
+            att_key{iatt}=['attr_' num2str(iatt)];
+            eval(['Data.' att_key{iatt} '=[];'])
         end
     end
@@ -184,5 +182,11 @@
             attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1);
             valuestr= netcdf.getAtt(nc,var_index(ivar)-1,attname);
+            attname=regexprep(attname,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
+            if strcmp(attname(1),'_')
+                attname(1)=[];
+            end
+            try
             if ischar(valuestr)
+               % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'});%remove  '\','.' or '-' if exists
                 eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';'])
             elseif isempty(valuestr)
@@ -190,4 +194,10 @@
             elseif isnumeric(valuestr)
                 eval(['Data.VarAttribute{ivar}.' attname '=valuestr;'])
+            end
+            catch ME
+                display(attname)
+                display(valuestr)
+                display(ME.message)         
+                eval(['Data.VarAttribute{ivar}.atrr_' num2str(iatt) '=''not read'';'])
             end
         end
