Grid generation

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Grid generation

#1 Unread post by kate »

Say, I was recently asked to give a roms class and the students were extremely eager to learn grid generation. I know of two ways to make grids: the nasty old Fortran way and the sexy Matlab way. I managed to download mexnc and seagrid onto one of their LInux boxes and could not get it to work. Since I came home, I also tried on my IBM and Linux boxes and failed there too. The very latest Seagrid download doesn't run the checks in the mex directory while my slightly older version does and fails on the mexrect check.

So, can *anyone* get the latest seagrid to work? How do we as a community want to be doing grid generation? Is a curvilinear option still important to anyone or should we go to a WRF style of rectangular grid only?

kawase
Posts: 7
Joined: Tue Aug 31, 2004 4:40 pm
Location: University of Washington

#2 Unread post by kawase »

Grid generation is definitely important to many of us working in regional applications, and is often the most time-consuming part of the model setup. I'm sure the ROMS community wants an effective curvilinear grid generator.

We've come across "gridgen": http://www.marine.csiro.au/~sakov/

I haven't used this myself but Dmitri Leonov, post-doc working for us, has generated a high-res grid for Puget Sound using this package for use with MITgcm.

Mitsuhiro.

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

#3 Unread post by kate »

Thanks for the pointer to a new toy! It works with xcoast about as well as my old Fortran codes. Here's an example:
Image
Note that I can't control the grid spacing on any wall, rather it seems to try for uniform aspect ratio of the grid boxes everywhere. It's a reasonable compromise. Where this will really shine is in the multiple grid domains Hernan is hoping to support someday:
Image

jpringle
Posts: 108
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

#4 Unread post by jpringle »

Hi everyone-

A few weeks ago I had this problem, and I created a matlab code that uses Sakov's grid gen to make a matlab domain, useing Rich P's m_map routines and some code I got from Rich Signell to create ROMS grid files from matlab data.

It is relatively primitive right now, but it is easy to use and easy to understand. I welcome comments on it. Now my code is basic, and does not allow me to telescope the grids, but this should be easy to do with Pavel's code. I have not done it because I have not needed it. The big win of useing code like this is that it is easy to understand.

To run my code, get the tar file roll_own_grid_share.tar.gz at

http://guppy.sr.unh.edu/~pringle/


You will need Rich P's m_map installed, and you will need to configure and compile the grid_gen code if you are not on a linux box already. The README in the gridgen directory is sufficient -- it is the usual "./configure ; make" dance on a linux box. If you look at the examples, and read his web page, you can see that gridgen can do much more than I have it doing here.

After you have m_map and gridgen, just examine and run make_roms_spherical_grid.m. You will need to provide coastline and bathymetry files in the same format as seagrid expects. This format is documented in the matlab code, and is dead easy.

Hope yall find this usefull.

Cheers,
Jamie

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Grid generation

#5 Unread post by rsignell »

kate wrote: I know of two ways to make grids: the nasty old Fortran way and the sexy Matlab way. I managed to download mexnc and seagrid onto one of their LInux boxes and could not get it to work. Since I came home, I also tried on my IBM and Linux boxes and failed there too. The very latest Seagrid download doesn't run the checks in the mex directory while my slightly older version does and fails on the mexrect check. So, can *anyone* get the latest seagrid to work?
Seagrid works fine on both my Windows XP box under R14 and R2006a, and on my Linux box under R14 (haven't tried R2006 yet).
kate wrote: How do we as a community want to be doing grid generation? Is a curvilinear option still important to anyone or should we go to a WRF style of rectangular grid only?
I think Sakov's grid generation tool is very useful, and the existing seagrid could be adapted without too much trouble to use this tool behind the scenes. The ability to have more than 4 corners is very nice indeed. Of course a python or java GUI would be nice also!

-Rich
Last edited by rsignell on Wed Oct 11, 2006 3:51 pm, edited 1 time in total.

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

#6 Unread post by kate »

Arrrr, matey, I can't get your package to work, Jamie, with the sample files provided:

Code: Select all

Now computing land mask from coastline file

??? Error using ==> mexnc
Too many output arguments.

Error in ==> mexcdf53 at 9
        [varargout{:}] = feval('mexnc', varargin{:});

Error in ==> ncmex at 139
        [varargout{:}] = feval(fcn, varargin{:});

Error in ==> netcdf.create at 13
[theNCid, status] = ncmex('create', name(self), thePermission);

Error in ==> netcdf.netcdf at 419
   result = create(result, thePermission);

Error in ==> mat2roms_rps at 91
nc = netcdf(theROMSFile, 'clobber');

Error in ==> make_roms_spherical_grid at 202
 mat2roms_rps('jnk.mat',output_grid)
I plan on going a different route than this, so don't fix it for me. I just needed to check out all the options. A note on bathymetries: I got sick of making subsets of global bathymetries for each domain and currently read in the whole globe instead. This works for ETOPO5, ETOPO2, and now GEBCO, assuming you have 64-bit address space. If you've got something better regionally, that's a different story (you lucky devil, you).

rmueller
Posts: 26
Joined: Thu May 04, 2006 4:15 am
Location: Earth & Space Research

Seagrid and mex mess

#7 Unread post by rmueller »

I recently went through a matlab/mex upgrade and seagrid installation. From this experience, Kate, it seems like your error may be more related to the matlab/mex communication than Jamie's code? Could this be the case? I came across a similar error, and it was because of path settings. In case it is helpful to you or others, I have copied my installation overview at the end of this message. (I have been too busy to try Jamie's code yet, but I plan to.)

For the matlab/seagrid/mex setup, I'm using an older version of Seagrid with the R2006a matlab and mex versions and it works okay. When I tried installing the newer seagrid version, I had trouble with the mex stuff and recieved the following advice from a kind person who no longer wishes to be bothered by Seagrid questions:
"The "SeaGrid" PCWIN mex-files have rarely worked, or never, and I have recommended that users invoke the "View/Setup" menu to turn them off. Alternatively, turn them off permanently at the end of the
"seagrid/seagrid.m" function."

E.g., uncheck the "UseMexFile" check box in View>Setup or change line 152 of seagrid.m to read: 'itUsesMexFile', ~~1.

Again, I resorted to an older version of Seagrid in the interest of time, so I'm not sure how useful this will be to you, but I thought I'd throw it out there just in case it is.


************Configuring Matlab/Mex************************
NOTE: YOU MAY JUST FIND THE END PART (INSTALLATION CHECK) MOST USEFUL.
*******************************************************

For a windows platform you do not exactly ‘install’ any of this. You just put the downloaded pre-built DLL files in the correct folders, update the windows path, and add some paths to Matlab. This file contains information for how to get mexnc and netcdf working with Matlab 7.2 r2006a build.

