Skip to content

Commit

Permalink
Remove hardcoded values (#50)
Browse files Browse the repository at this point in the history
* Replace some dimension hardcoded values with those read from the namelist file

* Emit a warning on missing nest file

* Small fix in example instructions
  • Loading branch information
milancurcic authored Jun 26, 2024
1 parent 532c707 commit fb49138
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cms-master/expt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ The resulting formatted nest files will be placed in a new directory: expt_getda
Either move or create a link to the nest files in expt_example/ by typing:

```bash
mv expt_getdata_example/nests expt_example/nests
mv expt_getdata_example/nests/* expt_example/nests/.
```

or:

```bash
ln -s expt_getdata_example/nests expt_example/nests
ln -s expt_getdata_example/nests/* expt_example/nests/.
```

## Run `cms`
Expand Down
26 changes: 13 additions & 13 deletions cms-master/src/getnestinfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ SUBROUTINE getnestinfo(nest_n)
nests(nest_n)%tend_mm = tend_mm
nests(nest_n)%tend_dd = tend_dd
nests(nest_n)%fill_value=fill_value
nests(nest_n)%uname="zu"
nests(nest_n)%vname="zv"
nests(nest_n)%wname="zw"
nests(nest_n)%densname="zd"
nests(nest_n)%tempname="zt"
nests(nest_n)%salnname="zs"
nests(nest_n)%uname = uvel_name
nests(nest_n)%vname = vvel_name
nests(nest_n)%wname = wvel_name
nests(nest_n)%densname = dens_name
nests(nest_n)%tempname = temp_name
nests(nest_n)%salnname = saln_name
nests(nest_n)%orthogrid = orthogrid

! check if fill value is the one used by getdata
Expand All @@ -142,10 +142,10 @@ SUBROUTINE getnestinfo(nest_n)
write(nestname,'(A,I0,A,I4.4,I2.2,I2.2,A)') &
trim(filenest)//'nest_',nest_n,'_',tstart_yy,tstart_mm,tstart_dd,'000000.nc'
call nc_open(trim(nestname),ncId)
call nc_info_dim2(nestname,ncId,1,nests(nest_n)%idm(1))
call nc_info_dim2(nestname,ncId,2,nests(nest_n)%jdm(1))
call nc_info_dim2(nestname,ncId,3,nests(nest_n)%kdm(1))
call nc_info_dim2(nestname,ncId,4,nests(nest_n)%tdm)
call nc_info_dim(nestname, ncId, xaxis, nests(nest_n)%idm(1))
call nc_info_dim(nestname, ncId, yaxis, nests(nest_n)%jdm(1))
call nc_info_dim(nestname, ncId, zaxis, nests(nest_n)%kdm(1))
call nc_info_dim(nestname, ncId, taxis, nests(nest_n)%tdm)
call nc_close(nestname, ncId)
else ! not agrid
allocate(nests(nest_n)%idm(4))
Expand Down Expand Up @@ -222,9 +222,9 @@ SUBROUTINE getnestinfo(nest_n)
if (agrid.eqv..true.) then
call nc_open(trim(nestname),ncId)
!read longitude
call nc_read1d(nestname, ncId,"Longitude", nests(nest_n)%lon(ax,1:nests(nest_n)%idm(ax),1), nests(nest_n)%idm(ax))
call nc_read1d(nestname, ncId,"Latitude", nests(nest_n)%lat(ax,1:nests(nest_n)%jdm(ax),1), nests(nest_n)%jdm(ax))
call nc_read1d(nestname, ncId,"Depth", nests(nest_n)%depth(ax,1:nests(nest_n)%kdm(ax)), nests(nest_n)%kdm(ax))
call nc_read1d(nestname, ncId, xaxis, nests(nest_n)%lon(ax,1:nests(nest_n)%idm(ax),1), nests(nest_n)%idm(ax))
call nc_read1d(nestname, ncId, yaxis, nests(nest_n)%lat(ax,1:nests(nest_n)%jdm(ax),1), nests(nest_n)%jdm(ax))
call nc_read1d(nestname, ncId, zaxis, nests(nest_n)%depth(ax,1:nests(nest_n)%kdm(ax)), nests(nest_n)%kdm(ax))
call nc_close(nestname, ncId)
else
if (AxUsed(ax) .eqv. .true.) then
Expand Down
16 changes: 9 additions & 7 deletions cms-master/src/getphysicaldata.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ SUBROUTINE getphysicaldata(time_t, basedate)
CALL getflnm(i,basedate,lc,fname)
ENDIF

! check if all the filenames exist
! check if all the filenames exist
nests(i)%dataExist = .true.
DO fileNumber = 1,numberFiles
INQUIRE(FILE=fname(UAx,fileNumber), EXIST=file_exists)
IF (file_exists .eqv. .false.) THEN
nests(i)%dataExist = .false.
ENDIF
ENDDO
do fileNumber = 1, numberFiles
inquire(file=fname(UAx, fileNumber), exist=file_exists)
if (.not. file_exists) then
nests(i)%dataExist = .false.
print *, "WARNING: File ", trim(fname(UAx, fileNumber)), &
" expected but not found."
end if
end do

! only read data from files if not done before
IF (nests(i)%fnameold .eq. "") THEN
Expand Down

0 comments on commit fb49138

Please sign in to comment.