! GTFigSave - 図を変数として保存

subroutine GTFigSave(fig, name, name_result)
    use gtgraph_generic, only: Save, GTGraphSaveName
    use gtgraph_types, only: GT_FIGURE
    use gtdata_types, only: GT_VARIABLE
    use gtdata_generic, only: Create, Close, put_attr, add_member
    use dc_string, only: VSTRING, vchar, len
    implicit none
    type(GT_FIGURE), intent(inout):: fig
    type(VSTRING), intent(in), optional:: name
    type(VSTRING), intent(out), optional:: name_result
    type(VSTRING):: vname, figtitle, childname
    type(GT_VARIABLE):: var
    integer:: i
continue
    if (present(name)) then
        vname = name
    else
        vname = GTGraphSaveName()
    endif
    figtitle = fig%title
    call Create(var, vchar(vname, len(vname)), xtype="int", overwrite=.TRUE., &
        long_name=vchar(figtitle, len(figtitle)))
    call Put_Attr(var, "gt_structure_class", "figure")

    ! 図のメンバになっているものたちの書き出し
    if (associated(fig%contours)) then
        do, i = 1, size(fig%contours)
            call Save(fig%contours(i), resultname=childname)
            call add_member(var, childname)
        enddo
    endif

    call Close(var)
    print *, "figure ", vchar(figtitle, len(figtitle)), &
        & " stored at ", vchar(vname, len(figtitle))
    if (present(name_result)) name_result = vname
end subroutine

