TPXO to ROMS EXPRESS (tide extraction software)

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

TPXO to ROMS EXPRESS (tide extraction software)

#1 Post by johnluick »

I have attached my matlab script for extracting the tidal harmonics from the TPXO 7.2 netcdf files and creating a forcing file for ROMS. I've put everything required (I hope) in the zip file. It also does some plots to check the results. My goal, in writing it, was to simplify the process provided in the ROMS repository of software.

If you find a bug please let me know here in this forum so I can fix it.
TPXOextraction.zip
(11.63 KiB) Downloaded 886 times

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#2 Post by yang »

I have download the files, but the .zip file can not be unzipped correctly. Can you give me the .m files ?

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#3 Post by johnluick »

The problem is with your unzipping software. Here is a link to an evaluation version of WinZip that does work:
http://download.cnet.com/WinZip/3000-22 ... 03164.html
There is plenty of other free compression software. Yes, I tried WinRAR and it failed.
Or you can go to my rather dusty and moth-eaten website www.austides.com where I chose to put the unzipped scripts. While you're there, feel free to ask Professor Loeb a question.

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#4 Post by yang »

Thanks. Now, it works.

User avatar
patrickm
Posts: 25
Joined: Fri Apr 30, 2004 6:41 pm
Location: IRD, FRANCE
Contact:

Re: TPXO to ROMS EXPRESS (tide extraction software)

#5 Post by patrickm »

For information, the romstools package (provided with the agrif version of roms) also has a tidal toolbox (in matlab) that processes TPXO for ROMS. It is called make_tides ...

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#6 Post by johnluick »

I'm glad you mentioned this Patrick. I used to use make_tides and am indebted to it's authors - thank you! The main reason I wrote this was (as I recall) at the time, at least, make_tides required the use of a tidal database (provided with ROMS_Tools) derived from TPXO 6.x, rather than directly using the database OSU provides (which by then was TPXO 7.x, which I wanted to use). Also, I have tried to make this script simpler and more straightforward (not sure if I succeeded). Of course, both scripts will work for both the AGRIF and Rutgers versions.

User avatar
patrickm
Posts: 25
Joined: Fri Apr 30, 2004 6:41 pm
Location: IRD, FRANCE
Contact:

Re: TPXO to ROMS EXPRESS (tide extraction software)

#7 Post by patrickm »

Hi John, make_tides now reads TPXO7 but we will look at your routines. The management and corrections of tidal phase and amplitude needed in the case of real time forcing is not straightforward. If you simplified some of the treatment processes, that would be interesting to us as well. We may want to converge at some point. cheers ... Patrick

chilequan
Posts: 2
Joined: Sat Nov 19, 2011 4:34 pm
Location: Ocean University of China

Re: TPXO to ROMS EXPRESS (tide extraction software)

#8 Post by chilequan »

I think I find a bug. Line 74 and line 80 in file "interpTPXO.m" may lead to mistakes when we get more than one i,j value from
"[j,i]=find(dr==(min(min(dr(VARinterp~=0)))));".

I use "VARinterp(ff(n))=VARinterp(j(1),i(1));" to fix it, but I'm not sure whether it is right.(I don't read scripts carefully for my final exam coming....)

====================appendix==========================
err by matlab:

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> interpTPXO at 80
VARinterp(ff(n))=VARinterp(j,i);

