Index: ccr/trunk/p/C0CRNF.m
===================================================================
--- ccr/trunk/p/C0CRNF.m	(revision 304)
+++ ccr/trunk/p/C0CRNF.m	(revision 307)
@@ -43,5 +43,5 @@
  Q
  ;
-GETN(GRTN,GFILE,GIEN,GNN) ; GET FIELDS FOR ACCESS BY NAME
+GETNOLD(GRTN,GFILE,GIEN,GNN) ; GET FIELDS FOR ACCESS BY NAME
  ; GRTN IS PASSED BY NAME
  ;
@@ -69,5 +69,5 @@
  Q
  ;
-GETN2(GRTN,GFILE,GREF,GNDX,GNN) ; NEW GET ;GPL ; RETURN A FIELD VALUE MAP
+GETN1(GRTN,GFILE,GREF,GNDX,GNN) ; NEW GET ;GPL ; RETURN A FIELD VALUE MAP
  ; GETN IS AN EXTRINSIC WHICH RETURNS THE NEXT IEN AFTER THE CURRENT GIEN
  ; GRTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
@@ -121,9 +121,10 @@
  Q
  ;
-GETALL(GARTN,GAFILE,GACNT,GASTRT,GANN) ; RETURN FIELD MAP AND VALUES
+GETN2(GARTN,GAFILE,GAIDX,GACNT,GASTRT,GANN) ; RETURN FIELD MAP AND VALUES
  ; GARTN, PASSED BY NAME, RETURNS A FIELD MAP AND A VALUE MAP
- ; .. FIELD MAP @GARTN@("F","FIELDNAME^FILE^FIELD#")=""
+ ; .. FIELD MAP @GARTN@("F","FIELDNAME")="FILE;FIELD#"
  ; ... ANY FIELD USED BY ANY RECORD PROCESSED IS IN THE FIELD MAP
- ; .. VALUE MAP @GARTN@("V","IEN","FIELDNAME")=VALUE
+ ; .. VALUE MAP @GARTN@("V","IEN","FIELDNAME","N")=VALUE
+ ; .. WHERE N IS THE INDEX FOR MULTIPLES.. 1 FOR SINGLE VALUES
  ; .. GARTN IS NOT INITIALIZED, SO MULTIPLE CALLS ARE CUMULATIVE
  ; .. IF GANN="ALL" THEN ALL FIELDS FOR THE FILE ARE IN THE FIELD MAP
@@ -131,4 +132,6 @@
  ; .. NUL FIELDS CAN BE DETERMINED BY CHECKING FIELD MAP - THIS SAVES SPACE
  ; GAFILE IS THE FILE NUMBER TO BE PROCESSED. IT IS PASSED BY VALUE
+ ; GAIDX IS THE OPTIONAL INDEX TO USE IN THE FILE. IF GAIDX IS "" THE IEN
+ ; .. OF THE FILE WILL BE USED
  ; GACNT IS THE NUMBER OF RECORDS TO PROCESS. IT IS PASSED BY VALUE
  ; .. IF GARCNT IS NULL, ALL RECORDS ARE PROCESSED
@@ -137,10 +140,93 @@
  ; GANN= NOT NULL - IF GANN IS "ALL" THEN EVEN NULL FIELDS WILL BE RETURNED
  ; OTHERWISE, ONLY POPULATED FIELDS ARE RETURNED IN GARFLD AND GARVAL
- N GATMP,GAI,GAF
+ ;N GATMP,GAI,GAF
  S GAF=$$FILEREF(GAFILE) ; GET CLOSED ROOT FOR THE FILE NUMBER GAFILE
+ I '$D(GAIDX) S GAIDX="" ;DEFAULT
+ I '$D(GANN) S GANN="" ;DEFAULT ONLY POPULATED FIELDS RETURNED
+ I GAIDX'="" S GAF=$NA(@GAF@(GAIDX)) ; IF WE ARE USING AN INDEX
  W GAF,!
  W $O(@GAF@(0)) ;
  S GAI=0 ;ITERATOR
