Command line executable to fix marthe fmt
In some older versions of MARTHE, grid attributes were miswritten.
A fix script is included in gridmarthe if users need to read such file.
This example show how to use this script, called cleanmgrid. All kind of gridfiles may not be included. Please make an issue if you appear to lack a treatment.
nb: the next commands are shell commands, the ‘!’ mark is only here for the python notebook version.
# how to use: print help message
!head -30 ./data/grid_wrong_attrs.hsubs
Marthe_Grid Version=9.0
Title=Bidon H_SUBSTRAT 1
[Infos]
Field=
Type=
Elem_Number=0
Name=
Time_Step=-9999
Time=0
Layer=0
Max_Layer=0
Nest_grid=0
Max_NestG=0
[Structure]
X_Left_Corner=528
Y_Lower_Corner=2503
Ncolumn=320
Nrows=189
[Data_Descript]
! Line 1 : 0 , 0 , < 1 , 2 , 3 , Ncolumn >
! Line 2 : 0 , 0 , < X_Center_of_all_Columns >
! Line 2+1 : 1 , Y_of_Row_1 , < Field_Values_of_all_Columns > , Dy_of_Row_1
! Line 2+2 : 2 , Y_of_Row_2 , < Field_Values_of_all_Columns > , Dy_of_Row_2
! Line 2+Nrows : Nrows , Y_of_Row_Nrows , < Field_Values_of_all_Columns > , Dy_of_Row_2
! Line 3+Nrows : 0 , 0 , < Dx_of_all_Colums >
[Data]
0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
0 0 528.25 528.75 529.25 529.75 530.25 530.75 531.25 531.75 532.25 532.75 533.25 533.75 534.25 534.75 535.25 535.75 536.25 536.75 537.25 537.75 538.25 538.75 539.25 539.75 540.25 540.75 541.25 541.75 542.25 542.75 543.25 543.75 544.25 544.75 545.25 545.75 546.25 546.75 547.25 547.75 548.25 548.75 549.25 549.75 550.25 550.75 551.25 551.75 552.25 552.75 553.25 553.75 554.25 554.75 555.25 555.75 556.25 556.75 557.25 557.75 558.25 558.75 559.25 559.75 560.25 560.75 561.25 561.75 562.25 562.75 563.25 563.75 564.25 564.75 565.25 565.75 566.25 566.75 567.25 567.75 568.25 568.75 569.25 569.75 570.25 570.75 571.25 571.75 572.25 572.75 573.25 573.75 574.25 574.75 575.25 575.75 576.25 576.75 577.25 577.75 578.25 578.75 579.25 579.75 580.25 580.75 581.25 581.75 582.25 582.75 583.25 583.75 584.25 584.75 585.25 585.75 586.25 586.75 587.25 587.75 588.25 588.75 589.25 589.75 590.25 590.75 591.25 591.75 592.25 592.75 593.25 593.75 594.25 594.75 595.25 595.75 596.25 596.75 597.25 597.75 598.25 598.75 599.25 599.75 600.25 600.75 601.25 601.75 602.25 602.75 603.25 603.75 604.25 604.75 605.25 605.75 606.25 606.75 607.25 607.75 608.25 608.75 609.25 609.75 610.25 610.75 611.25 611.75 612.25 612.75 613.25 613.75 614.25 614.75 615.25 615.75 616.25 616.75 617.25 617.75 618.25 618.75 619.25 619.75 620.25 620.75 621.25 621.75 622.25 622.75 623.25 623.75 624.25 624.75 625.25 625.75 626.25 626.75 627.25 627.75 628.25 628.75 629.25 629.75 630.25 630.75 631.25 631.75 632.25 632.75 633.25 633.75 634.25 634.75 635.25 635.75 636.25 636.75 637.25 637.75 638.25 638.75 639.25 639.75 640.25 640.75 641.25 641.75 642.25 642.75 643.25 643.75 644.25 644.75 645.25 645.75 646.25 646.75 647.25 647.75 648.25 648.75 649.25 649.75 650.25 650.75 651.25 651.75 652.25 652.75 653.25 653.75 654.25 654.75 655.25 655.75 656.25 656.75 657.25 657.75 658.25 658.75 659.25 659.75 660.25 660.75 661.25 661.75 662.25 662.75 663.25 663.75 664.25 664.75 665.25 665.75 666.25 666.75 667.25 667.75 668.25 668.75 669.25 669.75 670.25 670.75 671.25 671.75 672.25 672.75 673.25 673.75 674.25 674.75 675.25 675.75 676.25 676.75 677.25 677.75 678.25 678.75 679.25 679.75 680.25 680.75 681.25 681.75 682.25 682.75 683.25 683.75 684.25 684.75 685.25 685.75 686.25 686.75 687.25 687.75
1 2597.25 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 .5
2 2596.75 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 -24.81 -24.93 -23 -25.13 -23 -24.04 -20 -21.98 -20.87 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 .5
In the above results, we can see that Layer, Max_Layer, Nest_grid, Max_Nestg are all set to 0.
This is an error which prevent successfull Marthe IO operations with gridmarthe or pymarthe.
The script cleanmgrid is going to fix it.
# print help to check for accepted args
!cleanmgrid -h
usage: cleanmgrid [-h] [--layer LAYER] [--grid GRID] [--output OUTPUT]
[--no_overwrite]
PATH_TO_FILE
Clean marthe grid file for miswritten attributes. Only works for marthe grid v9.0 (a check is performed and <v9 are skipped)
positional arguments:
PATH_TO_FILE PATH_TO_FILE can be a relative path, if it ends with
".rma" all grid file in rma project will be processed.
options:
-h, --help show this help message and exit
--layer LAYER, -l LAYER
Number of layer. Only if PATH_TO_FILE is *NOT* a rma
file. Otherwise, it will be parsed from Marthe's
files.
--grid GRID, -g GRID Number of nested grid. Only if PATH_TO_FILE is *NOT* a
rma file. Otherwise, it will be parsed from Marthe's
files.
--output OUTPUT, -o OUTPUT
Output file name (without subdir if any). Only if
PATH_TO_FILE is a single grid file and *NOT* a rma
file. Otherwise, all files will be bakup and clean
--no_overwrite, -n Do no overwrite file, add `.fix` extension. By default
file is bakup and then overwrite.
gridmarthe Copyright (C) 2025 BRGM.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, see GNU General Public Lisence v3 for copying.
cleanmgrid is designed to work with single grid files or rma (Marthe Projects) files.
In the first case, you need to give to the program the value to fix (number of layer,
number of nested grids) before the argument (file to clean).
In the second case (rma mode), you only need to give the rma file as argument. All
values will be parsed from marthe files.
# let's try for a simple case, with only one grid file
!cleanmgrid ./data/grid_wrong_attrs.hsubs -l 1 -g 3 -o grid_clean.hsubs
# print variables headers and dimensions with nco tools
!head -30 ./data/grid_clean.hsubs
Marthe_Grid Version=9.0
Title=Bidon H_SUBSTRAT 1
[Infos]
Field=H_SUBSTRAT
Type=
Elem_Number=0
Name=
Time_Step=-9999
Time=0
Layer=1
Max_Layer=1
Nest_grid=0
Max_NestG=3
[Structure]
X_Left_Corner=528
Y_Lower_Corner=2503
Ncolumn=320
Nrows=189
[Data_Descript]
! Line 1 : 0 , 0 , < 1 , 2 , 3 , Ncolumn >
! Line 2 : 0 , 0 , < X_Center_of_all_Columns >
! Line 2+1 : 1 , Y_of_Row_1 , < Field_Values_of_all_Columns > , Dy_of_Row_1
! Line 2+2 : 2 , Y_of_Row_2 , < Field_Values_of_all_Columns > , Dy_of_Row_2
! Line 2+Nrows : Nrows , Y_of_Row_Nrows , < Field_Values_of_all_Columns > , Dy_of_Row_2
! Line 3+Nrows : 0 , 0 , < Dx_of_all_Colums >
[Data]
0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
0 0 528.25 528.75 529.25 529.75 530.25 530.75 531.25 531.75 532.25 532.75 533.25 533.75 534.25 534.75 535.25 535.75 536.25 536.75 537.25 537.75 538.25 538.75 539.25 539.75 540.25 540.75 541.25 541.75 542.25 542.75 543.25 543.75 544.25 544.75 545.25 545.75 546.25 546.75 547.25 547.75 548.25 548.75 549.25 549.75 550.25 550.75 551.25 551.75 552.25 552.75 553.25 553.75 554.25 554.75 555.25 555.75 556.25 556.75 557.25 557.75 558.25 558.75 559.25 559.75 560.25 560.75 561.25 561.75 562.25 562.75 563.25 563.75 564.25 564.75 565.25 565.75 566.25 566.75 567.25 567.75 568.25 568.75 569.25 569.75 570.25 570.75 571.25 571.75 572.25 572.75 573.25 573.75 574.25 574.75 575.25 575.75 576.25 576.75 577.25 577.75 578.25 578.75 579.25 579.75 580.25 580.75 581.25 581.75 582.25 582.75 583.25 583.75 584.25 584.75 585.25 585.75 586.25 586.75 587.25 587.75 588.25 588.75 589.25 589.75 590.25 590.75 591.25 591.75 592.25 592.75 593.25 593.75 594.25 594.75 595.25 595.75 596.25 596.75 597.25 597.75 598.25 598.75 599.25 599.75 600.25 600.75 601.25 601.75 602.25 602.75 603.25 603.75 604.25 604.75 605.25 605.75 606.25 606.75 607.25 607.75 608.25 608.75 609.25 609.75 610.25 610.75 611.25 611.75 612.25 612.75 613.25 613.75 614.25 614.75 615.25 615.75 616.25 616.75 617.25 617.75 618.25 618.75 619.25 619.75 620.25 620.75 621.25 621.75 622.25 622.75 623.25 623.75 624.25 624.75 625.25 625.75 626.25 626.75 627.25 627.75 628.25 628.75 629.25 629.75 630.25 630.75 631.25 631.75 632.25 632.75 633.25 633.75 634.25 634.75 635.25 635.75 636.25 636.75 637.25 637.75 638.25 638.75 639.25 639.75 640.25 640.75 641.25 641.75 642.25 642.75 643.25 643.75 644.25 644.75 645.25 645.75 646.25 646.75 647.25 647.75 648.25 648.75 649.25 649.75 650.25 650.75 651.25 651.75 652.25 652.75 653.25 653.75 654.25 654.75 655.25 655.75 656.25 656.75 657.25 657.75 658.25 658.75 659.25 659.75 660.25 660.75 661.25 661.75 662.25 662.75 663.25 663.75 664.25 664.75 665.25 665.75 666.25 666.75 667.25 667.75 668.25 668.75 669.25 669.75 670.25 670.75 671.25 671.75 672.25 672.75 673.25 673.75 674.25 674.75 675.25 675.75 676.25 676.75 677.25 677.75 678.25 678.75 679.25 679.75 680.25 680.75 681.25 681.75 682.25 682.75 683.25 683.75 684.25 684.75 685.25 685.75 686.25 686.75 687.25 687.75
1 2597.25 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 .5
2 2596.75 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 -24.81 -24.93 -23 -25.13 -23 -24.04 -20 -21.98 -20.87 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 .5
cleanmgrid also work if you specified a *.rma file (Marthe Project). In such case, the program will try to fix all grid files of the project !