# Database for NDFile driver, which saves files for NDArray data.
# Mark Rivers
# April 7, 2008

###################################################################
#  These records control file I/O                                 # 
###################################################################

# File path.
record(waveform, "$(P)$(R)FilePath")
{
    field(PINI, "YES")
    field(DTYP, "asynOctetWrite")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_PATH")
    field(FTVL, "UCHAR")
    field(NELM, "256")
}

record(waveform, "$(P)$(R)FilePath_RBV")
{
    field(DTYP, "asynOctetRead")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_PATH")
    field(FTVL, "UCHAR")
    field(NELM, "256")
    field(SCAN, "I/O Intr")
}

# Filename
record(waveform, "$(P)$(R)FileName")
{
    field(PINI, "YES")
    field(DTYP, "asynOctetWrite")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_NAME")
    field(FTVL, "UCHAR")
    field(NELM, "256")
}

record(waveform, "$(P)$(R)FileName_RBV")
{
    field(DTYP, "asynOctetRead")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_NAME")
    field(FTVL, "UCHAR")
    field(NELM, "256")
    field(SCAN, "I/O Intr")
}

record(longout, "$(P)$(R)FileNumber")
{
    field(PINI, "YES")
    field(OUT, "$(P)$(R)FileNumber_write PP")
    field(VAL, "1")
}

record(longout, "$(P)$(R)FileNumber_write")
{
    field(SDIS, "$(P)$(R)FileNumber_Sync.PACT")
    field(DISV, "1")
    field(DTYP, "asynInt32")
    field(OUT, "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_NUMBER")
}

record(longin, "$(P)$(R)FileNumber_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_NUMBER")
    field(SCAN, "I/O Intr")
    field(FLNK, "$(P)$(R)FileNumber_Sync")
}

record(longout, "$(P)$(R)FileNumber_Sync")
{
    field(DOL,  "$(P)$(R)FileNumber_RBV NPP")
    field(OMSL, "closed_loop")
    field(OUT,  "$(P)$(R)FileNumber PP")
}

# Autoincrement flag
record(bo, "$(P)$(R)AutoIncrement")
{
    field(PINI, "YES")
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))AUTO_INCREMENT")
    field(VAL,  "1")
    field(ZNAM, "No")
    field(ONAM, "Yes")
}

record(bi, "$(P)$(R)AutoIncrement_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))AUTO_INCREMENT")
    field(ZNAM, "No")
    field(ONAM, "Yes")
    field(SCAN, "I/O Intr")
}

# File template
record(waveform, "$(P)$(R)FileTemplate")
{
    field(PINI, "YES")
    field(DTYP, "asynOctetWrite")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_TEMPLATE")
    field(FTVL, "UCHAR")
    field(NELM, "256")
}

record(waveform, "$(P)$(R)FileTemplate_RBV")
{
    field(DTYP, "asynOctetRead")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_TEMPLATE")
    field(FTVL, "UCHAR")
    field(NELM, "256")
    field(SCAN, "I/O Intr")
}

# Full filename, including path
record(waveform, "$(P)$(R)FullFileName_RBV")
{
    field(DTYP, "asynOctetRead")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FULL_FILE_NAME")
    field(FTVL, "UCHAR")
    field(NELM, "256")
    field(SCAN, "I/O Intr")
}

# Autosave flag
record(bo, "$(P)$(R)AutoSave")
{
    field(PINI, "YES")
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))AUTO_SAVE")
    field(VAL,  "1")
    field(ZNAM, "No")
    field(ONAM, "Yes")
}

record(bi, "$(P)$(R)AutoSave_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))AUTO_SAVE")
    field(ZNAM, "No")
    field(ONAM, "Yes")
    field(SCAN, "I/O Intr")
}

# Write file
record(busy, "$(P)$(R)WriteFile")
{
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))WRITE_FILE")
    field(ZNAM, "Done")
    field(ONAM, "Write")
}

record(bi, "$(P)$(R)WriteFile_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))WRITE_FILE")
    field(ZNAM, "Done")
    field(ZSV,  "NO_ALARM")
    field(ONAM, "Writing")
    field(OSV,  "MINOR")
    field(SCAN, "I/O Intr")
}


# Read file
record(busy, "$(P)$(R)ReadFile")
{
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))READ_FILE")
    field(ZNAM, "Done")
    field(ONAM, "Read")
}

record(bi, "$(P)$(R)ReadFile_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))READ_FILE")
    field(ZNAM, "Done")
    field(ZSV,  "NO_ALARM")
    field(ONAM, "Reading")
    field(OSV,  "MINOR")
    field(SCAN, "I/O Intr")
}

# File data format 
record(mbbo, "$(P)$(R)FileFormat")
{
    field(PINI, "YES")
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_FORMAT")
    field(VAL,  "0")
    field(ZRST, "Undefined")
    field(ZRVL, "0")
    field(ONST, "Invalid")
    field(ONVL, "1")
}

record(mbbi, "$(P)$(R)FileFormat_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))FILE_FORMAT")
    field(ZRST, "netCDF")
    field(ZRVL, "0")
    field(ONST, "Undefined")
    field(ONVL, "1")
    field(SCAN, "I/O Intr")
}

# File save mode 
record(mbbo, "$(P)$(R)FileWriteMode")
{
    field(PINI, "YES")
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))WRITE_MODE")
    field(VAL,  "0")
    field(ZRST, "Single")
    field(ZRVL, "0")
    field(ONST, "Capture")
    field(ONVL, "1")
    field(TWST, "Stream")
    field(TWVL, "2")
}

record(mbbi, "$(P)$(R)FileWriteMode_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))WRITE_MODE")
    field(ZRST, "Single")
    field(ZRVL, "0")
    field(ONST, "Capture")
    field(ONVL, "1")
    field(TWST, "Stream")
    field(TWVL, "2")
    field(SCAN, "I/O Intr")
}

# Capture data
record(busy, "$(P)$(R)Capture")
{
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))CAPTURE")
    field(ZNAM, "Done")
    field(ONAM, "Capture")
}

record(bi, "$(P)$(R)Capture_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))CAPTURE")
    field(ZNAM, "Done")
    field(ZSV,  "NO_ALARM")
    field(ONAM, "Capturing")
    field(OSV,  "MINOR")
    field(SCAN, "I/O Intr")
}

record(longout, "$(P)$(R)NumCapture")
{
    field(PINI, "YES")
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))NUM_CAPTURE")
    field(VAL,  "1")
}

record(longin, "$(P)$(R)NumCapture_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))NUM_CAPTURE")
    field(SCAN, "I/O Intr")
}

record(longin, "$(P)$(R)NumCaptured_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))NUM_CAPTURED")
    field(SCAN, "I/O Intr")
}