- ; F  S GAI=$O(@GAF@
+ F  S GAI=$O(@GAF@(GAI)) Q:GAI=""  D  ;
+ . D GETN1("GATMP",GAFILE,GAI,GAIDX,GANN) ;GET ONE RECORD
+ . N GAX S GAX=0
+ . F  S GAX=$O(GATMP(GAX)) Q:GAX=""  D  ;PULL OUT THE FIELDS
+ . . D ADDNV(GARTN,GAI,GAX,GATMP(GAX)) ;INSERT THE NAME/VALUE INTO GARTN
+ Q
+ ;
+ADDNV(GNV,GNVN,GNVF,GNVV) ; CREATE AN ELEMENT OF THE MATRIX
+ ;
+ S @GNV@("F",GNVF)=$P(GNVV,"^",1)_"^"_$P(GNVV,"^",2) ;NAME=FILE^FIELD#
+ S @GNV@("V",GNVN,GNVF,1)=$P(GNVV,"^",3) ;SET THE VALUE
+ Q
+ ;
+RNF2CSV(RNRTN,RNIN,RNSTY) ;CONVERTS AN RFN2 GLOBAL TO A CSV FORMAT
+ ; READY TO WRITE FOR USE WITH EXCEL @RNRTN@(0) IS NUMBER OF LINES
+ ; RNSTY IS STYLE OF THE OUTPUT -
+ ; .. "NV"= ROWS ARE NAMES, COLUMNS ARE VALUES
+ ; .. "VN"= ROWS ARE VALUES, COLUMNS ARE NAMES
+ ; .. DEFAULT IS "NV" BECAUSE MANY MATRICES HAVE MORE FIELDS THAN VALUES
+ N RNR,RNC ;ROW ROOT,COL ROOT
+ N RNI,RNJ,RNX
+ I '$D(RNSTY) S RNSTY="NV" ;DEFAULT
+ I RNSTY="NV" D NV(RNRTN,RNIN)  ; INTERNAL SUBROUTINES DEPENDING ON ORIENTATION
+ E  D VN(RNRTN,RNIN) ;
+ Q
+ ;
+NV(RNRTN,RNIN) ;
+ S RNR=$NA(@RNIN@("F"))
+ S RNC=$NA(@RNIN@("V"))
+ ;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
+ S RNX="""FILE"""_"," ; FIRST COLUMN NAME IS "FIELD"
+ S RNI=""
+ F  S RNI=$O(@RNC@(RNI)) Q:RNI=""  D  ; FOR EACH COLUMN
+ . S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
+ S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
+ D PUSH^GPLXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
+ S RNI=""
+ F  S RNI=$O(@RNR@(RNI)) Q:RNI=""  D  ; FOR EACH ROW
+ . S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
+ . S RNJ=""
+ . F  S RNJ=$O(@RNC@(RNJ)) Q:RNJ=""  D  ; FOR EACH COL
+ . . I $D(@RNC@(RNJ,RNI,1)) D  ; THIS ROW HAS THIS COLUMN
+ . . . S RNX=RNX_""""_@RNC@(RNJ,RNI,1)_""""_"," ; ADD THE ELEMENT PLUS A COMMA
+ . . E  S RNX=RNX_"," ; NUL COLUMN
+ . S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
+ . D PUSH^GPLXPATH(RNRTN,RNX)
+ Q
+ ;
+VN(RNRTN,RNIN) ;
+ S RNR=$NA(@RNIN@("V"))
+ S RNC=$NA(@RNIN@("F"))
+ ;S RNY=$P(@RNIN@(0),"^",1) ; FILE NUMBER
+ S RNX="""FILE"""_"," ; FIRST COLUMN NAME IS "FIELD"
+ S RNI=""
+ F  S RNI=$O(@RNC@(RNI)) Q:RNI=""  D  ; FOR EACH COLUMN
+ . S RNX=RNX_RNI_"," ;ADD THE COLUMM ELEMENT AND A COMMA
+ S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
+ D PUSH^GPLXPATH(RNRTN,RNX) ; FIRST LINE CONTAINS COLUMN HEADINGS
+ S RNI=""
+ F  S RNI=$O(@RNR@(RNI)) Q:RNI=""  D  ; FOR EACH ROW
+ . S RNX=""""_RNI_""""_"," ; FIRST ELEMENT ON ROW IS THE FIELD
+ . S RNJ=""
+ . F  S RNJ=$O(@RNC@(RNJ)) Q:RNJ=""  D  ; FOR EACH COL
+ . . I $D(@RNR@(RNI,RNJ,1)) D  ; THIS ROW HAS THIS COLUMN
+ . . . S RNX=RNX_""""_@RNR@(RNI,RNJ,1)_""""_"," ; ADD THE ELEMENT PLUS A COMMA
+ . . E  S RNX=RNX_"," ; NUL COLUMN
+ . S RNX=$E(RNX,1,$L(RNX)-1) ; STRIP OFF THE LAST COMMA
+ . D PUSH^GPLXPATH(RNRTN,RNX)
+ Q
+ ;
+FILE2CSV(FNUM,FVN) ; WRITES OUT A FILEMAN FILE TO CSV
+ ;
+ ;N G1,G2
+ I '$D(FVN) S FVN="NV" ; DEFAULT ORIENTATION OF CVS FILE
+ S G1=$NA(^TMP($J,"C0CCSV",1))
+ S G2=$NA(^TMP($J,"C0CCSV",2))
+ D GETN2(G1,FNUM) ; GET THE MATRIX
+ D RNF2CSV(G2,G1,FVN) ; PREPARE THE CVS FILE
+ K @G1
+ W $$OUTPUT^GPLXPATH(@G2@(1),"FILE_"_FNUM_".csv",^TMP("GPLCCR","ODIR"))
+ K @G2
  Q
  ;
@@ -150,4 +236,5 @@
  S C0CF=^DIC(FNUM,0,"GL") ;OPEN ROOT TO FILE
  S C0CF=$P(C0CF,",",1)_")" ; CLOSE THE ROOT
+ I C0CF["()" S C0CF=$P(C0CF,"()",1)
  Q C0CF
  ;
