#if (defined (INT8) || defined (ALL8)) #define NB_INTW 8 #else #define NB_INTW 4 #endif #if (defined (REA8) || defined (ALL8)) #define NB_REAW 8 #else #define NB_REAW 4 #endif #if (defined (DBL16) || defined (CRAY)) #define NB_DBLW 16 #else #define NB_DBLW 8 #endif c----------------------------------------------------- subroutine mem_alloc (p_tr, msize, key, object) c----------------------------------------------------- character*(*) object common /all_loc/ memory_used byte bte(1) integer int(1) real flt(1) double precision dbl(1) pointer (p_tr, tr), (p_flt, flt), (p_int, int), * (p_bte, bte), (p_dbl, dbl) if (msize .le. 0) * call perror1('mem_alloc: Wrong allocation request...Stop!',1) if (key .eq. 0) then !! 1-byte allocation mem_request = msize else if (key .eq. 1) then !! INTEGER allocation mem_request = msize * NB_INTW else if (key .eq. 2) then !! REAL allocation mem_request = msize * NB_REAW else if (key .eq. 3) then !! DOUBLE allocation mem_request = msize * NB_DBLW endif p_tr = malloc(mem_request) if (p_tr .eq. 0) then write (6, *) 'mem_alloc: Out of memory for <', object, '> !!!' stop endif if (key .eq. 0) then !! 1-byte allocation p_bte = p_tr do i = 1, msize bte(i) = char(0) enddo else if (key .eq. 1) then !! INTEGER allocation p_int = p_tr do i = 1, msize int(i) = 0 enddo else if (key .eq. 2) then !! REAL allocation p_flt = p_tr c x = sqrt(-1.) do i = 1, msize flt(i) = 0. c flt(i) = x c flt(i) = -987654321. enddo else if (key .eq. 3) then !! DOUBLE allocation p_dbl = p_tr do i = 1, msize dbl(i) = 0d0 enddo endif memory_used = memory_used + mem_request return end c------------------------------------------- subroutine mem_free (p_tr, msize, key) c------------------------------------------- pointer (p_tr, tr) common /all_loc/ memory_used if (p_tr .eq. 0) then write (6, *) 'mem_free: Invalid pointer...Stop!' stop endif call free(p_tr) if (key .eq. 0) then !! 1-byte allocation mem_request = msize else if (key .eq. 1) then !! INTERGER allocation mem_request = msize * NB_INTW else if (key .eq. 2) then !! REAL allocation mem_request = msize * NB_REAW else if (key .eq. 3) then !! DOUBLE allocation mem_request = msize * NB_DBLW endif memory_used = memory_used - mem_request return end c----------------------------------------------------------- subroutine mem_realloc (p_old, mold, mnew, mcopy, key) c----------------------------------------------------------- common /all_loc/ memory_used byte b1(1), b2(1) integer i1(1), i2(1) real f1(1), f2(1) double precision d1(1), d2(1) pointer (p_b1, b1), (p_i1, i1), (p_f1, f1), (p_d1, d1), * (p_b2, b2), (p_i2, i2), (p_f2, f2), (p_d2, d2), * (p_new, new), (p_old, old) mmin = min(mold, mnew) if (mmin .le. 0) * call perror1('mem_realloc: Wrong rallocation request...Stop!',1) if (key .eq. 0) then !! 1-byte allocation mem_request_new = mnew mem_request_old = mold else if (key .eq. 1) then !! INTERGER allocation mem_request_new = mnew * NB_INTW mem_request_old = mold * NB_INTW else if (key .eq. 2) then !! REAL allocation mem_request_new = mnew * NB_REAW mem_request_old = mold * NB_REAW else if (key .eq. 3) then !! DOUBLE allocation mem_request_new = mnew * NB_DBLW mem_request_old = mold * NB_DBLW endif p_new = malloc(mem_request_new) mmin = min(mmin, mcopy) if (key .eq. 0) then !! 1-byte allocation p_b1 = p_new p_b2 = p_old do i = 1, mmin b1(i) = b2(i) enddo else if (key .eq. 1) then !! INTERGER allocation p_i1 = p_new p_i2 = p_old do i = 1, mmin i1(i) = i2(i) enddo else if (key .eq. 2) then !! REAL allocation p_f1 = p_new p_f2 = p_old do i = 1, mmin f1(i) = f2(i) enddo else if (key .eq. 3) then !! DOUBLE allocation p_d1 = p_new p_d2 = p_old do i = 1, mmin d1(i) = d2(i) enddo endif call free(p_old) p_old = p_new memory_used = memory_used + mem_request_new - mem_request_old return end c--------------------------------------------------- function mem_get () c--------------------------------------------------- common /all_loc/ memory_used mem_get = memory_used return end c------------------------------------------------- subroutine model_memory (nx, ny, nz, npt) c------------------------------------------------- include 'comm_new.h' include 'comm_data.h' include 'comm_pbl.h' nptz = npt * nz mptz = npt * max(4,nz) nxy = nx*ny call mem_alloc (p_u, mptz, 2, 'u') call mem_alloc (p_uc, nptz, 2, 'uc') call mem_alloc (p_fu, nptz, 2, 'fu') call mem_alloc (p_um, nptz, 2, 'um') call mem_alloc (p_v, mptz, 2, 'v') call mem_alloc (p_vc, nptz, 2, 'vc') call mem_alloc (p_fv, nptz, 2, 'fv') call mem_alloc (p_vm, nptz, 2, 'vm') call mem_alloc (p_w, nptz, 2, 'w') call mem_alloc (p_wm, nptz, 2, 'wm') call mem_alloc (p_h, nptz, 2, 'h') call mem_alloc (p_fh, nptz, 2, 'fh') call mem_alloc (p_fhd, nptz, 2, 'fhd') call mem_alloc (p_hm, nptz, 2, 'hm') call mem_alloc (p_pgfx, nptz, 2, 'pgf_x') call mem_alloc (p_pgfy, nptz, 2, 'pgf_y') call mem_alloc (p_corx, nptz, 2, 'cor_x') call mem_alloc (p_cory, nptz, 2, 'cor_y') call mem_alloc (p_xnl, nptz, 2, 'nonlin_x') call mem_alloc (p_ynl, nptz, 2, 'nonlin_y') #ifdef dump_all call mem_alloc (p_vertx, nptz, 2, 'vert_x') call mem_alloc (p_verty, nptz, 2, 'vert_y') call mem_alloc (p_rhsx, nptz, 2, 'rhs_x') call mem_alloc (p_rhsy, nptz, 2, 'rhs_y') call mem_alloc (p_crhsx, nptz, 2, 'crhs_x') call mem_alloc (p_crhsy, nptz, 2, 'crhs_y') #endif call mem_alloc (p_t, nptz, 2, 'tem') call mem_alloc (p_ft, nptz, 2, 'ftem') call mem_alloc (p_tp, mptz, 2, 'tp') call mem_alloc (p_tm, nptz, 2, 'tm') call mem_alloc (p_convn, nptz, 2, 'convn') if (use_temp) then call mem_alloc (p_dens, nptz, 2, 'dens') call mem_alloc (p_densm, nptz, 2, 'densm') call mem_alloc (p_dclim, nptz, 2, 'dclim') call mem_alloc (p_hclim, 2*nptz, 2, 'hclim') call mem_alloc (p_tclim, 2*nptz, 2, 'tclim') endif if (use_salt) then call mem_alloc (p_sal, nptz, 2, 'sal') call mem_alloc (p_fsal, nptz, 2, 'fsal') call mem_alloc (p_salm, nptz, 2, 'salm') call mem_alloc (p_sss, 2*npt, 2, 'sss') call mem_alloc (p_ep, 3*npt, 2, 'ep') call mem_alloc (p_sclim, 2*nptz, 2, 'sclim') endif c 2D--------------------------------------------- if (use_trac) then call mem_alloc (p_tr, nptz*ntrac, 2, 'tr') call mem_alloc (p_ftr, nptz*ntrac, 2, 'ftr') call mem_alloc (p_trm, nptz*ntrac, 2, 'trm') endif call mem_alloc (p_relax, npt, 2, 'c_relax') call mem_alloc (p_f, npt, 2, 'f') call mem_alloc (p_emx, npt, 2, 'emx') call mem_alloc (p_emy, npt, 2, 'emy') call mem_alloc (p_emxy, npt, 2, 'emxy') call mem_alloc (p_emx2, npt, 2, 'emx2') call mem_alloc (p_emy2, npt, 2, 'emy2') call mem_alloc (p_taux, npt, 2, 'taux') call mem_alloc (p_tauy, npt, 2, 'tauy') call mem_alloc (p_area, npt, 2, 'area') call mem_alloc (p_q, npt, 2, 'q') call mem_alloc (p_qr, npt, 2, 'qr') call mem_alloc (p_qb, 5*npt, 2, 'qb') call mem_alloc (p_sst, 3*npt, 2, 'sst') call mem_alloc (p_cld, 3*npt, 2, 'cld') call mem_alloc (p_solr, 3*npt, 2, 'solr') call mem_alloc (p_dtx, 2*npt, 2, 'dtx') call mem_alloc (p_dty, 2*npt, 2, 'dty') call mem_alloc (p_dept, npt, 2, 'dept') call mem_alloc (p_ubar, npt, 2, 'ubar') call mem_alloc (p_vbar, npt, 2, 'vbar') call mem_alloc (p_uforc, npt, 2, 'uforc') call mem_alloc (p_vforc, npt, 2, 'vforc') call mem_alloc (p_psi, npt, 2, 'psi') call mem_alloc (p_zfu, npt, 2, 'zfu') call mem_alloc (p_zfv, npt, 2, 'zfv') call mem_alloc (p_bdiv, npt, 2, 'bdiv') call mem_alloc (p_xm, nx, 2, 'x') call mem_alloc (p_ym, ny, 2, 'y') call mem_alloc (p_xp, nx, 2, 'xp') call mem_alloc (p_yp, ny, 2, 'yp') call mem_alloc (p_hsave, nz+1, 2, 'hsave') call mem_alloc (p_isk, npt*nz, 1, 'isk') call mem_alloc (p_iyk, npt*nz, 1, 'iyk') call mem_alloc (p_isxk, npt*nz, 1, 'isyk') call mem_alloc (p_isyk, npt*nz, 1, 'isyk') call mem_alloc (p_nzi, npt, 1, 'nzi') call mem_alloc (p_nzi_b, npt, 1, 'nzi_b') if (initq .eq. 8) then call mem_alloc (p_wnsp, 2*npt, 2, 'wnsp') call mem_alloc (p_uwnd, 2*npt, 2, 'uwnd') call mem_alloc (p_vwnd, 2*npt, 2, 'vwnd') call mem_alloc (p_ahum, 3*nxy, 2, 'ahum') call mem_alloc (p_atem, 3*nxy, 2, 'atem') call mem_alloc (p_amhum, nxy, 2, 'amhum') call mem_alloc (p_amth, nxy, 2, 'amth') endif call mem_alloc (p_wint, nz*ny, 2, 'zonal ave w') call mem_alloc (p_psiw, (nz+1)*ny, 2, 'meridional sf') return end c-------------------------------------- subroutine datagrid_memory (tmp) c-------------------------------------- dimension tmp(1) include 'comm_new.h' include 'comm_data.h' call mem_alloc (p_xd, mxp, 2, 'xd') do i = 1, mxp xd(i) = tmp(i) enddo call mem_alloc (p_yd, myp, 2, 'yd') do i = 1, myp yd(i) = tmp(mxp+i) enddo c.....shift SEGMENTS array to begining of tmp do i = 1, mseg tmp(i) = tmp(mxp+myp+i) enddo call mem_alloc (p_ixd, mxp*myp, 1, 'ixd') call mem_alloc (p_im2d, npt2, 1, 'im2d') call mem_alloc (p_blcf, 4*npt2, 2, 'blcf') idatgr = 1 return end