Error in ==> extractTPXOtides at 120
ur=interpTPXO('URe',ROMSnames(k),TPXOfile_vel,TPXOfile_grid,lonR,latR,maskR
--------------------------
then I found in line 73:
K>> [j,i]

ans =

76 28
76 30


And thank you for you scripts. I think its an easy way to create the tide file for ROMS

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#9 Post by johnluick »

Hi Chilequan,

thanks for your interest. I'm unable to reproduce this error, and to tell the truth, I can't see how it could arise (since min(min.. only seems to return a single value even there are two equal minimums), but your solution appears reasonable. If you like, when your exams are finished, we can discuss this offline (my email address is on the website mentioned above). Good luck with them.

John

chilequan
Posts: 2
Joined: Sat Nov 19, 2011 4:34 pm
Location: Ocean University of China

Re: TPXO to ROMS EXPRESS (tide extraction software)

#10 Post by chilequan »

It's true that min(min(....)) can only return a single value. But the codes are

"[j,i]=find(dr==min(min(dr(VARinterp~=0)))));", and

"find(dr=='some value')" may return more than one result.
=================================================
Here is an easy example:

>> a=[1 2;1 4];
[i,j]=find(a==min(min(a)));
[i,j]

ans =

1 1
2 1

elhunter
Posts: 9
Joined: Mon Dec 11, 2006 6:13 pm
Location: IMCS

Re: TPXO to ROMS EXPRESS (tide extraction software)

#11 Post by elhunter »

Hi John,


I was testing out your tidal extraction script today, to see how it compares with the scripts I posted on wikiroms (which are fairly cumbersome).

I came across a minor issue that some others might run into.

>> extractTPXOtides
'Extracting ' 'MM' ' amplitudes'

Error using &
Matrix dimensions must agree.

Error in interpTPXO (line 76)
ff=find (mask==1 & VARinterp==0); %ff: wet points that were not assigned 0

Error in extractTPXOtides (line 97)
zr=interpTPXO('hRe',ROMSnames(k),TPXOfile_elev,TPXOfile_grid,lonR,latR,maskR);




It turns the the problem was the range of longitude values. My grid is -180 to 180 and the TPXO7.2 grid is 0 to 360. The interpolation in interpTPXO does not check for this.


I added a lon=mod(lon,360) in interpTPXO.m.


Thanks,
Eli Hunter
Institute for Marine and Coastal Sciences

elhunter
Posts: 9
Joined: Mon Dec 11, 2006 6:13 pm
Location: IMCS

Re: TPXO to ROMS EXPRESS (tide extraction software)

#12 Post by elhunter »

Hi there,

So I ran into another issue when running the extraction script. It has to do with writing the output tidal forcing file.

>> extractTPXOtides
'Extracting ' 'K1' ' amplitudes'

'Extracting ' 'K1' ' u components'

'Extracting ' 'K1' ' v components'

'Extracting ' 'M2' ' amplitudes'

'Extracting ' 'M2' ' u components'

'Extracting ' 'M2' ' v components'

Error using snc_get_varput_indexing (line 43)
Expected START to be one of these types:

double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64

Instead its type was char.

Error in nc_varput_tmw (line 12)
[start,count,stride] =
snc_get_varput_indexing(ndims,info.Size,size(data),varargin{:});

Error in nc_varput (line 53)
nc_varput_tmw(ncfile,varname,data,varargin{:});

Error in extractTPXOtides (line 213)
nc_varput(ROMS_frc_file,'tide_period',ROMSperiods,'PRESERVE_FVD')


The call to nc_varput has a 'PRESERVE_FVD' input variable, which is not the correct usage in recent SNCTOOLS distributions. This spot is reserved for start,count,stride. PRESERVE_FVD should be set as a preference, i.e. setpref('SNCTOOLS','PRESERVE_FVD',1).

In the extractTPXOtides.m file, there is a comment:

%"PRESERVE_FVD" suppresses the permute that nc_varput_tmw would do.
%start/count/stride has been disabled in nc_varput_tmw.

Is that the case? I think it's generally not good practice to alter a toolbox your software uses.


Eli

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#13 Post by johnluick »

Eli,

thanks for pointing these things out. I haven't updated snctools in a long time and clearly it is time to do that.

I think that the Marchesiello/Penven/Gambon team will be revising make_tides soon, and perhaps now also you will be making your tide software extraction software simpler to use. When one or both of those things happens, I think it would be best for people to use one of them, so I will get the forum moderator to remove my stuff from here.

I do hope you guys take up my suggestion for adding the 2D velocities to the forcing file, so that in future they can replace ellipses (for simplicity).

Cheers

John

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#14 Post by johnluick »

The tide extraction software (TPXO2ROMS.m) I wrote and posted here last year has been updated. It requires at least R2012a but now uses the native Matlab netcdf interface instead of snctools. It also has improved interpolation (offers a choice between TriscatteredInterp.m and scatteredInterpolant.m/griddedInterpolant.m). Most of the improvements are due to Charles James. It is also faster as it makes use of the fact that both of those schemes are now capable of handling complex numbers.
Actually there is nothing wrong with otps2roms.m which is in the "repository" but I think this is simpler - at least, it does not require unix extract_HC executable.

Added 17 October:
Please see below for new version. This version was saving transports, not velocities.
Last edited by johnluick on Thu Oct 17, 2013 2:58 am, edited 1 time in total.

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#15 Post by yang »

I think that there is something wrong. For example, when i use this code to get tide, the Cmax is often larger than 100.[imgh=][/imgh]
Last edited by yang on Fri Nov 08, 2013 12:31 am, edited 2 times in total.

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#16 Post by johnluick »

Please pause Matlab right after the line:
TPXO=readTPXOdata(TPXOfile_elev,TPXOfile_vel,TPXOfile_grid,lonR,latR);
Then enter:

zz=squeeze(TPXO.h.z(:,:,8));
contourf(abs(zz))
colorbar

This will show if the values you are reading in are in correct units etc. What I get are numbers which are typical open ocean M2 amplitudes (0.1 - 0.3). Let me know and I can take it from there.

I should clarify something in my previous email. When I said "there's nothing wrong with otps2roms.m..." what I was trying to say was that in general I think people should use the matlab scripts from the repository (like otps2roms.m) unless they have some specific reason for not doing so. They are more thoroughly tested and keeps everyone on the same page.

One good thing about what Charles did in modifying TPXO2ROMS.m is he substituted in the new way Matlab requires you to interpolate. It is quite a good algorithm and soon TriScatteredInterp will be "deprecated" or whatever they call it.

John

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#17 Post by yang »

OK, the attached map is corresponding to the following code.
TPXO=readTPXOdata(TPXOfile_elev,TPXOfile_vel,TPXOfile_grid,lonR,latR);
zz=squeeze(TPXO.h.z(:,:,8));
contourf(abs(zz))
colorbar
Last edited by yang on Fri Nov 08, 2013 12:30 am, edited 3 times in total.

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#18 Post by johnluick »

Looks good. Before I go further, what version of Matlab are you using? Must be R2012 or later.

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#19 Post by yang »

Matlab-2012b

The tide data i used is from ftp://ftp.oce.orst.edu/dist/tides/Globa ... tcdf.tar.Z
Last edited by yang on Fri Oct 18, 2013 6:02 am, edited 1 time in total.

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#20 Post by johnluick »

Please send your next response to john.luick@austides.com, so we can go offline and thereby not annoy everyone with a troubleshooting exercise. Also, in your email, can you confirm that you are not plotting phase (rather than amplitude) in that first plot you sent?

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#21 Post by johnluick »

This version (3.1) should be used. The one I put up a couple of weeks ago saved transports instead of velocities (my apologies). I also made a number of lesser changes which noted are at the start of the function.

23 October note - the new Matlab/netcdf interface commands ncread, nccreate and ncwrite reverse the array order automatically. You need to be really careful. I have replaced the TPXO2ROMS and have uploaded a new TPXO2ROMS.zip which I believe to be CF-compliant, and ROMS did not complain.

As an example, you read in an array which ncdump said was A(eta_rho,xi_rho). Your array in Matlab will look like A(xi_rho,eta_rho). Then for the netcdf output file you define vardims={'xi_rho',L,'eta_rho',M}, which nccreate reverses in the netcdf output file, so that after you write with ncwrite, which reverses the array on output, you finally ncdump the result, and see B(eta_rho,xi_rho)!

Personally, I plan to go back to snctools, to preserve my sanity, but will leave TPXO2ROMS this way so that people won't need snctools to use TPXO2ROMS. The above was tested on R2012a on a Windows PC. I can't test on linux because ours only has R2010.
Attachments
TPXO2ROMS.zip
(8.01 KiB) Downloaded 307 times

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#22 Post by johnluick »

A week or two ago I posted an update of TPXO2ROMS and some comments about the new Matlab netcdf interface commands ncread, ncwrite, etc.
Since I did so by editing a previous post, there was no notification sent out (as far as I know).
TPXO2ROMS users are advised to download this update.
I would be interested if anyone else has had similar experience with ncread etc.

yang
Posts: 56
Joined: Mon Sep 25, 2006 2:37 pm
Location: Institue of oceanology ,Chinese acedemy of scinece

Re: TPXO to ROMS EXPRESS (tide extraction software)

#23 Post by yang »

Good work. very nice!
It works well, now.

geo_ytwin
Posts: 6
Joined: Tue Apr 13, 2010 4:16 pm
Location: South China Sea Institute of Oceanology, CAS

Re: TPXO to ROMS EXPRESS (tide extraction software)

#24 Post by geo_ytwin »

Hi,
Is there any way to consider specific tidal u and v components for rotating rectangular grid?

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

Re: TPXO to ROMS EXPRESS (tide extraction software)

#25 Post by kate »

Huh? ROMS will want the tidal velocities to be rotated to its grid, according to the "angle" variable.

geo_ytwin
Posts: 6
Joined: Tue Apr 13, 2010 4:16 pm
Location: South China Sea Institute of Oceanology, CAS

Re: TPXO to ROMS EXPRESS (tide extraction software)

#26 Post by geo_ytwin »

Yes, Kate.
So how can I rotate the tidal u and v (for example from TPXO data) to get tidal velocities that are perpendicular to the roms grid? The roms needs tidal current ellipses as the input information for tidal currents. I am confused how to rotate the tidal current ellipses.

User avatar
jivica
Posts: 150
Joined: Mon May 05, 2003 2:41 pm
Location: The University of Western Australia, Perth, Australia

Re: TPXO to ROMS EXPRESS (tide extraction software)

#27 Post by jivica »

I think tidal ellipses, to be more precise inclination, is not rotated to the ROMS grid within forcing file. It is rotated during applying BC see angler(i,j) in the last line of code, in Nonlinear/set_tides.F:

Code: Select all

# if defined UV_TIDES
!
!-----------------------------------------------------------------------
!  Add tidal currents (m/s) to 2D momentum climatologies.
!-----------------------------------------------------------------------
!
      Utide(:,:)=0.0_r8
      Vtide(:,:)=0.0_r8
      cff=2.0_r8*pi*(time(ng)-tide_start*day2sec)
      DO itide=1,NTC
        IF (Tperiod(itide).gt.0.0_r8) THEN
          omega=cff/Tperiod(itide)
          DO j=MIN(JstrR,Jstr-1),JendR
            DO i=MIN(IstrR,Istr-1),IendR
              angle=UV_Tangle(i,j,itide)-angler(i,j)
What it important to know is that tidal information (in terms of adding effect to the bry) is needed only along the active boundary cells, NOT AT THE WHOLE grid(!!). But ROMS is reading in a standard way forcing file and needs that info, but you can make trick and fill whole domain with zeros (if you do not know tides or do not want to extract them, ie big grid) and than only replace those along boundaries (+ 1 cell inside if needed for gradients)..... At the same time you can see how to optimize the code not to compute expensive trigonometrical functions etc along ALL POINTS, instead along only BRY stripes....

Cheers,
Ivica

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

Re: TPXO to ROMS EXPRESS (tide extraction software)

#28 Post by kate »

Thanks, Ivica. It's been years since I looked at this. Find a tool once and forget about it.

As for the other question, there are fields for which one might need to rotate to the ROMS grid. The rotation angle is called "angle" in the grid file and it is a matter of applying simple trigonometry. I guess I would assume readers here would have that knowledge already, but there's an example in uv_rotate.F in the ROMS source. Plus of course the code Ivica has pointed out.

geo_ytwin
Posts: 6
Joined: Tue Apr 13, 2010 4:16 pm
Location: South China Sea Institute of Oceanology, CAS

Re: TPXO to ROMS EXPRESS (tide extraction software)

#29 Post by geo_ytwin »

Thanks, Ivica and Kate.
Your replay make me clear for preparing tidal forcing file.

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#30 Post by johnluick »

TPXO2ROMS_v4pt0.zip
(8.79 KiB) Downloaded 369 times
This new version of TPXO2ROMS (TPXO2ROMSv4pt0) reads from the new TPXO 8 atlas. The most important harmonics in TPXO8 are at 1/30 degree resolution (as opposed to 1/4 degree for version 7.2 and earlier). There are other improvements in TPXO 8 as well (see http://volkov.oce.orst.edu/tides/tpxo8_atlas.html). You need to download the netcdf files (there are now two per harmonic plus the new grid). Four of the harmonics (MM, MF, MS4, MN4) are at 1/6 degree. I am not sure my interpolation scheme is working properly for them - you can try it for your area and let us all know - it is also possible there are some flaws on the database. I will update the software once this is established.

thomas.roc
Posts: 34
Joined: Tue Oct 28, 2008 3:19 pm
Location: IT Power

Re: TPXO to ROMS EXPRESS (tide extraction software)

#31 Post by thomas.roc »

Dear all,

I realize this thread is rather old but I noticed this odd line in TPXO2ROMS_v4pt1.m:
line 253: ncwrite(fnOut,'tide_Vphase',vamp)

Should not it be "ncwrite(fnOut,'tide_Vphase',vpha)" rather?

BTW, if some could direct me to a python package permitting similar functionality (i.e. creating tidal forcing file from TPXO dataset) it would be greatly appreciated.

Best,

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#32 Post by johnluick »

You are quite right of course. Thanks for pointing this out.
I do not know of any python script for this.
John

d.kobashi
Posts: 65
Joined: Tue Sep 28, 2010 11:59 pm
Location: Texas A&M University

Re: TPXO to ROMS EXPRESS (tide extraction software)

#33 Post by d.kobashi »

I don't think a python tool equivalent to the John's one exists. I searched for it before because I switched to Python.

There are few python tools on tidal analysis as far as I know. I found the following.
http://sourceforge.net/projects/tappy/

You can possibly write python scripts to create ROMS tidal forcing based on the tool.
I don't have enough energy to do that and the John's tool works fine by me (Thanks, John!).

Or there could be tools to convert Matlab codes to Python? something like f2py (fortran to python) I wonder.

Cheers,

DJ Kobashi

thomas.roc
Posts: 34
Joined: Tue Oct 28, 2008 3:19 pm
Location: IT Power

Re: TPXO to ROMS EXPRESS (tide extraction software)

#34 Post by thomas.roc »

Thank you all,

Here is an early christmas present, a python translation of John's tpxo8_to_roms package.
I've started testing it...so far, so good.

Enjoy

-T-
Attachments
tpxo8_to_roms_python.zip
(8.31 KiB) Downloaded 263 times

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#35 Post by johnluick »

I look forward to trying this myself!
Thanks Thomas.
John

fagundesmo
Posts: 46
Joined: Wed Dec 03, 2014 1:46 am
Location: University of Georgia

Re: TPXO to ROMS EXPRESS (tide extraction software)

#36 Post by fagundesmo »

Dear all,

I am trying TPX02ROMS version 3.2 to generate tides input to my area. However, I have had some issues while using it. These are the errors I am getting:


'Extracting ' 'M2' ' amplitudes'

'Extracting ' 'M2' ' u components'

Error using scatteredInterpolant
The input points must be a double array.

Error in TPXO2ROMS>interpTPXO (line 351)
F=scatteredInterpolant(x(m),y(m),z(m),'nearest');

Error in TPXO2ROMS (line 105)
ei=interpTPXO(TPXO.U,ROMSnames{k},lonR,latR,maskR);

Error in TPXO2ROMS_script (line 20)
TPXO2ROMS(t0,fnIn,fnOut,ndays)
[/b]


Since, I have used MATLAB for a couple weeks I do not know how I should proceed to fix these errors. I would appreciate if someone helped me.

Cheers,

fagundesmo
Posts: 46
Joined: Wed Dec 03, 2014 1:46 am
Location: University of Georgia

Re: TPXO to ROMS EXPRESS (tide extraction software)

#37 Post by fagundesmo »

I think I did it. Could all confirm whether I changed right or not? I added the following lines:

xx=double(x(:,:));
yy=double(y(:,:));
zz=double(z(:,:));
F=scatteredInterpolant(xx(m),yy(m),zz(m),'nearest');
z=F(xx,yy);
F=griddedInterpolant(xx',yy',zz');

User avatar
CharlesJames
Posts: 36
Joined: Thu May 24, 2007 12:12 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#38 Post by CharlesJames »

There may be a couple of issues here, the first is that scatteredInterpolant only takes datatype double (real or complex) so your solution will avoid that error.

But there may still be a problem with your u_tpxo72.nc file - the version of that file that I have has the variables URe and UIm (the variables you are reading at this step) both with datatype "double" so they shouldn't be triggering this problem. I don't know if there are different versions of this file or perhaps someone is saving space by converting the variables to single precision? The latest version of TPXO2ROMS (4.1) uses the TPXO8 netCDF files which might work better for you. In any case if the program runs OK with your fix I'd still have a close look at the resulting forcing file just to make sure it looks the way you expect.

fagundesmo
Posts: 46
Joined: Wed Dec 03, 2014 1:46 am
Location: University of Georgia

Re: TPXO to ROMS EXPRESS (tide extraction software)

#39 Post by fagundesmo »

CharlesJames wrote:There may be a couple of issues here, the first is that scatteredInterpolant only takes datatype double (real or complex) so your solution will avoid that error.

But there may still be a problem with your u_tpxo72.nc file - the version of that file that I have has the variables URe and UIm (the variables you are reading at this step) both with datatype "double" so they shouldn't be triggering this problem. I don't know if there are different versions of this file or perhaps someone is saving space by converting the variables to single precision? The latest version of TPXO2ROMS (4.1) uses the TPXO8 netCDF files which might work better for you. In any case if the program runs OK with your fix I'd still have a close look at the resulting forcing file just to make sure it looks the way you expect.

Hmm..., I downloaded tpxo72.nc from this website http://volkov.oce.orst.edu/tides/tpxo8_atlas.html that I took as reference from "tidal forcing topic" at wiki ROMS. About my output when I added those lines worked properly. However, some variables were not right maybe that's why I didn't understand what was wrong. I will try TPXO2ROMS (4.1) out instead.
Let's say I wanted to run TPXO2ROMS_v4pt0.m to my experiment that had a length of 30 years and my reference time I set to start at 1900-01-01. How should I set my t0 and lengthSim in this case?

Thanks in advance

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#40 Post by johnluick »

I'm overseas at the moment but I will answer as best I can from memory.

TPXO2ROMS 4.x is designed to run with TPXO 8.1 not TPXO 7.x.. You should download 8.1.
I believe you cannot accurately simulate tides for more than one year with ROMS because it doesn't allow the nodal factors (f and u) to vary over time. Someone correct me if I'm wrong there. The worst offender, O1, will be out by probably 5 to 8 degrees at times, and O1 amplitude out by up to 15 to 20%.

You can do one-year segments and use perfect restarts with new values of t0 and TIDE_START (set them to the same mid-year time). You would also have to change the start time (variable name DATE_START? I forget. It is the one right before TIDE_START in ocean.in).

Or you can forget about using perfect restarts... let's say your tides spin up in 5 days. You can do 370 day simulations starting 5 days before the start of each year then ignore the first five days of simulation. This is what I would do.

But the point is, as far as I know ROMS doesn't allow the harmonics to change in time (over lunar nodal cycle) so you have to use some finagle if you want to really accurately model tides even over one month let alone one year. It would be easy enough to modify the code in ROMS. It should input constants (exactly as from TPXO or other model), not phases at some specific time (as it currently does), and then compute f and u as a function of time, compute the "equation of time", etc... And it definitely should not use the ellipse velocities (which is also does), which are a total waste of computing time and more importantly add unnecessary confusion.

John

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#41 Post by johnluick »

I have updated the TPXO2ROMS Matlab software for creating a ROMS tidal input file from the TPXO tide database. It is now called TPXO2ROMS_v5pt1. Version 5.1 downloads the latest global tidal inversion (TPXO9) from Oregon State University. You will need permission from the authors (Lana Erofeeva and Gary Egbert) to download the TPXO9 netcdf files.

TPXO2ROMS v5.1 had a lot of changes due to the fact that TPXO9 includes harmonic 2N2. Matlab variables cannot begin with a number (like, 2) and I had previously referred to the different harmonics as struct variables by name, e.g. harmonic.M2, harmonic.K1, etc. Also, the TPXO9 data is organised differently from previous versions (much improved).

This new code worked correctly in extensive checking and testing, but I haven't actually run a ROMS model using the result. If anyone has a problem please let me know asap.

TPXO2ROMS v 5.1 can be freely downloaded from https://austides.com/downloads/

With great thanks to Lana and Gary for their fantastic product and continued updates.

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#42 Post by neelbasak08 »

Dear John luck and all ROMS forum colleagues,

I am extremely grateful to you for providing us with your TPXO v 5.1 zip file that includes scripts named : TPXO2ROMS_v5pt1.m and TPXO2ROMS_v5pt1_script.m . I am new to ROMS and just finished the upwelling test case and Fjord case a couple of days back. I received the OSU TPXO9-atlas-v4 netcdf file from Dr. Lana Erofeeva and Dr. Gary Egbert.

Issue I am facing it is that I have my grid file of the model i want to learn, the tpxo9-atlas-v4 netcdf files and both the matlab scripts TPXO2ROMS_v5pt1.m and TPXO2ROMS_v5pt1_script.m in one single directory added to my MATLAB path. But I am unable to understand which script I should run, in what way I should run (in the sense what command should i give in the command window or I should run the script ) and in what order should I run the command.

Also sir another issue I am facing is in the TPXO2ROMS_v5pt1.m :
function TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,ndays)

% t0: start time
% ROMSnames: ROMS components to calculate
% typical components: Q1 O1 P1 K1 N2 M2 S2 K2
% fnGrid: ROMS grid to calculate tidal components on
% fnOut: name of ROMS tide file
% ndays: Approximate length of run in days (default 365)

%Prepares a tidal forcing file for ROMS from TPXO tidal model (OSU) version 9.
%This version requires Matlab R2012a or later because it takes advantage of
%TriScatteredInterp being able to use complex values from R2012a on.
%If run on R2013 on it will use scatteredInterpolant/griddedInterpolant
%instead of TriScatteredInterp which will be discontinued at some point.

%Uses data from: http://volkov.oce.orst.edu/tides/tpxo8_atlas.html
%Download the netcdf files and put them in a folder on your Matlab path.

%Version v5.1
%Many changes needed for reading TPXO9.
%Reads all 15 harmonics from TPXO9 database, only uses those requested in calling script.
%No longer uses struct variables because 2N2 was not an allowed variable name.
Should I run the script .m file or in the command window I can type the command = TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,ndays) specifying each parameter in the bracket itself like ndays and fngrid?

In TPXO2ROMS_v5pt1_script.m:
% A wrapper for function TPXO2ROMS_v5pt1

%addpath(genpath('/storage0/group/Oceanography/JOHNL/myroms/PrepTides'))

%t0 can be any time of day not necessarily 00:00
%lengthSim is the approximate anticipated length of model run (days) (f & u are computed at mid-point).
%fnGrid is your ROMS grid file.
%TPXO2ROMS will write to fnOut.
%The available choices for ROMSnames are: 'MM' 'MF' 'Q1' 'O1' 'P1' 'K1' 'N2' 'M2' 'S2' 'K2' 'MN4' 'M4' 'MS4' '2N2' 'S1'
%For example, use ROMSnames={'M2' 'S2' 'MM'}; to use M2, S2, and MM only
clear

%****************Modify to suit***************
TIDE_START=17967; %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(1968,5,23); %TIDE_START in Matlab datenum
lengthSim=170; %approximate length of model run in days
fnGrid='C:\mystuff\MODELS\myroms\Projects\AGM1\DATA\grd_etopo1_AGM1.nc';
fnOut=['C:\mystuff\MODELS\myroms\Projects\AGM1\DATA\frc_TPXO_AGM1_' datestr(t0,'ddmmmyyyy') '.nc'];
ROMSnames={'MM' 'MF' 'Q1' 'O1' 'P1' 'K1' 'N2' 'M2' 'S2' 'K2' 'MN4' 'M4' 'MS4' '2N2' 'S1'};
%********************************************
I am unable to understand whether I need to run this script or I can just run the TPXO2ROMS_v5pt1.m script and do I need to mention the path to my directory as is shown the script TPXO2ROMS_v5pt1_script.m

Code: Select all

 
 fnGrid='C:\mystuff\MODELS\myroms\Projects\AGM1\DATA\grd_etopo1_AGM1.nc';
fnOut=['C:\mystuff\MODELS\myroms\Projects\AGM1\DATA\frc_TPXO_AGM1_' datestr(t0,'ddmmmyyyy') '.nc'];
ROMSnames={'MM' 'MF' 'Q1' 'O1' 'P1' 'K1' 'N2' 'M2' 'S2' 'K2' 'MN4' 'M4' 'MS4' '2N2' 'S1'};
 
I am a newbie to ROMS and MATLAB and any help from anyone in any manner is extremely appreciated by me.

Looking for a positive reply.

-Neel

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#43 Post by c.drinkorn »

Hi Neel,

the script is the Matlab program you should run from the command line or a bash script. There you can change the paths to your ROMS grid file, the output file name and location and the desired constituents as well as information about the time settings for your tides. This script then hands over your input to the function and initiates the processing.
However, if your TPXO files are not in the Matlab folder, you may want to change the path in the function file (TPXO_path). You can also change the names of the files. But I think the function is customized already for the TPXO file names. Just take care about the TPXO version. You are using TPXO-9 atlas. You may have to change the file names accordingly and the atlas data might even have a different file structure. If you are not too familiar with Matlab scripting you should try and find the matching dataset for the Matlab script or vice versa. E.g., I am using TPXO2ROMS version 4.0 with a TPXO8 atlas dataset.
I hope this could help you!

Cate

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#44 Post by neelbasak08 »

Thanks a lot for your help Cate.

I have another issue. While i am running the script TPXO2ROMS_v5pt1_script.m file, I am getting the following error in the command window of MATLAB:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Error using internal.matlab.imagesci.nc/openToRead (line 1272)
Could not open grid_tpxo9.nc for reading.

Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();

Error in ncread (line 61)
ncObj = internal.matlab.imagesci.nc(ncFile);

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 412)
X=ncread(TPXOfile.grid,'lon_z');

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 26)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
Let me run you through what I am doing. I gained access to TPXO9-atlas-v4 netcdf version by Dr. Erofeova . I downloaded the h_q1_tpxo9_atlas_30_v4.nc and u_q1_tpxo9_atlas_30_v4.nc , kept them in a single directory along with mexcdf files, matlab_dir, snctools,netcdf_toolbox, my grid file on which I want tidal forcing and both the TPXO2ROMS_v5pt1_script.m and TPXO2ROMS_v5pt1.m and added them to my matlab path.

