# Batch script for M3WNDW or BCWNDW

**URL:** <https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485>\
**Category:** m3tools\
**Created:** [May 8, 2020, 7:43pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485 "2020-05-08T19:43:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsanzine](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@nsanzine](https://forum.cmascenter.org/u/nsanzine)\
**Post date:** [May 8, 2020, 7:43pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/1 "2020-05-08T19:43:13Z")

</div>

I am looking for a sample batch script I can use to execute m3wndw and bcwndw. I am not sure what is the structure to use to provide the input file, output file and the grid domain bounds. I can run the program using the command prompt, but it’s tedious for regridding files for an entire year.

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [May 8, 2020, 9:06pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/2 "2020-05-08T21:06:29Z")

</div>

Copy down what all the responses were for _m3wndw_ (for example), and then use them to construct  
an command-file to use with it: Something like:

```
    set cmd = /tmp/m3wndw.$$
    echo "Yes continue with program " >& $cmd
    echo "INFILE" >> $cmd
    echo "$SDATE" >> $cmd
    echo "$STIME" >> $cmd
    echo " " >> $cmd # default RUNLEN
   ...etc ...
    m3wndw < $cmd
```

---

<div class="post-metadata">

**Author:** ![nsanzine](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@nsanzine](https://forum.cmascenter.org/u/nsanzine)\
**Post date:** [May 11, 2020, 3:16pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/3 "2020-05-11T15:16:42Z")

</div>

Can you please explain what the first line mean? specifically the double dollar sign?  
This is mu run script  
#!/bin/csh -f  
#This script window out the southwest US data from 12US1 domain  
#12US1 domain : 459 col by 299 row and origin of -2556 and -1728  
#ADEQ\_12PHX : 154 col by 110 row and origin of -2256 and -996

setenv infile /CAMData/CMAQ/2016\_12US1/emis/cmaq\_ready/emis\_mole\_all\_20160603\_12US1\_nobeis\_2016ff\_16j.ncf  
setenv outfile /CAMData/CMAQ/2016\_12US1/emis/cmaq\_ready/emis\_mole\_all\_20160603\_ADEQ\_12PHX\_nobeis\_2016ff\_16j.ncf  
set cmd = /CAMData/CMAQ/Libraries/ioapi-3.2/ioapi/lib/m3wndw.$$  
echo “$infile” \>&$cmd  
echo “$outfile” \>\>$cmd  
echo “2016155” \>\>$cmd  
echo “000000” \>\>$cmd  
echo “240000” \>\>$cmd  
echo “ADEQ\_12PHX” \>\>$cmd  
echo “26” \>\>$cmd  
echo “179” \>\>$cmd  
echo “62” \>\>$cmd  
echo “171” \>\>$cmd

/CAMData/CMAQ/Libraries/ioapi-3.2/ioapi/lib/m3wndw \< $cmd

When I run it I get:  
/CAMData/CMAQ/Libraries/ioapi-3.2/ioapi/lib/m3wndw.17550: Permission denied.

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [May 11, 2020, 3:48pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/4 "2020-05-11T15:48:46Z")

</div>

Normally that should be _/tmp/m3wndw.$$_ (or similarly).

This is the standard UNIX/Linux way of safely creating a scratch-file: _$$_ is the built-in shell-variable for the current-shell process-ID (which is unique on the entire system you’re running on), so that (short of malice), no other file on the system should have that name, and so no-one should accidentally corrupt or clobber that scratch-file.

FWIW, lots of people who should know better fail to do this and create brittle systems as a result. Cisco’s _anyconnect_ VPN-client is an example of such a failure. So you should not feel bad about not having been taught this…

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 11, 2021, 8:45pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/5 "2021-06-11T20:45:56Z")

</div>

Hy,

I’m not sure how to run m3wndw. I’ve tried to follow the guidelines but my terminal showing command not found. Please see the attached file.

Can you please let me know how to use this tool? I’m trying to use _m3wndw_ to window the emissions files to the grid of a smaller domain.

Thanks  
Rasel

 ![Screen Shot 2021-06-11 at 4.42.45 PM](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/2/2bb53e7df622790a193d3b08458bac654e529b6b.png)

---

<div class="post-metadata">

**Author:** ![nsanzine](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@nsanzine](https://forum.cmascenter.org/u/nsanzine)\
**Post date:** [June 11, 2021, 9:51pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/6 "2021-06-11T21:51:31Z")

</div>

Can you try running your command as ./m3wndw infile outfile ?

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 11, 2021, 10:24pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/7 "2021-06-11T22:24:42Z")

</div>

@nsanzine

It worked. Quick question. How can I set the location GRIDDESC file? I’m not sure about LOCOL, HICOL, LOROW, and HIROW values for my datasets. I need XORIG, YORIG, NCOLS and NROWS to be specific as like in my GRIDDESC file.

Please see the attached file.

Thanks  
Rasel

 ![Screen Shot 2021-06-11 at 6.22.52 PM](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/e/e79cc417b7b8b0357a582f49f77474536672f560.png)

---

<div class="post-metadata">

**Author:** ![nsanzine](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@nsanzine](https://forum.cmascenter.org/u/nsanzine)\
**Post date:** [June 11, 2021, 10:32pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/8 "2021-06-11T22:32:28Z")

</div>

I do not think you need GIRDDESC file. You can just enter your LOCOL, HICOL, LOROW, and HIROW values. in the command prompt.

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 11, 2021, 10:37pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/9 "2021-06-11T22:37:16Z")

</div>

I want my emission grid (442X265) to match exactly as my modeling domain (200X120).

---

<div class="post-metadata">

**Author:** ![nsanzine](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@nsanzine](https://forum.cmascenter.org/u/nsanzine)\
**Post date:** [June 11, 2021, 10:43pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/10 "2021-06-11T22:43:44Z")

</div>

Then, you are going to have to provide more information. Do the emission files and modeling domain have the same resolution? What’s the emissions XORIG, YORIG, NCOLS and NROWS vs model domain XORIG, YORIG, NCOLS and NROWS ?

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 11, 2021, 10:48pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/11 "2021-06-11T22:48:36Z")

</div>

Please see the attached GRIDDESC file.

 ![Screen Shot 2021-06-11 at 6.46.45 PM](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/e/e38b98a70b219e7577cd365905815f54fb56e25a.png)

Information of emission file:

 ![Screen Shot 2021-06-11 at 6.48.11 PM](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/f/f4693958d5a859dbf7dca7fcb39eb0aee70d865d.png)

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [June 12, 2021, 12:12pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/12 "2021-06-12T12:12:01Z")

</div>

You need to do a bit of simple arithmetic to find the lo/hi col/row values.  
Let the large grid `GRID1` (from which you are windowing) have grid parameters `XORIG1, YORIG1, XCELL1, YCELL1,NCOLS1,NROWS1` etc.

Let the small grid `GRID2` (to which you are windowing) have grid parameters `XORIG2, YORIG2, XCELL2, YCELL2,NCOLS2,NROWS2` etc.

For windowing, `XCELL1` and `XCELL2`, and `YCELL1` and `YCELL2` must match, as well as having correct grid alignment (more about alignment later).

Then let

```auto
DX = (XORIG2 - XORIG1)/XCELL1
DY = (YORIG2 - YORIG1)/YCELL1

```

For grid alignment, `DX` and `DY` must be positive integers.  
Then

```auto
LOCOL = 1 + NINT(DX)
LOROW = 1 + NINT( DY)
HICOL = LOCOL + NCOLS2 - 1
HIROW = LOROW + NROWS - 1

```

and “windowability” also requires that all of these must be less than the dimensions of `GRID1`.

_ **Note** that “match” means “up to reasonable round-off error” (and “`Z` is a positive integer” means that `DBLE(INT(Z))` matches `Z`). If you’re programming this, a good test for “does not match” is in the `DBLERR` function found throughout the I/O API and M3Tools:_  
`DBLERR(P,Q) = ( (P-Q)**2 .GT. 1.0D-10*( P*P+Q*Q+1.0D-5 ) )`

_ **Note also** that the approach advocated by some:_

> _Write P and Q to ASCII strings using 6 significant digits and compare the resulting strings_

_(and assuming that Fortran rounds correctly as it does so – not a valid assumption, since the Fortran Standard explicitly disavows this, calling it a “quality of implementation” issue) does **not** work; consider the examples_

```auto
P = 1.234565000000001d0
Q = 1.234564999999999d0

```

_which round differently to 6 digits, but are within **any** reasonable round-off error tolerance…_

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 13, 2021, 9:33pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/13 "2021-06-13T21:33:01Z")

</div>

Hello,

I’m trying to use m3wnd tool for windowing emission data. Here’s my script:  
After I run the script, it gives me the output for just one day (20200521). It was supposed to give 2 days’ output in 2 different files. Can you please let me know where did I do wrong?

See the log output file and my script  
[m4.sh.txt](https://forum.cmascenter.org/uploads/short-url/rMPM7Apf5itd3RyLCoclOQZKAOl.txt) (580 Bytes)  
[log.txt](https://forum.cmascenter.org/uploads/short-url/rCobBCIlEkf4TRAJLkRCdbEbZIN.txt) (6.9 KB)

Regards,  
Rasel

---

<div class="post-metadata">

**Author:** ![munshimdrasel](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@munshimdrasel](https://forum.cmascenter.org/u/munshimdrasel)\
**Post date:** [June 13, 2021, 9:56pm UTC](https://forum.cmascenter.org/t/batch-script-for-m3wndw-or-bcwndw/1485/15 "2021-06-13T21:56:16Z")

</div>

it worked. thank you so much.
