15
15
#include "fortprintf.h"
16
16
#include "utility.h"
17
17
18
+ #ifdef MPAS_CAM_DYCORE
19
+ #include <ctype.h>
20
+ #endif
21
+
18
22
void process_core_macro (const char * macro , const char * val , va_list ap );
19
23
void process_domain_macro (const char * macro , const char * val , va_list ap );
20
24
@@ -699,6 +703,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
699
703
const char * nmlrecname , * nmlrecindef , * nmlrecinsub ;
700
704
const char * nmloptname , * nmlopttype , * nmloptval , * nmloptunits , * nmloptdesc , * nmloptposvals , * nmloptindef ;
701
705
706
+ #ifdef MPAS_CAM_DYCORE
707
+ // Fortran variable names have a length limit of 63 characters. + 1 for the terminating null character.
708
+ char new_nmlrecname [64 ];
709
+ char new_nmloptname [64 ];
710
+ const char * old_nmlrecname ;
711
+ const char * old_nmloptname ;
712
+ #endif
713
+
702
714
char pool_name [1024 ];
703
715
char core_string [1024 ];
704
716
@@ -743,7 +755,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
743
755
744
756
// Parse Namelist Records
745
757
for (nmlrecs_xml = ezxml_child (registry , "nml_record" ); nmlrecs_xml ; nmlrecs_xml = nmlrecs_xml -> next ){
758
+ #ifdef MPAS_CAM_DYCORE
759
+ old_nmlrecname = ezxml_attr (nmlrecs_xml , "name" );
760
+ transform_name (new_nmlrecname , sizeof (new_nmlrecname ), old_nmlrecname );
761
+
762
+ nmlrecname = new_nmlrecname ;
763
+ #else
746
764
nmlrecname = ezxml_attr (nmlrecs_xml , "name" );
765
+ #endif
747
766
nmlrecindef = ezxml_attr (nmlrecs_xml , "in_defaults" );
748
767
nmlrecinsub = ezxml_attr (nmlrecs_xml , "in_subpool" );
749
768
@@ -777,7 +796,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
777
796
778
797
// Define variable definitions prior to reading the namelist in.
779
798
for (nmlopt_xml = ezxml_child (nmlrecs_xml , "nml_option" ); nmlopt_xml ; nmlopt_xml = nmlopt_xml -> next ){
799
+ #ifdef MPAS_CAM_DYCORE
800
+ old_nmloptname = ezxml_attr (nmlopt_xml , "name" );
801
+ transform_name (new_nmloptname , sizeof (new_nmloptname ), old_nmloptname );
802
+
803
+ nmloptname = new_nmloptname ;
804
+ #else
780
805
nmloptname = ezxml_attr (nmlopt_xml , "name" );
806
+ #endif
781
807
nmlopttype = ezxml_attr (nmlopt_xml , "type" );
782
808
nmloptval = ezxml_attr (nmlopt_xml , "default_value" );
783
809
nmloptunits = ezxml_attr (nmlopt_xml , "units" );
@@ -809,7 +835,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
809
835
// Define the namelist block, to read the namelist record in.
810
836
fortprintf (fd , " namelist /%s/ &\n" , nmlrecname );
811
837
for (nmlopt_xml = ezxml_child (nmlrecs_xml , "nml_option" ); nmlopt_xml ; nmlopt_xml = nmlopt_xml -> next ){
838
+ #ifdef MPAS_CAM_DYCORE
839
+ old_nmloptname = ezxml_attr (nmlopt_xml , "name" );
840
+ transform_name (new_nmloptname , sizeof (new_nmloptname ), old_nmloptname );
841
+
842
+ nmloptname = new_nmloptname ;
843
+ #else
812
844
nmloptname = ezxml_attr (nmlopt_xml , "name" );
845
+ #endif
813
846
if (nmlopt_xml -> next ){
814
847
fortprintf (fd , " %s, &\n" , nmloptname );
815
848
} else {
@@ -840,7 +873,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
840
873
// Define broadcast calls for namelist values.
841
874
fortprintf (fd , " if (ierr <= 0) then\n" );
842
875
for (nmlopt_xml = ezxml_child (nmlrecs_xml , "nml_option" ); nmlopt_xml ; nmlopt_xml = nmlopt_xml -> next ){
876
+ #ifdef MPAS_CAM_DYCORE
877
+ old_nmloptname = ezxml_attr (nmlopt_xml , "name" );
878
+ transform_name (new_nmloptname , sizeof (new_nmloptname ), old_nmloptname );
879
+
880
+ nmloptname = new_nmloptname ;
881
+ #else
843
882
nmloptname = ezxml_attr (nmlopt_xml , "name" );
883
+ #endif
844
884
nmlopttype = ezxml_attr (nmlopt_xml , "type" );
845
885
846
886
if (strncmp (nmlopttype , "real" , 1024 ) == 0 ){
@@ -858,7 +898,14 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
858
898
fortprintf (fd , " call mpas_log_write(' The following values will be used for variables in this record:')\n" );
859
899
fortprintf (fd , " call mpas_log_write(' ')\n" );
860
900
for (nmlopt_xml = ezxml_child (nmlrecs_xml , "nml_option" ); nmlopt_xml ; nmlopt_xml = nmlopt_xml -> next ){
901
+ #ifdef MPAS_CAM_DYCORE
902
+ old_nmloptname = ezxml_attr (nmlopt_xml , "name" );
903
+ transform_name (new_nmloptname , sizeof (new_nmloptname ), old_nmloptname );
904
+
905
+ nmloptname = new_nmloptname ;
906
+ #else
861
907
nmloptname = ezxml_attr (nmlopt_xml , "name" );
908
+ #endif
862
909
nmlopttype = ezxml_attr (nmlopt_xml , "type" );
863
910
864
911
if (strncmp (nmlopttype , "character" , 1024 ) == 0 ) {
@@ -885,10 +932,21 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
885
932
fortprintf (fd , "\n" );
886
933
887
934
for (nmlopt_xml = ezxml_child (nmlrecs_xml , "nml_option" ); nmlopt_xml ; nmlopt_xml = nmlopt_xml -> next ){
935
+ #ifdef MPAS_CAM_DYCORE
936
+ old_nmloptname = ezxml_attr (nmlopt_xml , "name" );
937
+ transform_name (new_nmloptname , sizeof (new_nmloptname ), old_nmloptname );
938
+
939
+ nmloptname = new_nmloptname ;
940
+
941
+ // Keep namelist options to their original names in MPAS pools for compatibility reasons.
942
+ fortprintf (fd , " call mpas_pool_add_config(%s, '%s', %s)\n" , pool_name , old_nmloptname , nmloptname );
943
+ fortprintf (fcg , " call mpas_pool_get_config(configPool, '%s', %s)\n" , old_nmloptname , nmloptname );
944
+ #else
888
945
nmloptname = ezxml_attr (nmlopt_xml , "name" );
889
946
890
947
fortprintf (fd , " call mpas_pool_add_config(%s, '%s', %s)\n" , pool_name , nmloptname , nmloptname );
891
948
fortprintf (fcg , " call mpas_pool_get_config(configPool, '%s', %s)\n" , nmloptname , nmloptname );
949
+ #endif
892
950
}
893
951
fortprintf (fd , "\n" );
894
952
fortprintf (fcg , "\n" );
@@ -2532,3 +2590,32 @@ int parse_structs_from_registry(ezxml_t registry)/*{{{*/
2532
2590
2533
2591
return 0 ;
2534
2592
}/*}}}*/
2593
+
2594
+
2595
+ #ifdef MPAS_CAM_DYCORE
2596
+ // Perform transformations for namelist group and option names.
2597
+ void transform_name (char * new_name , const size_t new_name_size , const char * old_name ) {
2598
+ const char * const new_prefix = "mpas_" ;
2599
+ const char * const old_prefix = "config_" ;
2600
+ size_t size = 0 ;
2601
+
2602
+ if (!new_name || !old_name || new_name_size == 0 ) return ;
2603
+
2604
+ // Remove all leading whitespaces by moving pointer forward.
2605
+ while (* old_name != '\0' && isspace ((unsigned char ) * old_name )) old_name ++ ;
2606
+
2607
+ // Remove all leading "config_" by moving pointer forward.
2608
+ while (strncasecmp (old_name , old_prefix , strlen (old_prefix )) == 0 ) old_name += strlen (old_prefix );
2609
+
2610
+ // Remove all leading "mpas_" by moving pointer forward.
2611
+ while (strncasecmp (old_name , new_prefix , strlen (new_prefix )) == 0 ) old_name += strlen (new_prefix );
2612
+
2613
+ * new_name = '\0' ;
2614
+ size = snprintf (NULL , 0 , "%s%s" , new_prefix , old_name ) + 1 ;
2615
+ snprintf (new_name , size > new_name_size ? new_name_size : size , "%s%s" , new_prefix , old_name );
2616
+
2617
+ // Remove all trailing whitespaces by zeroing (nulling) out.
2618
+ new_name += strlen (new_name ) - 1 ;
2619
+ while (* new_name != '\0' && isspace ((unsigned char ) * new_name )) * new_name -- = '\0' ;
2620
+ }
2621
+ #endif
0 commit comments