# Passing variable to filepath in u-al752 suite

**URL:** <https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946>\
**Category:** Rose/Cylc and FCM\
**Created:** [13 March 2023 22:20 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946 "2023-03-13T22:20:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalie](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@Natalie](https://cms-helpdesk.ncas.ac.uk/u/Natalie)\
**Post date:** [13 March 2023 22:20 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/1 "2023-03-13T22:20:06Z")

</div>

Hi all,  
I am working with my own version of the u-al752 suite and would like to run JULES over a loop passing **site** as a variable in place of **LBA\_K34** in the code below:

{% import “numpy” as np %}  
{%- for **site** in site\_info %}  
…  
#SET MAIN & SPINUP SITE-SPECIFIC ENVIRONMENTS  
[[jules\_{{ site|lower }}\_presc{{ PRESCRIBE\_DATASETS\_CONFIGURATION }}_post]]  
inherit = JULES\_POST  
{% set xa=np.load('/home/users/ndouglas/roses/u-cu756/bin/da\_files/xa_ **LBA\_K34**.npy’) %}  
[[[environment]]]  
…  
ALPHA = {{ xa[0] }}  
NEFF = {{ xa[1] }}

Does anybody have experience of this or know where I can look for notes on how to do it?  
Many thanks,  
Natalie

---

<div class="post-metadata">

**Author:** ![pmcguire](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pmcguire](https://cms-helpdesk.ncas.ac.uk/u/pmcguire)\
**Post date:** [14 March 2023 11:42 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/2 "2023-03-14T11:42:24Z")

</div>

Hi Natalie  
Can you replace LBA\_K34 with {{ site }} in your site loop? Have you tried that already?  
Patrick

---

<div class="post-metadata">

**Author:** ![Natalie](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@Natalie](https://cms-helpdesk.ncas.ac.uk/u/Natalie)\
**Post date:** [14 March 2023 12:59 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/3 "2023-03-14T12:59:16Z")

</div>

Hi Patrick,  
Yes I did and got this error:

 ![Screenshot 2023-03-14 at 12.57.42](https://europe1.discourse-cdn.com/flex013/uploads/cms_support/original/1X/6dc19bd3e7d56d86ea9ce2502bd6267c9582c8d2.png)

Thanks,  
Natalie

---

<div class="post-metadata">

**Author:** ![pmcguire](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pmcguire](https://cms-helpdesk.ncas.ac.uk/u/pmcguire)\
**Post date:** [14 March 2023 15:16 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/4 "2023-03-14T15:16:49Z")

</div>

Hi Natalie:  
Maybe you can concatenate the 3 substrings with the + operator? Does that make sense?  
Patrick

---

<div class="post-metadata">

**Author:** ![Natalie](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@Natalie](https://cms-helpdesk.ncas.ac.uk/u/Natalie)\
**Post date:** [14 March 2023 15:55 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/5 "2023-03-14T15:55:52Z")

</div>

Hi Patrick,  
Yes, I tried: {% set xa=np.load(‘/home/users/ndouglas/roses/u-cu756/bin/da\_files/xa\_’+{{ site }}+‘.npy’) %} with error:

 ![Screenshot 2023-03-14 at 15.51.05](https://europe1.discourse-cdn.com/flex013/uploads/cms_support/original/1X/ae609e8e1bdf15bc269353dbe8a68422dcbc21e0.png)  
and {% set xa=np.load(‘/home/users/ndouglas/roses/u-cu756/bin/da\_files/xa\_’{{ site }}‘.npy’) %} with similar error:  
 ![Screenshot 2023-03-14 at 15.52.12](https://europe1.discourse-cdn.com/flex013/uploads/cms_support/original/1X/bd92d787bb750aa1f496b3868b23f990dcd72544.png)

The mind boggles.  
Natalie

---

<div class="post-metadata">

**Author:** ![pmcguire](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pmcguire](https://cms-helpdesk.ncas.ac.uk/u/pmcguire)\
**Post date:** [14 March 2023 16:39 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/6 "2023-03-14T16:39:57Z")

</div>

Hi Natalie:  
Have you tried something like this?:  
{% set filename=‘/home/users/ndouglas/roses/u-cu756/bin/da\_files/xa\_’+{{ site }}+‘.npy’  
set xa=np.load(filename) %}  
Patrick

---

<div class="post-metadata">

**Author:** ![pmcguire](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pmcguire](https://cms-helpdesk.ncas.ac.uk/u/pmcguire)\
**Post date:** [14 March 2023 16:48 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/7 "2023-03-14T16:48:24Z")

</div>

Hi again Natalie  
You might also need spaces before and after the + sign. And you can also write a short jinja program to test the syntax, which can be called from the command line of linux.  
Patrick

---

<div class="post-metadata">

**Author:** ![Natalie](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@Natalie](https://cms-helpdesk.ncas.ac.uk/u/Natalie)\
**Post date:** [15 March 2023 10:10 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/8 "2023-03-15T10:10:00Z")

</div>

Hi Patrick,  
Thanks for all your help. Removing the curly braces seems to have worked:  
{% set filename=‘/home/users/ndouglas/roses/u-cu756/bin/da\_files/xa\_’ + site + ‘.npy’ %}  
{% set xa=np.load(filename) %}

Can you see any hidden problems that might arise from doing this?

Thanks,  
Natalie

---

<div class="post-metadata">

**Author:** ![pmcguire](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@pmcguire](https://cms-helpdesk.ncas.ac.uk/u/pmcguire)\
**Post date:** [15 March 2023 10:31 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/9 "2023-03-15T10:31:27Z")

</div>

Hi Natalie  
I am glad it works now.  
I don’t see any hidden problems with that.  
Did you also need to use spaces around the + signs?  
Patrick

---

<div class="post-metadata">

**Author:** ![Natalie](https://avatars.discourse-cdn.com/v4/letter/n/e9c0ed/32.png) [@Natalie](https://cms-helpdesk.ncas.ac.uk/u/Natalie)\
**Post date:** [15 March 2023 17:44 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/10 "2023-03-15T17:44:14Z")

</div>

Hi Patrick,  
It seems to work both with and without the spaces. Thanks!  
Natalie

---

<div class="post-metadata">

**Author:** ![RosalynHatcher](https://dub1.discourse-cdn.com/flex013/user_avatar/cms-helpdesk.ncas.ac.uk/rosalynhatcher/32/11_2.png) [@RosalynHatcher](https://cms-helpdesk.ncas.ac.uk/u/RosalynHatcher)\
**Post date:** [19 May 2023 15:00 UTC](https://cms-helpdesk.ncas.ac.uk/t/passing-variable-to-filepath-in-u-al752-suite/946/11 "2023-05-19T15:00:19Z")

</div>

Closed on 19 May 2023 15:00 UTC