A mexnc download (http://mexcdf.sourceforge.net/index.html) with NetCDF_Toolbox is enough to start using NetCDF files in Matlab. The mexnc download includes the most recent netCDF.dll file that that version of mexnc works with. So this is a very good way to go.

(If you only want to use the netCDF “interface”(the tools that let you talk to netCDF formatted data) outside of Matlab or from the windows command line then just download netCDF from Unidata (http://www.unidata.ucar.edu/software/netcdf/) and place the correct files (netcdf.dll, netcdf.lib, ncdump.exe, ncgen.exe) in the C:\Windows\System32 folder.)

MEXNC




http://mexcdf.sourceforge.net/downloads/ (go to this website)
|
-> R2006a Windows XP : (find this link in the follow it)
|
-> mexnc-w32-r2006a-2.0.19.zip (download from Superb internet in Seattle WA)


Extract mexnc folder to ‘MEXNCPATH\ mexnc_R2006a\’, which in my case is 'C:\Program Files\MexCDF\mexnc_R2006a'. The mexnc folder (‘mexnc_R2006a’) contains two subfolders, ‘CVS’ and ‘tests’, as well as many files, including 'mexnc.mexw32' and 'netcdf.dll'. Copy 'mexnc.mexw32' and 'netcdf.dll' to MATLABPATH\bin and MATLABPATH\bin\win32, overwriting existing files (if applicable). In my case, MATLABPATH is ‘C:\Program Files\MATLAB72’.

Remove any folder with reference to mexnc or netcdf folders from Matlab path. (If you use Seagrid, keep the seagrid\mex folder).
Keep or create \bin and\bin\win32 paths.
Add to path "C:\Program Files\MexCDF\mexnc_R2006a\mexnc\".
Delete 'mexnc.mexw32' and 'netcdf.dll' from "C:\Program Files\MexCDF\mexnc_R2006a\mexnc\".

NETCDF




http://mexcdf.sourceforge.net/downloads/ (go to this website)
|
-> NetCDF Toolbox : (follow this link)
|
-> netcdf_toolbox-1.0.11.zip (download from Superb internet in Seattle WA)

Unzip the netcdf_toobox-1.0.11.zip in MATLABPATH\toolbox\. This will create a folder called 'netcdf_toolbox'. Add to the Matlab path this folder ('netcdf_toolbox') and all subfolders.



INSTALLATION CHECK



!!****The correct configuration is:****!!

>> mexnc('STRERROR',0)

ans =

No error

>> which('mexnc','-all')
C:\Program Files\MATLAB72\bin\win32\mexnc.mexw32
C:\Program Files\MATLAB72\bin\mexnc.mexw32 % Shadowed
C:\Program Files\MexCDF\mexnc_R2006a\mexnc\mexnc.m % Shadowed
>> which('netcdf','-all')
C:\Program Files\MATLAB72\toolbox\netcdf_toolbox\netcdf\@netcdf\netcdf.m % netcdf constructor
C:\Program Files\MATLAB72\bin\win32\netcdf.dll % Shadowed
C:\Program Files\MATLAB72\bin\netcdf.dll % Shadowed
>>

If the order of any of the above isn’t the same on your machine then you need to adjust the order of things in your matlab path until it matches the above, exactly.

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Seagrid and mex mess

#8 Unread post by rsignell »

rmueller wrote: When I tried installing the newer seagrid version, I had trouble with the mex stuff and recieved the following advice from a kind person who no longer wishes to be bothered by Seagrid questions:
"The "SeaGrid" PCWIN mex-files have rarely worked, or never, and I have recommended that users invoke the "View/Setup" menu to turn them off. Alternatively, turn them off permanently at the end of the
"seagrid/seagrid.m" function."
Be careful if you do this! By turning off the mex-files for Seagrid, you are using a different elliptic solver, and you will get a different orthogonality error for the same grid. My experience has been that the error for the non-mex version can be signficantly larger than for the mex-file version.

So be sure to check the orthogonality of your grid (always a good idea anyway) by clicking <Compute>=>Orthogonality from the SeaGrid menu.

rmueller wrote: Extract mexnc folder to ‘MEXNCPATH\ mexnc_R2006a\’, which in my case is 'C:\Program Files\MexCDF\mexnc_R2006a'. The mexnc folder (‘mexnc_R2006a’) contains two subfolders, ‘CVS’ and ‘tests’, as well as many files, including 'mexnc.mexw32' and 'netcdf.dll'. Copy 'mexnc.mexw32' and 'netcdf.dll' to MATLABPATH\bin and MATLABPATH\bin\win32, overwriting existing files (if applicable). In my case, MATLABPATH is ‘C:\Program Files\MATLAB72’.
This is a bit more complicated than it needs to be. On Windows systems, Matlab needs the mex file explicitly called from within Matlab to be in the Matlab path (in this case, mexnc). If this mex file depends on other DLL files (such as netcdf.dll) then these DLL files need to be in a directory that is in the system path. That's all. So netcdf.dll does not need to be in the Matlab Path, and there does not need to be more than one copy on your system. Go to MyComputer=>Advanced=>Environmental Variables=>Path if you are not sure what's in your system path.

-Rich

rmueller
Posts: 26
Joined: Thu May 04, 2006 4:15 am
Location: Earth & Space Research

#9 Unread post by rmueller »

Thanks for a heads up on the difference with the orthogonality error. Also, the clarification about the paths is helpful. For some reason, on most websites that discuss installing mex and netcdf, they insist that the .dll and .mexw32 need to be in \bin and bin\win32. It worked, so I never really questioned it.

In any case, the more information that is online about this, the better.

Regards,
Rachael

andres
Posts: 54
Joined: Tue May 06, 2003 4:35 pm
Location: University of Concepcion
Contact:

#10 Unread post by andres »

kate wrote:Thanks for the pointer to a new toy! It works with xcoast about as well as my old Fortran codes.
Hi Kate,
Where can I find xcoast?

Andres

jpringle
Posts: 108
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

#11 Unread post by jpringle »

Hi all-

I think Kate's problems are, indeed, due to her mexcdf install. Several other folks have used my code without an issue. I am not sure, however, what the issue is, which is less helpful than I would like to be.

Also, Kate mentioned
This works for ETOPO5, ETOPO2, and now GEBCO, .... If you've got something better regionally, that's a different story (you lucky devil, you).
I would encourage people modeling the coastal US to check out

http://www.ngdc.noaa.gov/mgg/coastal/coastal.html

I have had good luck with this very high resolution (up to 3sec) bathymetry. It is not perfect, and will often need to be smoothed because of its high resolution, but it is very good.

Below is a small piece of code to read in the data from this web site, if it is saved in the GEODAS ASCII format.

Cheers,
Jamie

Code: Select all

%convert GEODAS ascii to a matlab file containing the variable "bathy" with 
%the fields
% bathy.lat, latitude
% bathy.lon, longitude
% bathy.depth, depth data in meters
% bathy.filename, the filename of the data
% bathy.dir, the directory this code is run in
%
% Jamie Pringle, 7/24/03

%filename of data, without extention
filename = 'PtReyes_1957';

fid=fopen([filename '.asc']);

%get info
ny=fscanf(fid,'NCOLS %f\n',1)
nx=fscanf(fid,'NROWS %f\n',1)
lon0=fscanf(fid,'XLLCORNER %f\n',1)
lat0=fscanf(fid,'YLLCORNER %f\n',1)
dlat=fscanf(fid,'CELLSIZE %f\n',1)
baddata=fscanf(fid,'NODATA_VALUE %f\n',1)

lat=lat0 + (0:nx-1)*dlat;
lon=lon0 + (0:ny-1)*dlat;
depth=zeros(nx,ny);

for n=1:nx
  depth(n,:)=fscanf(fid,'%f',ny)';
  n
end

depth=flipud(depth);

indx=find(depth==baddata);
depth(indx)=nan;

bathy.lat=lat;
bathy.lon=lon;
bathy.depth=depth;
bathy.filename=filename;
bathy.dir=pwd;

save(filename,'bathy')

indx=find(depth>0); depth(indx)=nan;
pcolor(lon,lat,depth); shading flat; caxis([-150 0]); colorbar

fclose(fid);


User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

#12 Unread post by kate »

andres wrote: Hi Kate,
Where can I find xcoast?

Andres
I've got a new version here. The old one is probably still at Rutgers somewhere, but was giving way too many warnings from modern gcc.

Some of you may know how I feel about Matlab. I have instead written an NCL script to take the gridgen output and create a ROMS NetCDF file. Unfortunately, NCL doesn't have map projection routines except in its private guts, so I'll probably end up trying Python for this. Anyway, my NCL script is assuming you ran gridgen asking for Lm*2+1,Mm*2+1 gridpoints and does the "right" thing for the staggered grids and the image points.

Rich - I finally got matlab on my mac and the seagrid thing is dying in test_mexsepeli with "afun*dfun less than or equal to 0". I can't believe it, but I got test_mexrect to run.

User avatar
shchepet
Posts: 188
Joined: Fri Nov 14, 2003 4:57 pm

RE: grid generation

#13 Unread post by shchepet »

Dear Kate, Rich, and all,

I am just wondering: sometime ago, back in February 2004 Hernan asked me to revise mex-function interface and fortran code "mexsepeli" in order to enable it to work on Linux platform and being called from Matlab on Linux. Which I succeeded to do. I knew that it was needed for grid-generation.

Did you find any use for it?

andres
Posts: 54
Joined: Tue May 06, 2003 4:35 pm
Location: University of Concepcion
Contact:

#14 Unread post by andres »

kate wrote:
andres wrote: Hi Kate,
Where can I find xcoast?

Andres
I've got a new version here. The old one is probably still at Rutgers somewhere, but was giving way too many warnings from modern gcc.
Hi Kate,

Thank your for the program. Seems it needs the world_int.cst file, which I can't access from http://marine.rutgers.edu/po/gridpak.html do you know where I can find it?


Andres

OcGaBy
Posts: 27
Joined: Wed Sep 13, 2006 3:25 pm
Location: National Oceanography Centre

seagrid issues...

#15 Unread post by OcGaBy »

I'am using seagrid with Matlab 7 in windows envirnoment. I get it to work, together with mexnc and NetCDF_Toolbox. All the seagrid test's are fine and Its seems to work all cool, but when I try to convert a file to NetCDF using the function seagrid2roms I get this error

Code: Select all

>> seagrid2roms('LaMalla.mat', 'roms_grd.nc')
 ## SeaGrid Source File  : LaMalla.mat
 ## ROMS Destination File: roms_grd.nc
 ## Defining Global Attributes...
 ## Defining Dimensions...
 ## Defining Variables and Attributes... 
 ## Filling Variables...
??? varput1:  cannot have empty set in input position 4.


Error in ==> mexcdf53 at 9
 [varargout{:}] = feval('mexnc', varargin{:});

Error in ==> ncmex at 139
 [varargout{:}] = feval(fcn, varargin{:});

Error in ==> ncvar.subsasgn at 244
      status = ncmex('varput1', ncid(self), varid(self), ...

Error in ==> netcdf.subsasgn at 83
      result = subsasgn(v, s, other);

Error in ==> seagrid2roms at 442
nc{'spherical'}(:) = 'T';   % T or F -- uppercase okay?
My matlab paths seems to be ok, as everyone suggest, can sombody help me to fix this...?

Greetings
GaBy

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

#16 Unread post by kate »

andres wrote: Hi Kate,

Thank your for the program. Seems it needs the world_int.cst file, which I can't access from http://marine.rutgers.edu/po/gridpak.html do you know where I can find it?

Andres
It is at http://people.arsc.edu/~kate/grids/world_int.cst. However, this is just an example of one possible coastline file. It comes from the GMT coastlines via a matlab script to extract part or all of the coasts at one of five different resolutions and write to ASCII or matlab binary. The extract script is part of Hernan's matlab tarball on the ROMS tools site. So this file is the whole world at the intermediate resolution, which is good enough for basin-scale plots, but not good enough for high-resolution small domains.

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

seagrid issues

#17 Unread post by rsignell »

OcGaBy wrote:I'am using seagrid with Matlab 7 in windows envirnoment. I get it to work, together with mexnc and NetCDF_Toolbox. All the seagrid test's are fine and Its seems to work all cool, but when I try to convert a file to NetCDF using the function seagrid2roms I get this error...
seagrid2roms works fine for me, but I seem to remember that at one point the netcdf_toolbox was having problems with this.

Make sure you have the most recent version of the netcdf_toolkit, and if that doesn't do it, make sure that your mexnc and netcdf.dll are the most recent also.

I'm using versions:
NetCDF Toolbox 1.0.10 from Feb 24, 2006
Mexnc 2.0.19 from May 25, 2006
netcdf.dll, 204,800 byes from July 12, 2005

-Rich

sak007

main features of `gridgen'

#18 Unread post by sak007 »

Hello everyone,

I came across this discussion and was very happy that quite a few people find `gridgen' useful and easy to use.

It occured to me that a list of the main features of `gridgen' could often help to decide whether it is the right tool in a particular context, without actually trying it. Following is such a list, to indicate what `gridgen' can do and what it can not (also added to the README file), and by all means please do not hesitate to ask me a question.
  1. `gridgen' generates a grid based on the domain boundary and the designated locations of the grid corners.
  2. `gridgen' can handle simply connected regions only. If you have a region with an island or re-connecting channels, the only way you can generate a grid for it with `gridgen' is through masking.
  3. Unlike many other generators, `gridgen' allows multiple corners (rather than 4 corners) in the index space. This gives one a great flexibility in regard to the representation of complicated regions.
  4. Unlike many other generators, `gridgen' does not allow to specify cell size explicitely. One can influence the cell density by:
    1. Changing positions of the corners.

      Compare grids for examples 1 and 2 from the package; they demonstrate how the relative cell density may be changed via the positions of the grid corners.
    2. By specifying node coordinates in the index space.

      This is done via the entry `grid' in the parameter file. This entry points at the file that contains node coordinates in index space scaled to 1x1 square. Two examples of using this technique may be seen at

      http://www.marine.csiro.au/~sakov/fitzroy.pdf

      (note elongated cells in the river); and

      http://www.marine.csiro.au/~sakov/torres.pdf

      (note the elongated cells in the narrowing).
    Despite the flexibility of `gridgen', I still find it difficult or impossible at times to achieve some specific grid characteristics for regions far from the boundary. This particularly refers to the alignment of the grid cells in a certain (flow) direction or to obtaining the desired cell density.
  5. Because `gridgen' is based on the (exact) Schwarz-Christoffel formula, it performs fast and is numerically robust.
  6. Beware that each boundary vertex represents a singularity in the Scwartz-Christoffel transform. To generate a smoother grid, for a section of the boundary without corners, avoid putting large angles close to water; try making sharp turns by using a few smaller turns rather than one big turn; or move the boundary polyline a away from the water. Also, try to make a right turn in the boundary polyline at the location of designated corners.
  7. To generate a grid with aspect ratio close to 1, look at the value of "conformal modulus" reported in the log generated by `gridgen' with "-v" option, and make the ratio (ny - 1) / (nx - 1) close to this number.
Pavel

OcGaBy
Posts: 27
Joined: Wed Sep 13, 2006 3:25 pm
Location: National Oceanography Centre

Can't jump from analitical to hand-made grids!!!!!

#19 Unread post by OcGaBy »

I'm using seagrid to generate grids. As my model blows up after a while, I start simplifying my bathymetry and mask. Just to be sure that It was the wrong thing I emulated with the seagrid an analytical grid that I used before to try my application, and I discover that just by changing to a crated grid the model become unstable after a while, even if the grid was just a rectangle with plane bottom, example that works fine when the same conditions are set analytically.

Can some body tell me what is wrong here??

Greetings
GaBy

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: Can't jump from analitical to hand-made grids!!!!!

#20 Unread post by kate »

OcGaBy wrote: Can some body tell me what is wrong here??
Not without seeing your grid file. Did you give it a perfectly rectangular region in seagrid?
Even if things aren't perfectly rectangular and orthogonal, I would have expected ROMS to run, though perhaps with larger errors than with an analytic grid.

OcGaBy
Posts: 27
Joined: Wed Sep 13, 2006 3:25 pm
Location: National Oceanography Centre

Set a minimum depth biger than 0

#21 Unread post by OcGaBy »

Thanks for your attention Kate!

The thing was that I was getting depths of cero in the borders of the rectangle. And the same when I used my bathymetry, even where there are no ceros in the original data, the seagrids sometimes compute to cero where there are small depths. The thing is to set something like 1 or 2 as minimum depth in the seagrid… Where is the information about these small details that can drive you crazy in some moments?? :roll:

There's no body around me working with ROMS and is being quite difficult to me to figure it out all by my self…

I think there is a lot of information missed for new users, maybe thinks that are quite obvious for you that have been workings with ROMS for a while… I think it is an important point to promote the use of ROMS… I can’t wait to see what are they going to publish in “CONFIGUING ROMS”…

RubenDiez-Lazaro

#22 Unread post by RubenDiez-Lazaro »

I am on same situation that OcGaBy: alone and (I think) with bad grid... Perhaps a Bulletin Board only for the very beginners?

User avatar
hetland
Posts: 81
Joined: Thu Jul 03, 2003 3:39 pm
Location: TAMU,USA

Gridgen with python

#23 Unread post by hetland »

All

I have made a gridgen wrapper for python. This is not too terribly different from using gridgen from the command line, but it does keep everything in one place.

You can get it with subversion using the command

svn co http://pong.tamu.edu/svn/python/trunk/gridgen gridgen

You can browse the code with a web browser using the same address.

An example of a grid made using this utility can be seen here:

http://pong.tamu.edu/~rob/plume/merrimack/grid.pdf

-Rob

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

#24 Unread post by kate »

RubenDiez-Lazaro wrote:Perhaps a Bulletin Board only for the very beginners?
You can't be serious - you need us and we need to know what you are struggling with.

So is Seagrid making bad grids for people? We need to know that and replace it. Personally, I have never gotten it to really work and always go back to my nasty old fortran code that no one else will touch. :twisted:

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#25 Unread post by rsignell »

kate wrote: So is Seagrid making bad grids for people? We need to know that and replace it. Personally, I have never gotten it to really work and always go back to my nasty old fortran code that no one else will touch. :twisted:
Seagrid doesn't make bad grids. People make bad grids. :wink:

Seriously, I and many others have been using Seagrid for years, and although the installation and quirks can be annoying, once you get the hang of it, it's pretty easy to modify the grid until you get something that has the grid resolution where you want it, and has small orthogonality errors on wet points.

Seagrid works well if your domain can be grid with 4 corners. If not, you need Sakov's grid generation tool.

-Rich Signell

carniel
Posts: 17
Joined: Tue Feb 17, 2004 10:12 am
Location: CNR-ISMAR

#26 Unread post by carniel »

rsignell wrote:
Seriously, I and many others have been using Seagrid for years, and although the installation and quirks can be annoying, once you get the hang of it, it's pretty easy to modify the grid until you get something that has the grid resolution where you want it, and has small orthogonality errors on wet points.

Seagrid works well if your domain can be grid with 4 corners. If not, you need Sakov's grid generation tool.

-Rich Signell

I can add some confusion on all this!
I am trying to setup a grid having a domain of 100x80; if under "view-setup" I tick the mexcdf option, I have some irregular shaping of the cells, lines are not orthogonal and go up and down. Rich said this may happen, since we are using a different elliptic algh., I think I recall.
When I untick it, I have regular orthoghonal cells, perfectly orthogonal to each other, but I cannot decide, apparently, how many along each direction. Seagrid helps itself, keeping the grid sizes square. When we convert the .mat -> .nc with seagrid2roms, I see a much larger than expected number of cells (e.g. 250x80).
Fiddling around with MATLAB path, I found out that all these problems disappear when I moved my /presto directory at the bottom of the path and removed the /seagrid/presto one.
This was a kind of lucky one, since the more things you store into your path, the more you are likely te get these troubles, I believe.
So, since there are possibly some pieces of scripts that sometimes may collide with each other, maybe we need not only a stable version of Seagrid (Rich, I agree the one in the web is stable enough, so to speak) but could also benefit from a list of things-to-be-avoided, like the case that happened to me.
Cheers,

Sandro

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#27 Unread post by rsignell »

Sandro,

Several comments on the above problems:

1) Presto: Seagrid depends on Presto, and we therefore supplied Presto as a subdirectory of the Seagrid distribution. This version should be in the matlab path, not some other version of Presto. It should not matter where it is in the path unless there is a conflict with some other toolbox.

2) Solver and orthogonality: I have never seen a case where unchecking the "UseMexFile" box (on the "View=>Setup" control panel) resulted in a more orthogonal solution.

3) Spacing along boundaries: Initially, Seagrid assumes that the number of grid lines you specify are uniformly spaced along side 1 and side 2. You can change side 1 to side 3, and side 2 to side 4 by using the "View=>Spacing Setup" control panel. You can then of course, adjust the sliders to make varying resolution along the two sides you have selected.

Hope this helps,
Rich

nganju
Posts: 82
Joined: Mon Aug 16, 2004 8:47 pm
Location: U.S. Geological Survey, Woods Hole
Contact:

seagrid funkiness

#28 Unread post by nganju »

I was going to stay quiet, since seagrid has always worked ok for me, but i have always had the same quirks mentioned by sandro (except for the presto path issue). I get more orthogonal results with mex off, and the cell density is always changed when i convert to a roms file using seagrid2roms. i usually just deal with it, but today I had major problems with a new bathymetry set.

The data are very detailed, with spacing at every meter (a narrow river). Seagrid seems to not want to interpolate properly to the data points, and where there is large variability in depth, seagrid runs a plane right through them. I have the seagrid dx and dy down to the same meter scale. Any ideas?

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#29 Unread post by rsignell »

Neil,

Can you put the problematic coast, bathy and seagrid file somewhere so I can take a look?

Thanks,
Rich

nganju
Posts: 82
Joined: Mon Aug 16, 2004 8:47 pm
Location: U.S. Geological Survey, Woods Hole
Contact:

matlab's fault?

#30 Unread post by nganju »

Thanks for the offer Rich-
I was getting the files ready for you, and I tried something different: I created the grid, opened it in Matlab, and recomputed the depths using:

zi=griddata(xbathy,ybathy,zbathy,lon_rho,lat_rho);

I got the same strange result as seagrid gave. Then I remembered a problem I had a few years back with 25 m gridded data (over the entire SF Bay) in Matlab: I had to multiply the longs and lats by 1e6, then subtract the leading digits for Matlab to perform a successful triangulation. Otherwise it reported multiple x-y values or unsuccessful triangulation. So I tried that this time, and voila--it worked. Then you put the coordinates back into the correct system.

I think very small differences between coordinates, when the coordinate value is high, e.g. 111 degrees, with the next coordinate only 1e-5 degrees away, creates some sort of problem, but I don't know why.

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: RE: grid generation

#31 Unread post by rsignell »

shchepet wrote:Dear Kate, Rich, and all,

I am just wondering: sometime ago, back in February 2004 Hernan asked me to revise mex-function interface and fortran code "mexsepeli" in order to enable it to work on Linux platform and being called from Matlab on Linux. Which I succeeded to do. I knew that it was needed for grid-generation.

Did you find any use for it?
Sasha,

Sorry, I missed this post. Yes, the Linux version of seagrid depends on "mexsepeli", which works fine.

Thanks,
Rich

jpringle
Posts: 108
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

#32 Unread post by jpringle »

Dear all-

If you are using Pavel of CSIRO's gridgen, I have a little chunk of matlab code which allows you to specify the resolution of the grid along the edges of the model domain. If you are interested, mail me. I am not yet distributing it publicly because the rest of my evolving non-interactive grid generation package is not well documented, and only works for one corner case -- mine.

Note that this code only exactly works for rectangular domains. Otherwise, it only lets you approximately set the resolution, for gridgen must still satisfy the constraints of orthogonality, etc. This is no different then seagrid, for it must satisfy the same constraints.

Cheers,
Jamie

Barbara
Posts: 25
Joined: Thu Sep 14, 2006 4:33 pm
Location: LTO, SCSIO

How to make large grid by seagrid?

#33 Unread post by Barbara »

Hi all,

i want to make large grid of 400×200 by seagrid, and i increased the NX, NY in mexsepeli.inc, and the size of the Z array in mexrect.F. But it is still not working.


??? warning - tracking error

Error in ==> C:\MATLAB6p1\toolbox\seagrid\mex\mexrect.dll
Error in ==> C:\MATLAB6p1\toolbox\seagrid\mexrect2grid.m
On line 98 ==> zrect = feval('mexrect', zrect, length(zrect), ...

Error in ==> C:\MATLAB6p1\toolbox\seagrid\@seagrid\gridcalc.m
On line 179 ==> [w, err] = feval(theFcn, zti, [], ci, [m n]); % <Error> C:\MATLAB6p1\toolbox\seagrid\@seagrid\dogrid.m
On line 64 ==> gridcalc(self) % <Calculate> C:\MATLAB6p1\toolbox\seagrid\@seagrid\doupdate.m
On line 92 ==> dogrid(self, needsUpdate); % <== Step #2 <Error> C:\MATLAB6p1\toolbox\seagrid\@seagrid\doevent.m
On line 188 ==> doupdate(self)

Error in ==> C:\MATLAB6p1\toolbox\seagrid\presto\psevent.m
On line 25 ==> doevent(ps(gcbf), theEvent, theMessage);

??? Error while evaluating uimenu Callback.


Do I have to make the seagrid mexfiles from source by make_seagrid_mex ? if so, how should I modify the compiler options in *.sh file if i use Compaq visual fortran.

Thanks!

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#34 Unread post by rsignell »

Barbara,

I increased the size to 1200x1200 and recompiled. If you replace your win32 mex files with these, does it work?

http://stellwagen.er.usgs.gov/rps/share ... d_mex2.zip

-Rich

Barbara
Posts: 25
Joined: Thu Sep 14, 2006 4:33 pm
Location: LTO, SCSIO

#35 Unread post by Barbara »

Hi Rich,

Thanks for your help! I copied these two files into my matlab\toolbox\seagrid\mex, it is still not working. i wonder if i have misunderstood what you mean, cause i don't have mexsepeli.mexw32 or mexrect.mexw32 in the original seagrid\mex folder.
If you replace your win32 mex files with these

Thanks!
Barbara

User avatar
wilkin
Posts: 922
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

Re: How to make large grid by seagrid?

#36 Unread post by wilkin »

Barbara ZU wrote:Hi all,

i want to make large grid of 400×200 by seagrid, and i increased the NX, NY in mexsepeli.inc, and the size of the Z array in mexrect.F. But it is still not working.


??? warning - tracking error

...

Thanks!


The "tracking error" is a failure of the conformal mapping algorithm to map the irregular boundary to a rectangle. It is deep inside the Ives and Zacharias algorithm that underpins seagrid and other related grid generating tools.

It is true that this error does tend to occur more frequently if the boundary has a large number of points, but is also more likely to be triggered in grids with high aspect ratios or highly variable distributons of points along a long boundary. Are these features of your grid?

Do you get an acceptable looking grid with smaller numbers of boundary points?

Is the tracking error sensitive to the number of points along one particular boundary, more than the other?

If the boundary you specify is quite irregular, check whether you end up with some very small or very large cells. If you have an unacceptably large range of cell sizes (that will cause strict CFL time step limitations later) then consider smoothing out the input boundary curve a little. This generally reduces the demands on the conformal mapping step.

If you still have problems, include a small gif/jpeg of your boundary shape in your next post.

John.
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

Barbara
Posts: 25
Joined: Thu Sep 14, 2006 4:33 pm
Location: LTO, SCSIO

#37 Unread post by Barbara »

Hi John,

Thanks for your information! I forget to mention that every time I launch seagrid, some warnings appear:

>> seagrid
??? SWITCH expression must be a scalar or string constant.

Error in ==> C:\MATLAB6p1\toolbox\seagrid\@seagrid\doticks.m
On line 78 ==> switch lower(theMapUnits)

Error in ==> C:\MATLAB6p1\toolbox\seagrid\@seagrid\doevent.m
On line 403 ==> doticks(self)

Error in ==> C:\MATLAB6p1\toolbox\seagrid\presto\psevent.m
On line 25 ==> doevent(ps(gcbf), theEvent, theMessage);

??? Error using ==> set
Error while evaluating figure ResizeFcn.

I haven't figured out how to modify this, and I don't know if the problem is also related to this error.



My domain is almost a rectangle, the aspect ratio is about 1:2.3

I could successfully generate grid with the following dimension:
300*150, 300*100
300*160, 400*100
300*200

but the "tracking error" occurs when I try to make grid with:
350*160 , 400*120, 320*200

and " Segmentation violation detected" when I try to make grid:
500*100, 380*150

I wonder if we want to get good grid, we'd better set the number of the grid points on each side of the boundary proportional to aspect ratio of the boundary, i.e. each grid cell is more like a square rather than a rectangle.

Thanks for your help!
Barbara

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

Seagrid vs Gridgen

#38 Unread post by nacholibre »

Dear all,
I am planning to model the entire Georgia and SC coast in detail. I used Seagrid for a few small areas I studied on, but I thought Gridgen might be a better option since it had more flexibility. I have read the bulletin board, but I am still unclear about following things:
1. is it possible to define more than 4 corners with gridgen and use the grid in ROMS?
2. If using only 4 corners, what advantage does Gridgen have over Seagrid? -In that case at least Seagrid seems to be more userfriendly to me.
Thank you very much for your comments in advance.
Last edited by nacholibre on Tue May 19, 2015 7:06 pm, edited 2 times in total.

jpringle
Posts: 108
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

#39 Unread post by jpringle »

I have a matlab code that calls gridgen and allows you to specify multiple points along each edge, and to specify (roughly) a spatially variable resolution within the model domain. It works well for me, and is reasonably well documented.

One caution, however -- if you have a very high-resolution coast with many twists and turns, you are more likely to have success by creating a grid that only roughly follows the coast, and then using land masking to get the exact coastline. Sharp changes in the coastline angle, along with the orthogonality constraints on the model grid, tend to cause un-helpful changes in model resolution and numerical errors near points and bays.

I can post the code for using grid friday afternoon on this forum, but am busy before then writing exams and with the end of term. You can try the codes I have already mentioned in this thread, or try Rob Hetland's python versions.

Cheers,
Jamie Pringle

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

how to increase the gridsize in seagrid

#40 Unread post by nacholibre »

rsignell wrote:Barbara,

I increased the size to 1200x1200 and recompiled. If you replace your win32 mex files with these, does it work?

http://stellwagen.er.usgs.gov/rps/share ... d_mex2.zip

-Rich
Hello,
I am having a similar problem to what Barbara had. I would like to increase the grid size (say 400x400). I increased the number in mexinside.c and compiled it. However, It still does not work. When I use the make_seagrid_mex.m I get error messages for the line
mex -v mexrect.F
It seems like my fortran compiler is not correctly installed or not the correct type? Because I get the following error messages:
Thank you for any help.
Zafer
lcc preprocessor error: mexrect.F:1 Could not find include file <fintrf>
lcc preprocessor error: mexrect.F:4 Unterminated string or char const
lcc preprocessor error: mexrect.F:5 Unterminated string or char const
Error mexrect.F: 2 syntax error; found `c' expecting `;'
Error mexrect.F: 2 syntax error; found `mex' expecting `;'
Error mexrect.F: 2 syntax error; found `routine' expecting `;'
Error mexrect.F: 2 syntax error; found `implementing' expecting `;'
Error mexrect.F: 2 syntax error; found `rect' expecting `;'
Error mexrect.F: 2 syntax error; found `.' expecting `;'
Error mexrect.F: 2 skipping `.'
Error mexrect.F: 2 syntax error; found `as' expecting `;'
Error mexrect.F: 2 syntax error; found `taken' expecting `;'
Error mexrect.F: 2 syntax error; found `from' expecting `;'
Error mexrect.F: 2 syntax error; found `Ives' expecting `;'
Error mexrect.F: 2 syntax error; found `.' expecting `;'
Error mexrect.F: 2 skipping `.'
Error mexrect.F: 2 syntax error; found `.' expecting `;'
Error mexrect.F: 2 skipping `.'
Error mexrect.F: 3 syntax error; found `c' expecting `;'
Error mexrect.F: 3 syntax error; found `R' expecting `;'
Error mexrect.F: 3 too many errors

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#41 Unread post by rsignell »

Nacholibre,

I don't know what you are doing wrong, but I hope this will help. This is the output from a successful compilation of the seagrid mex files I just performed on my RHEL4 Linux system on Intel32 with Matlab 7.2. The compilers are just gcc and g77. I'm including the verbose output only for the compilation of "mexsepeli", as the others are similar.

Code: Select all


>> mex mexinside.c
>> mex mexrect.F
>> mex -v -I. mexsepeli.F       % include the local directory so mexsepeli.inc is found

-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /home/rsignell/.matlab/R2006a/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /usr/local/matlab7.2
->    CC                    = gcc
->    CC flags:
         CFLAGS             = -fPIC -ansi -D_GNU_SOURCE -pthread -fexceptions -m32
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/usr/local/matlab7.2/bin/glnx86 -L/usr/local/matlab7.2/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++
         arguments          = 
->    CXX                   = g++
->    CXX flags:
         CXXFLAGS           = -fPIC -ansi -D_GNU_SOURCE -pthread 
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = -Wl,-rpath-link,/usr/local/matlab7.2/bin/glnx86 -L/usr/local/matlab7.2/bin/glnx86 -lmx -lmex -lmat -lm
         arguments          = 
->    FC                    = g77
->    FC flags:
         FFLAGS             = -fPIC -fexceptions
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/usr/local/matlab7.2/bin/glnx86 -L/usr/local/matlab7.2/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++
         arguments          = 
->    LD                    = g77
->    Link flags:
         LDFLAGS            = -pthread -shared -m32 -Wl,--version-script,/usr/local/matlab7.2/extern/lib/glnx86/fexport.map
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexglx
         arguments          = 
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          = 
----------------------------------------------------------------

-> g77 -c  -I. -I/usr/local/matlab7.2/extern/include -fPIC -fexceptions  -O mexsepeli.F

-> g77 -O -pthread -shared -m32 -Wl,--version-script,/usr/local/matlab7.2/extern/lib/glnx86/fexport.map -o mexsepeli.mexglx  mexsepeli.o /usr/local/matlab7.2/extern/lib/glnx86/version4.o  -Wl,-rpath-link,/usr/local/matlab7.2/bin/glnx86 -L/usr/local/matlab7.2/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++

>> 


nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

segmentation violation problem resolved - seagrid

#42 Unread post by nacholibre »

Thank you very much for the quick reply. I just realized that there are actually two different addresses for Seagrid.
http://woodshole.er.usgs.gov/operations ... index.html
and
http://woodshole.er.usgs.gov/operations ... agrid.html
I downloaded Seagrid again and used the specific folder for the versions that I am using. Thank you for increasing the dimensions to 1200x1200 already. I did not need to compile.
Thank you very much again.
zafer

rouf

#43 Unread post by rouf »

I'am using seagrid with Matlab 7 in windows environment with cygwin. I downloaded mexnc.R14sp3-2.0.29-3.tar.gz, netcdf-3.6.2. and netcdf_toolbox-1.0.12.tar.gz. All the seagrid test's are fine and seems to work all cool, but when I try to convert a seagrid file to NetCDF using the function seagrid2roms I get this error
>> seagrid2roms


## SeaGrid Source File : C:\matlab[1]\matlab\genga.mat
## ROMS Destination File: C:\Documents and Settings\Muhammad Abdur Rouf\Desktop\roms_grd.nc


??? Undefined function or variable "fcn".

Error in ==> ncmex at 108
[varargout{:}] = feval(fcn, varargin{:});

Error in ==> netcdf.create at 13
[theNCid, status] = ncmex('create', name(self), thePermission);

Error in ==> netcdf.netcdf at 428
result = create(result, thePermission);

Error in ==> seagrid2roms at 142
nc = netcdf(theRomsFile, 'clobber');

for more information about installation, my configuration as follows
>> which('mexnc','-all')
C:\Program Files\MATLAB71\bin\win32\mexnc.mexw32
C:\Program Files\MATLAB71\bin\mexnc.mexw32 % Shadowed
C:\Program Files\mexnc\mexnc.mexw32 % Shadowed

>> which('netcdf','-all')
C:\Program Files\MATLAB71\toolbox\netcdf_toolbox\netcdf\@netcdf\netcdf.m % netcdf constructor
C:\matlab[1]\matlab\netcdf\@netcdf\netcdf.m % Shadowed netcdf constructor
C:\Program Files\MATLAB71\bin\win32\netcdf.dll % Shadowed
C:\Program Files\MATLAB71\bin\netcdf.dll % Shadowed
C:\Program Files\mexnc\win32\netcdf.dll % Shadowed

>> mexnc('strerror',0)

ans =

No error
I went through this thread and get lost.

Can anyone help me?

Rouf

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#44 Unread post by rsignell »

When I use seagrid2roms, I call it with two arguments: the name of the mat file that seagrid produced, and the name of the output grid file for ROMS, like this:
seagrid2roms('seagrid.mat','roms_grid.nc');
-Rich

rouf

#45 Unread post by rouf »

Dear Rsignell,

Thanks for informing the way of seagrid2roms calling arguments. Actually, I am confused about the placement of netcdf.dll, mex files and NetCDF toolbox directories that gives the above errors. But now, I follow your following placement order.

Rsignell mentioned on MexNC, NetCDF and Matlab? Under Roms Problem thread
seagrid2roms uses the NetCDF Toolbox, which in turn uses mexnc. It works fine on win32 with any version of matlab, but you need to get the right mexnc mex file. Then you just need:
The mex file in a directory that is in your Matlab path
The netcdf.dll in a directory that is in your Windows system path
The NetCDF toolbox directories (netcdf, netcdf\nctype, and netcdf\ncutility) in your Matlab path
In that case, after installing mexnc, I cut (instead of copy as mentioned in point 6 of the tutorial: Installing MEXNC, SNCTOOLS and ROMS-Matlab-toolkit, Roms tutorials) the netcdf.dll and pest to Windows system path. So that netcdf.dll will not be anyway on matlab path.
I also avoid downloading NetCDF Toolbox separately from http://mexcdf.sourceforge.net as I found all that toolbox directories are included on matlab directory under ROMS processing package.

Am i right upto that?

Now Matlab can create nc file from seagrid file but still the matlab script showing following errors. Should I be worried about this error. If these are important pls suggest me how to solve the errors.
## SeaGrid Source File : C:\matlab[1]\matlab\genga.mat
## ROMS Destination File: C:\matlab[1]\matlab\roms_grd.nc
## Defining Global Attributes...
## Defining Dimensions...
## Defining Variables and Attributes...
## Filling Variables...
??? varput1: cannot have empty set in input position 4.


Error in ==> mexcdf53 at 9
[varargout{:}] = feval('mexnc', varargin{:});

Error in ==> ncmex at 139
[varargout{:}] = feval(fcn, varargin{:});

Error in ==> ncvar.subsasgn at 244
status = ncmex('varput1', ncid(self), varid(self), ...

Error in ==> netcdf.subsasgn at 83
result = subsasgn(v, s, other);

Error in ==> seagrid2roms at 442
nc{'spherical'} = 'T'; % T or F -- uppercase okay?

Rouf

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

#46 Unread post by rsignell »

rouf wrote: I also avoid downloading NetCDF Toolbox separately from http://mexcdf.sourceforge.net as I found all that toolbox directories are included on matlab directory under ROMS processing package.
I'm not sure if this is the problem, but I recommend going to
http://mexcdf.sourceforge.net/
and getting the latest mexnc and NetCDF toolbox, and then see if you still have the problem. You can test the NetCDF toolbox by typing "tnetcdf" at the Matlab prompt.

Arianna

#47 Unread post by Arianna »

Dear rouf,
I had similar problem using some scripts of the matlab folder. I founded that the scripts are written for the Matlab version number 6,5, and 4, while I'was using the 7 one.
I solved my problems correcting the ncmex.m and mexcdf.m files in the folders:
my_path/matlab/netcdf/ncutility
and
my_path/matlab/mexcdf5
with the actual version of Matlab, which I got typing "version" in the Matlab prompt. In my case the correction results:
% Mex-file gateway.
if version(1) == '7.0.0.19920 (R14)'
fcn = 'mexnc'; % Matlab-7.
elseif version(1) == '4'
fcn = 'mexcdf4'; % Matlab-4 only.
else
error(' ## Unrecognized Matlab version.')
end
I set fnc ='mexnc' istead of 'mexcdf53' because of the version I dowloded from the site http://mexcdf.sourceforge.net/ for Windows and Matlab 7 release 14.
I hope it can help you. :)
Cheers Arianna

rouf

#48 Unread post by rouf »

Dear Arianna,

I solve the problem in different way. I went to http://mexcdf.sourceforge.net/
and download the latest mexnc and NetCDF toolbox, as Rsignell suggest.
After that, I rearrange my Matlab path. I keep the NetCDF toolbox above the matalb supported netcdf files on Matlab path. Now there is no error when i convert seagrid file to .nc file.
I also test the NetCDF toolbox by typing "tnetcdf" at the Matlab prompt. It seems work and showed netcdf browser.
Thanks rsignell and Arianna.

Rouf

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

Seagrid

#49 Unread post by nacholibre »

rsignell wrote: I increased the size to 1200x1200 and recompiled. If you replace your win32 mex files with these, does it work?

http://stellwagen.er.usgs.gov/rps/share ... d_mex2.zip

-Rich
Is it possible to have seagrid handle a much larger grid like 2000x2000? The latest version I got from the web page gives the following error whenever I try to create a grid with any dimension larger than 1000. Would it require a recompile again?.
Thank you,
Zafer

Code: Select all

??? Error using ==> mexsepeli
work space length input in w(1) is not right

Error in ==> mexrect2grid at 206
	[u, v] = feval('mexsepeli', u, v, l2, m2, seta, sxi);

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Grid generation

#50 Unread post by rsignell »

Yes, you can recompile it using a larger dimension. Or even better, you could rewrite it to use dynamic memory allocation so people wouldn't have to do this in the future!
-Rich

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

Re: Grid generation

#51 Unread post by nacholibre »

rsignell wrote:Yes, you can recompile it using a larger dimension. Or even better, you could rewrite it to use dynamic memory allocation so people wouldn't have to do this in the future!
-Rich
I have never done it before, so I would be happy if you could please direct me in the correct direction. I am assuming that I will be changing a few parameters in fortran codes and compiling them. Or is it maybe more tedious than that??
Thanks
Last edited by nacholibre on Fri Aug 28, 2009 3:22 pm, edited 1 time in total.

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Grid generation

#52 Unread post by rsignell »

Yes, the easy way is just increase the array sizes in mexsepeli.inc and recreate the mex file. You might also have to increase the array sizes in mexrect.F (e.g. global replacement of 40000 to 80000 or whatever).

The better way would be to make these allocate memory dynamically, but that would require a fair bit more time and energy.
-Rich

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

Re: Grid generation

#53 Unread post by nacholibre »

Got it :!:
It took more than I thought (getting the Fortran compiler, version problems, manually editing the batch files... etc.), but finally I got it to work! I will be more than happy to help if anybody else ever has a similar problem in the future. :D
Thanks a lot,
Zafer

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Grid generation

#54 Unread post by rsignell »

Congrats! While it's fresh in your mind, it would be great if you would make a few notes on the problems you encountered and how you solved them. I'd be happy to add them to the WikiROMS section on grid generation.
-Rich

User avatar
arango
Site Admin
Posts: 1368
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Grid generation

#55 Unread post by arango »

I should look that program so we can use dynamic allocation of all the arrays needed to build the grid. It is really silly that we need to edit these files. We just use a F90 compiler. Dynamic allocation is really trivial:

Code: Select all

       real, allocatable ::  A2d(:,:)

...

       IF (.not.ALLOCATED(A2d)) THEN
         allocate ( A2d(Im,Jm) )
       END IF
...

rsignell
Posts: 124
Joined: Fri Apr 25, 2003 9:22 pm
Location: USGS

Re: Grid generation

#56 Unread post by rsignell »

That would be great! I'm sure if you took a look you would find a few other things worth fixing up, and it's only two little routines... :)

nacholibre
Posts: 81
Joined: Thu Dec 07, 2006 3:14 pm
Location: USGS
Contact:

Re: Grid generation

#57 Unread post by nacholibre »

rsignell wrote:Congrats! While it's fresh in your mind, it would be great if you would make a few notes on the problems you encountered and how you solved them. I'd be happy to add them to the WikiROMS section on grid generation.
-Rich
I followed the instructions in the readme.txt file in the downloaded seagrid package. The problem was getting the fortran compiler. I used Intel Fortran 11 instead of 9.1. That required me to change some of the lines in the batch files manually. However, there are still some issues.
1. Although it is set to NX=1200, NY=1200 I can still compile grid sizes upto 1000x1000 (whereas it should be limited to 600x600 according to the instructions).
2. If I can't create the grid due to workspace being too small, increasing NX, NY solves the problem. But then I get an out of memory error when I try to compute the masking.
3. Increasing the size of Z, R, and N in mexrect.F doesn't seem to help at all. I get a segmentation error if they are too small, but it seems to be working fine as it is.
4. Well, here is the most interesting part:
Once you exclude the path to mex files it is possible to create very large grids. However, I have found out that the grid is likely to be erroneous in that case. Seagrid does a check in the beginning to include mex files, but there is no warning about the possibility of generated grids being erroneous without them :!:
The error is more apparent for a more curvilinear grid.
Zafer
Last edited by nacholibre on Tue Sep 03, 2013 9:24 pm, edited 2 times in total.

donglai
Posts: 13
Joined: Fri Apr 15, 2005 2:58 pm
Location: Virginia Institute of Marine Science

Re: Grid generation

#58 Unread post by donglai »

I just did a re-write of seagrid2roms.m using Matlab 7.7+ built-in netcdf library. This version has no dependence on the netcdf_toolbox. If anyone's interested in helping me to test the code for various scenarios to shake out the bugs, please let me know.

Cheers,
Donglai

wgjlove
Posts: 5
Joined: Wed Nov 12, 2008 4:24 pm
Location: Ocean University of China

Re:

#59 Unread post by wgjlove »

kawase wrote:Grid generation is definitely important to many of us working in regional applications, and is often the most time-consuming part of the model setup. I'm sure the ROMS community wants an effective curvilinear grid generator.

We've come across "gridgen": http://www.marine.csiro.au/~sakov/

I haven't used this myself but Dmitri Leonov, post-doc working for us, has generated a high-res grid for Puget Sound using this package for use with MITgcm.

Mitsuhiro.
I want to learn how to use the 'gridgen',so I click the connection "http://www.marine.csiro.au/~sakov/ ",but it didn't go to the right page,maybe the address had changed,so could sb tell me where i can find the page which kawase wanted to show?Thank u very much!

User avatar
hetland
Posts: 81
Joined: Thu Jul 03, 2003 3:39 pm
Location: TAMU,USA

Re: Grid generation

#60 Unread post by hetland »

Pavel moved to Norway, and his web site was taken down by CSIRO. You can find his codes here:

http://code.google.com/p/octant/source/ ... ant/extern

Get it with a command like this:

svn checkout http://octant.googlecode.com/svn/trunk/octant/extern sakov

-Rob

sak007

Re: Grid generation

#61 Unread post by sak007 »

gridgen is now hosted on Google Code: http://code.google.com/p/gridgen-c. To checkout, run:

svn checkout https://gridgen-c.googlecode.com/svn/gridgen

-Pavel

sak007

Re: Grid generation

#62 Unread post by sak007 »

sak007 wrote:gridgen is now hosted on Google Code: http://code.google.com/p/gridgen-c. To checkout, run:

svn checkout https://gridgen-c.googlecode.com/svn/gridgen

-Pavel
A correction: "http" without "s":

svn checkout http://gridgen-c.googlecode.com/svn/gridgen

Post Reply