Adding variables to history and averages files

Suggest improvements/optimizations to the ROMS code.

Moderators: arango, robertson

Post Reply
Message
Author
abever
Posts: 23
Joined: Tue Feb 17, 2004 6:15 pm
Location: Anchor QEA, LLC

Adding variables to history and averages files

#1 Unread post by abever »

I am trying to add some new variables to the history and averages files, but am running into a snag. Below I will post the name of the file I modified, and what I added, shortened to a single variable only, even though I am adding a total of 5. The error, I believe, is that it is not reading in the "T" in the .in file to write out the variables (presumably this should be done in inp_par.F) I tried to copy the syntax used for other variables within the files. I didn't delete my debuging write statements for this. If anyone can point to why I get this error, and anything else that looks wrong that would be a great help. It looks like my tabs didn't copy over correctly, and a part of the code is short for a smiley.

The error is below, and comes directly after it starts definining the history file after step zero.

oceanS: string.c:42: NC_check_name: Assertion `name != ((void *)0)' failed.
Aborted


This write statement in def_his.F comes back with zeros for the variables.
write(6,*) 'hisVid', hisVid(idCwbl,ng), idCwbl



def_his.F

#ifdef WBLGRAV_HTG
!
! Define wbl variables
!
write(6,*) 'made here 1'
IF (Hout(idCwbl,ng)) THEN
Vinfo( 1)=Vname(1,idCwbl)
Vinfo( 2)=Vname(2,idCwbl)
Vinfo( 3)=Vname(3,idCwbl)
Vinfo(14)=Vname(4,idCwbl)
Vinfo(16)=Vname(1,idtime)
# if defined WRITE_WATER && defined MASKING
Vinfo(20)='mask_rho'
# endif
Vinfo(22)='coordinates'
Aval(5)=REAL(Iinfo(1,idCwbl,ng),r8)
write(6,*) 'made here 2'
write(6,*) 'hisVid', hisVid(idCwbl,ng), idCwbl
status=def_var(ncHISid(ng),hisVid(idCwbl,ng),NF_FOUT, &
& nvd3,t2dgrd,Aval,Vinfo,ncname)
END IF
#endif
#ifdef WBLGRAV_HTG
IF (TRIM(varnam(i)).eq.TRIM(Vname(1,idCwbl))) THEN
got_var(idCwbl)=.TRUE.
status=nf90_inq_varid(ncHISid(ng), &
& TRIM(Vname(1,idCwbl)), &
& hisVid(idCwbl,ng))
END IF
#endif

#ifdef WBLGRAV_HTG
IF (.not.got_var(idCwbl).and.Hout(idCwbl,ng)) THEN
WRITE (stdout,60) TRIM(Vname(1,idCwbl)), TRIM(ncname)
exit_flag=3
RETURN
END IFC
#endif




wrt_his.F

#ifdef WBLGRAV_HTG
!
! Write out wave boundary layer gravity flow variables.
! CsedW,Uwbl,Vwbl,Ri
!
write(6,*) idCwbl, idWdir
IF (Hout(idCwbl,ng)) THEN
write(6,*) 'made it into CsedW writing loop'
scale=1.0_r8
gtype=gfactor*r2dvar
status=nf_fwrite2d(ng, iNLM, ncHISid(ng), hisVid(idCwbl,ng), &
& tHISindx(ng), gtype, &
& LBi, UBi, LBj, UBj, scale, &
# ifdef MASKING
& GRID(ng) % rmask(LBi,LBj), &
# endif
& OCEAN(ng) % CsedW(LBi,LBj,NST))
IF (status.ne.nf90_noerr) THEN
IF (Master) THEN
WRITE (stdout,10) TRIM(Vname(1,idCwbl)), tHISindx(ng)
END IF
exit_flag=3
ioerror=status
RETURN
END IF
END IF
#endif




inp_par.F
It looks like I was unsure of this part since I added some and then commented it out, should it be there?

#ifdef WBLGRAV_HTG
write(6,*) 'idCwbl', idCwbl
ELSE IF (TRIM(KeyWord).eq.'Hout(idCwbl)') THEN
! IF (idCwbl.eq.0) THEN
! WRITE (out,280) 'idCwbl'
! STOP
! END IF
Npts=load_l(Nval, Cval, Ngrids, Hout(idCwbl,1))
#endif

#ifdef WBLGRAV_HTG
IF (Hout(idCwbl,ng)) WRITE (out,170) Hout(idCwbl,ng), &
& 'Hout(idCwbl)', &
& 'WBL concentration'
#endif



mod_ncparam.F

#ifdef WBLGRAV_HTG
integer :: idCwbl ! Wave boundary layer sediment concentration
#endif
#ifdef WBLGRAV_HTG
CASE ('idCwbl')
idCwbl=varid
write(6,*) 'after1', idCwbl
#endif


varinfo.dat

'CsedW' ! Output
'sediment concentration in the wbl'
'kg m-3'
'wbl concentration,scalar'
'ocean_time'
'idCwbl'
'r2dvar'
1.0d0


ocean_main.in (we are actually modifying ocean_riverplume2.in)

Hout(idCwbl) == T ! wbl sediment concentration




Thanks

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

#2 Unread post by jcwarner »

- don't use tabs !
- can you compile in debug and run oceanG?

abever
Posts: 23
Joined: Tue Feb 17, 2004 6:15 pm
Location: Anchor QEA, LLC

#3 Unread post by abever »

So space things out using multiple spaces? What breaks from hitting tab instead?

oceanG gives me

At line 618 of file inp_par.f90
Traceback: (Innermost first)
Called from line 58 of file inp_par.f90
Called from line 80 of file ocean_control.f90
Called from line 67 of file master.f90
Fortran runtime error: Array element out of bounds: 0 in (1:500), dim=1


line 618, and those around it, are

ELSE IF (TRIM(KeyWord).eq.'Hout(idCwbl)') THEN
! IF (idCwbl.eq.0) THEN
! WRITE (out,280) 'idCwbl'
! STOP
! END IF
Npts=load_l(Nval, Cval, Ngrids, Hout(idCwbl,1)) ( line 618 )
write(6,*) 'idCwbl, Npts', idCwbl, Npts

This was commented out because I got the 280 error, which is

280 FORMAT (/,' READ_PHYPAR - variable info not yet loaded, ', a)

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

#4 Unread post by jcwarner »

what is written to the screen from the mod_ncparam write statement :
'after', _____????___


mod_ncparam.F
#ifdef WBLGRAV_HTG
CASE ('idCwbl')
idCwbl=varid
write(6,*) 'after1', idCwbl
#endif

abever
Posts: 23
Joined: Tue Feb 17, 2004 6:15 pm
Location: Anchor QEA, LLC

#5 Unread post by abever »

I doesn't make it that far, it doesn't write out anything.

I do get a

before1 0 (from the same file)


and

idCwbl 0 (from inp_par.f90)

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

#6 Unread post by jcwarner »

well, that is your problem.
Your problem is that idCwbl = 0.
In inp_par, it is trying to put a value in

Fortran runtime error: Array element out of bounds: 0 in (1:500), dim=1
Npts=load_l(Nval, Cval, Ngrids, Hout(idCwbl,1)) ( line 618 )

so it is trying to put a value into Hout(0,1) but Hout is from (1:500,1).
So that will not work.

So the million dollar question is "why is idCwbl = 0 ??"

In mod_ncparam, in the subroutien initialize_ncparam, you added:

#ifdef WBLGRAV_HTG
CASE ('idCwbl')
idCwbl=varid
write(6,*) 'after1', idCwbl
#endif

You said it "doesn't get that far", but it actually has gone that far and beyond it. Inp_par calls initialize_ncparam, and so idCwbl should get a value. Edit mod_ncparam, look for :

CASE ('idCwbl')
idCwbl=varid
write(6,*) 'after1', idCwbl

Is it really in the *.f90 ??

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

#7 Unread post by kate »

Did you add idCwbl to varinfo.dat?

abever
Posts: 23
Joined: Tue Feb 17, 2004 6:15 pm
Location: Anchor QEA, LLC

#8 Unread post by abever »

Yes it is in the mod_ncparam.f90, but it looks like the left hand side is not lined up with the rest of the code, it is off by one space, which is where emacs tabs it to. Is the tab breaking it? Why wasn't I supposed to use a tab?


And yes it is in varinfo.dat

varinfo.dat

'CsedW' ! Output
'sediment concentration in the wbl'
'kg m-3'
'wbl concentration,scalar'
'ocean_time'
'idCwbl'
'r2dvar'
1.0d0

jcwarner
Posts: 1200
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

#9 Unread post by jcwarner »

some systems will idenitfy the tab as a different character than a space. Bottom line: do not use tabs.
Make sure there are no tabs in mod_ncparam.F.
The code needs to read that line to relate idCwbl to a variable number.
So keep trying at that location until the code reads that line.

jprinehimer
Posts: 20
Joined: Fri Oct 20, 2006 3:34 pm
Location: VIMS

#10 Unread post by jprinehimer »

Aaron -

Whether emacs enters a tab or spaces is determined by the mode you're in. Opening a .F or .f90 file should put you in Fortran or F90 mode automatically. When you hit tab in this mode, emacs should indent appropriately and spaces, not a tab, should be entered. Also, opening the .h files should put you in Obj C (I think...) mode, which (I think...) also puts in spaces. The indentation won't be right in this mode, unless you change to fortran or f90 mode.

When editing the .in files, however, you'll be in Fundamental mode which DOES enter tabs. I've had ROMS choke a number of times because of this...

To see whether you have blanks or tabs in emacs you can use this minor-mode: http://www.emacswiki.org/cgi-bin/emacs/ ... nk-mode.el

Good Luck
Last edited by jprinehimer on Fri Oct 12, 2007 8:50 pm, edited 1 time in total.

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

#11 Unread post by arango »

This question keeps coming again and again. I added a useful information to WikiROMS detailing how to do this. Check FAQ menu:
https://www.myroms.org/wiki/index.php/F ... _Questions

It is not a good idea to include TABS to any of ROMS code. This should be avoided at all cost :!: We have several code processing scripts that are affected by TABS and will give surprising results. As a matter of code style, TABS are not recommended. Many modern codes do not allow TABS.

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

Re: Adding variables to history and averages files

#12 Unread post by nganju »

I'm fairly certain my problem is not related to tabs, since I've added variables before with no problems. But I am now trying to split the ubar_hadv diagnostic into the u*du/dx and v*du/dy terms, add them as idDu2d variables, and having the same problem reported above. I'm sure it's a silly error, but I've spent two days troubleshooting and can't see what I'm doing wrong.

The cryptic "order is important" note in mod_scalars may be part of the issue. I've checked that NDM2d is larger by 2 in all routines.

I added a cppdef called M2HADV_SEP, and my modifications to mod_param.F, mod_scalars.F, mod_ncparam.F, and varinfo.dat are shown below. I removed my additions to step2d_LF_AM3.h for the two terms, it is my understanding that the arrays would be initialized with zeros anyway.

In mod_param.F
#

Code: Select all

 ifdef DIAGNOSTICS_UV
!
!  2D Momentum diagnostics.
!
        NDM2d=4        ! Acceleration, 2D P-Gradient, stresses
#   ifdef UV_ADV
        NDM2d=NDM2d+1  ! Horizontal advection
#   endif
#   ifdef NEARSHORE_MELLOR
        NDM2d=NDM2d+1  ! Horizontal radiation stresses
#   endif
#   ifdef UV_COR
        NDM2d=NDM2d+1  ! Coriolis
#   endif
#   if defined UV_VIS2 || defined UV_VIS4
        NDM2d=NDM2d+1  ! Horizontal viscosity
#   endif
#   ifdef M2HADV_SEP
        NDM2d=NDM2d+2  ! two hadv components
#   endif
In mod_ncparam.F

Code: Select all

#ifdef DIAGNOSTICS_UV
              CASE ('idDu2d(M2pgrd)')
                idDu2d(M2pgrd)=varid
              CASE ('idDv2d(M2pgrd)')
                idDv2d(M2pgrd)=varid
              CASE ('idDu2d(M2sstr)')
                idDu2d(M2sstr)=varid
              CASE ('idDu2d(M2bstr)')
                idDu2d(M2bstr)=varid
              CASE ('idDv2d(M2sstr)')
                idDv2d(M2sstr)=varid
              CASE ('idDv2d(M2bstr)')
                idDv2d(M2bstr)=varid
              CASE ('idDu2d(M2rate)')
                idDu2d(M2rate)=varid
              CASE ('idDv2d(M2rate)')
                idDv2d(M2rate)=varid
# ifdef UV_ADV
              CASE ('idDu2d(M2hadv)')
                idDu2d(M2hadv)=varid
              CASE ('idDv2d(M2hadv)')
                idDv2d(M2hadv)=varid
# endif


# ifdef NEARSHORE_MELLOR
              CASE ('idDu2d(M2hrad)')
                idDu2d(M2hrad)=varid
              CASE ('idDv2d(M2hrad)')
                idDv2d(M2hrad)=varid
# endif
# ifdef UV_COR
              CASE ('idDu2d(M2fcor)')
                idDu2d(M2fcor)=varid
              CASE ('idDv2d(M2fcor)')
                idDv2d(M2fcor)=varid
# endif
# if defined UV_VIS2 || defined UV_VIS4
              CASE ('idDu2d(M2hvis)')
                idDu2d(M2hvis)=varid
              CASE ('idDv2d(M2hvis)')
                idDv2d(M2hvis)=varid
# endif
# ifdef M2HADV_SEP
              CASE ('idDu2d(M2hadx)')
                idDu2d(M2hadx)=varid
              CASE ('idDu2d(M2hady)')
                idDu2d(M2hady)=varid
# endif
In mod_scalars.F

Code: Select all

# ifdef DIAGNOSTICS_UV
        integer :: M2pgrd            ! 2D momentum, pressure gradient
        integer :: M2fcor            ! 2D momentum, Coriolis
        integer :: M2rate            ! 2D momentum, time rate of change
        integer :: M2hadv            ! 2D momentum, horizontal advection
#  ifdef NEARSHORE_MELLOR
        integer :: M2hrad            ! 2D momentum, horizontal stresses
#  endif
        integer :: M2hvis            ! 2D momentum, horizontal viscosity
        integer :: M2sstr            ! 2D momentum, surface stress
        integer :: M2bstr            ! 2D momentum, bottom stress
#  ifdef M2HADV_SEP
        integer :: M2hadx            ! 2D momentum, h. adv uux comp.
        integer :: M2hady            ! 2D momentum, h. adv vuy comp.
#  endif
In mod_scalars.F

Code: Select all

# ifdef DIAGNOSTICS_UV
!
!  Indices for 2D momentum diagnostic variables.
!  Order is important!
!
      M2pgrd=1
      ic=1
#  if defined UV_COR
      M2fcor=ic+1
      ic=ic+1
#  endif
#  if defined UV_ADV
      M2hadv=ic+1
      ic=ic+1
#  endif

#  if defined NEARSHORE_MELLOR
      M2hrad=ic+1
      ic=ic+1
#  endif
      M2sstr=ic+1
      ic=ic+1
      M2bstr=ic+1
#  if defined UV_VIS2 || defined UV_VIS4
      M2hvis=ic+2
 
#  endif
#  if defined M2HADV_SEP
      M2hadx=ic+3
      M2hady=ic+4
#  endif
      M2rate=NDM2d
In varinfo.dat

Code: Select all

'ubar_uux'                                         ! Input/Output
  '2D u-momentum, hadv uux term'
  'meter second-2'                                 ! [m/s2]
  'ubar_uux, scalar, series'
  'ocean_time'
  'idDu2d(M2hadx)'
  'u2dvar'
  1.0d0

'ubar_vuy'                                         ! Input/Output
  '2D u-momentum, hadv vuy term'
  'meter second-2'                                 ! [m/s2]
  'ubar_vuy, scalar, series'
  'ocean_time'
  'idDu2d(M2hady)'
  'u2dvar'
  1.0d0
And this is the error, which occurs while the diagnostic file is being created. The file is unreadable by ncdump or otherwise.

Code: Select all

STEP   Day HH:MM:SS  KINETIC_ENRG   POTEN_ENRG    TOTAL_ENRG    NET_VOLUME
  
        0   608 00:00:00  0.000000E+00  8.372662E+01  8.372662E+01  9.075481E+08
        DEF_HIS   - creating history file: ./his_40m_tidalzo_0001.nc
        WRT_HIS   - wrote history  fields (Index=1,1) into time record = 0000001
        DEF_DIAGS - creating diagnostics file: ./dia_cblast2007_0001.nc
  9 additional processes aborted (not shown)

  
  oceanM: string.c:176: NC_check_name: Assertion `name != ((void *)0)' failed.
  [marlin07:14708] *** Process received signal ***
  [marlin07:14708] Signal: Aborted (6)
  [marlin07:14708] Signal code:  (-6)
  [marlin07:14708] [ 0] /lib/libpthread.so.0 [0x2b87329a57d0]
  [marlin07:14708] [ 1] /lib/libc.so.6(gsignal+0x35) [0x2b8732be5095]
  [marlin07:14708] [ 2] /lib/libc.so.6(abort+0x110) [0x2b8732be6af0]
  [marlin07:14708] [ 3] /lib/libc.so.6(__assert_fail+0xef) [0x2b8732bde2df]
  [marlin07:14708] [ 4] ./oceanM(NC_check_name+0xef) [0x59872f]
  [marlin07:14708] *** End of error message ***
  mpiexec noticed that job rank 0 with PID 14708 on node marlin07.marlin.loc exited on signal 6 (Aborted). 
