<p><b>dwj07@fsu.edu</b> 2013-03-14 14:15:45 -0600 (Thu, 14 Mar 2013)</p><p><br>
        -- BRANCH COMMIT --<br>
<br>
        Updating Registry to read a XML based Registry file.<br>
        Adding the ezxml library for parsing the XML file.<br>
<br>
        The XML parser is in it's own function call in parse.c, as was the previous parser.<br>
        This way it could potentially be modified at a later point in time.<br>
<br>
        Adding the schema definition for Registry to src/registry/Registry.xsd.<br>
        This schema has comments to describe what each element/attribute is supposed to be used for.<br>
        It also describes which attributes are required, and which are optional. It should be useful for people just getting started with registry.<br>
        It can also allow people to validate Registry.xml files.<br>
<br>
        Adding a starter Registry.xml file for the ocean core. Using this Registry.xml file, results are bit-reproducible with the ocean core on the trunk.<br>
        And the same number of lines are written to the .inc files as compared with the old Registry file, and then .inc files generated from the old parser.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/xml_registry/src/Makefile
===================================================================
--- branches/xml_registry/src/Makefile        2013-03-14 19:21:28 UTC (rev 2611)
+++ branches/xml_registry/src/Makefile        2013-03-14 20:15:45 UTC (rev 2612)
@@ -10,7 +10,6 @@
all: mpas
-
mpas: reg_includes externals frame ops dycore drver
        $(LINKER) $(LDFLAGS) -o $(CORE)_model.exe driver/*.o -L. -ldycore -lops -lframework $(LIBS) -I./external/esmf_time_f90 -L./external/esmf_time_f90 -lesmf_time
@@ -23,7 +22,7 @@
reg_includes:
        ( cd registry; $(MAKE) CC="$(SCC)" )
-        ( cd inc; $(CPP) ../core_$(CORE)/Registry | ../registry/parse > Registry.processed)
+        ( cd inc; $(CPP) ../core_$(CORE)/Registry.xml | ../registry/parse > Registry.processed)
frame: reg_includes externals
        ( cd framework; $(MAKE) CPPFLAGS="$(CPPFLAGS)" CPPINCLUDES="$(CPPINCLUDES)" all )
Added: branches/xml_registry/src/core_ocean/Registry.xml
===================================================================
--- branches/xml_registry/src/core_ocean/Registry.xml         (rev 0)
+++ branches/xml_registry/src/core_ocean/Registry.xml        2013-03-14 20:15:45 UTC (rev 2612)
@@ -0,0 +1,364 @@
+<?xml version="1.0"?>
+<registry>
+        <dims>
+                <dim name="nCells"/>
+                <dim name="nEdges"/>
+                <dim name="maxEdges"/>
+                <dim name="maxEdges2"/>
+                <dim name="nAdvectionCells" definition="maxEdges2+0"/>
+                <dim name="nVertices"/>
+                <dim name="TWO" definition="2"/>
+                <dim name="R3" definition="3"/>
+                <dim name="FIFTEEN" definition="15"/>
+                <dim name="TWENTYONE" definition="21"/>
+                <dim name="vertexDegree"/>
+                <dim name="nVertLevels"/>
+                <dim name="nVertLevelsP1" definition="nVertLevels+1"/>
+                <dim name="nMonths"/>
+        </dims>
+        <nml_record name="time_management">
+                <nml_option name="config_do_restart" type="logical" default_value=".false."/>
+                <nml_option name="config_start_time" type="character" default_value="'0000-01-01_00:00:00'"/>
+                <nml_option name="config_stop_time" type="character" default_value="'none'"/>
+                <nml_option name="config_run_duration" type="character" default_value="'0_06:00:00'"/>
+                <nml_option name="config_calendar_type" type="character" default_value="'360day'"/>
+        </nml_record>
+        <nml_record name="io">
+                <nml_option name="config_input_name" type="character" default_value="'grid.nc'"/>
+                <nml_option name="config_output_name" type="character" default_value="'output.nc'"/>
+                <nml_option name="config_restart_name" type="character" default_value="'restart.nc'"/>
+                <nml_option name="config_restart_interval" type="character" default_value="'0_06:00:00'"/>
+                <nml_option name="config_output_interval" type="character" default_value="'0_06:00:00'"/>
+                <nml_option name="config_stats_interval" type="character" default_value="'0_01:00:00'"/>
+                <nml_option name="config_write_stats_on_startup" type="logical" default_value=".true."/>
+                <nml_option name="config_write_output_on_startup" type="logical" default_value=".true."/>
+                <nml_option name="config_frames_per_outfile" type="integer" default_value="1000"/>
+                <nml_option name="config_pio_num_iotasks" type="integer" default_value="0"/>
+                <nml_option name="config_pio_stride" type="integer" default_value="1"/>
+        </nml_record>
+        <nml_record name="time_integration">
+                <nml_option name="config_dt" type="real" default_value="3000.0"/>
+                <nml_option name="config_time_integrator" type="character" default_value="'split_explicit'"/>
+        </nml_record>
+        <nml_record name="grid">
+                <nml_option name="config_num_halos" type="integer" default_value="3"/>
+                <nml_option name="config_vert_coord_movement" type="character" default_value="'uniform_stretching'"/>
+                <nml_option name="config_alter_ICs_for_pbcs" type="character" default_value="'zlevel_pbcs_off'"/>
+                <nml_option name="config_min_pbc_fraction" type="real" default_value="0.10"/>
+                <nml_option name="config_check_ssh_consistency" type="logical" default_value=".true."/>
+        </nml_record>
+        <nml_record name="decomposition">
+                <nml_option name="config_block_decomp_file_prefix" type="character" default_value="'graph.info.part.'"/>
+                <nml_option name="config_number_of_blocks" type="integer" default_value="0"/>
+                <nml_option name="config_explicit_proc_decomp" type="logical" default_value=".false."/>
+                <nml_option name="config_proc_decomp_file_prefix" type="character" default_value="'graph.info.part.'"/>
+        </nml_record>
+        <nml_record name="hmix">
+                <nml_option name="config_hmix_ScaleWithMesh" type="logical" default_value=".false."/>
+                <nml_option name="config_visc_vorticity_term" type="logical" default_value=".true."/>
+                <nml_option name="config_apvm_scale_factor" type="real" default_value="0.0"/>
+        </nml_record>
+        <nml_record name="hmix_del2">
+                <nml_option name="config_use_mom_del2" type="logical" default_value=".false."/>
+                <nml_option name="config_use_tracer_del2" type="logical" default_value=".false."/>
+                <nml_option name="config_mom_del2" type="real" default_value="0.0"/>
+                <nml_option name="config_tracer_del2" type="real" default_value="0.0"/>
+                <nml_option name="config_vorticity_del2_scale" type="real" default_value="1.0"/>
+        </nml_record>
+        <nml_record name="hmix_del4">
+                <nml_option name="config_use_mom_del4" type="logical" default_value=".true."/>
+                <nml_option name="config_use_tracer_del4" type="logical" default_value=".false."/>
+                <nml_option name="config_mom_del4" type="real" default_value="5.0e13"/>
+                <nml_option name="config_tracer_del4" type="real" default_value="0.0"/>
+                <nml_option name="config_vorticity_del4_scale" type="real" default_value="1.0"/>
+        </nml_record>
+        <nml_record name="hmix_Leith">
+                <nml_option name="config_use_Leith_del2" type="logical" default_value=".false."/>
+                <nml_option name="config_Leith_parameter" type="real" default_value="1.0"/>
+                <nml_option name="config_Leith_dx" type="real" default_value="15000.0"/>
+                <nml_option name="config_Leith_visc2_max" type="real" default_value="2.5e3"/>
+        </nml_record>
+        <nml_record name="standard_GM">
+                <nml_option name="config_h_kappa" type="real" default_value="0.0"/>
+                <nml_option name="config_h_kappa_q" type="real" default_value="0.0"/>
+        </nml_record>
+        <nml_record name="Rayleigh_damping">
+                <nml_option name="config_Rayleigh_friction" type="logical" default_value=".false."/>
+                <nml_option name="config_Rayleigh_damping_coeff" type="real" default_value="0.0"/>
+        </nml_record>
+        <nml_record name="vmix">
+                <nml_option name="config_convective_visc" type="real" default_value="1.0"/>
+                <nml_option name="config_convective_diff" type="real" default_value="1.0"/>
+        </nml_record>
+        <nml_record name="vmix_const">
+                <nml_option name="config_use_const_visc" type="logical" default_value=".false."/>
+                <nml_option name="config_use_const_diff" type="logical" default_value=".false."/>
+                <nml_option name="config_vert_visc" type="real" default_value="2.5e-4"/>
+                <nml_option name="config_vert_diff" type="real" default_value="2.5e-5"/>
+        </nml_record>
+        <nml_record name="vmix_rich">
+                <nml_option name="config_use_rich_visc" type="logical" default_value=".true."/>
+                <nml_option name="config_use_rich_diff" type="logical" default_value=".true."/>
+                <nml_option name="config_bkrd_vert_visc" type="real" default_value="1.0e-4"/>
+                <nml_option name="config_bkrd_vert_diff" type="real" default_value="1.0e-5"/>
+                <nml_option name="config_rich_mix" type="real" default_value="0.005"/>
+        </nml_record>
+        <nml_record name="vmix_tanh">
+                <nml_option name="config_use_tanh_visc" type="logical" default_value=".false."/>
+                <nml_option name="config_use_tanh_diff" type="logical" default_value=".false."/>
+                <nml_option name="config_max_visc_tanh" type="real" default_value="2.5e-1"/>
+                <nml_option name="config_min_visc_tanh" type="real" default_value="1.0e-4"/>
+                <nml_option name="config_max_diff_tanh" type="real" default_value="2.5e-2"/>
+                <nml_option name="config_min_diff_tanh" type="real" default_value="1.0e-5"/>
+                <nml_option name="config_zMid_tanh" type="real" default_value="-100"/>
+                <nml_option name="config_zWidth_tanh" type="real" default_value="100"/>
+        </nml_record>
+        <nml_record name="forcing">
+                <nml_option name="config_use_monthly_forcing" type="logical" default_value=".false."/>
+                <nml_option name="config_restoreTS" type="logical" default_value=".false."/>
+                <nml_option name="config_restoreT_timescale" type="real" default_value="90.0"/>
+                <nml_option name="config_restoreS_timescale" type="real" default_value="90.0"/>
+        </nml_record>
+        <nml_record name="advection">
+                <nml_option name="config_vert_tracer_adv" type="character" default_value="'stencil'"/>
+                <nml_option name="config_vert_tracer_adv_order" type="integer" default_value="3"/>
+                <nml_option name="config_horiz_tracer_adv_order" type="integer" default_value="3"/>
+                <nml_option name="config_coef_3rd_order" type="real" default_value="0.25"/>
+                <nml_option name="config_monotonic" type="logical" default_value=".true."/>
+        </nml_record>
+        <nml_record name="bottom_drag">
+                <nml_option name="config_bottom_drag_coeff" type="real" default_value="1.0e-3"/>
+        </nml_record>
+        <nml_record name="pressure_gradient">
+                <nml_option name="config_pressure_gradient_type" type="character" default_value="'pressure_and_zmid'"/>
+                <nml_option name="config_rho0" type="real" default_value="1014.65"/>
+        </nml_record>
+        <nml_record name="eos">
+                <nml_option name="config_eos_type" type="character" default_value="'jm'"/>
+        </nml_record>
+        <nml_record name="eos_linear">
+                <nml_option name="config_eos_linear_alpha" type="real" default_value="2.55e-1"/>
+                <nml_option name="config_eos_linear_beta" type="real" default_value="7.64e-1"/>
+                <nml_option name="config_eos_linear_Tref" type="real" default_value="19.0"/>
+                <nml_option name="config_eos_linear_Sref" type="real" default_value="35.0"/>
+                <nml_option name="config_eos_linear_rhoref" type="real" default_value="1025.022"/>
+        </nml_record>
+        <nml_record name="split_explicit_ts">
+                <nml_option name="config_n_ts_iter" type="integer" default_value="2"/>
+                <nml_option name="config_n_bcl_iter_beg" type="integer" default_value="1"/>
+                <nml_option name="config_n_bcl_iter_mid" type="integer" default_value="2"/>
+                <nml_option name="config_n_bcl_iter_end" type="integer" default_value="2"/>
+                <nml_option name="config_n_btr_subcycles" type="integer" default_value="20"/>
+                <nml_option name="config_n_btr_cor_iter" type="integer" default_value="2"/>
+                <nml_option name="config_u_correction" type="logical" default_value=".true."/>
+                <nml_option name="config_btr_subcycle_loop_factor" type="integer" default_value="2"/>
+                <nml_option name="config_btr_gam1_uWt1" type="real" default_value="0.5"/>
+                <nml_option name="config_btr_gam2_SSHWt1" type="real" default_value="1.0"/>
+                <nml_option name="config_btr_gam3_uWt2" type="real" default_value="1.0"/>
+                <nml_option name="config_btr_solve_SSH2" type="logical" default_value=".false."/>
+        </nml_record>
+        <nml_record name="debug">
+                <nml_option name="config_check_zlevel_consistency" type="logical" default_value=".false."/>
+                <nml_option name="config_filter_btr_mode" type="logical" default_value=".false."/>
+                <nml_option name="config_prescribe_velocity" type="logical" default_value=".false."/>
+                <nml_option name="config_prescribe_thickness" type="logical" default_value=".false."/>
+                <nml_option name="config_include_KE_vertex" type="logical" default_value=".false."/>
+                <nml_option name="config_check_tracer_monotonicity" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_h_all_tend" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_h_hadv" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_h_vadv" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_all_tend" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_coriolis" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_pgrad" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_hmix" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_windstress" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_vmix" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_u_vadv" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_tr_all_tend" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_tr_adv" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_tr_hmix" type="logical" default_value=".false."/>
+                <nml_option name="config_disable_tr_vmix" type="logical" default_value=".false."/>
+        </nml_record>
+        <var_struct name="state" time_levs="2">
+                <var_array name="tracers" type="real" dimensions="nVertLevels nCells Time">
+                        <var name="temperature" array_group="dynamics" streams="iro"/>
+                        <var name="salinity" array_group="dynamics" streams="iro"/>
+                        <var name="tracer1" array_group="testing" streams="iro"/>
+                </var_array>
+                <var name="xtime" type="text" dimensions="Time" streams="ro"/>
+                <var name="u" type="real" dimensions="nVertLevels nEdges Time" streams="ir" units="m/s"
+                         description="Normal velocity at edge midpoints."
+                />
+                <var name="h" type="real" dimensions="nVertLevels nCells Time" streams="iro" units="m"
+                         description="Layer thickness at cell centers."
+                />
+                <var name="rho" type="real" dimensions="nVertLevels nCells Time" streams="iro"/>
+                <var name="uBtr" type="real" dimensions="nEdges Time" streams="r"/>
+                <var name="ssh" type="real" dimensions="nCells Time" streams="o"/>
+                <var name="uBtrSubcycle" type="real" dimensions="nEdges Time"/>
+                <var name="sshSubcycle" type="real" dimensions="nCells Time"/>
+                <var name="FBtr" type="real" dimensions="nEdges Time"/>
+                <var name="GBtrForcing" type="real" dimensions="nEdges Time"/>
+                <var name="uBcl" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="zMid" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="v" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uTransport" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uBolusGM" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uBolusGMX" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uBolusGMY" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uBolusGMZ" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="uBolusGMZonal" type="real" dimensions="nVertLevels nEdges Time" streams="o"/>
+                <var name="uBolusGMMeridional" type="real" dimensions="nVertLevels nEdges Time" streams="o"/>
+                <var name="hEddyFlux" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="h_kappa" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="h_kappa_q" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="divergence" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="vorticity" type="real" dimensions="nVertLevels nVertices Time" streams="o"/>
+                <var name="Vor_edge" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="h_edge" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="h_vertex" type="real" dimensions="nVertLevels nVertices Time"/>
+                <var name="ke" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="kev" type="real" dimensions="nVertLevels nVertices Time" streams="o"/>
+                <var name="kevc" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="ke_edge" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="Vor_vertex" type="real" dimensions="nVertLevels nVertices Time"/>
+                <var name="Vor_cell" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="uReconstructX" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uReconstructY" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uReconstructZ" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uReconstructZonal" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="uReconstructMeridional" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="uSrcReconstructX" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uSrcReconstructY" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uSrcReconstructZ" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="uSrcReconstructZonal" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="uSrcReconstructMeridional" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="MontPot" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="pressure" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="wTop" type="real" dimensions="nVertLevelsP1 nCells Time"/>
+                <var name="vertVelocityTop" type="real" dimensions="nVertLevelsP1 nCells Time"/>
+                <var name="rhoDisplaced" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="BruntVaisalaFreqTop" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="viscosity" type="real" dimensions="nVertLevels nEdges Time" streams="o"/>
+                <var name="vh" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="circulation" type="real" dimensions="nVertLevels nVertices Time"/>
+                <var name="gradVor_t" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="gradVor_n" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="areaCellGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="areaEdgeGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="areaTriangleGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="volumeCellGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="volumeEdgeGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="CFLNumberGlobal" type="real" dimensions="Time" streams="o"/>
+                <var name="nAccumulate" type="real" dimensions="Time" streams="o"/>
+                <var name="acc_ssh" type="real" dimensions="nCells Time" streams="o"/>
+                <var name="acc_sshVar" type="real" dimensions="nCells Time" streams="o"/>
+                <var name="acc_uReconstructZonal" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="acc_uReconstructMeridional" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="acc_uReconstructZonalVar" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="acc_uReconstructMeridionalVar" type="real" dimensions="nVertLevels nCells Time" streams="o"/>
+                <var name="acc_u" type="real" dimensions="nVertLevels nEdges Time" streams="o"/>
+                <var name="acc_uVar" type="real" dimensions="nVertLevels nEdges Time" streams="o"/>
+                <var name="acc_vertVelocityTop" type="real" dimensions="nVertLevelsP1 nCells Time" streams="o"/>
+        </var_struct>
+        <var_struct name="mesh" time_levs="0">
+                <var name="latCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="lonCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="xCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="yCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="zCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="indexToCellID" type="integer" dimensions="nCells" streams="iro"/>
+                <var name="latEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="lonEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="xEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="yEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="zEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="indexToEdgeID" type="integer" dimensions="nEdges" streams="iro"/>
+                <var name="latVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="lonVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="xVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="yVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="zVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="indexToVertexID" type="integer" dimensions="nVertices" streams="iro"/>
+                <var name="meshDensity" type="real" dimensions="nCells" streams="iro"/>
+                <var name="meshScalingDel2" type="real" dimensions="nEdges" streams="ro"/>
+                <var name="meshScalingDel4" type="real" dimensions="nEdges" streams="ro"/>
+                <var name="meshScaling" type="real" dimensions="nEdges" streams="ro"/>
+                <var name="cellsOnEdge" type="integer" dimensions="TWO nEdges" streams="iro"/>
+                <var name="nEdgesOnCell" type="integer" dimensions="nCells" streams="iro"/>
+                <var name="nEdgesOnEdge" type="integer" dimensions="nEdges" streams="iro"/>
+                <var name="edgesOnCell" type="integer" dimensions="maxEdges nCells" streams="iro"/>
+                <var name="edgesOnEdge" type="integer" dimensions="maxEdges2 nEdges" streams="iro"/>
+                <var name="weightsOnEdge" type="real" dimensions="maxEdges2 nEdges" streams="iro"/>
+                <var name="dvEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="dcEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="angleEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="areaCell" type="real" dimensions="nCells" streams="iro"/>
+                <var name="areaTriangle" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="edgeNormalVectors" type="real" dimensions="R3 nEdges" streams="o"/>
+                <var name="localVerticalUnitVectors" type="real" dimensions="R3 nCells" streams="o"/>
+                <var name="cellTangentPlane" type="real" dimensions="R3 TWO nCells" streams="o"/>
+                <var name="cellsOnCell" type="integer" dimensions="maxEdges nCells" streams="iro"/>
+                <var name="verticesOnCell" type="integer" dimensions="maxEdges nCells" streams="iro"/>
+                <var name="verticesOnEdge" type="integer" dimensions="TWO nEdges" streams="iro"/>
+                <var name="edgesOnVertex" type="integer" dimensions="vertexDegree nVertices" streams="iro"/>
+                <var name="cellsOnVertex" type="integer" dimensions="vertexDegree nVertices" streams="iro"/>
+                <var name="kiteAreasOnVertex" type="real" dimensions="vertexDegree nVertices" streams="iro"/>
+                <var name="fEdge" type="real" dimensions="nEdges" streams="iro"/>
+                <var name="fVertex" type="real" dimensions="nVertices" streams="iro"/>
+                <var name="bottomDepth" type="real" dimensions="nCells" streams="iro"/>
+                <var name="deriv_two" type="real" dimensions="maxEdges2 TWO nEdges"/>
+                <var name="adv_coefs" type="real" dimensions="nAdvectionCells nEdges"/>
+                <var name="adv_coefs_2nd" type="real" dimensions="nAdvectionCells nEdges"/>
+                <var name="adv_coefs_3rd" type="real" dimensions="nAdvectionCells nEdges"/>
+                <var name="advCellsForEdge" type="integer" dimensions="nAdvectionCells nEdges"/>
+                <var name="nAdvCellsForEdge" type="integer" dimensions="nEdges"/>
+                <var name="highOrderAdvectionMask" type="integer" dimensions="nVertLevels nEdges"/>
+                <var name="lowOrderAdvectionMask" type="integer" dimensions="nVertLevels nEdges"/>
+                <var name="defc_a" type="real" dimensions="maxEdges nCells"/>
+                <var name="defc_b" type="real" dimensions="maxEdges nCells"/>
+                <var name="kdiff" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="coeffs_reconstruct" type="real" dimensions="R3 maxEdges nCells"/>
+                <var name="maxLevelCell" type="integer" dimensions="nCells" streams="iro"/>
+                <var name="maxLevelEdgeTop" type="integer" dimensions="nEdges"/>
+                <var name="maxLevelEdgeBot" type="integer" dimensions="nEdges"/>
+                <var name="maxLevelVertexTop" type="integer" dimensions="nVertices"/>
+                <var name="maxLevelVertexBot" type="integer" dimensions="nVertices"/>
+                <var name="refBottomDepth" type="real" dimensions="nVertLevels" streams="iro"/>
+                <var name="refBottomDepthTopOfCell" type="real" dimensions="nVertLevelsP1"/>
+                <var name="hZLevel" type="real" dimensions="nVertLevels" streams="iro"/>
+                <var name="vertCoordMovementWeights" type="real" dimensions="nVertLevels" streams="iro"/>
+                <var name="boundaryEdge" type="integer" dimensions="nVertLevels nEdges"/>
+                <var name="boundaryVertex" type="integer" dimensions="nVertLevels nVertices"/>
+                <var name="boundaryCell" type="integer" dimensions="nVertLevels nCells"/>
+                <var name="edgeMask" type="integer" dimensions="nVertLevels nEdges" streams="o"/>
+                <var name="vertexMask" type="integer" dimensions="nVertLevels nVertices" streams="o"/>
+                <var name="cellMask" type="integer" dimensions="nVertLevels nCells" streams="o"/>
+                <var name="u_src" type="real" dimensions="nVertLevels nEdges" streams="ir"/>
+                <var name="temperatureRestore" type="real" dimensions="nCells" streams="ir"/>
+                <var name="salinityRestore" type="real" dimensions="nCells" streams="ir"/>
+                <var name="windStressMonthly" type="real" dimensions="nMonths nEdges" streams="ir"/>
+                <var name="temperatureRestoreMonthly" type="real" dimensions="nMonths nCells" streams="ir"/>
+                <var name="salinityRestoreMonthly" type="real" dimensions="nMonths nCells" streams="ir"/>
+                <var name="edgeSignOnCell" type="integer" dimensions="maxEdges nCells"/>
+                <var name="edgeSignOnVertex" type="integer" dimensions="maxEdges nVertices"/>
+                <var name="kiteIndexOnCell" type="integer" dimensions="maxEdges nCells"/>
+                <var name="seaSurfacePressure" type="real" dimensions="nCells Time" streams="ir"/>
+        </var_struct>
+        <var_struct name="tend" time_levs="1">
+                <var_array name="tracers" type="real" dimensions="nVertLevels nCells Time">
+                        <var name="temperature" array_group="dynamics"/>
+                        <var name="salinity" array_group="dynamics"/>
+                        <var name="tracer1" array_group="testing"/>
+                </var_array>
+                <var name="u" type="real" dimensions="nVertLevels nEdges Time"/>
+                <var name="h" type="real" dimensions="nVertLevels nCells Time"/>
+                <var name="ssh" type="real" dimensions="nCells Time"/>
+        </var_struct>
+        <var_struct name="diagnostics" time_levs="1">
+                <var name="RiTopOfCell" type="real" dimensions="nVertLevelsP1 nCells Time"/>
+                <var name="RiTopOfEdge" type="real" dimensions="nVertLevelsP1 nEdges Time"/>
+                <var name="vertViscTopOfEdge" type="real" dimensions="nVertLevelsP1 nEdges Time"/>
+                <var name="vertDiffTopOfCell" type="real" dimensions="nVertLevelsP1 nCells Time"/>
+        </var_struct>
+</registry>
Modified: branches/xml_registry/src/registry/Makefile
===================================================================
--- branches/xml_registry/src/registry/Makefile        2013-03-14 19:21:28 UTC (rev 2611)
+++ branches/xml_registry/src/registry/Makefile        2013-03-14 20:15:45 UTC (rev 2612)
@@ -1,9 +1,12 @@
.SUFFIXES: .c .o
-OBJS = parse.o dictionary.o gen_inc.o fortprintf.o
+OBJS = parse.o dictionary.o gen_inc.o fortprintf.o ezxml/ezxml.o
all: parse
+ezxml/ezxml.o:
+        (cd ezxml; $(CC) -c ezxml.c)
+
parse: $(OBJS)
        $(CC) -o $@ $(OBJS)
Added: branches/xml_registry/src/registry/Registry.xsd
===================================================================
--- branches/xml_registry/src/registry/Registry.xsd         (rev 0)
+++ branches/xml_registry/src/registry/Registry.xsd        2013-03-14 20:15:45 UTC (rev 2612)
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" >
+        <xs:element name="registry" >
+                <xs:complexType>
+                        <xs:sequence>
+                                <!-- The dims element contains all dimensions -->
+                                <xs:element name="dims" >
+                                        <xs:complexType>
+                                                <xs:sequence>
+                                                        <!-- Each dimension is an independent child of the <dims></dims> element. -->
+                                                        <xs:element name="dim" maxOccurs="unbounded" >
+                                                                <xs:complexType>
+                                                                        <!-- The name attribute should specify the name of the dimension. -->
+                                                                        <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                        <!-- The definition attribute is used to define a dimension based on other pre-defined dimensions -->
+                                                                        <xs:attribute name="definition" type="xs:string" use="optional"/>
+                                                                        <!-- The units attribute defines the units of the dimension. -->
+                                                                        <xs:attribute name="units" type="xs:string" use="optional"/>
+                                                                        <!-- The description attribute describes the dimensions. -->
+                                                                        <xs:attribute name="description" type="xs:string" use="optional"/>
+                                                                </xs:complexType>
+                                                        </xs:element>
+                                                </xs:sequence>
+                                        </xs:complexType>
+                                </xs:element>
+                                <!-- The nml_record element contains all namelist options for a particular namelist record -->
+                                <xs:element name="nml_record" maxOccurs="unbounded" >
+                                        <xs:complexType>
+                                                <xs:sequence>
+                                                        <!-- The nml_option element defines a particular namelist option that lives within the defined nml_record -->
+                                                        <xs:element name="nml_option" maxOccurs="unbounded" >
+                                                                <xs:complexType>
+                                                                        <!-- The name attribute defines the name of the namelist option. This is how it would look in a namelist file. -->
+                                                                        <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                        <!-- The type attribute defines the type of the particular namelist option. Options are real, integer, character, and logical. -->
+                                                                        <xs:attribute name="type" type="xs:string" use="required"/>
+                                                                        <!-- The default_value attribute defines the default value of the namelist option. This is used if the option is omitted from a namelist file. -->
+                                                                        <xs:attribute name="default_value" type="xs:string" use="required"/>
+                                                                        <!-- The units attribute defines the units for the particular namelist option. -->
+                                                                        <xs:attribute name="units" type="xs:string" use="optional"/>
+                                                                        <!-- The description attribute describes the namelist option. -->
+                                                                        <xs:attribute name="description" type="xs:string" use="optional"/>
+                                                                        <!-- The possible_values attribute defines what values are allowable for the namelist option. -->
+                                                                        <xs:attribute name="possible_values" type="xs:string" use="optional"/>
+                                                                </xs:complexType>
+                                                        </xs:element>
+                                                </xs:sequence>
+                                                <!-- The name attribute defines the name of the namelist record. This would be seen as &name in the actual namelist. -->
+                                                <xs:attribute name="name" type="xs:string" use="required"/>
+                                        </xs:complexType>
+                                </xs:element>
+                                <!-- The var_struct element defines a grouping of variables. This is similar to mesh, or state and lives at the domain % blocklist level. -->
+                                <xs:element name="var_struct" maxOccurs="unbounded" >
+                                        <xs:complexType>
+                                                <xs:sequence>
+                                                        <!-- The var_array element defines an array of variables.
+                                                                 Within the code all constituent variables are merged into a one higher dimension array, for ease of use.
+                                                                 When written to the output file, they will be named their individual names. -->
+                                                        <xs:element name="var_array" maxOccurs="unbounded" minOccurs="0" >
+                                                                <xs:complexType>
+                                                                        <xs:sequence>
+                                                                                <!-- This specific var element defines a variable that is a constituent to a particular var_array group. -->
+                                                                                <xs:element name="var" maxOccurs="unbounded" minOccurs="0" >
+                                                                                        <xs:complexType>
+                                                                                                <!-- The name attribute is the name of the variable. This how it will be displayed in the output file. -->
+                                                                                                <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                                                <!-- The array_group attribute is used to group variables within the var_array for ease of use. -->
+                                                                                                <xs:attribute name="array_group" type="xs:string" use="required"/>
+                                                                                                <!-- The streams attribute defines the streams this variable is included in. Allowable values are omitted, i, r, o and any combination of i, r, and o. -->
+                                                                                                <xs:attribute name="streams" type="xs:string" use="optional"/>
+                                                                                                <!-- The name_in_code attribute defines the name of the variable in the code, if it should be different then in the input/output/restart streams. -->
+                                                                                                <xs:attribute name="name_in_code" type="xs:string" use="optional"/>
+                                                                                                <!-- The units attribute defines the units of the particular variable -->
+                                                                                                <xs:attribute name="units" type="xs:string" use="optional"/>
+                                                                                                <!-- The description attribute describes the particular variable -->
+                                                                                                <xs:attribute name="description" type="xs:string" use="optional"/>
+                                                                                        </xs:complexType>
+                                                                                </xs:element>
+                                                                        </xs:sequence>
+                                                                        <!-- The name attribute is the name of the var_array that will be seen in the code. -->
+                                                                        <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                        <!-- The type attribute defines the type of all constituents for the var_array. Valid options are real, integer, logical, and character -->
+                                                                        <xs:attribute name="type" type="xs:string" use="required"/>
+                                                                        <!-- The dimensions attribute defines the dimensions of each individual constituent. This does not include the collapsed dimension. -->
+                                                                        <xs:attribute name="dimensions" type="xs:string" use="required"/>
+                                                                        <!-- The persistence attribute determines if the var_array is persistence or scratch. Valid options are persistent, and scratch. -->
+                                                                        <xs:attribute name="persistence" type="xs:string" use="optional"/>
+                                                                </xs:complexType>
+                                                        </xs:element>
+                                                        <!-- This var element defines a variable that does not live within a var_array group. -->
+                                                        <xs:element name="var" maxOccurs="unbounded" minOccurs="0" >
+                                                                <xs:complexType>
+                                                                        <!-- The name attribute defines the name in the NetCDF files of this variable. -->
+                                                                        <xs:attribute name="name" type="xs:string" use="required"/>
+                                                                        <!-- The type attribute defines the type within MPAS of the variable. -->
+                                                                        <xs:attribute name="type" type="xs:string" use="required"/>
+                                                                        <!-- The dimensions attribute defines the dimensions of the variable. -->
+                                                                        <xs:attribute name="dimensions" type="xs:string" use="required"/>
+                                                                        <!-- The streams attribute defines the streams this variable is included in. -->
+                                                                        <xs:attribute name="streams" type="xs:string" use="optional"/>
+                                                                        <!-- The name_in_code attribute defines the name of the variable within MPAS (if different from name). -->
+                                                                        <xs:attribute name="name_in_code" type="xs:string" use="optional"/>
+                                                                        <!-- The units attribute defines the units of the variable. -->
+                                                                        <xs:attribute name="units" type="xs:string" use="optional"/>
+                                                                        <!-- The description attribute provides a brief description of the variable. -->
+                                                                        <xs:attribute name="description" type="xs:string" use="optional"/>
+                                                                </xs:complexType>
+                                                        </xs:element>
+                                                </xs:sequence>
+                                                <!-- The name attribute defines the name of the var_struct. This would be similar to mesh, or state. -->
+                                                <xs:attribute name="name" type="xs:string" use="required"/>
+                                                <!-- The time_levs attribute defines the number of time levels this var_struct contains. -->
+                                                <xs:attribute name="time_levs" type="xs:int" use="required"/>
+                                        </xs:complexType>
+                                </xs:element>
+                        </xs:sequence>
+                </xs:complexType>
+        </xs:element>
+</xs:schema>
Added: branches/xml_registry/src/registry/ezxml/ezxml.c
===================================================================
--- branches/xml_registry/src/registry/ezxml/ezxml.c         (rev 0)
+++ branches/xml_registry/src/registry/ezxml/ezxml.c        2013-03-14 20:15:45 UTC (rev 2612)
@@ -0,0 +1,1015 @@
+/* ezxml.c
+ *
+ * Copyright 2004-2006 Aaron Voisine <aaron@voisine.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <sys/types.h>
+#ifndef EZXML_NOMMAP
+#include <sys/mman.h>
+#endif // EZXML_NOMMAP
+#include <sys/stat.h>
+#include "ezxml.h"
+
+#define EZXML_WS "\t\r</font>
<font color="blue"> " // whitespace
+#define EZXML_ERRL 128 // maximum error string length
+
+typedef struct ezxml_root *ezxml_root_t;
+struct ezxml_root { // additional data for the root tag
+ struct ezxml xml; // is a super-struct built on top of ezxml struct
+ ezxml_t cur; // current xml tree insertion point
+ char *m; // original xml string
+ size_t len; // length of allocated memory for mmap, -1 for malloc
+ char *u; // UTF-8 conversion of string if original was UTF-16
+ char *s; // start of work area
+ char *e; // end of work area
+ char **ent; // general entities (ampersand sequences)
+ char ***attr; // default attributes
+ char ***pi; // processing instructions
+ short standalone; // non-zero if <?xml standalone="yes"?>
+ char err[EZXML_ERRL]; // error string
+};
+
+char *EZXML_NIL[] = { NULL }; // empty, null terminated array of strings
+
+// returns the first child tag with the given name or NULL if not found
+ezxml_t ezxml_child(ezxml_t xml, const char *name)
+{
+ xml = (xml) ? xml->child : NULL;
+ while (xml && strcmp(name, xml->name)) xml = xml->sibling;
+ return xml;
+}
+
+// returns the Nth tag with the same name in the same subsection or NULL if not
+// found
+ezxml_t ezxml_idx(ezxml_t xml, int idx)
+{
+ for (; xml && idx; idx--) xml = xml->next;
+ return xml;
+}
+
+// returns the value of the requested tag attribute or NULL if not found
+const char *ezxml_attr(ezxml_t xml, const char *attr)
+{
+ int i = 0, j = 1;
+ ezxml_root_t root = (ezxml_root_t)xml;
+
+ if (! xml || ! xml->attr) return NULL;
+ while (xml->attr[i] && strcmp(attr, xml->attr[i])) i += 2;
+ if (xml->attr[i]) return xml->attr[i + 1]; // found attribute
+
+ while (root->xml.parent) root = (ezxml_root_t)root->xml.parent; // root tag
+ for (i = 0; root->attr[i] && strcmp(xml->name, root->attr[i][0]); i++);
+ if (! root->attr[i]) return NULL; // no matching default attributes
+ while (root->attr[i][j] && strcmp(attr, root->attr[i][j])) j += 3;
+ return (root->attr[i][j]) ? root->attr[i][j + 1] : NULL; // found default
+}
+
+// same as ezxml_get but takes an already initialized va_list
+ezxml_t ezxml_vget(ezxml_t xml, va_list ap)
+{
+ char *name = va_arg(ap, char *);
+ int idx = -1;
+
+ if (name && *name) {
+ idx = va_arg(ap, int);
+ xml = ezxml_child(xml, name);
+ }
+ return (idx < 0) ? xml : ezxml_vget(ezxml_idx(xml, idx), ap);
+}
+
+// Traverses the xml tree to retrieve a specific subtag. Takes a variable
+// length list of tag names and indexes. The argument list must be terminated
+// by either an index of -1 or an empty string tag name. Example:
+// title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
+// This retrieves the title of the 3rd book on the 1st shelf of library.
+// Returns NULL if not found.
+ezxml_t ezxml_get(ezxml_t xml, ...)
+{
+ va_list ap;
+ ezxml_t r;
+
+ va_start(ap, xml);
+ r = ezxml_vget(xml, ap);
+ va_end(ap);
+ return r;
+}
+
+// returns a null terminated array of processing instructions for the given
+// target
+const char **ezxml_pi(ezxml_t xml, const char *target)
+{
+ ezxml_root_t root = (ezxml_root_t)xml;
+ int i = 0;
+
+ if (! root) return (const char **)EZXML_NIL;
+ while (root->xml.parent) root = (ezxml_root_t)root->xml.parent; // root tag
+ while (root->pi[i] && strcmp(target, root->pi[i][0])) i++; // find target
+ return (const char **)((root->pi[i]) ? root->pi[i] + 1 : EZXML_NIL);
+}
+
+// set an error string and return root
+ezxml_t ezxml_err(ezxml_root_t root, char *s, const char *err, ...)
+{
+ va_list ap;
+ int line = 1;
+ char *t, fmt[EZXML_ERRL];
+
+ for (t = root->s; t < s; t++) if (*t == '</font>
<font color="blue">') line++;
+ snprintf(fmt, EZXML_ERRL, "[error near line %d]: %s", line, err);
+
+ va_start(ap, err);
+ vsnprintf(root->err, EZXML_ERRL, fmt, ap);
+ va_end(ap);
+
+ return &root->xml;
+}
+
+// Recursively decodes entity and character references and normalizes new lines
+// ent is a null terminated array of alternating entity names and values. set t
+// to '&' for general entity decoding, '%' for parameter entity decoding, 'c'
+// for cdata sections, ' ' for attribute normalization, or '*' for non-cdata
+// attribute normalization. Returns s, or if the decoded string is longer than
+// s, returns a malloced string that must be freed.
+char *ezxml_decode(char *s, char **ent, char t)
+{
+ char *e, *r = s, *m = s;
+ long b, c, d, l;
+
+ for (; *s; s++) { // normalize line endings
+ while (*s == '\r') {
+ *(s++) = '</font>
<font color="blue">';
+ if (*s == '</font>
<font color="blue">') memmove(s, (s + 1), strlen(s));
+ }
+ }
+
+ for (s = r; ; ) {
+ while (*s && *s != '&' && (*s != '%' || t != '%') && !isspace(*s)) s++;
+
+ if (! *s) break;
+ else if (t != 'c' && ! strncmp(s, "&#", 2)) { // character reference
+ if (s[2] == 'x') c = strtol(s + 3, &e, 16); // base 16
+ else c = strtol(s + 2, &e, 10); // base 10
+ if (! c || *e != ';') { s++; continue; } // not a character ref
+
+ if (c < 0x80) *(s++) = c; // US-ASCII subset
+ else { // multi-byte UTF-8 sequence
+ for (b = 0, d = c; d; d /= 2) b++; // number of bits in c
+ b = (b - 2) / 5; // number of bytes in payload
+ *(s++) = (0xFF << (7 - b)) | (c >> (6 * b)); // head
+ while (b) *(s++) = 0x80 | ((c >> (6 * --b)) & 0x3F); // payload
+ }
+
+ memmove(s, strchr(s, ';') + 1, strlen(strchr(s, ';')));
+ }
+ else if ((*s == '&' && (t == '&' || t == ' ' || t == '*')) ||
+ (*s == '%' && t == '%')) { // entity reference
+ for (b = 0; ent[b] && strncmp(s + 1, ent[b], strlen(ent[b]));
+ b += 2); // find entity in entity list
+
+ if (ent[b++]) { // found a match
+ if ((c = strlen(ent[b])) - 1 > (e = strchr(s, ';')) - s) {
+ l = (d = (s - r)) + c + strlen(e); // new length
+ r = (r == m) ? strcpy(malloc(l), r) : realloc(r, l);
+ e = strchr((s = r + d), ';'); // fix up pointers
+ }
+
+ memmove(s + c, e + 1, strlen(e)); // shift rest of string
+ strncpy(s, ent[b], c); // copy in replacement text
+ }
+ else s++; // not a known entity
+ }
+ else if ((t == ' ' || t == '*') && isspace(*s)) *(s++) = ' ';
+ else s++; // no decoding needed
+ }
+
+ if (t == '*') { // normalize spaces for non-cdata attributes
+ for (s = r; *s; s++) {
+ if ((l = strspn(s, " "))) memmove(s, s + l, strlen(s + l) + 1);
+ while (*s && *s != ' ') s++;
+ }
+ if (--s >= r && *s == ' ') *s = '\0'; // trim any trailing space
+ }
+ return r;
+}
+
+// called when parser finds start of new tag
+void ezxml_open_tag(ezxml_root_t root, char *name, char **attr)
+{
+ ezxml_t xml = root->cur;
+
+ if (xml->name) xml = ezxml_add_child(xml, name, strlen(xml->txt));
+ else xml->name = name; // first open tag
+
+ xml->attr = attr;
+ root->cur = xml; // update tag insertion point
+}
+
+// called when parser finds character content between open and closing tag
+void ezxml_char_content(ezxml_root_t root, char *s, size_t len, char t)
+{
+ ezxml_t xml = root->cur;
+ char *m = s;
+ size_t l;
+
+ if (! xml || ! xml->name || ! len) return; // sanity check
+
+ s[len] = '\0'; // null terminate text (calling functions anticipate this)
+ len = strlen(s = ezxml_decode(s, root->ent, t)) + 1;
+
+ if (! *(xml->txt)) xml->txt = s; // initial character content
+ else { // allocate our own memory and make a copy
+ xml->txt = (xml->flags & EZXML_TXTM) // allocate some space
+ ? realloc(xml->txt, (l = strlen(xml->txt)) + len)
+ : strcpy(malloc((l = strlen(xml->txt)) + len), xml->txt);
+ strcpy(xml->txt + l, s); // add new char content
+ if (s != m) free(s); // free s if it was malloced by ezxml_decode()
+ }
+
+ if (xml->txt != m) ezxml_set_flag(xml, EZXML_TXTM);
+}
+
+// called when parser finds closing tag
+ezxml_t ezxml_close_tag(ezxml_root_t root, char *name, char *s)
+{
+ if (! root->cur || ! root->cur->name || strcmp(name, root->cur->name))
+ return ezxml_err(root, s, "unexpected closing tag </%s>", name);
+
+ root->cur = root->cur->parent;
+ return NULL;
+}
+
+// checks for circular entity references, returns non-zero if no circular
+// references are found, zero otherwise
+int ezxml_ent_ok(char *name, char *s, char **ent)
+{
+ int i;
+
+ for (; ; s++) {
+ while (*s && *s != '&') s++; // find next entity reference
+ if (! *s) return 1;
+ if (! strncmp(s + 1, name, strlen(name))) return 0; // circular ref.
+ for (i = 0; ent[i] && strncmp(ent[i], s + 1, strlen(ent[i])); i += 2);
+ if (ent[i] && ! ezxml_ent_ok(name, ent[i + 1], ent)) return 0;
+ }
+}
+
+// called when the parser finds a processing instruction
+void ezxml_proc_inst(ezxml_root_t root, char *s, size_t len)
+{
+ int i = 0, j = 1;
+ char *target = s;
+
+ s[len] = '\0'; // null terminate instruction
+ if (*(s += strcspn(s, EZXML_WS))) {
+ *s = '\0'; // null terminate target
+ s += strspn(s + 1, EZXML_WS) + 1; // skip whitespace after target
+ }
+
+ if (! strcmp(target, "xml")) { // <?xml ... ?>
+ if ((s = strstr(s, "standalone")) && ! strncmp(s + strspn(s + 10,
+ EZXML_WS "='\"") + 10, "yes", 3)) root->standalone = 1;
+ return;
+ }
+
+ if (! root->pi[0]) *(root->pi = malloc(sizeof(char **))) = NULL; //first pi
+
+ while (root->pi[i] && strcmp(target, root->pi[i][0])) i++; // find target
+ if (! root->pi[i]) { // new target
+ root->pi = realloc(root->pi, sizeof(char **) * (i + 2));
+ root->pi[i] = malloc(sizeof(char *) * 3);
+ root->pi[i][0] = target;
+ root->pi[i][1] = (char *)(root->pi[i + 1] = NULL); // terminate pi list
+ root->pi[i][2] = strdup(""); // empty document position list
+ }
+
+ while (root->pi[i][j]) j++; // find end of instruction list for this target
+ root->pi[i] = realloc(root->pi[i], sizeof(char *) * (j + 3));
+ root->pi[i][j + 2] = realloc(root->pi[i][j + 1], j + 1);
+ strcpy(root->pi[i][j + 2] + j - 1, (root->xml.name) ? ">" : "<");
+ root->pi[i][j + 1] = NULL; // null terminate pi list for this target
+ root->pi[i][j] = s; // set instruction
+}
+
+// called when the parser finds an internal doctype subset
+short ezxml_internal_dtd(ezxml_root_t root, char *s, size_t len)
+{
+ char q, *c, *t, *n = NULL, *v, **ent, **pe;
+ int i, j;
+
+ pe = memcpy(malloc(sizeof(EZXML_NIL)), EZXML_NIL, sizeof(EZXML_NIL));
+
+ for (s[len] = '\0'; s; ) {
+ while (*s && *s != '<' && *s != '%') s++; // find next declaration
+
+ if (! *s) break;
+ else if (! strncmp(s, "<!ENTITY", 8)) { // parse entity definitions
+ c = s += strspn(s + 8, EZXML_WS) + 8; // skip white space separator
+ n = s + strspn(s, EZXML_WS "%"); // find name
+ *(s = n + strcspn(n, EZXML_WS)) = ';'; // append ; to name
+
+ v = s + strspn(s + 1, EZXML_WS) + 1; // find value
+ if ((q = *(v++)) != '"' && q != '\'') { // skip externals
+ s = strchr(s, '>');
+ continue;
+ }
+
+ for (i = 0, ent = (*c == '%') ? pe : root->ent; ent[i]; i++);
+ ent = realloc(ent, (i + 3) * sizeof(char *)); // space for next ent
+ if (*c == '%') pe = ent;
+ else root->ent = ent;
+
+ *(++s) = '\0'; // null terminate name
+ if ((s = strchr(v, q))) *(s++) = '\0'; // null terminate value
+ ent[i + 1] = ezxml_decode(v, pe, '%'); // set value
+ ent[i + 2] = NULL; // null terminate entity list
+ if (! ezxml_ent_ok(n, ent[i + 1], ent)) { // circular reference
+ if (ent[i + 1] != v) free(ent[i + 1]);
+ ezxml_err(root, v, "circular entity declaration &%s", n);
+ break;
+ }
+ else ent[i] = n; // set entity name
+ }
+ else if (! strncmp(s, "<!ATTLIST", 9)) { // parse default attributes
+ t = s + strspn(s + 9, EZXML_WS) + 9; // skip whitespace separator
+ if (! *t) { ezxml_err(root, t, "unclosed <!ATTLIST"); break; }
+ if (*(s = t + strcspn(t, EZXML_WS ">")) == '>') continue;
+ else *s = '\0'; // null terminate tag name
+ for (i = 0; root->attr[i] && strcmp(n, root->attr[i][0]); i++);
+
+ while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
+ if (*(s = n + strcspn(n, EZXML_WS))) *s = '\0'; // attr name
+ else { ezxml_err(root, t, "malformed <!ATTLIST"); break; }
+
+ s += strspn(s + 1, EZXML_WS) + 1; // find next token
+ c = (strncmp(s, "CDATA", 5)) ? "*" : " "; // is it cdata?
+ if (! strncmp(s, "NOTATION", 8))
+ s += strspn(s + 8, EZXML_WS) + 8;
+ s = (*s == '(') ? strchr(s, ')') : s + strcspn(s, EZXML_WS);
+ if (! s) { ezxml_err(root, t, "malformed <!ATTLIST"); break; }
+
+ s += strspn(s, EZXML_WS ")"); // skip white space separator
+ if (! strncmp(s, "#FIXED", 6))
+ s += strspn(s + 6, EZXML_WS) + 6;
+ if (*s == '#') { // no default value
+ s += strcspn(s, EZXML_WS ">") - 1;
+ if (*c == ' ') continue; // cdata is default, nothing to do
+ v = NULL;
+ }
+ else if ((*s == '"' || *s == '\'') && // default value
+ (s = strchr(v = s + 1, *s))) *s = '\0';
+ else { ezxml_err(root, t, "malformed <!ATTLIST"); break; }
+
+ if (! root->attr[i]) { // new tag name
+ root->attr = (! i) ? malloc(2 * sizeof(char **))
+ : realloc(root->attr,
+ (i + 2) * sizeof(char **));
+ root->attr[i] = malloc(2 * sizeof(char *));
+ root->attr[i][0] = t; // set tag name
+ root->attr[i][1] = (char *)(root->attr[i + 1] = NULL);
+ }
+
+ for (j = 1; root->attr[i][j]; j += 3); // find end of list
+ root->attr[i] = realloc(root->attr[i],
+ (j + 4) * sizeof(char *));
+
+ root->attr[i][j + 3] = NULL; // null terminate list
+ root->attr[i][j + 2] = c; // is it cdata?
+ root->attr[i][j + 1] = (v) ? ezxml_decode(v, root->ent, *c)
+ : NULL;
+ root->attr[i][j] = n; // attribute name
+ }
+ }
+ else if (! strncmp(s, "<!--", 4)) s = strstr(s + 4, "-->"); // comments
+ else if (! strncmp(s, "<?", 2)) { // processing instructions
+ if ((s = strstr(c = s + 2, "?>")))
+ ezxml_proc_inst(root, c, s++ - c);
+ }
+ else if (*s == '<') s = strchr(s, '>'); // skip other declarations
+ else if (*(s++) == '%' && ! root->standalone) break;
+ }
+
+ free(pe);
+ return ! *root->err;
+}
+
+// Converts a UTF-16 string to UTF-8. Returns a new string that must be freed
+// or NULL if no conversion was needed.
+char *ezxml_str2utf8(char **s, size_t *len)
+{
+ char *u;
+ size_t l = 0, sl, max = *len;
+ long c, d;
+ int b, be = (**s == '\xFE') ? 1 : (**s == '\xFF') ? 0 : -1;
+
+ if (be == -1) return NULL; // not UTF-16
+
+ u = malloc(max);
+ for (sl = 2; sl < *len - 1; sl += 2) {
+ c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF) //UTF-16BE
+ : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF); //UTF-16LE
+ if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) { // high-half
+ d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
+ : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
+ c = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000;
+ }
+
+ while (l + 6 > max) u = realloc(u, max += EZXML_BUFSIZE);
+ if (c < 0x80) u[l++] = c; // US-ASCII subset
+ else { // multi-byte UTF-8 sequence
+ for (b = 0, d = c; d; d /= 2) b++; // bits in c
+ b = (b - 2) / 5; // bytes in payload
+ u[l++] = (0xFF << (7 - b)) | (c >> (6 * b)); // head
+ while (b) u[l++] = 0x80 | ((c >> (6 * --b)) & 0x3F); // payload
+ }
+ }
+ return *s = realloc(u, *len = l);
+}
+
+// frees a tag attribute list
+void ezxml_free_attr(char **attr) {
+ int i = 0;
+ char *m;
+
+ if (! attr || attr == EZXML_NIL) return; // nothing to free
+ while (attr[i]) i += 2; // find end of attribute list
+ m = attr[i + 1]; // list of which names and values are malloced
+ for (i = 0; m[i]; i++) {
+ if (m[i] & EZXML_NAMEM) free(attr[i * 2]);
+ if (m[i] & EZXML_TXTM) free(attr[(i * 2) + 1]);
+ }
+ free(m);
+ free(attr);
+}
+
+// parse the given xml string and return an ezxml structure
+ezxml_t ezxml_parse_str(char *s, size_t len)
+{
+ ezxml_root_t root = (ezxml_root_t)ezxml_new(NULL);
+ char q, e, *d, **attr, **a = NULL; // initialize a to avoid compile warning
+ int l, i, j;
+
+ root->m = s;
+ if (! len) return ezxml_err(root, NULL, "root tag missing");
+ root->u = ezxml_str2utf8(&s, &len); // convert utf-16 to utf-8
+ root->e = (root->s = s) + len; // record start and end of work area
+
+ e = s[len - 1]; // save end char
+ s[len - 1] = '\0'; // turn end char into null terminator
+
+ while (*s && *s != '<') s++; // find first tag
+ if (! *s) return ezxml_err(root, s, "root tag missing");
+
+ for (; ; ) {
+ attr = (char **)EZXML_NIL;
+ d = ++s;
+
+ if (isalpha(*s) || *s == '_' || *s == ':' || *s < '\0') { // new tag
+ if (! root->cur)
+ return ezxml_err(root, d, "markup outside of root element");
+
+ s += strcspn(s, EZXML_WS "/>");
+ while (isspace(*s)) *(s++) = '\0'; // null terminate tag name
+
+ if (*s && *s != '/' && *s != '>') // find tag in default attr list
+ for (i = 0; (a = root->attr[i]) && strcmp(a[0], d); i++);
+
+ for (l = 0; *s && *s != '/' && *s != '>'; l += 2) { // new attrib
+ attr = (l) ? realloc(attr, (l + 4) * sizeof(char *))
+ : malloc(4 * sizeof(char *)); // allocate space
+ attr[l + 3] = (l) ? realloc(attr[l + 1], (l / 2) + 2)
+ : malloc(2); // mem for list of maloced vals
+ strcpy(attr[l + 3] + (l / 2), " "); // value is not malloced
+ attr[l + 2] = NULL; // null terminate list
+ attr[l + 1] = ""; // temporary attribute value
+ attr[l] = s; // set attribute name
+
+ s += strcspn(s, EZXML_WS "=/>");
+ if (*s == '=' || isspace(*s)) {
+ *(s++) = '\0'; // null terminate tag attribute name
+ q = *(s += strspn(s, EZXML_WS "="));
+ if (q == '"' || q == '\'') { // attribute value
+ attr[l + 1] = ++s;
+ while (*s && *s != q) s++;
+ if (*s) *(s++) = '\0'; // null terminate attribute val
+ else {
+ ezxml_free_attr(attr);
+ return ezxml_err(root, d, "missing %c", q);
+ }
+
+ for (j = 1; a && a[j] && strcmp(a[j], attr[l]); j +=3);
+ attr[l + 1] = ezxml_decode(attr[l + 1], root->ent, (a
+ && a[j]) ? *a[j + 2] : ' ');
+ if (attr[l + 1] < d || attr[l + 1] > s)
+ attr[l + 3][l / 2] = EZXML_TXTM; // value malloced
+ }
+ }
+ while (isspace(*s)) s++;
+ }
+
+ if (*s == '/') { // self closing tag
+ *(s++) = '\0';
+ if ((*s && *s != '>') || (! *s && e != '>')) {
+ if (l) ezxml_free_attr(attr);
+ return ezxml_err(root, d, "missing >");
+ }
+ ezxml_open_tag(root, d, attr);
+ ezxml_close_tag(root, d, s);
+ }
+ else if ((q = *s) == '>' || (! *s && e == '>')) { // open tag
+ *s = '\0'; // temporarily null terminate tag name
+ ezxml_open_tag(root, d, attr);
+ *s = q;
+ }
+ else {
+ if (l) ezxml_free_attr(attr);
+ return ezxml_err(root, d, "missing >");
+ }
+ }
+ else if (*s == '/') { // close tag
+ s += strcspn(d = s + 1, EZXML_WS ">") + 1;
+ if (! (q = *s) && e != '>') return ezxml_err(root, d, "missing >");
+ *s = '\0'; // temporarily null terminate tag name
+ if (ezxml_close_tag(root, d, s)) return &root->xml;
+ if (isspace(*s = q)) s += strspn(s, EZXML_WS);
+ }
+ else if (! strncmp(s, "!--", 3)) { // xml comment
+ if (! (s = strstr(s + 3, "--")) || (*(s += 2) != '>' && *s) ||
+ (! *s && e != '>')) return ezxml_err(root, d, "unclosed <!--");
+ }
+ else if (! strncmp(s, "![CDATA[", 8)) { // cdata
+ if ((s = strstr(s, "]]>")))
+ ezxml_char_content(root, d + 8, (s += 2) - d - 10, 'c');
+ else return ezxml_err(root, d, "unclosed <![CDATA[");
+ }
+ else if (! strncmp(s, "!DOCTYPE", 8)) { // dtd
+ for (l = 0; *s && ((! l && *s != '>') || (l && (*s != ']' ||
+ *(s + strspn(s + 1, EZXML_WS) + 1) != '>')));
+ l = (*s == '[') ? 1 : l) s += strcspn(s + 1, "[]>") + 1;
+ if (! *s && e != '>')
+ return ezxml_err(root, d, "unclosed <!DOCTYPE");
+ d = (l) ? strchr(d, '[') + 1 : d;
+ if (l && ! ezxml_internal_dtd(root, d, s++ - d)) return &root->xml;
+ }
+ else if (*s == '?') { // <?...?> processing instructions
+ do { s = strchr(s, '?'); } while (s && *(++s) && *s != '>');
+ if (! s || (! *s && e != '>'))
+ return ezxml_err(root, d, "unclosed <?");
+ else ezxml_proc_inst(root, d + 1, s - d - 2);
+ }
+ else return ezxml_err(root, d, "unexpected <");
+
+ if (! s || ! *s) break;
+ *s = '\0';
+ d = ++s;
+ if (*s && *s != '<') { // tag character content
+ while (*s && *s != '<') s++;
+ if (*s) ezxml_char_content(root, d, s - d, '&');
+ else break;
+ }
+ else if (! *s) break;
+ }
+
+ if (! root->cur) return &root->xml;
+ else if (! root->cur->name) return ezxml_err(root, d, "root tag missing");
+ else return ezxml_err(root, d, "unclosed tag <%s>", root->cur->name);
+}
+
+// Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
+// stream into memory and then parses it. For xml files, use ezxml_parse_file()
+// or ezxml_parse_fd()
+ezxml_t ezxml_parse_fp(FILE *fp)
+{
+ ezxml_root_t root;
+ size_t l, len = 0;
+ char *s;
+
+ if (! (s = malloc(EZXML_BUFSIZE))) return NULL;
+ do {
+ len += (l = fread((s + len), 1, EZXML_BUFSIZE, fp));
+ if (l == EZXML_BUFSIZE) s = realloc(s, len + EZXML_BUFSIZE);
+ } while (s && l == EZXML_BUFSIZE);
+
+ if (! s) return NULL;
+ root = (ezxml_root_t)ezxml_parse_str(s, len);
+ root->len = -1; // so we know to free s in ezxml_free()
+ return &root->xml;
+}
+
+// A wrapper for ezxml_parse_str() that accepts a file descriptor. First
+// attempts to mem map the file. Failing that, reads the file into memory.
+// Returns NULL on failure.
+ezxml_t ezxml_parse_fd(int fd)
+{
+ ezxml_root_t root;
+ struct stat st;
+ size_t l;
+ void *m;
+
+ if (fd < 0) return NULL;
+ fstat(fd, &st);
+
+#ifndef EZXML_NOMMAP
+ l = (st.st_size + sysconf(_SC_PAGESIZE) - 1) & ~(sysconf(_SC_PAGESIZE) -1);
+ if ((m = mmap(NULL, l, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) !=
+ MAP_FAILED) {
+ madvise(m, l, MADV_SEQUENTIAL); // optimize for sequential access
+ root = (ezxml_root_t)ezxml_parse_str(m, st.st_size);
+ madvise(m, root->len = l, MADV_NORMAL); // put it back to normal
+ }
+ else { // mmap failed, read file into memory
+#endif // EZXML_NOMMAP
+ l = read(fd, m = malloc(st.st_size), st.st_size);
+ root = (ezxml_root_t)ezxml_parse_str(m, l);
+ root->len = -1; // so we know to free s in ezxml_free()
+#ifndef EZXML_NOMMAP
+ }
+#endif // EZXML_NOMMAP
+ return &root->xml;
+}
+
+// a wrapper for ezxml_parse_fd that accepts a file name
+ezxml_t ezxml_parse_file(const char *file)
+{
+ int fd = open(file, O_RDONLY, 0);
+ ezxml_t xml = ezxml_parse_fd(fd);
+
+ if (fd >= 0) close(fd);
+ return xml;
+}
+
+// Encodes ampersand sequences appending the results to *dst, reallocating *dst
+// if length excedes max. a is non-zero for attribute encoding. Returns *dst
+char *ezxml_ampencode(const char *s, size_t len, char **dst, size_t *dlen,
+ size_t *max, short a)
+{
+ const char *e;
+
+ for (e = s + len; s != e; s++) {
+ while (*dlen + 10 > *max) *dst = realloc(*dst, *max += EZXML_BUFSIZE);
+
+ switch (*s) {
+ case '\0': return *dst;
+ case '&': *dlen += sprintf(*dst + *dlen, "&amp;"); break;
+ case '<': *dlen += sprintf(*dst + *dlen, "&lt;"); break;
+ case '>': *dlen += sprintf(*dst + *dlen, "&gt;"); break;
+ case '"': *dlen += sprintf(*dst + *dlen, (a) ? "&quot;" : "\""); break;
+ case '</font>
<font color="black">': *dlen += sprintf(*dst + *dlen, (a) ? "&#xA;" : "</font>
<font color="blue">"); break;
+ case '\t': *dlen += sprintf(*dst + *dlen, (a) ? "&#x9;" : "\t"); break;
+ case '\r': *dlen += sprintf(*dst + *dlen, "&#xD;"); break;
+ default: (*dst)[(*dlen)++] = *s;
+ }
+ }
+ return *dst;
+}
+
+// Recursively converts each tag to xml appending it to *s. Reallocates *s if
+// its length excedes max. start is the location of the previous tag in the
+// parent tag's character content. Returns *s.
+char *ezxml_toxml_r(ezxml_t xml, char **s, size_t *len, size_t *max,
+ size_t start, char ***attr)
+{
+ int i, j;
+ char *txt = (xml->parent) ? xml->parent->txt : "";
+ size_t off = 0;
+
+ // parent character content up to this tag
+ *s = ezxml_ampencode(txt + start, xml->off - start, s, len, max, 0);
+
+ while (*len + strlen(xml->name) + 4 > *max) // reallocate s
+ *s = realloc(*s, *max += EZXML_BUFSIZE);
+
+ *len += sprintf(*s + *len, "<%s", xml->name); // open tag
+ for (i = 0; xml->attr[i]; i += 2) { // tag attributes
+ if (ezxml_attr(xml, xml->attr[i]) != xml->attr[i + 1]) continue;
+ while (*len + strlen(xml->attr[i]) + 7 > *max) // reallocate s
+ *s = realloc(*s, *max += EZXML_BUFSIZE);
+
+ *len += sprintf(*s + *len, " %s=\"", xml->attr[i]);
+ ezxml_ampencode(xml->attr[i + 1], -1, s, len, max, 1);
+ *len += sprintf(*s + *len, "\"");
+ }
+
+ for (i = 0; attr[i] && strcmp(attr[i][0], xml->name); i++);
+ for (j = 1; attr[i] && attr[i][j]; j += 3) { // default attributes
+ if (! attr[i][j + 1] || ezxml_attr(xml, attr[i][j]) != attr[i][j + 1])
+ continue; // skip duplicates and non-values
+ while (*len + strlen(attr[i][j]) + 7 > *max) // reallocate s
+ *s = realloc(*s, *max += EZXML_BUFSIZE);
+
+ *len += sprintf(*s + *len, " %s=\"", attr[i][j]);
+ ezxml_ampencode(attr[i][j + 1], -1, s, len, max, 1);
+ *len += sprintf(*s + *len, "\"");
+ }
+ *len += sprintf(*s + *len, ">");
+
+ *s = (xml->child) ? ezxml_toxml_r(xml->child, s, len, max, 0, attr) //child
+ : ezxml_ampencode(xml->txt, -1, s, len, max, 0); //data
+
+ while (*len + strlen(xml->name) + 4 > *max) // reallocate s
+ *s = realloc(*s, *max += EZXML_BUFSIZE);
+
+ *len += sprintf(*s + *len, "</%s>", xml->name); // close tag
+
+ while (txt[off] && off < xml->off) off++; // make sure off is within bounds
+ return (xml->ordered) ? ezxml_toxml_r(xml->ordered, s, len, max, off, attr)
+ : ezxml_ampencode(txt + off, -1, s, len, max, 0);
+}
+
+// Converts an ezxml structure back to xml. Returns a string of xml data that
+// must be freed.
+char *ezxml_toxml(ezxml_t xml)
+{
+ ezxml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
+ ezxml_root_t root = (ezxml_root_t)xml;
+ size_t len = 0, max = EZXML_BUFSIZE;
+ char *s = strcpy(malloc(max), ""), *t, *n;
+ int i, j, k;
+
+ if (! xml || ! xml->name) return realloc(s, len + 1);
+ while (root->xml.parent) root = (ezxml_root_t)root->xml.parent; // root tag
+
+ for (i = 0; ! p && root->pi[i]; i++) { // pre-root processing instructions
+ for (k = 2; root->pi[i][k - 1]; k++);
+ for (j = 1; (n = root->pi[i][j]); j++) {
+ if (root->pi[i][k][j - 1] == '>') continue; // not pre-root
+ while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
+ s = realloc(s, max += EZXML_BUFSIZE);
+ len += sprintf(s + len, "<?%s%s%s?></font>
<font color="blue">", t, *n ? " " : "", n);
+ }
+ }
+
+ xml->parent = xml->ordered = NULL;
+ s = ezxml_toxml_r(xml, &s, &len, &max, 0, root->attr);
+ xml->parent = p;
+ xml->ordered = o;
+
+ for (i = 0; ! p && root->pi[i]; i++) { // post-root processing instructions
+ for (k = 2; root->pi[i][k - 1]; k++);
+ for (j = 1; (n = root->pi[i][j]); j++) {
+ if (root->pi[i][k][j - 1] == '<') continue; // not post-root
+ while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max)
+ s = realloc(s, max += EZXML_BUFSIZE);
+ len += sprintf(s + len, "</font>
<font color="blue"><?%s%s%s?>", t, *n ? " " : "", n);
+ }
+ }
+ return realloc(s, len + 1);
+}
+
+// free the memory allocated for the ezxml structure
+void ezxml_free(ezxml_t xml)
+{
+ ezxml_root_t root = (ezxml_root_t)xml;
+ int i, j;
+ char **a, *s;
+
+ if (! xml) return;
+ ezxml_free(xml->child);
+ ezxml_free(xml->ordered);
+
+ if (! xml->parent) { // free root tag allocations
+ for (i = 10; root->ent[i]; i += 2) // 0 - 9 are default entites (<>&"')
+ if ((s = root->ent[i + 1]) < root->s || s > root->e) free(s);
+ free(root->ent); // free list of general entities
+
+ for (i = 0; (a = root->attr[i]); i++) {
+ for (j = 1; a[j++]; j += 2) // free malloced attribute values
+ if (a[j] && (a[j] < root->s || a[j] > root->e)) free(a[j]);
+ free(a);
+ }
+ if (root->attr[0]) free(root->attr); // free default attribute list
+
+ for (i = 0; root->pi[i]; i++) {
+ for (j = 1; root->pi[i][j]; j++);
+ free(root->pi[i][j + 1]);
+ free(root->pi[i]);
+ }
+ if (root->pi[0]) free(root->pi); // free processing instructions
+
+ if (root->len == -1) free(root->m); // malloced xml data
+#ifndef EZXML_NOMMAP
+ else if (root->len) munmap(root->m, root->len); // mem mapped xml data
+#endif // EZXML_NOMMAP
+ if (root->u) free(root->u); // utf8 conversion
+ }
+
+ ezxml_free_attr(xml->attr); // tag attributes
+ if ((xml->flags & EZXML_TXTM)) free(xml->txt); // character content
+ if ((xml->flags & EZXML_NAMEM)) free(xml->name); // tag name
+ free(xml);
+}
+
+// return parser error message or empty string if none
+const char *ezxml_error(ezxml_t xml)
+{
+ while (xml && xml->parent) xml = xml->parent; // find root tag
+ return (xml) ? ((ezxml_root_t)xml)->err : "";
+}
+
+// returns a new empty ezxml structure with the given root tag name
+ezxml_t ezxml_new(const char *name)
+{
+ static char *ent[] = { "lt;", "&#60;", "gt;", "&#62;", "quot;", "&#34;",
+ "apos;", "&#39;", "amp;", "&#38;", NULL };
+ ezxml_root_t root = (ezxml_root_t)memset(malloc(sizeof(struct ezxml_root)),
+ '\0', sizeof(struct ezxml_root));
+ root->xml.name = (char *)name;
+ root->cur = &root->xml;
+ strcpy(root->err, root->xml.txt = "");
+ root->ent = memcpy(malloc(sizeof(ent)), ent, sizeof(ent));
+ root->attr = root->pi = (char ***)(root->xml.attr = EZXML_NIL);
+ return &root->xml;
+}
+
+// inserts an existing tag into an ezxml structure
+ezxml_t ezxml_insert(ezxml_t xml, ezxml_t dest, size_t off)
+{
+ ezxml_t cur, prev, head;
+
+ xml->next = xml->sibling = xml->ordered = NULL;
+ xml->off = off;
+ xml->parent = dest;
+
+ if ((head = dest->child)) { // already have sub tags
+ if (head->off <= off) { // not first subtag
+ for (cur = head; cur->ordered && cur->ordered->off <= off;
+ cur = cur->ordered);
+ xml->ordered = cur->ordered;
+ cur->ordered = xml;
+ }
+ else { // first subtag
+ xml->ordered = head;
+ dest->child = xml;
+ }
+
+ for (cur = head, prev = NULL; cur && strcmp(cur->name, xml->name);
+ prev = cur, cur = cur->sibling); // find tag type
+ if (cur && cur->off <= off) { // not first of type
+ while (cur->next && cur->next->off <= off) cur = cur->next;
+ xml->next = cur->next;
+ cur->next = xml;
+ }
+ else { // first tag of this type
+ if (prev && cur) prev->sibling = cur->sibling; // remove old first
+ xml->next = cur; // old first tag is now next
+ for (cur = head, prev = NULL; cur && cur->off <= off;
+ prev = cur, cur = cur->sibling); // new sibling insert point
+ xml->sibling = cur;
+ if (prev) prev->sibling = xml;
+ }
+ }
+ else dest->child = xml; // only sub tag
+
+ return xml;
+}
+
+// Adds a child tag. off is the offset of the child tag relative to the start
+// of the parent tag's character content. Returns the child tag.
+ezxml_t ezxml_add_child(ezxml_t xml, const char *name, size_t off)
+{
+ ezxml_t child;
+
+ if (! xml) return NULL;
+ child = (ezxml_t)memset(malloc(sizeof(struct ezxml)), '\0',
+ sizeof(struct ezxml));
+ child->name = (char *)name;
+ child->attr = EZXML_NIL;
+ child->txt = "";
+
+ return ezxml_insert(child, xml, off);
+}
+
+// sets the character content for the given tag and returns the tag
+ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt)
+{
+ if (! xml) return NULL;
+ if (xml->flags & EZXML_TXTM) free(xml->txt); // existing txt was malloced
+ xml->flags &= ~EZXML_TXTM;
+ xml->txt = (char *)txt;
+ return xml;
+}
+
+// Sets the given tag attribute or adds a new attribute if not found. A value
+// of NULL will remove the specified attribute. Returns the tag given.
+ezxml_t ezxml_set_attr(ezxml_t xml, const char *name, const char *value)
+{
+ int l = 0, c;
+
+ if (! xml) return NULL;
+ while (xml->attr[l] && strcmp(xml->attr[l], name)) l += 2;
+ if (! xml->attr[l]) { // not found, add as new attribute
+ if (! value) return xml; // nothing to do
+ if (xml->attr == EZXML_NIL) { // first attribute
+ xml->attr = malloc(4 * sizeof(char *));
+ xml->attr[1] = strdup(""); // empty list of malloced names/vals
+ }
+ else xml->attr = realloc(xml->attr, (l + 4) * sizeof(char *));
+
+ xml->attr[l] = (char *)name; // set attribute name
+ xml->attr[l + 2] = NULL; // null terminate attribute list
+ xml->attr[l + 3] = realloc(xml->attr[l + 1],
+ (c = strlen(xml->attr[l + 1])) + 2);
+ strcpy(xml->attr[l + 3] + c, " "); // set name/value as not malloced
+ if (xml->flags & EZXML_DUP) xml->attr[l + 3][c] = EZXML_NAMEM;
+ }
+ else if (xml->flags & EZXML_DUP) free((char *)name); // name was strduped
+
+ for (c = l; xml->attr[c]; c += 2); // find end of attribute list
+ if (xml->attr[c + 1][l / 2] & EZXML_TXTM) free(xml->attr[l + 1]); //old val
+ if (xml->flags & EZXML_DUP) xml->attr[c + 1][l / 2] |= EZXML_TXTM;
+ else xml->attr[c + 1][l / 2] &= ~EZXML_TXTM;
+
+ if (value) xml->attr[l + 1] = (char *)value; // set attribute value
+ else { // remove attribute
+ if (xml->attr[c + 1][l / 2] & EZXML_NAMEM) free(xml->attr[l]);
+ memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char*));
+ xml->attr = realloc(xml->attr, (c + 2) * sizeof(char *));
+ memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1,
+ (c / 2) - (l / 2)); // fix list of which name/vals are malloced
+ }
+ xml->flags &= ~EZXML_DUP; // clear strdup() flag
+ return xml;
+}
+
+// sets a flag for the given tag and returns the tag
+ezxml_t ezxml_set_flag(ezxml_t xml, short flag)
+{
+ if (xml) xml->flags |= flag;
+ return xml;
+}
+
+// removes a tag along with its subtags without freeing its memory
+ezxml_t ezxml_cut(ezxml_t xml)
+{
+ ezxml_t cur;
+
+ if (! xml) return NULL; // nothing to do
+ if (xml->next) xml->next->sibling = xml->sibling; // patch sibling list
+
+ if (xml->parent) { // not root tag
+ cur = xml->parent->child; // find head of subtag list
+ if (cur == xml) xml->parent->child = xml->ordered; // first subtag
+ else { // not first subtag
+ while (cur->ordered != xml) cur = cur->ordered;
+ cur->ordered = cur->ordered->ordered; // patch ordered list
+
+ cur = xml->parent->child; // go back to head of subtag list
+ if (strcmp(cur->name, xml->name)) { // not in first sibling list
+ while (strcmp(cur->sibling->name, xml->name))
+ cur = cur->sibling;
+ if (cur->sibling == xml) { // first of a sibling list
+ cur->sibling = (xml->next) ? xml->next
+ : cur->sibling->sibling;
+ }
+ else cur = cur->sibling; // not first of a sibling list
+ }
+
+ while (cur->next && cur->next != xml) cur = cur->next;
+ if (cur->next) cur->next = cur->next->next; // patch next list
+ }
+ }
+ xml->ordered = xml->sibling = xml->next = NULL;
+ return xml;
+}
+
+#ifdef EZXML_TEST // test harness
+int main(int argc, char **argv)
+{
+ ezxml_t xml;
+ char *s;
+ int i;
+
+ if (argc != 2) return fprintf(stderr, "usage: %s xmlfile</font>
<font color="blue">", argv[0]);
+
+ xml = ezxml_parse_file(argv[1]);
+ printf("%s</font>
<font color="gray">", (s = ezxml_toxml(xml)));
+ free(s);
+ i = fprintf(stderr, "%s", ezxml_error(xml));
+ ezxml_free(xml);
+ return (i) ? 1 : 0;
+}
+#endif // EZXML_TEST
Added: branches/xml_registry/src/registry/ezxml/ezxml.h
===================================================================
--- branches/xml_registry/src/registry/ezxml/ezxml.h         (rev 0)
+++ branches/xml_registry/src/registry/ezxml/ezxml.h        2013-03-14 20:15:45 UTC (rev 2612)
@@ -0,0 +1,167 @@
+/* ezxml.h
+ *
+ * Copyright 2004-2006 Aaron Voisine <aaron@voisine.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _EZXML_H
+#define _EZXML_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <fcntl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define EZXML_BUFSIZE 1024 // size of internal memory buffers
+#define EZXML_NAMEM 0x80 // name is malloced
+#define EZXML_TXTM 0x40 // txt is malloced
+#define EZXML_DUP 0x20 // attribute name and value are strduped
+
+typedef struct ezxml *ezxml_t;
+struct ezxml {
+ char *name; // tag name
+ char **attr; // tag attributes { name, value, name, value, ... NULL }
+ char *txt; // tag character content, empty string if none
+ size_t off; // tag offset from start of parent tag character content
+ ezxml_t next; // next tag with same name in this section at this depth
+ ezxml_t sibling; // next tag with different name in same section and depth
+ ezxml_t ordered; // next tag, same section and depth, in original order
+ ezxml_t child; // head of sub tag list, NULL if none
+ ezxml_t parent; // parent tag, NULL if current tag is root tag
+ short flags; // additional information
+};
+
+// Given a string of xml data and its length, parses it and creates an ezxml
+// structure. For efficiency, modifies the data by adding null terminators
+// and decoding ampersand sequences. If you don't want this, copy the data and
+// pass in the copy. Returns NULL on failure.
+ezxml_t ezxml_parse_str(char *s, size_t len);
+
+// A wrapper for ezxml_parse_str() that accepts a file descriptor. First
+// attempts to mem map the file. Failing that, reads the file into memory.
+// Returns NULL on failure.
+ezxml_t ezxml_parse_fd(int fd);
+
+// a wrapper for ezxml_parse_fd() that accepts a file name
+ezxml_t ezxml_parse_file(const char *file);
+
+// Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
+// stream into memory and then parses it. For xml files, use ezxml_parse_file()
+// or ezxml_parse_fd()
+ezxml_t ezxml_parse_fp(FILE *fp);
+
+// returns the first child tag (one level deeper) with the given name or NULL
+// if not found
+ezxml_t ezxml_child(ezxml_t xml, const char *name);
+
+// returns the next tag of the same name in the same section and depth or NULL
+// if not found
+#define ezxml_next(xml) ((xml) ? xml->next : NULL)
+
+// Returns the Nth tag with the same name in the same section at the same depth
+// or NULL if not found. An index of 0 returns the tag given.
+ezxml_t ezxml_idx(ezxml_t xml, int idx);
+
+// returns the name of the given tag
+#define ezxml_name(xml) ((xml) ? xml->name : NULL)
+
+// returns the given tag's character content or empty string if none
+#define ezxml_txt(xml) ((xml) ? xml->txt : "")
+
+// returns the value of the requested tag attribute, or NULL if not found
+const char *ezxml_attr(ezxml_t xml, const char *attr);
+
+// Traverses the ezxml sturcture to retrieve a specific subtag. Takes a
+// variable length list of tag names and indexes. The argument list must be
+// terminated by either an index of -1 or an empty string tag name. Example:
+// title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
+// This retrieves the title of the 3rd book on the 1st shelf of library.
+// Returns NULL if not found.
+ezxml_t ezxml_get(ezxml_t xml, ...);
+
+// Converts an ezxml structure back to xml. Returns a string of xml data that
+// must be freed.
+char *ezxml_toxml(ezxml_t xml);
+
+// returns a NULL terminated array of processing instructions for the given
+// target
+const char **ezxml_pi(ezxml_t xml, const char *target);
+
+// frees the memory allocated for an ezxml structure
+void ezxml_free(ezxml_t xml);
+
+// returns parser error message or empty string if none
+const char *ezxml_error(ezxml_t xml);
+
+// returns a new empty ezxml structure with the given root tag name
+ezxml_t ezxml_new(const char *name);
+
+// wrapper for ezxml_new() that strdup()s name
+#define ezxml_new_d(name) ezxml_set_flag(ezxml_new(strdup(name)), EZXML_NAMEM)
+
+// Adds a child tag. off is the offset of the child tag relative to the start
+// of the parent tag's character content. Returns the child tag.
+ezxml_t ezxml_add_child(ezxml_t xml, const char *name, size_t off);
+
+// wrapper for ezxml_add_child() that strdup()s name
+#define ezxml_add_child_d(xml, name, off) \
+ ezxml_set_flag(ezxml_add_child(xml, strdup(name), off), EZXML_NAMEM)
+
+// sets the character content for the given tag and returns the tag
+ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt);
+
+// wrapper for ezxml_set_txt() that strdup()s txt
+#define ezxml_set_txt_d(xml, txt) \
+ ezxml_set_flag(ezxml_set_txt(xml, strdup(txt)), EZXML_TXTM)
+
+// Sets the given tag attribute or adds a new attribute if not found. A value
+// of NULL will remove the specified attribute. Returns the tag given.
+ezxml_t ezxml_set_attr(ezxml_t xml, const char *name, const char *value);
+
+// Wrapper for ezxml_set_attr() that strdup()s name/value. Value cannot be NULL
+#define ezxml_set_attr_d(xml, name, value) \
+ ezxml_set_attr(ezxml_set_flag(xml, EZXML_DUP), strdup(name), strdup(value))
+
+// sets a flag for the given tag and returns the tag
+ezxml_t ezxml_set_flag(ezxml_t xml, short flag);
+
+// removes a tag along with its subtags without freeing its memory
+ezxml_t ezxml_cut(ezxml_t xml);
+
+// inserts an existing tag into an ezxml structure
+ezxml_t ezxml_insert(ezxml_t xml, ezxml_t dest, size_t off);
+
+// Moves an existing tag to become a subtag of dest at the given offset from
+// the start of dest's character content. Returns the moved tag.
+#define ezxml_move(xml, dest, off) ezxml_insert(ezxml_cut(xml), dest, off)
+
+// removes a tag along with all its subtags
+#define ezxml_remove(xml) ezxml_free(ezxml_cut(xml))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _EZXML_H
Modified: branches/xml_registry/src/registry/gen_inc.c
===================================================================
--- branches/xml_registry/src/registry/gen_inc.c        2013-03-14 19:21:28 UTC (rev 2611)
+++ branches/xml_registry/src/registry/gen_inc.c        2013-03-14 20:15:45 UTC (rev 2612)
@@ -1159,7 +1159,10 @@
for(i=1; i<=ntime_levs; i++)
{
                                fortprintf(fd, " if(associated(next) .and. associated(prev)) then</font>
<font color="red">");        
-                                fortprintf(fd, " call mpas_create_%s_links(b %% %s %% time_levs(%i) %% %s, prev = prev %% %s %% time_levs(%i) %% %s, next = next %% %s %% time_levs(%i) %% %s)</font>
<font color="blue">", group_ptr->name, group_ptr->name, i, group_ptr->name, i, group_ptr->name, group_ptr->name, i, group_ptr->name);
+//                                fortprintf(fd, " call mpas_create_%s_links(b %% %s %% time_levs(%i) %% %s, prev = prev %% %s %% time_levs(%i) %% %s, next = next %% %s %% time_levs(%i) %% %s)</font>
<font color="blue">", group_ptr->name, group_ptr->name, i, group_ptr->name, i, group_ptr->name, group_ptr->name, i, group_ptr->name);
+                                fortprintf(fd, " call mpas_create_%s_links(b %% %s %% time_levs(%i) %% %s, ", group_ptr->name, group_ptr->name, i, group_ptr->name, i);
+                                fortprintf(fd, " prev = prev %% %s %% time_levs(%i) %% %s,", group_ptr->name, i, group_ptr->name);
+                                fortprintf(fd, " next = next %% %s %% time_levs(%i) %% %s)</font>
<font color="black">", group_ptr->name, i, group_ptr->name);
                                fortprintf(fd, " else if(associated(next)) then</font>
<font color="black">");        
                                fortprintf(fd, " call mpas_create_%s_links(b %% %s %% time_levs(%i) %% %s, next = next %% %s %% time_levs(%i) %% %s)</font>
<font color="black">", group_ptr->name, group_ptr->name, i, group_ptr->name, group_ptr->name, i, group_ptr->name);
                                fortprintf(fd, " else if(associated(prev)) then</font>
<font color="gray">");        
@@ -1387,7 +1390,7 @@
void gen_reads(struct group_list * groups, struct variable * vars, struct dimension * dims)
{
struct variable * var_ptr;
- struct variable_list * var_list_ptr;
+ struct variable_list * var_list_ptr, *var_list_ptr2;
struct dimension * dim_ptr;
struct dimension_list * dimlist_ptr, * lastdim;
struct group_list * group_ptr;
@@ -2117,8 +2120,10 @@
/* fortprintf(fd, " write(0,*) \'adding input field %s\'</font>
<font color="black">", var_ptr->super_array); */
fortprintf(fd, " call MPAS_streamAddField(input_obj %% io_stream, %s %% %s, nferr)</font>
<font color="blue">", struct_deref, var_ptr->super_array);
while (var_list_ptr && strncmp(super_array, var_list_ptr->var->super_array, 1024) == 0) {
+                         var_list_ptr2 = var_list_ptr;
var_list_ptr = var_list_ptr->next;
}
+                        var_list_ptr = var_list_ptr2;
}
else {
fortprintf(fd, " if ((%s %% %s %% ioinfo %% input .and. input_obj %% stream == STREAM_INPUT) .or. &</font>
<font color="gray">", struct_deref, var_ptr->name_in_code);
@@ -2174,8 +2179,10 @@
/* fortprintf(fd, " write(0,*) \'exchange halo for %s\'</font>
<font color="black">", var_ptr->super_array); */
fortprintf(fd, " call mpas_dmpar_exch_halo_field(%s %% %s)</font>
<font color="blue">", struct_deref, var_ptr->super_array);
while (var_list_ptr && strncmp(super_array, var_list_ptr->var->super_array, 1024) == 0) {
+                                                var_list_ptr2 = var_list_ptr;
var_list_ptr = var_list_ptr->next;
}
+                                         var_list_ptr = var_list_ptr2;
}
else {
fortprintf(fd, " if ((%s %% %s %% ioinfo %% input .and. input_obj %% stream == STREAM_INPUT) .or. &</font>
<font color="gray">", struct_deref, var_ptr->name_in_code);
@@ -2381,7 +2388,7 @@
void gen_writes(struct group_list * groups, struct variable * vars, struct dimension * dims, struct namelist * namelists)
{
struct variable * var_ptr;
- struct variable_list * var_list_ptr;
+ struct variable_list * var_list_ptr, *var_list_ptr2;
struct dimension * dim_ptr;
struct dimension_list * dimlist_ptr, * lastdim;
struct group_list * group_ptr;
@@ -2563,8 +2570,10 @@
memcpy(super_array, var_ptr->super_array, 1024);
fortprintf(fd, " call MPAS_streamAddField(output_obj %% io_stream, %s %% %s, ierr)</font>
<font color="blue">", struct_deref, super_array);
while (var_list_ptr && strncmp(super_array, var_list_ptr->var->super_array, 1024) == 0) {
+                         var_list_ptr2 = var_list_ptr;
var_list_ptr = var_list_ptr->next;
}
+                        var_list_ptr = var_list_ptr2;
}
else {
fortprintf(fd, " if ((%s %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &</font>
<font color="gray">", struct_deref, var_ptr->name_in_code);
Modified: branches/xml_registry/src/registry/parse.c
===================================================================
--- branches/xml_registry/src/registry/parse.c        2013-03-14 19:21:28 UTC (rev 2611)
+++ branches/xml_registry/src/registry/parse.c        2013-03-14 20:15:45 UTC (rev 2612)
@@ -3,6 +3,7 @@
#include <string.h>
#include "registry_types.h"
#include "gen_inc.h"
+#include "ezxml/ezxml.h"
int parse_reg(FILE *, struct namelist **, struct dimension **, struct variable **, struct group_list **);
int getword(FILE *, char *);
@@ -30,9 +31,16 @@
nls = NULL;
dims = NULL;
vars = NULL;
+
+ if (parse_reg_xml(regfile, &nls, &dims, &vars, &groups)) {
+ return 1;
+ }
+
+/* Old Parser
if (parse_reg(regfile, &nls, &dims, &vars, &groups)) {
return 1;
}
+*/
sort_vars(vars);
sort_group_vars(groups);
@@ -45,7 +53,391 @@
return 0;
}
+int parse_reg_xml(FILE * regfile, struct namelist **nls, struct dimension ** dims, struct variable ** vars, struct group_list ** groups)
+{
+        struct namelist * nls_ptr, *nls_ptr2;
+        struct namelist * nls_chk_ptr;
+        struct dimension * dim_ptr, *dim_ptr2;
+        struct variable * var_ptr, *var_ptr2;
+        struct dimension_list * dimlist_ptr;
+        struct dimension * dimlist_cursor;
+        struct group_list * grouplist_ptr;
+        struct variable_list * vlist_cursor;
+        ezxml_t registry = ezxml_parse_fp(regfile);
+        ezxml_t dims_xml, dim_xml;
+        ezxml_t structs_xml, var_arr_xml, var_xml;
+        ezxml_t nmlrecs_xml, nmlopt_xml;
+
+        const char *dimname, *dimunits, *dimdesc, *dimdef;
+        const char *nmlrecname, *nmloptname, *nmlopttype, *nmloptval, *nmloptunits, *nmloptdesc, *nmloptposvals;
+        const char *structname, *structlevs;
+        const char *vararrname, *vararrtype, *vararrdims, *vararrpersistence;
+        const char *varname, *varpersistence, *vartype, *vardims, *varunits, *vardesc, *vararrgroup, *varstreams;
+        const char *varname_in_code;
+
+        char dimensions[2048];
+        char *dimension_list;
+        char dimension_buffer[128];
+        char streams_buffer[128];
+
+        NEW_NAMELIST(nls_ptr)
+        NEW_DIMENSION(dim_ptr)
+        NEW_VARIABLE(var_ptr)
+        NEW_GROUP_LIST(grouplist_ptr);
+        *nls = nls_ptr;
+        *dims = dim_ptr;
+        *vars = var_ptr;
+        *groups = grouplist_ptr;
+
+        // Parse Namelist Records
+        for (nmlrecs_xml = ezxml_child(registry, "nml_record"); nmlrecs_xml; nmlrecs_xml = nmlrecs_xml->next){
+                nmlrecname = ezxml_attr(nmlrecs_xml, "name");
+                for (nmlopt_xml = ezxml_child(nmlrecs_xml, "nml_option"); nmlopt_xml; nmlopt_xml = nmlopt_xml->next){
+                        nmloptname = ezxml_attr(nmlopt_xml, "name");
+                        nmlopttype = ezxml_attr(nmlopt_xml, "type");
+                        nmloptval = ezxml_attr(nmlopt_xml, "default_value");
+                        nmloptunits = ezxml_attr(nmlopt_xml, "units");
+                        nmloptdesc = ezxml_attr(nmlopt_xml, "description");
+                        nmloptposvals = ezxml_attr(nmlopt_xml, "possible_values");
+
+                        snprintf(nls_ptr->record, 1024, "%s", nmlrecname);
+                        snprintf(nls_ptr->name, 1024, "%s", nmloptname);
+
+                        if(strncmp(nmlopttype, "real", 1024) == 0){
+                                nls_ptr->vtype = REAL;
+                        } else if(strncmp(nmlopttype, "integer", 1024) == 0){
+                                nls_ptr->vtype = INTEGER;
+                        } else if(strncmp(nmlopttype, "logical", 1024) == 0){
+                                nls_ptr->vtype = LOGICAL;
+                        } else if(strncmp(nmlopttype, "character", 1024) == 0){
+                                nls_ptr->vtype = CHARACTER;
+                        }
+
+                        switch(nls_ptr->vtype){
+                                case REAL:
+                                        nls_ptr->defval.rval = (float)atof(nmloptval);
+                                        break;
+                                case INTEGER:
+                                        nls_ptr->defval.ival = atoi(nmloptval);
+                                        break;
+                                case LOGICAL:
+                                        if(strncmp(nmloptval, "true", 1024) ==0){
+                                                nls_ptr->defval.lval = 1;
+                                        } else if (strncmp(nmloptval, "false", 1024) == 0){
+                                                nls_ptr->defval.lval = 0;
+                                        }
+                                        break;
+                                case CHARACTER:
+                                        snprintf(nls_ptr->defval.cval, 32, "%s", nmloptval);
+                                        break;
+                        }
+
+                        NEW_NAMELIST(nls_ptr->next)
+                        nls_ptr2 = nls_ptr;
+                        nls_ptr = nls_ptr->next;
+                }
+        }
+
+        if(nls_ptr2->next) free(nls_ptr2->next);
+        nls_ptr2->next = NULL;
+
+        // Parse Dimensions
+        for (dims_xml = ezxml_child(registry, "dims"); dims_xml; dims_xml = dims_xml->next){
+                for (dim_xml = ezxml_child(dims_xml, "dim"); dim_xml; dim_xml = dim_xml->next){
+                        dimname = ezxml_attr(dim_xml, "name");
+                        dimdef = ezxml_attr(dim_xml, "definition");        
+                        dimunits = ezxml_attr(dim_xml, "units");
+                        dimdesc = ezxml_attr(dim_xml, "description");
+
+                        dim_ptr->namelist_defined = 0;
+
+                        snprintf(dim_ptr->name_in_file, 1024, "%s", dimname);
+                        if(dimdef == NULL){
+                                snprintf(dim_ptr->name_in_code, 1024, "%s", dimname);
+                                dim_ptr->constant_value = -1;
+                        } else {
+                                snprintf(dim_ptr->name_in_code, 1024, "%s", dimdef);
+                                // Check namelist defined ??
+                                dim_ptr->constant_value = is_integer_constant(dim_ptr->name_in_code);
+                                if(strncmp(dim_ptr->name_in_code, "namelist:", 9) == 0) {
+                                        dim_ptr->namelist_defined = 1;
+                                        snprintf(dim_ptr->name_in_code, 1024, "%s", (dim_ptr->name_in_code)+9);
+
+                                        /* Check that the referenced namelist variable is defined as an integer variable */
+                                        nls_chk_ptr = (*nls)->next;
+                                        while (nls_chk_ptr) {
+                                                if (strncmp(nls_chk_ptr->name, dim_ptr->name_in_code, 1024) == 0) {
+                                                        if (nls_chk_ptr->vtype != INTEGER) {
+                                                                printf("</font>
<font color="black">Registry error: Namelist variable %s must be an integer for namelist-derived dimension %s</font>
<font color="black"></font>
<font color="blue">", nls_chk_ptr->name, dim_ptr->name_in_file);
+                                                                return 1;
+                                                        }
+                                                        break;
+                                                }
+                                                nls_chk_ptr = nls_chk_ptr->next;
+                                        }
+                                        if (!nls_chk_ptr) {
+                                                printf("</font>
<font color="black">Registry error: Namelist variable %s not defined for namelist-derived dimension %s</font>
<font color="black"></font>
<font color="blue">", dim_ptr->name_in_code, dim_ptr->name_in_file);
+                                                return 1;
+                                        }
+
+                                }
+                        }
+
+                        NEW_DIMENSION(dim_ptr->next)
+                        dim_ptr2 = dim_ptr;
+                        dim_ptr = dim_ptr->next;
+                }
+        }
+
+        if(dim_ptr2->next) free(dim_ptr2->next);
+        dim_ptr2->next = NULL;
+
+        // Parse Variable Structures
+        for(structs_xml = ezxml_child(registry, "var_struct"); structs_xml; structs_xml = structs_xml->next){
+                structname = ezxml_attr(structs_xml, "name");
+                structlevs = ezxml_attr(structs_xml, "time_levs");
+
+                grouplist_ptr = *groups;
+                while(grouplist_ptr->next) grouplist_ptr = grouplist_ptr->next;
+                NEW_GROUP_LIST(grouplist_ptr->next);
+                grouplist_ptr = grouplist_ptr->next;
+                snprintf(grouplist_ptr->name, 1024, "%s", structname);
+                vlist_cursor = NULL;
+
+                // Parse variable arrays
+                for(var_arr_xml = ezxml_child(structs_xml, "var_array"); var_arr_xml; var_arr_xml = var_arr_xml->next){
+                        vararrname = ezxml_attr(var_arr_xml, "name");
+                        vararrtype = ezxml_attr(var_arr_xml, "type");
+                        vararrdims = ezxml_attr(var_arr_xml, "dimensions");
+                        vararrpersistence = ezxml_attr(var_arr_xml, "persistence");
+
+                        //Parse variables in variable arrays
+                        for(var_xml = ezxml_child(var_arr_xml, "var"); var_xml; var_xml = var_xml->next){
+                                varname = ezxml_attr(var_xml, "name");
+                                varunits = ezxml_attr(var_xml, "units");
+                                vardesc = ezxml_attr(var_xml, "description");
+                                varstreams = ezxml_attr(var_xml, "streams");
+                                vararrgroup = ezxml_attr(var_xml, "array_group");
+                                varname_in_code = ezxml_attr(var_xml, "name_in_code");
+
+                                if(vlist_cursor == NULL){
+                                        NEW_VARIABLE_LIST(grouplist_ptr->vlist);
+                                        vlist_cursor = grouplist_ptr->vlist;
+                                } else {
+                                        NEW_VARIABLE_LIST(vlist_cursor->next);
+                                        vlist_cursor->next->prev = vlist_cursor;
+                                        vlist_cursor = vlist_cursor->next;
+                                }
+                                vlist_cursor->var = var_ptr;
+                                vlist_cursor->next = NULL;
+
+                                var_ptr->ndims = 0;
+                                var_ptr->timedim = 0;
+                                var_ptr->iostreams = 0;
+
+                                snprintf(var_ptr->name_in_file, 1024, "%s", varname);
+
+                                if(vararrpersistence == NULL){
+                                        var_ptr->persistence = PERSISTENT;
+                                } else {
+                                        if(strncmp(vararrpersistence, "persistent", 1024) == 0){
+                                                var_ptr->persistence = PERSISTENT;
+                                        } else if(strncmp(vararrpersistence, "scratch", 1024) == 0){
+                                                var_ptr->persistence = SCRATCH;
+                                        }
+                                }
+
+                                if(strncmp(vararrtype, "real", 1024) == 0){
+                                        var_ptr->vtype = REAL;
+                                } else if(strncmp(vararrtype, "integer", 1024) == 0){
+                                        var_ptr->vtype = INTEGER;
+                                } else if(strncmp(vararrtype, "logical", 1024) == 0){
+                                        var_ptr->vtype = LOGICAL;
+                                } else if(strncmp(vararrtype, "text", 1024) == 0){
+                                        var_ptr->vtype = CHARACTER;
+                                }
+
+                                NEW_DIMENSION_LIST(dimlist_ptr)
+                                var_ptr->dimlist = dimlist_ptr;
+
+                                snprintf(dimensions,2048, "%s", vararrdims);
+                                dimension_list = strtok(dimensions, " ");
+                                while(dimension_list != NULL){
+                                        snprintf(dimension_buffer, 128, "%s", dimension_list);
+                                        if(strncmp(dimension_buffer, "Time", 1024) == 0){
+                                                var_ptr->timedim = 1;
+                                        } else {
+                                                NEW_DIMENSION_LIST(dimlist_ptr->next)
+                                                dimlist_ptr->next->prev = dimlist_ptr;
+                                                dimlist_ptr = dimlist_ptr->next;
+
+                                                dimlist_cursor = (*dims);
+                                                while(dimlist_cursor && (strncmp(dimension_buffer, dimlist_cursor->name_in_file, 1024) != 0)){
+                                                        dimlist_cursor = dimlist_cursor->next;
+                                                }
+                                                if (dimlist_cursor) {
+                                                        dimlist_ptr->dim = dimlist_cursor;
+                                                } else {
+                                                        fprintf(stderr, "Error: Unknown dimension %s for variable %s</font>
<font color="blue">", dimension_buffer, var_ptr->name_in_file);
+                                                        return 1;
+                                                }
+                                                var_ptr->ndims++;
+                                        }
+                                        dimension_list = strtok(NULL, " ");
+                                }
+                                dimlist_ptr = var_ptr->dimlist;
+                                if(var_ptr->dimlist) var_ptr->dimlist = var_ptr->dimlist->next;
+                                free(dimlist_ptr);
+
+                                var_ptr->ntime_levs = atoi(structlevs);
+
+                                if(varstreams != NULL){
+                                        snprintf(streams_buffer, 128, "%s", varstreams);
+                                        if(strchr(streams_buffer, (int)'i')) var_ptr->iostreams |= INPUT0;
+                                        if(strchr(streams_buffer, (int)'s')) var_ptr->iostreams |= SFC0;
+                                        if(strchr(streams_buffer, (int)'r')) var_ptr->iostreams |= RESTART0;
+                                        if(strchr(streams_buffer, (int)'o')) var_ptr->iostreams |= OUTPUT0;
+                                }
+
+                                if(varname_in_code == NULL){
+                                        snprintf(var_ptr->name_in_code, 1024, "%s", varname);
+                                } else {
+                                        snprintf(var_ptr->name_in_code, 1024, "%s", varname_in_code);
+                                }
+
+                                snprintf(var_ptr->super_array, 1024, "%s", vararrname);
+                                snprintf(var_ptr->array_class, 1024, "%s", vararrgroup);
+
+                                NEW_VARIABLE(var_ptr->next);
+                                var_ptr2 = var_ptr;
+                                var_ptr = var_ptr->next;
+                        }
+                }
+
+                for(var_xml = ezxml_child(structs_xml, "var"); var_xml; var_xml = var_xml->next){
+                        varname = ezxml_attr(var_xml, "name");
+                        varpersistence = ezxml_attr(var_xml, "persistence");
+                        vartype = ezxml_attr(var_xml, "type");
+                        vardims = ezxml_attr(var_xml, "dimensions");
+                        varunits = ezxml_attr(var_xml, "units");
+                        vardesc = ezxml_attr(var_xml, "description");
+                        varstreams = ezxml_attr(var_xml, "streams");
+                        varname_in_code = ezxml_attr(var_xml, "name_in_code");
+
+                        if(vlist_cursor == NULL){
+                                NEW_VARIABLE_LIST(grouplist_ptr->vlist);
+                                vlist_cursor = grouplist_ptr->vlist;
+                        } else {
+                                NEW_VARIABLE_LIST(vlist_cursor->next);
+                                vlist_cursor->next->prev = vlist_cursor;
+                                vlist_cursor = vlist_cursor->next;
+                        }
+                        vlist_cursor->var = var_ptr;
+                        vlist_cursor->next = NULL;
+
+                        var_ptr->ndims = 0;
+                        var_ptr->timedim = 0;
+                        var_ptr->iostreams = 0;
+
+                        snprintf(var_ptr->name_in_file, 1024, "%s", varname);
+
+                        if(varpersistence == NULL){
+                                var_ptr->persistence = PERSISTENT;
+                        } else {
+                                if(strncmp(varpersistence, "persistent", 1024) == 0){
+                                        var_ptr->persistence = PERSISTENT;
+                                } else if(strncmp(varpersistence, "scratch", 1024) == 0){
+                                        var_ptr->persistence = SCRATCH;
+                                }
+                        }
+
+                        if(strncmp(vartype, "real", 1024) == 0){
+                                var_ptr->vtype = REAL;
+                        } else if(strncmp(vartype, "integer", 1024) == 0){
+                                var_ptr->vtype = INTEGER;
+                        } else if(strncmp(vartype, "logical", 1024) == 0){
+                                var_ptr->vtype = LOGICAL;
+                        } else if(strncmp(vartype, "text", 1024) == 0){
+                                var_ptr->vtype = CHARACTER;
+                        }
+
+                        NEW_DIMENSION_LIST(dimlist_ptr)
+                        var_ptr->dimlist = dimlist_ptr;
+
+                        snprintf(dimensions, 2048, "%s", vardims);
+                        dimension_list = strtok(dimensions, " ");
+                        while(dimension_list != NULL){
+                                snprintf(dimension_buffer, 128, "%s", dimension_list);
+                                if(strncmp(dimension_buffer, "Time", 1024) == 0){
+                                        var_ptr->timedim = 1;
+                                } else {
+                                        NEW_DIMENSION_LIST(dimlist_ptr->next)
+                                        dimlist_ptr->next->prev = dimlist_ptr;
+                                        dimlist_ptr = dimlist_ptr->next;
+
+                                        dimlist_cursor = (*dims);
+                                        while(dimlist_cursor && (strncmp(dimension_buffer, dimlist_cursor->name_in_file, 1024) != 0) )
+                                                dimlist_cursor = dimlist_cursor->next;
+                                        if (dimlist_cursor) {
+                                                dimlist_ptr->dim = dimlist_cursor;
+                                        } else {
+                                                fprintf(stderr, "Error: Unknown dimension %s for variable %s</font>
<font color="gray">", dimension_buffer, var_ptr->name_in_file);
+                                                return 1;
+                                        }
+                                        var_ptr->ndims++;
+                                }
+                                dimension_list = strtok(NULL, " ");
+                        }
+
+                        dimlist_ptr = var_ptr->dimlist;
+                        if(var_ptr->dimlist) var_ptr->dimlist = var_ptr->dimlist->next;
+                        free(dimlist_ptr);
+
+                        var_ptr->ntime_levs = atoi(structlevs);
+
+                        if(varstreams != NULL){
+                                snprintf(streams_buffer, 128, "%s", varstreams);
+                                if(strchr(streams_buffer, (int)'i')) {
+                                        var_ptr->iostreams |= INPUT0;
+                                }
+                                if(strchr(streams_buffer, (int)'s')) {
+                                        var_ptr->iostreams |= SFC0;
+                                }
+                                if(strchr(streams_buffer, (int)'r')) {
+                                        var_ptr->iostreams |= RESTART0;
+                                }
+                                if(strchr(streams_buffer, (int)'o')) {
+                                        var_ptr->iostreams |= OUTPUT0;
+                                }
+                        }
+
+                        if(varname_in_code == NULL){
+                                snprintf(var_ptr->name_in_code, 1024, "%s", varname);
+                        } else {
+                                snprintf(var_ptr->name_in_code, 1024, "%s", varname_in_code);
+                        }
+
+                        snprintf(var_ptr->super_array, 1024, "-");
+                        snprintf(var_ptr->array_class, 1024, "-");
+
+                        NEW_VARIABLE(var_ptr->next);
+                        var_ptr2 = var_ptr;
+                        var_ptr = var_ptr->next;
+                }
+        }
+
+        if(var_ptr2->next) free(var_ptr2->next);
+        var_ptr2->next = NULL;
+
+        grouplist_ptr = *groups;
+        if ((*groups)->next) *groups = (*groups)->next;
+        if (grouplist_ptr) free(grouplist_ptr);
+
+        return 0;
+}
+
+
int parse_reg(FILE * regfile, struct namelist ** nls, struct dimension ** dims, struct variable ** vars, struct group_list ** groups)
{
char word[1024];
@@ -228,7 +620,6 @@
vlist_cursor->var = var_ptr;
}
-
getword(regfile, var_ptr->super_array);
getword(regfile, var_ptr->array_class);
@@ -402,7 +793,7 @@
memcpy(super_array, var_ptr->var->super_array, 1024);
var_ptr2_prev = var_ptr;
var_ptr2 = var_ptr->next;
- if (var_ptr2 && strncmp(super_array, var_ptr2->var->super_array, 1024) != 0) {
+ if (var_ptr2 != NULL && strncmp(super_array, var_ptr2->var->super_array, 1024) != 0) {
while (var_ptr2) {
if (strncmp(super_array, var_ptr2->var->super_array, 1024) == 0) {
var_ptr2_prev->next = var_ptr2->next;
</font>
</pre>