| 600 | == Testing guidelines before committing new code to ORCHIDEE-CN-CAN on svn == |
| 601 | |
| 602 | In some rare cases after bugfixes or implementation of new code, problems with reproducibility or 1+1=2 might unintentionally be introduced. Often these are related to incorrect variable dimensions in different sub-routines, memory issues or the lack of variables in the restart files. Such issues are easier to catch sooner than later. Thus, to minimize the time spent on debugging reproducibility and 1+1=2 issues, the following simple test are suggested/required before each commit of substantial code changes*: |
| 603 | === 1+1=2 === |
| 604 | If you do not run these test globally, make sure to use impose_veg=y. |
| 605 | The standard F2 run.def settings have been tested/are currently tested and still results in 1+1=2 issues. Thus, please always make the test for the standard settings. In case of other run.def settings during your developments, make same tests for your settings also. |
| 606 | |
| 607 | 1) 1Y vs. 12*1M (compare the final restart files) |
| 608 | |
| 609 | Most issues should be caught with (1). In case of problems, it will make the debugging easier if you can track down the onset of difference between the files (i.e. start of year, onset of growing season, end of year etc.) Thus, continue with test like |
| 610 | |
| 611 | 2) 1D+1D=2D (compare the final restart files) |
| 612 | |
| 613 | 3) 1M+1M=2M (compare the final restart files) |
| 614 | |
| 615 | === Compare netcdf files === |
| 616 | The comparison is easiest if the same variables are contained in the two netcdf files and they are in the same order. The differ100.sh script by Josefine Ghattas, nicely does this. Moreover, it uses cdo diffv to compare the files, however 5dim variables are ignored by the cdo diffv command. |
| 617 | |
| 618 | === Have to check for differences between to netcdf files that have variables with dimensions higher than 4 === |
| 619 | The matlab function nccmp are able to compare all variables contained within two netcdf files. The original version can be found here: https://fr.mathworks.com/matlabcentral/fileexchange/47857-comparing-two-netcdf-files. |
| 620 | I have made some small modifications such that the information produced by the script are put into a file instead of printed to the screen. The update version can be found here:/ccc/work/cont003/dofoco/dofoco/SCRIPTS/debug/nccmp.m |
| 621 | |
| 622 | Sadly, matlab is not on obelix, but on IRENE. On IRENE open matlab by typing ‘Matlab’ or to run from the terminal type matlab -nodesktop. |
| 623 | |
| 624 | Next run the function by typing: |
| 625 | |
| 626 | {{{ |
| 627 | NCCMP(ncfile1,ncfile2,tolerance,forceCompare) |
| 628 | }}} |
| 629 | |
| 630 | Tolerance is if you allow some variation in the variables between the two files. We want identical files thus put [] here. |
| 631 | |
| 632 | forceCompare can be set to true or false. |
| 633 | |
| 634 | - True - write all occurrences of differences in a variable (specifically gives all the indices) to the file: all_diff.txt. |
| 635 | |
| 636 | - False - only write if there is differences in a variable and its first occurrence of such differences to the file: first_diff.txt. |
| 637 | |
| 638 | For global simulation the True option can produce a large file and the information might be hard to process, if there are many differences between the compared files. In addition, the True option can make the much script slower. However, for small simulation the true option might be very useful. |
| 639 | |
| 640 | I recommend that you use the re-ordered files from the difffer100.sh script as inputs to nccmp. |
| 641 | |
| 642 | Debugging: |
| 643 | - If possible limit the spatial scale (to maximize speed). |
| 644 | - Track down the problem. The best approach depend on the source of the problem (memory issue or lack variable in the restart file etc.). For memory issue a debugger could be the best choice. For lack of variables in restart file best to run two identical runs with different period lenghts – either manually or by Totalview while tracking down which variables are causing the differences. Hopefully, the differences in the restarts files will give you a clue on which variable to start the investigation from. |
| 645 | |