Here is the part I changed in the script(from the default one) as per my location:

1. TPXO2ROMS_v5pt1_script.m

Code: Select all

 TIDE_START=17967;  %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(2019,5,23);  %TIDE_START in Matlab datenum
lengthSim=170;  %approximate length of model run in days
fnGrid='C:\Users\aBc\Documents\MATLAB\TPXO\ROMS_grid_alderneyrace_new.nc';
fnOut=['C:\Users\aBc\Documents\MATLAB\TPXO\frc_TPXO_AGM1_' datestr(t0,'ddmmmyyyy') '.nc'];
ROMSnames={'Q1'};  
2. TPXO2ROMS_v5pt1.m
No change made in this script

My location for files are as follows-
  • matlab_dir: C:\Users\aBc\Documents\MATLAB\TPXO
    mexcdf: C:\Users\aBc\Documents\MATLAB\TPXO\
    netcdf_toolbox: C:\Users\aBc\Documents\MATLAB\TPXO\
    h_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO\
    u_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO\
    grid file on which i want forcing: C:\Users\aBc\Documents\MATLAB\TPXO\
    TPXO2ROMS_v5pt1_script.m: C:\Users\aBc\Documents\MATLAB\TPXO
    TPXO2ROMS_v5pt1.m: C:\Users\aBc\Documents\MATLAB\TPXO

I realised that I didn't download the grid_tpxo9_atlas_v4.nc file from the TPXO9-atlas-v4 package sent to me. Please let me know if anyone notices any other error. I will download grid_tpxo9_atlas_v4.nc but do I need to download other files as well such as h_s2_tpxo9_atlas_30_v4.nc and corresponding u_s2_tpxo9_atlas_30_v4.nc and all other files (I already have h_q1_tpxo9_atlas_30_v4.nc and u_q1_tpxo9_atlas_30_v4.nc in my directory) ? I want to just compute 'Q1' .All those remaining files are pretty large and I don't want to waste my memory of computer by downloading things I won't compute.

Any help by anyone is highly appreciated.

Thanks in advance.

-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#45 Post by johnluick »

Hi Neel,

