Changeset 15016


Ignore:
Timestamp:
05/13/13 14:59:06 (12 years ago)
Author:
Eric.Larour
Message:

CHG: applying dynamic memory allocation

Location:
issm/trunk-jpl/src/c/modules/GiaDeflectionCorex
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/GiaDeflectionCorex/GiaDeflectionCorex.cpp

    r14999 r15016  
    1212#include "../InputUpdateFromConstantx/InputUpdateFromConstantx.h"
    1313
    14 #define Ntime 5 // number of times with load history
    15 #define Ntimm 4 // Ntime-1 : for slope/y-cept of load segments
    16 #define Ntimp 6 // Ntime+1 : for evaluation time 
    1714
    1815/*External blocks: {{{*/
     
    2017        double pset[7];
    2118};
    22 
    23 struct blockt{
    24         double time[Ntimp];
    25         double bi[Ntimm];
    26         double dmi[Ntimm];
    27 };
    28 
     19       
    2920struct blocko{
    3021        double rhoi;
    31         double hload[Ntime];
    32 };
    33 
    34 struct blocky{
    35         double zhload[Ntime];
    36 };
     22};
     23
    3724
    3825struct blockn{
     
    5138
    5239extern "C" {
    53         int distme_( int* pidisk,int* piedge);
     40        int distme_( int* pidisk,int* piedge, int* pNtime, int* pNtimp, int* pNtimm, int* pNafter,double* time,double* bi,double* dmi,double* zhload,double* hload);
     41
    5442        int what0_( int* pidisk,int* piedge);
    5543        extern struct blockp blockp_;
    56         extern struct blockt blockt_;
    5744        extern struct blocko blocko_;
    58         extern struct blocky blocky_;
    5945        extern struct blockn blockn_;
    6046        extern struct blockrad blockrad_;
     
    6551
    6652void GiaDeflectionCorex( IssmDouble* pwi, IssmDouble* pdwidt, GiaDeflectionCoreArgs* arguments){
     53
     54        /*intermediary: */
     55        int i;
    6756
    6857        /*output: */
     
    8776        int numtimes; //loading history length
    8877        IssmDouble currenttime;
     78        int Ntime=5; // number of times with load history
     79        int Ntimm;  // Ntime-1 : for slope/y-cept of load segments
     80        int Ntimp; // Ntime+1 : for evaluation time 
     81        int Nafter;
     82        IssmDouble* blockt_time=NULL;
     83        IssmDouble* blockt_bi=NULL;
     84        IssmDouble* blockt_dmi=NULL;
     85        IssmDouble* blocky_zhload=NULL;
     86        IssmDouble* blocko_hload=NULL;
    8987
    9088        /*gia material parameters: */
     
    128126        //from our model, irate comes in with values in [1,2], which maps into [0,1] in naruse:
    129127        irate=irate-1;
     128        Nafter=1;
     129        Ntime=numtimes;
     130        Ntimm=Ntime-1;
     131        Ntimp=Ntime+Nafter;
    130132
    131133        /*Prepare block inputs for fortran distme and what0 routines of the naruse code: {{{*/
     
    141143
    142144        /*loading history: */
    143         blocky_.zhload[0]=hes[0];
    144         blocky_.zhload[1]=hes[1];
    145         blocky_.zhload[2]=hes[2];
    146         blocky_.zhload[3]=hes[3];
    147         blocky_.zhload[4]=hes[numtimes-1];
     145        blocky_zhload=xNew<IssmDouble>(numtimes);
     146        for(i=0;i<numtimes;i++){
     147        blocky_zhload[i]=hes[i];
     148        }
    148149
    149150        /*times: */
    150         blockt_.time[0]=times[0]/1000.0/yts;    // in kyr
    151         blockt_.time[1]=times[1]/1000.0/yts;    // in kyr
    152         blockt_.time[2]=times[2]/1000.0/yts;    // in kyr
    153         blockt_.time[3]=times[3]/1000.0/yts;    // in kyr
    154         blockt_.time[4]=2500.0;                 // in kyr 
    155         blockt_.time[5]=times[numtimes-1]/1000.0/yts;  // evaluation time, in kyr
     151        blockt_time=xNew<IssmDouble>(numtimes+1);
     152        for (i=0;i<numtimes;i++){
     153                blockt_time[i]=times[i]/1000.0/yts; //in kyr
     154                if(i==numtimes-2)blockt_time[i]=2500.0;                 // in kyr 
     155        }
     156       
     157        /*bi: */
     158        blockt_bi=xNew<IssmDouble>(numtimes-1);
     159
     160        /*dmi: */
     161        blockt_dmi=xNew<IssmDouble>(numtimes-1);
     162       
     163        /*hload:*/
     164        blocko_hload=xNew<IssmDouble>(numtimes);
    156165
    157166        /*irate: */
     
    163172
    164173        /*Call distme driver: */
    165         distme_(&idisk,&iedge);
     174        distme_(&idisk,&iedge,&Ntime,&Ntimp,&Ntimm,&Nafter,blockt_time,blockt_bi,blockt_dmi,blocky_zhload,blocko_hload);
     175
    166176
    167177        /*Call what0 driver: */
     
    180190        }
    181191
     192        /*Free ressources: */
     193        xDelete<IssmDouble>(blockt_time);
     194        xDelete<IssmDouble>(blockt_bi);
     195        xDelete<IssmDouble>(blockt_dmi);
     196        xDelete<IssmDouble>(blocky_zhload);
     197        xDelete<IssmDouble>(blocko_hload);
     198
    182199}
     200     
  • issm/trunk-jpl/src/c/modules/GiaDeflectionCorex/distme.f

    r14835 r15016  
    1       subroutine distme(idisk,iedge)
     1      subroutine distme(idisk,iedge,Ntime,Ntimp,Ntimm,Nafter,time,bi,
     2     &dmi,zhload,hload)
    23      implicit double precision (a-h,o-y)
     4      integer idisk,iedge,Ntime,Ntimp,Ntimm,Nafter
    35      parameter (N3G = 1)
    4       parameter (Ntime = 5)
    5       parameter (Ntimm = Ntime-1)
    6       parameter (Nafter = 1)
    7       parameter (Ntimp = Ntime + Nafter)
    86      double precision pset(7)
    97      double precision time(Ntimp),dmi(Ntimm),bi(Ntimm),dumbt(Ntimp)
     
    1311      common /blockp/ pset
    1412      common /blockrad/ distrad
    15       common /blockt/ time,bi,dmi
    16       common /blocky/ zhload
    17       common /blocko/ rhoi,hload
     13      common /blocko/ rhoi
    1814      data g /9.832186d0/, yearco /3.15576d7/, eradm/6.371d6/
    1915      data dpi /3.1415926535897932d0/, dzero/0.0d0/
     
    2723  776 continue
    2824c      write(6,*) time(1), time(2), time(3)
    29 c      write(6,*) zhload(1), zhload(2), distrad, rhoi
    3025c      write(6,*) pset(1), pset(2), pset(3), pset(4), pset(5), pset(6)
    3126c      write(6,*) pset(7)
Note: See TracChangeset for help on using the changeset viewer.