fortran - forrtl: severe(151) allocatable array already allocated -
i have used code given in answer netcdf fortran array allocation @ run time run time error when run code
forrtl : severe(151) allocatable array allocated
when recompile -g
, -traceback
error traced line
allocate(lats(latlen))
can memory modified @ runtime? using fortran , compiler ifort
.
here code
integer retval,reason,i,in_ndim,ierr integer ncid, lat_dimid,lat_varid, latlen integer lon_varid,lonlen character*(*) lat_name, lon_name parameter (lat_name='lat', lon_name='lon') real lats[allocatable](:) real lons[allocatable](:) call system('ls hgt_*.nc > hgtfiles.txt') open(10,file='hgtfiles.txt',action="read") varname = "hgt" read(10,*,iostat=reason) in_cfn if (reason/=0) exit print *,in_cfn retval = nf_open(in_cfn,nf_nowrite,ncid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_inq_dimid(ncid,lat_name,lat_dimid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_inq_dimlen(ncid,lat_dimid,latlen) if (retval .ne. nf_noerr) call handle_err(retval) print *,latlen allocate(lats(latlen)) retval = nf_inq_varid(ncid,lat_name,lat_varid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_get_var_real(ncid,lat_varid,lats) if (retval .ne. nf_noerr) call handle_err(retval) print *,lats end close(10)
you allocating lats
inside loop. therefore, @ second iteration allocated , fails error got. have 2 options here:
- if dimensions not change throughout loop, pull allocation outside
- or re-allocate array inside loop. in simplest case, need put
deallocate(lats)
@ end of loop body.
Comments
Post a Comment