I just saw this post, and unfortunately may not have time to spend on it for another 24 hours. Will do my best. For now, can only say your script looks fine (one single harmonic should be fine), but the error message is odd - it implies it can find grid_tpxo9.nc, but can't open it! But tearing hair out by the roots over read permissions is more of a linux divertissement than a Windows one, so I'm guessing it is a path issue. Have you done some addpaths in Matlab? I'm also noticing you have a trailing "\" in some but not all of your TPXO paths. I'll get back to this in a day or so, but meanwhile, please let me know if you have sorted it out (and what resolved it).

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#46 Post by neelbasak08 »

Hello john,

Thank you for the reply. Unfortunately I have added all my path to the files in MATLAB as per requirement.

When I ran the script TPXO2ROMS_v5pt1_script.m, i encountered the following error in my command window of MATLAB:
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\4dvar
> In path (line 109)
In startup (line 27)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\bathymetry
> In path (line 109)
In startup (line 28)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\boundary
> In path (line 109)
In startup (line 29)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\coastlines
> In path (line 109)
In startup (line 30)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\colormaps
> In path (line 109)
In startup (line 31)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\forcing
> In path (line 109)
In startup (line 32)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\grid
> In path (line 109)
In startup (line 33)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\grid_gui
> In path (line 109)
In startup (line 34)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\initial
> In path (line 109)
In startup (line 35)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\landmask
> In path (line 109)
In startup (line 36)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\mex
> In path (line 109)
In startup (line 37)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\netcdf
> In path (line 109)
In startup (line 38)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\seagrid
> In path (line 109)
In startup (line 39)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\seagrid\presto
> In path (line 109)
In startup (line 40)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\seawater
> In path (line 109)
In startup (line 41)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\t_tide
> In path (line 109)
In startup (line 42)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\tidal_ellipse
> In path (line 109)
In startup (line 43)
Warning: Name is nonexistent or not a directory: C:\ocean\repository\matlab\utility
> In path (line 109)
In startup (line 44)
>> TPXO2ROMS_v5pt1
Not enough input arguments.

Error in TPXO2ROMS_v5pt1 (line 61)
ROMStitle=['ROMS TPXO data for ' datestr(t0,0)];

>> clear all
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Index exceeds the number of array elements (0).

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 421)
TPXO.h.depth=ncread(TPXOfile.grid,'hz',[h.I(1) h.J(1)],[length(h.I) length(h.J)]); %bathymetry at z nodes

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 26)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
I don't know what went wrong in line 421 of TPXO2ROMS_v5pt1_script.m . Is it a problem with my grid file which I created using Austides GridBuilder .exe version 0.99.5 August 2016 ? I am not able to figure that out as the grid looked pretty good to me while making it. I shall attach that grid file for your reference.

As far as what you mentioned about a trailing '\' after TPXO was a total error in typing in ROMS forum from my side and I sincerely apologise for that. All files are contained inside the TPXO folder itself with location C:\Users\aBc\Documents\MATLAB\TPXO . This same location has been added to my MATLAB path accordingly with care.
  • My location for files are as follows-
    matlab_dir: C:\Users\aBc\Documents\MATLAB\TPXO
    mexcdf: C:\Users\aBc\Documents\MATLAB\TPXO
    netcdf_toolbox: C:\Users\aBc\Documents\MATLAB\TPXO
    h_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
    u_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
    grid file on which i want forcing: C:\Users\aBc\Documents\MATLAB\TPXO
    TPXO2ROMS_v5pt1_script.m: C:\Users\aBc\Documents\MATLAB\TPXO
    TPXO2ROMS_v5pt1.m: C:\Users\aBc\Documents\MATLAB\TPXO
As far as changes in the MATLAB script is concerned, the changes I made were:
TPXO2ROMS_v5pt1_script.m :

Code: Select all

 TIDE_START=17967;  %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(2019,5,23);  %TIDE_START in Matlab datenum
lengthSim=30;  %approximate length of model run in days
fnGrid='C:\Users\aBc\Documents\MATLAB\TPXO\ROMS_grid_alderneyrace_new.nc';
fnOut=['C:\Users\aBc\Documents\MATLAB\TPXO\frc_TPXO_AGM1_' datestr(t0,'ddmmmyyyy') '.nc'];
ROMSnames={'Q1'};  
In TPXO2ROMS_v5pt1.m , i changed the file names as per the name of the TPXO file I downloaded from TPXO9_atlas_nc packing sent to me by Dr. Erofeeva which were h_q1_tpxo9_atlas_30_v4.nc and u_q1_tpxo9_atlas_30_v4.nc and grid_tpxo9_atlas_v4.nc :

Code: Select all

 %TPXO filenames (files must be on Matlab path)
TPXOfile.grid='grid_tpxo9_atlas_v4.nc';
TPXOfile.elev='h_q1_tpxo9_atlas_30_v4.nc';
TPXOfile.vel='u_q1_tpxo9_atlas_30_v4.nc';
  
These are the new errors that I encountered today as a result of downloading grid_tpxo9_atlas_v4.nc file which I previously didn't have yesterday.

Any help in any kind is appreciated. I know I am bugging you guys unnecessarily but I am not able to navigate these problems as I am very new to Linux WSL in Windows, ROMS and MATLAB.

Thanks in advance for sparing a portion of your valuable time to help me out.

-Neel
Attachments
ROMS_grid_alderneyrace_new.nc
This is the grid file on which I will do tidal forcing.
(6.85 MiB) Downloaded 7 times
TPXO2ROMS_v5pt1.m
(22.76 KiB) Downloaded 7 times
TPXO2ROMS_v5pt1_script.m
(1.29 KiB) Downloaded 8 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#47 Post by c.drinkorn »

Hi Neel,

I really want to help you so I took another look at your function file. I know that John Luick is the absolute expert here but maybe this could help:

Before the critical line (line 421 is the line where the depth is read from the TPXO grid file) the variables X and Y are determined on the basis of lon_z and lat_z. These are one-dimensional variables in the TPXO files. I think the line 415 doesn't work like that so the indices for the reading are odd. Try this instead of lines 412 and 413 maybe:

Code: Select all

Xi=ncread(TPXOfile.grid,'lon_z');
Yi=ncread(TPXOfile.grid,'lat_z');
[X,Y]=meshgrid(Xi,Yi);
But, as I said, I am no expert with this, so this may just be a sloppy workaround. ;)

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#48 Post by neelbasak08 »

Hey Cate

Thanka a lot for your help. But I'm sorry to inform you that now I am getting a diffrent error by making the changes in TPXO2ROMS_v5pt1.m you suggested:
Before the critical line (line 421 is the line where the depth is read from the TPXO grid file) the variables X and Y are determined on the basis of lon_z and lat_z. These are one-dimensional variables in the TPXO files. I think the line 415 doesn't work like that so the indices for the reading are odd. Try this instead of lines 412 and 413 maybe:
CODE: SELECT ALL

Xi=ncread(TPXOfile.grid,'lon_z');
Yi=ncread(TPXOfile.grid,'lat_z');
[X,Y]=meshgrid(Xi,Yi);
But, as I said, I am no expert with this, so this may just be a sloppy workaround. ;)
The error message I received is as follows while running TPXO2ROMS_v5pt1_script.m is :
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Index exceeds the number of array elements (0).

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 432)
TPXO.U.depth=ncread(TPXOfile.grid,'hu',[u.I(1) u.J(1)],[length(u.I) length(u.J)]); %bathymetry at z nodes

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 26)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)
My critical line 432 in TPXO2ROMS_v5pt1.m looks like this :

Code: Select all

 TPXO.U.depth=ncread(TPXOfile.grid,'hu',[u.I(1) u.J(1)],[length(u.I) length(u.J)]); %bathymetry at z nodes
  
I am attaching my script files and grid file for your reference. MY TPXO9_atlas_30_v4 files are all same as in previous posts .nc files by me.
  • My location for files are as follows-
    matlab_dir: C:\Users\aBc\Documents\MATLAB\TPXO
    mexcdf: C:\Users\aBc\Documents\MATLAB\TPXO
    netcdf_toolbox: C:\Users\aBc\Documents\MATLAB\TPXO
    h_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
    u_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
    grid file on which i want forcing: C:\Users\aBc\Documents\MATLAB\TPXO
    TPXO2ROMS_v5pt1_script.m: C:\Users\aBc\Documents\MATLAB\TPXO
    TPXO2ROMS_v5pt1.m: C:\Users\aBc\Documents\MATLAB\TPXO
I am highly obliged to you for your time. Any help from anyone is highly appreciated.

Thanks a lot in advance.
-Neel
Attachments
ROMS_grid_alderneyrace_new.nc
This is the file on which I want to do tidal forcing.
(6.85 MiB) Downloaded 5 times
TPXO2ROMS_v5pt1.m
(22.79 KiB) Downloaded 6 times
TPXO2ROMS_v5pt1_script.m
(1.29 KiB) Downloaded 6 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#49 Post by c.drinkorn »

Hi Neel,

yes, it's basically the same problem as above, just now for the u-coordinate latitudes and longitudes and will be the same for the v-coordinate lat/lon, too. So I suggest you add the meshgrid lines there, too:

Code: Select all

