Merge branch 'release-v4.6.0' of github.com:wrf-model/WRF
[WRF.git] / tools / data.c
blob21405b460c10950fdbb6b91adb174598dfc2028e
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #ifdef _WIN32
5 #define rindex(X,Y) strrchr(X,Y)
6 #define index(X,Y) strchr(X,Y)
7 #define bzero(X,Y) memset(X,0,Y)
8 #else
9 # include <strings.h>
10 #endif
12 #include "registry.h"
13 #include "protos.h"
14 #include "data.h"
16 #define MAXTOKENS 30
18 int
19 init_dim_table()
21 Dim = NULL ;
22 return(0) ;
25 node_t *
26 new_node ( int kind )
27 { node_t *p ; p = (node_t *)malloc(sizeof(node_t)) ; bzero(p,sizeof(node_t)); p->node_kind = kind ; return (p) ; }
29 int
30 add_node_to_end ( node_t * node , node_t ** list )
32 node_t * p ;
33 if ( *list == NULL )
34 { *list = node ; }
35 else
37 for ( p = *list ; p->next != NULL ; p = p->next ) ;
38 p->next = node ;
40 return(0) ;
43 int
44 add_node_to_end_4d ( node_t * node , node_t ** list )
46 node_t * p ;
47 if ( *list == NULL )
48 { *list = node ; }
49 else
51 for ( p = *list ; p->next4d != NULL ; p = p->next4d ) ;
52 p->next4d = node ;
54 return(0) ;
57 #if 0
58 int
59 show_nodelist( node_t * p )
61 show_nodelist1( p , 0 ) ;
64 show_nodelist1( node_t * p , int indent )
66 if ( p == NULL ) return(0) ;
67 show_node1( p, indent) ;
68 show_nodelist1( p->next, indent ) ;
71 int
72 show_node( node_t * p )
74 return(show_node1(p,0)) ;
77 int
78 show_node1( node_t * p, int indent )
80 char spaces[] = " " ;
81 char tmp[25] , t1[25] , t2[25] ;
82 char * x, *ca, *ld, *ss, *se, *sg ;
83 char *nodekind ;
84 node_t * q ;
85 int nl ;
86 int i ;
88 if ( p == NULL ) return(1) ;
89 strcpy(tmp, spaces) ;
90 if ( indent >= 0 && indent < 20 ) tmp[indent] = '\0' ;
92 // this doesn't make much sense any more, ever since node_kind was
93 // changed to a bit mask
94 if ( p->node_kind & RCONFIG ) nodekind = "RCONFIG" ;
95 else if ( p->node_kind & I1 ) nodekind = "I1" ;
96 else if ( p->node_kind & FIELD ) nodekind = "FIELD" ;
97 else if ( p->node_kind & FOURD ) nodekind = "FOURD" ;
98 else if ( p->node_kind & MEMBER ) nodekind = "MEMBER" ;
99 else if ( p->node_kind & RCONFIG ) nodekind = "RCONFIG" ;
101 if ( !p->scalar_array_member )
103 switch ( p->node_kind )
105 case RCONFIG :
106 case I1 :
107 case FIELD :
108 case FOURD :
109 case MEMBER :
110 fprintf(stderr,"%s%s : %10s ndims %1d\n",tmp,nodekind,p->name, p->ndims) ;
111 for ( i = 0 ; i < p->ndims ; i++ )
113 sg = "" ;
114 switch ( p->dims[i]->coord_axis ) {
115 case COORD_X : ca = "X" ; if ( p->stag_x ) sg = "*" ; break ;
116 case COORD_Y : ca = "Y" ; if ( p->stag_y ) sg = "*" ; break ;
117 case COORD_Z : ca = "Z" ; if ( p->stag_z ) sg = "*" ; break ;
118 case COORD_C : ca = "C" ; break ;
120 switch ( p->dims[i]->len_defined_how ) {
121 case DOMAIN_STANDARD : ld = "STANDARD" ; ss = "" ; se = "" ; break ;
122 case NAMELIST : ld = "NAMELIST" ; ss = p->dims[i]->associated_namelist_variable ; se="" ; break ;
123 case CONSTANT : ld = "CONSTANT" ; sprintf(t1,"%d",p->dims[i]->coord_start) ; ss = t1 ;
124 sprintf(t2,"%d",p->dims[i]->coord_end ) ; se = t2 ;
125 break ;
127 fprintf(stderr," dim %1d: %c %2s%s %10s %10s %10s\n",i,p->dims[i]->dim_name,ca,sg,ld,ss,se) ;
129 nl = 0 ;
130 if ( strlen( p->use ) > 0 ) {
131 nl = 1 ; fprintf(stderr," use: %s",p->use) ;
132 if ( p->scalar_array_member ) fprintf(stderr,"(4D)") ;
134 if ( strlen( p->dname ) > 0 ) { nl = 1 ; fprintf(stderr," dname: %s",p->dname) ; }
135 if ( strlen( p->descrip ) > 0 ) { nl = 1 ; fprintf(stderr," descrip: %s",p->descrip) ; }
136 if ( nl == 1 ) fprintf(stderr,"\n") ;
137 show_node1( p->type, indent+1 ) ;
138 break ;
139 case TYPE :
140 x = "derived" ;
141 if ( p->type_type == SIMPLE ) x = "simple" ;
142 fprintf(stderr,"%sTYPE : %10s %s ndims %1d\n",tmp,p->name,x, p->ndims) ;
143 show_nodelist1( p->fields, indent+1 ) ;
144 break ;
145 case DIM :
146 break ;
147 default :
148 break ;
151 show_nodelist1( p->members , indent+2 ) ;
152 return(0) ;
154 #endif
157 set_mark ( int val , node_t * lst )
159 node_t * p ;
160 if ( lst == NULL ) return(0) ;
161 for ( p = lst ; p != NULL ; p = p->next )
163 p->mark = val ;
164 set_mark( val , p->fields ) ;
165 set_mark( val , p->members ) ;
167 return(0) ;
171 set_mark_4d ( int val , node_t * lst )
173 node_t * p ;
174 if ( lst == NULL ) return(0) ;
175 for ( p = lst ; p != NULL ; p = p->next4d )
177 p->mark = val ;
178 set_mark( val , p->fields ) ;
179 set_mark( val , p->members ) ;
181 return(0) ;