Wikiname 1 1 Result database connection HP_Omistaja 9. maata 2008 10:42 jtue 5. syyta 2008 17:35 48,24 1,0,0,1,1,1,0,0,0,0 1,719,104,510,620,17 Arial, 15 0,Linkmodule Result_database_conn,2,2,0,1,C:\temp\Result database connection.ANA 100,1,1,1,1,9,2970,2100,1,0 Inp dim 0 156,400,1 140,16 1,0,0,1,0,0,0,78,0,1 52425,39321,65535 New_dimension_info Inp run 0 156,432,1 140,16 1,0,0,1,0,0,0,78,0,1 52425,39321,65535 Run_info Inp var 0 156,336,1 140,16 1,0,0,1,0,0,0,78,0,1 52425,39321,65535 New_variable_info Var for rdb 0 156,256,1 140,16 1,0,0,1,0,0,0,78,0,1 52425,39321,65535 Variables_to_be_save Details jtue 18. heita 2008 10:14 48,24 408,456,1 48,24 1,444,14,754,502,17 Concatenation UDFs This library contains functions to make various instances of concatenation more convenient. Concat3 thru Concat10 are generalizations of the built-in Concat function which concatenate from 3 to 10 arrays in a single call (while the built-in Concat concatenates two arrays). ConcatRows concatenates all the rows of a single array. David Kendall & Lonnie Chrisman Mon, Jan 26, 2004 8:49 AM Lonnie Wed, Sep 05, 2007 3:23 PM 48,24 72,248,1 68,24 1,0,0,1,1,1,0,0,0,0 1,39,36,798,452,23 (A1, A2, A3: ArrayType; I1, I2, I3, J: IndexType ) Concat3 Concatenates three arrays, A1, A2, and A3. I1, I2, and I3 are the indexes that are joined; J is the index of the new array; J usually is the concatenation of I1, I2, and I3 Index I12 := Concat(I1,I2); Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, J ) 88,64,1 48,26 2,56,56,986,596 A1,A2,A3,I1,I2,I3,J (A1, A2, A3, A4: ArrayType; I1, I2, I3, I4, J: IndexType ) Concat4 Concatenates four arrays, A1, A2, A3, and A4. I1, I2, I3, and I4 are the indexes that are joined; J is the index of the new array; J usually is the concatenation of I1, I2, I3, and I4. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, J); 192,64,1 48,24 2,30,30,986,596 A1,A2,A3,A4,I1,I2,I3,I4,J 0 (A1, A2, A3, A4, A5, A6, A7, A8, A9: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, I9, J: IndexType) Concat9 Concatenates nine arrays, A1, ..., A9. I1, ..., I9 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I9. Index I12 := Concat(I1,I2); Index I123 := Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Index I12345678 := Concat(I1234567, I8); Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, I12345678), A9, I12345678, I9, J); 88,232,1 48,24 2,27,120,469,638 A1,A2,A3,A4,A5,A6,A7,A8,A9,I1,I2,I3,I4,I5,I6,I7,I8,I9,J 0 (A1, A2, A3, A4, A5: ArrayType; I1, I2, I3, I4, I5, J: IndexType ) Concat5 Concatenates five arrays, A1, ..., A5. I1, ..., I5 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I5. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, J); 88,120,1 48,24 2,160,160,986,596 A1,A2,A3,A4,A5,I1,I2,I3,I4,I5,J (A1, A2, A3, A4, A5, A6: ArrayType; I1, I2, I3, I4, I5, I6, J: IndexType ) Concat6 Concatenates six arrays, A1, ..., A6. I1, ..., I6 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I6. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, J); 192,120,1 48,24 2,644,94,602,712 A1,A2,A3,A4,A5,A6,I1,I2,I3,I4,I5,I6,J 0 (A1, A2, A3, A4, A5, A6, A7: ArrayType; I1, I2, I3, I4, I5, I6, I7, J: IndexType ) Concat7 Concatenates seven arrays, A1, ..., A7. I1, ..., I7 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I7. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, J); 88,176,1 48,24 2,580,98,551,565 A1,A2,A3,A4,A5,A6,A7,I1,I2,I3,I4,I5,I6,I7,J (A1, A2, A3, A4, A5, A6, A7, A8: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, J: IndexType ) Concat8 Concatenates eight arrays, A1, ..., A8. I1, ..., I8 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I8. Index I12 := Concat(I1,I2); Index I123:= Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, J); 192,176,1 48,24 2,12,98,561,737 A1,A2,A3,A4,A5,A6,A7,A8,I1,I2,I3,I4,I5,I6,I7,I8,J 0 (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10: ArrayType; I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, J: IndexType) Concat10 Concatenates ten arrays, A1, ..., A10. I1, ..., I10 are the indexes joined; J is the index of the new array; J usually is the concatenation of I1, ..., I10. Index I12 := Concat(I1,I2); Index I123 := Concat(I12, I3); Index I1234 := Concat(I123, I4); Index I12345 := Concat(I1234, I5); Index I123456 := Concat(I12345, I6); Index I1234567 := Concat(I123456, I7); Index I12345678 := Concat(I1234567, I8); Index I123456789 := Concat(I12345678, I9); Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, I123), A4, I123, I4, I1234), A5, I1234, I5, I12345), A6, I12345, I6, I123456), A7, I123456, I7, I1234567), A8, I1234567, I8, I12345678), A9, I12345678, I9, I123456789), A10, I123456789, I10, J); 192,232,1 48,24 2,542,93,632,744 A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,J 0 (A : ArrayType ; RowIndex,ColIndex,ResultIndex : IndexType) ConcatRows (A,I,J,K) Takes an array, A indexed by RowIndex & ColIndex, and concatenates each row, henceforth flattening the array by one dimension. The result is indexed by ResultIndex, which must be an index with size(RowIndex) * size(ColIndex) elements. index L := [ identifier of RowIndex, identifier of ColIndex, "val"]; slice(Mdarraytotable(A,ResultIndex,L),L,3) 320,64,1 64,24 2,30,320,478,348 A,RowIndex,ColIndex,ResultIndex Variables to be saved Table(Self,Vari)( 'H1907',1, 'H1908',1, 'H1910',1, 'H1911',1, 'H1912',1 ) ['item 1','item 2','Item 3','item 3','item 4'] 224,137,1 48,22 1,1,1,1,1,1,0,0,0,0 2,102,90,476,481 2,747,497,416,303,0,MIDM 2,818,667,420,256,0,MIDM [Formnode Var_for_rdb1] 52425,39321,65535 [Vari,Self] [Vari,Self] [1,1,1,0] [Sys_localindex('I'),1,Sys_localindex('F'),1,Sys_localindex('G'),1] Inp result 1) The process is done for each variable one at a time (this is indexed by x). 2) The variable is given index runn which is equal to run if probabilistic and 0 if not. 3) The array is flattened first to 2-D, the value only is kept, added with sample and result_id. 4) Variables are concatenated to each other. 5) Row is made the index of the implicit index. var output:= 0; var e:= card_res; var x:= 1; while x<= size(Variables_to_be_save)/size(vari) do ( var c:= slice(Variables_to_be_save,Variables_to_be_save,x); index runn:= if c[Vari='Probabilistic?']=1 then copyindex(run) else [0]; var b:= getfract(mid(evaluate(c[vari='Var_name'])),0.5); var a:= if c[Vari='Probabilistic?']=1 then ( var d:= sample(evaluate(c[vari='Var_name'])); d[run=runn]) else ( var d:= b; if runn=0 then d else d); index endscen:= 1+e..size(b)+e; index row2:= 1..size(endscen)*size(runn); index l:= concat(indexnames(b),['Value']); a:= mdarraytotable(a,endscen,l); a:= a[.l='Value']; var f:= if c[vari='Var_name']= Variables[.j='Var_name'] then Variables[.j='Var_id'] else 0; f:= sum(f,f.i); a:= array(iresult,[endscen,f,a,runn]); a:= concatrows(a,endscen,runn,row2); output:= if x= 1 then a else for y:= iresult do ( concat(output[iresult=y],a[iresult=y]) ); e:= e+size(b); x:= x+1); index row:= 1..size(output)/size(iresult); for y:= iresult do (slice(output[iresult=y],row)) 520,64,1 48,16 2,31,17,528,646 2,624,21,529,601,0,MIDM [Iresult,Sys_localindex('ROW')] [0,0,0,0] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24] [Sys_localindex('RUNN'),1,Iresult,3,Sys_localindex('ENDSCEN'),1] Write index if slice(indices_missing,1) = 'All indices have been defined already' then inp_ind else ( dbwrite(odbc_write, appendtablesql(inp_ind,Indices_missing,Inp_ind.j,'`Index` ')); 'Done') 640,360,1 48,16 65535,45873,39321 [Sys_localindex('A'),Iind] [] ODBC Library Lonnie Thu, Sep 11, 1997 2:15 PM Lonnie Tue, Feb 05, 2008 10:03 AM 48,24 56,304,1 52,24 1,1,1,1,1,1,0,0,0,0 1,20,272,499,497,17 Arial, 13 (A:ArrayType;I:IndexType;L:IndexType;row;dbTableName) InsertRecSql Generates the SQL "INSERT INTO" statement for one line of table A. A is a 2-D table indexed by rows I and columns L. L's domain serves as the column names in the database table. dbTableName is the name of the table in the database. The result begins with two semi-colons, since it will be used with an SQL statement preceeding it. 29.8.2008 Jouni Tuomisto I added the parameter IGNORE because it ignores rows that would cause duplicate-key violations. This way, there is no need to check for e.g. existing locations of new indices. (';;INSERT IGNORE INTO ' & dbTableName & '(' & JoinText(L,L,',') & ') VALUES (' & Vallist(A[I=row],L)) & ')' 184,32,1 52,24 2,41,136,487,469 A,I,L,row,dbTableName (V:ArrayType;I:IndexType) ValList Takes a list of values, and returns a string which the concatenation of each value, separated by commas, and with each value quoted. JoinText( '''' & V & '''', I, ',') 72,32,0 52,24 V,I 1,F,4,14,0,0 (Tabl:ArrayType;RowIndex:IndexType;LabelIndex:IndexType;dbTableName) WriteTableSql(Table,Rows,Labels,dbTableName) Returns the SQL that will write the table to the database table. This can be used as the second argument to DBWrite. This SQL statement replaces the entire contents of an existing table with the new data. 'DELETE FROM '& Dbtablename & JoinText(Insertrecsql(Tabl, Rowindex, Labelindex, Rowindex, Dbtablename),RowIndex) 328,32,1 88,24 2,728,341,510,476 Tabl,RowIndex,LabelIndex,dbTableName (Tabl:ArrayType;RowIndex:IndexType;LabelIndex:IndexType;dbTableName) AppendTableSql(Table,Rows,Labels,dbTableName) Returns the SQL that will write the table to the database table. This can be used as the second argument to DBWrite. This SQL statement replaces the entire contents of an existing table with the new data. JoinText(Insertrecsql(Tabl, Rowindex, Labelindex, Rowindex, Dbtablename),RowIndex) 328,88,1 88,24 2,353,73,510,476 Tabl,RowIndex,LabelIndex,dbTableName Inp_ind var a:= if Dimensions[.j='Dim_name']=New_index_info[iind='Dim_name'] then Dimensions[.j='Dim_id'] else 0; a:= sum(a,dimensions.i); index j:= ['Ind_id','Ind_name','Dim_id']; array(j,[ Card_ind+@Indices_missing, indices_missing, a]) ['item 1'] 520,360,1 48,16 2,197,430,416,303,0,MIDM 2,844,493,416,303,0,MIDM 19661,48336,65535 [Iind,Self] [Indices_missing,Sys_localindex('J')] ['item 1'] [Indices_missing,1,Sys_localindex('CO'),1,Sys_localindex('I'),1] iind ['Dim_name'] 56,392,1 48,13 ['Dim_name'] New dimension info Table(Idim,Dimensions_missing)( 'Pollutants considered', '-' ) ['item 1'] 168,321,1 48,31 2,197,253,767,303,0,MIDM 2,330,482,558,303,0,MIDM [Formnode Inp_dim1] 52425,39321,65535 [Idim,Dimensions_missing] [Dimensions_missing,Idim] ['item 1'] idim ['Dim_title','Dim_unit'] 168,360,1 48,13 ['Dim_title','Dim_unit'] Inp row var a:= if New_locs[.j='Ind_name'] = Inp_ind[.j='Ind_name'] then Inp_ind[.j='Ind_id'] else 0; a:= sum(a,Indices_missing); index j:= ['Ind_id','Row_number','Loc_id']; a:= array(j,[a,New_locs[.j='Row_number'],Inp_loc[.j='Loc_id']]) ['item 1'] 520,440,1 48,16 2,617,386,598,224 2,250,441,416,303,0,MIDM 2,782,442,448,347,0,MIDM 19661,48336,65535 [Self] [Sys_localindex('J'),Sys_localindex('I')] ['item 1'] Inp loc var a:= if New_locs[.j='Dim_name'] = Dimensions[.j='Dim_name'] then Dimensions[.j='Dim_id'] else 0; a:= max(a,Dimensions.i); index j:= ['Loc_id','Dim_id','Location']; a:= array(j,[card_loc+@New_locs.i, a, New_locs[.j='Location']]); ['item 1','item 2','item 3','item 4','item 5','item 6','item 7','item 8','item 9','item 10','item 11','item 12','item 13','item 14','item 15','item 16','item 17','item 18','item 19','item 20','item 21'] 520,400,1 48,16 2,319,169,421,433,0,MIDM 2,18,370,405,302,0,MIDM 19661,48336,65535 [Self] [Sys_localindex('J'),Sys_localindex('I')] ['item 1','item 2','item 3','item 4','item 5','item 6','item 7','item 8','item 9','item 10','item 11','item 12','item 13','item 14','item 15','item 16','item 17','item 18','item 19','item 20','item 21'] [Sys_localindex('J'),3,Sys_localindex('K'),1] Card ind Reset; index a:= DBquery(odbc,'SELECT Ind_id FROM `Index` '); index b:= ['Ind_id']; max(max(DBTable(a, b ),a),b) 376,360,1 48,16 39325,65535,39321 Card dim Reset; index a:= DBquery(odbc,'SELECT Dim_id FROM `Dimension` '); index b:= ['Dim_id']; max(max(DBTable(a, b ),a),b) 376,320,1 48,16 39325,65535,39321 Card loc Reset; index a:= DBquery('DSN=resultdatabase','SELECT Loc_id FROM `Location` '); index b:= ['Loc_id']; max(max(DBTable(a, b ),a),b) 376,400,1 48,16 39325,65535,39321 Write dimension if slice(dimensions_missing,1) = 'All dimensions have been defined already' then inp_dim else ( dbwrite(odbc_write, appendtablesql(Inp_dim,Dimensions_missing,Inp_dim.j,'Dimension ')); 'Done') 640,320,1 48,16 2,312,322,698,303,0,MIDM 65535,45873,39321 [Dimensions_missing,Sys_localindex('J')] [] Card res Reset; index a:= DBquery(odbc,'SELECT Result_id FROM `Result` '); index b:= ['Result_id']; max(max(DBTable(a, b ),a),b) 376,136,1 48,16 39325,65535,39321 Inp loc of result getfract forces the effect of sample() away, while mid doesn't 1) Does the process for each variable one at a time. Only the deterministic information about variables are considered (therefore getfract). 2) Flattens the array. The value is discarded and only the location info is kept. Location is changed into text because that is the format in the RDB. 3) Gets the Dimension (Dim_id) for each index of h. 4) Gets the Location (Loc_id) for each cell in a, given the dimension and location. 5) Flattens the array a. 6) Concatenates the results of all variables. 7) Makes Row the index of the implicit index. var output=0; var e:= card_res; var x:= 1; while x<= size(Variables_to_be_save)/size(vari) do ( var c:= slice(Variables_to_be_save,Variables_to_be_save,x); var a:= getfract(mid(evaluate(c[vari='Var_name'])),0.5); index h:= indexnames(a); index l:= concat(h,['Value']); index roww:= 1..size(a)*size(h); index endscen:= 1+e..size(a)+e; e:= e+size(a); a:= mdarraytotable(a,endscen,l); a:= selecttext(a[l=h],1); var dim:= if h=indices[.j='Ind_name'] then indices[.j='Dim_id'] else 0; dim:= sum(dim,indices.i); a:= if a=Locations[.j='Location'] and dim=Locations[.j='Dim_id'] then Locations[.j='Loc_id'] else 0; a:= sum(a,Locations.i); a:= array(Ilocres,[endscen,a]); a:= concatrows(a,a.h,endscen,roww); output:= if x= 1 then a else for y:= ilocres do ( concat(output[ilocres=y],a[ilocres=y]) ); x:= x+1); index row:= 1..size(output)/size(ilocres); for y:= ilocres do (slice(output[ilocres=y],row)) 520,136,1 48,16 2,59,37,518,793 2,457,6,335,809,0,MIDM [Ilocres,Sys_localindex('ROW')] [] [Sys_localindex('H'),3,Sys_localindex('I'),1,Sys_localindex('ENDSCEN'),1] Write locres dbwrite(odbc_write, appendtablesql(inp_loc_of_result,inp_loc_of_result.row,Ilocres,'Loc_of_result ')); 'Done' 640,136,1 48,16 65535,45873,39321 [] iresult ['Result_id','Var_id','Result','Sample'] 520,96,1 48,13 [] ['Result_id','Var_id','Result','Sample'] ilocres ['Result_id','Loc_id'] 520,168,1 48,13 Inp run list var output:= 0; var e:= card_res; var x:= 1; while x<= size(Variables_to_be_save)/size(vari) do ( var c:= slice(Variables_to_be_save,Variables_to_be_save,x); var b:= getfract(mid(evaluate(c[vari='Var_name'])),0.5); index endscen:= 1+e..size(b)+e; var a:= array(irunlist,[endscen,card_run+1]); output:= if x= 1 then a else for y:= irunlist do ( concat(output[irunlist=y],a[irunlist=y]) ); e:= e+size(b); x:= x+1); index row:= 1..size(output)/size(irunlist); for y:= irunlist do (slice(output[irunlist=y],row)) 520,208,1 48,16 2,102,90,476,578 2,859,396,372,337,0,MIDM [Irunlist,Sys_localindex('ROW')] Card run Reset; index a:= DBquery(odbc,'SELECT Run_id FROM `Run` '); index b:= ['Run_id']; max(max(DBTable(a, b ),a),b); 376,208,1 48,16 1,1,1,1,1,1,0,0,0,0 39325,65535,39321 irunlist ['Result_id','Run_id'] 520,240,1 48,13 1,1,1,1,1,1,0,0,0,0 Run info Table(Irun)( '5.9.2008','Jouni','Farmed salmon.ANA 10:36, 31 December 2007, RDB connection.ANA 13:58, 3 September 2008') 280,280,1 48,16 2,246,120,629,303,0,MIDM 2,415,466,457,303,0,MIDM [Formnode Inp_run1] 52425,39321,65535 [Irun,Self] [Self,Irun] 2,D,4,2,0,0,4,0,$,0,"yyyy-mm-dd",0 ['item 1'] irun ['Run_date','Run_who','Run_method'] 280,304,1 48,13 ['Run_date','Run_who','Run_method'] New variable info Table(Ivar,Variables_missing)( 'Omega-3 content in salmon', 'g/g' ) 224,25,1 48,22 2,239,183,675,453 2,190,0,589,183,0,MIDM 2,152,434,886,303,0,MIDM [Formnode Inp_var1] 52425,39321,65535 [Ivar,Variables_missing] [Ivar,Variables_missing] 2,D,4,2,0,0,4,0,$,0,"yyyy-mm-dd",0 ['item 1','item 2'] ivar ['Var_title','Var_unit'] 224,56,1 48,12 ['Var_title','Var_unit'] Write var if slice(Variables_missing,1) = 'All variables have been defined already' then Var1 else ( dbwrite(odbc_write, appendtablesql(var1,Variables_missing,var1.co,'Variable ')); 'Done') 640,24,1 48,16 65535,45873,39321 [Variables_missing,Sys_localindex('CO')] [] Write run dbwrite(odbc_write, appendtablesql(Inp_run,Inp_run.i,Inp_run.j,'Run ')); 'Done' 640,280,1 48,16 65535,45873,39321 [] Write runlist dbwrite(odbc_write, appendtablesql(inp_run_list,inp_run_list.row,Irunlist,'Run_list ')); 'Done' 640,208,1 48,16 65535,45873,39321 [] Write result dbwrite(odbc_write, appendtablesql(inp_result,inp_result.row,Iresult,'Result ')); 'Done' 640,64,1 48,16 65535,45873,39321 [] Write location if slice(indices_missing,1) = 'All indices have been defined already' then inp_loc else ( dbwrite(odbc_write, appendtablesql(inp_loc,New_locs.i,inp_loc.j,'Location ')); 'Done') 640,400,1 48,16 65535,45873,39321 [Sys_localindex('I'),Sys_localindex('J')] 2,D,4,2,0,0,4,0,$,0,"ABBREV",0 [] Write row if slice(indices_missing,1) = 'All indices have been defined already' then inp_row else ( dbwrite(odbc_write, appendtablesql(inp_row,New_locs.i,inp_row.j,'Rows ')); 'Done') 640,440,1 48,16 65535,45873,39321 [Sys_localindex('I'),Sys_localindex('J')] 2,D,4,2,0,0,4,0,$,0,"ABBREV",0 [] vari ['Var_name','Probabilistic?'] 224,168,1 48,12 ['Var_name','Probabilistic?'] Reset 184 56,40,1 48,12 1,1,0,1,1,1,0,0,0,0 New locs 1) Takes the first index and calculates the parameters for it. 2) Does the same for all other indices and concatenates the parameter results. 3) All parameters are lumped into a single array. 4) A complicated way to take into account whether there are any new indices. This is done because if then else cannot be used for these arrays in a straightforward way (the condition cannot have critical dimensions). If-then-else is replaced with conditional slice. 5) Finally, extra rows are removed. var a:= indices_used; var b:= evaluate(a[@.indices_used=1]); var c:= if b=0 then a[@.indices_used=1] else a[@.indices_used=1]; var e:= 1..size(b); var x:= 2; while x<=size(a) do ( var d:= evaluate(a[@.indices_used=x]); b:= concat(b,d); c:= concat(c,(if d=0 then a[@.indices_used=x] else a[@.indices_used=x])); e:= concat(e,1..size(d)); x:= x+1); index k:= 1..size(b); b:= slice(b,k); c:= slice(c,k); e:= slice(e,k); var d:= New_index_info[iind='Dim_name',indices_missing=c]; d:= if d=null then 0 else d; index j:= ['Dim_name','Location','Ind_name','Row_number']; a:= array(j,[d,b,c,e]); index L:= 1..size(k)+1; index m:= ['All locations have been defined already']; a:= concat(a,m,k,m,L); index g:= if slice(indices_missing,1) = 'All indices have been defined already' then size(k)+1..size(k)+1 else k; a:= slice(a,L,g); a:= a[g=subset(a[.j='Dim_name'])]; index i:= 1..(size(a)/size(j)); for f:= j do slice(a[j=f],i) 376,456,1 48,16 2,7,40,476,692 2,685,132,589,303,0,MIDM [Sys_localindex('J'),Sys_localindex('I')] ['','','','','','','','','',''] [Inp_ind,1,Indices_missing,1,Self,1] ODBC 'Driver={MySQL ODBC 5.1 Driver};Server=10.66.10.102;Database=resultdb;User=result_reader; Password=ora4ever;Option=3' 56,16,1 48,12 1,1,0,1,1,1,0,,0, 2,102,90,476,224 Dimensions Reset; index i:= DBquery(odbc,'SELECT Dim_id, Dim_name FROM `Dimension` '); index j:= ['Dim_id','Dim_name']; DBTable(i, j ) 56,136,1 48,12 1,1,0,1,1,1,0,0,0,0 2,922,53,316,489,0,MIDM 39325,65535,39321 [Sys_localindex('J'),Sys_localindex('I')] Variables missing This node checks the variables listed in Var_for_rdb and makes an index of those that are NOT found in the result database. This is then used as an index in Inp_var for adding variable information. var a:= Variables[.j='Var_name']; var e:= Variables_to_be_save[vari='Var_name']; a:= ','&jointext(a,a.i,',')&','; a:= if findintext(','&e&',',a)>0 then 0 else 1; a:= e[Variables_to_be_save=subset(a)]; var b:= if size(a)=0 then size(a)+1..size(a)+1 else 1..size(a); a:= concat(a,['All variables have been defined already']); slice(a,b) 224,88,1 48,22 1,1,1,1,1,1,0,0,0,0 2,7,24,493,501 2,807,266,435,273,0,MIDM 39321,39325,65535 [Self,Vari] ['All variables have been defined already'] Indices missing This node checks the indices listed in variables in Var_for_rdb and makes an index of those that are NOT found in the result database. This is then used as an index in Inp_var for adding variable information. Definition of e is based on the assumption that var_for_rdb is always the outermost index and therefore is always the last. {Reset; var a:= indices[.j='Ind_name']; var e:= indices_used; a:=','&jointext(a,a.i,',')&','; a:= if findintext(','&e&',',a)>0 then 0 else 1; a:= e[.indices_used=subset(a)]; var b:= if size(a)>0 then 1..size(a) else size(a)+1..size(a)+1; a:= concat(a,['All indices have been defined already']); slice(a,b)}['All indices have been defined already'] Reset; var a:= indices[.j='Ind_name']; var e:= indices_used; a:=','&jointext(a,a.i,',')&','; a:= if findintext(','&e&',',a)>0 then 0 else 1; a:= e[.indices_used=subset(a)]; var b:= if size(a)>0 then 1..size(a) else size(a)+1..size(a)+1; a:= concat(a,['All indices have been defined already']); slice(a,b) 56,424,1 48,22 1,1,1,1,1,1,0,0,0,0 2,466,22,493,593 2,743,52,490,302,0,MIDM 39321,39325,65535 [Self,Vari] ['All indices have been defined already'] New index info Table(Iind,Indices_missing)( 'Calendar_time' ) 56,360,1 48,22 2,34,74,606,204,0,MIDM 2,14,97,520,238,0,MIDM [Formnode Input_ind1] 52425,39321,65535 [Iind,Indices_missing] [Iind,Indices_missing] Indices used This lists all indices that are used by all of the variables that are to be inserted into the result database. This is based on an assumption that the index Ind_var is always the outermost index and therefore last. Then it is sliced away. reset; var a:= Variables_to_be_save[vari='Var_name']; a:= indexnames(evaluate(a)); index i:= 1..size(a); a:= slice(a,i); a:= if a= 'Variables_to_be_save' then 0 else a; a[i=subset(a)] 224,456,1 48,16 2,695,224,476,566 2,36,50,416,303,0,MIDM [Sys_localindex('J'),Self] ['Age1','Municipality_fin1','Inp_var'] [Inp_ind,1,Indices_missing,1,Self,1] Dimensions missing This node checks the indices listed in variables in Var_for_rdb and makes an index of those that are NOT found in the result database. This is then used as an index in Inp_var for adding variable information. Definition of e is based on the assumption that var_for_rdb is always the outermost index and therefore is always the last. var a:= dimensions[.j='Dim_name']; var e:= New_index_info[iind='Dim_name']; a:=','&jointext(a,a.i,',')&','; a:= if findintext(','&e&',',a)>0 then 0 else 1; a:= e[indices_missing=subset(a)]; var b:= if size(a)=0 or slice(Indices_missing,1) = 'All indices have been defined already' then size(a)+1..size(a)+1 else 1..size(a); a:= concat(a,['All dimensions have been defined already']); slice(a,b) 168,392,1 48,22 1,1,1,1,1,1,0,0,0,0 2,763,42,493,593 2,123,127,328,489,0,MIDM 39321,39325,65535 [Self,Indices_missing] ['All dimensions have been defined already'] Var var c:= Card_var; index co:= ['Var_id','Var_name','Var_title','Var_unit','Page_id','Wiki_id']; array(co,[ c+@Variables_missing, Variables_missing, New_variable_info[ivar='Var_title'], New_variable_info[ivar='Var_unit'], Selecttext( New_variable_info[ivar='Var_name'], 2), Selecttext( New_variable_info[ivar='Var_name'], 1,1)]) 520,24,1 48,16 1,1,1,1,1,1,0,0,0,0 2,102,90,502,425 2,255,386,800,303,0,MIDM 19661,48336,65535 [Variables_missing,Sys_localindex('CO')] Indices Reset; index i:= DBquery(odbc,'SELECT Ind_id, Ind_name, Dimension.Dim_id, Dim_name FROM `Index`, Dimension WHERE `Index`.Dim_id=Dimension.Dim_id '); index j:= ['Ind_id','Ind_name','Dim_id','Dim_name']; DBTable(i, j ) 56,160,1 48,12 1,1,0,1,1,1,0,0,0,0 2,-73,97,476,296 2,740,152,481,493,0,MIDM 39325,65535,39321 [Sys_localindex('J'),Sys_localindex('I')] Inp_dim index j:= ['Dim_id','Dim_name','Dim_title','Dim_unit']; array(j,[ Card_dim+@Dimensions_missing, Dimensions_missing, New_dimension_info[Idim='Dim_title'], New_dimension_info[Idim='Dim_unit']]) 520,320,1 48,16 2,440,450,416,303,0,MIDM [Dimensions_missing,Sys_localindex('J')] ODBC write 'Driver={MySQL ODBC 5.1 Driver};Server=10.66.10.102;Database=resultdb;User='&username&'; Password='&password&';Option=3' 56,112,1 48,12 1,1,0,1,1,1,0,,0, Add password 56,64,0 48,12 1,1,1,1,1,1,0,0,0,0 [Formnode Username1] 52425,39321,65535 'Add password' 56,88,0 48,12 1,1,1,1,1,1,0,0,0,0 [Formnode Password1] 52425,39321,65535 Inp run index j:= ['Run_id','Run_date','Run_who','Run_method']; index i:= 1..1; var a:= Run_info[Irun=j]; a:= if j='Run_id' then Card_run+1 else a; a:= if j='Run_method' then a[j='Run_method']&', '&Run_data else a; array(i,[a]) 520,280,1 48,16 2,168,178,683,303,0,MIDM [Sys_localindex('I'),Sys_localindex('J')] Locations Reset; index i:= DBquery(odbc,'SELECT Loc_id, Location, Dimension.Dim_id, Dim_name FROM `Location`, `Dimension` WHERE Location.Dim_id = Dimension.Dim_id '); index j:= ['Loc_id', 'Location', 'Dim_id', 'Dim_name']; DBTable(i, j) 56,184,1 48,12 1,1,0,1,1,1,0,0,0,0 2,102,90,476,445 2,572,44,696,521,0,MIDM 39325,65535,39321 [Sys_localindex('J'),Sys_localindex('I')] Card var Reset; index a:= DBquery(odbc,'SELECT Var_id FROM `Variable` '); index b:= ['Var_id']; max(max(DBTable(a, b ),a),b) 376,24,1 48,16 1,1,1,1,1,1,0,0,0,0 2,376,386,416,303,0,MIDM 39325,65535,39321 Variables This node checks the variables listed in Var_for_rdb and makes an index of those that are NOT found in the result database. This is then used as an index in Inp_var for adding variable information. Reset; index i:= DBquery(odbc,'SELECT Var_id, Var_name FROM `Variable` '); index j:= ['Var_id','Var_name']; var a:= DBTable(i, j ); a 56,208,1 48,12 1,1,0,1,1,1,0,0,0,0 2,254,142,493,501 2,529,143,331,437,0,MIDM 39325,65535,39321 [Sys_localindex('J'),Sys_localindex('I')] ['H1991'] [Self,1,Sys_localindex('I'),1,Sys_localindex('J'),1] Age1 ['18-65','3'] 80,560,1 48,12 Municipality_fin1 ['Harjavalta'] 72,584,1 64,12 Testvariable Municipality_fin2&Age1 80,528,1 48,24 [Municipality_fin1,Age1] Run data 'Edition: '&Analyticaedition&', Platform: '&Analyticaplatform&', Version: '&Analyticaversion&', Samplesize: '&Samplesize 280,248,1 48,16 2,119,357,476,303,0,MIDM 2,I,4,2,0,0,4,0,$,0,"ABBREV",0 Size of sample samplesize 192,520,1 48,16 [Formnode Size_of_sample1] 2,I,4,2,0,0,4,0,$,0,"ABBREV",0 appendtablesql(inp_loc,New_locs.i,inp_loc.j,'Location ') 280,392,1 48,24 2,376,386,587,303,0,MIDM Status 'Idle' 296,520,1 48,16 [Formnode Status1] This module saves model results into the Result Database. You need a password for that. Note that the necessary variable, index, dimension, and run information will be asked. You must add all tables before the process is completed. 236,40,-1 236,40 Note! You can insert several variables at the same time. Each variable MUST have at least one index. 152,120,-1 144,32 Te11 Fill in the data below if needed (in this order). 168,352,-5 160,192 1,0,0,1,0,1,0,,0, Username 0 156,196,1 140,12 1,0,0,1,0,0,0,110,0,1 52425,39321,65535 Username Password 0 156,220,1 140,12 1,0,0,1,0,0,0,110,0,1 52425,39321,65535 Password Input ind 0 156,368,1 140,16 1,0,0,1,0,0,0,78,0,1 52425,39321,65535 New_index_info Size of sample 1 156,460,1 140,12 1,0,0,1,0,0,0,72,0,1 Size_of_sample Status 1 156,484,1 140,12 1,0,0,1,0,0,0,126,0,1 Status