Xi=ncread(TPXOfile.grid,'lon_u');
Yi=ncread(TPXOfile.grid,'lat_u');
[X,Y]=meshgrid((Xi,Yi);
instead of lines 423 and 424

as well as

Code: Select all

Xi=ncread(TPXOfile.grid,'lon_v');
Yi=ncread(TPXOfile.grid,'lat_v');
[X,Y]=meshgrid((Xi,Yi);
instead of 433 and 434.

Let me know if this solved your problem. :)

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#50 Post by johnluick »

Hi Neel,

I hope Cate's solution worked for you. I downloaded your grid, and it also caused an error for me. I don't have time tonight to work out what's the problem with the grid. Maybe it will help you to get the software running with a grid that doesn't create an error, so I will attach a working one.

Cheers

John
ps here are the lines from my TPXO v5pt2 script file.
%****************Vizhinjam***************
RUNTPXO=1; %set to 0 to skip computation - handy for playing with the plot only
TIDE_START=18485; %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(1968,5,23); %TIDE_START in Matlab datenum
lengthSim=60; %approximate length of model run in days
fnGrid='C:\_mystuff\MODELS\myroms\Projects\Vizhinjam\DATA\grd_Vizhinjam.nc';
fnOut=['C:\_mystuff\MODELS\myroms\Projects\Vizhinjam\DATA\frc_TPXO9_Vizhinjam_' datestr(t0,'ddmmmyyyy') '_v4.nc'];
ROMSnames={'M2' 'S2' 'N2' 'K2' 'K1' 'O1' 'P1' 'Q1'};
%Hplot, skip, sfac, and smaj are parameters for the ellipse map
Hplot='M2'; %Which harmonic to plot (name one, e.g. 'M2', 'K1', etc.)
skip=10; %plot each skipth'th ellipse
sfac=0.1; %sf=scalefactor (the ellipse sizes are arbitrary)
smaj=1; %Semi-major axis of scale factor ellipse
%********************************************
grd_Vizhinjam.nc
(7.67 MiB) Downloaded 11 times

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#51 Post by neelbasak08 »

Thanks a lot Cate and John for your help.

Maybe there is an issue with my grid file, I will check that.

I made the changes suggested by Cate for my grid but sadly it didn't work out (I shall post the error at the end):
Hi Neel,

yes, it's basically the same problem as above, just now for the u-coordinate latitudes and longitudes and will be the same for the v-coordinate lat/lon, too. So I suggest you add the meshgrid lines there, too:
CODE: SELECT ALL

Xi=ncread(TPXOfile.grid,'lon_u');
Yi=ncread(TPXOfile.grid,'lat_u');
[X,Y]=meshgrid((Xi,Yi);
instead of lines 423 and 424

as well as
CODE: SELECT ALL

Xi=ncread(TPXOfile.grid,'lon_v');
Yi=ncread(TPXOfile.grid,'lat_v');
[X,Y]=meshgrid((Xi,Yi);
instead of 433 and 434.

Let me know if this solved your problem. :)
I also downloaded Mr. John's grid file grd_Vizhinjam.nc that he suggested and applied it to the updated script by Cate's help:
Hi Neel,

I hope Cate's solution worked for you. I downloaded your grid, and it also caused an error for me. I don't have time tonight to work out what's the problem with the grid. Maybe it will help you to get the software running with a grid that doesn't create an error, so I will attach a working one.

Cheers

John
ps here are the lines from my TPXO v5pt2 script file.
%****************Vizhinjam***************
RUNTPXO=1; %set to 0 to skip computation - handy for playing with the plot only
TIDE_START=18485; %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(1968,5,23); %TIDE_START in Matlab datenum
lengthSim=60; %approximate length of model run in days
fnGrid='C:\_mystuff\MODELS\myroms\Projects\Vizhinjam\DATA\grd_Vizhinjam.nc';
fnOut=['C:\_mystuff\MODELS\myroms\Projects\Vizhinjam\DATA\frc_TPXO9_Vizhinjam_' datestr(t0,'ddmmmyyyy') '_v4.nc'];
ROMSnames={'M2' 'S2' 'N2' 'K2' 'K1' 'O1' 'P1' 'Q1'};
%Hplot, skip, sfac, and smaj are parameters for the ellipse map
Hplot='M2'; %Which harmonic to plot (name one, e.g. 'M2', 'K1', etc.)
skip=10; %plot each skipth'th ellipse
sfac=0.1; %sf=scalefactor (the ellipse sizes are arbitrary)
smaj=1; %Semi-major axis of scale factor ellipse
%********************************************
grd_Vizhinjam.nc
In both the cases I ran into the same error as follows, both in my grid file and also Mr. John's grid file:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Error using internal.matlab.imagesci.nc/read (line 613)
START has incorrect number of elements (3). The variable has 2 dimensions.

Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 453)
Z=complex(ncread(TPXOfile.elev,'hRe',[h.I(1) h.J(1) nH],[length(h.I) length(h.J) 1]),...

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 32)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)
I don't know why START is taking 3 elements and how to remove that error. I am not even sure if it's an issue with my alderney_rice grid file or just the tPXO9_atlas_30_v4 files of which I only downloaded h_q1_tpxo9_atlas_30_v4.nc,u_q1_tpxo9_atlas_30_v4.nc and grid_tpxo9_atlas_v4.nc or just the script in general. All my file names and locations are same as previous posts.

Any help from anyone is extremely appreciated.

I am attaching my grid file in .mat format and .nc format both which I generated through GridBuilder tool as generously posted on Austides website

thanks a lot in advance.

-Neel
Attachments
TPXO2ROMS_v5pt1_script.m
(1.61 KiB) Downloaded 7 times
TPXO2ROMS_v5pt1.m
(22.84 KiB) Downloaded 6 times
Alderney_race_grid_mat_format.zip
My alderney rice grid file generated by GridBuilder by me saved in .mat format
(1.87 MiB) Downloaded 7 times
ROMS_grid_alderneyrace_new.nc
My alderney rice grid file generated by GridBuilder by me
(6.85 MiB) Downloaded 6 times
grd_Vizhinjam.nc
Grid file sent to me by Mr. John for testing
(7.67 MiB) Downloaded 7 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#52 Post by c.drinkorn »

Hi Neel,

I think I know what the issue is. The dimension ncread complains about is nH which is the number of constituents. You are only using one of them, Q1 as I can see. In your file the variables such as h have only two dimensions. I think in TPXO files with more than one constituent they have another dimension which is equivalent to nH. I ran into the same issue when I just wanted to simulate M2. What I did was to insert an if-condition for nH being one and then removing nH as a dimension in the reading lines. However, this would be a larger overhaul of the code and one could easily get confused and mess up the beautiful work of John Luick. :D
I suggest that you either wait for John Luick's solution or save the function file as a backup before you try and make the following changes:

Code: Select all

   if length(ROMSnames) == 1
   Z=complex(ncread(TPXOfile.elev,'hRe',[h.I(1) h.J(1)],[length(h.I) length(h.J)]),...
      ncread(TPXOfile.elev,'hIm',[h.I(1) h.J(1)],[length(h.I) length(h.J)]));
   TPXO.h.z(:,:)=double(Z);
else
   Z=complex(ncread(TPXOfile.elev,'hRe',[h.I(1) h.J(1) nH],[length(h.I) length(h.J) 1]),...
      ncread(TPXOfile.elev,'hIm',[h.I(1) h.J(1) nH],[length(h.I) length(h.J) 1]));
   TPXO.h.z(:,:,nH)=double(Z);
end
in lines 451 to 453

Code: Select all

if length(ROMSnames) == 1
   Z=complex(ncread(TPXOfile.vel,'uRe',[u.I(1) u.J(1)],[length(u.I) length(u.J)]),...
      ncread(TPXOfile.vel,'uIm',[u.I(1) u.J(1)],[length(u.I) length(u.J)]));
   Z=double(Z);
   TPXO.U.z(:,:)=Z./repmat(TPXO.U.depth,[1 size(Z,2)]);
else
   Z=complex(ncread(TPXOfile.vel,'uRe',[u.I(1) u.J(1) nH],[length(u.I) length(u.J) 1]),...
      ncread(TPXOfile.vel,'uIm',[u.I(1) u.J(1) nH],[length(u.I) length(u.J) 1]));
   Z=double(Z);
   TPXO.U.z(:,:,nH)=Z./repmat(TPXO.U.depth,[1 1 size(Z,3)]);
end
in lines 456 to 459

Code: Select all

if length(ROMSnames) == 1
    Z=complex(ncread(TPXOfile.vel,'vRe',[v.I(1) v.J(1)],[length(v.I) length(v.J)]),...
      ncread(TPXOfile.vel,'vIm',[v.I(1) v.J(1)],[length(v.I) length(v.J)]));
    Z=double(Z);
   TPXO.V.z(:,:)=Z./repmat(TPXO.V.depth,[1 size(Z,2)]);
else
    Z=complex(ncread(TPXOfile.vel,'vRe',[v.I(1) v.J(1) nH],[length(v.I) length(v.J) 1]),...
      ncread(TPXOfile.vel,'vIm',[v.I(1) v.J(1) nH],[length(v.I) length(v.J) 1]));
    Z=double(Z);
   TPXO.V.z(:,:,nH)=Z./repmat(TPXO.V.depth,[1 1 size(Z,3)]);
end
in lines 462 to 465.

BUT, I really have to admit that I am not sure if I had to change more than that in order to make it work. However, you can give it a try. First PLEASE backup your function file!!!

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#53 Post by neelbasak08 »

Thanks a lot Cate.

I just tested the suggestions you made by changing them accordingly in my script (I kept an original copy of the previous version of the scripts safe for backup). I ran into a rather unexpected error:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Unrecognized function or variable 'ROMSnames'.

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 453)
if length(ROMSnames) == 1

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 26)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
It's rather unexpected because I've checked the scripts quite a number of times now it's well defined in the TPXO2ROMS_v5pt1_script.m file by the name ROMSnames={'Q1'};

I don't know whats causing the error. is it that my TPXO2ROMS_v5pt1.m script isn't able to retrieve the variable from TPXO2ROMS_v5pt1_script.m accurately or is it something wrong in my grid ?
Any kind of help from anyone is appreciated to the fullest.

Kind Regards
-Neel
Attachments
TPXO2ROMS_v5pt1.m
(23.62 KiB) Downloaded 7 times
TPXO2ROMS_v5pt1_script.m
(1.29 KiB) Downloaded 6 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#54 Post by c.drinkorn »

Hi Nee,

yes, I know now I had to add the variable to the function readTPXOdata. Inside of the function file the code also calls subfunctions which need necessary variables passed on to them. readTPXOdata doesn't know ROMSnames in your file. You have to add it as a function variable:

Code: Select all

function TPXO=readTPXOdata(TPXOfile,lon,lat,ROMSnames)
in line 398.

and add the variable to the variables passed on to the function

Code: Select all

TPXO=readTPXOdata(TPXOfile,lonR,latR,ROMSnames);
in line 78.

Lets see how this works. :)

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#55 Post by neelbasak08 »

Thanks a lot Cate for constantly helping me out with my errors. I am highly indebted to you.

Unfortunately I am now in a belief that there's something wrong I guess with the grid file itself. I am constantly getting new error with every change you suggest. I guess I must have got the wrong grid file otherwise it shouldn't happen that the same script works for you and not for me. The error I got this time is new and is as follows:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Matrix dimensions must agree.

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 468)
TPXO.U.z(:,:)=Z./repmat(TPXO.U.depth,[1 size(Z,2)]);

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR,ROMSnames);

Error in TPXO2ROMS_v5pt1_script (line 26)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
Not sure what's the problem with dimension now. At this point I personally feel I've bothered you guys pretty well enough :( :( :( .

I am not sure why this error occurred in the first place .

Any help in any form is extremely appreciated by me.

Thanks a lot.

-Neel
Attachments
grd_Vizhinjam.nc
(7.67 MiB) Downloaded 4 times
TPXO2ROMS_v5pt1.m
(23.64 KiB) Downloaded 6 times
TPXO2ROMS_v5pt1_script.m
(1.29 KiB) Downloaded 7 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#56 Post by c.drinkorn »

Hi Neel,

I am very sorry I couldn't help you solve the problems.
I suspect TPXO2ROMS_v5x is not compatible with TPXO9_atlas data but maybe I am wrong. TPXO9_atlas data has a very different structure than TPXO8 and even if John Luick writes in the comments of the function that there were a lot of changes made in accordance to the new file structure, maybe this is only valid for the non-atlas data.
All I can say is that TPXO2ROMS_v4x is well compatible with TPXO8_atlas data. So maybe you try and work with this for the first. You can find the v4 further up in this thread and the v8 TPXO atlas data is available upon request, too.

Good Luck! :)

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#57 Post by johnluick »

Hi Neel,
tomorrow morning I will have another look. Meanwhile, could you download TPXO2ROMS_v5pt1.m again to ensure we are using the identical software, and try to run it with the Vizhinjam grid? Let me know what the error is, if you get one.
Cheers
John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#58 Post by neelbasak08 »

Thanks a lot Cate for your help. Will definitely consider your suggestion. Good luck to you as well :)

Thanks a lot Mr. John, I again downloaded the TPXO to ROMS Express v. 5.1 zip file from https://austides.com/downloads/ as you had suggested. I chaned the portion of script which required giving the location of my files and filenames in both scripts as follows:
TPXO2ROMS_v5pt1_script.m:

Code: Select all

 %****************Modify to suit*************** 
TIDE_START=18485;  %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(1968,5,23);  %TIDE_START in Matlab datenum
lengthSim=60;  %approximate length of model run in days
fnGrid='C:\Users\aBc\Documents\MATLAB\TPXO\grd_Vizhinjam.nc';
fnOut=['C:\Users\aBc\Documents\MATLAB\TPXO\frc_TPXO9_Vizhinjam_' datestr(t0,'ddmmmyyyy') '.nc'];
ROMSnames={'Q1'};

%******************************************** 
TPXO2ROMS_v5pt1.m in lines 71-74:

Code: Select all

 %TPXO filenames (files must be on Matlab path)
TPXOfile.grid='grid_tpxo9_atlas_v4.nc';
TPXOfile.elev='h_q1_tpxo9_atlas_30_v4.nc';
TPXOfile.vel='u_q1_tpxo9_atlas_30_v4.nc';
 

The error I received is as follows:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Index exceeds the number of array elements (0).

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 421)
TPXO.h.depth=ncread(TPXOfile.grid,'hz',[h.I(1) h.J(1)],[length(h.I) length(h.J)]); %bathymetry at z nodes

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 27)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)

