function [X,Y,Z]=asc2xyz(filename)
    // Function to convert a regular grid to X Y Z matrixes
    //
    // Inputs
    //     filename, file name
    //
    // Outputs
    //    X, Y, Z matrixes
    //
    //
    // Autor: Saul Arciniega Esparza
    // zaul.ae@gmail.com
    // Institute of engineering UNAM
    
    
    //Open file
    fd=mopen(filename,'r');
    s=mfscanf(fd,'%s\t%d'); nc=s(2); //cols
    s=mfscanf(fd,'%s\t%d'); nr=s(2); //rows
    s=mfscanf(fd,'%s\t%f'); x1=s(2); //X coordinate
    s=mfscanf(fd,'%s\t%f'); y1=s(2); //Y coordinate 
    s=mfscanf(fd,'%s\t%f'); dxy=s(2); // X and Y increment
    s=mfscanf(fd,'%s\t%f'); noval=s(2);
    mclose(fd)
    
    // Output data
    Z=fscanfMat(filename); //Z matrix
    Z(Z==noval)=%nan;
    lx=linspace(x1,x1+dxy*nc,nc);
    ly=linspace(y1,y1+dxy*nr,nr);
    [X,Y]=meshgrid(lx,ly); //X Y matrixes of coordinates
    
endfunction
