├── src ├── editor │ ├── .gitignore │ ├── VarDB │ ├── Categories │ ├── README │ ├── SConscript │ ├── StandardNames │ ├── define.h │ ├── c.cc │ ├── vared.cc │ ├── initv.cc │ ├── fbr.h │ └── Xwin.cc ├── vdb2ncml │ ├── .gitignore │ ├── SConscript │ └── vdb2ncml.cc ├── vdb2xml │ ├── .gitignore │ ├── SConscript │ ├── Dictionary │ └── vdb2xml.cc ├── vardb │ ├── .gitignore │ ├── vdb_test.cc │ ├── vardb_private.hh │ ├── raf │ │ ├── VarDBConverter.hh │ │ └── vardb.h │ ├── sort.cc │ ├── save.cc │ ├── SConscript │ ├── VDBDictionary.cc │ ├── VDBSchema.xsd │ ├── merge.cc │ ├── VDBVar.cc │ ├── vardb.3 │ ├── set.cc │ ├── tags │ ├── category.cc │ ├── std_name.cc │ ├── get.cc │ ├── init.cc │ └── VarDBConverter.cc └── vdbdump │ ├── .gitignore │ ├── SConscript │ ├── vdbdump.py │ ├── xlate.c │ ├── catdump.c │ ├── map_std_name.c │ ├── vdbmerge.c │ ├── vdbdump.cc │ ├── fix_units.cc │ └── set_categories.cc ├── python ├── src │ ├── .gitignore │ └── vardb.cc ├── vardb │ ├── .gitignore │ ├── __init__.py │ └── test_vardb.py ├── winter-real-time.sql.gz └── SConscript ├── tests ├── .gitignore ├── Categories ├── StandardNames └── SConscript ├── .gitignore ├── .gitmodules ├── editpy ├── SConscript ├── newSignal.py ├── delete.py ├── makeSingleRadioButton.py ├── remove.py ├── generateButtons.py ├── windowSetup.py ├── getInfo.py ├── vdbEditor ├── setup.py ├── addSignal.py └── radioClickEvent.py ├── SConstruct ├── Jenkinsfile ├── tool_vardb.py ├── README.md ├── README └── LICENSE /src/editor/.gitignore: -------------------------------------------------------------------------------- 1 | vared 2 | -------------------------------------------------------------------------------- /python/src/.gitignore: -------------------------------------------------------------------------------- 1 | /vardb.os 2 | -------------------------------------------------------------------------------- /src/vdb2ncml/.gitignore: -------------------------------------------------------------------------------- 1 | vdb2ncml 2 | -------------------------------------------------------------------------------- /src/vdb2xml/.gitignore: -------------------------------------------------------------------------------- 1 | vdb2xml 2 | -------------------------------------------------------------------------------- /src/vardb/.gitignore: -------------------------------------------------------------------------------- 1 | /vdbschema.xsd.cc 2 | -------------------------------------------------------------------------------- /src/vdbdump/.gitignore: -------------------------------------------------------------------------------- 1 | vdbdump 2 | fix_units 3 | set_categories 4 | -------------------------------------------------------------------------------- /python/vardb/.gitignore: -------------------------------------------------------------------------------- 1 | /Variable.pyc 2 | /__init__.pyc 3 | /__pycache__ 4 | /_vardb.so 5 | -------------------------------------------------------------------------------- /src/editor/VarDB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NCAR/aircraft_vardb/master/src/editor/VarDB -------------------------------------------------------------------------------- /python/winter-real-time.sql.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NCAR/aircraft_vardb/master/python/winter-real-time.sql.gz -------------------------------------------------------------------------------- /python/vardb/__init__.py: -------------------------------------------------------------------------------- 1 | "vardb package" 2 | 3 | from ._vardb import VDBVar 4 | from ._vardb import VDBFile 5 | 6 | from .Variable import Variable, VariableList, DataStore 7 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | /*~ 2 | /contrast_vardb.xml.saved 3 | /deepwave_vardb.xml.saved 4 | /home-granger-code-aircraft_vardb-tests-contrast_vardb.xml 5 | /vardb_tests 6 | /vg.memcheck.log 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore objects and archives, anywhere in the tree. 2 | *.[oa] 3 | .sconf_temp 4 | .sconsign.dblite 5 | config.log 6 | __pycache__ 7 | /tests/*-tests-contrast_vardb.xml 8 | apidocs 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "site_scons"] 2 | path = site_scons/eol_scons 3 | url = ../eol_scons 4 | [submodule "logx"] 5 | path = logx 6 | url = ../logx 7 | [submodule "domx"] 8 | path = domx 9 | url = ../domx 10 | [submodule "raf"] 11 | path = raf 12 | url = ../libraf 13 | -------------------------------------------------------------------------------- /src/vdbdump/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default', 'prefixoptions', 'vardb', 'vardbconverter']) 4 | 5 | env.Append(CXXFLAGS=Split("-Wall -g -O2")) 6 | 7 | vdbdump = env.Program("vdbdump.cc") 8 | 9 | env.Default(vdbdump) 10 | 11 | if env.get('INSTALL_VARDB') and env['INSTALL_VARDB'] == True: 12 | env.Install(env['INSTALL_PREFIX']+'/bin', vdbdump) 13 | -------------------------------------------------------------------------------- /src/vdb2ncml/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default', 'prefixoptions', 'vardb', 'netcdf', 'raf']) 4 | 5 | env.Append(CXXFLAGS=Split("-Wall -g -O2")) 6 | 7 | vdb2ncml = env.Program("vdb2ncml.cc") 8 | 9 | env.Default(vdb2ncml) 10 | 11 | if env.get('INSTALL_VARDB') and env['INSTALL_VARDB'] == True: 12 | env.Install(env['INSTALL_PREFIX']+'/bin', vdb2ncml) 13 | -------------------------------------------------------------------------------- /src/vdb2xml/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default', 'prefixoptions', 'vardb', 'vardbconverter']) 4 | 5 | env.Append(CXXFLAGS=Split("-std=c++11 -Wall -g -O2")) 6 | 7 | vdb2xml = env.Program("vdb2xml.cc") 8 | 9 | env.Default(vdb2xml) 10 | 11 | if env.get('INSTALL_VARDB') and env['INSTALL_VARDB'] == True: 12 | env.Install(env['INSTALL_PREFIX']+'/bin', vdb2xml) 13 | -------------------------------------------------------------------------------- /tests/Categories: -------------------------------------------------------------------------------- 1 | # 2 | # VarDB Catagory file. 3 | # 4 | # Caveat: don't change an unwanted catagory to something else, assign a 5 | # new number, comment out the one you don't want. 6 | # 7 | 0, None 8 | 1, Position 9 | 2, Thermodynamic 10 | 3, Aircraft State 11 | 4, Atmos. State 12 | 5, Liquid Water 13 | 6, Uncorr'd Raw 14 | 7, Wind 15 | 8, PMS Probe 16 | 9,Housekeeping 17 | 10, Chemistry 18 | 11, Radiation 19 | 12, Non-Standard 20 | -------------------------------------------------------------------------------- /src/editor/Categories: -------------------------------------------------------------------------------- 1 | # 2 | # VarDB Category file. 3 | # 4 | # Caveat: don't change an unwanted category to something else, assign a 5 | # new number, comment out the one you don't want. 6 | # 7 | 0, None 8 | 1, Position 9 | 2, Thermodynamic 10 | 3, Aircraft State 11 | 4, Atmos. State 12 | 5, Liquid Water 13 | 6, Uncorr'd Raw 14 | 7, Wind 15 | 8, PMS Probe 16 | 9, Housekeeping 17 | 10, Chemistry 18 | 11, Radiation 19 | 12, Non-Standard 20 | -------------------------------------------------------------------------------- /src/editor/README: -------------------------------------------------------------------------------- 1 | Directions for editing the Master Varriable DataBase 2 | 3 | cd /home/local/dev/proj/defaults 4 | sccs edit VarDB 5 | 6 | At this point you may get error messages saying someone already has it checked 7 | out. This must be resolved before you can continue. 8 | 9 | vared VarDB 10 | sccs delget VarDB 11 | get_sccs_winds 12 | 13 | The get_sccs_winds command makes a release of WINDS and associated projects. 14 | It might be worthwhile to tell Gary and Chris before doing this last step. 15 | -------------------------------------------------------------------------------- /src/editor/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default', 'prefixoptions', 'vardb', 'netcdf', 'raf']) 4 | 5 | env.Append(CXXFLAGS=Split("-std=c++11 -Wall -g -O2 -Wno-write-strings")) 6 | env.Append(LIBS=Split("Xm Xt X11 Xext")) 7 | 8 | srcs = Split("vared.cc initv.cc Xwin.cc ccb.cc") 9 | 10 | vared = env.Program("vared", srcs) 11 | 12 | env.Default(vared) 13 | 14 | if env.get('INSTALL_VARDB') and env['INSTALL_VARDB'] == True: 15 | env.Install(env['INSTALL_PREFIX']+'/bin', vared) 16 | -------------------------------------------------------------------------------- /src/vardb/vdb_test.cc: -------------------------------------------------------------------------------- 1 | #include "vardb.h" 2 | 3 | std::string fileName("VDB.xml"); 4 | 5 | int main() 6 | { 7 | VDBFile vdb(fileName); 8 | 9 | if (vdb.is_valid() == false) 10 | { 11 | std::cerr << "Failed to open " << fileName << endl; 12 | return 1; 13 | } 14 | 15 | VDBVar *zero = vdb.get_var("ZERO"); 16 | cout<num_vars(); 17 | if(zero->get_attribute("UnIts")=="none") 18 | {cout<<"Looks good!\n"; 19 | }else{cout<<"Check configuration\n";} 20 | 21 | vdb.close(); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /editpy/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default','prefixoptions']) 4 | 5 | modules = Split(""" 6 | addSignal.py 7 | delete.py 8 | generateButtons.py 9 | getInfo.py 10 | makeSingleRadioButton.py 11 | newSignal.py 12 | radioClickEvent.py 13 | remove.py 14 | setup.py 15 | windowSetup.py 16 | """) 17 | 18 | # Targets are only to install files. 19 | if env.get('INSTALL_VARDB') and env['INSTALL_VARDB'] == True: 20 | env.Install(env['INSTALL_PREFIX']+'/bin', 'vdbEditor') 21 | env.Install(env['INSTALL_PREFIX']+'/lib/python/site-packages/vardb', modules) 22 | -------------------------------------------------------------------------------- /src/editor/StandardNames: -------------------------------------------------------------------------------- 1 | # 2 | # VarDB Standard Names file. 3 | # 4 | # Caveat: don't change an unwanted standard_name to something else, assign a 5 | # new number, comment out the one you don't want. 6 | # 7 | 0, None 8 | 1, altitude 9 | 2, air_potential_temperature 10 | 3, air_pressure 11 | 4, air_temperature 12 | 5, dew_point_temperature 13 | 6, geopotential_height 14 | 7, eastward_wind 15 | 8, latitude 16 | 9, longitude 17 | 10, northward_wind 18 | 11, relative_humidity 19 | 12, surface_air_pressure 20 | 13, true_air_speed 21 | 14, upward_air_velocity 22 | 15, wind_from_direction 23 | 16, wind_speed 24 | 17, water_vapor_pressure 25 | 18, zenith_angle 26 | -------------------------------------------------------------------------------- /editpy/newSignal.py: -------------------------------------------------------------------------------- 1 | 2 | from getInfo import getDictionary 3 | from setup import fileName 4 | from radioClickEvent import * 5 | def newSig(self): 6 | 7 | #Deselect qlistwidget 8 | for entry in range(self.left.scrollAreaWidgetContents.count()): 9 | item=self.left.scrollAreaWidgetContents.item(entry) 10 | self.left.scrollAreaWidgetContents.setItemSelected(item,False) 11 | 12 | clearRightInfoHub() 13 | makeRightInfoHub(self,getDictionary(fileName())) 14 | 15 | i=0 16 | for entry in getDictionary(fileName()): 17 | labler(entry,'',self,i) 18 | i+=1 19 | 20 | self.saveButton.clicked.connect(lambda:saveChanges(self,headers,-1)) 21 | 22 | #def adding(self): 23 | 24 | -------------------------------------------------------------------------------- /src/vdb2xml/Dictionary: -------------------------------------------------------------------------------- 1 | # This file configures vardb's dictionary 2 | 3 | units,Units which signal is reported in 4 | long_name,Description of signal 5 | is_analog,Boolean describing if signal is analog. True means the signal is analog 6 | voltage_range,Minimum and maximum voltage [insert voltage units here] 7 | default_sample_rate,Signal's default sample rate 8 | min_limit,Minimum possible value signal can drop to 9 | max_limit,Maximum possible value signal can drop to 10 | category,Used to group signals 11 | modulus_range,We can put a definition here! 12 | derive,We can put a definition here! 13 | dependencies,We can put a definition here! 14 | standard_name,We can put a definition here! 15 | reference,We can put a definition here! 16 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | # This SConstruct does nothing more than load the SConscript in this dir 4 | # The Environment() is created in the SConstruct script 5 | # This dir can be built standalone by executing scons here, or together 6 | # by executing scons in a parent directory 7 | import os 8 | import eol_scons 9 | 10 | def Vardb(env): 11 | env['INSTALL_VARDB'] = install_vdb 12 | env.Require(['prefixoptions']) 13 | # Add NetCDF include path explicitly 14 | 15 | install_vdb = False 16 | if Dir('#') == Dir('.') : 17 | install_vdb = True 18 | 19 | env = Environment(GLOBAL_TOOLS = [Vardb]) 20 | 21 | SConscript('tool_vardb.py') 22 | 23 | variables = env.GlobalVariables() 24 | variables.Update(env) 25 | Help(variables.GenerateHelpText(env)) 26 | -------------------------------------------------------------------------------- /editpy/delete.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #This function comfirms the user desires to remove a variable, and calls the remove function 3 | import getInfo 4 | import remove 5 | from setup import fileName 6 | from PyQt5 import QtWidgets, QtCore 7 | def delete(signame,self,num): 8 | entries=getInfo.getinfo(fileName()) 9 | quit_messge='Are you sure you want to delete '+signame 10 | reply=QtWidgets.QMessageBox.question(self, 'Warning: altering varDB', quit_messge, QtWidgets.QMessageBox.Yes, QtGui.QMessageBox.No) 11 | if reply == QtWidgets.QMessageBox.Yes: 12 | from addSignal import addsignal 13 | from radioClickEvent import lookingAt 14 | from radioClickEvent import clearRightInfoHub 15 | clearRightInfoHub() 16 | #lookingAt(-1,self) 17 | addsignal(signame,self,num,{'action':'delete'}) 18 | -------------------------------------------------------------------------------- /editpy/makeSingleRadioButton.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #This function creates a radio button in the left scroll area, given a name for the button (name), and it's row in varDB.txt (num) 3 | #Chekd is a logical variable. If true, the button will be selected by this program 4 | #import sys 5 | #from PyQt5 import QtGui, QtCore 6 | #from radioClickEvent import lookingAt 7 | def mkbut(num,name,self,chekd): 8 | global rightInfoHub 9 | #button=QtGui.QRadioButton(name,self.left) 10 | #self.left.verticalLayoutScroll.addItem(button) 11 | self.left.scrollAreaWidgetContents.addItem(name) 12 | return 13 | try: 14 | button.clicked.disconnect() 15 | except Exception: pass 16 | button.clicked.connect(lambda: lookingAt(num,self)) 17 | if chekd==True: 18 | button.click() 19 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | node { 4 | label 'CentOS9_x86_64' 5 | } 6 | } 7 | triggers { 8 | pollSCM('H/20 7-20 * * *') 9 | } 10 | stages { 11 | stage('Checkout Scm') { 12 | steps { 13 | git 'eolJenkins:ncar/aircraft_vardb' 14 | } 15 | } 16 | stage('Build') { 17 | steps { 18 | sh 'git submodule update --init --recursive' 19 | sh 'scons' 20 | } 21 | } 22 | } 23 | post { 24 | failure { 25 | emailext to: "cjw@ucar.edu janine@ucar.edu cdewerd@ucar.edu granger@ucar.edu", 26 | subject: "Jenkinsfile aircraft_vardb build failed", 27 | body: "See console output attached", 28 | attachLog: true 29 | } 30 | } 31 | options { 32 | buildDiscarder(logRotator(numToKeepStr: '10')) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/editor/define.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget CreateMainWindow(Widget Shell000); 4 | 5 | 6 | void Initialize(int argc, char *argv[]), 7 | 8 | OpenNewFile(Widget w, XtPointer client, XtPointer call), 9 | OpenNewFile_OK(Widget w, XtPointer client, XmFileSelectionBoxCallbackStruct *call), 10 | SaveFileAs(Widget w, XtPointer client, XtPointer call), 11 | SaveFileAs_OK(Widget w, XtPointer client, XmFileSelectionBoxCallbackStruct *call), 12 | SaveFile(Widget w, XtPointer client, XtPointer call), 13 | EditVariable(Widget w, XtPointer client, XmListCallbackStruct *call), 14 | Accept(Widget w, XtPointer client, XtPointer call), 15 | Clear(Widget w, XtPointer client, XtPointer call), 16 | Delete(Widget w, XtPointer client, XtPointer call), 17 | SetCategory(Widget w, XtPointer client, XtPointer call), 18 | Quit(Widget w, XtPointer client, XtPointer call); 19 | 20 | -------------------------------------------------------------------------------- /editpy/remove.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #This function removes a variable from varDB and radio buttons using it's row number in varDB.txt (num) 3 | import makeSingleRadioButton 4 | from getInfo import getinfo 5 | def rem(num,self): 6 | from generateButtons import generateButtons 7 | varDB=open('varDB.txt','r') 8 | lines = [line.strip() for line in varDB] 9 | varDB.close() 10 | entries=getinfo() 11 | varDB2=open('varDB.txt','w') 12 | for i in reversed(range(self.left.verticalLayoutScroll.count())): #Remove buttons 13 | self.left.verticalLayoutScroll.itemAt(i).widget().setParent(None) 14 | i=0 15 | while i < len(lines): 16 | if inum: #Prevent data shift 19 | varDB2.write(lines[i]+"\n") 20 | i+=1 21 | varDB2.close() 22 | generateButtons(self,self.searchText.text(),0) 23 | print("Remove succesful: ",lines[num]) 24 | 25 | -------------------------------------------------------------------------------- /python/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | env = Environment(tools=['default', 'vardb', 'testing', 'pylint', 4 | 'postgres_testdb', 'boost_python']) 5 | 6 | module = env.SharedLibrary(env.File('vardb/_vardb.so'), ['src/vardb.cc']) 7 | pysrcs = Split("vardb/__init__.py vardb/Variable.py") 8 | tests = Split("vardb/test_vardb.py") 9 | 10 | pg = env.PostgresTestDB() 11 | sql = env.File("winter-real-time.sql.gz") 12 | 13 | env.AppendENVPath('PYTHONPATH', env.Dir("#/../python").get_abspath()) 14 | env.AppendENVPath('PYTHONPATH', env.Dir('.').get_abspath()) 15 | 16 | env.PythonLint('lint', pysrcs, 17 | PYLINTPYTHONPATH=env['ENV']['PYTHONPATH']) 18 | 19 | runtest = env.TestRun('pytests', tests+module+pysrcs+[sql], 20 | [ pg.action_init, 21 | "py.test ${SOURCE}", 22 | pg.action_stop ]) 23 | 24 | # Do not run these tests by default until the module is built by default. 25 | # 26 | # env.DefaultTest(runtest) 27 | -------------------------------------------------------------------------------- /src/vardb/vardb_private.hh: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 2; -*- */ 2 | 3 | #ifndef __vardb_private_hh__ 4 | #define __vardb_private_hh__ 5 | 6 | // Include the vardb.hh interface definition but use the real xerces 7 | // namespace. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | using xercesc::XMLString; 23 | #define _vardb_cc_ 24 | namespace xercesc_forward = xercesc; 25 | #include "raf/vardb.hh" 26 | 27 | using namespace xercesc; 28 | using namespace std; 29 | 30 | 31 | #endif // __vardb_private_hh__ 32 | -------------------------------------------------------------------------------- /src/vardb/raf/VarDBConverter.hh: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface to access older binary VarDB files using the newer C++ interface. 3 | **/ 4 | 5 | 6 | #ifndef _vardb_VDBConverter_hh_ 7 | #define _vardb_VDBConverter_hh_ 8 | 9 | #include "vardb.hh" 10 | 11 | /** 12 | * Open a VarDB file in binary format or XML, transparently converting from 13 | * VarDB to XML if necessary. 14 | **/ 15 | class VarDBConverter 16 | { 17 | public: 18 | 19 | VDBFile* 20 | open(VDBFile* vdb, const std::string& path); 21 | 22 | std::string 23 | defaultOutputPath(); 24 | 25 | std::string 26 | projDirPath(const std::string& filename); 27 | 28 | std::string 29 | defaultProjDirPath(const std::string& filename); 30 | 31 | void 32 | setupProjDir(const std::string& vardbarg); 33 | 34 | void 35 | checkDependencies(VDBFile& vdb); 36 | 37 | void 38 | checkDerivedNames(VDBFile& vdb); 39 | 40 | void 41 | checkModVars(VDBFile& vdb); 42 | 43 | private: 44 | 45 | std::string defaultProjDir; 46 | std::string projDir; 47 | 48 | 49 | 50 | }; 51 | 52 | 53 | 54 | 55 | 56 | #endif // _vardb_VDBConverter_hh_ 57 | 58 | 59 | -------------------------------------------------------------------------------- /tool_vardb.py: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | from SCons.Script import Environment, SConscript, GetOption, AddOption 4 | 5 | 6 | AddOption('--python', 7 | dest='python', 8 | action='store_true', 9 | default=False, 10 | help='compile python dir') 11 | 12 | 13 | def vardb_global(env): 14 | "Copy prefix settings into the prefixoptions." 15 | # The python wrapper must be built as a shared library, and so all the 16 | # libraries it links against must be relocatable, eg liblogx, libdomx, 17 | # and libVarDB. 18 | env.AppendUnique(CXXFLAGS=['-fPIC']) 19 | 20 | 21 | env = Environment(tools=['default', 'prefixoptions'], 22 | GLOBAL_TOOLS=[vardb_global]) 23 | 24 | SConscript('src/vardb/SConscript') 25 | SConscript('src/vdbdump/SConscript') 26 | SConscript('src/vdb2xml/SConscript') 27 | SConscript('src/vdb2ncml/SConscript') 28 | SConscript('editpy/SConscript') 29 | SConscript('src/editor/SConscript') 30 | if GetOption('python'): 31 | SConscript('python/SConscript') 32 | SConscript('tests/SConscript') 33 | 34 | env.Alias('apidocs', env.Dir("apidocs")) 35 | -------------------------------------------------------------------------------- /editpy/generateButtons.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #This function uses varDB to generate radio buttons 3 | #input: 4 | # num is which radio button to leave selected,using getinfo() as reference list 5 | # Filtering is search term 6 | from PyQt5 import QtCore 7 | from getInfo import getinfo 8 | from setup import fileName 9 | def generateButtons(self,filtering,num): 10 | global rightInfoHub 11 | #removes buttons from left 12 | self.left.scrollAreaWidgetContents.clear() 13 | entries=getinfo(fileName()) 14 | i=0 15 | while i=0: 22 | self.left.scrollAreaWidgetContents.setItemSelected(self.left.scrollAreaWidgetContents.item(num),True) 23 | try:self.left.scrollAreaWidgetContents.scrollToItem(self.left.scrollAreaWidgetContents.selectedItems()[0]) 24 | except:pass 25 | -------------------------------------------------------------------------------- /src/vdbdump/vdbdump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Python script to dump contents of the vardb.xml file using the 4 | # python editors internal structure. 5 | # Author : Julian Quick 6 | 7 | import time 8 | import sys 9 | sys.path.append('../editpy') 10 | import getInfo 11 | myList = getInfo.getinfo("../editpy/VDB.xml") 12 | 13 | 14 | # METHOD 1 15 | # Order matters in the XML 16 | # Does not take missing information into account 17 | 18 | # for line in myList: 19 | # print " {0: <20}{1: <25}{2: <28}".format(line[1],line[2],line[3]) 20 | 21 | #============================================== 22 | 23 | # METHOD 2 24 | # This way works with any XML element order 25 | for line in myList: 26 | nameIndex=line[0].index('name')+1 27 | 28 | #if no units exist, 'None' is displayed 29 | try:unitIndex=line[0].index('units')+1 30 | except ValueError: 31 | unitIndex=len(line) 32 | line.append('None') 33 | 34 | try : longNameIndex=line[0].index('long_name')+1 35 | except ValueError: 36 | longNameIndex=len(line) 37 | line.append('None') 38 | 39 | print " {0: <20}{1: <25}{2: <28}".format(line[nameIndex],line[unitIndex],line[longNameIndex]) 40 | 41 | -------------------------------------------------------------------------------- /editpy/windowSetup.py: -------------------------------------------------------------------------------- 1 | #This module sets the window and scroll area for the GUI 2 | #Window Dimensions 3 | import initSelf 4 | self.setGeometry(300, 300, 600, 600) 5 | self.setWindowTitle('varDB GUI') 6 | #Create middle division 7 | hbox = QtWidgets.QHBoxLayout(self) 8 | self.left = QtWidgets.QFrame(self) 9 | self.left.setFrameShape(QtWidgets.QFrame.StyledPanel) 10 | self.right = QtWidgets.QFrame(self) 11 | self.right.setFrameShape(QtWidgets.QFrame.StyledPanel) 12 | splitter1 = QtWidgets.QSplitter(QtCore.Qt.Horizontal) 13 | splitter1.addWidget(self.left) 14 | splitter1.addWidget(self.right) 15 | splitter1.setSizes([150,300]) 16 | hbox.addWidget(splitter1) 17 | self.setLayout(hbox) 18 | QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks')) 19 | #Create scroll area 20 | self.left.scrollArea=QtWidgets.QScrollArea(self.left) 21 | self.left.scrollArea.setWidgetResizable(True) 22 | self.left.scrollAreaWidgetContents=QtWidgets.QWidget(self.left.scrollArea) 23 | self.left.scrollArea.setWidget(self.left.scrollAreaWidgetContents) 24 | self.left.verticalLayout=QtWidgets.QVBoxLayout(self.left) 25 | self.left.verticalLayout.addWidget(self.left.scrollArea) 26 | self.left.verticalLayoutScroll=QtWidgets.QVBoxLayout(self.left.scrollAreaWidgetContents) 27 | 28 | -------------------------------------------------------------------------------- /src/editor/c.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "vardb.h" 7 | 8 | 9 | main() 10 | { 11 | QDomDocument doc("vardb"); 12 | QFile file("VarDB.xml"); 13 | 14 | if ( !file.open( IO_ReadOnly ) ) 15 | return(1); 16 | 17 | if ( !doc.setContent(&file) ) { 18 | file.close(); 19 | return(1); 20 | } 21 | 22 | file.close(); 23 | 24 | 25 | QDomElement docElem = doc.documentElement(); 26 | QDomNode n = docElem.firstChild(); 27 | 28 | while( !n.isNull() ) 29 | { 30 | QDomElement e = n.toElement(); // try to convert the node to an element. 31 | 32 | if ( !e.isNull() ) 33 | { 34 | cout << e.tagName() << "=" << e.attribute("name") << endl; 35 | 36 | if (e.hasChildNodes()) 37 | { 38 | QDomNode ch = e.firstChild(); 39 | 40 | for (ch = e.firstChild(); !ch.isNull(); ch = ch.nextSibling() ) 41 | { 42 | QDomElement e1 = ch.toElement(); 43 | cout << " " << e1.tagName() << "=" << e1.text() << endl; 44 | } 45 | } 46 | } 47 | else 48 | cout << "NULL\n"; 49 | 50 | n = n.nextSibling(); 51 | } 52 | 53 | 54 | /* 55 | struct var_v2 v; 56 | 57 | printf("%u\n", (unsigned)&v.FloatRange - (unsigned)&v); 58 | */ 59 | } 60 | -------------------------------------------------------------------------------- /tests/StandardNames: -------------------------------------------------------------------------------- 1 | # 2 | # VarDB Standard Names file. 3 | # 4 | # Caveat: don't change an unwanted catagory to something else, assign a 5 | # new number, comment out the one you don't want. 6 | # 7 | 0, None 8 | 1, altitude 9 | 2, air_potential_temperature 10 | 3, air_pressure 11 | 4, air_temperature 12 | 5, dew_point_temperature 13 | 6, geopotential_height 14 | 7, eastward_wind 15 | 8, latitude 16 | 9, longitude 17 | 10, northward_wind 18 | 11, relative_humidity 19 | 12, surface_air_pressure 20 | 13, platform_speed_wrt_air 21 | 14, upward_air_velocity 22 | 15, wind_from_direction 23 | 16, wind_speed 24 | 17, water_vapor_pressure 25 | 18, solar_zenith_angle 26 | 19, platform_course 27 | 20, platform_orientation 28 | 21, platform_pitch_angle 29 | 22, platform_roll_angle 30 | 23, platform_speed_wrt_ground 31 | 24, humidity_mixing_ratio 32 | 25, equivelent_potential_temperature 33 | 26, height 34 | 27, atmosphere_cloud_liquid_water_content 35 | 28, air_pressure_at_sea_level 36 | 29, solar_azimuth_angle 37 | 30, solar_elevation_angle 38 | 31, virtual_temperature 39 | 32, atmosphere_number_content_of_aerosol_particles 40 | 33, mole_fraction_of_carbon_dioxide_in_air 41 | 34, mole_fraction_of_methane_in_air 42 | 35, mole_fraction_of_carbon_monoxide_in_air 43 | 36, mole_fraction_of_ozone_in_air 44 | -------------------------------------------------------------------------------- /src/vdbdump/xlate.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: xlate.c 4 | 5 | FULL NAME: Translate to VarDB 6 | 7 | DESCRIPTION: This program converts an old bulletin.9 and plot_attr into 8 | a new VarDB. 9 | 10 | REFERENCES: libVarDB.a 11 | 12 | COPYRIGHT: University Corporation for Atmospheric Research, 1993 13 | ------------------------------------------------------------------------- 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | main(argc, argv) 20 | int argc; 21 | char *argv[]; 22 | { 23 | char buff1[1024], buff2[1024]; 24 | 25 | if (argc < 2) 26 | { 27 | fprintf(stderr, "Usage: xlate proj_num\n"); 28 | exit(1); 29 | } 30 | 31 | snprintf(buff1, 1024, "/home/local/proj/defaults/bulletin.9", argv[1]); 32 | snprintf(buff2, 1024, "/home/local/proj/%s/plot_attr", argv[1]); 33 | 34 | if (CreateVarDB(buff1, buff2) == ERR) 35 | { 36 | fprintf(stderr, "xlate: Translation failed.\n"); 37 | exit(1); 38 | } 39 | 40 | 41 | snprintf(buff1, 1024, "/home/local/proj/%s/VarDB", argv[1]); 42 | 43 | if (SaveVarDB(buff1) == ERR) 44 | { 45 | fprintf(stderr, "xlate: save failure.\n"); 46 | exit(1); 47 | } 48 | 49 | ReleaseVarDB(); 50 | 51 | } /* END MAIN */ 52 | 53 | /* END XLATE.C */ 54 | -------------------------------------------------------------------------------- /src/vardb/sort.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: init.c 4 | 5 | FULL NAME: Initialize 6 | 7 | ENTRY POINTS: SortVarDB() 8 | 9 | DESCRIPTION: 10 | 11 | COPYRIGHT: University Corporation for Atmospheric Research, 1993 12 | ------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | #include 17 | #include "raf/vardb.h" 18 | 19 | extern long VarDB_nRecords; 20 | 21 | /* -------------------------------------------------------------------- */ 22 | void SortVarDB() 23 | { 24 | int i, j; 25 | int swap; 26 | struct var_v2 temp; 27 | 28 | for (i = VarDB_nRecords - 1; i >= 0; --i) 29 | { 30 | swap = FALSE; 31 | 32 | for (j = VarDB_nRecords - 1; j >= 0; --j) 33 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, 34 | ((struct var_v2 *)VarDB)[j].Name) > 0) 35 | { 36 | swap = TRUE; 37 | 38 | memcpy(&temp, &((struct var_v2 *)VarDB)[j], sizeof(struct var_v2)); 39 | 40 | memcpy(&((struct var_v2 *)VarDB)[j], &((struct var_v2 *)VarDB)[i], 41 | sizeof(struct var_v2)); 42 | 43 | memcpy(&((struct var_v2 *)VarDB)[i], &temp, sizeof(struct var_v2)); 44 | } 45 | 46 | if (swap == FALSE) 47 | break; 48 | } 49 | 50 | } /* END SORTVARDB */ 51 | 52 | /* END SORT.C */ 53 | -------------------------------------------------------------------------------- /src/vardb/save.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: save.c 4 | 5 | FULL NAME: Save DB 6 | 7 | ENTRY POINTS: SaveVarDB() 8 | 9 | STATIC FNS: none 10 | 11 | DESCRIPTION: 12 | 13 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2006 14 | ------------------------------------------------------------------------- 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include "raf/vardb.h" 21 | #include 22 | 23 | extern long VarDB_RecLength, VarDB_nRecords; 24 | 25 | /* -------------------------------------------------------------------- */ 26 | int SaveVarDB(const char fileName[]) 27 | { 28 | FILE *fp; 29 | int rc; 30 | 31 | if ((fp = fopen(fileName, "w+")) == NULL) 32 | { 33 | fprintf(stderr, "VarDB: can't open %s\n", fileName); 34 | return(ERR); 35 | } 36 | 37 | varDB_Hdr.nRecords = htonl(VarDB_nRecords); 38 | varDB_Hdr.RecordLen = htonl(VarDB_RecLength); 39 | 40 | fwrite((char *)&varDB_Hdr, sizeof(struct vardb_hdr), 1, fp); 41 | 42 | if ((rc = fwrite((char *)VarDB, VarDB_RecLength, VarDB_nRecords,fp)) != VarDB_nRecords) 43 | { 44 | fprintf(stderr, "VarDB: wrote %d out of %ld entries\n", rc, VarDB_nRecords); 45 | fclose(fp); 46 | return(ERR); 47 | } 48 | 49 | fclose(fp); 50 | return(OK); 51 | 52 | } /* END SAVEVARDB */ 53 | 54 | /* END SAVE.C */ 55 | -------------------------------------------------------------------------------- /src/editor/vared.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vared.c 4 | 5 | FULL NAME: 6 | 7 | DESCRIPTION: 8 | 9 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2005 10 | ------------------------------------------------------------------------- 11 | */ 12 | 13 | // Fix deprecated 'register' keyword used in Motif. 14 | #define register 15 | 16 | #include 17 | 18 | #include "define.h" 19 | #include "fbr.h" 20 | 21 | 22 | Widget Shell000, MainWindow; 23 | 24 | extern "C" { 25 | void CreateErrorBox(Widget); 26 | void CreateWarningBox(Widget); 27 | void CreateFileSelectionBox(Widget); 28 | } 29 | 30 | /* -------------------------------------------------------------------- */ 31 | int main(int argc, char **argv) 32 | { 33 | Widget AppShell; /* The Main Application Shell */ 34 | XtAppContext context; 35 | Arg args[8]; 36 | Cardinal n; 37 | 38 | n = 0; 39 | AppShell = XtAppInitialize(&context, "XmVared", NULL, 0, &argc, argv, 40 | fallback_resources, NULL, 0); 41 | 42 | n = 0; 43 | Shell000 = XtCreatePopupShell("topLevelShell", 44 | topLevelShellWidgetClass, AppShell, args, n); 45 | 46 | MainWindow = CreateMainWindow(Shell000); 47 | 48 | CreateErrorBox(AppShell); 49 | CreateWarningBox(AppShell); 50 | CreateFileSelectionBox(AppShell); 51 | 52 | Initialize(argc, argv); 53 | 54 | XtManageChild(MainWindow); 55 | XtPopup(XtParent(MainWindow), XtGrabNone); 56 | 57 | XtAppMainLoop(context); 58 | 59 | return(0); 60 | 61 | } /* END MAIN */ 62 | 63 | /* END VARED.C */ 64 | -------------------------------------------------------------------------------- /src/editor/initv.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: init.c 4 | 5 | FULL NAME: Initialize Global Variables 6 | 7 | ENTRY POINTS: Initialize() 8 | 9 | STATIC FNS: none 10 | 11 | DESCRIPTION: 12 | 13 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2006 14 | ------------------------------------------------------------------------- 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | // Fix deprecated 'register' keyword used in Motif. 21 | #define register 22 | 23 | #include 24 | 25 | #include "define.h" 26 | #include 27 | 28 | char buffer[1024], FileName[1024], *catList[128], *ProjectDirectory, 29 | *stdNameList[512]; 30 | 31 | extern "C" { 32 | void ShowError(char msg[]); 33 | void WarnUser(char msg[], void (*okCB)(Widget, XtPointer, XtPointer), void (*cancelCB)(Widget, XtPointer, XtPointer)); 34 | 35 | const char * getAircraftName(int num); 36 | } 37 | 38 | /* -------------------------------------------------------------------- */ 39 | void Initialize(int argc, char *argv[]) 40 | { 41 | if (argc < 2) 42 | { 43 | fprintf(stderr, "Usage: vared var_db_file\n"); 44 | exit(1); 45 | } 46 | 47 | int pnum = atoi(argv[1]); 48 | 49 | ProjectDirectory = (char *)getenv("PROJ_DIR"); 50 | 51 | 52 | if (pnum > 99) 53 | snprintf(FileName, 1024, "%s/%d/%s/VarDB", ProjectDirectory, pnum, getAircraftName(pnum)); 54 | else 55 | strcpy(FileName, argv[1]); 56 | 57 | catList[0] = NULL; 58 | stdNameList[0] = NULL; 59 | OpenNewFile_OK(NULL, NULL, NULL); 60 | 61 | } /* END INITIALIZE */ 62 | 63 | /* END INIT.C */ 64 | -------------------------------------------------------------------------------- /editpy/getInfo.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #this function returns a list of each signal's properties 3 | from lxml import etree 4 | def getRef(name,file): 5 | doc=etree.parse(file) 6 | stdnames=[] 7 | for elm in doc.getiterator(name): 8 | i=0 9 | while i 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | extern long VarDB_nRecords; 21 | 22 | /* -------------------------------------------------------------------- */ 23 | int main(int argc, char *argv[]) 24 | { 25 | int i; 26 | 27 | if (argc != 2) 28 | { 29 | fprintf(stderr, "Usage: catdump [proj_num | VarDB_filename]\n"); 30 | exit(1); 31 | } 32 | 33 | if (InitializeVarDB(argv[1]) == ERR) 34 | { 35 | fprintf(stderr, "catdump: Initialize failure.\n"); 36 | exit(1); 37 | } 38 | 39 | 40 | printf("Version %d, with %d records.\n", ntohl(VarDB_Hdr.Version), 41 | VarDB_nRecords); 42 | 43 | for (i = 0; i < VarDB_nRecords; ++i) 44 | { 45 | if (VarDB_GetStandardName(((struct var_v2 *)VarDB)[i].Name) != 0) 46 | printf("%-12.12s %-40.40s %-15.15s %d %s\n", 47 | ((struct var_v2 *)VarDB)[i].Name, 48 | ((struct var_v2 *)VarDB)[i].Title, 49 | VarDB_GetCategoryName(((struct var_v2 *)VarDB)[i].Name), 50 | VarDB_GetStandardName(((struct var_v2 *)VarDB)[i].Name), 51 | VarDB_GetStandardNameName(((struct var_v2 *)VarDB)[i].Name)); 52 | } 53 | 54 | ReleaseVarDB(); 55 | 56 | return(0); 57 | 58 | } /* END MAIN */ 59 | 60 | /* END CATDUMP.C */ 61 | -------------------------------------------------------------------------------- /tests/SConscript: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | import os 4 | 5 | test_sources = Split(""" 6 | test_vdbfile.cc 7 | """) 8 | 9 | def gtest(env): 10 | env.Append(LIBS=['gtest']) 11 | 12 | env = Environment(tools=['default', 'vardb', 'boost_regex', 13 | gtest, 'valgrind', 'testing']) 14 | 15 | tv = env.Program('vardb_tests', test_sources) 16 | 17 | env.Alias('vtest', 18 | env.Test(tv, "cd ${SOURCE.dir} && ./${SOURCE.file} ${GTESTS}")) 19 | 20 | memcheck = env.Command('vg.memcheck.log', [tv], 21 | "cd ${SOURCE.dir} && " 22 | "valgrind --leak-check=full" 23 | " --leak-check=full --show-leak-kinds=all" 24 | " --gen-suppressions=all ./${SOURCE.file} ${GTESTS}" 25 | " >& ${TARGET.abspath}") 26 | env.ValgrindLog('memcheck', memcheck) 27 | 28 | # Smoke test for vdb2xml 29 | vdb2xml = env.File("../src/vdb2xml/vdb2xml") 30 | 31 | def vdb2xml_compare(env, source, xmlin): 32 | xd = None 33 | if os.path.exists(source) and os.path.exists(xmlin): 34 | print("Creating vdb2xml comparison test for %s" % (source)) 35 | xmlname = xmlin.replace('/', '-').strip('-') 36 | xmlout = env.Command([xmlname], [vdb2xml, source], 37 | "${SOURCES[0]} ${SOURCES[1]} ${TARGET}") 38 | xd = env.Diff([xmlout, xmlin]) 39 | env.Alias('test', xd) 40 | else: 41 | print("Skipping comparison test: %s or %s does not exist." % (source, xmlin)) 42 | return xd 43 | 44 | 45 | projdir = os.getenv('PROJ_DIR') 46 | if projdir: 47 | env['ENV']['PROJ_DIR'] = projdir 48 | vdb2xml_compare(env, 49 | projdir+'/DEEPWAVE/GV_N677F/VarDB', 50 | projdir+'/DEEPWAVE/GV_N677F/vardb.xml') 51 | 52 | # Test a direct translation 53 | vdb2xml_compare(env, 'contrast_vardb.xml', env.File('contrast_vardb.xml').abspath) 54 | -------------------------------------------------------------------------------- /src/vardb/VDBDictionary.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 2; -*- */ 2 | 3 | 4 | #include "vardb_private.hh" 5 | 6 | #include 7 | 8 | using domx::xstring; 9 | 10 | VDBDictionary:: 11 | VDBDictionary(xercesc_forward::DOMNode* dictnode): 12 | _dictionary(dictnode) 13 | { 14 | }; 15 | 16 | //--------------------------------------------------------------------------- 17 | // Returns number of entries in dictionary 18 | int 19 | VDBDictionary:: 20 | num_entries() const 21 | { 22 | int nelem = 0; 23 | // Count the definition elements. 24 | DOMNodeList *children = _dictionary->getChildNodes(); 25 | 26 | for (unsigned int i = 0; i < children->getLength(); ++i) 27 | { 28 | DOMElement* elem = domx::asElement(children->item(i)); 29 | if (elem && xstring(elem->getTagName()) == "definition") 30 | { 31 | ++nelem; 32 | } 33 | } 34 | return nelem; 35 | } 36 | 37 | 38 | std::string 39 | VDBDictionary:: 40 | get_entry(int index) 41 | { 42 | int ndef = 0; 43 | DOMNodeList *children = _dictionary->getChildNodes(); 44 | 45 | for (unsigned int i = 0; i < children->getLength(); ++i) 46 | { 47 | DOMElement* elem = domx::asElement(children->item(i)); 48 | if (elem && xstring(elem->getTagName()) == "definition" && ndef++ == index) 49 | { 50 | xstring name; 51 | domx::getAttribute(elem, "name", &name); 52 | return name; 53 | } 54 | } 55 | return ""; 56 | } 57 | 58 | 59 | std::string 60 | VDBDictionary:: 61 | get_definition(const std::string& target) 62 | { 63 | DOMNodeList *children = _dictionary->getChildNodes(); 64 | 65 | for (unsigned int i = 0; i < children->getLength(); ++i) 66 | { 67 | DOMElement* elem = domx::asElement(children->item(i)); 68 | if (elem && xstring(elem->getTagName()) == "definition") 69 | { 70 | xstring name; 71 | domx::getAttribute(elem, "name", &name); 72 | if (name == target) 73 | { 74 | return VDBFile::getTextValue(elem); 75 | } 76 | } 77 | } 78 | return ""; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /editpy/vdbEditor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Julian Quick; July 2014 4 | # GUI TO view and edit varDB 5 | # Several external functions are referenced. See GUI.pdf for flowchart. 6 | 7 | import os 8 | import sys 9 | from PyQt5 import QtWidgets, QtGui, QtCore 10 | 11 | sys.path.append(os.getenv('JLOCAL') + '/lib/python/site-packages') 12 | 13 | import vardb 14 | from vardb.newSignal import newSig 15 | from vardb.generateButtons import generateButtons 16 | from vardb.setup import setup 17 | 18 | class GUI(QtWidgets.QWidget): 19 | def __init__(self): 20 | super(GUI, self).__init__() 21 | self.initUI() 22 | def initUI(self): 23 | self.setGeometry(200, 200, 950, 700) 24 | self.setWindowTitle('Variable DB GUI') 25 | 26 | #Create option buttons 27 | addButton=QtWidgets.QPushButton("Add Variable") 28 | addButton.pressed.connect(lambda: newSig(self)) 29 | self.saveButton=QtWidgets.QPushButton("Save Changes") 30 | self.deleteButton=QtWidgets.QPushButton("Delete Selected variable") 31 | quitButton=QtWidgets.QPushButton("Quit") 32 | quitButton.clicked.connect(QtCore.QCoreApplication.instance().quit) 33 | 34 | #Creates left and right sections, search bar, scroll area 35 | hbox = QtWidgets.QHBoxLayout(self) 36 | self.left = QtWidgets.QFrame(self) 37 | self.upright = QtWidgets.QFrame(self) 38 | self.downright = QtWidgets.QFrame(self) 39 | self=setup(hbox,self, "vardb.xml") 40 | self.searchText.textEdited.connect(lambda: generateButtons(self,str(self.searchText.text()),0)) 41 | self.setLayout(hbox) 42 | 43 | #Populates scroll area 44 | generateButtons(self,'',-1) 45 | 46 | #Option buttons layout 47 | hlox=QtWidgets.QHBoxLayout() 48 | hlox2=QtWidgets.QHBoxLayout() 49 | hlox.addStretch(1) 50 | hlox.addWidget(addButton,1) 51 | hlox.addWidget(self.saveButton,1) 52 | hlox.addWidget(self.deleteButton,1) 53 | hlox.addWidget(quitButton,1) 54 | hlox.addStretch() 55 | vbox=QtGui.QVBoxLayout() 56 | vbox.addStretch(1) 57 | vbox.addLayout(hlox) 58 | vbox.addLayout(hlox2) 59 | self.downright.setLayout(vbox) 60 | 61 | app = QtWidgets.QApplication(sys.argv) 62 | ex = GUI() 63 | ex.show() 64 | app.processEvents() 65 | exit(app.exec_()) 66 | -------------------------------------------------------------------------------- /src/vdb2xml/vdb2xml.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vdb2ncml.cc 4 | 5 | FULL NAME: Convert VarDB to NcML. 6 | 7 | DESCRIPTION: Converts VarDB, Categories, StandardNames, DerivedNames, 8 | DependTable, ModVars and AircraftSpecs to NcML. 9 | 10 | COPYRIGHT: University Corporation for Atmospheric Research, 2006 11 | ------------------------------------------------------------------------- 12 | */ 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | using std::string; 20 | using std::cout; 21 | using std::cerr; 22 | using std::endl; 23 | 24 | 25 | void 26 | usage() 27 | { 28 | cerr << "Usage: vdb2xml [output xml path]\n"; 29 | cerr << "Default output path: /vardb.xml\n"; 30 | cerr << 31 | "PROJ_DIR must be set to locate the ModVars and DerivedNames\n" 32 | "files under $PROJ_DIR/Configuration. The VarDB file typically\n" 33 | "resides in a project directory like PROJ_DIR//,\n" 34 | "so the project directory is derived from .\n" 35 | "Here are the required input files:\n" 36 | " PROJ_DIR/Configuration/ModVars\n" 37 | " PROJ_DIR/Configuration/DerivedNames\n" 38 | " VarDB_dir/DependTable\n" 39 | " VarDB_dir/StandardNames\n" 40 | " VarDB_dir/Categories\n" 41 | "If VarDB_path is already in XML format, then no other files are\n" 42 | "needed to open that file. The file will just be opened and then\n" 43 | "saved to the output path without any conversion.\n"; 44 | } 45 | 46 | 47 | /* -------------------------------------------------------------------- */ 48 | int main(int argc, char *argv[]) 49 | { 50 | if (argc < 2 || argc > 3) 51 | { 52 | usage(); 53 | return 1; 54 | } 55 | string source(argv[1]); 56 | VDBFile vdb; 57 | VarDBConverter vdbc; 58 | vdbc.open(&vdb, source); 59 | if (vdb.is_valid()) 60 | { 61 | string vdbpath = vdbc.defaultOutputPath(); 62 | if (argc > 2) 63 | { 64 | vdbpath = argv[2]; 65 | } 66 | if (vdbpath == source) 67 | { 68 | cerr << "Source and output are the same path, not overwriting." << endl; 69 | } 70 | else 71 | { 72 | cout << "Converted " << source << ", writing to " << vdbpath << "\n"; 73 | vdb.save(vdbpath); 74 | } 75 | return 0; 76 | } 77 | return 1; 78 | } /* END MAIN */ 79 | 80 | /* END VDB2NCML.CC */ 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aircraft_vardb 2 | 3 | A library and collection of programs for manipulating the variable database. The variable database is a master list of all variables for netCDF output, their units, titles, and other miscellaneous metadata. 4 | The variable database does not use an actual database, but is rather an XML file. 5 | 6 | The OAP file format can be found at 7 | 8 | ## Documentation 9 | 10 | Directories in the aircraft_vardb library. 11 | 12 | | Directory | Description | 13 | | ----------- | ----------------------------------------------------------------------------------------- | 14 | | lib | Library routines to open and manipulate a variable database. | 15 | | editor | This is a Motif based editor for editing variables in a specific file. | 16 | | vdbdump | Utility to produce an ASCII dump of a variable database. | 17 | | vdb2xml | Utility to convert an style binary VarDB to new style vardb.xml. | 18 | | vdb2ncml | Utility to convert an style binary VarDB to netCDF NCML output. | 19 | 20 | ## Environment 21 | 22 | The aircraft_vardb libraries are written in C. The utilities build and run on any Unix/Linux operating system, including Mac OS X. 23 | 24 | ## Dependencies 25 | 26 | To install these programs on your computer, ensure the following libraries are installed: 27 | 28 | * python-devel 29 | * log4cpp-devel 30 | * xerces-c-devel 31 | * boost-devel 32 | * netcdf, netcdf-cxx 33 | 34 | These programs depend on libraf, domx, logx, and site_scons, which are included as submodules to this repo. They are automatically downloaded by using --recursive on the command line. 35 | 36 | ### Installation 37 | 38 | The aircraft_vardb libraries can either be installed in the local directory, or redirected to install in a common area (such as /opt/local in a linux system). 39 | 40 | To install everything locally in the current working directory: 41 | 42 | * git clone --recursive 43 | * cd aircraft_vardb 44 | * scons install <- install under vardb/lib, vardb/include, and vardb/bin 45 | 46 | To install in a common area, first download and install site_scons, libraf, domx, and logx in a common area. Then use to --prefix option to point to that area and install libvardb under that same area. 47 | 48 | * scons install INSTALL_PREFIX= <- Install under a dir of your choosing 49 | These libraries may be used by placing a "-lVarDB" in your compile statement. 50 | -------------------------------------------------------------------------------- /src/vdbdump/map_std_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: map_std_name.c 4 | 5 | FULL NAME: VarDB merge 6 | 7 | ENTRY POINTS: main() 8 | 9 | STATIC FNS: none 10 | 11 | DESCRIPTION: Take Standard Name information from master file and map 12 | into an existing file. 13 | VarDB. This allows indivdual copies to be brought upto 14 | date quickly and easily. 15 | 16 | INPUT: FileName 17 | 18 | COPYRIGHT: University Corporation for Atmospheric Research, 2005 19 | ------------------------------------------------------------------------- 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | struct vardb_hdr VarDB_Hdr1, VarDB_Hdr2; 29 | struct var_v2 VarDB1[1000], VarDB2; 30 | 31 | /* -------------------------------------------------------------------- */ 32 | int main(int argc, char *argv[]) 33 | { 34 | FILE *fp1, *fp2; 35 | int rc, masterCount, slaveCount; 36 | int i, j; 37 | 38 | if (argc != 2) 39 | { 40 | fprintf(stderr, "Usage: map_std_name VarDB_filename\n"); 41 | exit(1); 42 | } 43 | 44 | 45 | if ((fp1 = fopen(argv[1], "r+b")) == NULL) 46 | { 47 | fprintf(stderr, "VarDB: can't open %s\n", argv[1]); 48 | return(ERR); 49 | } 50 | 51 | if ((fp2 = fopen("/jnet/tmp/chris/raf/proj/defaults/VarDB", "rb")) == NULL) 52 | { 53 | fprintf(stderr, "VarDB: can't open $JLOCAL/proj/defaults/VarDB\n"); 54 | fclose(fp1); 55 | return(ERR); 56 | } 57 | 58 | fread((char *)&VarDB_Hdr1, sizeof(struct vardb_hdr), 1, fp1); 59 | fread((char *)&VarDB_Hdr2, sizeof(struct vardb_hdr), 1, fp2); 60 | 61 | VarDB_Hdr1.Version = VarDB_Hdr2.Version; 62 | 63 | slaveCount = ntohl(VarDB_Hdr1.nRecords); 64 | masterCount = ntohl(VarDB_Hdr2.nRecords); 65 | fread((char *)VarDB1, sizeof(struct var_v2), slaveCount, fp1); 66 | 67 | for (i = 0; i < masterCount; ++i) 68 | { 69 | fread((char *)&VarDB2, sizeof(struct var_v2), 1, fp2); 70 | 71 | for (j = 0; j < slaveCount; ++j) 72 | if (strcmp(VarDB1[j].Name, VarDB2.Name) == 0) 73 | { 74 | VarDB1[j].standard_name = VarDB2.standard_name; 75 | VarDB1[j].reference = VarDB2.reference; 76 | } 77 | } 78 | 79 | rewind(fp1); 80 | fwrite((char *)&VarDB_Hdr1, sizeof(struct vardb_hdr), 1, fp1); 81 | fwrite((char *)VarDB1, sizeof(struct var_v2), slaveCount, fp1); 82 | 83 | fclose(fp1); 84 | fclose(fp2); 85 | 86 | return(0); 87 | 88 | } /* END MAIN */ 89 | 90 | /* END VDBMERGE.C */ 91 | -------------------------------------------------------------------------------- /src/vdbdump/vdbmerge.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vdbmerge.c 4 | 5 | FULL NAME: VarDB merge 6 | 7 | DESCRIPTION: This merges /home/local/proj/defaults/VarDB into another 8 | VarDB. This allows indivdual copies to be brought upto 9 | date quickly and easily. 10 | 11 | COPYRIGHT: University Corporation for Atmospheric Research, 1993 12 | ------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | struct vardb_hdr VarDB_Hdr1, VarDB_Hdr2; 22 | struct var_v2 VarDB1[1000], VarDB2; 23 | 24 | /* -------------------------------------------------------------------- */ 25 | int main(int argc, char *argv[]) 26 | { 27 | FILE *fp1, *fp2; 28 | int rc, newCount; 29 | int i, j; 30 | int Replaced; 31 | 32 | if (argc != 2) 33 | { 34 | fprintf(stderr, "Usage: vdbmerge VarDB_filename\n"); 35 | exit(1); 36 | } 37 | 38 | 39 | if ((fp1 = fopen(argv[1], "r+b")) == NULL) 40 | { 41 | fprintf(stderr, "VarDB: can't open %s\n", argv[1]); 42 | return(ERR); 43 | } 44 | 45 | if ((fp2 = fopen("/home/local/proj/defaults/VarDB", "rb")) == NULL) 46 | { 47 | fprintf(stderr, "VarDB: can't open $LOCAL/proj/defaults/VarDB\n"); 48 | fclose(fp1); 49 | return(ERR); 50 | } 51 | 52 | fread((char *)&VarDB_Hdr1, sizeof(struct vardb_hdr), 1, fp1); 53 | fread((char *)&VarDB_Hdr2, sizeof(struct vardb_hdr), 1, fp2); 54 | 55 | if (VarDB_Hdr1.Version != VarDB_Hdr2.Version) 56 | { 57 | fprintf(stderr, "VarDB: versions don't match.\n"); 58 | fclose(fp1); 59 | fclose(fp2); 60 | return(ERR); 61 | } 62 | 63 | newCount = ntohl(VarDB_Hdr1.nRecords); 64 | fread((char *)VarDB1, sizeof(struct var_v2), newCount, fp1); 65 | 66 | for (i = 0; i < ntohl(VarDB_Hdr2.nRecords); ++i) 67 | { 68 | fread((char *)&VarDB2, sizeof(struct var_v2), 1, fp2); 69 | 70 | Replaced = FALSE; 71 | 72 | for (j = 0; j < newCount; ++j) 73 | if (strcmp(VarDB1[j].Name, VarDB2.Name) == 0) 74 | { 75 | VarDB1[j] = VarDB2; 76 | Replaced = TRUE; 77 | break; 78 | } 79 | 80 | if (!Replaced) /* then ADD */ 81 | VarDB1[newCount++] = VarDB2; 82 | } 83 | 84 | rewind(fp1); 85 | fwrite((char *)&VarDB_Hdr1, sizeof(struct vardb_hdr), 1, fp1); 86 | fwrite((char *)VarDB1, sizeof(struct var_v2), newCount, fp1); 87 | 88 | fclose(fp1); 89 | fclose(fp2); 90 | 91 | return(0); 92 | 93 | } /* END MAIN */ 94 | 95 | /* END VDBMERGE.C */ 96 | -------------------------------------------------------------------------------- /python/src/vardb.cc: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace boost::python; 5 | 6 | #include "vardb.hh" 7 | 8 | namespace 9 | { 10 | void (VDBFile::*save_filename)(const std::string&) = &VDBFile::save; 11 | VDBVar* (VDBFile::*get_var_string)(const std::string&) = &VDBFile::get_var; 12 | VDBVar* (VDBFile::*get_var_int)(int) = &VDBFile::get_var; 13 | 14 | std::string (VDBVar::*get_attribute) 15 | (const std::string&, const std::string&) const = &VDBVar::get_attribute; 16 | 17 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(get_attribute_overloads, 18 | get_attribute, 1, 2); 19 | 20 | template 21 | list std_vector_to_py_list(const std::vector& v) 22 | { 23 | list result; 24 | for (typename std::vector::const_iterator it = v.begin(); 25 | it != v.end(); ++it) 26 | { 27 | result.append(*it); 28 | } 29 | return result; 30 | } 31 | 32 | list convert_standard_names(VDBFile* vdb) 33 | { 34 | return std_vector_to_py_list(vdb->get_standard_names()); 35 | } 36 | 37 | list convert_categories(VDBFile* vdb) 38 | { 39 | return std_vector_to_py_list(vdb->get_categories()); 40 | } 41 | 42 | } 43 | 44 | 45 | BOOST_PYTHON_MODULE(_vardb) 46 | { 47 | object vdbvar = class_("VDBVar", no_init) 48 | .def("name", &VDBVar::name) 49 | .def("get_attribute", get_attribute, get_attribute_overloads()) 50 | ; 51 | 52 | vdbvar.attr("UNITS") = VDBVar::UNITS; 53 | vdbvar.attr("LONG_NAME") = VDBVar::LONG_NAME; 54 | vdbvar.attr("IS_ANALOG") = VDBVar::IS_ANALOG; 55 | vdbvar.attr("VOLTAGE_RANGE") = VDBVar::VOLTAGE_RANGE; 56 | vdbvar.attr("DEFAULT_SAMPLE_RATE") = VDBVar::DEFAULT_SAMPLE_RATE; 57 | vdbvar.attr("MIN_LIMIT") = VDBVar::MIN_LIMIT; 58 | vdbvar.attr("MAX_LIMIT") = VDBVar::MAX_LIMIT; 59 | vdbvar.attr("CATEGORY") = VDBVar::CATEGORY; 60 | vdbvar.attr("MODULUS_RANGE") = VDBVar::MODULUS_RANGE; 61 | vdbvar.attr("DERIVE") = VDBVar::DERIVE; 62 | vdbvar.attr("DEPENDENCIES") = VDBVar::DEPENDENCIES; 63 | vdbvar.attr("STANDARD_NAME") = VDBVar::STANDARD_NAME; 64 | vdbvar.attr("REFERENCE") = VDBVar::REFERENCE; 65 | 66 | class_("VDBFile", init()) 67 | .def("open", &VDBFile::open) 68 | .def("close", &VDBFile::close) 69 | .def("load", &VDBFile::load) 70 | .def("save", save_filename) 71 | .def("is_valid", &VDBFile::is_valid) 72 | .def("get_var", get_var_string, 73 | return_internal_reference<>()) 74 | .def("get_var_at", get_var_int, 75 | return_internal_reference<>()) 76 | .def("num_vars", &VDBFile::num_vars) 77 | .def("get_standard_names", convert_standard_names) 78 | .def("get_categories", convert_categories) 79 | ; 80 | } 81 | -------------------------------------------------------------------------------- /src/vardb/VDBSchema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /editpy/setup.py: -------------------------------------------------------------------------------- 1 | #Julian QUick 2 | #Sets up GUI Window, scroll area, and data lables 3 | import sys 4 | 5 | fileLocation='NULL' 6 | def fileName(): 7 | return fileLocation 8 | 9 | def setup(hbox,self,file): 10 | 11 | #Establish filename 12 | global fileLocation 13 | if len(sys.argv)==1: 14 | print("please enter filename in command line") 15 | quit() 16 | fileLocation=str(sys.argv[1]) 17 | 18 | self.saveChanges=False 19 | 20 | #some definitions 21 | from radioClickEvent import lookingAt 22 | from PyQt5 import QtWidgets, QtCore 23 | self.booleanList=['reference','is_analog'] 24 | self.catelogList=[['standard_name','standardNames'],['category','Categories']] 25 | 26 | #Create division between right up and down layouts 27 | splitter1=QtWidgets.QSplitter(QtCore.Qt.Vertical) 28 | splitter1.addWidget(self.upright) 29 | splitter1.addWidget(self.downright) 30 | splitter1.setStretchFactor(1,0) 31 | splitter1.setSizes([560,40]) 32 | hbox.addWidget(splitter1) 33 | 34 | #Create middle division 35 | splitter2 = QtWidgets.QSplitter(QtCore.Qt.Horizontal) 36 | splitter2.addWidget(self.left) 37 | splitter2.addWidget(splitter1) 38 | splitter2.setStretchFactor(1,1) 39 | splitter2.setSizes([180,420]) 40 | hbox.addWidget(splitter2) 41 | self.left.setFrameShape(QtWidgets.QFrame.StyledPanel) 42 | self.downright.setFrameShape(QtWidgets.QFrame.StyledPanel) 43 | self.upright.setFrameShape(QtWidgets.QFrame.StyledPanel) 44 | QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks')) 45 | 46 | #=========================================== 47 | #Create scroll areas 48 | 49 | #------------------------------------------------ 50 | #left area 51 | 52 | #Create scroll area 53 | # self.left.scrollArea=QtWidgets.QScrollArea(self.left) 54 | # self.left.scrollArea.setWidgetResizable(True) 55 | # self.left.scrollAreaWidgetContents=QtWidgets.QListWidget(self.left.scrollArea) 56 | 57 | self.left.scrollAreaWidgetContents=QtWidgets.QListWidget(self.left) 58 | 59 | self.left.scrollAreaWidgetContents.itemSelectionChanged.connect(lambda:lookingAt(self)) 60 | # self.left.scrollArea.setWidget(self.left.scrollAreaWidgetContents) 61 | self.left.verticalLayout=QtWidgets.QVBoxLayout(self.left) 62 | self.left.verticalLayoutScroll=QtWidgets.QVBoxLayout(self.left.scrollAreaWidgetContents) 63 | 64 | #Create search bar 65 | searchLabel = QtWidgets.QLabel(" Search", self) 66 | self.searchText = QtWidgets.QLineEdit() 67 | searchLabel.setBuddy(self.searchText) 68 | 69 | #Populate left side 70 | self.left.verticalLayout.addWidget(searchLabel) 71 | self.left.verticalLayout.addWidget(self.searchText) 72 | self.left.verticalLayout.addWidget(self.left.scrollAreaWidgetContents) 73 | 74 | #------------------------------------------------ 75 | #right area 76 | 77 | self.upright.scrollArea=QtWidgets.QScrollArea(self.upright) 78 | self.upright.scrollArea.setWidgetResizable(True) 79 | self.upright.scrollAreaWidgetContents=QtWidgets.QWidget(self.upright.scrollArea) 80 | self.upright.scrollArea.setWidget(self.upright.scrollAreaWidgetContents) 81 | self.upright.verticalLayout=QtWidgets.QVBoxLayout(self.upright) 82 | self.upright.verticalLayout.addWidget(self.upright.scrollArea) 83 | self.upright.verticalLayoutScroll=QtWidgets.QGridLayout(self.upright.scrollAreaWidgetContents) 84 | #self.upright.verticalLayoutScroll=QtWidgets.QVBoxLayout(self.upright.scrollAreaWidgetContents) 85 | #=================================================================== 86 | 87 | return self 88 | -------------------------------------------------------------------------------- /src/vardb/merge.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: merge.c 4 | 5 | FULL NAME: 6 | 7 | ENTRY POINTS: CreateVarDB() 8 | 9 | STATIC FNS: none 10 | 11 | DESCRIPTION: Creates a VarDB from WINDS' Bulliten 9 and plot_attr files. 12 | 13 | NOTES: This file is not fully converted for byte swapping. 14 | 15 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-7 16 | ------------------------------------------------------------------------- 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "raf/vardb.h" 23 | #include 24 | 25 | extern const long VarDB_MagicCookie, VarDB_CurrentVersion; 26 | extern long VarDB_RecLength; 27 | 28 | 29 | /* -------------------------------------------------------------------- */ 30 | int CreateVarDB(const char Bull9_name[], const char Pattr_name[]) 31 | { 32 | int i, j, cnt; 33 | float f1, f2; 34 | char buffer[256], name[VARDB_NL]; 35 | FILE *Bull9, *Pattr; 36 | struct var_v2 *vdb[1024]; 37 | 38 | if ((Bull9 = fopen(Bull9_name, "r")) == NULL) 39 | { 40 | fprintf(stderr, "CreateVarDB: can't open %s\n", Bull9_name); 41 | return(ERR); 42 | } 43 | 44 | if ((Pattr = fopen(Pattr_name, "r")) == NULL) 45 | { 46 | fprintf(stderr, "CreateVarDB: can't open %s\n", Pattr_name); 47 | fclose(Bull9); 48 | return(ERR); 49 | } 50 | 51 | 52 | /* Scan Plot_Attr first, then Bulletin 9. 53 | */ 54 | for (cnt = 0; fgets(buffer, 256, Pattr); ++cnt) 55 | { 56 | vdb[cnt] = (struct var_v2 *)malloc(sizeof(struct var_v2)); 57 | sscanf(buffer, "%s %s %f %f", vdb[cnt]->Name, vdb[cnt]->Units, &f1,&f2); 58 | 59 | strcpy(vdb[cnt]->Title, "No title"); 60 | strcpy(vdb[cnt]->AlternateUnits, ""); 61 | 62 | vdb[cnt]->is_analog = false; 63 | vdb[cnt]->voltageRange[0] = -10; 64 | vdb[cnt]->voltageRange[1] = 10; 65 | vdb[cnt]->defaultSampleRate = 100; 66 | } 67 | 68 | 69 | while (fgets(buffer, 256, Bull9)) 70 | { 71 | if (strlen(buffer) <= 45) 72 | continue; 73 | 74 | sscanf(buffer, "%*44c %*s %s", name); 75 | 76 | for (i = 0; i < cnt; ++i) 77 | if (strcmp(vdb[i]->Name, name) == 0) 78 | { 79 | strncpy(vdb[i]->Title, buffer, 44); 80 | break; 81 | } 82 | 83 | if (i == cnt) /* Not Found, then add */ 84 | { 85 | vdb[cnt] = (struct var_v2 *)malloc(sizeof(struct var_v2)); 86 | sscanf(buffer, "%44c %s %s %f %f", vdb[cnt]->Title, vdb[cnt]->Units, 87 | vdb[cnt]->Name, &f1, &f2); 88 | 89 | strcpy(vdb[cnt]->AlternateUnits, ""); 90 | 91 | vdb[cnt]->is_analog = false; 92 | vdb[cnt]->voltageRange[0] = -10; 93 | vdb[cnt]->voltageRange[1] = 10; 94 | vdb[cnt]->defaultSampleRate = 100; 95 | 96 | ++cnt; 97 | } 98 | 99 | vdb[i]->Title[44] = '\0'; 100 | 101 | for (j = 43; vdb[i]->Title[j] == ' '; --j) 102 | vdb[i]->Title[j] = '\0'; 103 | } 104 | 105 | fclose(Bull9); 106 | fclose(Pattr); 107 | 108 | /* Now transfer the data into the VarDB variables provided by the API 109 | */ 110 | varDB_Hdr.MagicCookie = htonl(VarDB_MagicCookie); 111 | varDB_Hdr.Version = htonl(VarDB_CurrentVersion); 112 | varDB_Hdr.nRecords = htonl(cnt); 113 | varDB_Hdr.RecordLen = htonl(sizeof(struct var_v2)); 114 | 115 | if ((VarDB = (char *)calloc((unsigned)cnt, VarDB_RecLength)) == NULL) 116 | { 117 | fprintf(stderr, "VarDB: calloc failure\n"); 118 | return(ERR); 119 | } 120 | 121 | for (i = 0; i < cnt; ++i) 122 | { 123 | memcpy((char *)&((struct var_v2 *)VarDB)[i], (char *)vdb[i], 124 | sizeof(struct var_v2)); 125 | free(vdb[i]); 126 | } 127 | 128 | return(OK); 129 | 130 | } /* END CREATEVARDB */ 131 | 132 | /* END MERGE.C */ 133 | -------------------------------------------------------------------------------- /src/vardb/VDBVar.cc: -------------------------------------------------------------------------------- 1 | /* -*- mode: C++; c-basic-offset: 2; -*- 2 | * ------------------------------------------------------------------------- 3 | * OBJECT NAME: vardb.cc 4 | * 5 | * FULL NAME: VarDB C++ API 6 | * 7 | * TYPE: API 8 | * 9 | * DESCRIPTION: This is an API to edit Vardb xml. 10 | * 11 | * COPYRIGHT: University Corporation for Atmospheric Research, 2014 12 | * ------------------------------------------------------------------------- 13 | */ 14 | 15 | 16 | #include "vardb_private.hh" 17 | 18 | #include 19 | 20 | #include "domx/XML.h" 21 | using domx::xstring; 22 | 23 | const std::string VDBVar::UNITS = "units"; 24 | const std::string VDBVar::LONG_NAME = "long_name"; 25 | const std::string VDBVar::IS_ANALOG = "is_analog"; 26 | const std::string VDBVar::VOLTAGE_RANGE = "voltage_range"; 27 | const std::string VDBVar::DEFAULT_SAMPLE_RATE = "default_sample_rate"; 28 | const std::string VDBVar::MIN_LIMIT = "min_limit"; 29 | const std::string VDBVar::MAX_LIMIT = "max_limit"; 30 | const std::string VDBVar::CATEGORY = "category"; 31 | const std::string VDBVar::MODULUS_RANGE = "modulus_range"; 32 | const std::string VDBVar::DERIVE = "derive"; 33 | const std::string VDBVar::DEPENDENCIES = "dependencies"; 34 | const std::string VDBVar::STANDARD_NAME = "standard_name"; 35 | const std::string VDBVar::REFERENCE = "reference"; 36 | 37 | 38 | VDBVar:: 39 | VDBVar(xercesc_forward::DOMElement* node) : 40 | _variable(node) 41 | { 42 | } 43 | 44 | 45 | std::string 46 | VDBVar:: 47 | name() const 48 | { 49 | DOMNamedNodeMap* atts = _variable->getAttributes(); 50 | DOMNode* name = atts->getNamedItem(xstring("name")); 51 | return xstring(name->getNodeValue()); 52 | } 53 | 54 | 55 | std::string 56 | VDBVar:: 57 | get_attribute(int index) const 58 | { 59 | xstring name; 60 | DOMNodeList* x = _variable->getChildNodes(); 61 | int nelem = 0; 62 | 63 | for (unsigned int i = 0; i < x->getLength(); ++i) 64 | { 65 | // Only ELEMENT children are attributes. 66 | DOMElement* elem = domx::asElement(x->item(i)); 67 | if (!elem) 68 | { 69 | continue; 70 | } 71 | if (nelem == index) 72 | { 73 | name = elem->getTagName(); 74 | break; 75 | } 76 | ++nelem; 77 | } 78 | return name; 79 | } 80 | 81 | 82 | int 83 | VDBVar:: 84 | num_atts() const 85 | { 86 | DOMNodeList* x = _variable->getChildNodes(); 87 | int nelem = 0; 88 | 89 | for (unsigned int i = 0; i < x->getLength(); ++i) 90 | { 91 | // Only ELEMENT children are attributes. 92 | if (domx::asElement(x->item(i))) 93 | { 94 | ++nelem; 95 | } 96 | } 97 | return nelem; 98 | } 99 | 100 | 101 | std::string 102 | VDBVar:: 103 | get_attribute(const std::string& attr_name, const std::string& dfault) const 104 | { 105 | DOMElement* attnode = domx::findElement(_variable, attr_name); 106 | std::string answer = dfault; 107 | 108 | if (attnode) 109 | { 110 | answer = VDBFile::getTextValue(attnode); 111 | } 112 | return answer; 113 | } 114 | 115 | 116 | bool 117 | VDBVar:: 118 | has_attribute(const std::string& name) 119 | { 120 | return bool(domx::findElement(_variable, name)); 121 | } 122 | 123 | 124 | template<> 125 | void 126 | VDBVar:: 127 | set_attribute(const std::string& attr_name, const std::string& value) 128 | { 129 | DOMDocument* doc = _variable->getOwnerDocument(); 130 | DOMElement* attnode = domx::findElement(_variable, attr_name); 131 | if (!_variable->getFirstChild()) 132 | { 133 | _variable->appendChild(VDBFile::newlineNode(doc, 2)); 134 | } 135 | if (!attnode) 136 | { 137 | attnode = doc->createElement(xstring(attr_name)); 138 | _variable->appendChild(VDBFile::indentNode(doc)); 139 | _variable->appendChild(attnode); 140 | _variable->appendChild(VDBFile::newlineNode(doc, 2)); 141 | } 142 | // Replace any current value in this node. 143 | domx::removeChildren(attnode); 144 | attnode->appendChild(doc->createTextNode(xstring(value))); 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/vdbdump/vdbdump.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vdbdump.cc 4 | 5 | FULL NAME: VarDB dump 6 | 7 | DESCRIPTION: This program does a basic text dump of a Variable DataBase 8 | file. 9 | 10 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2014 11 | ------------------------------------------------------------------------- 12 | */ 13 | 14 | #include 15 | #include 16 | #include //for getopt 17 | #include // for setw 18 | 19 | #include 20 | #include 21 | 22 | bool tracker = false; 23 | 24 | using namespace std; 25 | 26 | 27 | /* -------------------------------------------------------------------- */ 28 | void print_usage() 29 | { 30 | cout << "Usage: vdbdump [options] [proj_num | VarDB_filename]\n" 31 | << "Options:\n" 32 | << " -h Display this message\n" 33 | << " -a Disabled legacy: stream without newlines, different formatting \n" 34 | << " -c Category\n" 35 | << " -u Units\n" 36 | << " -l Long_name\n"; 37 | } 38 | 39 | /* -------------------------------------------------------------------- */ 40 | int 41 | main(int argc, char *argv[]) 42 | { 43 | char opt; 44 | vector attribute_names; 45 | vector width; 46 | vector substring_length; 47 | bool user_format_specified = false; 48 | 49 | if (argc < 2) 50 | { 51 | print_usage(); 52 | return(1); 53 | } 54 | 55 | 56 | while ((opt = getopt(argc, argv, "aulch"))!= -1) { 57 | switch (opt) { 58 | case 'a': 59 | //tracker = true; 60 | //i = 1; 61 | // uncertain what this is for 62 | // breaking to find use cases 63 | cout << "Unknown use for -a: please revise" << endl; 64 | return(1); 65 | break; 66 | case 'c': 67 | width.push_back(12); 68 | substring_length.push_back(12); 69 | attribute_names.push_back("category"); 70 | user_format_specified = true; 71 | break; 72 | case 'u': 73 | width.push_back(12); 74 | substring_length.push_back(12); 75 | attribute_names.push_back("units"); 76 | user_format_specified = true; 77 | break; 78 | case 'l': 79 | width.push_back(50); 80 | substring_length.push_back(50); 81 | attribute_names.push_back("long_name"); 82 | user_format_specified = true; 83 | break; 84 | case 'h': 85 | print_usage(); 86 | default: 87 | cout<<"\n default case" << endl; 88 | //print_usage(); 89 | } 90 | 91 | if (optind >= argc) { 92 | cerr << "Expected argument after options" << endl; 93 | return(1); 94 | } 95 | } 96 | 97 | if (!user_format_specified) 98 | { 99 | // If no output options default to name, units, long_name 100 | width.push_back(12); 101 | substring_length.push_back(12); 102 | attribute_names.push_back("units"); 103 | width.push_back(50); 104 | substring_length.push_back(50); 105 | attribute_names.push_back("long_name"); 106 | } 107 | 108 | VDBFile file; 109 | VarDBConverter vdbc; 110 | string substring; 111 | 112 | vdbc.open(&file, argv[optind]); 113 | if (file.is_valid() == false) 114 | { 115 | cerr << "vdbdump: Initialize failure.\n"; 116 | return(1); 117 | } 118 | 119 | // print header 120 | cout << left << setw(12) << "name "; 121 | for (size_t k = 0; k < attribute_names.size(); ++k) { 122 | cout << left << setw(width[k]) << attribute_names[k] << " " ; 123 | } 124 | cout << endl; 125 | 126 | for (int i = 0; i < file.num_vars(); ++i) 127 | { 128 | VDBVar *var = file.get_var(i); 129 | 130 | cout << left << setw(12) << var->name(); 131 | for (size_t j = 0; j < attribute_names.size(); ++j) { 132 | substring = var->get_attribute(attribute_names[j]).substr(0,substring_length[j]); 133 | cout << left << setw(width[j]) << substring << " "; 134 | } 135 | cout << endl; 136 | } 137 | return(0); 138 | } 139 | -------------------------------------------------------------------------------- /src/vardb/raf/vardb.h: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vardb.h 4 | 5 | FULL NAME: Variable DataBase header file 6 | 7 | DESCRIPTION: 8 | 9 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2011 10 | ------------------------------------------------------------------------- 11 | */ 12 | 13 | #ifndef VARDB_H 14 | #define VARDB_H 15 | 16 | #include 17 | 18 | #define FIXED 0 19 | #define FLOATING 1 20 | 21 | #define VARDB_NL 16 /* Name Length */ 22 | #define VARDB_UL 16 /* Units Length */ 23 | #define VARDB_TL 64 /* Title Length */ 24 | 25 | #ifndef ERR 26 | #define ERR (-1) 27 | #define OK (0) 28 | #endif 29 | 30 | #ifndef TRUE 31 | #define TRUE 1 32 | #define FALSE 0 33 | #endif 34 | 35 | 36 | struct vardb_hdr /* This is the first struct in the file */ 37 | { 38 | int32_t MagicCookie; 39 | int32_t Version; 40 | int32_t nRecords; 41 | int32_t RecordLen; 42 | char unused[8]; 43 | }; 44 | 45 | struct var_v1 46 | { 47 | char Name[VARDB_NL]; 48 | char Units[VARDB_UL]; 49 | char AlternateUnits[VARDB_UL]; 50 | char Title[VARDB_TL]; 51 | 52 | int32_t type; /* FIXED or FLOATING */ 53 | float FixedRange[2]; 54 | float FloatRange; 55 | float MinLimit; 56 | float MaxLimit; 57 | 58 | float CalRange[2]; /* Analog SDI's only */ 59 | }; 60 | 61 | struct var_v2 62 | { 63 | char Name[VARDB_NL]; 64 | char Units[VARDB_UL]; 65 | char AlternateUnits[VARDB_UL]; 66 | char Title[VARDB_TL]; 67 | 68 | int32_t is_analog; /* bool true/false if analog channel */ 69 | int32_t voltageRange[2]; 70 | int32_t defaultSampleRate; 71 | float MinLimit; 72 | float MaxLimit; 73 | 74 | float CalRange[2]; /* Analog SDI's only */ 75 | 76 | int32_t Category; 77 | int32_t standard_name; /* V3, was "unused" space in V2 */ 78 | int32_t reference; /* V3 - bool, was "unused" space in V2 */ 79 | }; 80 | 81 | 82 | extern "C" { 83 | 84 | typedef struct vardb_hdr VarDB_Hdr; 85 | 86 | extern VarDB_Hdr master_VarDB_Hdr; 87 | extern void *master_VarDB; 88 | 89 | extern VarDB_Hdr varDB_Hdr; 90 | extern void *VarDB; 91 | 92 | extern int VarDB_NcML; 93 | 94 | 95 | bool VarDB_isNcML(); 96 | 97 | const char 98 | *VarDB_GetUnits(const char vn[]), 99 | *VarDB_GetAlternateUnits(const char vn[]), 100 | *VarDB_GetCategoryName(const char vn[]), 101 | *VarDB_GetStandardNameName(const char vn[]), 102 | *VarDB_GetTitle(const char vn[]), 103 | *VarDB_GetDependencies(const char vn[]); 104 | char **VarDB_GetVariablesInCategory(const int catNum); 105 | 106 | int InitializeVarDB(const char fileName[]), 107 | VarDB_lookup(const char name[]), 108 | SaveVarDB(const char fileName[]), 109 | ReadCategories(), ReadStandardNames(), 110 | VarDB_GetCategory(const char vn[]), 111 | VarDB_GetCategoryNumber(const char categoryName[]), 112 | VarDB_GetCategoryList(char *list[]), 113 | VarDB_GetStandardName(const char vn[]), 114 | VarDB_GetStandardNameNumber(const char categoryName[]), 115 | VarDB_GetStandardNameList(char *list[]); 116 | 117 | void SortVarDB(), ReleaseVarDB(), SetCategoryFileName(const char fn[]), 118 | SetStandardNameFileName(const char fn[]); 119 | 120 | float VarDB_GetFixedRangeLower(const char vn[]), 121 | VarDB_GetFixedRangeUpper(const char vn[]), 122 | VarDB_GetFloatRange(const char vn[]), 123 | VarDB_GetFillValue(const char vn[]), 124 | VarDB_GetMinLimit(const char vn[]), 125 | VarDB_GetMaxLimit(const char vn[]), 126 | VarDB_GetCalRangeLower(const char vn[]), 127 | VarDB_GetCalRangeUpper(const char vn[]), 128 | VarDB_GetSpikeSlope(const char vn[]); 129 | 130 | bool VarDB_isAnalog(const char vn[]); 131 | // VarDB_isRangeFixed(const char vn[]), 132 | // VarDB_isRangeFloating(const char vn[]); 133 | 134 | int VarDB_SetUnits(const char vn[], const char units[]), 135 | VarDB_SetAlternateUnits(const char vn[], const char units[]), 136 | VarDB_SetTitle(const char vn[], const char title[]), 137 | VarDB_SetIsAnalog(const char vn[], bool value), 138 | VarDB_SetVoltageRangeLower(const char vn[], int32_t value), 139 | VarDB_SetVoltageRangeUpper(const char vn[], int32_t value), 140 | VarDB_SetDefaultSampleRate(const char vn[], int32_t value), 141 | VarDB_SetMinLimit(const char vn[], float value), 142 | VarDB_SetMaxLimit(const char vn[], float value), 143 | VarDB_SetCalRangeLower(const char vn[], float value), 144 | VarDB_SetCalRangeUpper(const char vn[], float value), 145 | VarDB_SetCategory(const char vn[], uint32_t value), 146 | VarDB_SetStandardName(const char vn[], uint32_t value), 147 | VarDB_SetReference(const char vn[], uint32_t value), 148 | VarDB_SetSpikeSlope(const char vn[], float value), 149 | VarDB_GetVoltageRangeLower(const char vn[]), 150 | VarDB_GetVoltageRangeUpper(const char vn[]); 151 | } 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /src/vardb/vardb.3: -------------------------------------------------------------------------------- 1 | .na 2 | .nh 3 | .TH VARDB 3 "20 Jan 1995" "RAF Library Functions" 4 | .SH NAME 5 | vardb \- Variable DataBase API 6 | .SH SYNOPSIS 7 | .nf 8 | .ft B 9 | #include "vardb.h" 10 | .ft 11 | .fi 12 | .LP 13 | .nf 14 | .ft B 15 | int InitializeVarDB(filename) 16 | char \(**filename; 17 | .ft 18 | .fi 19 | .LP 20 | .nf 21 | .ft B 22 | int ReleaseVarDB() 23 | .ft 24 | .fi 25 | .LP 26 | .nf 27 | .ft B 28 | int SaveVarDB(filename) 29 | char \(**filename; 30 | .ft 31 | .fi 32 | .LP 33 | .nf 34 | .ft B 35 | char \(**VarDB_GetUnits(var_name) 36 | char \(**var_name; 37 | .ft 38 | .fi 39 | .LP 40 | .nf 41 | .ft B 42 | char \(**VarDB_GetAlternateUnits(var_name) 43 | char \(**var_name; 44 | .ft 45 | .fi 46 | .LP 47 | .nf 48 | .ft B 49 | char \(**VarDB_GetTitle(var_name) 50 | char \(**var_name; 51 | .ft 52 | .fi 53 | .LP 54 | .nf 55 | .ft B 56 | float VarDB_GetFixedRangeLower(var_name) 57 | char \(**var_name; 58 | .ft 59 | .fi 60 | .LP 61 | .nf 62 | .ft B 63 | float VarDB_GetFixedRangeUpper(var_name) 64 | char \(**var_name; 65 | .ft 66 | .fi 67 | .LP 68 | .nf 69 | .ft B 70 | float VarDB_GetFloatRange(var_name) 71 | char \(**var_name; 72 | .ft 73 | .fi 74 | .LP 75 | .nf 76 | .ft B 77 | float VarDB_GetMinLimit(var_name) 78 | char \(**var_name; 79 | .ft 80 | .fi 81 | .LP 82 | .nf 83 | .ft B 84 | float VarDB_GetMaxLimit(var_name) 85 | char \(**var_name; 86 | .ft 87 | .fi 88 | .LP 89 | .nf 90 | .ft B 91 | float VarDB_GetCalRangeLower(var_name) 92 | char \(**var_name; 93 | .ft 94 | .fi 95 | .LP 96 | .nf 97 | .ft B 98 | float VarDB_GetCalRangeUpper(var_name) 99 | char \(**var_name; 100 | .ft 101 | .fi 102 | .LP 103 | .nf 104 | .ft B 105 | int VarDB_GetCategory(var_name) 106 | char \(**var_name; 107 | .ft 108 | .fi 109 | .LP 110 | .nf 111 | .ft B 112 | float VarDB_GetSpikeSlope(var_name) 113 | char \(**var_name; 114 | .ft 115 | .fi 116 | .LP 117 | .nf 118 | .ft B 119 | VarDB_isRangeFixed(var_name) 120 | char \(**var_name; 121 | .ft 122 | .fi 123 | .LP 124 | .nf 125 | .ft B 126 | VarDB_isRangeFloating(var_name) 127 | char \(**var_name; 128 | .ft 129 | .fi 130 | .LP 131 | .nf 132 | .ft B 133 | VarDB_SetUnits(var_name, units) 134 | char \(**var_name; 135 | char \(**units; 136 | .ft 137 | .fi 138 | .LP 139 | .nf 140 | .ft B 141 | VarDB_SetAlternateUnits(var_name, units) 142 | char \(**var_name; 143 | char \(**units; 144 | .ft 145 | .fi 146 | .LP 147 | .nf 148 | .ft B 149 | VarDB_SetTitle(var_name, title) 150 | char \(**var_name; 151 | char \(**title; 152 | .ft 153 | .fi 154 | .LP 155 | .nf 156 | .ft B 157 | VarDB_SetRangeFixed(var_name, value) 158 | char \(**var_name; 159 | int value; 160 | .ft 161 | .fi 162 | .LP 163 | .nf 164 | .ft B 165 | VarDB_SetRangeFloating(var_name, value) 166 | char \(**var_name; 167 | int value; 168 | .ft 169 | .fi 170 | .LP 171 | .nf 172 | .ft B 173 | VarDB_SetFixedRangeLower(var_name, value) 174 | char \(**var_name; 175 | float value; 176 | .ft 177 | .fi 178 | .LP 179 | .nf 180 | .ft B 181 | VarDB_SetFixedRangeUpper(var_name, value) 182 | char \(**var_name; 183 | float value; 184 | .ft 185 | .fi 186 | .LP 187 | .nf 188 | .ft B 189 | VarDB_SetFloatRange(var_name, value) 190 | char \(**var_name; 191 | float value; 192 | .ft 193 | .fi 194 | .LP 195 | .nf 196 | .ft B 197 | VarDB_SetMinLimit(var_name, value) 198 | char \(**var_name; 199 | float value; 200 | .ft 201 | .fi 202 | .LP 203 | .nf 204 | .ft B 205 | VarDB_SetMaxLimit(var_name, value) 206 | char \(**var_name; 207 | float value; 208 | .ft 209 | .fi 210 | .LP 211 | .nf 212 | .ft B 213 | VarDB_SetCalRangeLower(var_name, value) 214 | char \(**var_name; 215 | float value; 216 | .ft 217 | .fi 218 | .LP 219 | .nf 220 | .ft B 221 | VarDB_SetCalRangeUpper(var_name, value) 222 | char \(**var_name; 223 | float value; 224 | .ft 225 | .fi 226 | .LP 227 | .nf 228 | .ft B 229 | VarDB_SetCategory(var_name, value) 230 | char \(**var_name; 231 | int value; 232 | .ft 233 | .fi 234 | .LP 235 | .nf 236 | .ft B 237 | VarDB_SetSpikeSlope(var_name, value) 238 | char \(**var_name; 239 | float value; 240 | .ft 241 | .fi 242 | .SH DESCRIPTION 243 | .LP 244 | These functions provide an easy method for accessing the Variable 245 | Data Base (bulletin 9). There are two groups of functions, VarDB_Get*() 246 | and VarDB_Set*(). You must use SaveVarDB() if you want VarDB_Set*() 247 | calls to be written to disk, otherwise changes are only kept in memory. 248 | If a variable does not exist for a given variable, then default values 249 | will be returned. 250 | .SH EXAMPLE 251 | .LP 252 | .nf 253 | #include "/home/local/include/vardb.h" 254 | 255 | 256 | if (InitializeVarDB("/home/local/proj/817/VarDB") == ERR) 257 | { 258 | Croak; 259 | } 260 | 261 | printf("%s %f\n", VarDB_GetUnits("LAT"), VarDB_GetFloatRange("LAT")); 262 | 263 | VarDB_SetMinLimit("THDG", 0.0); 264 | VarDB_SetMaxLimit("THDG", 360.0); 265 | 266 | SaveVarDB("/home/local/proj/817/VarDB"); 267 | ReleaseVarDB(); 268 | -------------------------------------------------------------------------------- /src/editor/fbr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Resource file for vared (VarDB editor) 3 | */ 4 | 5 | static String fallback_resources[] = 6 | { 7 | "*defaultFontList: -adobe-courier-bold-r-*-*-14-140-75-75-*-*-*-*", 8 | "*XmForm.horizontalSpacing: 8", 9 | "*XmForm.verticalSpacing: 8", 10 | "*editFieldRC*XmLabel.width: 200", 11 | "*editFieldRC*XmLabel.recomputeSize: False", 12 | "*buttonFrame*XmPushButton.height: 32", 13 | "*buttonFrame*XmPushButton.width: 100", 14 | "*buttonFrame*XmPushButton.recomputeSize: False", 15 | "*XmTextField.background: Burlywood", 16 | "*XmTextField.foreground: black", 17 | "*buttonFrame.shadowType: SHADOW_IN", 18 | "*buttonRC.entryAlignment: ALIGNMENT_CENTER", 19 | "*buttonRC.isAligned: True", 20 | "*buttonRC.orientation: HORIZONTAL", 21 | 22 | "*topLevelShell.x: 200", 23 | "*topLevelShell.y: 200", 24 | "*topLevelShell.title: Variable DataBase Editor", 25 | "*topLevelShell.iconName: vared", 26 | "*topLevelForm.resizePolicy: RESIZE_GROW", 27 | 28 | "*menuBar*filePD_CB.labelString: File", 29 | "*menuBar*filePD_CB.mnemonic: F", 30 | "*menuBar*editPD_CB.labelString: Edit", 31 | "*menuBar*editPD_CB.mnemonic: E", 32 | 33 | "*menuBar*openNewFile.labelString: Open New File", 34 | "*menuBar*openNewFile.mnemonic: O", 35 | "*menuBar*openNewFile.accelerator: CtrlO", 36 | "*menuBar*openNewFile.acceleratorText: Ctrl-O", 37 | "*menuBar*saveFile.labelString: Save", 38 | "*menuBar*saveFile.mnemonic: S", 39 | "*menuBar*saveFile.accelerator: CtrlS", 40 | "*menuBar*saveFile.acceleratorText: Ctrl-S", 41 | "*menuBar*saveFileAs.labelString: Save As", 42 | "*menuBar*saveFileAs.mnemonic: A", 43 | "*menuBar*saveFileAs.accelerator: CtrlA", 44 | "*menuBar*saveFileAs.acceleratorText: Ctrl-A", 45 | "*menuBar*quit.labelString: Quit", 46 | "*menuBar*quit.mnemonic: Q", 47 | "*menuBar*quit.accelerator: CtrlQ", 48 | "*menuBar*quit.acceleratorText: Ctrl-Q", 49 | 50 | "*menuBar*clearVar.labelString: Clear Variable", 51 | "*menuBar*clearVar.mnemonic: C", 52 | "*menuBar*clearVar.accelerator: CtrlC", 53 | "*menuBar*clearVar.acceleratorText: Ctrl-C", 54 | "*menuBar*resetVar.labelString: Reset Variable", 55 | "*menuBar*resetVar.mnemonic: R", 56 | "*menuBar*resetVar.accelerator: CtrlR", 57 | "*menuBar*resetVar.acceleratorText: Ctrl-R", 58 | "*menuBar*deleteVar.labelString: Delete Variable", 59 | "*menuBar*deleteVar.mnemonic: D", 60 | "*menuBar*deleteVar.accelerator: CtrlD", 61 | "*menuBar*deleteVar.acceleratorText: Ctrl-D", 62 | 63 | "*acceptButton.labelString: Accept", 64 | 65 | "*varList.background: black", 66 | "*varList.foreground: green", 67 | "*varList.listSizePolicy: CONSTANT", 68 | "*varList.scrollBarDisplayPolicy: STATIC", 69 | "*varList.visibleItemCount: 22", 70 | "*varList.width: 125", 71 | "*editFieldRC.orientation: VERTICAL", 72 | "*editFieldRC.rowColumnType: WORK_AREA", 73 | "*editFieldRC*XmForm.verticalSpacing: 0", 74 | "*editFieldRC*XmForm.horizontalSpacing: 3", 75 | "*editFieldRC*XmLabel.alignment: ALIGNMENT_END", 76 | "*typeRadioBox.orientation: HORIZONTAL", 77 | "*typeRadioBox.spacing: 20", 78 | "*analogButton.labelString: Is Analog", 79 | "*EFlabel0.labelString: Name:", 80 | "*EFlabel1.labelString: Title:", 81 | "*EFlabel2.labelString: Units:", 82 | "*EFlabel3.labelString: Alt Units:", 83 | "*EFlabel4.labelString: Is Analog:", 84 | "*EFlabel5.labelString: Voltage Range:", 85 | "*EFlabel6.labelString: Default Sample Rate:", 86 | "*EFlabel7.labelString: Minimum Value:", 87 | "*EFlabel8.labelString: Maximum Value:", 88 | "*EFlabel9.labelString: Calibration Range:", 89 | "*catMenu.labelString: Category:", 90 | "*catMenu*XmLabelGadget.alignment: ALIGNMENT_END", 91 | "*stdNameMenu.labelString: Standard Name:", 92 | "*stdNameMenu*XmLabelGadget.alignment: ALIGNMENT_END", 93 | "*referenceButton.labelString: Is this variable *the* reference?", 94 | "*EFtext0.columns: 16", 95 | "*EFtext0.maxLength: 16", 96 | "*EFtext1.columns: 35", 97 | "*EFtext1.maxLength: 64", 98 | "*EFtext2.columns: 16", 99 | "*EFtext2.maxLength: 16", 100 | "*EFtext3.columns: 16", 101 | "*EFtext3.maxLength: 16", 102 | "*EFtext4.columns: 16", 103 | "*EFtext4.maxLength: 16", 104 | "*EFtext5.columns: 16", 105 | "*EFtext5.maxLength: 16", 106 | "*EFtext6.columns: 16", 107 | "*EFtext6.maxLength: 16", 108 | "*EFtext7.columns: 16", 109 | "*EFtext7.maxLength: 16", 110 | "*EFtext8.columns: 16", 111 | "*EFtext8.maxLength: 16", 112 | "*EFtext9.columns: 16", 113 | "*EFtext9.maxLength: 16", 114 | "*EFtext10.columns: 16", 115 | "*EFtext10.maxLength: 16", 116 | 117 | "*errorBox*background: DarkSlateGray", 118 | "*errorBox*dialogTitle: Error Message", 119 | "*errorBox*foreground: Red", 120 | "*errorBox*XmLabel.alignment: ALIGNMENT_CENTER", 121 | "*warnBox*background: DarkSlateGray", 122 | "*warnBox*dialogTitle: Warning Message", 123 | "*warnBox*foreground: Yellow", 124 | "*warnBox*XmLabel.alignment: ALIGNMENT_CENTER", 125 | "*fileBox.defaultPosition: FALSE", 126 | "*fileBox.x: 130", 127 | "*fileBox.y: 200", 128 | "*fileBox*textColumns: 50", 129 | "*fileBox*dialogTitle: Select a File", 130 | NULL 131 | }; 132 | -------------------------------------------------------------------------------- /src/vardb/set.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: set.c 4 | 5 | FULL NAME: Variable DataBase Set functions 6 | 7 | ENTRY POINTS: VarDB_Set*() 8 | 9 | DESCRIPTION: 10 | 11 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2005 12 | ------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "raf/vardb.h" 20 | #include 21 | 22 | 23 | /* -------------------------------------------------------------------- */ 24 | int VarDB_SetUnits(const char vn[], const char units[]) 25 | { 26 | int indx; 27 | 28 | if ((indx = VarDB_lookup(vn)) == ERR) 29 | return(ERR); 30 | 31 | strcpy(((struct var_v2 *)VarDB)[indx].Units, units); 32 | return(OK); 33 | 34 | } /* END VARDB_SETUNITS */ 35 | 36 | /* -------------------------------------------------------------------- */ 37 | int VarDB_SetAlternateUnits(const char vn[], const char units[]) 38 | { 39 | int indx; 40 | 41 | if ((indx = VarDB_lookup(vn)) == ERR) 42 | return(ERR); 43 | 44 | strcpy(((struct var_v2 *)VarDB)[indx].AlternateUnits, units); 45 | return(OK); 46 | 47 | } /* END VARDB_SETALTERNATEUNITS */ 48 | 49 | /* -------------------------------------------------------------------- */ 50 | int VarDB_SetTitle(const char vn[], const char title[]) 51 | { 52 | int indx; 53 | 54 | if ((indx = VarDB_lookup(vn)) == ERR) 55 | return(ERR); 56 | 57 | strcpy(((struct var_v2 *)VarDB)[indx].Title, title); 58 | return(OK); 59 | 60 | } /* END VARDB_SETTITLE */ 61 | 62 | /* -------------------------------------------------------------------- */ 63 | int VarDB_SetIsAnalog(const char vn[], bool analog) 64 | { 65 | int indx; 66 | 67 | if ((indx = VarDB_lookup(vn)) == ERR) 68 | return(ERR); 69 | 70 | ((struct var_v2 *)VarDB)[indx].is_analog = htonl(analog); 71 | return(OK); 72 | 73 | } /* END VARDB_ISANALOG */ 74 | 75 | /* -------------------------------------------------------------------- */ 76 | int VarDB_SetVoltageRangeLower(const char vn[], int32_t value) 77 | { 78 | int indx; 79 | 80 | if ((indx = VarDB_lookup(vn)) == ERR) 81 | return(ERR); 82 | 83 | ((struct var_v2 *)VarDB)[indx].voltageRange[0] = htonl(value); 84 | return(OK); 85 | 86 | } /* END VARDB_SETFIXEDRANGELOWER */ 87 | 88 | /* -------------------------------------------------------------------- */ 89 | int VarDB_SetVoltageRangeUpper(const char vn[], int32_t value) 90 | { 91 | int indx; 92 | 93 | if ((indx = VarDB_lookup(vn)) == ERR) 94 | return(ERR); 95 | 96 | ((struct var_v2 *)VarDB)[indx].voltageRange[1] = htonl(value); 97 | return(OK); 98 | 99 | } /* END VARDB_SETFIXEDRANGEUPPER */ 100 | 101 | /* -------------------------------------------------------------------- */ 102 | int VarDB_SetDefaultSampleRate(const char vn[], int32_t value) 103 | { 104 | int indx; 105 | 106 | if ((indx = VarDB_lookup(vn)) == ERR) 107 | return(ERR); 108 | 109 | ((struct var_v2 *)VarDB)[indx].defaultSampleRate = htonl(value); 110 | return(OK); 111 | 112 | } /* END VARDB_SETFLOATRANGE */ 113 | 114 | /* -------------------------------------------------------------------- */ 115 | int VarDB_SetMinLimit(const char vn[], float value) 116 | { 117 | int indx; 118 | 119 | if ((indx = VarDB_lookup(vn)) == ERR) 120 | return(ERR); 121 | 122 | ((struct var_v2 *)VarDB)[indx].MinLimit = htonf(value); 123 | return(OK); 124 | 125 | } /* END VARDB_SETMINLIMIT */ 126 | 127 | /* -------------------------------------------------------------------- */ 128 | int VarDB_SetMaxLimit(const char vn[], float value) 129 | { 130 | int indx; 131 | 132 | if ((indx = VarDB_lookup(vn)) == ERR) 133 | return(ERR); 134 | 135 | ((struct var_v2 *)VarDB)[indx].MaxLimit = htonf(value); 136 | return(OK); 137 | 138 | } /* END VARDB_SETMINLIMIT */ 139 | 140 | /* -------------------------------------------------------------------- */ 141 | int VarDB_SetCalRangeLower(const char vn[], float value) 142 | { 143 | int indx; 144 | 145 | if ((indx = VarDB_lookup(vn)) == ERR) 146 | return(ERR); 147 | 148 | ((struct var_v2 *)VarDB)[indx].CalRange[0] = htonf(value); 149 | return(OK); 150 | 151 | } /* END VARDB_SETCALRANGELOWER */ 152 | 153 | /* -------------------------------------------------------------------- */ 154 | int VarDB_SetCalRangeUpper(const char vn[], float value) 155 | { 156 | int indx; 157 | 158 | if ((indx = VarDB_lookup(vn)) == ERR) 159 | return(ERR); 160 | 161 | ((struct var_v2 *)VarDB)[indx].CalRange[1] = htonf(value); 162 | return(OK); 163 | 164 | } /* END VARDB_SETCALRANGEUPPER */ 165 | 166 | /* -------------------------------------------------------------------- */ 167 | int VarDB_SetCategory(const char vn[], uint32_t value) 168 | { 169 | int indx; 170 | 171 | if ((indx = VarDB_lookup(vn)) == ERR) 172 | return(ERR); 173 | 174 | ((struct var_v2 *)VarDB)[indx].Category = htonl(value); 175 | return(OK); 176 | 177 | } /* END VARDB_SETCATEGORY */ 178 | 179 | /* -------------------------------------------------------------------- */ 180 | int VarDB_SetStandardName(const char vn[], uint32_t value) 181 | { 182 | int indx; 183 | 184 | if ((indx = VarDB_lookup(vn)) == ERR) 185 | return(ERR); 186 | 187 | ((struct var_v2 *)VarDB)[indx].standard_name = htonl(value); 188 | return(OK); 189 | 190 | } /* END VARDB_SETSTANDARDNAME */ 191 | 192 | /* END SET.C */ 193 | -------------------------------------------------------------------------------- /src/vardb/tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.5.4 // 7 | CATEGORY category.c /^ } CATEGORY;$/;" t file: 8 | CAT_NAME_LEN category.c 32;" d file: 9 | Category category.c /^static CATEGORY *Category[MAX_CATEGORIES];$/;" v file: 10 | CreateVarDB merge.c /^CreateVarDB(Bull9_name, Pattr_name)$/;" f 11 | InitializeVarDB init.c /^int InitializeVarDB(const char fileName[])$/;" f 12 | MAX_CATEGORIES category.c 31;" d file: 13 | MAX_STD_NAMES std_name.c 27;" d file: 14 | Name category.c /^ char Name[CAT_NAME_LEN];$/;" m file: 15 | Name std_name.c /^ char Name[STD_NAME_LEN];$/;" m file: 16 | Number category.c /^ int Number;$/;" m file: 17 | Number std_name.c /^ int Number;$/;" m file: 18 | ReadCategories category.c /^ReadCategories()$/;" f 19 | ReadStandardNames std_name.c /^ReadStandardNames()$/;" f 20 | ReleaseVarDB init.c /^void ReleaseVarDB()$/;" f 21 | STD_NAME std_name.c /^ } STD_NAME;$/;" t file: 22 | STD_NAME_LEN std_name.c 28;" d file: 23 | SaveVarDB save.c /^SaveVarDB(const char fileName[])$/;" f 24 | SetCategoryFileName category.c /^void SetCategoryFileName(const char fn[])$/;" f 25 | SetStandardNameFileName std_name.c /^void SetStandardNameFileName(const char fn[])$/;" f 26 | SortVarDB sort.c /^void SortVarDB()$/;" f 27 | StdName std_name.c /^static STD_NAME *StdName[MAX_STD_NAMES];$/;" v file: 28 | VarDB init.c /^void *VarDB = NULL;$/;" v 29 | VarDB_CurrentVersion init.c /^const long VarDB_CurrentVersion = 3;$/;" v 30 | VarDB_GetAlternateUnits get.c /^char *VarDB_GetAlternateUnits(const char vn[])$/;" f 31 | VarDB_GetCalRangeLower get.c /^float VarDB_GetCalRangeLower(const char vn[])$/;" f 32 | VarDB_GetCalRangeUpper get.c /^float VarDB_GetCalRangeUpper(const char vn[])$/;" f 33 | VarDB_GetCategory get.c /^int VarDB_GetCategory(const char vn[])$/;" f 34 | VarDB_GetCategoryList category.c /^int VarDB_GetCategoryList(char *list[])$/;" f 35 | VarDB_GetCategoryName category.c /^char *VarDB_GetCategoryName(const char vn[])$/;" f 36 | VarDB_GetCategoryNumber category.c /^int VarDB_GetCategoryNumber(const char catagoryName[])$/;" f 37 | VarDB_GetFixedRangeLower get.c /^float VarDB_GetFixedRangeLower(const char vn[])$/;" f 38 | VarDB_GetFixedRangeUpper get.c /^float VarDB_GetFixedRangeUpper(const char vn[])$/;" f 39 | VarDB_GetFloatRange get.c /^float VarDB_GetFloatRange(const char vn[])$/;" f 40 | VarDB_GetMaxLimit get.c /^float VarDB_GetMaxLimit(const char vn[])$/;" f 41 | VarDB_GetMinLimit get.c /^float VarDB_GetMinLimit(const char vn[])$/;" f 42 | VarDB_GetStandardName get.c /^int VarDB_GetStandardName(const char vn[])$/;" f 43 | VarDB_GetStandardNameList std_name.c /^int VarDB_GetStandardNameList(char *list[])$/;" f 44 | VarDB_GetStandardNameName std_name.c /^char *VarDB_GetStandardNameName(const char vn[])$/;" f 45 | VarDB_GetStandardNameNumber std_name.c /^int VarDB_GetStandardNameNumber(const char catagoryName[])$/;" f 46 | VarDB_GetTitle get.c /^char *VarDB_GetTitle(const char vn[])$/;" f 47 | VarDB_GetUnits get.c /^char *VarDB_GetUnits(const char vn[])$/;" f 48 | VarDB_GetVariablesInCategory category.c /^char **VarDB_GetVariablesInCategory(int catNum)$/;" f 49 | VarDB_GetVariablesInStandardName std_name.c /^char **VarDB_GetVariablesInStandardName(int catNum)$/;" f 50 | VarDB_Hdr init.c /^struct vardb_hdr VarDB_Hdr;$/;" v 51 | VarDB_MagicCookie init.c /^const long VarDB_MagicCookie = 0x42756c6c;$/;" v 52 | VarDB_RecLength init.c /^long VarDB_RecLength, VarDB_nRecords;$/;" v 53 | VarDB_SetAlternateUnits set.c /^VarDB_SetAlternateUnits(const char vn[], char units[])$/;" f 54 | VarDB_SetCalRangeLower set.c /^VarDB_SetCalRangeLower(const char vn[], float value)$/;" f 55 | VarDB_SetCalRangeUpper set.c /^VarDB_SetCalRangeUpper(const char vn[], float value)$/;" f 56 | VarDB_SetCategory set.c /^VarDB_SetCategory(const char vn[], long value)$/;" f 57 | VarDB_SetFixedRangeLower set.c /^VarDB_SetFixedRangeLower(const char vn[], float value)$/;" f 58 | VarDB_SetFixedRangeUpper set.c /^VarDB_SetFixedRangeUpper(const char vn[], float value)$/;" f 59 | VarDB_SetFloatRange set.c /^VarDB_SetFloatRange(const char vn[], float value)$/;" f 60 | VarDB_SetMaxLimit set.c /^VarDB_SetMaxLimit(const char vn[], float value)$/;" f 61 | VarDB_SetMinLimit set.c /^VarDB_SetMinLimit(const char vn[], float value)$/;" f 62 | VarDB_SetRangeFixed set.c /^VarDB_SetRangeFixed(const char vn[])$/;" f 63 | VarDB_SetRangeFloating set.c /^VarDB_SetRangeFloating(const char vn[])$/;" f 64 | VarDB_SetStandardName set.c /^VarDB_SetStandardName(const char vn[], long value)$/;" f 65 | VarDB_SetTitle set.c /^VarDB_SetTitle(const char vn[], char title[])$/;" f 66 | VarDB_SetUnits set.c /^VarDB_SetUnits(const char vn[], char units[])$/;" f 67 | VarDB_isRangeFixed get.c /^int VarDB_isRangeFixed(const char vn[])$/;" f 68 | VarDB_isRangeFloating get.c /^int VarDB_isRangeFloating(const char vn[])$/;" f 69 | VarDB_lookup init.c /^int VarDB_lookup(const char vn[])$/;" f 70 | VarDB_nRecords init.c /^long VarDB_RecLength, VarDB_nRecords;$/;" v 71 | defaults get.c /^static struct var_v2 defaults =$/;" v file: 72 | fileName category.c /^static char *fileName;$/;" v file: 73 | fileName std_name.c /^static char *fileName;$/;" v file: 74 | firstTime category.c /^static int firstTime = TRUE;$/;" v file: 75 | firstTime std_name.c /^static int firstTime = TRUE;$/;" v file: 76 | master_VarDB init.c /^void *master_VarDB = NULL;$/;" v 77 | master_VarDB_Hdr init.c /^struct vardb_hdr master_VarDB_Hdr;$/;" v 78 | nCategories category.c /^static int nCategories = 0;$/;" v file: 79 | nStdNames std_name.c /^static int nStdNames = 0;$/;" v file: 80 | readFile init.c /^void *readFile(const char fileName[], struct vardb_hdr *vdbHdr)$/;" f 81 | -------------------------------------------------------------------------------- /src/vardb/category.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: category.c 4 | 5 | FULL NAME: VarDB_ Category functions 6 | 7 | ENTRY POINTS: SetCategoryFileName() 8 | ReadCategories() 9 | VarDB_GetCategoryName() 10 | VarDB_AddCategory() 11 | VarDB_GetVariablesInCategory() 12 | VarDB_GetCategoryList() 13 | 14 | STATIC FNS: none 15 | 16 | DESCRIPTION: 17 | 18 | INPUT: Variable Name 19 | 20 | OUTPUT: Category Name 21 | 22 | COPYRIGHT: University Corporation for Atmospheric Research, 1994-2006 23 | ------------------------------------------------------------------------- 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "raf/vardb.h" 32 | #include 33 | #include 34 | 35 | #define MAX_CATEGORIES 128 36 | #define CAT_NAME_LEN 64 37 | 38 | 39 | typedef struct 40 | { 41 | int Number; 42 | char Name[CAT_NAME_LEN]; 43 | } CATEGORY; 44 | 45 | static int firstTime = TRUE; 46 | static char *fileName; 47 | static int nCategories = 0; 48 | static CATEGORY *Category[MAX_CATEGORIES]; 49 | 50 | extern long VarDB_RecLength, VarDB_nRecords; 51 | extern char VarDB_NcML_text_result[]; 52 | 53 | 54 | /* -------------------------------------------------------------------- */ 55 | void SetCategoryFileName(const char fn[]) 56 | { 57 | char *p; 58 | 59 | fileName = (char *)malloc(strlen(fn) + 10); 60 | strcpy(fileName, fn); 61 | p = strrchr(fileName, '/'); 62 | 63 | if (p) 64 | ++p; 65 | else 66 | p = fileName; 67 | 68 | strcpy(p, "Categories"); 69 | 70 | } /* END SETCATEGORYFILENAME */ 71 | 72 | /* -------------------------------------------------------------------- */ 73 | int ReadCategories() 74 | { 75 | char line[128], *p; 76 | FILE *fp; 77 | 78 | if ((fp = fopen(fileName, "r")) == NULL) 79 | { 80 | fprintf(stderr, "category.c: Can't open %s.\n", fileName); 81 | return(ERR); 82 | } 83 | 84 | for (nCategories = 0; fgets(line, 128, fp); ) 85 | { 86 | if (line[0] == '#' || strlen(line) < (size_t)5) 87 | continue; 88 | 89 | if (nCategories >= MAX_CATEGORIES-1) 90 | { 91 | fprintf(stderr, "vardb/lib/category.c: MAX_CATEGORIES exceeded.\n"); 92 | fprintf(stderr, " Ignoring extra categories and continuing.\n"); 93 | fprintf(stderr, " Please notify a programmer of this problem.\n"); 94 | 95 | fclose(fp); 96 | return(OK); 97 | } 98 | 99 | Category[nCategories] = (CATEGORY *)malloc(sizeof(CATEGORY)); 100 | 101 | Category[nCategories]->Number = atoi(line); 102 | 103 | for (p = strchr(line, ',')+1; *p == ' ' || *p == '\t'; ++p) 104 | ; 105 | 106 | strncpy(Category[nCategories]->Name, p, CAT_NAME_LEN); 107 | Category[nCategories]->Name[strlen(Category[nCategories]->Name)-1]='\0'; 108 | ++nCategories; 109 | } 110 | 111 | fclose(fp); 112 | return(OK); 113 | 114 | } /* END READCATEGORIES */ 115 | 116 | /* -------------------------------------------------------------------- */ 117 | const char *VarDB_GetCategoryName(const char vn[]) 118 | { 119 | int i, rc, indx; 120 | int catNum; 121 | 122 | if (firstTime) 123 | { 124 | if (ReadCategories() == ERR) 125 | return((char *)ERR); 126 | 127 | firstTime = FALSE; 128 | } 129 | 130 | 131 | if ((indx = VarDB_lookup(vn)) == ERR) 132 | return(Category[0]->Name); 133 | 134 | if (VarDB_NcML > 0) 135 | { 136 | if (nc_get_att_text(VarDB_NcML, indx, "Category", VarDB_NcML_text_result) == NC_NOERR) 137 | return VarDB_NcML_text_result; 138 | else 139 | return Category[0]->Name; 140 | } 141 | 142 | catNum = ntohl(((struct var_v2 *)VarDB)[indx].Category); 143 | 144 | for (rc = i = 0; i < nCategories; ++i) 145 | if (Category[i]->Number == catNum) 146 | rc = i; 147 | 148 | return(Category[rc]->Name); 149 | 150 | } /* END VARDB_GETCATEGORYNAME */ 151 | 152 | /* -------------------------------------------------------------------- */ 153 | char **VarDB_GetVariablesInCategory(int catNum) 154 | { 155 | int i, cnt; 156 | char **p; 157 | 158 | if (firstTime) 159 | { 160 | if (ReadCategories() == ERR) 161 | return((char **)ERR); 162 | 163 | firstTime = FALSE; 164 | } 165 | 166 | cnt = 0; 167 | p = (char **)malloc(sizeof(char *)); 168 | 169 | for (i = 0; i < VarDB_nRecords; ++i) 170 | if (ntohl(((struct var_v2 *)VarDB)[i].Category) == (unsigned int)catNum) 171 | { 172 | p = (char **)realloc(p, sizeof(char *) * (cnt+2)); 173 | p[cnt] = ((struct var_v2 *)VarDB)[i].Name; 174 | 175 | ++cnt; 176 | } 177 | 178 | p[cnt] = NULL; 179 | 180 | return(p); 181 | 182 | } /* END VARDB_GETVARIABLESINCATEGORY */ 183 | 184 | /* -------------------------------------------------------------------- */ 185 | int VarDB_GetCategoryList(char *list[]) 186 | { 187 | int i; 188 | 189 | if (firstTime) 190 | { 191 | if (ReadCategories() == ERR) 192 | return(ERR); 193 | 194 | firstTime = FALSE; 195 | } 196 | 197 | 198 | for (i = 0; i < nCategories; ++i) 199 | list[i] = Category[i]->Name; 200 | 201 | list[i] = NULL; 202 | 203 | return(i); 204 | 205 | } /* END VARDB_GETCATEGORYLIST */ 206 | 207 | /* -------------------------------------------------------------------- */ 208 | int VarDB_GetCategoryNumber(const char categoryName[]) 209 | { 210 | int i; 211 | 212 | if (firstTime) 213 | { 214 | if (ReadCategories() == ERR) 215 | return(ERR); 216 | 217 | firstTime = FALSE; 218 | } 219 | 220 | 221 | for (i = 0; i < nCategories; ++i) 222 | if (strcmp(categoryName, Category[i]->Name) == 0) 223 | return(Category[i]->Number); 224 | 225 | return(0); /* Category 0 is "None" */ 226 | 227 | } /* END VARDB_GETCATEGORYNUMBER */ 228 | 229 | /* END CATEGORY.C */ 230 | -------------------------------------------------------------------------------- /src/vardb/std_name.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: std_name.c 4 | 5 | FULL NAME: VarDB_ Standard Name functions 6 | 7 | ENTRY POINTS: SetStandardNameFileName() 8 | ReadStandardNames() 9 | VarDB_GetStandardNameName() 10 | VarDB_AddStandardName() 11 | VarDB_GetVariablesInStandardName() 12 | VarDB_GetStandardNameList() 13 | 14 | STATIC FNS: none 15 | 16 | DESCRIPTION: 17 | 18 | COPYRIGHT: University Corporation for Atmospheric Research, 2005-24 19 | ------------------------------------------------------------------------- 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "raf/vardb.h" 27 | #include 28 | 29 | #include 30 | 31 | #define MAX_STD_NAMES 128 32 | #define STD_NAME_LEN 64 33 | 34 | 35 | typedef struct 36 | { 37 | int Number; 38 | char Name[STD_NAME_LEN]; 39 | } STD_NAME; 40 | 41 | static int firstTime = true; 42 | static char *fileName = 0; 43 | static int nStdNames = 0; 44 | static STD_NAME *StdName[MAX_STD_NAMES]; 45 | 46 | extern long VarDB_RecLength, VarDB_nRecords; 47 | extern char VarDB_NcML_text_result[]; 48 | 49 | 50 | /* -------------------------------------------------------------------- */ 51 | void SetStandardNameFileName(const char fn[]) 52 | { 53 | char *p; 54 | 55 | fileName = (char *)malloc(strlen(fn) + 10); 56 | strcpy(fileName, fn); 57 | p = strrchr(fileName, '/'); 58 | 59 | if (p) 60 | ++p; 61 | else 62 | p = fileName; 63 | 64 | strcpy(p, "StandardNames"); 65 | 66 | } /* END SETSTANDARDNAMEFILENAME */ 67 | 68 | /* -------------------------------------------------------------------- */ 69 | int ReadStandardNames() 70 | { 71 | char line[128], *p; 72 | FILE *fp; 73 | 74 | if (fileName == 0) 75 | return(ERR); 76 | 77 | if ((fp = fopen(fileName, "r")) == NULL) 78 | { 79 | fprintf(stderr, "std_name.c: Can't open %s.\n", fileName); 80 | return(ERR); 81 | } 82 | 83 | for (nStdNames = 0; fgets(line, 128, fp); ) 84 | { 85 | if (line[0] == '#' || strlen(line) < (size_t)5) 86 | continue; 87 | 88 | if (nStdNames >= MAX_STD_NAMES-1) 89 | { 90 | fprintf(stderr, "vardb/lib/category.c: MAX_STD_NAME exceeded.\n"); 91 | fprintf(stderr, " Ignoring extra categories and continuing.\n"); 92 | fprintf(stderr, " Please notify a programmer of this problem.\n"); 93 | 94 | fclose(fp); 95 | return(OK); 96 | } 97 | 98 | StdName[nStdNames] = (STD_NAME *)malloc(sizeof(STD_NAME)); 99 | 100 | StdName[nStdNames]->Number = atoi(line); 101 | 102 | for (p = strchr(line, ',')+1; *p == ' ' || *p == '\t'; ++p) 103 | ; 104 | 105 | strncpy(StdName[nStdNames]->Name, p, STD_NAME_LEN); 106 | StdName[nStdNames]->Name[strlen(StdName[nStdNames]->Name)-1]='\0'; 107 | ++nStdNames; 108 | } 109 | 110 | fclose(fp); 111 | return(OK); 112 | 113 | } /* END READSTANDARDNAMES */ 114 | 115 | /* -------------------------------------------------------------------- */ 116 | const char *VarDB_GetStandardNameName(const char vn[]) 117 | { 118 | int i, rc, indx; 119 | int catNum; 120 | 121 | if (firstTime) 122 | { 123 | if (ReadStandardNames() == ERR) 124 | return("None"); 125 | 126 | firstTime = false; 127 | } 128 | 129 | 130 | if ((indx = VarDB_lookup(vn)) == ERR) 131 | return("None"); 132 | 133 | if (VarDB_NcML > 0) 134 | { 135 | if (nc_get_att_text(VarDB_NcML, indx, "standard_name", VarDB_NcML_text_result) == NC_NOERR) 136 | return VarDB_NcML_text_result; 137 | else 138 | return StdName[0]->Name; 139 | } 140 | 141 | catNum = ntohl(((struct var_v2 *)VarDB)[indx].standard_name); 142 | 143 | for (rc = i = 0; i < nStdNames; ++i) 144 | if (StdName[i]->Number == catNum) 145 | rc = i; 146 | 147 | return(StdName[rc]->Name); 148 | 149 | } /* END VARDB_GETSTANDARDNAMENAME */ 150 | 151 | /* -------------------------------------------------------------------- */ 152 | char **VarDB_GetVariablesInStandardName(int catNum) 153 | { 154 | int i, cnt; 155 | char **p; 156 | 157 | if (firstTime) 158 | { 159 | if (ReadStandardNames() == ERR) 160 | return((char **)0); 161 | 162 | firstTime = false; 163 | } 164 | 165 | 166 | cnt = 0; 167 | p = (char **)malloc(sizeof(char *)); 168 | 169 | for (i = 0; i < VarDB_nRecords; ++i) 170 | if (ntohl(((struct var_v2 *)VarDB)[i].standard_name) == 171 | (unsigned int)catNum) 172 | { 173 | p = (char **)realloc(p, sizeof(char *) * (cnt+2)); 174 | p[cnt] = ((struct var_v2 *)VarDB)[i].Name; 175 | 176 | ++cnt; 177 | } 178 | 179 | p[cnt] = NULL; 180 | 181 | return(p); 182 | 183 | } /* END VARDB_GETVARIABLESINSTANDARDNAME */ 184 | 185 | /* -------------------------------------------------------------------- */ 186 | int VarDB_GetStandardNameList(char *list[]) 187 | { 188 | int i; 189 | 190 | if (firstTime) 191 | { 192 | if (ReadStandardNames() == ERR) 193 | return(ERR); 194 | 195 | firstTime = false; 196 | } 197 | 198 | 199 | for (i = 0; i < nStdNames; ++i) 200 | list[i] = StdName[i]->Name; 201 | 202 | list[i] = NULL; 203 | 204 | return(i); 205 | 206 | } /* END VARDB_GETSTANDARDNAMELIST */ 207 | 208 | /* -------------------------------------------------------------------- */ 209 | int VarDB_GetStandardNameNumber(const char categoryName[]) 210 | { 211 | int i; 212 | 213 | if (firstTime) 214 | { 215 | if (ReadStandardNames() == ERR) 216 | return(0); 217 | 218 | firstTime = false; 219 | } 220 | 221 | 222 | for (i = 0; i < nStdNames; ++i) 223 | if (strcmp(categoryName, StdName[i]->Name) == 0) 224 | return(StdName[i]->Number); 225 | 226 | return(0); /* Category 0 is "None" */ 227 | 228 | } /* END VARDB_GETSTANDARDNAMENUMBER */ 229 | 230 | /* END STD_NAME.C */ 231 | -------------------------------------------------------------------------------- /python/vardb/test_vardb.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from vardb import VDBFile, VDBVar 4 | 5 | from .Variable import Variable, VariableList, DataStore 6 | 7 | import os.path 8 | import datetime 9 | 10 | _testdir = os.path.join(os.path.dirname(__file__), "../../tests") 11 | _deepwave_xml = os.path.join(_testdir, "deepwave_vardb.xml") 12 | 13 | def test_open_and_save(): 14 | vdb = VDBFile("") 15 | dir(vdb) 16 | vdb.open(_deepwave_xml) 17 | assert(vdb.is_valid()) 18 | qcf = vdb.get_var("QCF") 19 | assert(qcf.name() == "QCF") 20 | assert(qcf.get_attribute("units") == "hPa") 21 | assert(qcf.get_attribute(VDBVar.LONG_NAME) == 22 | "Raw Dynamic Pressure, Fuselage") 23 | assert(qcf.get_attribute(VDBVar.UNITS) == "hPa") 24 | assert(qcf.get_attribute(VDBVar.STANDARD_NAME) == "") 25 | assert(qcf.get_attribute(VDBVar.REFERENCE) == "false") 26 | assert(qcf.get_attribute(VDBVar.IS_ANALOG) == "true") 27 | assert(qcf.get_attribute(VDBVar.VOLTAGE_RANGE) == "0 10") 28 | assert(qcf.get_attribute(VDBVar.DEFAULT_SAMPLE_RATE) == "100") 29 | assert(qcf.get_attribute(VDBVar.CATEGORY) == "Uncorr'd Raw") 30 | # Missing attribute returns empty string. 31 | assert(qcf.get_attribute(VDBVar.MODULUS_RANGE) == "") 32 | 33 | # Missing attribute returns a supplied default. 34 | assert(qcf.get_attribute(VDBVar.STANDARD_NAME, "air_pressure") == 35 | "air_pressure") 36 | 37 | # Test access by index 38 | acetone = vdb.get_var_at(12) 39 | assert(acetone.name() == "ACETONE") 40 | 41 | # vdb.save("saved.xml") 42 | vdb.close() 43 | 44 | 45 | def test_categories(): 46 | vdb = VDBFile(_deepwave_xml) 47 | categories = vdb.get_categories() 48 | assert(categories == ["Position", "Thermodynamic", "Aircraft State", 49 | "Atmos. State", "Liquid Water", 50 | "Uncorr'd Raw", "Wind", "PMS Probe", 51 | "Housekeeping", "Chemistry", "Radiation", 52 | "Non-Standard"]) 53 | vdb.close() 54 | 55 | 56 | def test_standard_names(): 57 | vdb = VDBFile(_deepwave_xml) 58 | standard_names = vdb.get_standard_names() 59 | assert(standard_names == 60 | ["altitude", "air_potential_temperature", "air_pressure", 61 | "air_temperature", "dew_point_temperature", "geopotential_height", 62 | "eastward_wind", "latitude", "longitude", "northward_wind", 63 | "relative_humidity", "surface_air_pressure", 64 | "platform_speed_wrt_air", "upward_air_velocity", 65 | "wind_from_direction", "wind_speed", "water_vapor_pressure", 66 | "solar_zenith_angle", "platform_course", "platform_orientation", 67 | "platform_pitch_angle", "platform_roll_angle", 68 | "platform_speed_wrt_ground", "humidity_mixing_ratio", 69 | "equivelent_potential_temperature", "height", 70 | "atmosphere_cloud_liquid_water_content", 71 | "air_pressure_at_sea_level", "solar_azimuth_angle", 72 | "solar_elevation_angle", "virtual_temperature", 73 | "atmosphere_number_content_of_aerosol_particles", 74 | "mole_fraction_of_carbon_dioxide_in_air", 75 | "mole_fraction_of_methane_in_air", 76 | "mole_fraction_of_carbon_monoxide_in_air", 77 | "mole_fraction_of_ozone_in_air"]) 78 | vdb.close() 79 | 80 | 81 | def test_variable(): 82 | vdb = VDBFile("") 83 | vdb.open(_deepwave_xml) 84 | assert(vdb.is_valid()) 85 | vdbqcf = vdb.get_var("QCF") 86 | qcf = Variable(vdbqcf.name()) 87 | qcf.fromVDBVar(vdbqcf) 88 | assert(qcf.name == "QCF") 89 | assert(qcf.units == "hPa") 90 | assert(qcf.long_name == "Raw Dynamic Pressure, Fuselage") 91 | assert(qcf.units == "hPa") 92 | assert(qcf.standard_name == None) 93 | assert(qcf.reference == False) 94 | assert(qcf.is_analog == True) 95 | assert(qcf.voltage_range == "0 10") 96 | assert(qcf.default_sample_rate == 100) 97 | assert(qcf.category == "Uncorr'd Raw") 98 | assert(qcf.modulus_range == None) 99 | assert(qcf.min_limit == None) 100 | assert(qcf.max_limit == None) 101 | vdb.close() 102 | 103 | 104 | def test_variables_from_database(): 105 | vlist = VariableList() 106 | vlist.setDatabaseSpecifier('env') 107 | # vlist.hostname = "eol-rt-data.eol.ucar.edu" 108 | # vlist.dbname = "real-time-C130" 109 | vars = vlist.loadVariables() 110 | thdg = vars['THDG'] 111 | assert(thdg.long_name == "IRS Aircraft True Heading Angle") 112 | assert(thdg.units == "degree_T") 113 | assert(thdg.uncalibrated_units == "degree_T") 114 | assert(thdg.missing_value == -32767) 115 | assert(thdg.ndims == 1) 116 | 117 | # Test global metadata, though this will break eventually... 118 | assert(vlist.project == "WINTER") 119 | assert(vlist.aircraft == "C130_N130AR") 120 | assert(vlist.platform == "N130AR") 121 | assert(vlist.aircraftFromPlatform("N677F") == "GV_N677F") 122 | 123 | vlist.projdir = "/tmp" 124 | assert(vlist.vdbPath() == "/tmp/WINTER/C130_N130AR/vardb.xml") 125 | vlist.close() 126 | 127 | 128 | def test_datastore(): 129 | vlist = VariableList() 130 | vlist.setDatabaseSpecifier('env') 131 | vlist.loadVariables() 132 | 133 | # So THDG should be added to columns, but THDGX should not. 134 | vlist.selectVariable('THDG') 135 | assert(len(vlist.columns) == 1) 136 | vlist.selectVariable('THDGX') 137 | assert(len(vlist.columns) == 1) 138 | 139 | # Now grab the last 10 values. 140 | datastore = vlist.getLatestValues(DataStore(), 10) 141 | thdg = datastore.getValues('THDG') 142 | assert(len(thdg) == 10) 143 | assert(thdg[0] == 278.41399999999999) 144 | assert(datastore.getTimes()[0] == datetime.datetime(2015, 2, 9, 19, 8, 55)) 145 | 146 | thdg = datastore.getValues('THDG', 1) 147 | assert(len(thdg) == 1) 148 | assert(thdg[0] == 278.41399999999999) 149 | vlist.close() 150 | 151 | 152 | -------------------------------------------------------------------------------- /editpy/addSignal.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #This is the master VDB edit function. This is the only write access point to VDB (getInfo reads VDB) 3 | #Input: 4 | # signals-New information to transcribe. Is of different forms depending on desired action 5 | # self-holds all Gui information 6 | # num- used to call generate buttons after edditing is finished. -1 is a flag 7 | # for no need to generate the buttons again 8 | # instructions- dictionary with instructions of what action to take. Determines 9 | # how VDB will be editted, and what signals is expected to look like. 10 | #example attribute: is_analog 11 | import csv 12 | from getInfo import * 13 | from generateButtons import generateButtons 14 | from radioClickEvent import lookingAt 15 | from setup import fileName 16 | from lxml import etree 17 | 18 | logFile='/tmp/vardbEditor.log' 19 | 20 | def addsignal(signals,self,num,instructions): 21 | parser = etree.XMLParser(remove_blank_text=True) 22 | doc=etree.parse(fileName(),parser) 23 | root=doc.getroot() 24 | log=open(logFile,'a') 25 | #+++++++++++ 26 | if instructions['action']=='edit': 27 | #Expecting signals to be of form [ [attribute,new valie] * n ] 28 | #Edits existing attributes 29 | 30 | added=False 31 | newAtt=[] 32 | j=0 33 | for elm in root.iter('variable'): 34 | if elm.attrib['name'] == signals[0][1].upper(): 35 | 36 | #variable is already in vardb 37 | added=True 38 | 39 | #edit exiting entries 40 | i=0 41 | while i>log, 'changed ', elm.attrib['name'],": ",elm[i].tag,' to '+elm[i].text+'.' 47 | i+=1 48 | 49 | #Check for new entries 50 | for sig in signals: 51 | inThere=False 52 | wasRemoved=False 53 | i=0 54 | while igetDictionary(fileName()).index(sig[0]): 63 | att.addnext(newAtt[j]) 64 | break 65 | j+=1 66 | print('Added ',sig[0],' to ',elm.attrib['name'],' set as ',sig[1]) 67 | print>>log, 'Added ',sig[0],' to ',elm.attrib['name'],' set as ',sig[1] 68 | 69 | #check for blank entries, remove them 70 | for att in elm: 71 | if str(att.text)=='':#and str(att.tag) not in [s[0] for s in self.catelogList]: 72 | print('removed ',att.tag,' from ',elm.attrib['name']) 73 | print>>log, 'removed ',att.tag,' from ',elm.attrib['name'] 74 | elm.remove(att) 75 | if added==False: 76 | instructions['action']='new signal' 77 | print(str(signals[0][1]).upper(),' not found in VDB. Creating new entry.') 78 | print>>log, str(signals[0][1]).upper(),' not found in VDB. Creating new entry.' 79 | #++++++++++++ 80 | if instructions['action']=='delete': 81 | for elm in root.iter('variable'): 82 | if elm.attrib['name']==signals: 83 | elm.getparent().remove(elm) 84 | print('removed ',signals) 85 | print>>log, 'removed ',signals 86 | 87 | #+++++++++++ 88 | if instructions['action']=='new signal': 89 | #Expecting signals to be list of for [ [attribute,value]*n] 90 | #Inserts a new signal into varDB in alphabetical order 91 | 92 | #Check for name input 93 | if signals[0][0]!='name' : 94 | print('exit code 1 in addsignal.py: no name was input') 95 | print>>log, 'exit code 1 in addsignal.py: no name was input' 96 | quit() 97 | 98 | #Insert element 99 | elms=[] 100 | for elm in root.iter('variable'): 101 | elms.append(str(elm.attrib['name'])) 102 | elms.append(str(signals[0][1]).upper()) 103 | elms.sort() 104 | 105 | added=False 106 | i=0 107 | for elm in root.iter('variable'): 108 | if str(elm.attrib['name'])!=elms[i] and added==False: 109 | new = etree.Element('variable',name=signals[0][1].upper()) 110 | l=1 111 | while l>log, 'added ',signals[0][1] 121 | i+=1 122 | if added==False: 123 | new = etree.Element('variable',name=signals[0][1].upper()) 124 | l=1 125 | while l>log, 'appended ',signals[0][1] 134 | 135 | #============= 136 | doc.write(fileName(),pretty_print=True) 137 | generateButtons(self,str(self.searchText.text()),num) 138 | return 139 | 140 | 141 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @mainpage VarDB Library 4 | 5 | ## Introduction ## 6 | 7 | VDBFile is the main class for accessing XML variable databases. The other 8 | classes are VDBVar and VDBDictionary. 9 | 10 | The classes use the Xerces-C++ Document Object Model API to manipulate the 11 | XML database, but that model is hidden by VarDB API. 12 | 13 | ## Building ## 14 | 15 | The vardb library uses eol_scons as the build tool. 16 | 17 | @code 18 | scons # Build default targets 19 | scons test # Run tests 20 | scons pytests # Build the python module and run the python tests 21 | scons apidocs # Generate HTML documentation with doxygen 22 | @endcode 23 | 24 | ## Recent Changes 25 | 26 | Here are changes to the VarDB library since adding the XML format for the 27 | variable database: 28 | 29 | 1. Resolve the XSD schema from memory so it does not need to be installed 30 | next to the vardb.xml file. Likewise, force the validating schema to be 31 | fixed (rather than varying according to the elements in the dictionary), 32 | and force that schema to be used regardless of any schema specified in 33 | the XML file. 34 | 35 | 2. Improve the error reporting on parser errors. 36 | 37 | 3. Keep the use of xerces hidden from the vardb public API rather than 38 | exposing it in the vardb.hh header. 39 | 40 | 4. Add testing. The tests source directory contains tests written using 41 | the Google test framework. The tests verify things like API behavior 42 | and preservation of XML comments across edits. 43 | 44 | 5. Clean up and simplify vdb2xml. The converter now uses the VDBFile API 45 | to create a variable database rather than printing XML syntax directly. 46 | The API directly modifies the DOM in memory as the database is changed, 47 | and then that DOM can be streamed to a file as XML. 48 | 49 | 6. All of the python artifacts for generating XML have been removed, such 50 | as schemaMaker.py, standardNameCorrection.py, appendInfo.py, and the 51 | vdb2xml.sh script. 52 | 53 | Originally the schema was generated according to the contents of the 54 | Dictionary file, meaning elements had to exist in the Dictionary before 55 | they could be validated in an XML database file. However, that introduces 56 | practical problems as far as where the Dictionary should be located, and it 57 | means each XML database also has its own specific schema file to which it 58 | must refer. Instead, the schema is now fixed and compiled into the code. 59 | The dictionary is the part of the schema, and it can describe the variable 60 | attributes in the schema as well as attributes not in the schema. However, 61 | there is currently no way to validate an XML file with variable attributes 62 | which are only in the dictionary and not in the schema. If we end up 63 | wanting to use Xerces to validate against the dictionary, then it may be 64 | possible to load the XML first without validation, find the dictionary 65 | element, generate a schema in memory, and finally supply the generated 66 | schema to load the XML a second time and validate it. 67 | 68 | The use of 'any' in XML Schema may also provide a cool solution for this. 69 | As new elements are added, they could be defined in their own schemas, and 70 | a vdb xml file can extend the basic schema with those new schemas. New 71 | elements still cannot be added arbitarily though (ie, at runtime). 72 | 73 | Another option is to drop schema validation completely. Instead, load the 74 | XML without validation (meaning it is well-formed), then explicitly check 75 | that all the variable attribute elements exist in the dictionary. 76 | 77 | For the moment, though, there is not enough of a need to extend the 78 | variable attributes in the database to warrant more complicated validation. 79 | 80 | ## To Do ## 81 | 82 | ### Rewrite the Graphical Editor ### 83 | 84 | Wrap the C++ VDBFile interface in a python module and re-write the 85 | Python-Qt editor to use that interface. (Presumably that would be easier 86 | than porting the binary editor to the new API and a newer GUI toolkit.) 87 | 88 | Probably there needs to be a standalone vardb editor first, to facilitate 89 | replacing the binary vardb files with XML, until the variable metadata 90 | editing can be incorporated into the config editor. 91 | 92 | ### Implement a Validation Layer in the Library ### 93 | 94 | Start including and migrating "business and validation logic" into the 95 | VDBFile library, eg, the standard_name attribute must be in the list of 96 | standard_names, likewise for category, some attributes take specific forms 97 | like voltage ranges, and some must be numeric. Some of that validation 98 | could be done by the schema. 99 | 100 | ### Incorporate Other Config Files as Possible ### 101 | 102 | Somehow reconcile the rest of the files in Configuration/ and the 103 | project directory associated with variable metadata and processing, eg, 104 | include _projdir_/Lags in vardb.xml. From _defaultprojdir_ include 105 | SumVars, LowRateVars, Despike, and BcastVars, MetaDataTable. These and the 106 | DerivedNames and other cross-project defaults should be in one variable 107 | database XML file, and then project-specific settings can be overridden 108 | (where they are not already exclusive to one domain or the other) in the 109 | project file. 110 | 111 | 112 | ### Consolidate Variable Metadata from XML File and Real-time Database ### 113 | 114 | The database variable_list table contains the currently active real-time 115 | variables and some of their metadata, so in real-time it should serve as 116 | the most consistent and accessible source for variables and metadata. 117 | Normally it will be consistent with what is in the nidas XML file and the 118 | XML variable database (VDBFile), but it does not contain all the metadata 119 | from those files. For example, the variable_list table does not contain 120 | the min/max limits from the XML file, and those are needed for tools like 121 | real-time qc checks. Therefore this class provides a consolidated view of 122 | the real-time variable metadata by augmenting the database variable_list 123 | with the metadata from the VDB XML file. Eventually this consolidated view 124 | should also include the nidas XML file. Either all of the requisite 125 | metadata can be put in the variable_list table where other applications can 126 | get it, or there should be an API in both C++ and Python which provides a 127 | single, consistent, consolidated view of variables and metadata. The 128 | latter would be better, since it might be made to work the same for both 129 | real-time and post-processing and encapsulate the SQL access. 130 | 131 | More elaborate solutions for consolidated access to variable metadata could 132 | use a web application with a SOAP or REST interface. A web app which 133 | encapsulates variable metadata can run on the plane and in EOL and provide 134 | access methods (and perhaps even editing) for both software and users. 135 | 136 | **/ 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/vdbdump/fix_units.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: fix_units.c 4 | 5 | FULL NAME: VarDB dump 6 | 7 | DESCRIPTION: Mass replacement of units with units that conform to Unidata 8 | UD Units project. This doesn't do lookups in UDunits, you 9 | need to hardcode the changes into this program. 10 | 11 | COPYRIGHT: University Corporation for Atmospheric Research, 2005 12 | 13 | COMPILE: g++ -I../vardb/raf -I../../raf fix_units.cc -L../vardb -L../../raf -lVarDB -lraf -lnetcdf -o fix_units 14 | 15 | ------------------------------------------------------------------------- 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | extern long VarDB_nRecords; 26 | 27 | /* -------------------------------------------------------------------- */ 28 | int main(int argc, char *argv[]) 29 | { 30 | if (argc < 2) 31 | { 32 | fprintf(stderr, "Usage: vdbdump [-a] [proj_num | VarDB_filename]\n"); 33 | return(1); 34 | } 35 | 36 | if (InitializeVarDB(argv[1]) == ERR) 37 | { 38 | fprintf(stderr, "vdbdump: Initialize failure.\n"); 39 | return(1); 40 | } 41 | 42 | 43 | printf("Version %d, with %d records.\n", ntohl(master_VarDB_Hdr.Version), 44 | VarDB_nRecords); 45 | 46 | VarDB_SetUnits("CLAT", "degree_N"); 47 | VarDB_SetMinLimit("CLAT", -90.0); 48 | VarDB_SetMaxLimit("CLAT", 90.0); 49 | 50 | VarDB_SetUnits("GLAT", "degree_N"); 51 | VarDB_SetMinLimit("GLAT", -90.0); 52 | VarDB_SetMaxLimit("GLAT", 90.0); 53 | 54 | VarDB_SetUnits("GGLAT", "degree_N"); 55 | VarDB_SetMinLimit("GGLAT", -90.0); 56 | VarDB_SetMaxLimit("GGLAT", 90.0); 57 | 58 | VarDB_SetUnits("LAT", "degree_N"); 59 | VarDB_SetMinLimit("LAT", -90.0); 60 | VarDB_SetMaxLimit("LAT", 90.0); 61 | 62 | VarDB_SetUnits("DSLAT", "degree_N"); 63 | VarDB_SetMinLimit("DSLAT", -90.0); 64 | VarDB_SetMaxLimit("DSLAT", 90.0); 65 | 66 | VarDB_SetUnits("LATC", "degree_N"); 67 | VarDB_SetMinLimit("LATC", -90.0); 68 | VarDB_SetMaxLimit("LATC", 90.0); 69 | 70 | VarDB_SetUnits("XLATC", "degree_N"); 71 | VarDB_SetMinLimit("XLATC", -90.0); 72 | VarDB_SetMaxLimit("XLATC", 90.0); 73 | 74 | 75 | VarDB_SetUnits("CLON", "degree_E"); 76 | VarDB_SetMinLimit("CLON", -180.0); 77 | VarDB_SetMaxLimit("CLON", 180.0); 78 | 79 | VarDB_SetUnits("GLON", "degree_E"); 80 | VarDB_SetMinLimit("GLON", -180.0); 81 | VarDB_SetMaxLimit("GLON", 180.0); 82 | 83 | VarDB_SetUnits("GGLON", "degree_E"); 84 | VarDB_SetMinLimit("GGLON", -180.0); 85 | VarDB_SetMaxLimit("GGLON", 180.0); 86 | 87 | VarDB_SetUnits("LON", "degree_E"); 88 | VarDB_SetMinLimit("LON", -180.0); 89 | VarDB_SetMaxLimit("LON", 180.0); 90 | 91 | VarDB_SetUnits("DSLON", "degree_E"); 92 | VarDB_SetMinLimit("DSLON", -180.0); 93 | VarDB_SetMaxLimit("DSLON", 180.0); 94 | 95 | VarDB_SetUnits("LONC", "degree_E"); 96 | VarDB_SetMinLimit("LONC", -180.0); 97 | VarDB_SetMaxLimit("LONC", 180.0); 98 | 99 | VarDB_SetUnits("XLONC", "degree_E"); 100 | VarDB_SetMinLimit("XLONC", -180.0); 101 | VarDB_SetMaxLimit("XLONC", 180.0); 102 | 103 | VarDB_SetUnits("WD", "degree_T"); 104 | VarDB_SetMinLimit("WD", 0.0); 105 | VarDB_SetMaxLimit("WD", 360.0); 106 | VarDB_SetUnits("WDC", "degree_T"); 107 | VarDB_SetMinLimit("WDC", 0.0); 108 | VarDB_SetMaxLimit("WDC", 360.0); 109 | VarDB_SetUnits("CTHDG", "degree_T"); 110 | VarDB_SetMinLimit("CTHDG", 0.0); 111 | VarDB_SetMaxLimit("CTHDG", 360.0); 112 | VarDB_SetUnits("TKAT", "degree_T"); 113 | VarDB_SetMinLimit("TKAT", 0.0); 114 | VarDB_SetMaxLimit("TKAT", 360.0); 115 | VarDB_SetUnits("THDG", "degree_T"); 116 | VarDB_SetMinLimit("THDG", 0.0); 117 | VarDB_SetMaxLimit("THDG", 360.0); 118 | VarDB_SetUnits("GGTRK", "degree_T"); 119 | VarDB_SetMinLimit("GGTRK", 0.0); 120 | VarDB_SetMaxLimit("GGTRK", 360.0); 121 | VarDB_SetUnits("DSWD", "degree_T"); 122 | VarDB_SetMinLimit("DSWD", 0.0); 123 | VarDB_SetMaxLimit("DSWD", 360.0); 124 | 125 | VarDB_SetMinLimit("DRFTA", -90.0); 126 | VarDB_SetMaxLimit("DRFTA", 90.0); 127 | VarDB_SetMinLimit("CROLL", -180.0); 128 | VarDB_SetMaxLimit("CROLL", 180.0); 129 | VarDB_SetMinLimit("ROLL", -180.0); 130 | VarDB_SetMaxLimit("ROLL", 180.0); 131 | VarDB_SetMinLimit("CPITCH", -180.0); 132 | VarDB_SetMaxLimit("CPITCH", 180.0); 133 | VarDB_SetMinLimit("PITCH", -180.0); 134 | VarDB_SetMaxLimit("PITCH", 180.0); 135 | 136 | VarDB_SetUnits("EV1", "none"); 137 | 138 | for (int i = 0; i < VarDB_nRecords; ++i) 139 | { 140 | char *vu, *p; 141 | 142 | vu = ((struct var_v2 *)VarDB)[i].Units; 143 | 144 | /* Clean up metres first. 145 | */ 146 | if (strcmp(vu, "M") == 0) 147 | strcpy(vu, "m"); 148 | 149 | if ((p = strstr(vu, "uM")) || (p = strstr(vu, "kM"))) 150 | *(p+1) = 'm'; 151 | 152 | if ((p = strstr(vu, "M/")) ) 153 | *p = 'm'; 154 | 155 | if ((p = strstr(vu, "M2")) ) 156 | *p = 'm'; 157 | 158 | if ((p = strstr(vu, "M3")) ) 159 | *p = 'm'; 160 | 161 | if (strcmp(vu, "kV/M") == 0) 162 | strcpy(vu, "kV/m"); 163 | 164 | if (strcmp(vu, "kVdc") == 0) 165 | strcpy(vu, "kV"); 166 | 167 | 168 | if (strcmp(vu, "Vdc") == 0 || strcmp(vu, "Volts") == 0) 169 | strcpy(vu, "V"); 170 | 171 | if (strcmp(vu, "C") == 0) 172 | strcpy(vu, "deg_C"); 173 | 174 | if (strcmp(vu, "G") == 0) 175 | strcpy(vu, "g"); 176 | 177 | if (strcmp(vu, "hours") == 0) 178 | strcpy(vu, "hour"); 179 | 180 | if (strcmp(vu, "radians") == 0) 181 | strcpy(vu, "radian"); 182 | 183 | if (strcmp(vu, "minutes") == 0) 184 | strcpy(vu, "minute"); 185 | 186 | if (strcmp(vu, "knots") == 0) 187 | strcpy(vu, "knot"); 188 | 189 | if (strcmp(vu, "deg") == 0) 190 | strcpy(vu, "degree"); 191 | 192 | if (strncmp(vu, "micron", 6) == 0) 193 | strcpy(vu, "um"); 194 | 195 | if (strcmp(vu, "deg/S") == 0) 196 | strcpy(vu, "deg/s"); 197 | 198 | if (strcmp(vu, "g/m3") == 0) 199 | strcpy(vu, "gram/m3"); 200 | 201 | if (strcmp(vu, "g/kg") == 0) 202 | strcpy(vu, "gram/kg"); 203 | 204 | 205 | if (strcmp(vu, "Lpm") == 0) 206 | strcpy(vu, "L/min"); 207 | 208 | if (strcmp(vu, "cc/m3") == 0) 209 | strcpy(vu, "cm3/m3"); 210 | 211 | if (strcmp(vu, "cnts") == 0 || 212 | strcmp(vu, "cnt") == 0 || 213 | strcmp(vu, "counts") == 0) 214 | strcpy(vu, "count"); 215 | 216 | if ( (p = strstr(vu, "N/")) ) 217 | *p = '#'; 218 | 219 | 220 | printf("%-16s %-16s %-60s\n", ((struct var_v2 *)VarDB)[i].Name, 221 | ((struct var_v2 *)VarDB)[i].Units, ((struct var_v2 *)VarDB)[i].Title); 222 | /* 223 | ulong p0, p1; 224 | float *rc0 = (float *)&p0, *rc1 = (float *)&p1; 225 | 226 | p0 = ntohl(*((int *)&(((struct var_v2 *)VarDB)[i].MinLimit))); 227 | p1 = ntohl(*((int *)&(((struct var_v2 *)VarDB)[i].MaxLimit))); 228 | printf(" %6.1f %6.1f\n", *rc0, *rc1); 229 | */ 230 | } 231 | 232 | SaveVarDB(argv[1]); 233 | ReleaseVarDB(); 234 | 235 | return(0); 236 | 237 | } 238 | -------------------------------------------------------------------------------- /src/vardb/get.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: get.c 4 | 5 | FULL NAME: VarDB_Get* functions 6 | 7 | DESCRIPTION: 8 | 9 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2011 10 | ------------------------------------------------------------------------- 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "raf/vardb.h" 17 | #include 18 | #include 19 | 20 | static struct var_v2 defaults = 21 | { 22 | "", "Unk", "Unk", "No title", 23 | false, {-10, 10}, 100, 0.0, 0.0, {0.0, 0.0}, 0, 0, 0 24 | }; 25 | 26 | static const float default_FillValue = -32767.0; 27 | 28 | 29 | extern char VarDB_NcML_text_result[]; 30 | 31 | 32 | /* -------------------------------------------------------------------- */ 33 | const char *VarDB_GetUnits(const char vn[]) 34 | { 35 | int indx; 36 | 37 | if ((indx = VarDB_lookup(vn)) == ERR) 38 | return(defaults.Units); 39 | 40 | if (VarDB_NcML > 0) 41 | { 42 | if (nc_get_att_text(VarDB_NcML, indx, "units", VarDB_NcML_text_result) == NC_NOERR) 43 | return VarDB_NcML_text_result; 44 | else 45 | return 0; 46 | } 47 | 48 | return(((struct var_v2 *)VarDB)[indx].Units); 49 | 50 | } /* END VARDB_GETUNITS */ 51 | 52 | /* -------------------------------------------------------------------- */ 53 | const char *VarDB_GetAlternateUnits(const char vn[]) 54 | { 55 | int indx; 56 | 57 | if ((indx = VarDB_lookup(vn)) == ERR) 58 | return(defaults.AlternateUnits); 59 | 60 | if (VarDB_NcML > 0) 61 | return 0; 62 | 63 | return(((struct var_v2 *)VarDB)[indx].AlternateUnits); 64 | 65 | } /* END VARDB_GETALTERNATEUNITS */ 66 | 67 | /* -------------------------------------------------------------------- */ 68 | const char *VarDB_GetTitle(const char vn[]) 69 | { 70 | int indx; 71 | 72 | if ((indx = VarDB_lookup(vn)) == ERR) 73 | return(defaults.Title); 74 | 75 | if (VarDB_NcML > 0) 76 | { 77 | if (nc_get_att_text(VarDB_NcML, indx, "long_name", VarDB_NcML_text_result) == NC_NOERR) 78 | return VarDB_NcML_text_result; 79 | else 80 | return 0; 81 | } 82 | 83 | return(((struct var_v2 *)VarDB)[indx].Title); 84 | 85 | } /* END VARDB_GETTITLE */ 86 | 87 | /* -------------------------------------------------------------------- */ 88 | const char *VarDB_GetDependencies(const char vn[]) 89 | { 90 | int indx; 91 | 92 | if ((indx = VarDB_lookup(vn)) == ERR) 93 | return 0; 94 | 95 | if (VarDB_NcML > 0) 96 | { 97 | if (nc_get_att_text(VarDB_NcML, indx, "Dependencies", VarDB_NcML_text_result) == NC_NOERR) 98 | return VarDB_NcML_text_result; 99 | } 100 | 101 | return 0; 102 | 103 | } /* END VARDB_GETDEPENDENCIES */ 104 | 105 | /* -------------------------------------------------------------------- */ 106 | bool VarDB_isAnalog(const char vn[]) 107 | { 108 | int indx; 109 | long type; 110 | 111 | if ((indx = VarDB_lookup(vn)) == ERR) 112 | return(FALSE); 113 | 114 | if (VarDB_NcML > 0) // Not really supported under ADS3. 115 | return FALSE; 116 | 117 | type = ntohl(((struct var_v2 *)VarDB)[indx].is_analog); 118 | 119 | return(type); 120 | 121 | } /* END VARDB_ISRANGEFIXED */ 122 | 123 | /* -------------------------------------------------------------------- */ 124 | int32_t VarDB_GetVoltageRangeLower(const char vn[]) 125 | { 126 | int indx; 127 | 128 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 129 | return(defaults.voltageRange[0]); 130 | 131 | return(ntohl(((struct var_v2 *)VarDB)[indx].voltageRange[0])); 132 | 133 | } /* END VARDB_GETFIXEDRANGELOWER */ 134 | 135 | /* -------------------------------------------------------------------- */ 136 | int32_t VarDB_GetVoltageRangeUpper(const char vn[]) 137 | { 138 | int indx; 139 | 140 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 141 | return(defaults.voltageRange[1]); 142 | 143 | return(ntohl(((struct var_v2 *)VarDB)[indx].voltageRange[1])); 144 | 145 | } /* END VARDB_GETFIXEDRANGEUPPER */ 146 | 147 | /* -------------------------------------------------------------------- */ 148 | float VarDB_DefaultSampleRate(const char vn[]) 149 | { 150 | int indx; 151 | 152 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 153 | return(defaults.defaultSampleRate); 154 | 155 | return(ntohf(((struct var_v2 *)VarDB)[indx].defaultSampleRate)); 156 | 157 | } /* END VARDB_GETFLOATRANGE */ 158 | 159 | /* -------------------------------------------------------------------- */ 160 | float VarDB_GetFillValue(const char vn[]) 161 | { 162 | int indx; 163 | 164 | if ((indx = VarDB_lookup(vn)) == ERR) 165 | return(default_FillValue); 166 | 167 | if (VarDB_NcML > 0) 168 | { 169 | float fv; 170 | if (nc_get_att_float(VarDB_NcML, indx, "_FillValue", &fv) == NC_NOERR) 171 | return fv; 172 | else 173 | return 0; 174 | } 175 | 176 | return(default_FillValue); 177 | 178 | } /* END VARDB_GETMINLIMIT */ 179 | 180 | /* -------------------------------------------------------------------- */ 181 | float VarDB_GetMinLimit(const char vn[]) 182 | { 183 | int indx; 184 | 185 | if ((indx = VarDB_lookup(vn)) == ERR) 186 | return(defaults.MinLimit); 187 | 188 | if (VarDB_NcML > 0) 189 | { 190 | float range[2]; 191 | if (nc_get_att_float(VarDB_NcML, indx, "valid_range", range) == NC_NOERR) 192 | return range[0]; 193 | else 194 | return 0; 195 | } 196 | 197 | return(ntohf(((struct var_v2 *)VarDB)[indx].MinLimit)); 198 | 199 | } /* END VARDB_GETMINLIMIT */ 200 | 201 | /* -------------------------------------------------------------------- */ 202 | float VarDB_GetMaxLimit(const char vn[]) 203 | { 204 | int indx; 205 | 206 | if ((indx = VarDB_lookup(vn)) == ERR) 207 | return(defaults.MaxLimit); 208 | 209 | if (VarDB_NcML > 0) 210 | { 211 | float range[2]; 212 | if (nc_get_att_float(VarDB_NcML, indx, "valid_range", range) == NC_NOERR) 213 | return range[1]; 214 | else 215 | return 0; 216 | } 217 | 218 | return(ntohf(((struct var_v2 *)VarDB)[indx].MaxLimit)); 219 | 220 | } /* END VARDB_GETMAXLIMIT */ 221 | 222 | /* -------------------------------------------------------------------- */ 223 | float VarDB_GetCalRangeLower(const char vn[]) 224 | { 225 | int indx; 226 | 227 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 228 | return(defaults.CalRange[0]); 229 | 230 | return(ntohf(((struct var_v2 *)VarDB)[indx].CalRange[0])); 231 | 232 | } /* END VARDB_GETCALRANGELOWER */ 233 | 234 | /* -------------------------------------------------------------------- */ 235 | float VarDB_GetCalRangeUpper(const char vn[]) 236 | { 237 | int indx; 238 | 239 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 240 | return(defaults.CalRange[1]); 241 | 242 | return(ntohf(((struct var_v2 *)VarDB)[indx].CalRange[1])); 243 | 244 | } /* END VARDB_GETCALRANGEUPPER */ 245 | 246 | /* -------------------------------------------------------------------- */ 247 | int VarDB_GetCategory(const char vn[]) 248 | { 249 | int indx; 250 | 251 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 252 | return(defaults.Category); 253 | 254 | return(ntohl(((struct var_v2 *)VarDB)[indx].Category)); 255 | 256 | } /* END VARDB_GETCATEGORY */ 257 | 258 | /* -------------------------------------------------------------------- */ 259 | int VarDB_GetStandardName(const char vn[]) 260 | { 261 | int indx; 262 | 263 | if ((indx = VarDB_lookup(vn)) == ERR || VarDB_NcML > 0) 264 | return(defaults.standard_name); 265 | 266 | return(ntohl(((struct var_v2 *)VarDB)[indx].standard_name)); 267 | 268 | } /* END VARDB_GETCATEGORY */ 269 | 270 | /* END GET.C */ 271 | -------------------------------------------------------------------------------- /src/vdbdump/set_categories.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: set_categories.c 4 | 5 | FULL NAME: VarDB dump w/ Categories 6 | 7 | DESCRIPTION: Update categories. 8 | 9 | COPYRIGHT: University Corporation for Atmospheric Research, 2025 10 | 11 | COMPILE: g++ -I../vardb/raf -I../../raf set_categories.cc -L../vardb -L../../raf -lVarDB -lraf -lnetcdf -o set_categories 12 | ------------------------------------------------------------------------- 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | extern long VarDB_nRecords; 24 | 25 | /* -------------------------------------------------------------------- */ 26 | int main(int argc, char *argv[]) 27 | { 28 | int i; 29 | 30 | if (argc != 2) 31 | { 32 | fprintf(stderr, "Usage: catdump [proj_num | VarDB_filename]\n"); 33 | exit(1); 34 | } 35 | 36 | if (InitializeVarDB(argv[1]) == ERR) 37 | { 38 | fprintf(stderr, "catdump: Initialize failure.\n"); 39 | exit(1); 40 | } 41 | 42 | 43 | printf("Version %d, with %d records.\n", ntohl(master_VarDB_Hdr.Version), 44 | VarDB_nRecords); 45 | 46 | for (i = 0; i < VarDB_nRecords; ++i) 47 | { 48 | /* Done, don't do again, but here for reference. 49 | // Move old Aerosol to new Aerosol 50 | if (ntohl(((struct var_v2 *)VarDB)[i].Category) == 13) 51 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 5); 52 | */ 53 | 54 | // NavAttitide 55 | if (strstr(((struct var_v2 *)VarDB)[i].Name, "PITCH") || 56 | strstr(((struct var_v2 *)VarDB)[i].Name, "ROLL") || 57 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DRFTA") == 0 || 58 | strncmp(((struct var_v2 *)VarDB)[i].Name, "BL", 2) == 0 || 59 | strncmp(((struct var_v2 *)VarDB)[i].Name, "AK", 2) == 0 || 60 | strncmp(((struct var_v2 *)VarDB)[i].Name, "SS", 2) == 0 || 61 | strcmp(((struct var_v2 *)VarDB)[i].Name, "ATTACK") == 0 || 62 | strcmp(((struct var_v2 *)VarDB)[i].Name, "BNORMA") == 0 || 63 | strstr(((struct var_v2 *)VarDB)[i].Name, "YAW")) 64 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 13); 65 | 66 | 67 | 68 | // Cloud 69 | if (strncmp(((struct var_v2 *)VarDB)[i].Name, "XG", 2) == 0 || 70 | strcmp(((struct var_v2 *)VarDB)[i].Name, "NLWCC") == 0 || 71 | strcmp(((struct var_v2 *)VarDB)[i].Name, "NTWCC") == 0 || 72 | strncmp(((struct var_v2 *)VarDB)[i].Name, "PLWCC", 5) == 0 || 73 | strcmp(((struct var_v2 *)VarDB)[i].Name, "RICE") == 0) 74 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 8); 75 | 76 | // Aerosol 77 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, "CONCN") == 0 || 78 | strcmp(((struct var_v2 *)VarDB)[i].Name, "XUFCN") == 0 || 79 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 5); 80 | 81 | // Radiation 82 | if (strncmp(((struct var_v2 *)VarDB)[i].Name, "SOL", 3) == 0) 83 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 11); 84 | 85 | // NavPosition 86 | if (strncmp(((struct var_v2 *)VarDB)[i].Name, "ALT", 3) == 0) 87 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 1); 88 | 89 | // NavVelocity 90 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, "VZI") == 0 || 91 | strncmp(((struct var_v2 *)VarDB)[i].Name, "TAS", 3) == 0 || 92 | strcmp(((struct var_v2 *)VarDB)[i].Name, "XMACH2") == 0) 93 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 3); 94 | 95 | // Chemistry 96 | if (strncmp(((struct var_v2 *)VarDB)[i].Name, "XWL", 3) == 0 || 97 | strncmp(((struct var_v2 *)VarDB)[i].Name, "AO2", 3) == 0) 98 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 10); 99 | 100 | // Atmos State 101 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, "PSC") == 0 || 102 | strcmp(((struct var_v2 *)VarDB)[i].Name, "OAT") == 0 || 103 | strcmp(((struct var_v2 *)VarDB)[i].Name, "ATLH") == 0) 104 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 4); 105 | 106 | // Raw uncorr 107 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, "XPSFD") == 0 || 108 | strcmp(((struct var_v2 *)VarDB)[i].Name, "PSFRD") == 0 || 109 | strstr(((struct var_v2 *)VarDB)[i].Name, "DIFR") || 110 | strcmp(((struct var_v2 *)VarDB)[i].Name, "CORAW") == 0 || 111 | strcmp(((struct var_v2 *)VarDB)[i].Name, "NO") == 0 || 112 | strcmp(((struct var_v2 *)VarDB)[i].Name, "FO3") == 0 || 113 | strcmp(((struct var_v2 *)VarDB)[i].Name, "NOY") == 0 || 114 | strcmp(((struct var_v2 *)VarDB)[i].Name, "SO2") == 0 || 115 | strcmp(((struct var_v2 *)VarDB)[i].Name, "FCN") == 0 || 116 | strcmp(((struct var_v2 *)VarDB)[i].Name, "TEO3") == 0 || 117 | strcmp(((struct var_v2 *)VarDB)[i].Name, "CORAW") == 0 || 118 | strcmp(((struct var_v2 *)VarDB)[i].Name, "PSLH") == 0) 119 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 6); 120 | 121 | // Housekeeping 122 | if (strstr(((struct var_v2 *)VarDB)[i].Name, "CAV") || 123 | strstr(((struct var_v2 *)VarDB)[i].Name, "TIME") || 124 | strncmp(((struct var_v2 *)VarDB)[i].Name, "XUV", 3) == 0 || 125 | strncmp(((struct var_v2 *)VarDB)[i].Name, "2D", 2) == 0 || 126 | strncmp(((struct var_v2 *)VarDB)[i].Name, "HV", 2) == 0 || 127 | strncmp(((struct var_v2 *)VarDB)[i].Name, "H2D", 3) == 0 || 128 | strncmp(((struct var_v2 *)VarDB)[i].Name, "THIM", 4) == 0 || 129 | strncmp(((struct var_v2 *)VarDB)[i].Name, "TCAB", 4) == 0 || 130 | strncmp(((struct var_v2 *)VarDB)[i].Name, "MED", 3) == 0 || 131 | strncmp(((struct var_v2 *)VarDB)[i].Name, "PER", 3) == 0 || 132 | strncmp(((struct var_v2 *)VarDB)[i].Name, "SDW", 3) == 0 || 133 | strncmp(((struct var_v2 *)VarDB)[i].Name, "SHDOR", 5) == 0 || 134 | strncmp(((struct var_v2 *)VarDB)[i].Name, "SPB", 3) == 0 || 135 | strncmp(((struct var_v2 *)VarDB)[i].Name, "SPT", 3) == 0 || 136 | strncmp(((struct var_v2 *)VarDB)[i].Name, "XAE", 3) == 0 || 137 | strncmp(((struct var_v2 *)VarDB)[i].Name, "XCELL", 5) == 0 || 138 | strncmp(((struct var_v2 *)VarDB)[i].Name, "INLET", 5) == 0 || 139 | strcmp(((struct var_v2 *)VarDB)[i].Name, "AO2STAT") == 0 || 140 | strcmp(((struct var_v2 *)VarDB)[i].Name, "FCNC") == 0 || 141 | strcmp(((struct var_v2 *)VarDB)[i].Name, "PCN") == 0 || 142 | strcmp(((struct var_v2 *)VarDB)[i].Name, "XICNC") == 0 || 143 | strcmp(((struct var_v2 *)VarDB)[i].Name, "NSYS") == 0 || 144 | strcmp(((struct var_v2 *)VarDB)[i].Name, "COZRO") == 0 || 145 | strcmp(((struct var_v2 *)VarDB)[i].Name, "TASFLG") == 0 || 146 | strcmp(((struct var_v2 *)VarDB)[i].Name, "CMODE") == 0 || 147 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DPB") == 0 || 148 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DPT") == 0 || 149 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DPL") == 0 || 150 | strcmp(((struct var_v2 *)VarDB)[i].Name, "TEP") == 0 || 151 | strcmp(((struct var_v2 *)VarDB)[i].Name, "TET") == 0 || 152 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DPR") == 0 || 153 | strcmp(((struct var_v2 *)VarDB)[i].Name, "XTUBETEMP") == 0 || 154 | strcmp(((struct var_v2 *)VarDB)[i].Name, "HOUR") == 0 || 155 | strcmp(((struct var_v2 *)VarDB)[i].Name, "MINUTE") == 0 || 156 | strcmp(((struct var_v2 *)VarDB)[i].Name, "SECOND") == 0 || 157 | strcmp(((struct var_v2 *)VarDB)[i].Name, "YEAR") == 0 || 158 | strcmp(((struct var_v2 *)VarDB)[i].Name, "MONTH") == 0 || 159 | strcmp(((struct var_v2 *)VarDB)[i].Name, "DAY") == 0 || 160 | strcmp(((struct var_v2 *)VarDB)[i].Name, "XSIGV") == 0) 161 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 9); 162 | 163 | 164 | // None 165 | if (strncmp(((struct var_v2 *)VarDB)[i].Name, "DIFF", 4) == 0) 166 | VarDB_SetCategory(((struct var_v2 *)VarDB)[i].Name, 0); 167 | 168 | printf("%-12.12s %-40.40s %-15.15s %d %s\n", 169 | ((struct var_v2 *)VarDB)[i].Name, 170 | ((struct var_v2 *)VarDB)[i].Title, 171 | VarDB_GetCategoryName(((struct var_v2 *)VarDB)[i].Name), 172 | VarDB_GetStandardName(((struct var_v2 *)VarDB)[i].Name), 173 | VarDB_GetStandardNameName(((struct var_v2 *)VarDB)[i].Name)); 174 | } 175 | 176 | SaveVarDB(argv[1]); 177 | ReleaseVarDB(); 178 | 179 | return(0); 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/vdb2ncml/vdb2ncml.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: vdb2ncml.cc 4 | 5 | FULL NAME: Convert VarDB to NcML. 6 | 7 | DESCRIPTION: Converts VarDB, Categories, StandardNames, DerivedNames, 8 | DependTable, ModVars and AircraftSpecs to NcML. 9 | 10 | COPYRIGHT: University Corporation for Atmospheric Research, 2006 11 | ------------------------------------------------------------------------- 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | static char defaultProjDir[1000]; 25 | static char projDir[1000]; 26 | 27 | static const char COMMENT = '#'; 28 | static const float fill_value = -32767.0; 29 | 30 | extern long VarDB_nRecords; 31 | 32 | /* -------------------------------------------------------------------- */ 33 | void checkModVars(int ncid, int varID, const char *varName) 34 | { 35 | char fileName[500], buffer[BUFSIZ], name[100]; 36 | strcpy(fileName, defaultProjDir); 37 | strcat(fileName, "ModVars"); 38 | 39 | FILE *fp; 40 | if ((fp = fopen(fileName, "r")) == NULL) 41 | { 42 | fprintf(stderr, "vdb2ncml:checkModVars: Failed to open '%s'.\n", fileName); 43 | return; 44 | } 45 | 46 | float vals[2]; 47 | while (fgets(buffer, BUFSIZ, fp)) 48 | { 49 | if (buffer[0] == COMMENT) 50 | continue; 51 | 52 | sscanf(buffer, "%s %f %f", name, &vals[0], &vals[1]); 53 | 54 | if (strcmp(name, varName) == 0) 55 | nc_put_att_float(ncid, varID, "modulus_range", NC_FLOAT, 2, vals); 56 | } 57 | 58 | fclose(fp); 59 | } 60 | 61 | /* -------------------------------------------------------------------- */ 62 | void checkDerivedNames(int ncid, int varID, const char *varName) 63 | { 64 | char fileName[500], buffer[BUFSIZ], *p; 65 | strcpy(fileName, defaultProjDir); 66 | strcat(fileName, "DerivedNames"); 67 | 68 | FILE *fp; 69 | if ((fp = fopen(fileName, "r")) == NULL) 70 | { 71 | fprintf(stderr, "vdb2ncml:checkDerivedNames: Failed to open '%s'.\n", fileName); 72 | return; 73 | } 74 | 75 | while (fgets(buffer, BUFSIZ, fp)) 76 | { 77 | if (buffer[0] == COMMENT) 78 | continue; 79 | 80 | p = strtok(buffer, " \t"); 81 | 82 | if (strcmp(p, varName) == 0) 83 | { 84 | p = strtok(NULL, "\n"); 85 | while (isspace(*p)) ++p; 86 | nc_put_att_text(ncid, varID, "derive", strlen(p)+1, p); 87 | } 88 | } 89 | 90 | fclose(fp); 91 | } 92 | 93 | /* -------------------------------------------------------------------- */ 94 | void checkDependencies(int ncid, int varID, const char *varName) 95 | { 96 | char fileName[500], buffer[BUFSIZ], *p; 97 | strcpy(fileName, projDir); 98 | strcat(fileName, "DependTable"); 99 | 100 | FILE *fp; 101 | if ((fp = fopen(fileName, "r")) == NULL) 102 | { 103 | fprintf(stderr, "vdb2ncml:checkDependencies: Failed to open '%s'.\n", fileName); 104 | return; 105 | } 106 | 107 | while (fgets(buffer, BUFSIZ, fp)) 108 | { 109 | if (buffer[0] == COMMENT) 110 | continue; 111 | 112 | p = strtok(buffer, " \t\n"); 113 | 114 | if (p && strcmp(p, varName) == 0) 115 | { 116 | if ( (p = strtok(NULL, "\n")) ) 117 | { 118 | while (isspace(*p)) ++p; 119 | nc_put_att_text(ncid, varID, "Dependencies", strlen(p)+1, p); 120 | } 121 | else 122 | nc_put_att_text(ncid, varID, "Dependencies", 1, ""); 123 | } 124 | } 125 | 126 | fclose(fp); 127 | } 128 | 129 | /* -------------------------------------------------------------------- */ 130 | int main(int argc, char *argv[]) 131 | { 132 | int i = 1, ncid, timeDim, varID; 133 | char outFile[512]; 134 | const char *p; 135 | 136 | if (argc < 2) 137 | { 138 | fprintf(stderr, "Usage: vdbdump [-a] [proj_num | VarDB_filename]\n"); 139 | return(1); 140 | } 141 | 142 | if (InitializeVarDB(argv[i]) == ERR) 143 | { 144 | fprintf(stderr, "vdb2ncml: Initialize failure.\n"); 145 | return(1); 146 | } 147 | 148 | strcpy(defaultProjDir, getenv("PROJ_DIR")); 149 | strcat(defaultProjDir, "/Configuration/"); 150 | 151 | if (strchr(argv[i], '/')) 152 | { 153 | strcpy(projDir, argv[i]); 154 | dirname(projDir); 155 | strcat(projDir, "/"); 156 | } 157 | else 158 | projDir[0] = '\0'; 159 | 160 | strcpy(outFile, argv[i]); 161 | strcat(outFile, ".nc"); 162 | 163 | if (nc_create(outFile, 0, &ncid) != NC_NOERR) 164 | { 165 | fprintf(stderr, "vdb2ncml: Can't create output file %s.\n", outFile); 166 | return(1); 167 | } 168 | 169 | 170 | // Time dimension. Do we have to have a dimension? 171 | nc_def_dim(ncid, "Time", NC_UNLIMITED, &timeDim); 172 | 173 | 174 | // Time variable. 175 | nc_def_var(ncid, "Time", NC_INT, 1, &timeDim, &varID); 176 | p = "time of measurement"; 177 | nc_put_att_text(ncid, varID, "long_name", strlen(p)+1, p); 178 | p = "seconds since yyyy-mm-dd hh:mm:ss +0000"; 179 | nc_put_att_text(ncid, varID, "units", strlen(p)+1, p); 180 | p = "seconds since %F %T %z"; 181 | nc_put_att_text(ncid, varID, "strptime_format", strlen(p)+1, p); 182 | 183 | // AircraftSpecs - boom_len. 184 | float boom_len = 5.18; // C-130 185 | nc_def_var(ncid, "N130AR", NC_INT, 0, 0, &varID); 186 | nc_put_att_float(ncid, varID, "boom_length", NC_FLOAT, 1, &boom_len); 187 | p = "TASHC MR THETA THETAE RHUM ATTACK SSLIP ATX DPXC EDPC PALT PSX PSXC QCX QCXC TASX TTX XMACH2 THETAV ZERO ONE PALTF IAS"; 188 | nc_put_att_text(ncid, varID, "always_derive", strlen(p)+1, p); 189 | 190 | boom_len = 4.42; // GV 191 | nc_def_var(ncid, "N677F", NC_INT, 0, 0, &varID); 192 | nc_put_att_float(ncid, varID, "boom_length", NC_FLOAT, 1, &boom_len); 193 | p = "TASHC MR THETA THETAE RHUM ATTACK SSLIP ATX DPXC EDPC PALT PSX PSXC QCX QCXC TASX TTX XMACH2 THETAV ZERO ONE PALTF IAS"; 194 | nc_put_att_text(ncid, varID, "always_derive", strlen(p)+1, p); 195 | 196 | boom_len = 4.21; // NRL-P3 197 | nc_def_var(ncid, "NRL-P3", NC_INT, 0, 0, &varID); 198 | nc_put_att_float(ncid, varID, "boom_length", NC_FLOAT, 1, &boom_len); 199 | p = "TASHC MR THETA THETAE RHUM ATTACK SSLIP ATX DPXC EDPC PALT PSX PSXC QCX QCXC TASX TTX XMACH2 THETAV ZERO ONE PALTF"; 200 | nc_put_att_text(ncid, varID, "always_derive", strlen(p)+1, p); 201 | 202 | boom_len = 4.52; // Electra 203 | nc_def_var(ncid, "N308D", NC_INT, 0, 0, &varID); 204 | nc_put_att_float(ncid, varID, "boom_length", NC_FLOAT, 1, &boom_len); 205 | p = "TASHC MR THETA THETAE RHUM ATTACK SSLIP ATX DPXC EDPC PALT PSX PSXC QCX QCXC TASX TTX XMACH2 THETAV ZERO ONE PALTF"; 206 | nc_put_att_text(ncid, varID, "always_derive", strlen(p)+1, p); 207 | 208 | 209 | for (i = 0; i < VarDB_nRecords; ++i) 210 | { 211 | struct var_v2 * vp = &((struct var_v2 *)VarDB)[i]; 212 | 213 | if (isdigit(vp->Name[0])) 214 | { 215 | printf("Variables in netCDF can not start with a digit, skipping [%s]\n", vp->Name); 216 | continue; 217 | } 218 | 219 | 220 | nc_def_var(ncid, vp->Name, NC_FLOAT, 1, &timeDim, &varID); 221 | 222 | nc_put_att_float(ncid, varID, "_FillValue", NC_FLOAT, 1, &fill_value); 223 | 224 | p = vp->Units; 225 | if (strcmp(p, "mb") == 0 || strcmp(p, "mbar") == 0) 226 | p = "hPa"; 227 | nc_put_att_text(ncid, varID, "units", strlen(p)+1, p); 228 | 229 | p = vp->Title; 230 | nc_put_att_text(ncid, varID, "long_name", strlen(p)+1, p); 231 | 232 | p = VarDB_GetCategoryName(vp->Name); 233 | if (strcmp(p, "None")) 234 | nc_put_att_text(ncid, varID, "Category", strlen(p)+1, p); 235 | p = VarDB_GetStandardNameName(vp->Name); 236 | if (strcmp(p, "None")) 237 | nc_put_att_text(ncid, varID, "standard_name", strlen(p)+1, p); 238 | 239 | if (fabs(VarDB_GetMinLimit(vp->Name)) + fabs(VarDB_GetMaxLimit(vp->Name)) > 0.0001) 240 | { 241 | float range[2]; 242 | 243 | range[0] = VarDB_GetMinLimit(vp->Name); 244 | range[1] = VarDB_GetMaxLimit(vp->Name); 245 | nc_put_att_float(ncid, varID, "valid_range", NC_FLOAT, 2, range); 246 | } 247 | 248 | 249 | checkModVars(ncid, varID, vp->Name); 250 | checkDerivedNames(ncid, varID, vp->Name); 251 | checkDependencies(ncid, varID, vp->Name); 252 | 253 | // What about Spikes & Lags? Put in aircraft specific? 254 | // What about default global_attrs; coordinates, etc. 255 | } 256 | 257 | ReleaseVarDB(); 258 | nc_close(ncid); 259 | 260 | return(0); 261 | 262 | } /* END MAIN */ 263 | 264 | /* END VDB2NCML.CC */ 265 | -------------------------------------------------------------------------------- /src/vardb/init.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: init.c 4 | 5 | FULL NAME: Initialize 6 | 7 | ENTRY POINTS: InitializeVarDB() 8 | ReleaseVarDB() 9 | VarDB_lookup() 10 | 11 | STATIC FNS: readFile() 12 | 13 | DESCRIPTION: 14 | 15 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2006 16 | ------------------------------------------------------------------------- 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "raf/vardb.h" 26 | #include 27 | #include 28 | 29 | const long VarDB_MagicCookie = 0x42756c6c; 30 | const long VarDB_CurrentVersion = 3; 31 | 32 | VarDB_Hdr master_VarDB_Hdr; 33 | void *master_VarDB = NULL; 34 | 35 | VarDB_Hdr varDB_Hdr; 36 | void *VarDB = NULL; 37 | 38 | int VarDB_NcML = -1; 39 | char VarDB_NcML_text_result[512]; 40 | 41 | long VarDB_RecLength, VarDB_nRecords; 42 | 43 | static void *readFile(const char fileName[], VarDB_Hdr *vdbHdr); 44 | static bool checkIfOlderVersionAndConvert(void *varDB, VarDB_Hdr *vdbHdr); 45 | static bool performCorrections(void *varDB); 46 | 47 | 48 | /* -------------------------------------------------------------------- */ 49 | int InitializeVarDB(const char fileName[]) 50 | { 51 | char *p, masterFileName[MAXPATHLEN]; 52 | 53 | 54 | /* Try to open new NcML version first. If it opens we are done. 55 | */ 56 | strcpy(masterFileName, fileName); 57 | strcat(masterFileName, ".nc"); 58 | if (nc_open(masterFileName, 0, &VarDB_NcML) != NC_NOERR) 59 | { 60 | fprintf(stderr, "VarDB: NcML version not found, reverting to standard VarDB.\n"); 61 | VarDB_NcML = -1; 62 | } 63 | 64 | /* Try to open the master VarDB first, then we'll overlay the user 65 | * requested file. 66 | */ 67 | p = getenv("PROJ_DIR"); 68 | if (p) 69 | { 70 | snprintf(masterFileName, MAXPATHLEN, "%s/Configuration/VarDB", p); 71 | // We are not ready for a master file. lookup returns a master, but then 72 | // the index always goes into the regular not master VarDB list. Needs work. 73 | // master_VarDB = readFile(masterFileName, &master_VarDB_Hdr); 74 | } 75 | 76 | 77 | SetCategoryFileName(masterFileName); 78 | SetStandardNameFileName(masterFileName); 79 | 80 | if (VarDB_NcML < 0) 81 | { 82 | VarDB = readFile(fileName, &varDB_Hdr); 83 | 84 | if (VarDB == 0 && master_VarDB == 0) 85 | return(ERR); 86 | } 87 | 88 | return(OK); 89 | 90 | } /* INITIALIZEVARDB */ 91 | 92 | /* -------------------------------------------------------------------- */ 93 | static void *readFile(const char fileName[], VarDB_Hdr *vdbHdr) 94 | { 95 | FILE *fp; 96 | int rc; 97 | void *varDB; 98 | 99 | VarDB_nRecords = 0; 100 | VarDB_RecLength = 0; 101 | 102 | if ((fp = fopen(fileName, "rb")) == NULL) 103 | { 104 | fprintf(stderr, "VarDB: can't open %s.\n", fileName); 105 | return(0); 106 | } 107 | 108 | fread((char *)vdbHdr, sizeof(VarDB_Hdr), 1, fp); 109 | 110 | if (ntohl(vdbHdr->MagicCookie) != VarDB_MagicCookie) 111 | { 112 | fprintf(stderr, "VarDB: bad VarDB file %s.\n", fileName); 113 | fclose(fp); 114 | return(0); 115 | } 116 | 117 | if (ntohl(vdbHdr->Version) > VarDB_CurrentVersion) 118 | { 119 | fprintf(stderr,"VarDB: File has newer version than code can handle.\n"); 120 | fclose(fp); 121 | return(0); 122 | } 123 | 124 | VarDB_nRecords = ntohl(vdbHdr->nRecords); 125 | VarDB_RecLength = ntohl(vdbHdr->RecordLen); 126 | 127 | if ((varDB = (void *)malloc((unsigned)VarDB_nRecords * VarDB_RecLength)) == NULL) 128 | { 129 | fprintf(stderr, "VarDB: out of memory.\n"); 130 | fclose(fp); 131 | return(0); 132 | } 133 | 134 | if ((rc = fread((char *)varDB, VarDB_RecLength, VarDB_nRecords, fp)) != VarDB_nRecords) 135 | { 136 | fprintf(stderr, "VarDB: read %d out of %ld entries\n", rc, VarDB_nRecords); 137 | fclose(fp); 138 | return(0); 139 | } 140 | 141 | fclose(fp); 142 | 143 | if (checkIfOlderVersionAndConvert(varDB, vdbHdr) || performCorrections(varDB)) 144 | { 145 | fprintf(stderr, "VarDB modified, saving.\n"); 146 | VarDB = varDB; 147 | SaveVarDB(fileName); 148 | } 149 | 150 | return(varDB); 151 | } 152 | 153 | static bool checkIfOlderVersionAndConvert(void *varDB, VarDB_Hdr *vdbHdr) 154 | { 155 | bool modified = false; 156 | 157 | if (ntohl(vdbHdr->Version) == 1) 158 | { 159 | fprintf(stderr, "VarDB: File is version 1, cannot convert at this time.\n"); 160 | exit(1); 161 | } 162 | 163 | if (ntohl(vdbHdr->Version) < VarDB_CurrentVersion) 164 | { 165 | fprintf(stderr, "VarDB: File has older version, converting to new version.\n"); 166 | 167 | for (int i = 0; i < VarDB_nRecords; ++i) 168 | { 169 | ((struct var_v2 *)varDB)[i].standard_name = 0; 170 | ((struct var_v2 *)varDB)[i].reference = false; 171 | } 172 | 173 | vdbHdr->Version = htonl(VarDB_CurrentVersion); 174 | vdbHdr->RecordLen = htonl(sizeof(struct var_v2)); 175 | modified = true; 176 | } 177 | 178 | return(modified); 179 | } 180 | 181 | #ifdef notdef 182 | static void addVariable(void *varDB, var_v2 *p) 183 | { 184 | void *tmp; 185 | int pos; 186 | 187 | // Don't add if already exists. 188 | for (pos = 0; pos < VarDB_nRecords; ++pos) 189 | if (strcmp(p->Name, ((struct var_v2 *)varDB)[pos].Name) == 0) 190 | return; 191 | 192 | if ((tmp = (void *)realloc(varDB, (unsigned)(VarDB_nRecords+1) * 193 | (unsigned)VarDB_RecLength)) == NULL) 194 | return; 195 | 196 | varDB = tmp; 197 | 198 | // Add in sorted position 199 | for (pos = VarDB_nRecords-1; pos >= 0; --pos) 200 | { 201 | if (strcmp(p->Name, ((struct var_v2 *)varDB)[pos].Name) < 0) 202 | memcpy( &((struct var_v2 *)varDB)[pos+1], 203 | &((struct var_v2 *)varDB)[pos], 204 | sizeof(struct var_v2)); 205 | else 206 | break; 207 | } 208 | 209 | ++pos; 210 | ++VarDB_nRecords; 211 | memcpy(&((struct var_v2 *)varDB)[pos], p, sizeof(var_v2)); 212 | } 213 | #endif 214 | 215 | static bool performCorrections(void *varDB) 216 | { 217 | bool modified = false; 218 | 219 | // Perform some sanity. 220 | for (int i = 0; i < VarDB_nRecords; ++i) 221 | { 222 | struct var_v2 *p = &((struct var_v2 *)varDB)[i]; 223 | 224 | if (strcmp(p->Units, "deg_C") == 0 || strcmp(p->Units, "Deg_C") == 0) 225 | { 226 | modified = true; 227 | strcpy(p->Units, "degC"); 228 | printf("%s - deg_C changed to degC, per SI units\n", p->Name); 229 | } 230 | 231 | if (strcmp(p->Units, "mbar") == 0) 232 | { 233 | modified = true; 234 | strcpy(p->Units, "hPa"); 235 | printf("%s - mbar changed to hPa\n", p->Name); 236 | } 237 | 238 | if (p->is_analog == false && p->defaultSampleRate != 0) 239 | { 240 | modified = true; 241 | p->defaultSampleRate = 0; 242 | p->voltageRange[0] = 0; 243 | p->voltageRange[1] = 0; 244 | printf("%s - is !analog cleanup, clear rate/range fields\n", p->Name); 245 | } 246 | } 247 | 248 | /* 249 | struct var_v2 newVar; 250 | memset(&newVar, 0, sizeof(newVar)); 251 | strcpy(newVar.Name, "RTX"); 252 | strcpy(newVar.Units, "degC"); 253 | strcpy(newVar.Title, "Recovery Temperature, Reference"); 254 | newVar.is_analog = false; 255 | newVar.Category = 6; 256 | newVar.standard_name = 0; 257 | newVar.reference = true; 258 | addVariable(varDB, &newVar); 259 | modified = true; 260 | */ 261 | return(modified); 262 | } 263 | 264 | /* -------------------------------------------------------------------- */ 265 | bool VarDB_isNcML() 266 | { 267 | if (VarDB_NcML == -1) 268 | return false; // Old style vardb, binary file. 269 | else 270 | return true; // New, netCDF/NcML version. 271 | } 272 | 273 | /* -------------------------------------------------------------------- */ 274 | void ReleaseVarDB() 275 | { 276 | if (VarDB) 277 | { 278 | free(VarDB); 279 | free(master_VarDB); 280 | VarDB = NULL; 281 | master_VarDB = NULL; 282 | } 283 | } /* END RELEASEVARDB */ 284 | 285 | /* -------------------------------------------------------------------- */ 286 | int VarDB_lookup(const char vn[]) 287 | { 288 | int i; 289 | /*int masterNrecords;*/ 290 | char tname[64]; 291 | 292 | // Strip off suffix for lookup. 293 | for (i = 0; vn[i] && vn[i] != '_'; ++i) 294 | tname[i] = vn[i]; 295 | 296 | tname[i] = '\0'; 297 | 298 | if (VarDB_NcML > 0) 299 | { 300 | int varID; 301 | if (nc_inq_varid(VarDB_NcML, vn, &varID) == NC_NOERR || 302 | nc_inq_varid(VarDB_NcML, tname, &varID) == NC_NOERR) 303 | return(varID); 304 | else 305 | return(ERR); 306 | } 307 | 308 | for (i = 0; i < VarDB_nRecords; ++i) 309 | if (strcmp(((struct var_v2 *)VarDB)[i].Name, tname) == 0) 310 | return(i); 311 | /* 312 | masterNrecords = ntohl(master_VarDB_Hdr.nRecords); 313 | 314 | for (i = 0; i < masterNrecords; ++i) 315 | if (strcmp(((struct var_v2 *)master_VarDB)[i].Name, tname) == 0) 316 | return(i); 317 | */ 318 | return(ERR); 319 | 320 | } /* END VARDB_LOOKUP */ 321 | 322 | /* END INIT.C */ 323 | -------------------------------------------------------------------------------- /src/vardb/VarDBConverter.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "raf/VarDBConverter.hh" 4 | #include 5 | #include 6 | #include // for ntohf() 7 | #include 8 | #include 9 | 10 | #include "raf/vardb.h" 11 | 12 | using std::string; 13 | using std::ostringstream; 14 | using std::cerr; 15 | using std::endl; 16 | 17 | static const char COMMENT = '#'; 18 | static const float fill_value = -32767.0; 19 | 20 | extern long VarDB_nRecords; 21 | 22 | 23 | 24 | std::string 25 | VarDBConverter:: 26 | defaultOutputPath() 27 | { 28 | return projDirPath("vardb.xml"); 29 | } 30 | 31 | 32 | void 33 | VarDBConverter:: 34 | setupProjDir(const std::string& vardbarg) 35 | { 36 | string dbdir(vardbarg); 37 | 38 | if (dbdir.find('/') != string::npos) 39 | { 40 | dbdir.erase(dbdir.rfind('/')+1, dbdir.length()); 41 | projDir = dbdir; 42 | } 43 | // Initialize the global project configuration directory also. 44 | defaultProjDirPath(""); 45 | } 46 | 47 | 48 | string 49 | VarDBConverter:: 50 | defaultProjDirPath(const std::string& filename) 51 | { 52 | if (defaultProjDir.empty()) 53 | { 54 | const char* projdir = getenv("PROJ_DIR"); 55 | if (projdir) 56 | { 57 | defaultProjDir = string(projdir) + "/Configuration/"; 58 | } 59 | } 60 | string path = defaultProjDir + filename; 61 | if (filename.length()) 62 | { 63 | cerr << "Looking for " << filename << " at path " << path << "\n"; 64 | } 65 | return path; 66 | } 67 | 68 | 69 | string 70 | VarDBConverter:: 71 | projDirPath(const std::string& filename) 72 | { 73 | return projDir + filename; 74 | } 75 | 76 | 77 | 78 | void 79 | VarDBConverter:: 80 | checkModVars(VDBFile& vdb) 81 | { 82 | char buffer[BUFSIZ+1]; 83 | char name[100]; 84 | string path = defaultProjDirPath("ModVars"); 85 | 86 | FILE *fp; 87 | if ((fp = fopen(path.c_str(), "r")) == NULL) 88 | { 89 | return; 90 | } 91 | 92 | float vals[2]; 93 | while (fgets(buffer, BUFSIZ, fp)) 94 | { 95 | if (buffer[0] == COMMENT) 96 | continue; 97 | 98 | sscanf(buffer, "%s %f %f", name, &vals[0], &vals[1]); 99 | 100 | VDBVar* var = vdb.get_var(name); 101 | if (var) 102 | { 103 | ostringstream oss; 104 | oss << vals[0] << " " << vals[1]; 105 | var->set_attribute(VDBVar::MODULUS_RANGE, oss.str()); 106 | } 107 | } 108 | fclose(fp); 109 | } 110 | 111 | 112 | void 113 | VarDBConverter:: 114 | checkDerivedNames(VDBFile& vdb) 115 | { 116 | string path = defaultProjDirPath("DerivedNames"); 117 | char buffer[BUFSIZ]; 118 | 119 | FILE *fp; 120 | if ((fp = fopen(path.c_str(), "r")) == NULL) 121 | { 122 | return; 123 | } 124 | 125 | while (fgets(buffer, BUFSIZ, fp)) 126 | { 127 | if (buffer[0] == COMMENT) 128 | continue; 129 | 130 | char* p = strtok(buffer, " \t"); 131 | 132 | VDBVar* var = vdb.get_var(p); 133 | if (var) 134 | { 135 | p = strtok(NULL, "\n"); 136 | while (isspace(*p)) 137 | { 138 | ++p; 139 | } 140 | var->set_attribute(VDBVar::DERIVE, p); 141 | } 142 | } 143 | 144 | fclose(fp); 145 | } 146 | 147 | 148 | void 149 | VarDBConverter:: 150 | checkDependencies(VDBFile& vdb) 151 | { 152 | char buffer[BUFSIZ], *p; 153 | 154 | string path = projDirPath("DependTable"); 155 | 156 | FILE *fp; 157 | if ((fp = fopen(path.c_str(), "r")) == NULL) 158 | { 159 | return; 160 | } 161 | 162 | while (fgets(buffer, BUFSIZ, fp)) 163 | { 164 | if (buffer[0] == COMMENT) 165 | continue; 166 | 167 | p = strtok(buffer, " \t\n"); 168 | 169 | if (!p) 170 | { 171 | continue; 172 | } 173 | VDBVar* var = vdb.get_var(p); 174 | if (var) 175 | { 176 | if ( (p = strtok(NULL, "\n")) ) 177 | { 178 | if (var->get_attribute(VDBVar::DEPENDENCIES).size()) 179 | { 180 | // There is more than one entry in the DependTable 181 | cerr << "Multiple entries for " << var->name() 182 | << " in DependTable found, repair. Fatal.\n"; 183 | exit(1); 184 | } 185 | while (isspace(*p)) 186 | { 187 | ++p; 188 | } 189 | var->set_attribute(VDBVar::DEPENDENCIES, p); 190 | } 191 | } 192 | } 193 | fclose(fp); 194 | } 195 | 196 | 197 | 198 | VDBFile* 199 | VarDBConverter:: 200 | open(VDBFile* vdb_in, const std::string& path) 201 | { 202 | VDBFile& vdb = *vdb_in; 203 | 204 | if (path.rfind(".xml") == path.length() - 4) 205 | { 206 | cerr << "Opening " << path << " directly as XML..." << endl; 207 | vdb.open(path); 208 | return vdb_in; 209 | } 210 | 211 | // Initialize the project directory to be the directory containing the 212 | // vardb file in path. 213 | setupProjDir(path); 214 | 215 | if (defaultProjDir.empty()) 216 | { 217 | cerr << "PROJ_DIR is not set, cannot convert to XML." << endl; 218 | return vdb_in; 219 | } 220 | 221 | vdb.create(); 222 | 223 | // First categories and standard names. 224 | VDBFile::categories_type categories; 225 | std::string cpath = projDirPath("Categories"); 226 | cerr << "Loading categories from " << cpath << "\n"; 227 | categories = VDBFile::readCategories(cpath); 228 | vdb.set_categories(categories); 229 | 230 | std::string snamespath = projDirPath("StandardNames"); 231 | VDBFile::standard_names_type standard_names; 232 | cerr << "Loading standard names from " << snamespath << "\n"; 233 | standard_names = VDBFile::readStandardNames(snamespath); 234 | vdb.set_standard_names(standard_names); 235 | 236 | // Finally variables themselves, retrieved through the original 237 | // VarDB interface. 238 | if (InitializeVarDB(path.c_str()) == ERR) 239 | { 240 | cerr << "VarDBConverter: Initialize failure." << endl; 241 | vdb.close(); 242 | return vdb_in; 243 | } 244 | 245 | int i; 246 | for (i = 0; i < VarDB_nRecords; ++i) 247 | { 248 | struct var_v2 * vp = &((struct var_v2 *)VarDB)[i]; 249 | 250 | if (isdigit(vp->Name[0])) 251 | { 252 | continue; 253 | } 254 | 255 | VDBVar* var = vdb.add_var(vp->Name); 256 | var->set_attribute(VDBVar::UNITS, vp->Units); 257 | var->set_attribute(VDBVar::LONG_NAME, vp->Title); 258 | if (ntohl(vp->is_analog) != 0) 259 | { 260 | // The ntohl() returns unsigned type, but the voltage range values 261 | // are actually signed. 262 | var->set_attribute(VDBVar::IS_ANALOG, true); 263 | ostringstream oss; 264 | oss << (int)ntohl(vp->voltageRange[0]) << " " 265 | << (int)ntohl(vp->voltageRange[1]); 266 | var->set_attribute(VDBVar::VOLTAGE_RANGE, oss.str()); 267 | var->set_attribute(VDBVar::DEFAULT_SAMPLE_RATE, 268 | ntohl(vp->defaultSampleRate)); 269 | } 270 | else 271 | { 272 | var->set_attribute(VDBVar::IS_ANALOG, false); 273 | } 274 | if(vp->MaxLimit - vp->MinLimit != 0) 275 | { 276 | var->set_attribute(VDBVar::MIN_LIMIT, ntohf(vp->MinLimit)); 277 | var->set_attribute(VDBVar::MAX_LIMIT, ntohf(vp->MaxLimit)); 278 | } 279 | 280 | string category = VarDB_GetCategoryName(vp->Name); 281 | if (category != "None") 282 | { 283 | var->set_attribute(VDBVar::CATEGORY, category); 284 | } 285 | } 286 | 287 | checkModVars(vdb); 288 | checkDerivedNames(vdb); 289 | checkDependencies(vdb); 290 | 291 | // Set the reference and standard_name attributes last just to be 292 | // consistent with the ordering used before introducing the VDBFile API. 293 | for (i = 0; i < VarDB_nRecords; ++i) 294 | { 295 | struct var_v2 * vp = &((struct var_v2 *)VarDB)[i]; 296 | 297 | if (isdigit(vp->Name[0])) 298 | { 299 | continue; 300 | } 301 | 302 | VDBVar* var = vdb.get_var(vp->Name); 303 | string standard_name = VarDB_GetStandardNameName(vp->Name); 304 | if (standard_name != "None") 305 | { 306 | var->set_attribute(VDBVar::STANDARD_NAME, standard_name); 307 | } 308 | var->set_attribute(VDBVar::REFERENCE, bool(ntohl(vp->reference) != 0)); 309 | } 310 | 311 | // What about Spikes & Lags? Put in aircraft specific? 312 | // What about default global_attrs; coordinates, etc. 313 | 314 | // Done with the binary variable database. 315 | ReleaseVarDB(); 316 | return vdb_in; 317 | } 318 | 319 | 320 | #ifdef notdef 321 | // Copied from vdb2xml when it's functionality was moved into the library. 322 | // Not sure it will ever be needed. 323 | void 324 | update_dictionary() 325 | { 326 | // We could at this point search for the Dictionary file and insert those 327 | // lines into the XML file. However, since the Dictionary is not used 328 | // anymore (not since the schema was fixed rather than generated), it's 329 | // not clear how to use it and where it should be maintained. 330 | fprintf(vdb," \n"); 331 | std::string dictionaryLocation = 332 | "/home/local/vardb/utils/vdb2xml/Dictionary"; 333 | std::ifstream dictionaryNames; 334 | dictionaryNames.open(dictionaryLocation.c_str()); 335 | 336 | std::string raw_line,named,definition; 337 | while(std::getline(dictionaryNames,raw_line)) 338 | { 339 | if (raw_line[0]!='#' and !raw_line.empty()) 340 | { 341 | named=""; 342 | definition=""; 343 | std::stringstream iss(raw_line); 344 | std::getline(iss,named,','); 345 | std::getline(iss,definition,','); 346 | //std::cout<%s\n", 348 | named.c_str(),definition.c_str()); 349 | } 350 | } 351 | fprintf(vdb," \n"); 352 | } 353 | #endif 354 | 355 | -------------------------------------------------------------------------------- /src/editor/Xwin.cc: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | OBJECT NAME: Xwin.c 4 | 5 | FULL NAME: Create X window GUI 6 | 7 | ENTRY POINTS: CreateMainWindow() 8 | 9 | STATIC FNS: none 10 | 11 | DESCRIPTION: 12 | 13 | COPYRIGHT: University Corporation for Atmospheric Research, 1993-2011 14 | ------------------------------------------------------------------------- 15 | */ 16 | 17 | #include 18 | 19 | // Fix deprecated 'register' keyword used in Motif. 20 | #define register 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "define.h" 34 | #include 35 | 36 | 37 | static const int nForms = 13; 38 | 39 | /* Global widget declarations. 40 | */ 41 | Widget EFtext[16], catMenu, stdNameMenu, catXx, stdNameXx; 42 | Widget list, analogButton, referenceButton; 43 | 44 | extern char buffer[]; 45 | 46 | 47 | /* -------------------------------------------------------------------- */ 48 | Widget CreateMainWindow(Widget parent) 49 | { 50 | int i, textCnt; 51 | Arg args[32]; 52 | Cardinal n; 53 | Widget topLevelForm; 54 | Widget buttonFrame, buttonRC; 55 | Widget menuBar, pullDown[3], cascadeButton[2]; 56 | Widget b[10], acceptButton; 57 | Widget separ; 58 | Widget editFieldRC, EFform[nForms], EFlabel[nForms]; 59 | 60 | n = 0; 61 | topLevelForm = XmCreateForm(parent, (char *)"topLevelForm", args, n); 62 | 63 | 64 | /* Create Menus 65 | */ 66 | n = 0; 67 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 68 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 69 | menuBar = XmCreateMenuBar(topLevelForm, (char *)"menuBar", args, n); 70 | XtManageChild(menuBar); 71 | 72 | n = 0; 73 | pullDown[0] = XmCreatePulldownMenu(menuBar, (char *)"filePullDown", args, n); 74 | pullDown[1] = XmCreatePulldownMenu(menuBar, (char *)"editPullDown", args, n); 75 | 76 | n = 0; 77 | XtSetArg(args[n], XmNsubMenuId, pullDown[0]); ++n; 78 | cascadeButton[0] = XmCreateCascadeButton(menuBar, (char *)"filePD_CB", args, n); 79 | 80 | n = 0; 81 | XtSetArg(args[n], XmNsubMenuId, pullDown[1]); ++n; 82 | cascadeButton[1] = XmCreateCascadeButton(menuBar, (char *)"editPD_CB", args, n); 83 | 84 | XtManageChildren(cascadeButton, 2); 85 | XtManageChildren(pullDown, 2); 86 | 87 | n = 0; 88 | b[0] = XmCreatePushButton(pullDown[0], (char *)"openNewFile", args, n); 89 | b[1] = XmCreatePushButton(pullDown[0], (char *)"saveFile", args, n); 90 | b[2] = XmCreatePushButton(pullDown[0], (char *)"saveFileAs", args, n); 91 | b[3] = XmCreatePushButton(pullDown[0], (char *)"quit", args, n); 92 | XtAddCallback(b[0], XmNactivateCallback, OpenNewFile, NULL); 93 | XtAddCallback(b[1], XmNactivateCallback, SaveFile, NULL); 94 | XtAddCallback(b[2], XmNactivateCallback, SaveFileAs, NULL); 95 | XtAddCallback(b[3], XmNactivateCallback, Quit, NULL); 96 | XtManageChildren(b, 4); 97 | 98 | n = 0; 99 | b[0] = XmCreatePushButton(pullDown[1], (char *)"clearVar", args, n); 100 | b[1] = XmCreatePushButton(pullDown[1], (char *)"deleteVar", args, n); 101 | b[2] = XmCreatePushButton(pullDown[1], (char *)"resetVar", args, n); 102 | XtAddCallback(b[0], XmNactivateCallback, Clear, NULL); 103 | XtAddCallback(b[1], XmNactivateCallback, Delete, NULL); 104 | XtAddCallback(b[2], XmNactivateCallback, (XtCallbackProc)EditVariable, NULL); 105 | XtManageChildren(b, 3); 106 | 107 | 108 | 109 | /* Separator 110 | */ 111 | n = 0; 112 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; 113 | XtSetArg(args[n], XmNtopWidget, menuBar); n++; 114 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 115 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; 116 | separ = XmCreateSeparator(topLevelForm, (char *)"separ1", args, n); 117 | XtManageChild(separ); 118 | 119 | 120 | /* Create Form & Label widgets. 121 | */ 122 | n = 0; 123 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; 124 | XtSetArg(args[n], XmNtopWidget, separ); n++; 125 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 126 | editFieldRC = XmCreateRowColumn(topLevelForm, (char *)"editFieldRC", args, n); 127 | XtManageChild(editFieldRC); 128 | 129 | /* Create 11 Form and 10 Label widgets 130 | */ 131 | for (i = 0; i < nForms; ++i) 132 | { 133 | n = 0; 134 | snprintf(buffer, 1024, "EFform%d", i); 135 | EFform[i] = XmCreateForm(editFieldRC, buffer, args, n); 136 | 137 | if (i < 10) 138 | { 139 | snprintf(buffer, 1024, "EFlabel%d", i); 140 | 141 | n = 0; 142 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 143 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 144 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 145 | EFlabel[i] = XmCreateLabel(EFform[i], buffer, args, n); 146 | XtManageChild(EFlabel[i]); 147 | } 148 | } 149 | 150 | XtManageChildren(EFform, nForms); 151 | 152 | n = 0; 153 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 154 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 155 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; 156 | buttonFrame = XmCreateFrame(EFform[12], (char *)"buttonFrame", args, n); 157 | XtManageChild(buttonFrame); 158 | 159 | 160 | /* Add first 4 TextField widgets 161 | */ 162 | for (i = 0; i < 4; ++i) 163 | { 164 | n = 0; 165 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 166 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 167 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; 168 | XtSetArg(args[n], XmNleftWidget, EFlabel[i]); n++; 169 | snprintf(buffer, 1024, "EFtext%d", i); 170 | EFtext[i] = XmCreateTextField(EFform[i], buffer, args, n); 171 | XtAddCallback(EFtext[i], XmNactivateCallback, 172 | (XtCallbackProc)XmProcessTraversal, 173 | (XtPointer)XmTRAVERSE_NEXT_TAB_GROUP); 174 | XtManageChild(EFtext[i]); 175 | } 176 | 177 | 178 | n = 0; 179 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 180 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 181 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; 182 | XtSetArg(args[n], XmNleftWidget, EFlabel[4]); n++; 183 | analogButton = XmCreateToggleButton(EFform[4], (char *)"analogButton", args, n); 184 | XtManageChild(analogButton); 185 | 186 | 187 | for (i = 5, textCnt = 4; i < 10; ++i) 188 | { 189 | n = 0; 190 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 191 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 192 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; 193 | XtSetArg(args[n], XmNleftWidget, EFlabel[i]); n++; 194 | 195 | 196 | snprintf(buffer, 1024, "EFtext%d", textCnt); 197 | EFtext[textCnt] = XmCreateTextField(EFform[i], buffer, args, n); 198 | XtAddCallback(EFtext[textCnt], XmNactivateCallback, 199 | (XtCallbackProc)XmProcessTraversal, 200 | (XtPointer)XmTRAVERSE_NEXT_TAB_GROUP); 201 | XtManageChild(EFtext[textCnt]); 202 | ++textCnt; 203 | 204 | if (i == 5 || i == 9) /* Add second text widget */ 205 | { 206 | n = 0; 207 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 208 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);n++; 209 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; 210 | XtSetArg(args[n], XmNleftWidget, EFtext[textCnt-1]); n++; 211 | 212 | snprintf(buffer, 1024, "EFtext%d", textCnt); 213 | EFtext[textCnt] = XmCreateTextField(EFform[i], buffer, args, n); 214 | XtAddCallback(EFtext[textCnt], XmNactivateCallback, 215 | (XtCallbackProc)XmProcessTraversal, 216 | (XtPointer)XmTRAVERSE_NEXT_TAB_GROUP); 217 | XtManageChild(EFtext[textCnt]); 218 | ++textCnt; 219 | } 220 | } 221 | 222 | 223 | /* Create category option menu 224 | */ 225 | n = 0; 226 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 227 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 228 | XtSetArg(args[n], XmNrightWidget, XmATTACH_WIDGET); n++; 229 | XtSetArg(args[n], XmNrightWidget, buttonFrame); n++; 230 | catMenu = XmCreatePulldownMenu(EFform[10], (char *)"optionMenu", args, n); 231 | 232 | n = 0; 233 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 234 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 235 | XtSetArg(args[n], XmNrightWidget, XmATTACH_WIDGET); n++; 236 | XtSetArg(args[n], XmNrightWidget, buttonFrame); n++; 237 | XtSetArg(args[n], XmNsubMenuId, catMenu); ++n; 238 | catXx = XmCreateOptionMenu(EFform[10], (char *)"catMenu", args, n); 239 | 240 | XtManageChild(catXx); 241 | 242 | /* Create standard_name option menu 243 | */ 244 | n = 0; 245 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; 246 | XtSetArg(args[n], XmNtopWidget, catMenu); n++; 247 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 248 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 249 | stdNameMenu = XmCreatePulldownMenu(EFform[11], (char *)"optionMenu", args, n); 250 | 251 | n = 0; 252 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; 253 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 254 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; 255 | XtSetArg(args[n], XmNrightWidget, XmATTACH_WIDGET); n++; 256 | XtSetArg(args[n], XmNrightWidget, buttonFrame); n++; 257 | XtSetArg(args[n], XmNsubMenuId, stdNameMenu); ++n; 258 | stdNameXx = XmCreateOptionMenu(EFform[11], (char *)"stdNameMenu", args, n); 259 | 260 | XtManageChild(stdNameXx); 261 | 262 | n = 0; 263 | referenceButton = XmCreateToggleButton(EFform[12], (char *)"referenceButton", args, n); 264 | XtManageChild(referenceButton); 265 | 266 | /* Scrolled List of variable names 267 | */ 268 | n = 0; 269 | XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; 270 | XtSetArg(args[n], XmNtopWidget, separ); n++; 271 | XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; 272 | XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; 273 | XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++; 274 | XtSetArg(args[n], XmNleftWidget, editFieldRC); n++; 275 | list = XmCreateScrolledList(topLevelForm, (char *)"varList", args, n); 276 | XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)EditVariable, NULL); 277 | XtManageChild(list); 278 | 279 | /* Create accept button 280 | */ 281 | n = 0; 282 | buttonRC = XmCreateRowColumn(buttonFrame, (char *)"buttonRC", args, n); 283 | XtManageChild(buttonRC); 284 | 285 | n = 0; 286 | acceptButton = XmCreatePushButton(buttonRC, (char *)"acceptButton", args, n); 287 | XtAddCallback(acceptButton, XmNactivateCallback, Accept, (XtPointer)0); 288 | XtManageChild(acceptButton); 289 | 290 | return(topLevelForm); 291 | 292 | } /* END CREATEMAINWINDOW */ 293 | 294 | /* END XWIN.C */ 295 | -------------------------------------------------------------------------------- /editpy/radioClickEvent.py: -------------------------------------------------------------------------------- 1 | #Julian Quick 2 | #Logical flow of functions is from bottom to top 3 | import getInfo 4 | from delete import delete 5 | from PyQt5 import QtWidgets, QtCore 6 | from functools import partial 7 | from setup import fileName 8 | 9 | #Labes is used to store info for exec commands in textChange function 10 | #headers contains a list of attribute names 11 | headers=[] 12 | rightInfoHub={'headers':{},'textBoxes':{}} 13 | #------------------------------------------------------------------------------ 14 | #removes leading descriptior from static lable, appends to signal list 15 | def signalSet(self,name): 16 | global rightInfoHub 17 | try: 18 | s=rightInfoHub['textBoxes'][name].text() 19 | except AttributeError: 20 | s=rightInfoHub['textBoxes'][name].currentText() 21 | return str(s) 22 | #return info 23 | #----------------------------------------------------------------------------- 24 | #When any right info hub text box is edited, this function is called 25 | #Sets textbox label as text, used to access text later. 26 | def textChange(self): 27 | self.saveChanges=True 28 | if str(rightInfoHub['textBoxes']['is_analog'].currentText())=='false': 29 | rightInfoHub['textBoxes']['voltage_range'].setDisabled(True) 30 | rightInfoHub['textBoxes']['voltage_range'].setCurrentIndex(0) 31 | rightInfoHub['textBoxes']['default_sample_rate'].setDisabled(True) 32 | rightInfoHub['textBoxes']['default_sample_rate'].setCurrentIndex(0) 33 | else: 34 | rightInfoHub['textBoxes']['voltage_range'].setDisabled(False) 35 | rightInfoHub['textBoxes']['default_sample_rate'].setDisabled(False) 36 | #----------------------------------------------------------------------------- 37 | #Creates upright hand side lables and text boxes 38 | def labler(lablename,signalname,self,num): 39 | #incoming signal names are local, must be global for use in exec 40 | global selfglobal 41 | global rightInfoHub 42 | selfglobal=self 43 | 44 | #boolean logic 45 | if lablename in self.booleanList: 46 | if signalname=='true': 47 | rightInfoHub['textBoxes'][lablename].setCurrentIndex(0) 48 | elif signalname=='false': 49 | rightInfoHub['textBoxes'][lablename].setCurrentIndex(1) 50 | if lablename in (x[0] for x in self.catelogList) and signalname!='': 51 | if lablename==self.catelogList[0][0]: 52 | stdList=getInfo.getStandardNames(fileName()) 53 | stdList.insert(0,'') 54 | else: 55 | stdList=getInfo.getCategories(fileName()) 56 | rightInfoHub['textBoxes'][lablename].setCurrentIndex(stdList.index(signalname)) 57 | if lablename=='voltage_range' or lablename=='default_sample_rate': 58 | rightInfoHub['textBoxes'][lablename].setCurrentIndex(rightInfoHub['textBoxes'][lablename].findText(signalname)) 59 | 60 | rightInfoHub['headers'][lablename].setText(lablename) 61 | rightInfoHub['headers'][lablename].setMinimumSize(rightInfoHub['headers'][lablename].sizeHint()) 62 | if lablename not in self.booleanList and lablename not in (x[0] for x in self.catelogList) and lablename not in ['voltage_range','default_sample_rate']: 63 | rightInfoHub['textBoxes'][lablename].setText(str(signalname)) 64 | 65 | #Connvects changes in text box to bools logic 66 | rightInfoHub['textBoxes'][lablename].textEdited.connect(lambda: textChange(self)) 67 | textChange(self) 68 | #global variable bools set False to indicate no changes have been made yet 69 | self.saveChanges=False 70 | 71 | #------------------------------------------------ 72 | def clearRightInfoHub(): 73 | global rightInfoHub 74 | dictionary=getInfo.getDictionary(fileName()) 75 | i=0 76 | while i