Not sure if what this error is. I tried Cate's solution before (actually a series of modifications she suggested) but down the road, unfortunately it didn't work out pretty well. These are the location of my files and filenames present in my MATLAB path:
My location for files are as follows-
matlab_dir: C:\Users\aBc\Documents\MATLAB\TPXO
mexcdf: C:\Users\aBc\Documents\MATLAB\TPXO
netcdf_toolbox: C:\Users\aBc\Documents\MATLAB\TPXO
h_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
u_q1_tpxo9_atlas_30_v4.nc : C:\Users\aBc\Documents\MATLAB\TPXO
grid file on which i want forcing: C:\Users\aBc\Documents\MATLAB\TPXO
TPXO2ROMS_v5pt1_script.m: C:\Users\aBc\Documents\MATLAB\TPXO
TPXO2ROMS_v5pt1.m: C:\Users\aBc\Documents\MATLAB\TPXO

Looking forward to a positive reply.

Thanks a lot in advance.
-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#59 Post by johnluick »

Hi Neel

please replace your TPXO2ROMS_v5pt1.m with attached (TPXO2ROMS_v5pt2.m) and let me know if it works.

John
Attachments
TPXO2ROMS_v5pt2.m
(24.83 KiB) Downloaded 13 times

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#60 Post by neelbasak08 »

I believe that my TPXO9 files are the ones I got i.e. TPXO9-atlas-v4 netcdf isn't what the script was made to extract tidal forcing from. I believe the script was meant to work on TPXO9v1 netcdf. I tried your new script TPXO2ROMS_v5pt2.m script and TPXO2ROMS_v5pt1_script.m script with the following error

Error :
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Index exceeds the number of array elements (0).

Error in TPXO2ROMS_v5pt1>readTPXOdata (line 421)
TPXO.h.depth=ncread(TPXOfile.grid,'hz',[h.I(1) h.J(1)],[length(h.I) length(h.J)]); %bathymetry at z nodes

Error in TPXO2ROMS_v5pt1 (line 78)
TPXO=readTPXOdata(TPXOfile,lonR,latR);

Error in TPXO2ROMS_v5pt1_script (line 27)
TPXO2ROMS_v5pt1(t0,ROMSnames,fnGrid,fnOut,lengthSim)
I had got access to TPXO9-atlas-v4 netcdf. Therefore when I tried the new script as provided by you, it showed same error. Therefore, I have requested Dr. Erofeeva agin for TPXO9v1 netcdf files. Maybe that will work. I will keep you posted. Then I will try with TPXO9v1 netcdf files , the same script. Will let you know of errors.

Thanks a lot again Mr. John Luick.

I hope of not running running into troubles again.

-Neel

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#61 Post by c.drinkorn »

Hi Neel and John

the attached file is my Matlab function to read TPXO atlas data. I adapted it to the current TPXO9 version on the basis of John's TPXO2ROMS_v4 script. It works fine for me. It can read in several constituents after each other on the basis of individual TPXO files or just one, such as Q1. It just needs the right file names and paths. (I just adapted the M2 names). The TPXO path name may be empty if the files are in the Matlab working folder. I think it should work like that, too.
It is a bit hard coded in some places and the newest version 5 looks way more elegant than this, but for the atlas data maybe it's a working alternative. :)

Let me know if this works for you, too, Neel. You will have to change the name of the called function in the _script file, of course. And the names and paths to your TPXO constituent files. I press my thumbs! ;)
Attachments
TPXO2ROMS.m
(23.15 KiB) Downloaded 8 times

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#62 Post by neelbasak08 »

Hello Cate.

Thanks a lot for your constant help to me. The script was working extremely well (atleast better than all my previous iterations) till it encountered an error at this portion specifically line 141 in your script:
>> TPXO2ROMS_v5pt1_script

TPXO_path =

'C:\Users\aBc\Documents\MATLAB\TPXO\'

Reading TPXO
'Interpolating ' 'M2' ' amplitudes'

Reference to non-existent field 'h'.

Error in TPXO2ROMS (line 141)
ei=interpTPXO(TPXO.h,harmonic,count,lonR,latR,maskR);

Error in TPXO2ROMS_v5pt1_script (line 27)
TPXO2ROMS(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
P.S. I am using u_m2_tpxo9_atlas_30_v4.nc, h_m2_tpxo9_atlas_30_v4.nc and grid_tpxo9_atlas_v4.nc in the path C:\Users\aBc\Documents\MATLAB\TPXO\

How should I remove this error in your script Cate ? 'Reference to non-existent field 'h' , have you got any clue as to how this reference can be created ? I think same errors might occur in in subsequent lines of 146(ei=interpTPXO(TPXO.U,harmonic,count,lonR,latR,maskR);) and 151(ei=interpTPXO(TPXO.V,harmonic,count,lonR,latR,maskR);) as all these lines are similar to line 141. I don't know for sure. You're an expert and can better guide me.

Is there something to do to remove this error ?


Any help is appreciated heartily.
-neel

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#63 Post by c.drinkorn »

Hi Neel,

I think the error comes from the line 617 and following. I forgot to mention that you also have to change the path to your grid file here or remove mine if your grid file is in the Matlab working folder:

Code: Select all

elseif strcmp(TPXOfile_grid,'grid_tpxo9_atlas_v4.nc');
Then it should work. :)

Cheers,
Cate

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#64 Post by neelbasak08 »

Hello Cate

Thanks a lot for your script. It moved a step ahead until it met the error:
>> TPXO2ROMS_v5pt1_script

TPXO_path =

'C:\Users\aBc\Documents\MATLAB\TPXO\'

Reading TPXO
'Interpolating ' 'M2' ' amplitudes'

Warning: Insufficient number of data points to create a triangulation-based interpolant.
> In TPXO2ROMS>interpTPXO (line 397)
In TPXO2ROMS (line 141)
In TPXO2ROMS_v5pt1_script (line 27)
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.

