Welcome to the RAS Solution Forums HECRAS Controller Running HEC-RAS from a loop in MATLAB with different unsteady flow data

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8248
    Tcollings
    Participant

    Hi guys,

    I’m trying to run HEC-RAS with a load of different unsteady flow data. I’ve written a loop in matlab which edits the unsteady flow file for the current plan in HEC-RAS, and the program seems fine running the file outside of the loop.

    However, once I run HEC-RAS inside the loop (i.e. initiate a new instantance of HEC-RAS and open project file with current plan using the unsteady flow file that has just been edited), HEC-RAS doesn’t seem to read the newly edited unsteady flow file, but just runs using the original unsteady flow file from before the loop was started. I can’t work out how to get HEC-RAS to read the unsteady flow file that has just been edited by the loop.

    I would have thought that everytime HEC-RAS runs it re-reads the flow files, or at least re-reads them on reopening the project? Does anyone have any ideas? I’m hoping someone might have done this before.

    Cheers,

    Tom

    #13616
    Tcollings
    Participant

    I have managed to solve it.

    Matlab wasn’t waiting for HEC-RAS to run and so was closing the program almost immediately after opening it. By simply adding a pause(10) and making the loop pause for 10 seconds, matlab now gives hecras enough time to run before reading out the outputs and closing the program.

    Cheers,

    Tom

    #13617
    SILVIA HEREDIA
    Participant

    Hi Tcollings!! I read your post and think you can help me out a bit.
    I would like to make a code in Hec-Ras in order to multi-run several unsteady flow data. Can you give any advice about it? This is my first time doing it, so maybe some references will help.
    Thank you!!

    #13618
    Tcollings
    Participant

    Hi Silvia,

    Happy to help. I used this paper a lot as the basis of my code – http://www2.egr.uh.edu/~aleon3/papers_PDF/Journal/HEC_RAS_Controller.pdf

    Below is the loop I wrote complete the task. Feel free to get in touch if it needs more explaining.

    Cheers,

    Tom

    % outputs
    reach_in= [1,1,2,3]; % 1 = Upper, 2 =Saltash, 3 = Devonport
    Ri_St_in=[42,50,4,4];% 42 = 3905, 50 = 5018, 4 = 2526, 4 = 1251

    for ii = 1:5 % Tides
    disp(ii)
    for jj=1:7 % Surges
    for kk = 1:7 % Lag
    Tide_in=Tide(Lag(:,kk),ii)+(Surge(Lag(:,kk),jj).*Surge_cont(Lag(:,kk))’); % create stage boundary condition to rewrite HEC-RAS input file
    for pp = 1:192
    if Tide_in(pp) <0 %formatting the numbers to the correct format to paste into the input file
    Tide_in_str{pp}=num2str(Tide_in(pp),'%.5f');
    else
    Tide_in_str{pp}=num2str(Tide_in(pp),'%8f');
    end
    end
    Tide_in_str=string(Tide_in_str);
    % the code above here formulates the unsteady flow data to be
    % input in the hec-ras unsteady flow file

    filenameinput = ('C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary_TEMP.u15');
    filenameoutput = ('C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary.u15');
    copyfile(filenameoutput,filenameinput);
    fid = fopen(filenameinput, 'rt');
    fout = fopen (filenameoutput , 'wt');

    while ~feof(fid)
    strTextLine = fgetl(fid); %To read one additional line

    if strfind(strTextLine,'Stage Hydrograph= 192 ') % find line to enter new stage data below
    fprintf(fout,'%s\n',strTextLine);
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(1:10));
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(11:20));
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(21:30)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(31:40)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(41:50)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(51:60)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(61:70)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(71:80)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(81:90)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(91:100)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(101:110));
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(111:120));
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(121:130)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(131:140)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(141:150)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(151:160)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(161:170)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(171:180)) ;
    fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(181:190)) ;
    fprintf(fout,'%s%s',Tide_in_str(191:192)); %print in the new data line by line
    fseek(fid,1574,'cof'); % skip forward in the reading file to the next line below the old input data
    else
    fprintf(fout,'%s\n',strTextLine); % copy line into the new input file
    end
    end
    fclose(fid);
    fclose(fout);
    h=actxserver('RAS507.HECRASCONTROLLER'); %start hecras in the background
    h.Project_Open('C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary.prj'); %open project file
    h.Compute_HideComputationWindow;
    h.Plan_SetCurrent('Plan 24');
    h.Compute_CurrentPlan(0,0);
    pause(12) % pause necessary to allow Hec-ras time to run the model before matlab reads the output and closes it
    run_check(ii,jj,kk)=h.Compute_Complete() % checks if HEC-RAS has run - if 0, increases pause time

    for ll = 1:4
    for mm = 2:193
    z=h.Output_NodeOutput(2,reach_in(ll),Ri_St_in(ll),0,mm,2); %read output (WS elevation) for the 4 river stations
    WS_elv(mm-1,ll)=z; %save into mega matrix for processing and analysis
    end
    end
    h.Project_Save;
    h.Project_Close()
    h.QuitRas

    %WS_elv=run_hec();

    WS_El(:,:,ii,jj,kk)=WS_elv; %save into mega matrix for processing and analysis

    clear Tide_in
    clear z
    clear Tide_in_str

    end
    end
    end

    #13619
    SILVIA HEREDIA
    Participant

    Return-Path:
    Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
    by sloti1d2t14 (Cyrus 3.3.0-92-g11c785d-fm-20200721.004-g11c785d5) with LMTPA;
    Mon, 27 Jul 2020 23:17:56 -0400
    X-Cyrus-Session-Id: sloti1d2t14-1595906276-1019952-2-5338876426284943849
    X-Sieve: CMU Sieve 3.0
    X-Spam-known-sender: no
    X-Spam-sender-reputation: 500 (none)
    X-Spam-score: 0.1
    X-Spam-hits: FREEMAIL_FROM 0.001, HTML_MESSAGE 0.001, ME_SENDERREP_NEUTRAL 0.001,
    RCVD_IN_DNSWL_NONE -0.0001, RCVD_IN_MSPIKE_H2 -0.001,
    SPF_HELO_NONE 0.001, SPF_PASS -0.001, URI_HEX 0.1, LANGUAGES en,
    BAYES_USED none, SA_VERSION 3.4.2
    X-Spam-source: IP=’209.85.219.180′, Host=’mail-yb1-f180.google.com’, Country=’US’,
    FromHeader=’com’, MailFrom=’com’
    X-Spam-charsets: plain=’UTF-8′, html=’UTF-8′
    X-Resolved-to: [email protected]
    X-Delivered-to: [email protected]
    X-Mail-from: [email protected]
    Received: from mx3 ([10.202.2.202])
    by compute1.internal (LMTPProxy); Mon, 27 Jul 2020 23:17:56 -0400
    Received: from mx3.messagingengine.com (localhost [127.0.0.1])
    by mailmx.nyi.internal (Postfix) with ESMTP id 2249019600B1
    for ; Mon, 27 Jul 2020 23:17:56 -0400 (EDT)
    Received: from mx3.messagingengine.com (localhost [127.0.0.1])
    by mx3.messagingengine.com (Authentication Milter) with ESMTP
    id AEB48B635CB;
    Mon, 27 Jul 2020 23:17:56 -0400
    ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=fm3; t=
    1595906276; b=mTQy0P3umn3lz2nXmHdN6NZyAYzhJyE6hvZKUdfK2jl+Y71Di5
    f7KQUFGGhnJeWFiq6R8MpKv4JR2vWK9snTT+kGgdrywQnSCM8sWzj9qRqxEUdyQC
    hABzG8RKSJuCb1BaF2e/lKsZGlCX6kLf5wJOJG13xUCkZ326SkBhRMaZFL6Pvyx4
    rwj+Ec3mZcX5PWZ8WiQf0tyuiJ8FmNTIJQsyebiK5StD6WeEgbRLErIN2XPA4R+6
    ycmiP8xCXrepHoAXo2rGK6dzU4fccqXuXw63CFzsTI9uCeMmFS2i99WKK61xqPAT
    tqiOvq7bRpSLGrMvxd6tGHey5ma22Fpg3N3A==
    ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=
    messagingengine.com; h=mime-version:references:in-reply-to:from
    :date:message-id:subject:to:content-type; s=fm3; t=1595906276;
    bh=lifb6gmNEEZ5vT5/Sj8oCrkjqr1qTrUgcGyObb3KgSM=; b=JYY7Q2bIlriy
    EA9kLgFvSSZC8HdpnC8OmlvQZsTGz/4mD1LzWJsRhYDBVyjsg+tdnOoE1BhyqEjW
    XK25O8cgkfN94UWUAUHGyQ8+GB2EVTKUlBpl2v6JWzyP22K00fyYvzVkUj+GlPuE
    Phh/+6rRrSJl8wsnukUs5DGzi/hwAffZlhFSraVSL1/LCezm4rVkeVoTBzt6FN/5
    YD+oPedCR0hsdtBycJ+S5t0XLtU4n8SmcrFqt1jQPk3LesNWZSmC+MQ/CDHQtTIp
    kTTGTCcAxgFVqPBFF+yIUzUi8vajWPIwBl/yTGmuCsCncIszXblfNy3SYhVJoS80
    185KZy49nQ==
    ARC-Authentication-Results: i=1; mx3.messagingengine.com; arc=none (no signatures found);
    bimi=none (Domain is not BIMI enabled);
    dkim=pass (2048-bit rsa key sha256) header.d=gmail.com
    [email protected] header.b=HPBdO79/ header.a=rsa-sha256
    header.s=20161025 x-bits=2048;
    dmarc=pass policy.published-domain-policy=none
    policy.published-subdomain-policy=quarantine
    policy.applied-disposition=none policy.evaluated-disposition=none
    (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p
    header.from=gmail.com;
    iprev=pass smtp.remote-ip=209.85.219.180 (mail-yb1-f180.google.com);
    spf=pass [email protected]
    smtp.helo=mail-yb1-f180.google.com;
    x-aligned-from=pass (Address match);
    x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net
    [email protected] header.b=szZ4jFfx;
    x-ptr=pass smtp.helo=mail-yb1-f180.google.com
    policy.ptr=mail-yb1-f180.google.com;
    x-return-mx=pass header.domain=gmail.com policy.is_org=yes
    (MX Records found: alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com);
    x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes
    (MX Records found: alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com);
    x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES128-GCM-SHA256
    smtp.bits=128/128;
    x-vs=clean score=0 state=0
    Authentication-Results: mx3.messagingengine.com;
    arc=none (no signatures found);
    bimi=none (Domain is not BIMI enabled);
    dkim=pass (2048-bit rsa key sha256) header.d=gmail.com
    [email protected] header.b=HPBdO79/ header.a=rsa-sha256
    header.s=20161025 x-bits=2048;
    dmarc=pass policy.published-domain-policy=none
    policy.published-subdomain-policy=quarantine
    policy.applied-disposition=none policy.evaluated-disposition=none
    (p=none,sp=quarantine,d=none,d.eval=none) policy.policy-from=p
    header.from=gmail.com;
    iprev=pass smtp.remote-ip=209.85.219.180 (mail-yb1-f180.google.com);
    spf=pass [email protected]
    smtp.helo=mail-yb1-f180.google.com;
    x-aligned-from=pass (Address match);
    x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net
    [email protected] header.b=szZ4jFfx;
    x-ptr=pass smtp.helo=mail-yb1-f180.google.com
    policy.ptr=mail-yb1-f180.google.com;
    x-return-mx=pass header.domain=gmail.com policy.is_org=yes
    (MX Records found: alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com);
    x-return-mx=pass smtp.domain=gmail.com policy.is_org=yes
    (MX Records found: alt1.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com);
    x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES128-GCM-SHA256
    smtp.bits=128/128;
    x-vs=clean score=0 state=0
    X-ME-VSSU: VW5zdWI9aHR0cDovL2hlYy1yYXMtaGVscC4xMDkxMTEyLm41Lm5hYmJsZS5jb20vdGVtcG
    xhdGUvTmFtbFNlcnZsZXQuanRwP21hY3JvPXVuc3Vic2NyaWJlX2J5X2NvZGUmbm9kZT05
    MDA4JmNvZGU9YzJsc2RtbGhhR1Z5WldScFlXeGhRR2R0WVdsc0xtTnZiWHc1TURBNGZDMD
    BOek01TVRRMU5UZz0
    X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgeduiedriedugdeikecutefuodetggdotefrodftvf
    curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr
    tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepgghfjgfhff
    fkuffvtgesrgdtreertddtjeenucfhrhhomhepufhilhhvihgrucffihgrnhgrucfjvghr
    vgguihgrucfnrghrrgcuoehsihhlvhhirghhvghrvgguihgrlhgrsehgmhgrihhlrdgtoh
    hmqeenucggtffrrghtthgvrhhnpeeigfegveegveetudevfedtlefhveduieevveeijeev
    ieehtdegfeeuieffvdfgteenucffohhmrghinhepuhhhrdgvughupdhnrggssghlvgdrtg
    homhenucfkphepvddtledrkeehrddvudelrddukedtnecuvehluhhsthgvrhfuihiivgep
    tdenucfrrghrrghmpehinhgvthepvddtledrkeehrddvudelrddukedtpdhhvghlohepmh
    grihhlqdihsgduqdhfudektddrghhoohhglhgvrdgtohhmpdhmrghilhhfrhhomhepoehs
    ihhlvhhirghhvghrvgguihgrlhgrsehgmhgrihhlrdgtohhmqecuuffkkgfgpedvuddtie
    du
    X-ME-VSScore: 0
    X-ME-VSCategory: clean
    Received-SPF: pass
    (gmail.com … _spf.google.com: Sender is authorized to use ‘[email protected]’ in ‘mfrom’ identity (mechanism ‘include:_netblocks.google.com’ matched))
    receiver=mx3.messagingengine.com;
    identity=mailfrom;
    envelope-from=”[email protected]”;
    helo=mail-yb1-f180.google.com;
    client-ip=209.85.219.180
    Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180])
    (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
    (No client certificate requested)
    by mx3.messagingengine.com (Postfix) with ESMTPS
    for ; Mon, 27 Jul 2020 23:17:55 -0400 (EDT)
    Received: by mail-yb1-f180.google.com with SMTP id 133so9863647ybu.7
    for ; Mon, 27 Jul 2020 20:17:55 -0700 (PDT)
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=gmail.com; s=20161025;
    h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
    bh=lifb6gmNEEZ5vT5/Sj8oCrkjqr1qTrUgcGyObb3KgSM=;
    b=HPBdO79/aVMZbdiSBErzZnoO2mWLdNTOEPmjWM9HB+DJXJ059ZUaTMteLfa/ORNujk
    +3Wxl8zsDJMb1QSmVLw3fNI208DevOnUW4vvyyx0Rm0DQSbWox51Dp2s3vV8V8HtYMV8
    HH2L4D96vtWmOHAczTpRecy3IE/pHs1PiOk/LamrY5kvRAHbu1jJTgEBY5rcjtSVV7rZ
    1QmTIRTANWaphej2M0bUciObnFSHcO8HV9gcDn8BVXEmBqkgMZcFfcuIGus0RkTuWHE9
    dwaQgPlnr26iBoGirf0PIoBpYapRQohrMGTRXXzdeo61gNQumxyrCIU4WUJtwmJUOwRW
    jQSg==
    X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=1e100.net; s=20161025;
    h=x-gm-message-state:mime-version:references:in-reply-to:from:date
    :message-id:subject:to;
    bh=lifb6gmNEEZ5vT5/Sj8oCrkjqr1qTrUgcGyObb3KgSM=;
    b=szZ4jFfxBBSdPOtsP77dmorD1+Qdq+l5MZP/u+N5B/tZSDgndz1KxH99QjljIs37dj
    pwEwXOH6xqJ1PVem2qZHDONrzRxsopAy18jRq0V59xtw/EvZ0kAdGXB8yehaIsm3i+Dw
    5tBs5j5117gCZv7eCK1DEGpEwqbN2ccupdtaM9qJO9Wp/AWR3W/sGxLEFWkgGl+X5EdR
    xJofJEfgHeBw3CSj6qjiFn98rEvPmDxpWQE165eZLMAszbWTTyvqk5I2V+7DBaVcvgIQ
    DrDdOtNjMxodFPi1wK/PbqtDrkutmnouBcw4MK2D6dCgsKlcMgWbHA3rsUSfgoWwajdT
    5hHg==
    X-Gm-Message-State: AOAM530ZOLDh6/DnA8TyEO8D3IaY23v6oWeoQKCfHbF35svoFWTJUVMl
    pC/L3TpEKxLBYfitclSecosbP4gG1y4Q+zeC7wgqBsyy
    X-Google-Smtp-Source: ABdhPJykclXwPqkjYM53vyLDsfYTn6om+g0/jUqgrB0/hA7b7xfxi34+ET+BLndXl5uXxjJM9GcYghKtYbZOGbytVBo=
    X-Received: by 2002:a25:328e:: with SMTP id y136mr1042576yby.281.1595906274016;
    Mon, 27 Jul 2020 20:17:54 -0700 (PDT)
    MIME-Version: 1.0
    References: <[email protected]> <[email protected]>
    <[email protected]> <[email protected]>
    In-Reply-To: <[email protected]>
    From: Silvia Diana Heredia Lara
    Date: Mon, 27 Jul 2020 22:17:42 -0500
    Message-ID:
    Subject: Re: Running HEC-RAS from a loop in MATLAB with different unsteady
    flow data
    To: “Tcollings [via HEC-RAS Help]”
    Content-Type: multipart/alternative; boundary=”0000000000008ebedc05ab77e2f5″

    –0000000000008ebedc05ab77e2f5
    Content-Type: text/plain; charset=”UTF-8″
    Content-Transfer-Encoding: quoted-printable

    Thank you so much for your help! you’ll hear from me soon.
    Wish me luck !!

    Silvia

    El lun., 27 jul. 2020 a las 2:52, Tcollings [via HEC-RAS Help] (< [email protected]>) escribi=C3=B3:

    > Hi Silvia,
    >
    > Happy to help. I used this paper a lot as the basis of my code –
    > http://www2.egr.uh.edu/~aleon3/papers_PDF/Journal/HEC_RAS_Controller.pdf
    >
    > Below is the loop I wrote complete the task. Feel free to get in touch if
    > it needs more explaining.
    >
    > Cheers,
    >
    > Tom
    >
    >
    > % outputs
    > reach_in=3D [1,1,2,3]; % 1 =3D Upper, 2 =3DSaltash, 3 =3D Devonport
    > Ri_St_in=3D[42,50,4,4];% 42 =3D 3905, 50 =3D 5018, 4 =3D 2526, 4 =3D 1251
    >
    >
    >
    > for ii =3D 1:5 % Tides
    > disp(ii)
    > for jj=3D1:7 % Surges
    > for kk =3D 1:7 % Lag
    >
    > Tide_in=3DTide(Lag(:,kk),ii)+(Surge(Lag(:,kk),jj).*Surge_cont(Lag(:,kk))’=
    ); %
    > create stage boundary condition to rewrite HEC-RAS input file
    > for pp =3D 1:192
    > if Tide_in(pp) <0 %formatting the numbers to the correct
    > format to paste into the input file
    > Tide_in_str{pp}=3Dnum2str(Tide_in(pp),’%.5f’);
    > else
    > Tide_in_str{pp}=3Dnum2str(Tide_in(pp),’%8f’);
    > end
    > end
    > Tide_in_str=3Dstring(Tide_in_str);
    > % the code above here formulates the unsteady flow data to be
    > % input in the hec-ras unsteady flow file
    >
    >
    > filenameinput =3D
    > (‘C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary_TEMP.u15’);
    > filenameoutput =3D
    > (‘C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary.u15’);
    > copyfile(filenameoutput,filenameinput);
    > fid =3D fopen(filenameinput, ‘rt’);
    > fout =3D fopen (filenameoutput , ‘wt’);
    >
    > while ~feof(fid)
    > strTextLine =3D fgetl(fid); %To read one additional line
    >
    > if strfind(strTextLine,’Stage Hydrograph=3D 192 ‘) % find
    > line to enter new stage data below
    > fprintf(fout,’%s\n’,strTextLine);
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(1:10));
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(11:20));
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(21:30)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(31:40)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(41:50)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(51:60)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(61:70)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(71:80)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(81:90)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(91:100)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(101:110));
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(111:120));
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(121:130)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(131:140)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(141:150)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(151:160)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(161:170)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(171:180)) ;
    >
    > fprintf(fout,’%s%s%s%s%s%s%s%s%s%s\n’,Tide_in_str(181:190)) ;
    > fprintf(fout,’%s%s’,Tide_in_str(191:192)); %print in
    > the new data line by line
    > fseek(fid,1574,’cof’); % skip forward in the reading
    > file to the next line below the old input data
    > else
    > fprintf(fout,’%s\n’,strTextLine); % copy line into th=
    e
    > new input file
    > end
    > end
    > fclose(fid);
    > fclose(fout);
    > h=3Dactxserver(‘RAS507.HECRASCONTROLLER’); %start hecras in t=
    he
    > background
    >
    > h.Project_Open(‘C:\Users\Tom\Documents\HECRAS\TamarTavyEstuary.prj’); %op=
    en
    > project file
    > h.Compute_HideComputationWindow;
    > h.Plan_SetCurrent(‘Plan 24’);
    > h.Compute_CurrentPlan(0,0);
    > pause(12) % pause necessary to allow Hec-ras time to run the
    > model before matlab reads the output and closes it
    > run_check(ii,jj,kk)=3Dh.Compute_Complete() % checks if HEC-RA=
    S
    > has run – if 0, increases pause time
    >
    >
    >
    > for ll =3D 1:4
    > for mm =3D 2:193
    >
    > z=3Dh.Output_NodeOutput(2,reach_in(ll),Ri_St_in(ll),0,mm,2); %read output=
    (WS
    > elevation) for the 4 river stations
    > WS_elv(mm-1,ll)=3Dz; %save into mega matrix for
    > processing and analysis
    > end
    > end
    > h.Project_Save;
    > h.Project_Close()
    > h.QuitRas
    >
    >
    > %WS_elv=3Drun_hec();
    >
    > WS_El(:,:,ii,jj,kk)=3DWS_elv; %save into mega matrix for
    > processing and analysis
    >
    > clear Tide_in
    > clear z
    > clear Tide_in_str
    >
    >
    >
    > end
    > end
    > end
    >
    > ——————————
    > If you reply to this email, your message will be added to the discussion
    > below:
    >
    > http://hec-ras-help.1091112.n5.nabble.com/Running-HEC-RAS-from-a-loop-in-=
    MATLAB-with-different-unsteady-flow-data-tp9008p9057.html
    > To unsubscribe from Running HEC-RAS from a loop in MATLAB with different
    > unsteady flow data, click here
    > <http://hec-ras-help.1091112.n5.nabble.com/template/NamlServlet.jtp?macro=
    =3Dunsubscribe_by_code&node=3D9008&code=3Dc2lsdmlhaGVyZWRpYWxhQGdtYWlsLmNvb=
    Xw5MDA4fC00NzM5MTQ1NTg=3D>
    > .
    > NAML
    > <http://hec-ras-help.1091112.n5.nabble.com/template/NamlServlet.jtp?macro=
    =3Dmacro_viewer&id=3Dinstant_html%21nabble%3Aemail.naml&base=3Dnabble.naml.=
    namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.v=
    iew.web.template.NodeNamespace&breadcrumbs=3Dnotify_subscribers%21nabble%3A=
    email.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble=
    %3Aemail.naml>
    >

    –=20
    *M.C. Silvia Diana Heredia Lara*
    +52 999 412 5499
    *”Water is the driving force of all nature”*

    –0000000000008ebedc05ab77e2f5
    Content-Type: text/html; charset=”UTF-8″
    Content-Transfer-Encoding: quoted-printable

    Thank you so much for your help! you'll hear from me s=
    oon.

    Wish me luck !!
    =C2=A0
    Silvia

    =

    =
    El lun., 27 jul. 2020 a las 2:52, Tcollings [via HEC-RAS Help] (<[email protected]=
    le.com
    >) escribi=C3=B3:
    tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad= ding-left:1ex">

    Hi Silvia,=20

    Happy to help. I used this paper a lot as the basis of my code – http://www2.egr.uh.edu/~aleon3/p=
    apers_PDF/Journal/HEC_RAS_Controller.pdf=C2=A0

    Below is the loop I wrote complete the task. Feel free to get in to=
    uch if it needs more explaining.

    Cheers,

    Tom

    % outputs

    reach_in=3D [1,1,2,3]; % 1 =3D Upper, 2 =3DSaltash, 3 =3D Devonport

    Ri_St_in=3D[42,50,4,4];% 42 =3D 3905, 50 =3D 5018, 4 =3D 2526, 4 =3D 12=
    51

    for ii =3D 1:5 % Tides

    =C2=A0 =C2=A0 disp(ii)

    =C2=A0 =C2=A0 for jj=3D1:7 % Surges

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 for kk =3D 1:7 % Lag

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Tide_in=3DTide(Lag(:,kk),ii)+=
    (Surge(Lag(:,kk),jj).*Surge_cont(Lag(:,kk))'); % create stage boundary =
    condition to rewrite HEC-RAS input file

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for pp =3D 1:192

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if Tide_in(pp) &=
    lt;0 %formatting the numbers to the correct format to paste into the input =
    file

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ti=
    de_in_str{pp}=3Dnum2str(Tide_in(pp),'%.5f');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ti=
    de_in_str{pp}=3Dnum2str(Tide_in(pp),'%8f');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Tide_in_str=3Dstring(Tide_in_=
    str);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 % the code above here formula=
    tes the unsteady flow data to be

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 % input in the hec-ras unstea=
    dy flow file

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filenameinput =3D ('C:\Us=
    ers\Tom\Documents\HECRAS\TamarTavyEstuary_TEMP.u15');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filenameoutput =3D ('C:\U=
    sers\Tom\Documents\HECRAS\TamarTavyEstuary.u15');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 copyfile(filenameoutput,filen=
    ameinput);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fid =3D fopen(filenameinput, =
    'rt');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fout =3D fopen (filenameoutpu=
    t , 'wt');

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 while ~feof(fid)

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 strTextLine =3D=
    fgetl(fid); %To read one additional line

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if strfind(=
    strTextLine,'Stage Hydrograph=3D 192 ') % find line to enter new st=
    age data below

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s\n',strTextLine);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(1:10));

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(11:20));=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(21:30)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(31:40)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(41:50)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(51:60)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(61:70)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(71:80)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(81:90)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(91:100)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(101:110));

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(111:120));

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(121:130)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(131:140)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(141:150)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(151:160)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(161:170)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(171:180)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s%s%s%s%s%s%s%s%s\n',Tide_in_str(181:190)) ;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fprintf(fout,'%s%s',Tide_in_str(191:192)); %print in the new =
    data line by line

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
    =C2=A0fseek(fid,1574,'cof'); % skip forward in the reading file to =
    the next line below the old input data

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 f=
    printf(fout,'%s\n',strTextLine); % copy line into the new input fil=
    e

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fclose(fid);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fclose(fout);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h=3Dactxserver('RAS507.HE=
    CRASCONTROLLER'); %start hecras in the background

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Project_Open('C:\Users\=
    Tom\Documents\HECRAS\TamarTavyEstuary.prj'); %open project file

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Compute_HideComputationWind=
    ow;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Plan_SetCurrent('Plan 2=
    4');=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Compute_CurrentPlan(0,0);

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pause(12) % pause necessary t=
    o allow Hec-ras time to run the model before matlab =C2=A0reads the output =
    and closes it

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 run_check(ii,jj,kk)=3Dh.Compu=
    te_Complete() % checks if HEC-RAS has run – =C2=A0if 0, increases pause tim=
    e

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for ll =C2=A0=3D =
    1:4

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for mm =3D 2:19=
    3

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 z=
    =3Dh.Output_NodeOutput(2,reach_in(ll),Ri_St_in(ll),0,mm,2); %read output (W=
    S elevation) for the 4 river stations=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 W=
    S_elv(mm-1,ll)=3Dz; %save into mega matrix for processing and analysis

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Project_Save;

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.Project_Close()

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 h.QuitRas

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 %WS_elv=3Drun_hec();

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 WS_El(:,:,ii,jj,kk)=3DWS_elv;=
    %save into mega matrix for processing and analysis

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clear Tide_in

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clear z

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clear Tide_in_str

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=20

    =C2=A0 =C2=A0 =C2=A0 =C2=A0 end=20

    =C2=A0 =C2=A0 end=20

    end=20

    =09
    =09
    =09



    =09
    To unsubscribe from Running HEC-RAS from a loop in MATLAB with different =
    unsteady flow data, click here.
    NAML


    <= div style=3D"text-align:center">M.C. Silvia Diana Heredia Lara
    +52 999 412 5499
    "Water is the driving force of all nature=
    "

    –0000000000008ebedc05ab77e2f5–

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.