Any advice is appreciated, thanks...

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

Re: Adding variables to history and averages files

#13 Unread post by kate »

This code is so complicated that I very rarely get it all on the first pass when making changes. This is when good debugging skills become important, whether you use a debugger with a gui or just print statements.

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

Re: Adding variables to history and averages files

#14 Unread post by arango »

Actually, adding each component of the horizontal advection and viscosity is in my to do list. This needs to be done carefully because the advection has an additional term in curvilinear coordinates. You need to do splitting in both 2D and 3D equations because of the coupling. The split-explicit scheme is a numerical technique to resolve gravity-wave dynamics. Many people call ubar and vbar as barotropic velocities. I prefer to call them vertically-integrated velocity components.

Let me see if I can do it soon.

crowley
Posts: 12
Joined: Wed Mar 26, 2003 4:14 pm
Location: DOI/MMS

Re: Adding variables to history and averages files

#15 Unread post by crowley »

Do you have UV_VIS2 or UV_VIS4 defined? If not, then NDM2d is off by 1 (it was never incremented) You will need to adjust mod_scalars.F.
I would try this:

Code: Select all

# ifdef DIAGNOSTICS_UV
!
!  Indices for 2D momentum diagnostic variables.
!  Order is important!
!
      M2pgrd=1
      ic=1
#  if defined UV_COR
      M2fcor=ic+1
      ic=ic+1
#  endif
#  if defined UV_ADV
      M2hadv=ic+1
      ic=ic+1
#  endif
#  if defined M2HADV_SEP           !move here and increment ic
      M2hadx=ic+1
      M2hady=ic+2
      ic=ic+2
#  endif
#  if defined NEARSHORE_MELLOR
      M2hrad=ic+1
      ic=ic+1
#  endif
      M2sstr=ic+1
      ic=ic+1
      M2bstr=ic+1
#  if defined UV_VIS2 || defined UV_VIS4
      M2hvis=ic+2
#  endif
      M2rate=NDM2d
I don't remember details, but I do recall that ROMS was much happier when the indices were defined in a certain order. :wink:

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

Re: Adding variables to history and averages files

#16 Unread post by arango »

I updated the code to include the ξ- and η-components of horizontal advection, viscosity and diffusion. See following :arrow: ticket for details. I also added 2D and 3D relative and potential vorticity.

I did some testing but it will be advantageous if other users help us to test these new diagnostics fields in their particular applications.

Post Reply