Error in TPXO2ROMS>interpTPXO (line 398)
F=griddedInterpolant(x',y',z');

Error in TPXO2ROMS (line 141)
ei=interpTPXO(TPXO.h,harmonic,count,lonR,latR,maskR);

Error in TPXO2ROMS_v5pt1_script (line 27)
TPXO2ROMS(t0,ROMSnames,fnGrid,fnOut,lengthSim)
Any clue on what might cause this error ?

Any form of help is appreciated.

Regards
-Neel

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#65 Post by neelbasak08 »

Hello Cate and John

I have a ran into an error while running my grid file which I made using GridBuilder .exe tool version 0.99.5

First and foremost a very very hearty gratitude for all your help and efforts. The script sent by you gentle humans got the grid file which was sent for test by Mr. John Luick ' grd_Vizhinjam.nc' is up and running with outputs . I am attaching the script as a reference for future help seekers.


I'm not sure what's wrong with my own grid on which I want to work on is causing an error:
>> TPXO2ROMS_v5pt1_script
Reading TPXO data
Finished reading
Interpolating M2 amplitudes
Artifically doubling TPXO grid resolution
Interpolating M2 u components
Interpolating M2 v components
Warning: Insufficient number of data points to create a triangulation-based interpolant.
> In TPXO2ROMS_v5pt2>interpTPXO (line 424)
In TPXO2ROMS_v5pt2 (line 177)
In TPXO2ROMS_v5pt1_script (line 27)
Error using griddedInterpolant
Sample values must be a single or double array.

Error in TPXO2ROMS_v5pt2>doubleResolution (line 692)
F=griddedInterpolant(xA',yA',varA');

Error in TPXO2ROMS_v5pt2 (line 181)
mask=doubleResolution(TPXO.V.mask,factor);

Error in TPXO2ROMS_v5pt1_script (line 27)
TPXO2ROMS_v5pt2(t0,ROMSnames,fnGrid,fnOut,lengthSim)

>>
Not sure what's the error in it . If you guys could help me out with the grid file as to what is causing this error and how to remove it, then it would be highly beneficial for me. Is it a problem with gridbuilder tool that the grid file has defects ?

Thanks a lot in advance and extreme thanks for all the support you guys gave me all the time.

Regards
-Neel
Attachments
modify_bath.jpg
modify_mask.jpg
modify_z.jpg
TPXO2ROMS_v5pt1_script.m
(1.37 KiB) Downloaded 5 times
TPXO2ROMS_v5pt2.m
(24.83 KiB) Downloaded 7 times
ROMS_grid_alderneyrace_new.nc
The grid that's causing this error using these scripts
(6.85 MiB) Downloaded 5 times

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#66 Post by johnluick »

Hi Neel

it is pretty obvious that you have chosen some parameter or set of parameters in GridBuilder which is causing the problem in TPXO2ROMS. The GridBuilder guru, Charles James, is on leave at the moment so probably won't be able to help you with that for a week or two. There is something strange about the fact that you have 300 cells in M, only 150 in L, the M axis is much shorter than the L axis, yet your cells are nearly square.

Meanwhile, I am attaching an Alderney grid that I created. TPXO2ROMS has no problem with it. I recommend you "Import" it into GridBuilder, edit the mask, export it, test it with TPXO2ROMS, modify a few parameters from the menu on the right hand side in strict accordance with the reference guide under "Help", then again test it with TPXO2ROMS, modify a few more parameters, repeat, etc. Don't change any of the defaults unless you have good reason to. This will get you going with some actual modelling.

All I did was set up the grid (choose boundaries) and set the minimum depth to +2 metres (my normal practice). I didn't touch the "Modify Z coordinate" or other things. I saw no point in putting the grid at an angle (as you did). (Actually I never have a grid at an angle unless absolutely necessary, which is almost never. KISS principle.) Oh yes, another thing I did which I consider to be of paramount importance, unless you want to go insane, is set the pivot corner to lower left hand (just drag the blue diamond down from whatever corner it is, to LLH).

In brief summary, I recommend you abandon the grid you created, and start over, without trying to get cute with the orthogonality and other options.

Good luck

John
Attachments
ROMS_grid_alderneyrace_v1.nc
(6.85 MiB) Downloaded 8 times

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#67 Post by neelbasak08 »

Extremely sorry for my late reply.

Thank you so much for your guidance and help. I have now created my own new grid for the region and kept the parameters as simple as possible. I took my references from the help menu and the suggestions you very generously made to me. Although the grid didn't turn out as good as yours but I learned a lot and thank you heartily for all the pain you took to sort my naïve queries out.

Once again thanks a lot Mr. John and Cate for helping me with everything I need.

Kind regards
-Neel

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#68 Post by neelbasak08 »

johnluick wrote: Tue Jan 19, 2021 12:19 am Hi Neel

it is pretty obvious that you have chosen some parameter or set of parameters in GridBuilder which is causing the problem in TPXO2ROMS. The GridBuilder guru, Charles James, is on leave at the moment so probably won't be able to help you with that for a week or two. There is something strange about the fact that you have 300 cells in M, only 150 in L, the M axis is much shorter than the L axis, yet your cells are nearly square.

Meanwhile, I am attaching an Alderney grid that I created. TPXO2ROMS has no problem with it. I recommend you "Import" it into GridBuilder, edit the mask, export it, test it with TPXO2ROMS, modify a few parameters from the menu on the right hand side in strict accordance with the reference guide under "Help", then again test it with TPXO2ROMS, modify a few more parameters, repeat, etc. Don't change any of the defaults unless you have good reason to. This will get you going with some actual modelling.

All I did was set up the grid (choose boundaries) and set the minimum depth to +2 metres (my normal practice). I didn't touch the "Modify Z coordinate" or other things. I saw no point in putting the grid at an angle (as you did). (Actually I never have a grid at an angle unless absolutely necessary, which is almost never. KISS principle.) Oh yes, another thing I did which I consider to be of paramount importance, unless you want to go insane, is set the pivot corner to lower left hand (just drag the blue diamond down from whatever corner it is, to LLH).

In brief summary, I recommend you abandon the grid you created, and start over, without trying to get cute with the orthogonality and other options.

Good luck

John
Mr. John,
Greetings

I was working with TPXO9 script sent by you and all was working well. I was able to generate the output .nc as well.

But today when I was again working with the script, it showed some error that I hadn't previously encountered:
TPXO2ROMS_v5pt1_script
Reading TPXO data
Finished reading
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt1_script (line 27)

Index in position 1 is invalid. Array indices must be positive integers or logical values.

Error in TPXO2ROMS_v5pt2 (line 114)
ROMSharmonics(nR,:)=TPXOharmonicData(nT,:);

Error in TPXO2ROMS_v5pt1_script (line 27)
I then tried to check with the previous grids i had worked on using this script but it showed the aforementioned error for those as well including the grd_Vizhinjam.nc file. These were the same scripts that were earlier working perfectly fine but now i don't know why it throws this error.

I checked Nharmonics variable and it seems okay to me. nR and nT also seemed okay as they should have integer values. But what might the the reason for this error? How should I remove this error ?

I am extremely sorry for bugging you again.

Thanks a lot in advance.
Kind regards
-Neel
Attachments
TPXO2ROMS_v5pt2.m
(24.83 KiB) Downloaded 7 times
TPXO2ROMS_v5pt1_script.m
(1.3 KiB) Downloaded 6 times

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#69 Post by johnluick »

Hi Neel,

can you repeat the exercise, but with TPXO2ROMS_v5pt2_script.m (instead of TPXO2ROMS_v5pt1_script.m), and let me know what happens?

If it works, I recommend deleting v5pt1, to remove future confusion.

Cheers

John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#70 Post by neelbasak08 »

johnluick wrote: Thu Feb 04, 2021 8:31 am Hi Neel,

can you repeat the exercise, but with TPXO2ROMS_v5pt2_script.m (instead of TPXO2ROMS_v5pt1_script.m), and let me know what happens?

If it works, I recommend deleting v5pt1, to remove future confusion.

Cheers

John
Dear Mr. John, I repeated the process using TPXO2ROMS_v5pt2_script.m downloaded from austides website. Sorry for writing it down here without checking the austides websites again. But again I'm being shown the same error again :
>> TPXO2ROMS_v5pt2_script
Reading TPXO data
Finished reading
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Index in position 1 is invalid. Array indices must be positive integers or logical values.

Error in TPXO2ROMS_v5pt2 (line 114)
ROMSharmonics(nR,:)=TPXOharmonicData(nT,:);

Error in TPXO2ROMS_v5pt2_script (line 338)
TPXO2ROMS_v5pt2(t0,ROMSnames,fnGrid,fnOut,lengthSim)
Is it a problem with my MATLAB version ? I'm using MATLAB 2019b and I don't think it should be a problem. I checked grid file as well grd_Vizhinjam.nc, same as the previous one which worked. I have all my mexcdf and snctools files in the same directory added to the path as well. How should i remove this error ?

P.S. I am using grid_tpxo9.v4a.nc, h_tpxo9.v4a.nc ,u_tpxo9.v4a.nc files. It had worked fine earlier.

Any help in any form is deeply appreciated by me.

Kind regards
-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#71 Post by johnluick »

Hi Neel,

sorry for the delay. I was interstate. As an experiment to see if I could live without my laptop for two days, I did not bring it along. Yes, I survived.

I downloaded and ran your TPXO2ROMS script file and TRXO2ROMS.m, and they worked fine. The only changes I made were to the file paths in the script file, and I change the names of the TPXO files back to my versions of TPXO9 as follows:
%TPXO filenames (files must be on Matlab path)
TPXOfile.grid='grid_tpxo9.nc';
TPXOfile.elev='h_tpxo9.v1.nc';
TPXOfile.vel='u_tpxo9.v1.nc';
%TPXOfile.grid='grid_tpxo9.v4a.nc';
%TPXOfile.elev='h_tpxo9.v4a.nc';
%TPXOfile.vel='u_tpxo9.v4a.nc';

Apparently they have changed something about the character array in TPXO9 version v4a (the characters that are read into TPXO.harmonicNames). I will look into that when I can, and create a new version of TPXO2ROMS if necessary. Meanwhile, if you still have an older version of the TPXO data ( for example, v1) it should work.

I would be interested in the result of the following test using v4a. Pause the code at the line that fails (I think it was line 109)
I mean this line: cmp=strcmp(deblank(TPXO.harmonicNames(k,1:4)),ROMSnames{nR});
Then enter the following:
K>> dd=deblank(TPXO.harmonicNames(13,1:4))
You should get the following result:
dd = 'MS4'
Then enter:
K>> whos dd
You should get:
Name Size Bytes Class Attributes
dd 1x3 6 char

Cheers

John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#72 Post by neelbasak08 »

Dear Mr. John

Thanks a lot for your kind reply.

I think I had figured out the problem yesterday when I was working, I am not sure if it's correct. I made the change and it started working again but then I'm not sure what I've done is healthy or not .

Code: Select all

 for nR=1:Nharmonics
   nT=0;
   for k=1:NTPXO
      cmp=strcmp(deblank(TPXO.harmonicNames(k,1:4)),ROMSnames{nR});
      if cmp
         nT=k;
      end
   end 
While running the code in debug mode I found out that even after successive iteration in the loop nT value wasn't changing from an initially set 0. I checked the value of cmp and it was 0 after every pass in the loop so what I did was I just changed if cmp condition to

Code: Select all

 if cmp==0
            nT=k;
            end
           end  
Then I saw that nT variable was incrementing as was required by the script and it successfully generated the output file. Again I'm not sure if what I have done is right or wrong or just a bad patchment work. I checked it with tpxo9_v4a.nc files itself as I have access only to that database. It is working as it seems to me.

You are the expert in this Mr. John, maybe you could comment whether it's correct or not .

Kind regards
-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#73 Post by johnluick »

Neel,

I have been told there was no format change between v1 and v4, so there must be a problem in your inputs. Can you please post the ten or so input lines from your TPXO2ROMS_v5pt2_script.m, and also post the lines that are displayed when you change that section of code to:

if cmp
nT=k;
disp([deblank(TPXO.harmonicNames(k,1:4)),' ',ROMSnames{nR}]) %New 11Feb2021
end

No, I do not think your change will produce the correct result.

Thanks

John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#74 Post by neelbasak08 »

Dear Mr. John,
Thanks for the reply.

Here is my input lines in the TPXO2ROMS_v5pt2_script.m file:

Code: Select all

 %****************Alderney Race*************** 
RUNTPXO=1; %set to 0 to skip computation - handy for playing with the plot only
TIDE_START=3042;  %From ROMS *.in file (TIME_REF=-2)
t0=TIDE_START+datenum(2011,1,1);  %TIDE_START in Matlab datenum
lengthSim=30;  %approximate length of model run in days
fnGrid='C:\Users\aBc\Documents\MATLAB\TPXO\ROMS_alderney_z_test.nc';
fnOut=['C:\Users\aBc\Documents\MATLAB\TPXO\frc_TPXO9_alderneyv1' datestr(t0,'ddmmmyyyy') '_v4a.nc'];
ROMSnames={'MM' 'MF' 'Q1' 'O1' 'P1' 'K1' 'N2' 'M2' 'S2' 'K2' 'MN4' 'M4' 'MS4' '2N2' 'S1'}; 
% Hplot, skip, sfac, and smaj are parameters for the ellipse map
% Hplot='Q1'; %Which harmonic to plot (name one, e.g. 'M2', 'K1', etc.)
% skip=10; %plot each skipth'th ellipse
% sfac=0.1; %sf=scalefactor (the ellipse sizes are arbitrary)
% smaj=1; %Semi-major axis of scale factor ellipse 
After the I changed the code to the one you suggested I didnot get any specific output pertaining to the line disp([deblank(TPXO.harmonicNames(k,1:4)),' ',ROMSnames{nR}]) %New 11Feb2021. Instead I receive the error message as follows when I run the script:
>> TPXO2ROMS_v5pt2_script
Reading TPXO data
Finished reading
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 109)
In TPXO2ROMS_v5pt2_script (line 338)
Index in position 1 is invalid. Array indices must be positive integers or logical values.

Error in TPXO2ROMS_v5pt2 (line 115)
ROMSharmonics(nR,:)=TPXOharmonicData(nT,:);

Error in TPXO2ROMS_v5pt2_script (line 338)
TPXO2ROMS_v5pt2(t0,ROMSnames,fnGrid,fnOut,lengthSim)
As far as my understanding after executing the code I see , line 109 - " cmp=strcmp(deblank(TPXO.harmonicNames(k,1:4)),ROMSnames{nR});" after execution cmp value remains 0 after every iteration of the loop.

Part of the code looks like this :

Code: Select all

 Nharmonics=length(ROMSnames);
NTPXO=length(TPXO.harmonicNames);
ROMSperiods=zeros(1,Nharmonics);
ROMSharmonics=zeros(Nharmonics,8);
Vdeg=zeros(Nharmonics,1);
for nR=1:Nharmonics
   nT=0;
   for k=1:NTPXO
      cmp=strcmp(deblank(TPXO.harmonicNames(k,1:4)),ROMSnames{nR});
      if cmp
         nT=k;
         disp([deblank(TPXO.harmonicNames(k,1:4)),' ',ROMSnames{nR}]) %New 11Feb2021
      end
   end
   ROMSharmonics(nR,:)=TPXOharmonicData(nT,:); 
And all the values as seen from the workspace window looks like the attachment image.

What might be going wrong in that case ? I believe the script is working for you. I haven't really made any changes to it except for the time initialization which I needed according to my other files.

Kind regards
-Neel
Attachments
Workspace details
Workspace details
Screenshot 2021-02-11 093917.jpg (43.6 KiB) Viewed 1399 times
TPXO2ROMS_v5pt2_script.m
(21.64 KiB) Downloaded 6 times
TPXO2ROMS_v5pt2.m
(24.92 KiB) Downloaded 5 times

c.drinkorn
Posts: 104
Joined: Thu Mar 08, 2018 2:47 am
Location: German Research Centre for Geosciences

Re: TPXO to ROMS EXPRESS (tide extraction software)

#75 Post by c.drinkorn »

Hi Neel!

It seems like the string comparison never finds a match. So I guess there is something wrong with the reading of the constituents from the file. In line 486 of TPXO2ROMS_v5pt2.m you can see that the harmonicNames are read from the variable "con" in the elevation file. Can you check if the file h_tpxo9.v4a.nc has the variable "con" in it?

To John Luick: The function uses nc_varget here which is not a native Matlab function. Is there a reason why?

Cheers,
Cate

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#76 Post by johnluick »

Hi Neel,

Change that section of code to:

for nR=1:Nharmonics
disp(['nR = ', num2str(nR)])
nT=0;
for k=1:NTPXO
s1=deblank(TPXO.harmonicNames(k,1:4));
s2=ROMSnames{nR};
disp([s1,' ',s2])
cmp=strcmp(s1,s2);
if cmp
nT=k;
disp(['k = ',num2str(k)])
end
end
ROMSharmonics(nR,:)=TPXOharmonicData(nT,:);
%ROMSharmonics.(ROMSnames{n})=TPXOharmonicData(nT,:);
ROMSperiods(nR)=360./TPXOharmonicData(nT,end);
Vdeg(nR)=Vphase(t0,ROMSharmonics(nR,:));
%Vdeg.(ROMSnames{n})=Vphase(t0,ROMSharmonics.(ROMSnames{n}));
end

It is the same but with a couple of new disp statements.
I suggest you also put a debug stop after that section to stop it from going further.

Using your script with 15 harmonics, the following was displayed to my screen:
>> TPXO2ROMS_v5pt2_script
Reading TPXO data
Finished reading
nR = 1
M2 MM
S2 MM
N2 MM
K2 MM
K1 MM
O1 MM
P1 MM
Q1 MM
MM MM
k = 9
MF MM
M4 MM
MN4 MM
MS4 MM
2N2 MM
S1 MM
nR = 2
M2 MF
S2 MF
N2 MF
K2 MF
K1 MF
O1 MF
P1 MF
Q1 MF
MM MF
MF MF
k = 10
M4 MF
MN4 MF
MS4 MF
2N2 MF
S1 MF
nR = 3
M2 Q1
S2 Q1
N2 Q1
K2 Q1
K1 Q1
O1 Q1
P1 Q1
Q1 Q1
k = 8
MM Q1
MF Q1
M4 Q1
MN4 Q1
MS4 Q1
2N2 Q1
S1 Q1
nR = 4
M2 O1
S2 O1
N2 O1
K2 O1
K1 O1
O1 O1
k = 6
P1 O1
Q1 O1
MM O1
MF O1
M4 O1
MN4 O1
MS4 O1
2N2 O1
S1 O1
nR = 5
M2 P1
S2 P1
N2 P1
K2 P1
K1 P1
O1 P1
P1 P1
k = 7
Q1 P1
MM P1
MF P1
M4 P1
MN4 P1
MS4 P1
2N2 P1
S1 P1
nR = 6
M2 K1
S2 K1
N2 K1
K2 K1
K1 K1
k = 5
O1 K1
P1 K1
Q1 K1
MM K1
MF K1
M4 K1
MN4 K1
MS4 K1
2N2 K1
S1 K1
nR = 7
M2 N2
S2 N2
N2 N2
k = 3
K2 N2
K1 N2
O1 N2
P1 N2
Q1 N2
MM N2
MF N2
M4 N2
MN4 N2
MS4 N2
2N2 N2
S1 N2
nR = 8
M2 M2
k = 1
S2 M2
N2 M2
K2 M2
K1 M2
O1 M2
P1 M2
Q1 M2
MM M2
MF M2
M4 M2
MN4 M2
MS4 M2
2N2 M2
S1 M2
nR = 9
M2 S2
S2 S2
k = 2
N2 S2
K2 S2
K1 S2
O1 S2
P1 S2
Q1 S2
MM S2
MF S2
M4 S2
MN4 S2
MS4 S2
2N2 S2
S1 S2
nR = 10
M2 K2
S2 K2
N2 K2
K2 K2
k = 4
K1 K2
O1 K2
P1 K2
Q1 K2
MM K2
MF K2
M4 K2
MN4 K2
MS4 K2
2N2 K2
S1 K2
nR = 11
M2 MN4
S2 MN4
N2 MN4
K2 MN4
K1 MN4
O1 MN4
P1 MN4
Q1 MN4
MM MN4
MF MN4
M4 MN4
MN4 MN4
k = 12
MS4 MN4
2N2 MN4
S1 MN4
nR = 12
M2 M4
S2 M4
N2 M4
K2 M4
K1 M4
O1 M4
P1 M4
Q1 M4
MM M4
MF M4
M4 M4
k = 11
MN4 M4
MS4 M4
2N2 M4
S1 M4
nR = 13
M2 MS4
S2 MS4
N2 MS4
K2 MS4
K1 MS4
O1 MS4
P1 MS4
Q1 MS4
MM MS4
MF MS4
M4 MS4
MN4 MS4
MS4 MS4
k = 13
2N2 MS4
S1 MS4
nR = 14
M2 2N2
S2 2N2
N2 2N2
K2 2N2
K1 2N2
O1 2N2
P1 2N2
Q1 2N2
MM 2N2
MF 2N2
M4 2N2
MN4 2N2
MS4 2N2
2N2 2N2
k = 14
S1 2N2
nR = 15
M2 S1
S2 S1
N2 S1
K2 S1
K1 S1
O1 S1
P1 S1
Q1 S1
MM S1
MF S1
M4 S1
MN4 S1
MS4 S1
2N2 S1
S1 S1
k = 15

Please tell me what you get.

Cheers

John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#77 Post by neelbasak08 »

Dear Mr. John, I did what you had suggested me to do and received the following while running in debug mode :
>> TPXO2ROMS_v5pt2_script
Reading TPXO data
Finished reading
nR = 1
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
m2 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
s2 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
n2 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
k2 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
k1 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
o1 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
p1 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
q1 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
mm MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
mf MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
m4 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
mn4 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
ms4 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
2n2 MM
Warning: Input should be a string, character array, or cell array of character arrays.
> In TPXO2ROMS_v5pt2 (line 110)
In TPXO2ROMS_v5pt2_script (line 338)
s1 MM
Index in position 1 is invalid. Array indices must be positive integers or logical values.

Error in TPXO2ROMS_v5pt2 (line 119)
ROMSharmonics(nR,:)=TPXOharmonicData(nT,:);

Error in TPXO2ROMS_v5pt2_script (line 338)
TPXO2ROMS_v5pt2(t0,ROMSnames,fnGrid,fnOut,lengthSim)
And after this the script execution ended. This is the same error which I had earlier posted.

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#78 Post by neelbasak08 »

c.drinkorn wrote: Thu Feb 11, 2021 9:20 am Hi Neel!

It seems like the string comparison never finds a match. So I guess there is something wrong with the reading of the constituents from the file. In line 486 of TPXO2ROMS_v5pt2.m you can see that the harmonicNames are read from the variable "con" in the elevation file. Can you check if the file h_tpxo9.v4a.nc has the variable "con" in it?

To John Luick: The function uses nc_varget here which is not a native Matlab function. Is there a reason why?

Cheers,
Cate
Thanks Cate for your advice. I checked my h_tpxo9.v4a.nc file in matlab using ncdisp command and it seems fine. Here's a portion of the output :
file='h_tpxo9.v4a.nc'

file =

'h_tpxo9.v4a.nc'

>> ncdisp(file)
Source:
C:\Users\aBc\Documents\MATLAB\TPXO\h_tpxo9.v4a.nc
Format:
classic
Global Attributes:
type = 'OTIS tidal elevation file'
title = 'TPXO9.v4a 2020 tidal elevation file: open ocean - TPXO9.v1, coastal - averaged TPXO9-atlas-v4'
Dimensions:
nx = 2160
ny = 1081
nc = 15
nct = 4
Variables:
con
Size: 4x15
Dimensions: nct,nc
Datatype: char
Attributes:
log_name = 'tidal constituents'
lon_z
Size: 1081x2160
Dimensions: ny,nx
Datatype: double
Attributes:
long_name = 'longitude of Z nodes'
units = 'degree_east'
lat_z
Size: 1081x2160
Dimensions: ny,nx
Datatype: double
Attributes:
long_name = 'latitude of Z nodes'
units = 'degree_north'
It had a bunch of other variables as well but I didn't post it here.

Kind regards
-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#79 Post by johnluick »

Cate is right (thank you, Cate!). The line at or near 486 in TPXO2ROMS_v5pt2.m, which currently reads
harmonicNames=upper(nc_varget(TPXOfile.elev,'con'));
must be changed to two lines:
harmonicNames=upper(ncread(TPXOfile.elev,'con'));
harmonicNames=permute(harmonicNames,[2,1]);
I will put a new v5pt3 online asap with this change.
My apologies to Neel.
In case you are interested, I think this is what happened. The original version was written before the native Matlab tools for reading netcdf became available (i.e., the command before ncread existed). So, like most people, I used snctools (e.g., command nc_varget). At some point, I converted TPXO2ROMS to native tools (ncread etc.), but somehow I missed that line. For me and anyone else with snctools in their path, it still worked.
What I do not understand is why Neel did not get an error message at line 486.
Cheers
John

User avatar
neelbasak08
Posts: 64
Joined: Wed Dec 09, 2020 3:58 pm
Location: Thapar Institute of Engineering and Technology, Patiala, PN, India

Re: TPXO to ROMS EXPRESS (tide extraction software)

#80 Post by neelbasak08 »

Sorry for the late reply Mr. John and Cate. I was dealing with my examinations.

I took your suggestion, implemented it by changing the lines mentioned by Mr. John and again ran my file. Now it's working fine.

Thanks a lot for your help.

Kind regards
-Neel

johnluick
Posts: 112
Joined: Mon Jun 20, 2005 3:46 pm
Location: South Australian Research and Development Institute

Re: TPXO to ROMS EXPRESS (tide extraction software)

#81 Post by johnluick »

Hi Neel

that comes as a great relief - thanks for letting us know. Thanks again to Cate.

John

Post Reply