Changeset 919 for trunk


Ignore:
Timestamp:
Jun 26, 2015, 5:14:45 PM (6 years ago)
Author:
sommeria
Message:

netcdf files stored in 32 bits (not double)

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series.m

    r918 r919  
    17641764
    17651765
    1766 %% direct processing on the current Matlab session
    1767 % if strcmp (RunMode,'local')
     1766%% direct processing on the current Matlab session or creation of command files
     1767filexml=cell(1,NbProcess);% initialisation of the names of the files containing the processing parameters
     1768extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
    17681769for iprocess=1:NbProcess
    17691770    if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
     
    17731774    if isempty(Param.IndexRange.NbSlice)
    17741775        Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
    1775 %         Param.IndexRange.first_i=ref_i(1+(iprocess-1)*BlockLength);
     1776        %         Param.IndexRange.first_i=ref_i(1+(iprocess-1)*BlockLength);
    17761777        if Param.IndexRange.first_i>last_i
    17771778            NbProcess=iprocess-1;% leave the loop, we are at the end of the calculation
     
    17821783        Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
    17831784    else %multislices (then incr_i is not empty)
    1784 %         Param.IndexRange.first_i= first_i+incr_i*(iprocess-1);
    1785 %         Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
     1785        %         Param.IndexRange.first_i= first_i+incr_i*(iprocess-1);
     1786        %         Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
    17861787        Param.IndexRange.first_i= first_i+iprocess-1;
    17871788        Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
     
    18091810        extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
    18101811            Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
    1811         filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess})
    1812         save(t, filexml{iprocess});% save the xml file containing the processing parameters
     1812        filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
     1813        try
     1814            save(t, filexml{iprocess});% save the xml file containing the processing parameters
     1815        catch ME
     1816            if ~strcmp (RunMode,'local')
     1817                errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
     1818                return
     1819            end
     1820        end
    18131821    end
    18141822    if strcmp (RunMode,'local')
     
    18271835    end
    18281836end
     1837
    18291838if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
    18301839    %% processing on a different session of the same computer (background) or cluster, create executable files
  • trunk/src/set_grid.m

    r918 r919  
    194194YA=grid_pix_A(:,2);
    195195unitcolumn=32*ones(size(XA));
    196 Xchar=num2str(XA,2);
     196Xchar=num2str(XA,'%1.1f');% write x coordinate in px, rounded at the first decimal
    197197blanc=char(unitcolumn);
    198 Ychar=num2str(YA,2);
     198Ychar=num2str(YA,'%1.1f');% write y coordinate in px, rounded at the first decimal
    199199tete=['1 ' num2str(nbpointsA(1))];
    200200txt=[Xchar blanc Ychar];
  • trunk/src/struct2nc.m

    r913 r919  
    4949    return
    5050end
    51 %check the validity of the input field structure
     51
     52%% check the validity of the input field structure
    5253[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data);
    5354if ~isempty(errormsg)
     
    5657end
    5758ListVarName=Data.ListVarName;
    58 %nc=netcdf.create(flname,'NC_CLOBBER');%,'clobber'); %create the netcdf file with name flname
     59
     60%% create the netcdf file with name flname in format NETCDF4
    5961cmode = netcdf.getConstant('NETCDF4');
    6062cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
    6163cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
    62 nc = netcdf.create(flname, cmode)
    63 
    64 %write global constants
     64nc = netcdf.create(flname, cmode);
     65
     66%% write global constants
    6567if isfield(Data,'ListGlobalAttribute')
    6668    keys=Data.ListGlobalAttribute;
     
    8486    end
    8587end
    86 %create dimensions
     88
     89%% create the dimensions
    8790dimid=zeros(1,length(ListDimName));
    8891for idim=1:length(ListDimName)
     
    9598    testattr=1;
    9699end
    97 varid=zeros(1,length(Data.ListVarName));
     100
     101
     102%% create the variables
     103varid=nan(1,length(Data.ListVarName));
    98104for ivar=1:length(ListVarName)
    99     varid(ivar)=netcdf.defVar(nc,ListVarName{ivar},'nc_double',dimid(VarDimIndex{ivar}));%define variable 
    100 end
    101  %write variable attributes
     105    if isfield(Data,ListVarName{ivar})
     106        VarClass=class(Data.(ListVarName{ivar}));
     107        VarType='';
     108        switch VarClass
     109            case {'single','double'}
     110                VarType='nc_float'; % store all floating reals as single
     111            case {'uint8','int16','uint16','int32','uint32','int64','uint64'}
     112                VarType='nc_int';
     113            case  'logical'
     114                VarType='nc_byte';
     115        end
     116        if ~isempty(VarType)
     117            varid(ivar)=netcdf.defVar(nc,ListVarName{ivar},VarType,dimid(VarDimIndex{ivar}));%define variable
     118        end
     119    end
     120end
     121
     122%% write variable attributes
    102123if testattr
    103124    for ivar=1:min(numel(VarAttribute),numel(ListVarName)) 
    104         if isstruct(VarAttribute{ivar})
     125        if isstruct(VarAttribute{ivar}) && ~isnan(varid(ivar))
    105126            attr_names=fields(VarAttribute{ivar});
    106127            for iattr=1:length(attr_names)
     
    114135end
    115136netcdf.endDef(nc); %put in data mode
     137
     138%% fill the variables with input data
    116139for ivar=1:length(ListVarName)
    117     if isfield(Data,ListVarName{ivar})
     140    if ~isnan(varid(ivar))
    118141        VarVal=Data.(ListVarName{ivar});
    119142        %varval=values of the current variable
    120 %        VarDimIndex=Data.VarDimIndex{ivar}; %indices of the variable dimensions in the list of dimensions
    121143        VarDimName=Data.VarDimName{ivar};
    122144        if ischar(VarDimName)
     
    126148        testrange=(numel(VarDimName)==1 && strcmp(VarDimName{1},ListVarName{ivar}) && numel(VarVal)==2);% case of a coordinate defined on a regular mesh by the first and last values.
    127149        testline=isequal(length(siz),2) && isequal(siz(1),1)&& isequal(siz(2), DimValue(VarDimIndex{ivar}));%matlab vector
    128         testcolumn=isequal(length(siz),2) && isequal(siz(1), DimValue(VarDimIndex{ivar}))&& isequal(siz(2),1);%matlab column vector
    129 %             if ~testrange && ~testline && ~testcolumn && ~isequal(siz,DimValue(VarDimIndex))
    130 %                 errormsg=['wrong dimensions declared for ' ListVarName{ivar} ' in struct2nc.m'];
    131 %                 break
    132 %             end
     150        %testcolumn=isequal(length(siz),2) && isequal(siz(1), DimValue(VarDimIndex{ivar}))&& isequal(siz(2),1);%matlab column vector
    133151        if testline || testrange
    134152            if testrange
  • trunk/src/struct2xml.m

    r908 r919  
    1 %'struct2xml': transform a matlab structure to a xml tree.
     1%'struct2xml': transforms a matlab structure to a xml tree.
    22%--------------------------------------------------------------
     3%
    34% each field with char string or num vector is transformed into a corresponding  xml element
    45% each field with a matrix containing n lines is transformed into a xml element repeated n times
    5 % WARNING: PROBLEM WITH HIERARCHICAL structures
     6% each substructure of the input matlab structure is translateed into a subtree in the xml object
     7% it is also possible to append a subtree to an existing xml object t
     8%
     9% t=struct2xml(Object,t,root_uid)
    610%%%%%%%%%%%%%%%%%%%%%%%
    711% OUTPUT:
    812% t: xmltree reproducing the structure of Object
    913% type 'save(t)' to visualize the xml text and save(filename,t) to save it in a file
     14% to set the title tag of the file, type t=set(t,1,'name','titletag')
    1015%
    1116% INPUT:
    1217%  Object: matlab structure, possibly hierarchical
    13 %  t: optional input xml tree in which a new branch needs to be appended
     18%  t: optional input xml tree in which a subtree needs to be appended
    1419%  root_uid: optional uid of the xml element under which the new subtree must be appended
    1520
Note: See TracChangeset for help on using the changeset viewer.